cs4236_lib.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  3. * Routines for control of CS4235/4236B/4237B/4238B/4239 chips
  4. *
  5. * Note:
  6. * -----
  7. *
  8. * Bugs:
  9. * -----
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. *
  25. */
  26. /*
  27. * Indirect control registers (CS4236B+)
  28. *
  29. * C0
  30. * D8: WSS reset (all chips)
  31. *
  32. * C1 (all chips except CS4236)
  33. * D7-D5: version
  34. * D4-D0: chip id
  35. * 11101 - CS4235
  36. * 01011 - CS4236B
  37. * 01000 - CS4237B
  38. * 01001 - CS4238B
  39. * 11110 - CS4239
  40. *
  41. * C2
  42. * D7-D4: 3D Space (CS4235,CS4237B,CS4238B,CS4239)
  43. * D3-D0: 3D Center (CS4237B); 3D Volume (CS4238B)
  44. *
  45. * C3
  46. * D7: 3D Enable (CS4237B)
  47. * D6: 3D Mono Enable (CS4237B)
  48. * D5: 3D Serial Output (CS4237B,CS4238B)
  49. * D4: 3D Enable (CS4235,CS4238B,CS4239)
  50. *
  51. * C4
  52. * D7: consumer serial port enable (CS4237B,CS4238B)
  53. * D6: channels status block reset (CS4237B,CS4238B)
  54. * D5: user bit in sub-frame of digital audio data (CS4237B,CS4238B)
  55. * D4: validity bit bit in sub-frame of digital audio data (CS4237B,CS4238B)
  56. *
  57. * C5 lower channel status (digital serial data description) (CS4237B,CS4238B)
  58. * D7-D6: first two bits of category code
  59. * D5: lock
  60. * D4-D3: pre-emphasis (0 = none, 1 = 50/15us)
  61. * D2: copy/copyright (0 = copy inhibited)
  62. * D1: 0 = digital audio / 1 = non-digital audio
  63. *
  64. * C6 upper channel status (digital serial data description) (CS4237B,CS4238B)
  65. * D7-D6: sample frequency (0 = 44.1kHz)
  66. * D5: generation status (0 = no indication, 1 = original/commercially precaptureed data)
  67. * D4-D0: category code (upper bits)
  68. *
  69. * C7 reserved (must write 0)
  70. *
  71. * C8 wavetable control
  72. * D7: volume control interrupt enable (CS4235,CS4239)
  73. * D6: hardware volume control format (CS4235,CS4239)
  74. * D3: wavetable serial port enable (all chips)
  75. * D2: DSP serial port switch (all chips)
  76. * D1: disable MCLK (all chips)
  77. * D0: force BRESET low (all chips)
  78. *
  79. */
  80. #include <asm/io.h>
  81. #include <linux/delay.h>
  82. #include <linux/init.h>
  83. #include <linux/time.h>
  84. #include <linux/wait.h>
  85. #include <sound/core.h>
  86. #include <sound/wss.h>
  87. #include <sound/asoundef.h>
  88. /*
  89. *
  90. */
  91. static unsigned char snd_cs4236_ext_map[18] = {
  92. /* CS4236_LEFT_LINE */ 0xff,
  93. /* CS4236_RIGHT_LINE */ 0xff,
  94. /* CS4236_LEFT_MIC */ 0xdf,
  95. /* CS4236_RIGHT_MIC */ 0xdf,
  96. /* CS4236_LEFT_MIX_CTRL */ 0xe0 | 0x18,
  97. /* CS4236_RIGHT_MIX_CTRL */ 0xe0,
  98. /* CS4236_LEFT_FM */ 0xbf,
  99. /* CS4236_RIGHT_FM */ 0xbf,
  100. /* CS4236_LEFT_DSP */ 0xbf,
  101. /* CS4236_RIGHT_DSP */ 0xbf,
  102. /* CS4236_RIGHT_LOOPBACK */ 0xbf,
  103. /* CS4236_DAC_MUTE */ 0xe0,
  104. /* CS4236_ADC_RATE */ 0x01, /* 48kHz */
  105. /* CS4236_DAC_RATE */ 0x01, /* 48kHz */
  106. /* CS4236_LEFT_MASTER */ 0xbf,
  107. /* CS4236_RIGHT_MASTER */ 0xbf,
  108. /* CS4236_LEFT_WAVE */ 0xbf,
  109. /* CS4236_RIGHT_WAVE */ 0xbf
  110. };
  111. /*
  112. *
  113. */
  114. static void snd_cs4236_ctrl_out(struct snd_wss *chip,
  115. unsigned char reg, unsigned char val)
  116. {
  117. outb(reg, chip->cport + 3);
  118. outb(chip->cimage[reg] = val, chip->cport + 4);
  119. }
  120. static unsigned char snd_cs4236_ctrl_in(struct snd_wss *chip, unsigned char reg)
  121. {
  122. outb(reg, chip->cport + 3);
  123. return inb(chip->cport + 4);
  124. }
  125. /*
  126. * PCM
  127. */
  128. #define CLOCKS 8
  129. static struct snd_ratnum clocks[CLOCKS] = {
  130. { .num = 16934400, .den_min = 353, .den_max = 353, .den_step = 1 },
  131. { .num = 16934400, .den_min = 529, .den_max = 529, .den_step = 1 },
  132. { .num = 16934400, .den_min = 617, .den_max = 617, .den_step = 1 },
  133. { .num = 16934400, .den_min = 1058, .den_max = 1058, .den_step = 1 },
  134. { .num = 16934400, .den_min = 1764, .den_max = 1764, .den_step = 1 },
  135. { .num = 16934400, .den_min = 2117, .den_max = 2117, .den_step = 1 },
  136. { .num = 16934400, .den_min = 2558, .den_max = 2558, .den_step = 1 },
  137. { .num = 16934400/16, .den_min = 21, .den_max = 192, .den_step = 1 }
  138. };
  139. static struct snd_pcm_hw_constraint_ratnums hw_constraints_clocks = {
  140. .nrats = CLOCKS,
  141. .rats = clocks,
  142. };
  143. static int snd_cs4236_xrate(struct snd_pcm_runtime *runtime)
  144. {
  145. return snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  146. &hw_constraints_clocks);
  147. }
  148. static unsigned char divisor_to_rate_register(unsigned int divisor)
  149. {
  150. switch (divisor) {
  151. case 353: return 1;
  152. case 529: return 2;
  153. case 617: return 3;
  154. case 1058: return 4;
  155. case 1764: return 5;
  156. case 2117: return 6;
  157. case 2558: return 7;
  158. default:
  159. if (divisor < 21 || divisor > 192) {
  160. snd_BUG();
  161. return 192;
  162. }
  163. return divisor;
  164. }
  165. }
  166. static void snd_cs4236_playback_format(struct snd_wss *chip,
  167. struct snd_pcm_hw_params *params,
  168. unsigned char pdfr)
  169. {
  170. unsigned long flags;
  171. unsigned char rate = divisor_to_rate_register(params->rate_den);
  172. spin_lock_irqsave(&chip->reg_lock, flags);
  173. /* set fast playback format change and clean playback FIFO */
  174. snd_wss_out(chip, CS4231_ALT_FEATURE_1,
  175. chip->image[CS4231_ALT_FEATURE_1] | 0x10);
  176. snd_wss_out(chip, CS4231_PLAYBK_FORMAT, pdfr & 0xf0);
  177. snd_wss_out(chip, CS4231_ALT_FEATURE_1,
  178. chip->image[CS4231_ALT_FEATURE_1] & ~0x10);
  179. snd_cs4236_ext_out(chip, CS4236_DAC_RATE, rate);
  180. spin_unlock_irqrestore(&chip->reg_lock, flags);
  181. }
  182. static void snd_cs4236_capture_format(struct snd_wss *chip,
  183. struct snd_pcm_hw_params *params,
  184. unsigned char cdfr)
  185. {
  186. unsigned long flags;
  187. unsigned char rate = divisor_to_rate_register(params->rate_den);
  188. spin_lock_irqsave(&chip->reg_lock, flags);
  189. /* set fast capture format change and clean capture FIFO */
  190. snd_wss_out(chip, CS4231_ALT_FEATURE_1,
  191. chip->image[CS4231_ALT_FEATURE_1] | 0x20);
  192. snd_wss_out(chip, CS4231_REC_FORMAT, cdfr & 0xf0);
  193. snd_wss_out(chip, CS4231_ALT_FEATURE_1,
  194. chip->image[CS4231_ALT_FEATURE_1] & ~0x20);
  195. snd_cs4236_ext_out(chip, CS4236_ADC_RATE, rate);
  196. spin_unlock_irqrestore(&chip->reg_lock, flags);
  197. }
  198. #ifdef CONFIG_PM
  199. static void snd_cs4236_suspend(struct snd_wss *chip)
  200. {
  201. int reg;
  202. unsigned long flags;
  203. spin_lock_irqsave(&chip->reg_lock, flags);
  204. for (reg = 0; reg < 32; reg++)
  205. chip->image[reg] = snd_wss_in(chip, reg);
  206. for (reg = 0; reg < 18; reg++)
  207. chip->eimage[reg] = snd_cs4236_ext_in(chip, CS4236_I23VAL(reg));
  208. for (reg = 2; reg < 9; reg++)
  209. chip->cimage[reg] = snd_cs4236_ctrl_in(chip, reg);
  210. spin_unlock_irqrestore(&chip->reg_lock, flags);
  211. }
  212. static void snd_cs4236_resume(struct snd_wss *chip)
  213. {
  214. int reg;
  215. unsigned long flags;
  216. snd_wss_mce_up(chip);
  217. spin_lock_irqsave(&chip->reg_lock, flags);
  218. for (reg = 0; reg < 32; reg++) {
  219. switch (reg) {
  220. case CS4236_EXT_REG:
  221. case CS4231_VERSION:
  222. case 27: /* why? CS4235 - master left */
  223. case 29: /* why? CS4235 - master right */
  224. break;
  225. default:
  226. snd_wss_out(chip, reg, chip->image[reg]);
  227. break;
  228. }
  229. }
  230. for (reg = 0; reg < 18; reg++)
  231. snd_cs4236_ext_out(chip, CS4236_I23VAL(reg), chip->eimage[reg]);
  232. for (reg = 2; reg < 9; reg++) {
  233. switch (reg) {
  234. case 7:
  235. break;
  236. default:
  237. snd_cs4236_ctrl_out(chip, reg, chip->cimage[reg]);
  238. }
  239. }
  240. spin_unlock_irqrestore(&chip->reg_lock, flags);
  241. snd_wss_mce_down(chip);
  242. }
  243. #endif /* CONFIG_PM */
  244. int snd_cs4236_create(struct snd_card *card,
  245. unsigned long port,
  246. unsigned long cport,
  247. int irq, int dma1, int dma2,
  248. unsigned short hardware,
  249. unsigned short hwshare,
  250. struct snd_wss **rchip)
  251. {
  252. struct snd_wss *chip;
  253. unsigned char ver1, ver2;
  254. unsigned int reg;
  255. int err;
  256. *rchip = NULL;
  257. if (hardware == WSS_HW_DETECT)
  258. hardware = WSS_HW_DETECT3;
  259. if (cport < 0x100) {
  260. snd_printk(KERN_ERR "please, specify control port "
  261. "for CS4236+ chips\n");
  262. return -ENODEV;
  263. }
  264. err = snd_wss_create(card, port, cport,
  265. irq, dma1, dma2, hardware, hwshare, &chip);
  266. if (err < 0)
  267. return err;
  268. if (!(chip->hardware & WSS_HW_CS4236B_MASK)) {
  269. snd_printk(KERN_ERR "CS4236+: MODE3 and extended registers "
  270. "not available, hardware=0x%x\n", chip->hardware);
  271. snd_device_free(card, chip);
  272. return -ENODEV;
  273. }
  274. #if 0
  275. {
  276. int idx;
  277. for (idx = 0; idx < 8; idx++)
  278. snd_printk(KERN_DEBUG "CD%i = 0x%x\n",
  279. idx, inb(chip->cport + idx));
  280. for (idx = 0; idx < 9; idx++)
  281. snd_printk(KERN_DEBUG "C%i = 0x%x\n",
  282. idx, snd_cs4236_ctrl_in(chip, idx));
  283. }
  284. #endif
  285. ver1 = snd_cs4236_ctrl_in(chip, 1);
  286. ver2 = snd_cs4236_ext_in(chip, CS4236_VERSION);
  287. snd_printdd("CS4236: [0x%lx] C1 (version) = 0x%x, ext = 0x%x\n", cport, ver1, ver2);
  288. if (ver1 != ver2) {
  289. snd_printk(KERN_ERR "CS4236+ chip detected, but "
  290. "control port 0x%lx is not valid\n", cport);
  291. snd_device_free(card, chip);
  292. return -ENODEV;
  293. }
  294. snd_cs4236_ctrl_out(chip, 0, 0x00);
  295. snd_cs4236_ctrl_out(chip, 2, 0xff);
  296. snd_cs4236_ctrl_out(chip, 3, 0x00);
  297. snd_cs4236_ctrl_out(chip, 4, 0x80);
  298. snd_cs4236_ctrl_out(chip, 5, ((IEC958_AES1_CON_PCM_CODER & 3) << 6) | IEC958_AES0_CON_EMPHASIS_NONE);
  299. snd_cs4236_ctrl_out(chip, 6, IEC958_AES1_CON_PCM_CODER >> 2);
  300. snd_cs4236_ctrl_out(chip, 7, 0x00);
  301. /* 0x8c for C8 is valid for Turtle Beach Malibu - the IEC-958 output */
  302. /* is working with this setup, other hardware should have */
  303. /* different signal paths and this value should be selectable */
  304. /* in the future */
  305. snd_cs4236_ctrl_out(chip, 8, 0x8c);
  306. chip->rate_constraint = snd_cs4236_xrate;
  307. chip->set_playback_format = snd_cs4236_playback_format;
  308. chip->set_capture_format = snd_cs4236_capture_format;
  309. #ifdef CONFIG_PM
  310. chip->suspend = snd_cs4236_suspend;
  311. chip->resume = snd_cs4236_resume;
  312. #endif
  313. /* initialize extended registers */
  314. for (reg = 0; reg < sizeof(snd_cs4236_ext_map); reg++)
  315. snd_cs4236_ext_out(chip, CS4236_I23VAL(reg), snd_cs4236_ext_map[reg]);
  316. /* initialize compatible but more featured registers */
  317. snd_wss_out(chip, CS4231_LEFT_INPUT, 0x40);
  318. snd_wss_out(chip, CS4231_RIGHT_INPUT, 0x40);
  319. snd_wss_out(chip, CS4231_AUX1_LEFT_INPUT, 0xff);
  320. snd_wss_out(chip, CS4231_AUX1_RIGHT_INPUT, 0xff);
  321. snd_wss_out(chip, CS4231_AUX2_LEFT_INPUT, 0xdf);
  322. snd_wss_out(chip, CS4231_AUX2_RIGHT_INPUT, 0xdf);
  323. snd_wss_out(chip, CS4231_RIGHT_LINE_IN, 0xff);
  324. snd_wss_out(chip, CS4231_LEFT_LINE_IN, 0xff);
  325. snd_wss_out(chip, CS4231_RIGHT_LINE_IN, 0xff);
  326. switch (chip->hardware) {
  327. case WSS_HW_CS4235:
  328. case WSS_HW_CS4239:
  329. snd_wss_out(chip, CS4235_LEFT_MASTER, 0xff);
  330. snd_wss_out(chip, CS4235_RIGHT_MASTER, 0xff);
  331. break;
  332. }
  333. *rchip = chip;
  334. return 0;
  335. }
  336. int snd_cs4236_pcm(struct snd_wss *chip, int device, struct snd_pcm **rpcm)
  337. {
  338. struct snd_pcm *pcm;
  339. int err;
  340. err = snd_wss_pcm(chip, device, &pcm);
  341. if (err < 0)
  342. return err;
  343. pcm->info_flags &= ~SNDRV_PCM_INFO_JOINT_DUPLEX;
  344. if (rpcm)
  345. *rpcm = pcm;
  346. return 0;
  347. }
  348. /*
  349. * MIXER
  350. */
  351. #define CS4236_SINGLE(xname, xindex, reg, shift, mask, invert) \
  352. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  353. .info = snd_cs4236_info_single, \
  354. .get = snd_cs4236_get_single, .put = snd_cs4236_put_single, \
  355. .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
  356. static int snd_cs4236_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  357. {
  358. int mask = (kcontrol->private_value >> 16) & 0xff;
  359. uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
  360. uinfo->count = 1;
  361. uinfo->value.integer.min = 0;
  362. uinfo->value.integer.max = mask;
  363. return 0;
  364. }
  365. static int snd_cs4236_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  366. {
  367. struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
  368. unsigned long flags;
  369. int reg = kcontrol->private_value & 0xff;
  370. int shift = (kcontrol->private_value >> 8) & 0xff;
  371. int mask = (kcontrol->private_value >> 16) & 0xff;
  372. int invert = (kcontrol->private_value >> 24) & 0xff;
  373. spin_lock_irqsave(&chip->reg_lock, flags);
  374. ucontrol->value.integer.value[0] = (chip->eimage[CS4236_REG(reg)] >> shift) & mask;
  375. spin_unlock_irqrestore(&chip->reg_lock, flags);
  376. if (invert)
  377. ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
  378. return 0;
  379. }
  380. static int snd_cs4236_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  381. {
  382. struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
  383. unsigned long flags;
  384. int reg = kcontrol->private_value & 0xff;
  385. int shift = (kcontrol->private_value >> 8) & 0xff;
  386. int mask = (kcontrol->private_value >> 16) & 0xff;
  387. int invert = (kcontrol->private_value >> 24) & 0xff;
  388. int change;
  389. unsigned short val;
  390. val = (ucontrol->value.integer.value[0] & mask);
  391. if (invert)
  392. val = mask - val;
  393. val <<= shift;
  394. spin_lock_irqsave(&chip->reg_lock, flags);
  395. val = (chip->eimage[CS4236_REG(reg)] & ~(mask << shift)) | val;
  396. change = val != chip->eimage[CS4236_REG(reg)];
  397. snd_cs4236_ext_out(chip, reg, val);
  398. spin_unlock_irqrestore(&chip->reg_lock, flags);
  399. return change;
  400. }
  401. #define CS4236_SINGLEC(xname, xindex, reg, shift, mask, invert) \
  402. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  403. .info = snd_cs4236_info_single, \
  404. .get = snd_cs4236_get_singlec, .put = snd_cs4236_put_singlec, \
  405. .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
  406. static int snd_cs4236_get_singlec(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  407. {
  408. struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
  409. unsigned long flags;
  410. int reg = kcontrol->private_value & 0xff;
  411. int shift = (kcontrol->private_value >> 8) & 0xff;
  412. int mask = (kcontrol->private_value >> 16) & 0xff;
  413. int invert = (kcontrol->private_value >> 24) & 0xff;
  414. spin_lock_irqsave(&chip->reg_lock, flags);
  415. ucontrol->value.integer.value[0] = (chip->cimage[reg] >> shift) & mask;
  416. spin_unlock_irqrestore(&chip->reg_lock, flags);
  417. if (invert)
  418. ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
  419. return 0;
  420. }
  421. static int snd_cs4236_put_singlec(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  422. {
  423. struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
  424. unsigned long flags;
  425. int reg = kcontrol->private_value & 0xff;
  426. int shift = (kcontrol->private_value >> 8) & 0xff;
  427. int mask = (kcontrol->private_value >> 16) & 0xff;
  428. int invert = (kcontrol->private_value >> 24) & 0xff;
  429. int change;
  430. unsigned short val;
  431. val = (ucontrol->value.integer.value[0] & mask);
  432. if (invert)
  433. val = mask - val;
  434. val <<= shift;
  435. spin_lock_irqsave(&chip->reg_lock, flags);
  436. val = (chip->cimage[reg] & ~(mask << shift)) | val;
  437. change = val != chip->cimage[reg];
  438. snd_cs4236_ctrl_out(chip, reg, val);
  439. spin_unlock_irqrestore(&chip->reg_lock, flags);
  440. return change;
  441. }
  442. #define CS4236_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
  443. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  444. .info = snd_cs4236_info_double, \
  445. .get = snd_cs4236_get_double, .put = snd_cs4236_put_double, \
  446. .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
  447. static int snd_cs4236_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  448. {
  449. int mask = (kcontrol->private_value >> 24) & 0xff;
  450. uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
  451. uinfo->count = 2;
  452. uinfo->value.integer.min = 0;
  453. uinfo->value.integer.max = mask;
  454. return 0;
  455. }
  456. static int snd_cs4236_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  457. {
  458. struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
  459. unsigned long flags;
  460. int left_reg = kcontrol->private_value & 0xff;
  461. int right_reg = (kcontrol->private_value >> 8) & 0xff;
  462. int shift_left = (kcontrol->private_value >> 16) & 0x07;
  463. int shift_right = (kcontrol->private_value >> 19) & 0x07;
  464. int mask = (kcontrol->private_value >> 24) & 0xff;
  465. int invert = (kcontrol->private_value >> 22) & 1;
  466. spin_lock_irqsave(&chip->reg_lock, flags);
  467. ucontrol->value.integer.value[0] = (chip->eimage[CS4236_REG(left_reg)] >> shift_left) & mask;
  468. ucontrol->value.integer.value[1] = (chip->eimage[CS4236_REG(right_reg)] >> shift_right) & mask;
  469. spin_unlock_irqrestore(&chip->reg_lock, flags);
  470. if (invert) {
  471. ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
  472. ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
  473. }
  474. return 0;
  475. }
  476. static int snd_cs4236_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  477. {
  478. struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
  479. unsigned long flags;
  480. int left_reg = kcontrol->private_value & 0xff;
  481. int right_reg = (kcontrol->private_value >> 8) & 0xff;
  482. int shift_left = (kcontrol->private_value >> 16) & 0x07;
  483. int shift_right = (kcontrol->private_value >> 19) & 0x07;
  484. int mask = (kcontrol->private_value >> 24) & 0xff;
  485. int invert = (kcontrol->private_value >> 22) & 1;
  486. int change;
  487. unsigned short val1, val2;
  488. val1 = ucontrol->value.integer.value[0] & mask;
  489. val2 = ucontrol->value.integer.value[1] & mask;
  490. if (invert) {
  491. val1 = mask - val1;
  492. val2 = mask - val2;
  493. }
  494. val1 <<= shift_left;
  495. val2 <<= shift_right;
  496. spin_lock_irqsave(&chip->reg_lock, flags);
  497. if (left_reg != right_reg) {
  498. val1 = (chip->eimage[CS4236_REG(left_reg)] & ~(mask << shift_left)) | val1;
  499. val2 = (chip->eimage[CS4236_REG(right_reg)] & ~(mask << shift_right)) | val2;
  500. change = val1 != chip->eimage[CS4236_REG(left_reg)] || val2 != chip->eimage[CS4236_REG(right_reg)];
  501. snd_cs4236_ext_out(chip, left_reg, val1);
  502. snd_cs4236_ext_out(chip, right_reg, val2);
  503. } else {
  504. val1 = (chip->eimage[CS4236_REG(left_reg)] & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
  505. change = val1 != chip->eimage[CS4236_REG(left_reg)];
  506. snd_cs4236_ext_out(chip, left_reg, val1);
  507. }
  508. spin_unlock_irqrestore(&chip->reg_lock, flags);
  509. return change;
  510. }
  511. #define CS4236_DOUBLE1(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
  512. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  513. .info = snd_cs4236_info_double, \
  514. .get = snd_cs4236_get_double1, .put = snd_cs4236_put_double1, \
  515. .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
  516. static int snd_cs4236_get_double1(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  517. {
  518. struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
  519. unsigned long flags;
  520. int left_reg = kcontrol->private_value & 0xff;
  521. int right_reg = (kcontrol->private_value >> 8) & 0xff;
  522. int shift_left = (kcontrol->private_value >> 16) & 0x07;
  523. int shift_right = (kcontrol->private_value >> 19) & 0x07;
  524. int mask = (kcontrol->private_value >> 24) & 0xff;
  525. int invert = (kcontrol->private_value >> 22) & 1;
  526. spin_lock_irqsave(&chip->reg_lock, flags);
  527. ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask;
  528. ucontrol->value.integer.value[1] = (chip->eimage[CS4236_REG(right_reg)] >> shift_right) & mask;
  529. spin_unlock_irqrestore(&chip->reg_lock, flags);
  530. if (invert) {
  531. ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
  532. ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
  533. }
  534. return 0;
  535. }
  536. static int snd_cs4236_put_double1(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  537. {
  538. struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
  539. unsigned long flags;
  540. int left_reg = kcontrol->private_value & 0xff;
  541. int right_reg = (kcontrol->private_value >> 8) & 0xff;
  542. int shift_left = (kcontrol->private_value >> 16) & 0x07;
  543. int shift_right = (kcontrol->private_value >> 19) & 0x07;
  544. int mask = (kcontrol->private_value >> 24) & 0xff;
  545. int invert = (kcontrol->private_value >> 22) & 1;
  546. int change;
  547. unsigned short val1, val2;
  548. val1 = ucontrol->value.integer.value[0] & mask;
  549. val2 = ucontrol->value.integer.value[1] & mask;
  550. if (invert) {
  551. val1 = mask - val1;
  552. val2 = mask - val2;
  553. }
  554. val1 <<= shift_left;
  555. val2 <<= shift_right;
  556. spin_lock_irqsave(&chip->reg_lock, flags);
  557. val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1;
  558. val2 = (chip->eimage[CS4236_REG(right_reg)] & ~(mask << shift_right)) | val2;
  559. change = val1 != chip->image[left_reg] || val2 != chip->eimage[CS4236_REG(right_reg)];
  560. snd_wss_out(chip, left_reg, val1);
  561. snd_cs4236_ext_out(chip, right_reg, val2);
  562. spin_unlock_irqrestore(&chip->reg_lock, flags);
  563. return change;
  564. }
  565. #define CS4236_MASTER_DIGITAL(xname, xindex) \
  566. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  567. .info = snd_cs4236_info_double, \
  568. .get = snd_cs4236_get_master_digital, .put = snd_cs4236_put_master_digital, \
  569. .private_value = 71 << 24 }
  570. static inline int snd_cs4236_mixer_master_digital_invert_volume(int vol)
  571. {
  572. return (vol < 64) ? 63 - vol : 64 + (71 - vol);
  573. }
  574. static int snd_cs4236_get_master_digital(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  575. {
  576. struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
  577. unsigned long flags;
  578. spin_lock_irqsave(&chip->reg_lock, flags);
  579. ucontrol->value.integer.value[0] = snd_cs4236_mixer_master_digital_invert_volume(chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] & 0x7f);
  580. ucontrol->value.integer.value[1] = snd_cs4236_mixer_master_digital_invert_volume(chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)] & 0x7f);
  581. spin_unlock_irqrestore(&chip->reg_lock, flags);
  582. return 0;
  583. }
  584. static int snd_cs4236_put_master_digital(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  585. {
  586. struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
  587. unsigned long flags;
  588. int change;
  589. unsigned short val1, val2;
  590. val1 = snd_cs4236_mixer_master_digital_invert_volume(ucontrol->value.integer.value[0] & 0x7f);
  591. val2 = snd_cs4236_mixer_master_digital_invert_volume(ucontrol->value.integer.value[1] & 0x7f);
  592. spin_lock_irqsave(&chip->reg_lock, flags);
  593. val1 = (chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] & ~0x7f) | val1;
  594. val2 = (chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)] & ~0x7f) | val2;
  595. change = val1 != chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] || val2 != chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)];
  596. snd_cs4236_ext_out(chip, CS4236_LEFT_MASTER, val1);
  597. snd_cs4236_ext_out(chip, CS4236_RIGHT_MASTER, val2);
  598. spin_unlock_irqrestore(&chip->reg_lock, flags);
  599. return change;
  600. }
  601. #define CS4235_OUTPUT_ACCU(xname, xindex) \
  602. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  603. .info = snd_cs4236_info_double, \
  604. .get = snd_cs4235_get_output_accu, .put = snd_cs4235_put_output_accu, \
  605. .private_value = 3 << 24 }
  606. static inline int snd_cs4235_mixer_output_accu_get_volume(int vol)
  607. {
  608. switch ((vol >> 5) & 3) {
  609. case 0: return 1;
  610. case 1: return 3;
  611. case 2: return 2;
  612. case 3: return 0;
  613. }
  614. return 3;
  615. }
  616. static inline int snd_cs4235_mixer_output_accu_set_volume(int vol)
  617. {
  618. switch (vol & 3) {
  619. case 0: return 3 << 5;
  620. case 1: return 0 << 5;
  621. case 2: return 2 << 5;
  622. case 3: return 1 << 5;
  623. }
  624. return 1 << 5;
  625. }
  626. static int snd_cs4235_get_output_accu(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  627. {
  628. struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
  629. unsigned long flags;
  630. spin_lock_irqsave(&chip->reg_lock, flags);
  631. ucontrol->value.integer.value[0] = snd_cs4235_mixer_output_accu_get_volume(chip->image[CS4235_LEFT_MASTER]);
  632. ucontrol->value.integer.value[1] = snd_cs4235_mixer_output_accu_get_volume(chip->image[CS4235_RIGHT_MASTER]);
  633. spin_unlock_irqrestore(&chip->reg_lock, flags);
  634. return 0;
  635. }
  636. static int snd_cs4235_put_output_accu(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  637. {
  638. struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
  639. unsigned long flags;
  640. int change;
  641. unsigned short val1, val2;
  642. val1 = snd_cs4235_mixer_output_accu_set_volume(ucontrol->value.integer.value[0]);
  643. val2 = snd_cs4235_mixer_output_accu_set_volume(ucontrol->value.integer.value[1]);
  644. spin_lock_irqsave(&chip->reg_lock, flags);
  645. val1 = (chip->image[CS4235_LEFT_MASTER] & ~(3 << 5)) | val1;
  646. val2 = (chip->image[CS4235_RIGHT_MASTER] & ~(3 << 5)) | val2;
  647. change = val1 != chip->image[CS4235_LEFT_MASTER] || val2 != chip->image[CS4235_RIGHT_MASTER];
  648. snd_wss_out(chip, CS4235_LEFT_MASTER, val1);
  649. snd_wss_out(chip, CS4235_RIGHT_MASTER, val2);
  650. spin_unlock_irqrestore(&chip->reg_lock, flags);
  651. return change;
  652. }
  653. static struct snd_kcontrol_new snd_cs4236_controls[] = {
  654. CS4236_DOUBLE("Master Digital Playback Switch", 0,
  655. CS4236_LEFT_MASTER, CS4236_RIGHT_MASTER, 7, 7, 1, 1),
  656. CS4236_DOUBLE("Master Digital Capture Switch", 0,
  657. CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1),
  658. CS4236_MASTER_DIGITAL("Master Digital Volume", 0),
  659. CS4236_DOUBLE("Capture Boost Volume", 0,
  660. CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1),
  661. WSS_DOUBLE("PCM Playback Switch", 0,
  662. CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
  663. WSS_DOUBLE("PCM Playback Volume", 0,
  664. CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1),
  665. CS4236_DOUBLE("DSP Playback Switch", 0,
  666. CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1),
  667. CS4236_DOUBLE("DSP Playback Volume", 0,
  668. CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 0, 0, 63, 1),
  669. CS4236_DOUBLE("FM Playback Switch", 0,
  670. CS4236_LEFT_FM, CS4236_RIGHT_FM, 7, 7, 1, 1),
  671. CS4236_DOUBLE("FM Playback Volume", 0,
  672. CS4236_LEFT_FM, CS4236_RIGHT_FM, 0, 0, 63, 1),
  673. CS4236_DOUBLE("Wavetable Playback Switch", 0,
  674. CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 7, 7, 1, 1),
  675. CS4236_DOUBLE("Wavetable Playback Volume", 0,
  676. CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 0, 0, 63, 1),
  677. WSS_DOUBLE("Synth Playback Switch", 0,
  678. CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
  679. WSS_DOUBLE("Synth Volume", 0,
  680. CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1),
  681. WSS_DOUBLE("Synth Capture Switch", 0,
  682. CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1),
  683. WSS_DOUBLE("Synth Capture Bypass", 0,
  684. CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 5, 5, 1, 1),
  685. CS4236_DOUBLE("Mic Playback Switch", 0,
  686. CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1),
  687. CS4236_DOUBLE("Mic Capture Switch", 0,
  688. CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1),
  689. CS4236_DOUBLE("Mic Volume", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 0, 0, 31, 1),
  690. CS4236_DOUBLE("Mic Playback Boost", 0,
  691. CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 5, 5, 1, 0),
  692. WSS_DOUBLE("Line Playback Switch", 0,
  693. CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
  694. WSS_DOUBLE("Line Volume", 0,
  695. CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1),
  696. WSS_DOUBLE("Line Capture Switch", 0,
  697. CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1),
  698. WSS_DOUBLE("Line Capture Bypass", 0,
  699. CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 5, 5, 1, 1),
  700. WSS_DOUBLE("CD Playback Switch", 0,
  701. CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
  702. WSS_DOUBLE("CD Volume", 0,
  703. CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
  704. WSS_DOUBLE("CD Capture Switch", 0,
  705. CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1),
  706. CS4236_DOUBLE1("Mono Output Playback Switch", 0,
  707. CS4231_MONO_CTRL, CS4236_RIGHT_MIX_CTRL, 6, 7, 1, 1),
  708. CS4236_DOUBLE1("Mono Playback Switch", 0,
  709. CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1),
  710. WSS_SINGLE("Mono Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1),
  711. WSS_SINGLE("Mono Playback Bypass", 0, CS4231_MONO_CTRL, 5, 1, 0),
  712. WSS_DOUBLE("Capture Volume", 0,
  713. CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0),
  714. WSS_DOUBLE("Analog Loopback Capture Switch", 0,
  715. CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0),
  716. WSS_SINGLE("Digital Loopback Playback Switch", 0, CS4231_LOOPBACK, 0, 1, 0),
  717. CS4236_DOUBLE1("Digital Loopback Playback Volume", 0,
  718. CS4231_LOOPBACK, CS4236_RIGHT_LOOPBACK, 2, 0, 63, 1)
  719. };
  720. static struct snd_kcontrol_new snd_cs4235_controls[] = {
  721. WSS_DOUBLE("Master Switch", 0,
  722. CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 7, 7, 1, 1),
  723. WSS_DOUBLE("Master Volume", 0,
  724. CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 0, 0, 31, 1),
  725. CS4235_OUTPUT_ACCU("Playback Volume", 0),
  726. CS4236_DOUBLE("Master Digital Playback Switch", 0,
  727. CS4236_LEFT_MASTER, CS4236_RIGHT_MASTER, 7, 7, 1, 1),
  728. CS4236_DOUBLE("Master Digital Capture Switch", 0,
  729. CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1),
  730. CS4236_MASTER_DIGITAL("Master Digital Volume", 0),
  731. WSS_DOUBLE("Master Digital Playback Switch", 1,
  732. CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
  733. WSS_DOUBLE("Master Digital Capture Switch", 1,
  734. CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1),
  735. WSS_DOUBLE("Master Digital Volume", 1,
  736. CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1),
  737. CS4236_DOUBLE("Capture Volume", 0,
  738. CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1),
  739. WSS_DOUBLE("PCM Switch", 0,
  740. CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
  741. WSS_DOUBLE("PCM Volume", 0,
  742. CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1),
  743. CS4236_DOUBLE("DSP Switch", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1),
  744. CS4236_DOUBLE("FM Switch", 0, CS4236_LEFT_FM, CS4236_RIGHT_FM, 7, 7, 1, 1),
  745. CS4236_DOUBLE("Wavetable Switch", 0,
  746. CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 7, 7, 1, 1),
  747. CS4236_DOUBLE("Mic Capture Switch", 0,
  748. CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1),
  749. CS4236_DOUBLE("Mic Playback Switch", 0,
  750. CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1),
  751. CS4236_SINGLE("Mic Volume", 0, CS4236_LEFT_MIC, 0, 31, 1),
  752. CS4236_SINGLE("Mic Playback Boost", 0, CS4236_LEFT_MIC, 5, 1, 0),
  753. WSS_DOUBLE("Aux Playback Switch", 0,
  754. CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
  755. WSS_DOUBLE("Aux Capture Switch", 0,
  756. CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1),
  757. WSS_DOUBLE("Aux Volume", 0,
  758. CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1),
  759. WSS_DOUBLE("Aux Playback Switch", 1,
  760. CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
  761. WSS_DOUBLE("Aux Capture Switch", 1,
  762. CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1),
  763. WSS_DOUBLE("Aux Volume", 1,
  764. CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
  765. CS4236_DOUBLE1("Master Mono Switch", 0,
  766. CS4231_MONO_CTRL, CS4236_RIGHT_MIX_CTRL, 6, 7, 1, 1),
  767. CS4236_DOUBLE1("Mono Switch", 0,
  768. CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1),
  769. WSS_SINGLE("Mono Volume", 0, CS4231_MONO_CTRL, 0, 15, 1),
  770. WSS_DOUBLE("Analog Loopback Switch", 0,
  771. CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0),
  772. };
  773. #define CS4236_IEC958_ENABLE(xname, xindex) \
  774. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  775. .info = snd_cs4236_info_single, \
  776. .get = snd_cs4236_get_iec958_switch, .put = snd_cs4236_put_iec958_switch, \
  777. .private_value = 1 << 16 }
  778. static int snd_cs4236_get_iec958_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  779. {
  780. struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
  781. unsigned long flags;
  782. spin_lock_irqsave(&chip->reg_lock, flags);
  783. ucontrol->value.integer.value[0] = chip->image[CS4231_ALT_FEATURE_1] & 0x02 ? 1 : 0;
  784. #if 0
  785. printk(KERN_DEBUG "get valid: ALT = 0x%x, C3 = 0x%x, C4 = 0x%x, "
  786. "C5 = 0x%x, C6 = 0x%x, C8 = 0x%x\n",
  787. snd_wss_in(chip, CS4231_ALT_FEATURE_1),
  788. snd_cs4236_ctrl_in(chip, 3),
  789. snd_cs4236_ctrl_in(chip, 4),
  790. snd_cs4236_ctrl_in(chip, 5),
  791. snd_cs4236_ctrl_in(chip, 6),
  792. snd_cs4236_ctrl_in(chip, 8));
  793. #endif
  794. spin_unlock_irqrestore(&chip->reg_lock, flags);
  795. return 0;
  796. }
  797. static int snd_cs4236_put_iec958_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  798. {
  799. struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
  800. unsigned long flags;
  801. int change;
  802. unsigned short enable, val;
  803. enable = ucontrol->value.integer.value[0] & 1;
  804. mutex_lock(&chip->mce_mutex);
  805. snd_wss_mce_up(chip);
  806. spin_lock_irqsave(&chip->reg_lock, flags);
  807. val = (chip->image[CS4231_ALT_FEATURE_1] & ~0x0e) | (0<<2) | (enable << 1);
  808. change = val != chip->image[CS4231_ALT_FEATURE_1];
  809. snd_wss_out(chip, CS4231_ALT_FEATURE_1, val);
  810. val = snd_cs4236_ctrl_in(chip, 4) | 0xc0;
  811. snd_cs4236_ctrl_out(chip, 4, val);
  812. udelay(100);
  813. val &= ~0x40;
  814. snd_cs4236_ctrl_out(chip, 4, val);
  815. spin_unlock_irqrestore(&chip->reg_lock, flags);
  816. snd_wss_mce_down(chip);
  817. mutex_unlock(&chip->mce_mutex);
  818. #if 0
  819. printk(KERN_DEBUG "set valid: ALT = 0x%x, C3 = 0x%x, C4 = 0x%x, "
  820. "C5 = 0x%x, C6 = 0x%x, C8 = 0x%x\n",
  821. snd_wss_in(chip, CS4231_ALT_FEATURE_1),
  822. snd_cs4236_ctrl_in(chip, 3),
  823. snd_cs4236_ctrl_in(chip, 4),
  824. snd_cs4236_ctrl_in(chip, 5),
  825. snd_cs4236_ctrl_in(chip, 6),
  826. snd_cs4236_ctrl_in(chip, 8));
  827. #endif
  828. return change;
  829. }
  830. static struct snd_kcontrol_new snd_cs4236_iec958_controls[] = {
  831. CS4236_IEC958_ENABLE("IEC958 Output Enable", 0),
  832. CS4236_SINGLEC("IEC958 Output Validity", 0, 4, 4, 1, 0),
  833. CS4236_SINGLEC("IEC958 Output User", 0, 4, 5, 1, 0),
  834. CS4236_SINGLEC("IEC958 Output CSBR", 0, 4, 6, 1, 0),
  835. CS4236_SINGLEC("IEC958 Output Channel Status Low", 0, 5, 1, 127, 0),
  836. CS4236_SINGLEC("IEC958 Output Channel Status High", 0, 6, 0, 255, 0)
  837. };
  838. static struct snd_kcontrol_new snd_cs4236_3d_controls_cs4235[] = {
  839. CS4236_SINGLEC("3D Control - Switch", 0, 3, 4, 1, 0),
  840. CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1)
  841. };
  842. static struct snd_kcontrol_new snd_cs4236_3d_controls_cs4237[] = {
  843. CS4236_SINGLEC("3D Control - Switch", 0, 3, 7, 1, 0),
  844. CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1),
  845. CS4236_SINGLEC("3D Control - Center", 0, 2, 0, 15, 1),
  846. CS4236_SINGLEC("3D Control - Mono", 0, 3, 6, 1, 0),
  847. CS4236_SINGLEC("3D Control - IEC958", 0, 3, 5, 1, 0)
  848. };
  849. static struct snd_kcontrol_new snd_cs4236_3d_controls_cs4238[] = {
  850. CS4236_SINGLEC("3D Control - Switch", 0, 3, 4, 1, 0),
  851. CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1),
  852. CS4236_SINGLEC("3D Control - Volume", 0, 2, 0, 15, 1),
  853. CS4236_SINGLEC("3D Control - IEC958", 0, 3, 5, 1, 0)
  854. };
  855. int snd_cs4236_mixer(struct snd_wss *chip)
  856. {
  857. struct snd_card *card;
  858. unsigned int idx, count;
  859. int err;
  860. struct snd_kcontrol_new *kcontrol;
  861. if (snd_BUG_ON(!chip || !chip->card))
  862. return -EINVAL;
  863. card = chip->card;
  864. strcpy(card->mixername, snd_wss_chip_id(chip));
  865. if (chip->hardware == WSS_HW_CS4235 ||
  866. chip->hardware == WSS_HW_CS4239) {
  867. for (idx = 0; idx < ARRAY_SIZE(snd_cs4235_controls); idx++) {
  868. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4235_controls[idx], chip))) < 0)
  869. return err;
  870. }
  871. } else {
  872. for (idx = 0; idx < ARRAY_SIZE(snd_cs4236_controls); idx++) {
  873. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4236_controls[idx], chip))) < 0)
  874. return err;
  875. }
  876. }
  877. switch (chip->hardware) {
  878. case WSS_HW_CS4235:
  879. case WSS_HW_CS4239:
  880. count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4235);
  881. kcontrol = snd_cs4236_3d_controls_cs4235;
  882. break;
  883. case WSS_HW_CS4237B:
  884. count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4237);
  885. kcontrol = snd_cs4236_3d_controls_cs4237;
  886. break;
  887. case WSS_HW_CS4238B:
  888. count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4238);
  889. kcontrol = snd_cs4236_3d_controls_cs4238;
  890. break;
  891. default:
  892. count = 0;
  893. kcontrol = NULL;
  894. }
  895. for (idx = 0; idx < count; idx++, kcontrol++) {
  896. if ((err = snd_ctl_add(card, snd_ctl_new1(kcontrol, chip))) < 0)
  897. return err;
  898. }
  899. if (chip->hardware == WSS_HW_CS4237B ||
  900. chip->hardware == WSS_HW_CS4238B) {
  901. for (idx = 0; idx < ARRAY_SIZE(snd_cs4236_iec958_controls); idx++) {
  902. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4236_iec958_controls[idx], chip))) < 0)
  903. return err;
  904. }
  905. }
  906. return 0;
  907. }