vx222_ops.c 35 KB

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