1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <linux/delay.h>
24#include <linux/device.h>
25#include <linux/firmware.h>
26#include <linux/mutex.h>
27#include <linux/io.h>
28
29#include <sound/core.h>
30#include <sound/control.h>
31#include <sound/tlv.h>
32#include "vx222.h"
33
34
35static int vx2_reg_offset[VX_REG_MAX] = {
36 [VX_ICR] = 0x00,
37 [VX_CVR] = 0x04,
38 [VX_ISR] = 0x08,
39 [VX_IVR] = 0x0c,
40 [VX_RXH] = 0x14,
41 [VX_RXM] = 0x18,
42 [VX_RXL] = 0x1c,
43 [VX_DMA] = 0x10,
44 [VX_CDSP] = 0x20,
45 [VX_CFG] = 0x24,
46 [VX_RUER] = 0x28,
47 [VX_DATA] = 0x2c,
48 [VX_STATUS] = 0x30,
49 [VX_LOFREQ] = 0x34,
50 [VX_HIFREQ] = 0x38,
51 [VX_CSUER] = 0x3c,
52 [VX_SELMIC] = 0x40,
53 [VX_COMPOT] = 0x44,
54 [VX_SCOMPR] = 0x48,
55 [VX_GLIMIT] = 0x4c,
56 [VX_INTCSR] = 0x4c,
57 [VX_CNTRL] = 0x50,
58 [VX_GPIOC] = 0x54,
59};
60
61static int vx2_reg_index[VX_REG_MAX] = {
62 [VX_ICR] = 1,
63 [VX_CVR] = 1,
64 [VX_ISR] = 1,
65 [VX_IVR] = 1,
66 [VX_RXH] = 1,
67 [VX_RXM] = 1,
68 [VX_RXL] = 1,
69 [VX_DMA] = 1,
70 [VX_CDSP] = 1,
71 [VX_CFG] = 1,
72 [VX_RUER] = 1,
73 [VX_DATA] = 1,
74 [VX_STATUS] = 1,
75 [VX_LOFREQ] = 1,
76 [VX_HIFREQ] = 1,
77 [VX_CSUER] = 1,
78 [VX_SELMIC] = 1,
79 [VX_COMPOT] = 1,
80 [VX_SCOMPR] = 1,
81 [VX_GLIMIT] = 1,
82 [VX_INTCSR] = 0,
83 [VX_CNTRL] = 0,
84 [VX_GPIOC] = 0,
85};
86
87static inline unsigned long vx2_reg_addr(struct vx_core *_chip, int reg)
88{
89 struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
90 return chip->port[vx2_reg_index[reg]] + vx2_reg_offset[reg];
91}
92
93
94
95
96
97
98static unsigned char vx2_inb(struct vx_core *chip, int offset)
99{
100 return inb(vx2_reg_addr(chip, offset));
101}
102
103
104
105
106
107
108
109static void vx2_outb(struct vx_core *chip, int offset, unsigned char val)
110{
111 outb(val, vx2_reg_addr(chip, offset));
112
113
114
115}
116
117
118
119
120
121
122static unsigned int vx2_inl(struct vx_core *chip, int offset)
123{
124 return inl(vx2_reg_addr(chip, offset));
125}
126
127
128
129
130
131
132
133static void vx2_outl(struct vx_core *chip, int offset, unsigned int val)
134{
135
136
137
138 outl(val, vx2_reg_addr(chip, offset));
139}
140
141
142
143
144#undef vx_inb
145#define vx_inb(chip,reg) vx2_inb((struct vx_core*)(chip), VX_##reg)
146#undef vx_outb
147#define vx_outb(chip,reg,val) vx2_outb((struct vx_core*)(chip), VX_##reg, val)
148#undef vx_inl
149#define vx_inl(chip,reg) vx2_inl((struct vx_core*)(chip), VX_##reg)
150#undef vx_outl
151#define vx_outl(chip,reg,val) vx2_outl((struct vx_core*)(chip), VX_##reg, val)
152
153
154
155
156
157
158#define XX_DSP_RESET_WAIT_TIME 2
159
160static void vx2_reset_dsp(struct vx_core *_chip)
161{
162 struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
163
164
165 vx_outl(chip, CDSP, chip->regCDSP & ~VX_CDSP_DSP_RESET_MASK);
166
167 mdelay(XX_DSP_RESET_WAIT_TIME);
168
169 chip->regCDSP |= VX_CDSP_DSP_RESET_MASK;
170
171 vx_outl(chip, CDSP, chip->regCDSP);
172}
173
174
175static int vx2_test_xilinx(struct vx_core *_chip)
176{
177 struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
178 unsigned int data;
179
180 dev_dbg(_chip->card->dev, "testing xilinx...\n");
181
182
183
184
185
186 vx_outl(chip, CDSP, chip->regCDSP | VX_CDSP_TEST0_MASK);
187 vx_inl(chip, ISR);
188 data = vx_inl(chip, STATUS);
189 if ((data & VX_STATUS_VAL_TEST0_MASK) == VX_STATUS_VAL_TEST0_MASK) {
190 dev_dbg(_chip->card->dev, "bad!\n");
191 return -ENODEV;
192 }
193
194
195 vx_outl(chip, CDSP, chip->regCDSP & ~VX_CDSP_TEST0_MASK);
196 vx_inl(chip, ISR);
197 data = vx_inl(chip, STATUS);
198 if (! (data & VX_STATUS_VAL_TEST0_MASK)) {
199 dev_dbg(_chip->card->dev, "bad! #2\n");
200 return -ENODEV;
201 }
202
203 if (_chip->type == VX_TYPE_BOARD) {
204
205
206 vx_outl(chip, CDSP, chip->regCDSP | VX_CDSP_TEST1_MASK);
207 vx_inl(chip, ISR);
208 data = vx_inl(chip, STATUS);
209 if ((data & VX_STATUS_VAL_TEST1_MASK) == VX_STATUS_VAL_TEST1_MASK) {
210 dev_dbg(_chip->card->dev, "bad! #3\n");
211 return -ENODEV;
212 }
213
214
215 vx_outl(chip, CDSP, chip->regCDSP & ~VX_CDSP_TEST1_MASK);
216 vx_inl(chip, ISR);
217 data = vx_inl(chip, STATUS);
218 if (! (data & VX_STATUS_VAL_TEST1_MASK)) {
219 dev_dbg(_chip->card->dev, "bad! #4\n");
220 return -ENODEV;
221 }
222 }
223 dev_dbg(_chip->card->dev, "ok, xilinx fine.\n");
224 return 0;
225}
226
227
228
229
230
231
232
233static void vx2_setup_pseudo_dma(struct vx_core *chip, int do_write)
234{
235
236
237
238 vx_outl(chip, ICR, do_write ? ICR_TREQ : ICR_RREQ);
239
240
241
242
243 vx_outl(chip, RESET_DMA, 0);
244}
245
246
247
248
249static inline void vx2_release_pseudo_dma(struct vx_core *chip)
250{
251
252 vx_outl(chip, ICR, 0);
253}
254
255
256
257
258static void vx2_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime,
259 struct vx_pipe *pipe, int count)
260{
261 unsigned long port = vx2_reg_addr(chip, VX_DMA);
262 int offset = pipe->hw_ptr;
263 u32 *addr = (u32 *)(runtime->dma_area + offset);
264
265 if (snd_BUG_ON(count % 4))
266 return;
267
268 vx2_setup_pseudo_dma(chip, 1);
269
270
271
272 if (offset + count > pipe->buffer_bytes) {
273 int length = pipe->buffer_bytes - offset;
274 count -= length;
275 length >>= 2;
276
277 while (length-- > 0) {
278 outl(cpu_to_le32(*addr), port);
279 addr++;
280 }
281 addr = (u32 *)runtime->dma_area;
282 pipe->hw_ptr = 0;
283 }
284 pipe->hw_ptr += count;
285 count >>= 2;
286
287 while (count-- > 0) {
288 outl(cpu_to_le32(*addr), port);
289 addr++;
290 }
291
292 vx2_release_pseudo_dma(chip);
293}
294
295
296
297static void vx2_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime,
298 struct vx_pipe *pipe, int count)
299{
300 int offset = pipe->hw_ptr;
301 u32 *addr = (u32 *)(runtime->dma_area + offset);
302 unsigned long port = vx2_reg_addr(chip, VX_DMA);
303
304 if (snd_BUG_ON(count % 4))
305 return;
306
307 vx2_setup_pseudo_dma(chip, 0);
308
309
310 if (offset + count > pipe->buffer_bytes) {
311 int length = pipe->buffer_bytes - offset;
312 count -= length;
313 length >>= 2;
314
315 while (length-- > 0)
316 *addr++ = le32_to_cpu(inl(port));
317 addr = (u32 *)runtime->dma_area;
318 pipe->hw_ptr = 0;
319 }
320 pipe->hw_ptr += count;
321 count >>= 2;
322
323 while (count-- > 0)
324 *addr++ = le32_to_cpu(inl(port));
325
326 vx2_release_pseudo_dma(chip);
327}
328
329#define VX_XILINX_RESET_MASK 0x40000000
330#define VX_USERBIT0_MASK 0x00000004
331#define VX_USERBIT1_MASK 0x00000020
332#define VX_CNTRL_REGISTER_VALUE 0x00172012
333
334
335
336
337static int put_xilinx_data(struct vx_core *chip, unsigned int port, unsigned int counts, unsigned char data)
338{
339 unsigned int i;
340
341 for (i = 0; i < counts; i++) {
342 unsigned int val;
343
344
345 val = VX_CNTRL_REGISTER_VALUE & ~VX_USERBIT0_MASK;
346 vx2_outl(chip, port, val);
347 vx2_inl(chip, port);
348 udelay(1);
349
350 if (data & (1 << i))
351 val |= VX_USERBIT1_MASK;
352 else
353 val &= ~VX_USERBIT1_MASK;
354 vx2_outl(chip, port, val);
355 vx2_inl(chip, port);
356
357
358 val |= VX_USERBIT0_MASK;
359 vx2_outl(chip, port, val);
360 vx2_inl(chip, port);
361 udelay(1);
362 }
363 return 0;
364}
365
366
367
368
369static int vx2_load_xilinx_binary(struct vx_core *chip, const struct firmware *xilinx)
370{
371 unsigned int i;
372 unsigned int port;
373 const unsigned char *image;
374
375
376 vx_outl(chip, CNTRL, VX_CNTRL_REGISTER_VALUE | VX_XILINX_RESET_MASK);
377 vx_inl(chip, CNTRL);
378 msleep(10);
379 vx_outl(chip, CNTRL, VX_CNTRL_REGISTER_VALUE);
380 vx_inl(chip, CNTRL);
381 msleep(10);
382
383 if (chip->type == VX_TYPE_BOARD)
384 port = VX_CNTRL;
385 else
386 port = VX_GPIOC;
387
388 image = xilinx->data;
389 for (i = 0; i < xilinx->size; i++, image++) {
390 if (put_xilinx_data(chip, port, 8, *image) < 0)
391 return -EINVAL;
392
393 cond_resched();
394 }
395 put_xilinx_data(chip, port, 4, 0xff);
396
397 msleep(200);
398
399
400 if (chip->type != VX_TYPE_BOARD) {
401
402 i = vx_inl(chip, GPIOC);
403 if (i & 0x0100)
404 return 0;
405 dev_err(chip->card->dev,
406 "xilinx test failed after load, GPIOC=0x%x\n", i);
407 return -EINVAL;
408 }
409
410 return 0;
411}
412
413
414
415
416
417static int vx2_load_dsp(struct vx_core *vx, int index, const struct firmware *dsp)
418{
419 int err;
420
421 switch (index) {
422 case 1:
423
424 if ((err = vx2_load_xilinx_binary(vx, dsp)) < 0)
425 return err;
426 if ((err = vx2_test_xilinx(vx)) < 0)
427 return err;
428 return 0;
429 case 2:
430
431 return snd_vx_dsp_boot(vx, dsp);
432 case 3:
433
434 return snd_vx_dsp_load(vx, dsp);
435 default:
436 snd_BUG();
437 return -EINVAL;
438 }
439}
440
441
442
443
444
445
446
447
448
449static int vx2_test_and_ack(struct vx_core *chip)
450{
451
452 if (! (chip->chip_status & VX_STAT_XILINX_LOADED))
453 return -ENXIO;
454
455 if (! (vx_inl(chip, STATUS) & VX_STATUS_MEMIRQ_MASK))
456 return -EIO;
457
458
459
460 vx_outl(chip, STATUS, 0);
461
462
463
464 vx_inl(chip, STATUS);
465
466 vx_outl(chip, STATUS, VX_STATUS_MEMIRQ_MASK);
467
468
469 vx_inl(chip, STATUS);
470
471 vx_outl(chip, STATUS, 0);
472
473 return 0;
474}
475
476
477
478
479
480static void vx2_validate_irq(struct vx_core *_chip, int enable)
481{
482 struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
483
484
485 if (enable) {
486
487 vx_outl(chip, INTCSR, VX_INTCSR_VALUE|VX_PCI_INTERRUPT_MASK);
488 chip->regCDSP |= VX_CDSP_VALID_IRQ_MASK;
489 } else {
490
491 vx_outl(chip, INTCSR, VX_INTCSR_VALUE&~VX_PCI_INTERRUPT_MASK);
492 chip->regCDSP &= ~VX_CDSP_VALID_IRQ_MASK;
493 }
494 vx_outl(chip, CDSP, chip->regCDSP);
495}
496
497
498
499
500
501static void vx2_write_codec_reg(struct vx_core *chip, unsigned int data)
502{
503 unsigned int i;
504
505 vx_inl(chip, HIFREQ);
506
507
508 for (i = 0; i < 24; i++, data <<= 1)
509 vx_outl(chip, DATA, ((data & 0x800000) ? VX_DATA_CODEC_MASK : 0));
510
511 vx_inl(chip, RUER);
512}
513
514
515#define AKM_CODEC_POWER_CONTROL_CMD 0xA007
516#define AKM_CODEC_RESET_ON_CMD 0xA100
517#define AKM_CODEC_RESET_OFF_CMD 0xA103
518#define AKM_CODEC_CLOCK_FORMAT_CMD 0xA240
519#define AKM_CODEC_MUTE_CMD 0xA38D
520#define AKM_CODEC_UNMUTE_CMD 0xA30D
521#define AKM_CODEC_LEFT_LEVEL_CMD 0xA400
522#define AKM_CODEC_RIGHT_LEVEL_CMD 0xA500
523
524static const u8 vx2_akm_gains_lut[VX2_AKM_LEVEL_MAX+1] = {
525 0x7f,
526 0x7d,
527 0x7c,
528 0x7a,
529 0x79,
530 0x77,
531 0x76,
532 0x75,
533 0x73,
534 0x72,
535 0x71,
536 0x70,
537 0x6f,
538 0x6d,
539 0x6c,
540 0x6a,
541 0x69,
542 0x67,
543 0x66,
544 0x65,
545 0x64,
546 0x62,
547 0x61,
548 0x60,
549 0x5f,
550 0x5e,
551 0x5c,
552 0x5b,
553 0x59,
554 0x58,
555 0x56,
556 0x55,
557 0x54,
558 0x53,
559 0x52,
560 0x51,
561 0x50,
562 0x4e,
563 0x4d,
564 0x4b,
565 0x4a,
566 0x48,
567 0x47,
568 0x46,
569 0x44,
570 0x43,
571 0x42,
572 0x41,
573 0x40,
574 0x3f,
575 0x3e,
576 0x3c,
577 0x3b,
578 0x39,
579 0x38,
580 0x37,
581 0x36,
582 0x34,
583 0x33,
584 0x32,
585 0x31,
586 0x31,
587 0x30,
588 0x2e,
589 0x2d,
590 0x2b,
591 0x2a,
592 0x29,
593 0x28,
594 0x27,
595 0x25,
596 0x24,
597 0x24,
598 0x23,
599 0x22,
600 0x21,
601 0x20,
602 0x1f,
603 0x1e,
604 0x1d,
605 0x1c,
606 0x1b,
607 0x1a,
608 0x19,
609 0x18,
610 0x17,
611 0x16,
612 0x15,
613 0x14,
614 0x14,
615 0x13,
616 0x12,
617 0x12,
618 0x11,
619 0x11,
620 0x10,
621 0x10,
622 0x0f,
623 0x0e,
624 0x0d,
625 0x0d,
626 0x0c,
627 0x0b,
628 0x0b,
629 0x0a,
630 0x0a,
631 0x09,
632 0x09,
633 0x08,
634 0x08,
635 0x07,
636 0x07,
637 0x06,
638 0x06,
639 0x06,
640 0x05,
641 0x05,
642 0x05,
643 0x05,
644 0x04,
645 0x04,
646 0x04,
647 0x04,
648 0x03,
649 0x03,
650 0x03,
651 0x03,
652 0x03,
653 0x03,
654 0x02,
655 0x02,
656 0x02,
657 0x02,
658 0x02,
659 0x02,
660 0x02,
661 0x02,
662 0x02,
663 0x02,
664 0x01,
665 0x01,
666 0x01,
667 0x01,
668 0x01,
669 0x01,
670 0x01,
671 0x01,
672 0x00};
673
674
675
676
677static void vx2_write_akm(struct vx_core *chip, int reg, unsigned int data)
678{
679 unsigned int val;
680
681 if (reg == XX_CODEC_DAC_CONTROL_REGISTER) {
682 vx2_write_codec_reg(chip, data ? AKM_CODEC_MUTE_CMD : AKM_CODEC_UNMUTE_CMD);
683 return;
684 }
685
686
687
688
689
690 if (snd_BUG_ON(data >= sizeof(vx2_akm_gains_lut)))
691 return;
692
693 switch (reg) {
694 case XX_CODEC_LEVEL_LEFT_REGISTER:
695 val = AKM_CODEC_LEFT_LEVEL_CMD;
696 break;
697 case XX_CODEC_LEVEL_RIGHT_REGISTER:
698 val = AKM_CODEC_RIGHT_LEVEL_CMD;
699 break;
700 default:
701 snd_BUG();
702 return;
703 }
704 val |= vx2_akm_gains_lut[data];
705
706 vx2_write_codec_reg(chip, val);
707}
708
709
710
711
712
713static void vx2_old_write_codec_bit(struct vx_core *chip, int codec, unsigned int data)
714{
715 int i;
716
717
718 vx_inl(chip, HIFREQ);
719
720 for (i = 0; i < 24; i++, data <<= 1)
721 vx_outl(chip, DATA, ((data & 0x800000) ? VX_DATA_CODEC_MASK : 0));
722
723
724 vx_inl(chip, RUER);
725}
726
727
728
729
730
731static void vx2_reset_codec(struct vx_core *_chip)
732{
733 struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
734
735
736 vx_outl(chip, CDSP, chip->regCDSP &~ VX_CDSP_CODEC_RESET_MASK);
737 vx_inl(chip, CDSP);
738 msleep(10);
739
740 chip->regCDSP |= VX_CDSP_CODEC_RESET_MASK;
741 vx_outl(chip, CDSP, chip->regCDSP);
742 vx_inl(chip, CDSP);
743 if (_chip->type == VX_TYPE_BOARD) {
744 msleep(1);
745 return;
746 }
747
748 msleep(5);
749
750 vx2_write_codec_reg(_chip, AKM_CODEC_POWER_CONTROL_CMD);
751
752 vx2_write_codec_reg(_chip, AKM_CODEC_CLOCK_FORMAT_CMD);
753 vx2_write_codec_reg(_chip, AKM_CODEC_MUTE_CMD);
754 vx2_write_codec_reg(_chip, AKM_CODEC_RESET_OFF_CMD);
755
756 if (_chip->type == VX_TYPE_MIC) {
757
758 chip->regSELMIC = MICRO_SELECT_INPUT_NORM |
759 MICRO_SELECT_PREAMPLI_G_0 |
760 MICRO_SELECT_NOISE_T_52DB;
761
762
763 chip->regSELMIC &= ~MICRO_SELECT_PHANTOM_ALIM;
764
765 vx_outl(_chip, SELMIC, chip->regSELMIC);
766 }
767}
768
769
770
771
772
773static void vx2_change_audio_source(struct vx_core *_chip, int src)
774{
775 struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
776
777 switch (src) {
778 case VX_AUDIO_SRC_DIGITAL:
779 chip->regCFG |= VX_CFG_DATAIN_SEL_MASK;
780 break;
781 default:
782 chip->regCFG &= ~VX_CFG_DATAIN_SEL_MASK;
783 break;
784 }
785 vx_outl(chip, CFG, chip->regCFG);
786}
787
788
789
790
791
792static void vx2_set_clock_source(struct vx_core *_chip, int source)
793{
794 struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
795
796 if (source == INTERNAL_QUARTZ)
797 chip->regCFG &= ~VX_CFG_CLOCKIN_SEL_MASK;
798 else
799 chip->regCFG |= VX_CFG_CLOCKIN_SEL_MASK;
800 vx_outl(chip, CFG, chip->regCFG);
801}
802
803
804
805
806static void vx2_reset_board(struct vx_core *_chip, int cold_reset)
807{
808 struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
809
810
811 chip->regCDSP = VX_CDSP_CODEC_RESET_MASK | VX_CDSP_DSP_RESET_MASK ;
812 chip->regCFG = 0;
813}
814
815
816
817
818
819
820
821
822
823
824
825#define V2_MICRO_LEVEL_RANGE (318 - 255)
826
827static void vx2_set_input_level(struct snd_vx222 *chip)
828{
829 int i, miclevel, preamp;
830 unsigned int data;
831
832 miclevel = chip->mic_level;
833 miclevel += V2_MICRO_LEVEL_RANGE;
834 preamp = 0;
835 while (miclevel > 210) {
836 preamp++;
837 miclevel -= (18 * 2);
838 }
839 if (snd_BUG_ON(preamp >= 4))
840 return;
841
842
843 chip->regSELMIC &= ~MICRO_SELECT_PREAMPLI_MASK;
844 chip->regSELMIC |= (preamp << MICRO_SELECT_PREAMPLI_OFFSET) & MICRO_SELECT_PREAMPLI_MASK;
845 vx_outl(chip, SELMIC, chip->regSELMIC);
846
847 data = (unsigned int)miclevel << 16 |
848 (unsigned int)chip->input_level[1] << 8 |
849 (unsigned int)chip->input_level[0];
850 vx_inl(chip, DATA);
851
852
853 for (i = 0; i < 32; i++, data <<= 1)
854 vx_outl(chip, DATA, ((data & 0x80000000) ? VX_DATA_CODEC_MASK : 0));
855
856 vx_inl(chip, RUER);
857}
858
859
860#define MIC_LEVEL_MAX 0xff
861
862static const DECLARE_TLV_DB_SCALE(db_scale_mic, -6450, 50, 0);
863
864
865
866
867
868
869static int vx_input_level_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
870{
871 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
872 uinfo->count = 2;
873 uinfo->value.integer.min = 0;
874 uinfo->value.integer.max = MIC_LEVEL_MAX;
875 return 0;
876}
877
878static int vx_input_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
879{
880 struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
881 struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
882 mutex_lock(&_chip->mixer_mutex);
883 ucontrol->value.integer.value[0] = chip->input_level[0];
884 ucontrol->value.integer.value[1] = chip->input_level[1];
885 mutex_unlock(&_chip->mixer_mutex);
886 return 0;
887}
888
889static int vx_input_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
890{
891 struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
892 struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
893 if (ucontrol->value.integer.value[0] < 0 ||
894 ucontrol->value.integer.value[0] > MIC_LEVEL_MAX)
895 return -EINVAL;
896 if (ucontrol->value.integer.value[1] < 0 ||
897 ucontrol->value.integer.value[1] > MIC_LEVEL_MAX)
898 return -EINVAL;
899 mutex_lock(&_chip->mixer_mutex);
900 if (chip->input_level[0] != ucontrol->value.integer.value[0] ||
901 chip->input_level[1] != ucontrol->value.integer.value[1]) {
902 chip->input_level[0] = ucontrol->value.integer.value[0];
903 chip->input_level[1] = ucontrol->value.integer.value[1];
904 vx2_set_input_level(chip);
905 mutex_unlock(&_chip->mixer_mutex);
906 return 1;
907 }
908 mutex_unlock(&_chip->mixer_mutex);
909 return 0;
910}
911
912
913static int vx_mic_level_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
914{
915 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
916 uinfo->count = 1;
917 uinfo->value.integer.min = 0;
918 uinfo->value.integer.max = MIC_LEVEL_MAX;
919 return 0;
920}
921
922static int vx_mic_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
923{
924 struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
925 struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
926 ucontrol->value.integer.value[0] = chip->mic_level;
927 return 0;
928}
929
930static int vx_mic_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
931{
932 struct vx_core *_chip = snd_kcontrol_chip(kcontrol);
933 struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
934 if (ucontrol->value.integer.value[0] < 0 ||
935 ucontrol->value.integer.value[0] > MIC_LEVEL_MAX)
936 return -EINVAL;
937 mutex_lock(&_chip->mixer_mutex);
938 if (chip->mic_level != ucontrol->value.integer.value[0]) {
939 chip->mic_level = ucontrol->value.integer.value[0];
940 vx2_set_input_level(chip);
941 mutex_unlock(&_chip->mixer_mutex);
942 return 1;
943 }
944 mutex_unlock(&_chip->mixer_mutex);
945 return 0;
946}
947
948static struct snd_kcontrol_new vx_control_input_level = {
949 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
950 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
951 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
952 .name = "Capture Volume",
953 .info = vx_input_level_info,
954 .get = vx_input_level_get,
955 .put = vx_input_level_put,
956 .tlv = { .p = db_scale_mic },
957};
958
959static struct snd_kcontrol_new vx_control_mic_level = {
960 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
961 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
962 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
963 .name = "Mic Capture Volume",
964 .info = vx_mic_level_info,
965 .get = vx_mic_level_get,
966 .put = vx_mic_level_put,
967 .tlv = { .p = db_scale_mic },
968};
969
970
971
972
973
974static int vx2_add_mic_controls(struct vx_core *_chip)
975{
976 struct snd_vx222 *chip = (struct snd_vx222 *)_chip;
977 int err;
978
979 if (_chip->type != VX_TYPE_MIC)
980 return 0;
981
982
983 chip->input_level[0] = chip->input_level[1] = 0;
984 chip->mic_level = 0;
985 vx2_set_input_level(chip);
986
987
988 if ((err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_input_level, chip))) < 0)
989 return err;
990 if ((err = snd_ctl_add(_chip->card, snd_ctl_new1(&vx_control_mic_level, chip))) < 0)
991 return err;
992
993 return 0;
994}
995
996
997
998
999
1000struct snd_vx_ops vx222_ops = {
1001 .in8 = vx2_inb,
1002 .in32 = vx2_inl,
1003 .out8 = vx2_outb,
1004 .out32 = vx2_outl,
1005 .test_and_ack = vx2_test_and_ack,
1006 .validate_irq = vx2_validate_irq,
1007 .akm_write = vx2_write_akm,
1008 .reset_codec = vx2_reset_codec,
1009 .change_audio_source = vx2_change_audio_source,
1010 .set_clock_source = vx2_set_clock_source,
1011 .load_dsp = vx2_load_dsp,
1012 .reset_dsp = vx2_reset_dsp,
1013 .reset_board = vx2_reset_board,
1014 .dma_write = vx2_dma_write,
1015 .dma_read = vx2_dma_read,
1016 .add_controls = vx2_add_mic_controls,
1017};
1018
1019
1020struct snd_vx_ops vx222_old_ops = {
1021 .in8 = vx2_inb,
1022 .in32 = vx2_inl,
1023 .out8 = vx2_outb,
1024 .out32 = vx2_outl,
1025 .test_and_ack = vx2_test_and_ack,
1026 .validate_irq = vx2_validate_irq,
1027 .write_codec = vx2_old_write_codec_bit,
1028 .reset_codec = vx2_reset_codec,
1029 .change_audio_source = vx2_change_audio_source,
1030 .set_clock_source = vx2_set_clock_source,
1031 .load_dsp = vx2_load_dsp,
1032 .reset_dsp = vx2_reset_dsp,
1033 .reset_board = vx2_reset_board,
1034 .dma_write = vx2_dma_write,
1035 .dma_read = vx2_dma_read,
1036};
1037
1038