vx222_ops.c 34 KB

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