cs4236_lib.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@suse.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 <sound/driver.h>
  81. #include <asm/io.h>
  82. #include <linux/delay.h>
  83. #include <linux/init.h>
  84. #include <linux/time.h>
  85. #include <linux/wait.h>
  86. #include <sound/core.h>
  87. #include <sound/cs4231.h>
  88. #include <sound/asoundef.h>
  89. MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
  90. MODULE_DESCRIPTION("Routines for control of CS4235/4236B/4237B/4238B/4239 chips");
  91. MODULE_LICENSE("GPL");
  92. /*
  93. *
  94. */
  95. static unsigned char snd_cs4236_ext_map[18] = {
  96. /* CS4236_LEFT_LINE */ 0xff,
  97. /* CS4236_RIGHT_LINE */ 0xff,
  98. /* CS4236_LEFT_MIC */ 0xdf,
  99. /* CS4236_RIGHT_MIC */ 0xdf,
  100. /* CS4236_LEFT_MIX_CTRL */ 0xe0 | 0x18,
  101. /* CS4236_RIGHT_MIX_CTRL */ 0xe0,
  102. /* CS4236_LEFT_FM */ 0xbf,
  103. /* CS4236_RIGHT_FM */ 0xbf,
  104. /* CS4236_LEFT_DSP */ 0xbf,
  105. /* CS4236_RIGHT_DSP */ 0xbf,
  106. /* CS4236_RIGHT_LOOPBACK */ 0xbf,
  107. /* CS4236_DAC_MUTE */ 0xe0,
  108. /* CS4236_ADC_RATE */ 0x01, /* 48kHz */
  109. /* CS4236_DAC_RATE */ 0x01, /* 48kHz */
  110. /* CS4236_LEFT_MASTER */ 0xbf,
  111. /* CS4236_RIGHT_MASTER */ 0xbf,
  112. /* CS4236_LEFT_WAVE */ 0xbf,
  113. /* CS4236_RIGHT_WAVE */ 0xbf
  114. };
  115. /*
  116. *
  117. */
  118. static void snd_cs4236_ctrl_out(struct snd_cs4231 *chip, unsigned char reg, unsigned char val)
  119. {
  120. outb(reg, chip->cport + 3);
  121. outb(chip->cimage[reg] = val, chip->cport + 4);
  122. }
  123. static unsigned char snd_cs4236_ctrl_in(struct snd_cs4231 *chip, unsigned char reg)
  124. {
  125. outb(reg, chip->cport + 3);
  126. return inb(chip->cport + 4);
  127. }
  128. /*
  129. * PCM
  130. */
  131. #define CLOCKS 8
  132. static struct snd_ratnum clocks[CLOCKS] = {
  133. { .num = 16934400, .den_min = 353, .den_max = 353, .den_step = 1 },
  134. { .num = 16934400, .den_min = 529, .den_max = 529, .den_step = 1 },
  135. { .num = 16934400, .den_min = 617, .den_max = 617, .den_step = 1 },
  136. { .num = 16934400, .den_min = 1058, .den_max = 1058, .den_step = 1 },
  137. { .num = 16934400, .den_min = 1764, .den_max = 1764, .den_step = 1 },
  138. { .num = 16934400, .den_min = 2117, .den_max = 2117, .den_step = 1 },
  139. { .num = 16934400, .den_min = 2558, .den_max = 2558, .den_step = 1 },
  140. { .num = 16934400/16, .den_min = 21, .den_max = 192, .den_step = 1 }
  141. };
  142. static struct snd_pcm_hw_constraint_ratnums hw_constraints_clocks = {
  143. .nrats = CLOCKS,
  144. .rats = clocks,
  145. };
  146. static int snd_cs4236_xrate(struct snd_pcm_runtime *runtime)
  147. {
  148. return snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  149. &hw_constraints_clocks);
  150. }
  151. static unsigned char divisor_to_rate_register(unsigned int divisor)
  152. {
  153. switch (divisor) {
  154. case 353: return 1;
  155. case 529: return 2;
  156. case 617: return 3;
  157. case 1058: return 4;
  158. case 1764: return 5;
  159. case 2117: return 6;
  160. case 2558: return 7;
  161. default:
  162. if (divisor < 21 || divisor > 192) {
  163. snd_BUG();
  164. return 192;
  165. }
  166. return divisor;
  167. }
  168. }
  169. static void snd_cs4236_playback_format(struct snd_cs4231 *chip, struct snd_pcm_hw_params *params, unsigned char pdfr)
  170. {
  171. unsigned long flags;
  172. unsigned char rate = divisor_to_rate_register(params->rate_den);
  173. spin_lock_irqsave(&chip->reg_lock, flags);
  174. /* set fast playback format change and clean playback FIFO */
  175. snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | 0x10);
  176. snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, pdfr & 0xf0);
  177. snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] & ~0x10);
  178. snd_cs4236_ext_out(chip, CS4236_DAC_RATE, rate);
  179. spin_unlock_irqrestore(&chip->reg_lock, flags);
  180. }
  181. static void snd_cs4236_capture_format(struct snd_cs4231 *chip, struct snd_pcm_hw_params *params, unsigned char cdfr)
  182. {
  183. unsigned long flags;
  184. unsigned char rate = divisor_to_rate_register(params->rate_den);
  185. spin_lock_irqsave(&chip->reg_lock, flags);
  186. /* set fast capture format change and clean capture FIFO */
  187. snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] | 0x20);
  188. snd_cs4231_out(chip, CS4231_REC_FORMAT, cdfr & 0xf0);
  189. snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] & ~0x20);
  190. snd_cs4236_ext_out(chip, CS4236_ADC_RATE, rate);
  191. spin_unlock_irqrestore(&chip->reg_lock, flags);
  192. }
  193. #ifdef CONFIG_PM
  194. static void snd_cs4236_suspend(struct snd_cs4231 *chip)
  195. {
  196. int reg;
  197. unsigned long flags;
  198. spin_lock_irqsave(&chip->reg_lock, flags);
  199. for (reg = 0; reg < 32; reg++)
  200. chip->image[reg] = snd_cs4231_in(chip, reg);
  201. for (reg = 0; reg < 18; reg++)
  202. chip->eimage[reg] = snd_cs4236_ext_in(chip, CS4236_I23VAL(reg));
  203. for (reg = 2; reg < 9; reg++)
  204. chip->cimage[reg] = snd_cs4236_ctrl_in(chip, reg);
  205. spin_unlock_irqrestore(&chip->reg_lock, flags);
  206. }
  207. static void snd_cs4236_resume(struct snd_cs4231 *chip)
  208. {
  209. int reg;
  210. unsigned long flags;
  211. snd_cs4231_mce_up(chip);
  212. spin_lock_irqsave(&chip->reg_lock, flags);
  213. for (reg = 0; reg < 32; reg++) {
  214. switch (reg) {
  215. case CS4236_EXT_REG:
  216. case CS4231_VERSION:
  217. case 27: /* why? CS4235 - master left */
  218. case 29: /* why? CS4235 - master right */
  219. break;
  220. default:
  221. snd_cs4231_out(chip, reg, chip->image[reg]);
  222. break;
  223. }
  224. }
  225. for (reg = 0; reg < 18; reg++)
  226. snd_cs4236_ext_out(chip, CS4236_I23VAL(reg), chip->eimage[reg]);
  227. for (reg = 2; reg < 9; reg++) {
  228. switch (reg) {
  229. case 7:
  230. break;
  231. default:
  232. snd_cs4236_ctrl_out(chip, reg, chip->cimage[reg]);
  233. }
  234. }
  235. spin_unlock_irqrestore(&chip->reg_lock, flags);
  236. snd_cs4231_mce_down(chip);
  237. }
  238. #endif /* CONFIG_PM */
  239. int snd_cs4236_create(struct snd_card *card,
  240. unsigned long port,
  241. unsigned long cport,
  242. int irq, int dma1, int dma2,
  243. unsigned short hardware,
  244. unsigned short hwshare,
  245. struct snd_cs4231 ** rchip)
  246. {
  247. struct snd_cs4231 *chip;
  248. unsigned char ver1, ver2;
  249. unsigned int reg;
  250. int err;
  251. *rchip = NULL;
  252. if (hardware == CS4231_HW_DETECT)
  253. hardware = CS4231_HW_DETECT3;
  254. if (cport < 0x100) {
  255. snd_printk("please, specify control port for CS4236+ chips\n");
  256. return -ENODEV;
  257. }
  258. if ((err = snd_cs4231_create(card, port, cport, irq, dma1, dma2, hardware, hwshare, &chip)) < 0)
  259. return err;
  260. if (!(chip->hardware & CS4231_HW_CS4236B_MASK)) {
  261. snd_printk("CS4236+: MODE3 and extended registers not available, hardware=0x%x\n",chip->hardware);
  262. snd_device_free(card, chip);
  263. return -ENODEV;
  264. }
  265. #if 0
  266. {
  267. int idx;
  268. for (idx = 0; idx < 8; idx++)
  269. snd_printk("CD%i = 0x%x\n", idx, inb(chip->cport + idx));
  270. for (idx = 0; idx < 9; idx++)
  271. snd_printk("C%i = 0x%x\n", idx, snd_cs4236_ctrl_in(chip, idx));
  272. }
  273. #endif
  274. ver1 = snd_cs4236_ctrl_in(chip, 1);
  275. ver2 = snd_cs4236_ext_in(chip, CS4236_VERSION);
  276. snd_printdd("CS4236: [0x%lx] C1 (version) = 0x%x, ext = 0x%x\n", cport, ver1, ver2);
  277. if (ver1 != ver2) {
  278. snd_printk("CS4236+ chip detected, but control port 0x%lx is not valid\n", cport);
  279. snd_device_free(card, chip);
  280. return -ENODEV;
  281. }
  282. snd_cs4236_ctrl_out(chip, 0, 0x00);
  283. snd_cs4236_ctrl_out(chip, 2, 0xff);
  284. snd_cs4236_ctrl_out(chip, 3, 0x00);
  285. snd_cs4236_ctrl_out(chip, 4, 0x80);
  286. snd_cs4236_ctrl_out(chip, 5, ((IEC958_AES1_CON_PCM_CODER & 3) << 6) | IEC958_AES0_CON_EMPHASIS_NONE);
  287. snd_cs4236_ctrl_out(chip, 6, IEC958_AES1_CON_PCM_CODER >> 2);
  288. snd_cs4236_ctrl_out(chip, 7, 0x00);
  289. /* 0x8c for C8 is valid for Turtle Beach Malibu - the IEC-958 output */
  290. /* is working with this setup, other hardware should have */
  291. /* different signal paths and this value should be selectable */
  292. /* in the future */
  293. snd_cs4236_ctrl_out(chip, 8, 0x8c);
  294. chip->rate_constraint = snd_cs4236_xrate;
  295. chip->set_playback_format = snd_cs4236_playback_format;
  296. chip->set_capture_format = snd_cs4236_capture_format;
  297. #ifdef CONFIG_PM
  298. chip->suspend = snd_cs4236_suspend;
  299. chip->resume = snd_cs4236_resume;
  300. #endif
  301. /* initialize extended registers */
  302. for (reg = 0; reg < sizeof(snd_cs4236_ext_map); reg++)
  303. snd_cs4236_ext_out(chip, CS4236_I23VAL(reg), snd_cs4236_ext_map[reg]);
  304. /* initialize compatible but more featured registers */
  305. snd_cs4231_out(chip, CS4231_LEFT_INPUT, 0x40);
  306. snd_cs4231_out(chip, CS4231_RIGHT_INPUT, 0x40);
  307. snd_cs4231_out(chip, CS4231_AUX1_LEFT_INPUT, 0xff);
  308. snd_cs4231_out(chip, CS4231_AUX1_RIGHT_INPUT, 0xff);
  309. snd_cs4231_out(chip, CS4231_AUX2_LEFT_INPUT, 0xdf);
  310. snd_cs4231_out(chip, CS4231_AUX2_RIGHT_INPUT, 0xdf);
  311. snd_cs4231_out(chip, CS4231_RIGHT_LINE_IN, 0xff);
  312. snd_cs4231_out(chip, CS4231_LEFT_LINE_IN, 0xff);
  313. snd_cs4231_out(chip, CS4231_RIGHT_LINE_IN, 0xff);
  314. switch (chip->hardware) {
  315. case CS4231_HW_CS4235:
  316. case CS4231_HW_CS4239:
  317. snd_cs4231_out(chip, CS4235_LEFT_MASTER, 0xff);
  318. snd_cs4231_out(chip, CS4235_RIGHT_MASTER, 0xff);
  319. break;
  320. }
  321. *rchip = chip;
  322. return 0;
  323. }
  324. int snd_cs4236_pcm(struct snd_cs4231 *chip, int device, struct snd_pcm **rpcm)
  325. {
  326. struct snd_pcm *pcm;
  327. int err;
  328. if ((err = snd_cs4231_pcm(chip, device, &pcm)) < 0)
  329. return err;
  330. pcm->info_flags &= ~SNDRV_PCM_INFO_JOINT_DUPLEX;
  331. if (rpcm)
  332. *rpcm = pcm;
  333. return 0;
  334. }
  335. /*
  336. * MIXER
  337. */
  338. #define CS4236_SINGLE(xname, xindex, reg, shift, mask, invert) \
  339. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  340. .info = snd_cs4236_info_single, \
  341. .get = snd_cs4236_get_single, .put = snd_cs4236_put_single, \
  342. .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
  343. static int snd_cs4236_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  344. {
  345. int mask = (kcontrol->private_value >> 16) & 0xff;
  346. uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
  347. uinfo->count = 1;
  348. uinfo->value.integer.min = 0;
  349. uinfo->value.integer.max = mask;
  350. return 0;
  351. }
  352. static int snd_cs4236_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  353. {
  354. struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
  355. unsigned long flags;
  356. int reg = kcontrol->private_value & 0xff;
  357. int shift = (kcontrol->private_value >> 8) & 0xff;
  358. int mask = (kcontrol->private_value >> 16) & 0xff;
  359. int invert = (kcontrol->private_value >> 24) & 0xff;
  360. spin_lock_irqsave(&chip->reg_lock, flags);
  361. ucontrol->value.integer.value[0] = (chip->eimage[CS4236_REG(reg)] >> shift) & mask;
  362. spin_unlock_irqrestore(&chip->reg_lock, flags);
  363. if (invert)
  364. ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
  365. return 0;
  366. }
  367. static int snd_cs4236_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  368. {
  369. struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
  370. unsigned long flags;
  371. int reg = kcontrol->private_value & 0xff;
  372. int shift = (kcontrol->private_value >> 8) & 0xff;
  373. int mask = (kcontrol->private_value >> 16) & 0xff;
  374. int invert = (kcontrol->private_value >> 24) & 0xff;
  375. int change;
  376. unsigned short val;
  377. val = (ucontrol->value.integer.value[0] & mask);
  378. if (invert)
  379. val = mask - val;
  380. val <<= shift;
  381. spin_lock_irqsave(&chip->reg_lock, flags);
  382. val = (chip->eimage[CS4236_REG(reg)] & ~(mask << shift)) | val;
  383. change = val != chip->eimage[CS4236_REG(reg)];
  384. snd_cs4236_ext_out(chip, reg, val);
  385. spin_unlock_irqrestore(&chip->reg_lock, flags);
  386. return change;
  387. }
  388. #define CS4236_SINGLEC(xname, xindex, reg, shift, mask, invert) \
  389. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  390. .info = snd_cs4236_info_single, \
  391. .get = snd_cs4236_get_singlec, .put = snd_cs4236_put_singlec, \
  392. .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
  393. static int snd_cs4236_get_singlec(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  394. {
  395. struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
  396. unsigned long flags;
  397. int reg = kcontrol->private_value & 0xff;
  398. int shift = (kcontrol->private_value >> 8) & 0xff;
  399. int mask = (kcontrol->private_value >> 16) & 0xff;
  400. int invert = (kcontrol->private_value >> 24) & 0xff;
  401. spin_lock_irqsave(&chip->reg_lock, flags);
  402. ucontrol->value.integer.value[0] = (chip->cimage[reg] >> shift) & mask;
  403. spin_unlock_irqrestore(&chip->reg_lock, flags);
  404. if (invert)
  405. ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
  406. return 0;
  407. }
  408. static int snd_cs4236_put_singlec(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  409. {
  410. struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
  411. unsigned long flags;
  412. int reg = kcontrol->private_value & 0xff;
  413. int shift = (kcontrol->private_value >> 8) & 0xff;
  414. int mask = (kcontrol->private_value >> 16) & 0xff;
  415. int invert = (kcontrol->private_value >> 24) & 0xff;
  416. int change;
  417. unsigned short val;
  418. val = (ucontrol->value.integer.value[0] & mask);
  419. if (invert)
  420. val = mask - val;
  421. val <<= shift;
  422. spin_lock_irqsave(&chip->reg_lock, flags);
  423. val = (chip->cimage[reg] & ~(mask << shift)) | val;
  424. change = val != chip->cimage[reg];
  425. snd_cs4236_ctrl_out(chip, reg, val);
  426. spin_unlock_irqrestore(&chip->reg_lock, flags);
  427. return change;
  428. }
  429. #define CS4236_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
  430. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  431. .info = snd_cs4236_info_double, \
  432. .get = snd_cs4236_get_double, .put = snd_cs4236_put_double, \
  433. .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
  434. static int snd_cs4236_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  435. {
  436. int mask = (kcontrol->private_value >> 24) & 0xff;
  437. uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
  438. uinfo->count = 2;
  439. uinfo->value.integer.min = 0;
  440. uinfo->value.integer.max = mask;
  441. return 0;
  442. }
  443. static int snd_cs4236_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  444. {
  445. struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
  446. unsigned long flags;
  447. int left_reg = kcontrol->private_value & 0xff;
  448. int right_reg = (kcontrol->private_value >> 8) & 0xff;
  449. int shift_left = (kcontrol->private_value >> 16) & 0x07;
  450. int shift_right = (kcontrol->private_value >> 19) & 0x07;
  451. int mask = (kcontrol->private_value >> 24) & 0xff;
  452. int invert = (kcontrol->private_value >> 22) & 1;
  453. spin_lock_irqsave(&chip->reg_lock, flags);
  454. ucontrol->value.integer.value[0] = (chip->eimage[CS4236_REG(left_reg)] >> shift_left) & mask;
  455. ucontrol->value.integer.value[1] = (chip->eimage[CS4236_REG(right_reg)] >> shift_right) & mask;
  456. spin_unlock_irqrestore(&chip->reg_lock, flags);
  457. if (invert) {
  458. ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
  459. ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
  460. }
  461. return 0;
  462. }
  463. static int snd_cs4236_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  464. {
  465. struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
  466. unsigned long flags;
  467. int left_reg = kcontrol->private_value & 0xff;
  468. int right_reg = (kcontrol->private_value >> 8) & 0xff;
  469. int shift_left = (kcontrol->private_value >> 16) & 0x07;
  470. int shift_right = (kcontrol->private_value >> 19) & 0x07;
  471. int mask = (kcontrol->private_value >> 24) & 0xff;
  472. int invert = (kcontrol->private_value >> 22) & 1;
  473. int change;
  474. unsigned short val1, val2;
  475. val1 = ucontrol->value.integer.value[0] & mask;
  476. val2 = ucontrol->value.integer.value[1] & mask;
  477. if (invert) {
  478. val1 = mask - val1;
  479. val2 = mask - val2;
  480. }
  481. val1 <<= shift_left;
  482. val2 <<= shift_right;
  483. spin_lock_irqsave(&chip->reg_lock, flags);
  484. if (left_reg != right_reg) {
  485. val1 = (chip->eimage[CS4236_REG(left_reg)] & ~(mask << shift_left)) | val1;
  486. val2 = (chip->eimage[CS4236_REG(right_reg)] & ~(mask << shift_right)) | val2;
  487. change = val1 != chip->eimage[CS4236_REG(left_reg)] || val2 != chip->eimage[CS4236_REG(right_reg)];
  488. snd_cs4236_ext_out(chip, left_reg, val1);
  489. snd_cs4236_ext_out(chip, right_reg, val2);
  490. } else {
  491. val1 = (chip->eimage[CS4236_REG(left_reg)] & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
  492. change = val1 != chip->eimage[CS4236_REG(left_reg)];
  493. snd_cs4236_ext_out(chip, left_reg, val1);
  494. }
  495. spin_unlock_irqrestore(&chip->reg_lock, flags);
  496. return change;
  497. }
  498. #define CS4236_DOUBLE1(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
  499. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  500. .info = snd_cs4236_info_double, \
  501. .get = snd_cs4236_get_double1, .put = snd_cs4236_put_double1, \
  502. .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
  503. static int snd_cs4236_get_double1(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  504. {
  505. struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
  506. unsigned long flags;
  507. int left_reg = kcontrol->private_value & 0xff;
  508. int right_reg = (kcontrol->private_value >> 8) & 0xff;
  509. int shift_left = (kcontrol->private_value >> 16) & 0x07;
  510. int shift_right = (kcontrol->private_value >> 19) & 0x07;
  511. int mask = (kcontrol->private_value >> 24) & 0xff;
  512. int invert = (kcontrol->private_value >> 22) & 1;
  513. spin_lock_irqsave(&chip->reg_lock, flags);
  514. ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask;
  515. ucontrol->value.integer.value[1] = (chip->eimage[CS4236_REG(right_reg)] >> shift_right) & mask;
  516. spin_unlock_irqrestore(&chip->reg_lock, flags);
  517. if (invert) {
  518. ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
  519. ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
  520. }
  521. return 0;
  522. }
  523. static int snd_cs4236_put_double1(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  524. {
  525. struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
  526. unsigned long flags;
  527. int left_reg = kcontrol->private_value & 0xff;
  528. int right_reg = (kcontrol->private_value >> 8) & 0xff;
  529. int shift_left = (kcontrol->private_value >> 16) & 0x07;
  530. int shift_right = (kcontrol->private_value >> 19) & 0x07;
  531. int mask = (kcontrol->private_value >> 24) & 0xff;
  532. int invert = (kcontrol->private_value >> 22) & 1;
  533. int change;
  534. unsigned short val1, val2;
  535. val1 = ucontrol->value.integer.value[0] & mask;
  536. val2 = ucontrol->value.integer.value[1] & mask;
  537. if (invert) {
  538. val1 = mask - val1;
  539. val2 = mask - val2;
  540. }
  541. val1 <<= shift_left;
  542. val2 <<= shift_right;
  543. spin_lock_irqsave(&chip->reg_lock, flags);
  544. val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1;
  545. val2 = (chip->eimage[CS4236_REG(right_reg)] & ~(mask << shift_right)) | val2;
  546. change = val1 != chip->image[left_reg] || val2 != chip->eimage[CS4236_REG(right_reg)];
  547. snd_cs4231_out(chip, left_reg, val1);
  548. snd_cs4236_ext_out(chip, right_reg, val2);
  549. spin_unlock_irqrestore(&chip->reg_lock, flags);
  550. return change;
  551. }
  552. #define CS4236_MASTER_DIGITAL(xname, xindex) \
  553. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  554. .info = snd_cs4236_info_double, \
  555. .get = snd_cs4236_get_master_digital, .put = snd_cs4236_put_master_digital, \
  556. .private_value = 71 << 24 }
  557. static inline int snd_cs4236_mixer_master_digital_invert_volume(int vol)
  558. {
  559. return (vol < 64) ? 63 - vol : 64 + (71 - vol);
  560. }
  561. static int snd_cs4236_get_master_digital(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  562. {
  563. struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
  564. unsigned long flags;
  565. spin_lock_irqsave(&chip->reg_lock, flags);
  566. ucontrol->value.integer.value[0] = snd_cs4236_mixer_master_digital_invert_volume(chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] & 0x7f);
  567. ucontrol->value.integer.value[1] = snd_cs4236_mixer_master_digital_invert_volume(chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)] & 0x7f);
  568. spin_unlock_irqrestore(&chip->reg_lock, flags);
  569. return 0;
  570. }
  571. static int snd_cs4236_put_master_digital(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  572. {
  573. struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
  574. unsigned long flags;
  575. int change;
  576. unsigned short val1, val2;
  577. val1 = snd_cs4236_mixer_master_digital_invert_volume(ucontrol->value.integer.value[0] & 0x7f);
  578. val2 = snd_cs4236_mixer_master_digital_invert_volume(ucontrol->value.integer.value[1] & 0x7f);
  579. spin_lock_irqsave(&chip->reg_lock, flags);
  580. val1 = (chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] & ~0x7f) | val1;
  581. val2 = (chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)] & ~0x7f) | val2;
  582. change = val1 != chip->eimage[CS4236_REG(CS4236_LEFT_MASTER)] || val2 != chip->eimage[CS4236_REG(CS4236_RIGHT_MASTER)];
  583. snd_cs4236_ext_out(chip, CS4236_LEFT_MASTER, val1);
  584. snd_cs4236_ext_out(chip, CS4236_RIGHT_MASTER, val1);
  585. spin_unlock_irqrestore(&chip->reg_lock, flags);
  586. return change;
  587. }
  588. #define CS4235_OUTPUT_ACCU(xname, xindex) \
  589. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  590. .info = snd_cs4236_info_double, \
  591. .get = snd_cs4235_get_output_accu, .put = snd_cs4235_put_output_accu, \
  592. .private_value = 3 << 24 }
  593. static inline int snd_cs4235_mixer_output_accu_get_volume(int vol)
  594. {
  595. switch ((vol >> 5) & 3) {
  596. case 0: return 1;
  597. case 1: return 3;
  598. case 2: return 2;
  599. case 3: return 0;
  600. }
  601. return 3;
  602. }
  603. static inline int snd_cs4235_mixer_output_accu_set_volume(int vol)
  604. {
  605. switch (vol & 3) {
  606. case 0: return 3 << 5;
  607. case 1: return 0 << 5;
  608. case 2: return 2 << 5;
  609. case 3: return 1 << 5;
  610. }
  611. return 1 << 5;
  612. }
  613. static int snd_cs4235_get_output_accu(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  614. {
  615. struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
  616. unsigned long flags;
  617. spin_lock_irqsave(&chip->reg_lock, flags);
  618. ucontrol->value.integer.value[0] = snd_cs4235_mixer_output_accu_get_volume(chip->image[CS4235_LEFT_MASTER]);
  619. ucontrol->value.integer.value[1] = snd_cs4235_mixer_output_accu_get_volume(chip->image[CS4235_RIGHT_MASTER]);
  620. spin_unlock_irqrestore(&chip->reg_lock, flags);
  621. return 0;
  622. }
  623. static int snd_cs4235_put_output_accu(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  624. {
  625. struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
  626. unsigned long flags;
  627. int change;
  628. unsigned short val1, val2;
  629. val1 = snd_cs4235_mixer_output_accu_set_volume(ucontrol->value.integer.value[0]);
  630. val2 = snd_cs4235_mixer_output_accu_set_volume(ucontrol->value.integer.value[1]);
  631. spin_lock_irqsave(&chip->reg_lock, flags);
  632. val1 = (chip->image[CS4235_LEFT_MASTER] & ~(3 << 5)) | val1;
  633. val2 = (chip->image[CS4235_RIGHT_MASTER] & ~(3 << 5)) | val2;
  634. change = val1 != chip->image[CS4235_LEFT_MASTER] || val2 != chip->image[CS4235_RIGHT_MASTER];
  635. snd_cs4231_out(chip, CS4235_LEFT_MASTER, val1);
  636. snd_cs4231_out(chip, CS4235_RIGHT_MASTER, val2);
  637. spin_unlock_irqrestore(&chip->reg_lock, flags);
  638. return change;
  639. }
  640. static struct snd_kcontrol_new snd_cs4236_controls[] = {
  641. CS4236_DOUBLE("Master Digital Playback Switch", 0, CS4236_LEFT_MASTER, CS4236_RIGHT_MASTER, 7, 7, 1, 1),
  642. CS4236_DOUBLE("Master Digital Capture Switch", 0, CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1),
  643. CS4236_MASTER_DIGITAL("Master Digital Volume", 0),
  644. CS4236_DOUBLE("Capture Boost Volume", 0, CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1),
  645. CS4231_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
  646. CS4231_DOUBLE("PCM Playback Volume", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1),
  647. CS4236_DOUBLE("DSP Playback Switch", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1),
  648. CS4236_DOUBLE("DSP Playback Volume", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 0, 0, 63, 1),
  649. CS4236_DOUBLE("FM Playback Switch", 0, CS4236_LEFT_FM, CS4236_RIGHT_FM, 7, 7, 1, 1),
  650. CS4236_DOUBLE("FM Playback Volume", 0, CS4236_LEFT_FM, CS4236_RIGHT_FM, 0, 0, 63, 1),
  651. CS4236_DOUBLE("Wavetable Playback Switch", 0, CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 7, 7, 1, 1),
  652. CS4236_DOUBLE("Wavetable Playback Volume", 0, CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 0, 0, 63, 1),
  653. CS4231_DOUBLE("Synth Playback Switch", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
  654. CS4231_DOUBLE("Synth Volume", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1),
  655. CS4231_DOUBLE("Synth Capture Switch", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1),
  656. CS4231_DOUBLE("Synth Capture Bypass", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 5, 5, 1, 1),
  657. CS4236_DOUBLE("Mic Playback Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1),
  658. CS4236_DOUBLE("Mic Capture Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1),
  659. CS4236_DOUBLE("Mic Volume", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 0, 0, 31, 1),
  660. CS4236_DOUBLE("Mic Playback Boost", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 5, 5, 1, 0),
  661. CS4231_DOUBLE("Line Playback Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
  662. CS4231_DOUBLE("Line Volume", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1),
  663. CS4231_DOUBLE("Line Capture Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1),
  664. CS4231_DOUBLE("Line Capture Bypass", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 5, 5, 1, 1),
  665. CS4231_DOUBLE("CD Playback Switch", 0, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
  666. CS4231_DOUBLE("CD Volume", 0, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
  667. CS4231_DOUBLE("CD Capture Switch", 0, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1),
  668. CS4236_DOUBLE1("Mono Output Playback Switch", 0, CS4231_MONO_CTRL, CS4236_RIGHT_MIX_CTRL, 6, 7, 1, 1),
  669. CS4236_DOUBLE1("Mono Playback Switch", 0, CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1),
  670. CS4231_SINGLE("Mono Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1),
  671. CS4231_SINGLE("Mono Playback Bypass", 0, CS4231_MONO_CTRL, 5, 1, 0),
  672. CS4231_DOUBLE("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0),
  673. CS4231_DOUBLE("Analog Loopback Capture Switch", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0),
  674. CS4231_SINGLE("Digital Loopback Playback Switch", 0, CS4231_LOOPBACK, 0, 1, 0),
  675. CS4236_DOUBLE1("Digital Loopback Playback Volume", 0, CS4231_LOOPBACK, CS4236_RIGHT_LOOPBACK, 2, 0, 63, 1)
  676. };
  677. static struct snd_kcontrol_new snd_cs4235_controls[] = {
  678. CS4231_DOUBLE("Master Switch", 0, CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 7, 7, 1, 1),
  679. CS4231_DOUBLE("Master Volume", 0, CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 0, 0, 31, 1),
  680. CS4235_OUTPUT_ACCU("Playback Volume", 0),
  681. CS4236_DOUBLE("Master Digital Playback Switch", 0, CS4236_LEFT_MASTER, CS4236_RIGHT_MASTER, 7, 7, 1, 1),
  682. CS4236_DOUBLE("Master Digital Capture Switch", 0, CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1),
  683. CS4236_MASTER_DIGITAL("Master Digital Volume", 0),
  684. CS4231_DOUBLE("Master Digital Playback Switch", 1, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
  685. CS4231_DOUBLE("Master Digital Capture Switch", 1, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1),
  686. CS4231_DOUBLE("Master Digital Volume", 1, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1),
  687. CS4236_DOUBLE("Capture Volume", 0, CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1),
  688. CS4231_DOUBLE("PCM Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
  689. CS4231_DOUBLE("PCM Volume", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1),
  690. CS4236_DOUBLE("DSP Switch", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1),
  691. CS4236_DOUBLE("FM Switch", 0, CS4236_LEFT_FM, CS4236_RIGHT_FM, 7, 7, 1, 1),
  692. CS4236_DOUBLE("Wavetable Switch", 0, CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 7, 7, 1, 1),
  693. CS4236_DOUBLE("Mic Capture Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1),
  694. CS4236_DOUBLE("Mic Playback Switch", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1),
  695. CS4236_SINGLE("Mic Volume", 0, CS4236_LEFT_MIC, 0, 31, 1),
  696. CS4236_SINGLE("Mic Playback Boost", 0, CS4236_LEFT_MIC, 5, 1, 0),
  697. CS4231_DOUBLE("Aux Playback Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
  698. CS4231_DOUBLE("Aux Capture Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1),
  699. CS4231_DOUBLE("Aux Volume", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1),
  700. CS4231_DOUBLE("Aux Playback Switch", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
  701. CS4231_DOUBLE("Aux Capture Switch", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1),
  702. CS4231_DOUBLE("Aux Volume", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
  703. CS4236_DOUBLE1("Master Mono Switch", 0, CS4231_MONO_CTRL, CS4236_RIGHT_MIX_CTRL, 6, 7, 1, 1),
  704. CS4236_DOUBLE1("Mono Switch", 0, CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1),
  705. CS4231_SINGLE("Mono Volume", 0, CS4231_MONO_CTRL, 0, 15, 1),
  706. CS4231_DOUBLE("Analog Loopback Switch", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0),
  707. };
  708. #define CS4236_IEC958_ENABLE(xname, xindex) \
  709. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  710. .info = snd_cs4236_info_single, \
  711. .get = snd_cs4236_get_iec958_switch, .put = snd_cs4236_put_iec958_switch, \
  712. .private_value = 1 << 16 }
  713. static int snd_cs4236_get_iec958_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  714. {
  715. struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
  716. unsigned long flags;
  717. spin_lock_irqsave(&chip->reg_lock, flags);
  718. ucontrol->value.integer.value[0] = chip->image[CS4231_ALT_FEATURE_1] & 0x02 ? 1 : 0;
  719. #if 0
  720. printk("get valid: ALT = 0x%x, C3 = 0x%x, C4 = 0x%x, C5 = 0x%x, C6 = 0x%x, C8 = 0x%x\n",
  721. snd_cs4231_in(chip, CS4231_ALT_FEATURE_1),
  722. snd_cs4236_ctrl_in(chip, 3),
  723. snd_cs4236_ctrl_in(chip, 4),
  724. snd_cs4236_ctrl_in(chip, 5),
  725. snd_cs4236_ctrl_in(chip, 6),
  726. snd_cs4236_ctrl_in(chip, 8));
  727. #endif
  728. spin_unlock_irqrestore(&chip->reg_lock, flags);
  729. return 0;
  730. }
  731. static int snd_cs4236_put_iec958_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  732. {
  733. struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
  734. unsigned long flags;
  735. int change;
  736. unsigned short enable, val;
  737. enable = ucontrol->value.integer.value[0] & 1;
  738. down(&chip->mce_mutex);
  739. snd_cs4231_mce_up(chip);
  740. spin_lock_irqsave(&chip->reg_lock, flags);
  741. val = (chip->image[CS4231_ALT_FEATURE_1] & ~0x0e) | (0<<2) | (enable << 1);
  742. change = val != chip->image[CS4231_ALT_FEATURE_1];
  743. snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, val);
  744. val = snd_cs4236_ctrl_in(chip, 4) | 0xc0;
  745. snd_cs4236_ctrl_out(chip, 4, val);
  746. udelay(100);
  747. val &= ~0x40;
  748. snd_cs4236_ctrl_out(chip, 4, val);
  749. spin_unlock_irqrestore(&chip->reg_lock, flags);
  750. snd_cs4231_mce_down(chip);
  751. up(&chip->mce_mutex);
  752. #if 0
  753. printk("set valid: ALT = 0x%x, C3 = 0x%x, C4 = 0x%x, C5 = 0x%x, C6 = 0x%x, C8 = 0x%x\n",
  754. snd_cs4231_in(chip, CS4231_ALT_FEATURE_1),
  755. snd_cs4236_ctrl_in(chip, 3),
  756. snd_cs4236_ctrl_in(chip, 4),
  757. snd_cs4236_ctrl_in(chip, 5),
  758. snd_cs4236_ctrl_in(chip, 6),
  759. snd_cs4236_ctrl_in(chip, 8));
  760. #endif
  761. return change;
  762. }
  763. static struct snd_kcontrol_new snd_cs4236_iec958_controls[] = {
  764. CS4236_IEC958_ENABLE("IEC958 Output Enable", 0),
  765. CS4236_SINGLEC("IEC958 Output Validity", 0, 4, 4, 1, 0),
  766. CS4236_SINGLEC("IEC958 Output User", 0, 4, 5, 1, 0),
  767. CS4236_SINGLEC("IEC958 Output CSBR", 0, 4, 6, 1, 0),
  768. CS4236_SINGLEC("IEC958 Output Channel Status Low", 0, 5, 1, 127, 0),
  769. CS4236_SINGLEC("IEC958 Output Channel Status High", 0, 6, 0, 255, 0)
  770. };
  771. static struct snd_kcontrol_new snd_cs4236_3d_controls_cs4235[] = {
  772. CS4236_SINGLEC("3D Control - Switch", 0, 3, 4, 1, 0),
  773. CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1)
  774. };
  775. static struct snd_kcontrol_new snd_cs4236_3d_controls_cs4237[] = {
  776. CS4236_SINGLEC("3D Control - Switch", 0, 3, 7, 1, 0),
  777. CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1),
  778. CS4236_SINGLEC("3D Control - Center", 0, 2, 0, 15, 1),
  779. CS4236_SINGLEC("3D Control - Mono", 0, 3, 6, 1, 0),
  780. CS4236_SINGLEC("3D Control - IEC958", 0, 3, 5, 1, 0)
  781. };
  782. static struct snd_kcontrol_new snd_cs4236_3d_controls_cs4238[] = {
  783. CS4236_SINGLEC("3D Control - Switch", 0, 3, 4, 1, 0),
  784. CS4236_SINGLEC("3D Control - Space", 0, 2, 4, 15, 1),
  785. CS4236_SINGLEC("3D Control - Volume", 0, 2, 0, 15, 1),
  786. CS4236_SINGLEC("3D Control - IEC958", 0, 3, 5, 1, 0)
  787. };
  788. int snd_cs4236_mixer(struct snd_cs4231 *chip)
  789. {
  790. struct snd_card *card;
  791. unsigned int idx, count;
  792. int err;
  793. struct snd_kcontrol_new *kcontrol;
  794. snd_assert(chip != NULL && chip->card != NULL, return -EINVAL);
  795. card = chip->card;
  796. strcpy(card->mixername, snd_cs4231_chip_id(chip));
  797. if (chip->hardware == CS4231_HW_CS4235 ||
  798. chip->hardware == CS4231_HW_CS4239) {
  799. for (idx = 0; idx < ARRAY_SIZE(snd_cs4235_controls); idx++) {
  800. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4235_controls[idx], chip))) < 0)
  801. return err;
  802. }
  803. } else {
  804. for (idx = 0; idx < ARRAY_SIZE(snd_cs4236_controls); idx++) {
  805. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4236_controls[idx], chip))) < 0)
  806. return err;
  807. }
  808. }
  809. switch (chip->hardware) {
  810. case CS4231_HW_CS4235:
  811. case CS4231_HW_CS4239:
  812. count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4235);
  813. kcontrol = snd_cs4236_3d_controls_cs4235;
  814. break;
  815. case CS4231_HW_CS4237B:
  816. count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4237);
  817. kcontrol = snd_cs4236_3d_controls_cs4237;
  818. break;
  819. case CS4231_HW_CS4238B:
  820. count = ARRAY_SIZE(snd_cs4236_3d_controls_cs4238);
  821. kcontrol = snd_cs4236_3d_controls_cs4238;
  822. break;
  823. default:
  824. count = 0;
  825. kcontrol = NULL;
  826. }
  827. for (idx = 0; idx < count; idx++, kcontrol++) {
  828. if ((err = snd_ctl_add(card, snd_ctl_new1(kcontrol, chip))) < 0)
  829. return err;
  830. }
  831. if (chip->hardware == CS4231_HW_CS4237B ||
  832. chip->hardware == CS4231_HW_CS4238B) {
  833. for (idx = 0; idx < ARRAY_SIZE(snd_cs4236_iec958_controls); idx++) {
  834. if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4236_iec958_controls[idx], chip))) < 0)
  835. return err;
  836. }
  837. }
  838. return 0;
  839. }
  840. EXPORT_SYMBOL(snd_cs4236_create);
  841. EXPORT_SYMBOL(snd_cs4236_pcm);
  842. EXPORT_SYMBOL(snd_cs4236_mixer);
  843. /*
  844. * INIT part
  845. */
  846. static int __init alsa_cs4236_init(void)
  847. {
  848. return 0;
  849. }
  850. static void __exit alsa_cs4236_exit(void)
  851. {
  852. }
  853. module_init(alsa_cs4236_init)
  854. module_exit(alsa_cs4236_exit)