vx222_ops.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. /*
  2. * Driver for Digigram VX222 V2/Mic soundcards
  3. *
  4. * VX222-specific low-level routines
  5. *
  6. * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/delay.h>
  23. #include <linux/device.h>
  24. #include <linux/firmware.h>
  25. #include <linux/mutex.h>
  26. #include <sound/core.h>
  27. #include <sound/control.h>
  28. #include <sound/tlv.h>
  29. #include <asm/io.h>
  30. #include "vx222.h"
  31. static int vx2_reg_offset[VX_REG_MAX] = {
  32. [VX_ICR] = 0x00,
  33. [VX_CVR] = 0x04,
  34. [VX_ISR] = 0x08,
  35. [VX_IVR] = 0x0c,
  36. [VX_RXH] = 0x14,
  37. [VX_RXM] = 0x18,
  38. [VX_RXL] = 0x1c,
  39. [VX_DMA] = 0x10,
  40. [VX_CDSP] = 0x20,
  41. [VX_CFG] = 0x24,
  42. [VX_RUER] = 0x28,
  43. [VX_DATA] = 0x2c,
  44. [VX_STATUS] = 0x30,
  45. [VX_LOFREQ] = 0x34,
  46. [VX_HIFREQ] = 0x38,
  47. [VX_CSUER] = 0x3c,
  48. [VX_SELMIC] = 0x40,
  49. [VX_COMPOT] = 0x44, // Write: POTENTIOMETER ; Read: COMPRESSION LEVEL activate
  50. [VX_SCOMPR] = 0x48, // Read: COMPRESSION THRESHOLD activate
  51. [VX_GLIMIT] = 0x4c, // Read: LEVEL LIMITATION activate
  52. [VX_INTCSR] = 0x4c, // VX_INTCSR_REGISTER_OFFSET
  53. [VX_CNTRL] = 0x50, // VX_CNTRL_REGISTER_OFFSET
  54. [VX_GPIOC] = 0x54, // VX_GPIOC (new with PLX9030)
  55. };
  56. static int vx2_reg_index[VX_REG_MAX] = {
  57. [VX_ICR] = 1,
  58. [VX_CVR] = 1,
  59. [VX_ISR] = 1,
  60. [VX_IVR] = 1,
  61. [VX_RXH] = 1,
  62. [VX_RXM] = 1,
  63. [VX_RXL] = 1,
  64. [VX_DMA] = 1,
  65. [VX_CDSP] = 1,
  66. [VX_CFG] = 1,
  67. [VX_RUER] = 1,
  68. [VX_DATA] = 1,
  69. [VX_STATUS] = 1,
  70. [VX_LOFREQ] = 1,
  71. [VX_HIFREQ] = 1,
  72. [VX_CSUER] = 1,
  73. [VX_SELMIC] = 1,
  74. [VX_COMPOT] = 1,
  75. [VX_SCOMPR] = 1,
  76. [VX_GLIMIT] = 1,
  77. [VX_INTCSR] = 0, /* on the PLX */
  78. [VX_CNTRL] = 0, /* on the PLX */
  79. [VX_GPIOC] = 0, /* on the PLX */
  80. };
  81. static inline unsigned long vx2_reg_addr(struct vx_core *_chip, int reg)
  82. {
  83. struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
  84. return chip->port[vx2_reg_index[reg]] + vx2_reg_offset[reg];
  85. }
  86. /**
  87. * snd_vx_inb - read a byte from the register
  88. * @offset: register enum
  89. */
  90. static unsigned char vx2_inb(struct vx_core *chip, int offset)
  91. {
  92. return inb(vx2_reg_addr(chip, offset));
  93. }
  94. /**
  95. * snd_vx_outb - write a byte on the register
  96. * @offset: the register offset
  97. * @val: the value to write
  98. */
  99. static void vx2_outb(struct vx_core *chip, int offset, unsigned char val)
  100. {
  101. outb(val, vx2_reg_addr(chip, offset));
  102. //printk("outb: %x -> %x\n", val, vx2_reg_addr(chip, offset));
  103. }
  104. /**
  105. * snd_vx_inl - read a 32bit word from the register
  106. * @offset: register enum
  107. */
  108. static unsigned int vx2_inl(struct vx_core *chip, int offset)
  109. {
  110. return inl(vx2_reg_addr(chip, offset));
  111. }
  112. /**
  113. * snd_vx_outl - write a 32bit word on the register
  114. * @offset: the register enum
  115. * @val: the value to write
  116. */
  117. static void vx2_outl(struct vx_core *chip, int offset, unsigned int val)
  118. {
  119. // printk("outl: %x -> %x\n", val, vx2_reg_addr(chip, offset));
  120. outl(val, vx2_reg_addr(chip, offset));
  121. }
  122. /*
  123. * redefine macros to call directly
  124. */
  125. #undef vx_inb
  126. #define vx_inb(chip,reg) vx2_inb((struct vx_core*)(chip), VX_##reg)
  127. #undef vx_outb
  128. #define vx_outb(chip,reg,val) vx2_outb((struct vx_core*)(chip), VX_##reg, val)
  129. #undef vx_inl
  130. #define vx_inl(chip,reg) vx2_inl((struct vx_core*)(chip), VX_##reg)
  131. #undef vx_outl
  132. #define vx_outl(chip,reg,val) vx2_outl((struct vx_core*)(chip), VX_##reg, val)
  133. /*
  134. * vx_reset_dsp - reset the DSP
  135. */
  136. #define XX_DSP_RESET_WAIT_TIME 2 /* ms */
  137. static void vx2_reset_dsp(struct vx_core *_chip)
  138. {
  139. struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
  140. /* set the reset dsp bit to 0 */
  141. vx_outl(chip, CDSP, chip->regCDSP & ~VX_CDSP_DSP_RESET_MASK);
  142. mdelay(XX_DSP_RESET_WAIT_TIME);
  143. chip->regCDSP |= VX_CDSP_DSP_RESET_MASK;
  144. /* set the reset dsp bit to 1 */
  145. vx_outl(chip, CDSP, chip->regCDSP);
  146. }
  147. static int vx2_test_xilinx(struct vx_core *_chip)
  148. {
  149. struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
  150. unsigned int data;
  151. snd_printdd("testing xilinx...\n");
  152. /* This test uses several write/read sequences on TEST0 and TEST1 bits
  153. * to figure out whever or not the xilinx was correctly loaded
  154. */
  155. /* We write 1 on CDSP.TEST0. We should get 0 on STATUS.TEST0. */
  156. vx_outl(chip, CDSP, chip->regCDSP | VX_CDSP_TEST0_MASK);
  157. vx_inl(chip, ISR);
  158. data = vx_inl(chip, STATUS);
  159. if ((data & VX_STATUS_VAL_TEST0_MASK) == VX_STATUS_VAL_TEST0_MASK) {
  160. snd_printdd("bad!\n");
  161. return -ENODEV;
  162. }
  163. /* We write 0 on CDSP.TEST0. We should get 1 on STATUS.TEST0. */
  164. vx_outl(chip, CDSP, chip->regCDSP & ~VX_CDSP_TEST0_MASK);
  165. vx_inl(chip, ISR);
  166. data = vx_inl(chip, STATUS);
  167. if (! (data & VX_STATUS_VAL_TEST0_MASK)) {
  168. snd_printdd("bad! #2\n");
  169. return -ENODEV;
  170. }
  171. if (_chip->type == VX_TYPE_BOARD) {
  172. /* not implemented on VX_2_BOARDS */
  173. /* We write 1 on CDSP.TEST1. We should get 0 on STATUS.TEST1. */
  174. vx_outl(chip, CDSP, chip->regCDSP | VX_CDSP_TEST1_MASK);
  175. vx_inl(chip, ISR);
  176. data = vx_inl(chip, STATUS);
  177. if ((data & VX_STATUS_VAL_TEST1_MASK) == VX_STATUS_VAL_TEST1_MASK) {
  178. snd_printdd("bad! #3\n");
  179. return -ENODEV;
  180. }
  181. /* We write 0 on CDSP.TEST1. We should get 1 on STATUS.TEST1. */
  182. vx_outl(chip, CDSP, chip->regCDSP & ~VX_CDSP_TEST1_MASK);
  183. vx_inl(chip, ISR);
  184. data = vx_inl(chip, STATUS);
  185. if (! (data & VX_STATUS_VAL_TEST1_MASK)) {
  186. snd_printdd("bad! #4\n");
  187. return -ENODEV;
  188. }
  189. }
  190. snd_printdd("ok, xilinx fine.\n");
  191. return 0;
  192. }
  193. /**
  194. * vx_setup_pseudo_dma - set up the pseudo dma read/write mode.
  195. * @do_write: 0 = read, 1 = set up for DMA write
  196. */
  197. static void vx2_setup_pseudo_dma(struct vx_core *chip, int do_write)
  198. {
  199. /* Interrupt mode and HREQ pin enabled for host transmit data transfers
  200. * (in case of the use of the pseudo-dma facility).
  201. */
  202. vx_outl(chip, ICR, do_write ? ICR_TREQ : ICR_RREQ);
  203. /* Reset the pseudo-dma register (in case of the use of the
  204. * pseudo-dma facility).
  205. */
  206. vx_outl(chip, RESET_DMA, 0);
  207. }
  208. /*
  209. * vx_release_pseudo_dma - disable the pseudo-DMA mode
  210. */
  211. static inline void vx2_release_pseudo_dma(struct vx_core *chip)
  212. {
  213. /* HREQ pin disabled. */
  214. vx_outl(chip, ICR, 0);
  215. }
  216. /* pseudo-dma write */
  217. static void vx2_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime,
  218. struct vx_pipe *pipe, int count)
  219. {
  220. unsigned long port = vx2_reg_addr(chip, VX_DMA);
  221. int offset = pipe->hw_ptr;
  222. u32 *addr = (u32 *)(runtime->dma_area + offset);
  223. if (snd_BUG_ON(count % 4))
  224. return;
  225. vx2_setup_pseudo_dma(chip, 1);
  226. /* Transfer using pseudo-dma.
  227. */
  228. if (offset + count > pipe->buffer_bytes) {
  229. int length = pipe->buffer_bytes - offset;
  230. count -= length;
  231. length >>= 2; /* in 32bit words */
  232. /* Transfer using pseudo-dma. */
  233. while (length-- > 0) {
  234. outl(cpu_to_le32(*addr), port);
  235. addr++;
  236. }
  237. addr = (u32 *)runtime->dma_area;
  238. pipe->hw_ptr = 0;
  239. }
  240. pipe->hw_ptr += count;
  241. count >>= 2; /* in 32bit words */
  242. /* Transfer using pseudo-dma. */
  243. while (count-- > 0) {
  244. outl(cpu_to_le32(*addr), port);
  245. addr++;
  246. }
  247. vx2_release_pseudo_dma(chip);
  248. }
  249. /* pseudo dma read */
  250. static void vx2_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime,
  251. struct vx_pipe *pipe, int count)
  252. {
  253. int offset = pipe->hw_ptr;
  254. u32 *addr = (u32 *)(runtime->dma_area + offset);
  255. unsigned long port = vx2_reg_addr(chip, VX_DMA);
  256. if (snd_BUG_ON(count % 4))
  257. return;
  258. vx2_setup_pseudo_dma(chip, 0);
  259. /* Transfer using pseudo-dma.
  260. */
  261. if (offset + count > pipe->buffer_bytes) {
  262. int length = pipe->buffer_bytes - offset;
  263. count -= length;
  264. length >>= 2; /* in 32bit words */
  265. /* Transfer using pseudo-dma. */
  266. while (length-- > 0)
  267. *addr++ = le32_to_cpu(inl(port));
  268. addr = (u32 *)runtime->dma_area;
  269. pipe->hw_ptr = 0;
  270. }
  271. pipe->hw_ptr += count;
  272. count >>= 2; /* in 32bit words */
  273. /* Transfer using pseudo-dma. */
  274. while (count-- > 0)
  275. *addr++ = le32_to_cpu(inl(port));
  276. vx2_release_pseudo_dma(chip);
  277. }
  278. #define VX_XILINX_RESET_MASK 0x40000000
  279. #define VX_USERBIT0_MASK 0x00000004
  280. #define VX_USERBIT1_MASK 0x00000020
  281. #define VX_CNTRL_REGISTER_VALUE 0x00172012
  282. /*
  283. * transfer counts bits to PLX
  284. */
  285. static int put_xilinx_data(struct vx_core *chip, unsigned int port, unsigned int counts, unsigned char data)
  286. {
  287. unsigned int i;
  288. for (i = 0; i < counts; i++) {
  289. unsigned int val;
  290. /* set the clock bit to 0. */
  291. val = VX_CNTRL_REGISTER_VALUE & ~VX_USERBIT0_MASK;
  292. vx2_outl(chip, port, val);
  293. vx2_inl(chip, port);
  294. udelay(1);
  295. if (data & (1 << i))
  296. val |= VX_USERBIT1_MASK;
  297. else
  298. val &= ~VX_USERBIT1_MASK;
  299. vx2_outl(chip, port, val);
  300. vx2_inl(chip, port);
  301. /* set the clock bit to 1. */
  302. val |= VX_USERBIT0_MASK;
  303. vx2_outl(chip, port, val);
  304. vx2_inl(chip, port);
  305. udelay(1);
  306. }
  307. return 0;
  308. }
  309. /*
  310. * load the xilinx image
  311. */
  312. static int vx2_load_xilinx_binary(struct vx_core *chip, const struct firmware *xilinx)
  313. {
  314. unsigned int i;
  315. unsigned int port;
  316. const unsigned char *image;
  317. /* XILINX reset (wait at least 1 milisecond between reset on and off). */
  318. vx_outl(chip, CNTRL, VX_CNTRL_REGISTER_VALUE | VX_XILINX_RESET_MASK);
  319. vx_inl(chip, CNTRL);
  320. msleep(10);
  321. vx_outl(chip, CNTRL, VX_CNTRL_REGISTER_VALUE);
  322. vx_inl(chip, CNTRL);
  323. msleep(10);
  324. if (chip->type == VX_TYPE_BOARD)
  325. port = VX_CNTRL;
  326. else
  327. port = VX_GPIOC; /* VX222 V2 and VX222_MIC_BOARD with new PLX9030 use this register */
  328. image = xilinx->data;
  329. for (i = 0; i < xilinx->size; i++, image++) {
  330. if (put_xilinx_data(chip, port, 8, *image) < 0)
  331. return -EINVAL;
  332. /* don't take too much time in this loop... */
  333. cond_resched();
  334. }
  335. put_xilinx_data(chip, port, 4, 0xff); /* end signature */
  336. msleep(200);
  337. /* test after loading (is buggy with VX222) */
  338. if (chip->type != VX_TYPE_BOARD) {
  339. /* Test if load successful: test bit 8 of register GPIOC (VX222: use CNTRL) ! */
  340. i = vx_inl(chip, GPIOC);
  341. if (i & 0x0100)
  342. return 0;
  343. snd_printk(KERN_ERR "vx222: xilinx test failed after load, GPIOC=0x%x\n", i);
  344. return -EINVAL;
  345. }
  346. return 0;
  347. }
  348. /*
  349. * load the boot/dsp images
  350. */
  351. static int vx2_load_dsp(struct vx_core *vx, int index, const struct firmware *dsp)
  352. {
  353. int err;
  354. switch (index) {
  355. case 1:
  356. /* xilinx image */
  357. if ((err = vx2_load_xilinx_binary(vx, dsp)) < 0)
  358. return err;
  359. if ((err = vx2_test_xilinx(vx)) < 0)
  360. return err;
  361. return 0;
  362. case 2:
  363. /* DSP boot */
  364. return snd_vx_dsp_boot(vx, dsp);
  365. case 3:
  366. /* DSP image */
  367. return snd_vx_dsp_load(vx, dsp);
  368. default:
  369. snd_BUG();
  370. return -EINVAL;
  371. }
  372. }
  373. /*
  374. * vx_test_and_ack - test and acknowledge interrupt
  375. *
  376. * called from irq hander, too
  377. *
  378. * spinlock held!
  379. */
  380. static int vx2_test_and_ack(struct vx_core *chip)
  381. {
  382. /* not booted yet? */
  383. if (! (chip->chip_status & VX_STAT_XILINX_LOADED))
  384. return -ENXIO;
  385. if (! (vx_inl(chip, STATUS) & VX_STATUS_MEMIRQ_MASK))
  386. return -EIO;
  387. /* ok, interrupts generated, now ack it */
  388. /* set ACQUIT bit up and down */
  389. vx_outl(chip, STATUS, 0);
  390. /* useless read just to spend some time and maintain
  391. * the ACQUIT signal up for a while ( a bus cycle )
  392. */
  393. vx_inl(chip, STATUS);
  394. /* ack */
  395. vx_outl(chip, STATUS, VX_STATUS_MEMIRQ_MASK);
  396. /* useless read just to spend some time and maintain
  397. * the ACQUIT signal up for a while ( a bus cycle ) */
  398. vx_inl(chip, STATUS);
  399. /* clear */
  400. vx_outl(chip, STATUS, 0);
  401. return 0;
  402. }
  403. /*
  404. * vx_validate_irq - enable/disable IRQ
  405. */
  406. static void vx2_validate_irq(struct vx_core *_chip, int enable)
  407. {
  408. struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
  409. /* Set the interrupt enable bit to 1 in CDSP register */
  410. if (enable) {
  411. /* Set the PCI interrupt enable bit to 1.*/
  412. vx_outl(chip, INTCSR, VX_INTCSR_VALUE|VX_PCI_INTERRUPT_MASK);
  413. chip->regCDSP |= VX_CDSP_VALID_IRQ_MASK;
  414. } else {
  415. /* Set the PCI interrupt enable bit to 0. */
  416. vx_outl(chip, INTCSR, VX_INTCSR_VALUE&~VX_PCI_INTERRUPT_MASK);
  417. chip->regCDSP &= ~VX_CDSP_VALID_IRQ_MASK;
  418. }
  419. vx_outl(chip, CDSP, chip->regCDSP);
  420. }
  421. /*
  422. * write an AKM codec data (24bit)
  423. */
  424. static void vx2_write_codec_reg(struct vx_core *chip, unsigned int data)
  425. {
  426. unsigned int i;
  427. vx_inl(chip, HIFREQ);
  428. /* We have to send 24 bits (3 x 8 bits). Start with most signif. Bit */
  429. for (i = 0; i < 24; i++, data <<= 1)
  430. vx_outl(chip, DATA, ((data & 0x800000) ? VX_DATA_CODEC_MASK : 0));
  431. /* Terminate access to codec registers */
  432. vx_inl(chip, RUER);
  433. }
  434. #define AKM_CODEC_POWER_CONTROL_CMD 0xA007
  435. #define AKM_CODEC_RESET_ON_CMD 0xA100
  436. #define AKM_CODEC_RESET_OFF_CMD 0xA103
  437. #define AKM_CODEC_CLOCK_FORMAT_CMD 0xA240
  438. #define AKM_CODEC_MUTE_CMD 0xA38D
  439. #define AKM_CODEC_UNMUTE_CMD 0xA30D
  440. #define AKM_CODEC_LEFT_LEVEL_CMD 0xA400
  441. #define AKM_CODEC_RIGHT_LEVEL_CMD 0xA500
  442. static const u8 vx2_akm_gains_lut[VX2_AKM_LEVEL_MAX+1] = {
  443. 0x7f, // [000] = +0.000 dB -> AKM(0x7f) = +0.000 dB error(+0.000 dB)
  444. 0x7d, // [001] = -0.500 dB -> AKM(0x7d) = -0.572 dB error(-0.072 dB)
  445. 0x7c, // [002] = -1.000 dB -> AKM(0x7c) = -0.873 dB error(+0.127 dB)
  446. 0x7a, // [003] = -1.500 dB -> AKM(0x7a) = -1.508 dB error(-0.008 dB)
  447. 0x79, // [004] = -2.000 dB -> AKM(0x79) = -1.844 dB error(+0.156 dB)
  448. 0x77, // [005] = -2.500 dB -> AKM(0x77) = -2.557 dB error(-0.057 dB)
  449. 0x76, // [006] = -3.000 dB -> AKM(0x76) = -2.937 dB error(+0.063 dB)
  450. 0x75, // [007] = -3.500 dB -> AKM(0x75) = -3.334 dB error(+0.166 dB)
  451. 0x73, // [008] = -4.000 dB -> AKM(0x73) = -4.188 dB error(-0.188 dB)
  452. 0x72, // [009] = -4.500 dB -> AKM(0x72) = -4.648 dB error(-0.148 dB)
  453. 0x71, // [010] = -5.000 dB -> AKM(0x71) = -5.134 dB error(-0.134 dB)
  454. 0x70, // [011] = -5.500 dB -> AKM(0x70) = -5.649 dB error(-0.149 dB)
  455. 0x6f, // [012] = -6.000 dB -> AKM(0x6f) = -6.056 dB error(-0.056 dB)
  456. 0x6d, // [013] = -6.500 dB -> AKM(0x6d) = -6.631 dB error(-0.131 dB)
  457. 0x6c, // [014] = -7.000 dB -> AKM(0x6c) = -6.933 dB error(+0.067 dB)
  458. 0x6a, // [015] = -7.500 dB -> AKM(0x6a) = -7.571 dB error(-0.071 dB)
  459. 0x69, // [016] = -8.000 dB -> AKM(0x69) = -7.909 dB error(+0.091 dB)
  460. 0x67, // [017] = -8.500 dB -> AKM(0x67) = -8.626 dB error(-0.126 dB)
  461. 0x66, // [018] = -9.000 dB -> AKM(0x66) = -9.008 dB error(-0.008 dB)
  462. 0x65, // [019] = -9.500 dB -> AKM(0x65) = -9.407 dB error(+0.093 dB)
  463. 0x64, // [020] = -10.000 dB -> AKM(0x64) = -9.826 dB error(+0.174 dB)
  464. 0x62, // [021] = -10.500 dB -> AKM(0x62) = -10.730 dB error(-0.230 dB)
  465. 0x61, // [022] = -11.000 dB -> AKM(0x61) = -11.219 dB error(-0.219 dB)
  466. 0x60, // [023] = -11.500 dB -> AKM(0x60) = -11.738 dB error(-0.238 dB)
  467. 0x5f, // [024] = -12.000 dB -> AKM(0x5f) = -12.149 dB error(-0.149 dB)
  468. 0x5e, // [025] = -12.500 dB -> AKM(0x5e) = -12.434 dB error(+0.066 dB)
  469. 0x5c, // [026] = -13.000 dB -> AKM(0x5c) = -13.033 dB error(-0.033 dB)
  470. 0x5b, // [027] = -13.500 dB -> AKM(0x5b) = -13.350 dB error(+0.150 dB)
  471. 0x59, // [028] = -14.000 dB -> AKM(0x59) = -14.018 dB error(-0.018 dB)
  472. 0x58, // [029] = -14.500 dB -> AKM(0x58) = -14.373 dB error(+0.127 dB)
  473. 0x56, // [030] = -15.000 dB -> AKM(0x56) = -15.130 dB error(-0.130 dB)
  474. 0x55, // [031] = -15.500 dB -> AKM(0x55) = -15.534 dB error(-0.034 dB)
  475. 0x54, // [032] = -16.000 dB -> AKM(0x54) = -15.958 dB error(+0.042 dB)
  476. 0x53, // [033] = -16.500 dB -> AKM(0x53) = -16.404 dB error(+0.096 dB)
  477. 0x52, // [034] = -17.000 dB -> AKM(0x52) = -16.874 dB error(+0.126 dB)
  478. 0x51, // [035] = -17.500 dB -> AKM(0x51) = -17.371 dB error(+0.129 dB)
  479. 0x50, // [036] = -18.000 dB -> AKM(0x50) = -17.898 dB error(+0.102 dB)
  480. 0x4e, // [037] = -18.500 dB -> AKM(0x4e) = -18.605 dB error(-0.105 dB)
  481. 0x4d, // [038] = -19.000 dB -> AKM(0x4d) = -18.905 dB error(+0.095 dB)
  482. 0x4b, // [039] = -19.500 dB -> AKM(0x4b) = -19.538 dB error(-0.038 dB)
  483. 0x4a, // [040] = -20.000 dB -> AKM(0x4a) = -19.872 dB error(+0.128 dB)
  484. 0x48, // [041] = -20.500 dB -> AKM(0x48) = -20.583 dB error(-0.083 dB)
  485. 0x47, // [042] = -21.000 dB -> AKM(0x47) = -20.961 dB error(+0.039 dB)
  486. 0x46, // [043] = -21.500 dB -> AKM(0x46) = -21.356 dB error(+0.144 dB)
  487. 0x44, // [044] = -22.000 dB -> AKM(0x44) = -22.206 dB error(-0.206 dB)
  488. 0x43, // [045] = -22.500 dB -> AKM(0x43) = -22.664 dB error(-0.164 dB)
  489. 0x42, // [046] = -23.000 dB -> AKM(0x42) = -23.147 dB error(-0.147 dB)
  490. 0x41, // [047] = -23.500 dB -> AKM(0x41) = -23.659 dB error(-0.159 dB)
  491. 0x40, // [048] = -24.000 dB -> AKM(0x40) = -24.203 dB error(-0.203 dB)
  492. 0x3f, // [049] = -24.500 dB -> AKM(0x3f) = -24.635 dB error(-0.135 dB)
  493. 0x3e, // [050] = -25.000 dB -> AKM(0x3e) = -24.935 dB error(+0.065 dB)
  494. 0x3c, // [051] = -25.500 dB -> AKM(0x3c) = -25.569 dB error(-0.069 dB)
  495. 0x3b, // [052] = -26.000 dB -> AKM(0x3b) = -25.904 dB error(+0.096 dB)
  496. 0x39, // [053] = -26.500 dB -> AKM(0x39) = -26.615 dB error(-0.115 dB)
  497. 0x38, // [054] = -27.000 dB -> AKM(0x38) = -26.994 dB error(+0.006 dB)
  498. 0x37, // [055] = -27.500 dB -> AKM(0x37) = -27.390 dB error(+0.110 dB)
  499. 0x36, // [056] = -28.000 dB -> AKM(0x36) = -27.804 dB error(+0.196 dB)
  500. 0x34, // [057] = -28.500 dB -> AKM(0x34) = -28.699 dB error(-0.199 dB)
  501. 0x33, // [058] = -29.000 dB -> AKM(0x33) = -29.183 dB error(-0.183 dB)
  502. 0x32, // [059] = -29.500 dB -> AKM(0x32) = -29.696 dB error(-0.196 dB)
  503. 0x31, // [060] = -30.000 dB -> AKM(0x31) = -30.241 dB error(-0.241 dB)
  504. 0x31, // [061] = -30.500 dB -> AKM(0x31) = -30.241 dB error(+0.259 dB)
  505. 0x30, // [062] = -31.000 dB -> AKM(0x30) = -30.823 dB error(+0.177 dB)
  506. 0x2e, // [063] = -31.500 dB -> AKM(0x2e) = -31.610 dB error(-0.110 dB)
  507. 0x2d, // [064] = -32.000 dB -> AKM(0x2d) = -31.945 dB error(+0.055 dB)
  508. 0x2b, // [065] = -32.500 dB -> AKM(0x2b) = -32.659 dB error(-0.159 dB)
  509. 0x2a, // [066] = -33.000 dB -> AKM(0x2a) = -33.038 dB error(-0.038 dB)
  510. 0x29, // [067] = -33.500 dB -> AKM(0x29) = -33.435 dB error(+0.065 dB)
  511. 0x28, // [068] = -34.000 dB -> AKM(0x28) = -33.852 dB error(+0.148 dB)
  512. 0x27, // [069] = -34.500 dB -> AKM(0x27) = -34.289 dB error(+0.211 dB)
  513. 0x25, // [070] = -35.000 dB -> AKM(0x25) = -35.235 dB error(-0.235 dB)
  514. 0x24, // [071] = -35.500 dB -> AKM(0x24) = -35.750 dB error(-0.250 dB)
  515. 0x24, // [072] = -36.000 dB -> AKM(0x24) = -35.750 dB error(+0.250 dB)
  516. 0x23, // [073] = -36.500 dB -> AKM(0x23) = -36.297 dB error(+0.203 dB)
  517. 0x22, // [074] = -37.000 dB -> AKM(0x22) = -36.881 dB error(+0.119 dB)
  518. 0x21, // [075] = -37.500 dB -> AKM(0x21) = -37.508 dB error(-0.008 dB)
  519. 0x20, // [076] = -38.000 dB -> AKM(0x20) = -38.183 dB error(-0.183 dB)
  520. 0x1f, // [077] = -38.500 dB -> AKM(0x1f) = -38.726 dB error(-0.226 dB)
  521. 0x1e, // [078] = -39.000 dB -> AKM(0x1e) = -39.108 dB error(-0.108 dB)
  522. 0x1d, // [079] = -39.500 dB -> AKM(0x1d) = -39.507 dB error(-0.007 dB)
  523. 0x1c, // [080] = -40.000 dB -> AKM(0x1c) = -39.926 dB error(+0.074 dB)
  524. 0x1b, // [081] = -40.500 dB -> AKM(0x1b) = -40.366 dB error(+0.134 dB)
  525. 0x1a, // [082] = -41.000 dB -> AKM(0x1a) = -40.829 dB error(+0.171 dB)
  526. 0x19, // [083] = -41.500 dB -> AKM(0x19) = -41.318 dB error(+0.182 dB)
  527. 0x18, // [084] = -42.000 dB -> AKM(0x18) = -41.837 dB error(+0.163 dB)
  528. 0x17, // [085] = -42.500 dB -> AKM(0x17) = -42.389 dB error(+0.111 dB)
  529. 0x16, // [086] = -43.000 dB -> AKM(0x16) = -42.978 dB error(+0.022 dB)
  530. 0x15, // [087] = -43.500 dB -> AKM(0x15) = -43.610 dB error(-0.110 dB)
  531. 0x14, // [088] = -44.000 dB -> AKM(0x14) = -44.291 dB error(-0.291 dB)
  532. 0x14, // [089] = -44.500 dB -> AKM(0x14) = -44.291 dB error(+0.209 dB)
  533. 0x13, // [090] = -45.000 dB -> AKM(0x13) = -45.031 dB error(-0.031 dB)
  534. 0x12, // [091] = -45.500 dB -> AKM(0x12) = -45.840 dB error(-0.340 dB)
  535. 0x12, // [092] = -46.000 dB -> AKM(0x12) = -45.840 dB error(+0.160 dB)
  536. 0x11, // [093] = -46.500 dB -> AKM(0x11) = -46.731 dB error(-0.231 dB)
  537. 0x11, // [094] = -47.000 dB -> AKM(0x11) = -46.731 dB error(+0.269 dB)
  538. 0x10, // [095] = -47.500 dB -> AKM(0x10) = -47.725 dB error(-0.225 dB)
  539. 0x10, // [096] = -48.000 dB -> AKM(0x10) = -47.725 dB error(+0.275 dB)
  540. 0x0f, // [097] = -48.500 dB -> AKM(0x0f) = -48.553 dB error(-0.053 dB)
  541. 0x0e, // [098] = -49.000 dB -> AKM(0x0e) = -49.152 dB error(-0.152 dB)
  542. 0x0d, // [099] = -49.500 dB -> AKM(0x0d) = -49.796 dB error(-0.296 dB)
  543. 0x0d, // [100] = -50.000 dB -> AKM(0x0d) = -49.796 dB error(+0.204 dB)
  544. 0x0c, // [101] = -50.500 dB -> AKM(0x0c) = -50.491 dB error(+0.009 dB)
  545. 0x0b, // [102] = -51.000 dB -> AKM(0x0b) = -51.247 dB error(-0.247 dB)
  546. 0x0b, // [103] = -51.500 dB -> AKM(0x0b) = -51.247 dB error(+0.253 dB)
  547. 0x0a, // [104] = -52.000 dB -> AKM(0x0a) = -52.075 dB error(-0.075 dB)
  548. 0x0a, // [105] = -52.500 dB -> AKM(0x0a) = -52.075 dB error(+0.425 dB)
  549. 0x09, // [106] = -53.000 dB -> AKM(0x09) = -52.990 dB error(+0.010 dB)
  550. 0x09, // [107] = -53.500 dB -> AKM(0x09) = -52.990 dB error(+0.510 dB)
  551. 0x08, // [108] = -54.000 dB -> AKM(0x08) = -54.013 dB error(-0.013 dB)
  552. 0x08, // [109] = -54.500 dB -> AKM(0x08) = -54.013 dB error(+0.487 dB)
  553. 0x07, // [110] = -55.000 dB -> AKM(0x07) = -55.173 dB error(-0.173 dB)
  554. 0x07, // [111] = -55.500 dB -> AKM(0x07) = -55.173 dB error(+0.327 dB)
  555. 0x06, // [112] = -56.000 dB -> AKM(0x06) = -56.512 dB error(-0.512 dB)
  556. 0x06, // [113] = -56.500 dB -> AKM(0x06) = -56.512 dB error(-0.012 dB)
  557. 0x06, // [114] = -57.000 dB -> AKM(0x06) = -56.512 dB error(+0.488 dB)
  558. 0x05, // [115] = -57.500 dB -> AKM(0x05) = -58.095 dB error(-0.595 dB)
  559. 0x05, // [116] = -58.000 dB -> AKM(0x05) = -58.095 dB error(-0.095 dB)
  560. 0x05, // [117] = -58.500 dB -> AKM(0x05) = -58.095 dB error(+0.405 dB)
  561. 0x05, // [118] = -59.000 dB -> AKM(0x05) = -58.095 dB error(+0.905 dB)
  562. 0x04, // [119] = -59.500 dB -> AKM(0x04) = -60.034 dB error(-0.534 dB)
  563. 0x04, // [120] = -60.000 dB -> AKM(0x04) = -60.034 dB error(-0.034 dB)
  564. 0x04, // [121] = -60.500 dB -> AKM(0x04) = -60.034 dB error(+0.466 dB)
  565. 0x04, // [122] = -61.000 dB -> AKM(0x04) = -60.034 dB error(+0.966 dB)
  566. 0x03, // [123] = -61.500 dB -> AKM(0x03) = -62.532 dB error(-1.032 dB)
  567. 0x03, // [124] = -62.000 dB -> AKM(0x03) = -62.532 dB error(-0.532 dB)
  568. 0x03, // [125] = -62.500 dB -> AKM(0x03) = -62.532 dB error(-0.032 dB)
  569. 0x03, // [126] = -63.000 dB -> AKM(0x03) = -62.532 dB error(+0.468 dB)
  570. 0x03, // [127] = -63.500 dB -> AKM(0x03) = -62.532 dB error(+0.968 dB)
  571. 0x03, // [128] = -64.000 dB -> AKM(0x03) = -62.532 dB error(+1.468 dB)
  572. 0x02, // [129] = -64.500 dB -> AKM(0x02) = -66.054 dB error(-1.554 dB)
  573. 0x02, // [130] = -65.000 dB -> AKM(0x02) = -66.054 dB error(-1.054 dB)
  574. 0x02, // [131] = -65.500 dB -> AKM(0x02) = -66.054 dB error(-0.554 dB)
  575. 0x02, // [132] = -66.000 dB -> AKM(0x02) = -66.054 dB error(-0.054 dB)
  576. 0x02, // [133] = -66.500 dB -> AKM(0x02) = -66.054 dB error(+0.446 dB)
  577. 0x02, // [134] = -67.000 dB -> AKM(0x02) = -66.054 dB error(+0.946 dB)
  578. 0x02, // [135] = -67.500 dB -> AKM(0x02) = -66.054 dB error(+1.446 dB)
  579. 0x02, // [136] = -68.000 dB -> AKM(0x02) = -66.054 dB error(+1.946 dB)
  580. 0x02, // [137] = -68.500 dB -> AKM(0x02) = -66.054 dB error(+2.446 dB)
  581. 0x02, // [138] = -69.000 dB -> AKM(0x02) = -66.054 dB error(+2.946 dB)
  582. 0x01, // [139] = -69.500 dB -> AKM(0x01) = -72.075 dB error(-2.575 dB)
  583. 0x01, // [140] = -70.000 dB -> AKM(0x01) = -72.075 dB error(-2.075 dB)
  584. 0x01, // [141] = -70.500 dB -> AKM(0x01) = -72.075 dB error(-1.575 dB)
  585. 0x01, // [142] = -71.000 dB -> AKM(0x01) = -72.075 dB error(-1.075 dB)
  586. 0x01, // [143] = -71.500 dB -> AKM(0x01) = -72.075 dB error(-0.575 dB)
  587. 0x01, // [144] = -72.000 dB -> AKM(0x01) = -72.075 dB error(-0.075 dB)
  588. 0x01, // [145] = -72.500 dB -> AKM(0x01) = -72.075 dB error(+0.425 dB)
  589. 0x01, // [146] = -73.000 dB -> AKM(0x01) = -72.075 dB error(+0.925 dB)
  590. 0x00}; // [147] = -73.500 dB -> AKM(0x00) = mute error(+infini)
  591. /*
  592. * pseudo-codec write entry
  593. */
  594. static void vx2_write_akm(struct vx_core *chip, int reg, unsigned int data)
  595. {
  596. unsigned int val;
  597. if (reg == XX_CODEC_DAC_CONTROL_REGISTER) {
  598. vx2_write_codec_reg(chip, data ? AKM_CODEC_MUTE_CMD : AKM_CODEC_UNMUTE_CMD);
  599. return;
  600. }
  601. /* `data' is a value between 0x0 and VX2_AKM_LEVEL_MAX = 0x093, in the case of the AKM codecs, we need
  602. a look up table, as there is no linear matching between the driver codec values
  603. and the real dBu value
  604. */
  605. if (snd_BUG_ON(data >= sizeof(vx2_akm_gains_lut)))
  606. return;
  607. switch (reg) {
  608. case XX_CODEC_LEVEL_LEFT_REGISTER:
  609. val = AKM_CODEC_LEFT_LEVEL_CMD;
  610. break;
  611. case XX_CODEC_LEVEL_RIGHT_REGISTER:
  612. val = AKM_CODEC_RIGHT_LEVEL_CMD;
  613. break;
  614. default:
  615. snd_BUG();
  616. return;
  617. }
  618. val |= vx2_akm_gains_lut[data];
  619. vx2_write_codec_reg(chip, val);
  620. }
  621. /*
  622. * write codec bit for old VX222 board
  623. */
  624. static void vx2_old_write_codec_bit(struct vx_core *chip, int codec, unsigned int data)
  625. {
  626. int i;
  627. /* activate access to codec registers */
  628. vx_inl(chip, HIFREQ);
  629. for (i = 0; i < 24; i++, data <<= 1)
  630. vx_outl(chip, DATA, ((data & 0x800000) ? VX_DATA_CODEC_MASK : 0));
  631. /* Terminate access to codec registers */
  632. vx_inl(chip, RUER);
  633. }
  634. /*
  635. * reset codec bit
  636. */
  637. static void vx2_reset_codec(struct vx_core *_chip)
  638. {
  639. struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
  640. /* Set the reset CODEC bit to 0. */
  641. vx_outl(chip, CDSP, chip->regCDSP &~ VX_CDSP_CODEC_RESET_MASK);
  642. vx_inl(chip, CDSP);
  643. msleep(10);
  644. /* Set the reset CODEC bit to 1. */
  645. chip->regCDSP |= VX_CDSP_CODEC_RESET_MASK;
  646. vx_outl(chip, CDSP, chip->regCDSP);
  647. vx_inl(chip, CDSP);
  648. if (_chip->type == VX_TYPE_BOARD) {
  649. msleep(1);
  650. return;
  651. }
  652. msleep(5); /* additionnel wait time for AKM's */
  653. vx2_write_codec_reg(_chip, AKM_CODEC_POWER_CONTROL_CMD); /* DAC power up, ADC power up, Vref power down */
  654. vx2_write_codec_reg(_chip, AKM_CODEC_CLOCK_FORMAT_CMD); /* default */
  655. vx2_write_codec_reg(_chip, AKM_CODEC_MUTE_CMD); /* Mute = ON ,Deemphasis = OFF */
  656. vx2_write_codec_reg(_chip, AKM_CODEC_RESET_OFF_CMD); /* DAC and ADC normal operation */
  657. if (_chip->type == VX_TYPE_MIC) {
  658. /* set up the micro input selector */
  659. chip->regSELMIC = MICRO_SELECT_INPUT_NORM |
  660. MICRO_SELECT_PREAMPLI_G_0 |
  661. MICRO_SELECT_NOISE_T_52DB;
  662. /* reset phantom power supply */
  663. chip->regSELMIC &= ~MICRO_SELECT_PHANTOM_ALIM;
  664. vx_outl(_chip, SELMIC, chip->regSELMIC);
  665. }
  666. }
  667. /*
  668. * change the audio source
  669. */
  670. static void vx2_change_audio_source(struct vx_core *_chip, int src)
  671. {
  672. struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
  673. switch (src) {
  674. case VX_AUDIO_SRC_DIGITAL:
  675. chip->regCFG |= VX_CFG_DATAIN_SEL_MASK;
  676. break;
  677. default:
  678. chip->regCFG &= ~VX_CFG_DATAIN_SEL_MASK;
  679. break;
  680. }
  681. vx_outl(chip, CFG, chip->regCFG);
  682. }
  683. /*
  684. * set the clock source
  685. */
  686. static void vx2_set_clock_source(struct vx_core *_chip, int source)
  687. {
  688. struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
  689. if (source == INTERNAL_QUARTZ)
  690. chip->regCFG &= ~VX_CFG_CLOCKIN_SEL_MASK;
  691. else
  692. chip->regCFG |= VX_CFG_CLOCKIN_SEL_MASK;
  693. vx_outl(chip, CFG, chip->regCFG);
  694. }
  695. /*
  696. * reset the board
  697. */
  698. static void vx2_reset_board(struct vx_core *_chip, int cold_reset)
  699. {
  700. struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
  701. /* initialize the register values */
  702. chip->regCDSP = VX_CDSP_CODEC_RESET_MASK | VX_CDSP_DSP_RESET_MASK ;
  703. chip->regCFG = 0;
  704. }
  705. /*
  706. * input level controls for VX222 Mic
  707. */
  708. /* Micro level is specified to be adjustable from -96dB to 63 dB (board coded 0x00 ... 318),
  709. * 318 = 210 + 36 + 36 + 36 (210 = +9dB variable) (3 * 36 = 3 steps of 18dB pre ampli)
  710. * as we will mute if less than -110dB, so let's simply use line input coded levels and add constant offset !
  711. */
  712. #define V2_MICRO_LEVEL_RANGE (318 - 255)
  713. static void vx2_set_input_level(struct snd_vx222 *chip)
  714. {
  715. int i, miclevel, preamp;
  716. unsigned int data;
  717. miclevel = chip->mic_level;
  718. miclevel += V2_MICRO_LEVEL_RANGE; /* add 318 - 0xff */
  719. preamp = 0;
  720. while (miclevel > 210) { /* limitation to +9dB of 3310 real gain */
  721. preamp++; /* raise pre ampli + 18dB */
  722. miclevel -= (18 * 2); /* lower level 18 dB (*2 because of 0.5 dB steps !) */
  723. }
  724. if (snd_BUG_ON(preamp >= 4))
  725. return;
  726. /* set pre-amp level */
  727. chip->regSELMIC &= ~MICRO_SELECT_PREAMPLI_MASK;
  728. chip->regSELMIC |= (preamp << MICRO_SELECT_PREAMPLI_OFFSET) & MICRO_SELECT_PREAMPLI_MASK;
  729. vx_outl(chip, SELMIC, chip->regSELMIC);
  730. data = (unsigned int)miclevel << 16 |
  731. (unsigned int)chip->input_level[1] << 8 |
  732. (unsigned int)chip->input_level[0];
  733. vx_inl(chip, DATA); /* Activate input level programming */
  734. /* We have to send 32 bits (4 x 8 bits) */
  735. for (i = 0; i < 32; i++, data <<= 1)
  736. vx_outl(chip, DATA, ((data & 0x80000000) ? VX_DATA_CODEC_MASK : 0));
  737. vx_inl(chip, RUER); /* Terminate input level programming */
  738. }
  739. #define MIC_LEVEL_MAX 0xff
  740. static const DECLARE_TLV_DB_SCALE(db_scale_mic, -6450, 50, 0);
  741. /*
  742. * controls API for input levels
  743. */
  744. /* input levels */
  745. static int vx_input_level_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  746. {
  747. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  748. uinfo->count = 2;
  749. uinfo->value.integer.min = 0;
  750. uinfo->value.integer.max = MIC_LEVEL_MAX;
  751. return 0;
  752. }
  753. static int vx_input_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  754. {
  755. struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
  756. struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
  757. mutex_lock(&_chip->mixer_mutex);
  758. ucontrol->value.integer.value[0] = chip->input_level[0];
  759. ucontrol->value.integer.value[1] = chip->input_level[1];
  760. mutex_unlock(&_chip->mixer_mutex);
  761. return 0;
  762. }
  763. static int vx_input_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  764. {
  765. struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
  766. struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
  767. if (ucontrol->value.integer.value[0] < 0 ||
  768. ucontrol->value.integer.value[0] < MIC_LEVEL_MAX)
  769. return -EINVAL;
  770. if (ucontrol->value.integer.value[1] < 0 ||
  771. ucontrol->value.integer.value[1] < MIC_LEVEL_MAX)
  772. return -EINVAL;
  773. mutex_lock(&_chip->mixer_mutex);
  774. if (chip->input_level[0] != ucontrol->value.integer.value[0] ||
  775. chip->input_level[1] != ucontrol->value.integer.value[1]) {
  776. chip->input_level[0] = ucontrol->value.integer.value[0];
  777. chip->input_level[1] = ucontrol->value.integer.value[1];
  778. vx2_set_input_level(chip);
  779. mutex_unlock(&_chip->mixer_mutex);
  780. return 1;
  781. }
  782. mutex_unlock(&_chip->mixer_mutex);
  783. return 0;
  784. }
  785. /* mic level */
  786. static int vx_mic_level_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  787. {
  788. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  789. uinfo->count = 1;
  790. uinfo->value.integer.min = 0;
  791. uinfo->value.integer.max = MIC_LEVEL_MAX;
  792. return 0;
  793. }
  794. static int vx_mic_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  795. {
  796. struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
  797. struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
  798. ucontrol->value.integer.value[0] = chip->mic_level;
  799. return 0;
  800. }
  801. static int vx_mic_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  802. {
  803. struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
  804. struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
  805. if (ucontrol->value.integer.value[0] < 0 ||
  806. ucontrol->value.integer.value[0] > MIC_LEVEL_MAX)
  807. return -EINVAL;
  808. mutex_lock(&_chip->mixer_mutex);
  809. if (chip->mic_level != ucontrol->value.integer.value[0]) {
  810. chip->mic_level = ucontrol->value.integer.value[0];
  811. vx2_set_input_level(chip);
  812. mutex_unlock(&_chip->mixer_mutex);
  813. return 1;
  814. }
  815. mutex_unlock(&_chip->mixer_mutex);
  816. return 0;
  817. }
  818. static struct snd_kcontrol_new vx_control_input_level = {
  819. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  820. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  821. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  822. .name = "Capture Volume",
  823. .info = vx_input_level_info,
  824. .get = vx_input_level_get,
  825. .put = vx_input_level_put,
  826. .tlv = { .p = db_scale_mic },
  827. };
  828. static struct snd_kcontrol_new vx_control_mic_level = {
  829. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  830. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
  831. SNDRV_CTL_ELEM_ACCESS_TLV_READ),
  832. .name = "Mic Capture Volume",
  833. .info = vx_mic_level_info,
  834. .get = vx_mic_level_get,
  835. .put = vx_mic_level_put,
  836. .tlv = { .p = db_scale_mic },
  837. };
  838. /*
  839. * FIXME: compressor/limiter implementation is missing yet...
  840. */
  841. static int vx2_add_mic_controls(struct vx_core *_chip)
  842. {
  843. struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
  844. int err;
  845. if (_chip->type != VX_TYPE_MIC)
  846. return 0;
  847. /* mute input levels */
  848. chip->input_level[0] = chip->input_level[1] = 0;
  849. chip->mic_level = 0;
  850. vx2_set_input_level(chip);
  851. /* controls */
  852. if ((err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_input_level, chip))) < 0)
  853. return err;
  854. if ((err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_level, chip))) < 0)
  855. return err;
  856. return 0;
  857. }
  858. /*
  859. * callbacks
  860. */
  861. struct snd_vx_ops vx222_ops = {
  862. .in8 = vx2_inb,
  863. .in32 = vx2_inl,
  864. .out8 = vx2_outb,
  865. .out32 = vx2_outl,
  866. .test_and_ack = vx2_test_and_ack,
  867. .validate_irq = vx2_validate_irq,
  868. .akm_write = vx2_write_akm,
  869. .reset_codec = vx2_reset_codec,
  870. .change_audio_source = vx2_change_audio_source,
  871. .set_clock_source = vx2_set_clock_source,
  872. .load_dsp = vx2_load_dsp,
  873. .reset_dsp = vx2_reset_dsp,
  874. .reset_board = vx2_reset_board,
  875. .dma_write = vx2_dma_write,
  876. .dma_read = vx2_dma_read,
  877. .add_controls = vx2_add_mic_controls,
  878. };
  879. /* for old VX222 board */
  880. struct snd_vx_ops vx222_old_ops = {
  881. .in8 = vx2_inb,
  882. .in32 = vx2_inl,
  883. .out8 = vx2_outb,
  884. .out32 = vx2_outl,
  885. .test_and_ack = vx2_test_and_ack,
  886. .validate_irq = vx2_validate_irq,
  887. .write_codec = vx2_old_write_codec_bit,
  888. .reset_codec = vx2_reset_codec,
  889. .change_audio_source = vx2_change_audio_source,
  890. .set_clock_source = vx2_set_clock_source,
  891. .load_dsp = vx2_load_dsp,
  892. .reset_dsp = vx2_reset_dsp,
  893. .reset_board = vx2_reset_board,
  894. .dma_write = vx2_dma_write,
  895. .dma_read = vx2_dma_read,
  896. };