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