forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sonicvibes.c
1513 lines (1341 loc) · 51.2 KB
/
sonicvibes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Driver for S3 SonicVibes soundcard
* Copyright (c) by Jaroslav Kysela <[email protected]>
*
* BUGS:
* It looks like 86c617 rev 3 doesn't supports DDMA buffers above 16MB?
* Driver sometimes hangs... Nobody knows why at this moment...
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/gameport.h>
#include <linux/moduleparam.h>
#include <linux/dma-mapping.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/info.h>
#include <sound/control.h>
#include <sound/mpu401.h>
#include <sound/opl3.h>
#include <sound/initval.h>
#include <asm/io.h>
MODULE_AUTHOR("Jaroslav Kysela <[email protected]>");
MODULE_DESCRIPTION("S3 SonicVibes PCI");
MODULE_LICENSE("GPL");
MODULE_SUPPORTED_DEVICE("{{S3,SonicVibes PCI}}");
#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
#define SUPPORT_JOYSTICK 1
#endif
static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
static int reverb[SNDRV_CARDS];
static int mge[SNDRV_CARDS];
static unsigned int dmaio = 0x7a00; /* DDMA i/o address */
module_param_array(index, int, NULL, 0444);
MODULE_PARM_DESC(index, "Index value for S3 SonicVibes soundcard.");
module_param_array(id, charp, NULL, 0444);
MODULE_PARM_DESC(id, "ID string for S3 SonicVibes soundcard.");
module_param_array(enable, bool, NULL, 0444);
MODULE_PARM_DESC(enable, "Enable S3 SonicVibes soundcard.");
module_param_array(reverb, bool, NULL, 0444);
MODULE_PARM_DESC(reverb, "Enable reverb (SRAM is present) for S3 SonicVibes soundcard.");
module_param_array(mge, bool, NULL, 0444);
MODULE_PARM_DESC(mge, "MIC Gain Enable for S3 SonicVibes soundcard.");
module_param(dmaio, uint, 0444);
MODULE_PARM_DESC(dmaio, "DDMA i/o base address for S3 SonicVibes soundcard.");
/*
* Enhanced port direct registers
*/
#define SV_REG(sonic, x) ((sonic)->enh_port + SV_REG_##x)
#define SV_REG_CONTROL 0x00 /* R/W: CODEC/Mixer control register */
#define SV_ENHANCED 0x01 /* audio mode select - enhanced mode */
#define SV_TEST 0x02 /* test bit */
#define SV_REVERB 0x04 /* reverb enable */
#define SV_WAVETABLE 0x08 /* wavetable active / FM active if not set */
#define SV_INTA 0x20 /* INTA driving - should be always 1 */
#define SV_RESET 0x80 /* reset chip */
#define SV_REG_IRQMASK 0x01 /* R/W: CODEC/Mixer interrupt mask register */
#define SV_DMAA_MASK 0x01 /* mask DMA-A interrupt */
#define SV_DMAC_MASK 0x04 /* mask DMA-C interrupt */
#define SV_SPEC_MASK 0x08 /* special interrupt mask - should be always masked */
#define SV_UD_MASK 0x40 /* Up/Down button interrupt mask */
#define SV_MIDI_MASK 0x80 /* mask MIDI interrupt */
#define SV_REG_STATUS 0x02 /* R/O: CODEC/Mixer status register */
#define SV_DMAA_IRQ 0x01 /* DMA-A interrupt */
#define SV_DMAC_IRQ 0x04 /* DMA-C interrupt */
#define SV_SPEC_IRQ 0x08 /* special interrupt */
#define SV_UD_IRQ 0x40 /* Up/Down interrupt */
#define SV_MIDI_IRQ 0x80 /* MIDI interrupt */
#define SV_REG_INDEX 0x04 /* R/W: CODEC/Mixer index address register */
#define SV_MCE 0x40 /* mode change enable */
#define SV_TRD 0x80 /* DMA transfer request disabled */
#define SV_REG_DATA 0x05 /* R/W: CODEC/Mixer index data register */
/*
* Enhanced port indirect registers
*/
#define SV_IREG_LEFT_ADC 0x00 /* Left ADC Input Control */
#define SV_IREG_RIGHT_ADC 0x01 /* Right ADC Input Control */
#define SV_IREG_LEFT_AUX1 0x02 /* Left AUX1 Input Control */
#define SV_IREG_RIGHT_AUX1 0x03 /* Right AUX1 Input Control */
#define SV_IREG_LEFT_CD 0x04 /* Left CD Input Control */
#define SV_IREG_RIGHT_CD 0x05 /* Right CD Input Control */
#define SV_IREG_LEFT_LINE 0x06 /* Left Line Input Control */
#define SV_IREG_RIGHT_LINE 0x07 /* Right Line Input Control */
#define SV_IREG_MIC 0x08 /* MIC Input Control */
#define SV_IREG_GAME_PORT 0x09 /* Game Port Control */
#define SV_IREG_LEFT_SYNTH 0x0a /* Left Synth Input Control */
#define SV_IREG_RIGHT_SYNTH 0x0b /* Right Synth Input Control */
#define SV_IREG_LEFT_AUX2 0x0c /* Left AUX2 Input Control */
#define SV_IREG_RIGHT_AUX2 0x0d /* Right AUX2 Input Control */
#define SV_IREG_LEFT_ANALOG 0x0e /* Left Analog Mixer Output Control */
#define SV_IREG_RIGHT_ANALOG 0x0f /* Right Analog Mixer Output Control */
#define SV_IREG_LEFT_PCM 0x10 /* Left PCM Input Control */
#define SV_IREG_RIGHT_PCM 0x11 /* Right PCM Input Control */
#define SV_IREG_DMA_DATA_FMT 0x12 /* DMA Data Format */
#define SV_IREG_PC_ENABLE 0x13 /* Playback/Capture Enable Register */
#define SV_IREG_UD_BUTTON 0x14 /* Up/Down Button Register */
#define SV_IREG_REVISION 0x15 /* Revision */
#define SV_IREG_ADC_OUTPUT_CTRL 0x16 /* ADC Output Control */
#define SV_IREG_DMA_A_UPPER 0x18 /* DMA A Upper Base Count */
#define SV_IREG_DMA_A_LOWER 0x19 /* DMA A Lower Base Count */
#define SV_IREG_DMA_C_UPPER 0x1c /* DMA C Upper Base Count */
#define SV_IREG_DMA_C_LOWER 0x1d /* DMA C Lower Base Count */
#define SV_IREG_PCM_RATE_LOW 0x1e /* PCM Sampling Rate Low Byte */
#define SV_IREG_PCM_RATE_HIGH 0x1f /* PCM Sampling Rate High Byte */
#define SV_IREG_SYNTH_RATE_LOW 0x20 /* Synthesizer Sampling Rate Low Byte */
#define SV_IREG_SYNTH_RATE_HIGH 0x21 /* Synthesizer Sampling Rate High Byte */
#define SV_IREG_ADC_CLOCK 0x22 /* ADC Clock Source Selection */
#define SV_IREG_ADC_ALT_RATE 0x23 /* ADC Alternative Sampling Rate Selection */
#define SV_IREG_ADC_PLL_M 0x24 /* ADC PLL M Register */
#define SV_IREG_ADC_PLL_N 0x25 /* ADC PLL N Register */
#define SV_IREG_SYNTH_PLL_M 0x26 /* Synthesizer PLL M Register */
#define SV_IREG_SYNTH_PLL_N 0x27 /* Synthesizer PLL N Register */
#define SV_IREG_MPU401 0x2a /* MPU-401 UART Operation */
#define SV_IREG_DRIVE_CTRL 0x2b /* Drive Control */
#define SV_IREG_SRS_SPACE 0x2c /* SRS Space Control */
#define SV_IREG_SRS_CENTER 0x2d /* SRS Center Control */
#define SV_IREG_WAVE_SOURCE 0x2e /* Wavetable Sample Source Select */
#define SV_IREG_ANALOG_POWER 0x30 /* Analog Power Down Control */
#define SV_IREG_DIGITAL_POWER 0x31 /* Digital Power Down Control */
#define SV_IREG_ADC_PLL SV_IREG_ADC_PLL_M
#define SV_IREG_SYNTH_PLL SV_IREG_SYNTH_PLL_M
/*
* DMA registers
*/
#define SV_DMA_ADDR0 0x00
#define SV_DMA_ADDR1 0x01
#define SV_DMA_ADDR2 0x02
#define SV_DMA_ADDR3 0x03
#define SV_DMA_COUNT0 0x04
#define SV_DMA_COUNT1 0x05
#define SV_DMA_COUNT2 0x06
#define SV_DMA_MODE 0x0b
#define SV_DMA_RESET 0x0d
#define SV_DMA_MASK 0x0f
/*
* Record sources
*/
#define SV_RECSRC_RESERVED (0x00<<5)
#define SV_RECSRC_CD (0x01<<5)
#define SV_RECSRC_DAC (0x02<<5)
#define SV_RECSRC_AUX2 (0x03<<5)
#define SV_RECSRC_LINE (0x04<<5)
#define SV_RECSRC_AUX1 (0x05<<5)
#define SV_RECSRC_MIC (0x06<<5)
#define SV_RECSRC_OUT (0x07<<5)
/*
* constants
*/
#define SV_FULLRATE 48000
#define SV_REFFREQUENCY 24576000
#define SV_ADCMULT 512
#define SV_MODE_PLAY 1
#define SV_MODE_CAPTURE 2
/*
*/
struct sonicvibes {
unsigned long dma1size;
unsigned long dma2size;
int irq;
unsigned long sb_port;
unsigned long enh_port;
unsigned long synth_port;
unsigned long midi_port;
unsigned long game_port;
unsigned int dmaa_port;
struct resource *res_dmaa;
unsigned int dmac_port;
struct resource *res_dmac;
unsigned char enable;
unsigned char irqmask;
unsigned char revision;
unsigned char format;
unsigned char srs_space;
unsigned char srs_center;
unsigned char mpu_switch;
unsigned char wave_source;
unsigned int mode;
struct pci_dev *pci;
struct snd_card *card;
struct snd_pcm *pcm;
struct snd_pcm_substream *playback_substream;
struct snd_pcm_substream *capture_substream;
struct snd_rawmidi *rmidi;
struct snd_hwdep *fmsynth; /* S3FM */
spinlock_t reg_lock;
unsigned int p_dma_size;
unsigned int c_dma_size;
struct snd_kcontrol *master_mute;
struct snd_kcontrol *master_volume;
#ifdef SUPPORT_JOYSTICK
struct gameport *gameport;
#endif
};
static struct pci_device_id snd_sonic_ids[] = {
{ 0x5333, 0xca00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
{ 0, }
};
MODULE_DEVICE_TABLE(pci, snd_sonic_ids);
static struct snd_ratden sonicvibes_adc_clock = {
.num_min = 4000 * 65536,
.num_max = 48000UL * 65536,
.num_step = 1,
.den = 65536,
};
static struct snd_pcm_hw_constraint_ratdens snd_sonicvibes_hw_constraints_adc_clock = {
.nrats = 1,
.rats = &sonicvibes_adc_clock,
};
/*
* common I/O routines
*/
static inline void snd_sonicvibes_setdmaa(struct sonicvibes * sonic,
unsigned int addr,
unsigned int count)
{
count--;
outl(addr, sonic->dmaa_port + SV_DMA_ADDR0);
outl(count, sonic->dmaa_port + SV_DMA_COUNT0);
outb(0x18, sonic->dmaa_port + SV_DMA_MODE);
#if 0
printk("program dmaa: addr = 0x%x, paddr = 0x%x\n", addr, inl(sonic->dmaa_port + SV_DMA_ADDR0));
#endif
}
static inline void snd_sonicvibes_setdmac(struct sonicvibes * sonic,
unsigned int addr,
unsigned int count)
{
/* note: dmac is working in word mode!!! */
count >>= 1;
count--;
outl(addr, sonic->dmac_port + SV_DMA_ADDR0);
outl(count, sonic->dmac_port + SV_DMA_COUNT0);
outb(0x14, sonic->dmac_port + SV_DMA_MODE);
#if 0
printk("program dmac: addr = 0x%x, paddr = 0x%x\n", addr, inl(sonic->dmac_port + SV_DMA_ADDR0));
#endif
}
static inline unsigned int snd_sonicvibes_getdmaa(struct sonicvibes * sonic)
{
return (inl(sonic->dmaa_port + SV_DMA_COUNT0) & 0xffffff) + 1;
}
static inline unsigned int snd_sonicvibes_getdmac(struct sonicvibes * sonic)
{
/* note: dmac is working in word mode!!! */
return ((inl(sonic->dmac_port + SV_DMA_COUNT0) & 0xffffff) + 1) << 1;
}
static void snd_sonicvibes_out1(struct sonicvibes * sonic,
unsigned char reg,
unsigned char value)
{
outb(reg, SV_REG(sonic, INDEX));
udelay(10);
outb(value, SV_REG(sonic, DATA));
udelay(10);
}
static void snd_sonicvibes_out(struct sonicvibes * sonic,
unsigned char reg,
unsigned char value)
{
unsigned long flags;
spin_lock_irqsave(&sonic->reg_lock, flags);
outb(reg, SV_REG(sonic, INDEX));
udelay(10);
outb(value, SV_REG(sonic, DATA));
udelay(10);
spin_unlock_irqrestore(&sonic->reg_lock, flags);
}
static unsigned char snd_sonicvibes_in1(struct sonicvibes * sonic, unsigned char reg)
{
unsigned char value;
outb(reg, SV_REG(sonic, INDEX));
udelay(10);
value = inb(SV_REG(sonic, DATA));
udelay(10);
return value;
}
static unsigned char snd_sonicvibes_in(struct sonicvibes * sonic, unsigned char reg)
{
unsigned long flags;
unsigned char value;
spin_lock_irqsave(&sonic->reg_lock, flags);
outb(reg, SV_REG(sonic, INDEX));
udelay(10);
value = inb(SV_REG(sonic, DATA));
udelay(10);
spin_unlock_irqrestore(&sonic->reg_lock, flags);
return value;
}
#if 0
static void snd_sonicvibes_debug(struct sonicvibes * sonic)
{
printk("SV REGS: INDEX = 0x%02x ", inb(SV_REG(sonic, INDEX)));
printk(" STATUS = 0x%02x\n", inb(SV_REG(sonic, STATUS)));
printk(" 0x00: left input = 0x%02x ", snd_sonicvibes_in(sonic, 0x00));
printk(" 0x20: synth rate low = 0x%02x\n", snd_sonicvibes_in(sonic, 0x20));
printk(" 0x01: right input = 0x%02x ", snd_sonicvibes_in(sonic, 0x01));
printk(" 0x21: synth rate high = 0x%02x\n", snd_sonicvibes_in(sonic, 0x21));
printk(" 0x02: left AUX1 = 0x%02x ", snd_sonicvibes_in(sonic, 0x02));
printk(" 0x22: ADC clock = 0x%02x\n", snd_sonicvibes_in(sonic, 0x22));
printk(" 0x03: right AUX1 = 0x%02x ", snd_sonicvibes_in(sonic, 0x03));
printk(" 0x23: ADC alt rate = 0x%02x\n", snd_sonicvibes_in(sonic, 0x23));
printk(" 0x04: left CD = 0x%02x ", snd_sonicvibes_in(sonic, 0x04));
printk(" 0x24: ADC pll M = 0x%02x\n", snd_sonicvibes_in(sonic, 0x24));
printk(" 0x05: right CD = 0x%02x ", snd_sonicvibes_in(sonic, 0x05));
printk(" 0x25: ADC pll N = 0x%02x\n", snd_sonicvibes_in(sonic, 0x25));
printk(" 0x06: left line = 0x%02x ", snd_sonicvibes_in(sonic, 0x06));
printk(" 0x26: Synth pll M = 0x%02x\n", snd_sonicvibes_in(sonic, 0x26));
printk(" 0x07: right line = 0x%02x ", snd_sonicvibes_in(sonic, 0x07));
printk(" 0x27: Synth pll N = 0x%02x\n", snd_sonicvibes_in(sonic, 0x27));
printk(" 0x08: MIC = 0x%02x ", snd_sonicvibes_in(sonic, 0x08));
printk(" 0x28: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x28));
printk(" 0x09: Game port = 0x%02x ", snd_sonicvibes_in(sonic, 0x09));
printk(" 0x29: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x29));
printk(" 0x0a: left synth = 0x%02x ", snd_sonicvibes_in(sonic, 0x0a));
printk(" 0x2a: MPU401 = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2a));
printk(" 0x0b: right synth = 0x%02x ", snd_sonicvibes_in(sonic, 0x0b));
printk(" 0x2b: drive ctrl = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2b));
printk(" 0x0c: left AUX2 = 0x%02x ", snd_sonicvibes_in(sonic, 0x0c));
printk(" 0x2c: SRS space = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2c));
printk(" 0x0d: right AUX2 = 0x%02x ", snd_sonicvibes_in(sonic, 0x0d));
printk(" 0x2d: SRS center = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2d));
printk(" 0x0e: left analog = 0x%02x ", snd_sonicvibes_in(sonic, 0x0e));
printk(" 0x2e: wave source = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2e));
printk(" 0x0f: right analog = 0x%02x ", snd_sonicvibes_in(sonic, 0x0f));
printk(" 0x2f: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2f));
printk(" 0x10: left PCM = 0x%02x ", snd_sonicvibes_in(sonic, 0x10));
printk(" 0x30: analog power = 0x%02x\n", snd_sonicvibes_in(sonic, 0x30));
printk(" 0x11: right PCM = 0x%02x ", snd_sonicvibes_in(sonic, 0x11));
printk(" 0x31: analog power = 0x%02x\n", snd_sonicvibes_in(sonic, 0x31));
printk(" 0x12: DMA data format = 0x%02x ", snd_sonicvibes_in(sonic, 0x12));
printk(" 0x32: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x32));
printk(" 0x13: P/C enable = 0x%02x ", snd_sonicvibes_in(sonic, 0x13));
printk(" 0x33: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x33));
printk(" 0x14: U/D button = 0x%02x ", snd_sonicvibes_in(sonic, 0x14));
printk(" 0x34: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x34));
printk(" 0x15: revision = 0x%02x ", snd_sonicvibes_in(sonic, 0x15));
printk(" 0x35: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x35));
printk(" 0x16: ADC output ctrl = 0x%02x ", snd_sonicvibes_in(sonic, 0x16));
printk(" 0x36: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x36));
printk(" 0x17: --- = 0x%02x ", snd_sonicvibes_in(sonic, 0x17));
printk(" 0x37: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x37));
printk(" 0x18: DMA A upper cnt = 0x%02x ", snd_sonicvibes_in(sonic, 0x18));
printk(" 0x38: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x38));
printk(" 0x19: DMA A lower cnt = 0x%02x ", snd_sonicvibes_in(sonic, 0x19));
printk(" 0x39: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x39));
printk(" 0x1a: --- = 0x%02x ", snd_sonicvibes_in(sonic, 0x1a));
printk(" 0x3a: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3a));
printk(" 0x1b: --- = 0x%02x ", snd_sonicvibes_in(sonic, 0x1b));
printk(" 0x3b: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3b));
printk(" 0x1c: DMA C upper cnt = 0x%02x ", snd_sonicvibes_in(sonic, 0x1c));
printk(" 0x3c: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3c));
printk(" 0x1d: DMA C upper cnt = 0x%02x ", snd_sonicvibes_in(sonic, 0x1d));
printk(" 0x3d: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3d));
printk(" 0x1e: PCM rate low = 0x%02x ", snd_sonicvibes_in(sonic, 0x1e));
printk(" 0x3e: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3e));
printk(" 0x1f: PCM rate high = 0x%02x ", snd_sonicvibes_in(sonic, 0x1f));
printk(" 0x3f: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3f));
}
#endif
static void snd_sonicvibes_setfmt(struct sonicvibes * sonic,
unsigned char mask,
unsigned char value)
{
unsigned long flags;
spin_lock_irqsave(&sonic->reg_lock, flags);
outb(SV_MCE | SV_IREG_DMA_DATA_FMT, SV_REG(sonic, INDEX));
if (mask) {
sonic->format = inb(SV_REG(sonic, DATA));
udelay(10);
}
sonic->format = (sonic->format & mask) | value;
outb(sonic->format, SV_REG(sonic, DATA));
udelay(10);
outb(0, SV_REG(sonic, INDEX));
udelay(10);
spin_unlock_irqrestore(&sonic->reg_lock, flags);
}
static void snd_sonicvibes_pll(unsigned int rate,
unsigned int *res_r,
unsigned int *res_m,
unsigned int *res_n)
{
unsigned int r, m = 0, n = 0;
unsigned int xm, xn, xr, xd, metric = ~0U;
if (rate < 625000 / SV_ADCMULT)
rate = 625000 / SV_ADCMULT;
if (rate > 150000000 / SV_ADCMULT)
rate = 150000000 / SV_ADCMULT;
/* slight violation of specs, needed for continuous sampling rates */
for (r = 0; rate < 75000000 / SV_ADCMULT; r += 0x20, rate <<= 1);
for (xn = 3; xn < 33; xn++) /* 35 */
for (xm = 3; xm < 257; xm++) {
xr = ((SV_REFFREQUENCY / SV_ADCMULT) * xm) / xn;
if (xr >= rate)
xd = xr - rate;
else
xd = rate - xr;
if (xd < metric) {
metric = xd;
m = xm - 2;
n = xn - 2;
}
}
*res_r = r;
*res_m = m;
*res_n = n;
#if 0
printk("metric = %i, xm = %i, xn = %i\n", metric, xm, xn);
printk("pll: m = 0x%x, r = 0x%x, n = 0x%x\n", reg, m, r, n);
#endif
}
static void snd_sonicvibes_setpll(struct sonicvibes * sonic,
unsigned char reg,
unsigned int rate)
{
unsigned long flags;
unsigned int r, m, n;
snd_sonicvibes_pll(rate, &r, &m, &n);
if (sonic != NULL) {
spin_lock_irqsave(&sonic->reg_lock, flags);
snd_sonicvibes_out1(sonic, reg, m);
snd_sonicvibes_out1(sonic, reg + 1, r | n);
spin_unlock_irqrestore(&sonic->reg_lock, flags);
}
}
static void snd_sonicvibes_set_adc_rate(struct sonicvibes * sonic, unsigned int rate)
{
unsigned long flags;
unsigned int div;
unsigned char clock;
div = 48000 / rate;
if (div > 8)
div = 8;
if ((48000 / div) == rate) { /* use the alternate clock */
clock = 0x10;
} else { /* use the PLL source */
clock = 0x00;
snd_sonicvibes_setpll(sonic, SV_IREG_ADC_PLL, rate);
}
spin_lock_irqsave(&sonic->reg_lock, flags);
snd_sonicvibes_out1(sonic, SV_IREG_ADC_ALT_RATE, (div - 1) << 4);
snd_sonicvibes_out1(sonic, SV_IREG_ADC_CLOCK, clock);
spin_unlock_irqrestore(&sonic->reg_lock, flags);
}
static int snd_sonicvibes_hw_constraint_dac_rate(struct snd_pcm_hw_params *params,
struct snd_pcm_hw_rule *rule)
{
unsigned int rate, div, r, m, n;
if (hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->min ==
hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->max) {
rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->min;
div = 48000 / rate;
if (div > 8)
div = 8;
if ((48000 / div) == rate) {
params->rate_num = rate;
params->rate_den = 1;
} else {
snd_sonicvibes_pll(rate, &r, &m, &n);
snd_assert((SV_REFFREQUENCY % 16) == 0, return -EINVAL);
snd_assert((SV_ADCMULT % 512) == 0, return -EINVAL);
params->rate_num = (SV_REFFREQUENCY/16) * (n+2) * r;
params->rate_den = (SV_ADCMULT/512) * (m+2);
}
}
return 0;
}
static void snd_sonicvibes_set_dac_rate(struct sonicvibes * sonic, unsigned int rate)
{
unsigned int div;
unsigned long flags;
div = (rate * 65536 + SV_FULLRATE / 2) / SV_FULLRATE;
if (div > 65535)
div = 65535;
spin_lock_irqsave(&sonic->reg_lock, flags);
snd_sonicvibes_out1(sonic, SV_IREG_PCM_RATE_HIGH, div >> 8);
snd_sonicvibes_out1(sonic, SV_IREG_PCM_RATE_LOW, div);
spin_unlock_irqrestore(&sonic->reg_lock, flags);
}
static int snd_sonicvibes_trigger(struct sonicvibes * sonic, int what, int cmd)
{
int result = 0;
spin_lock(&sonic->reg_lock);
if (cmd == SNDRV_PCM_TRIGGER_START) {
if (!(sonic->enable & what)) {
sonic->enable |= what;
snd_sonicvibes_out1(sonic, SV_IREG_PC_ENABLE, sonic->enable);
}
} else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
if (sonic->enable & what) {
sonic->enable &= ~what;
snd_sonicvibes_out1(sonic, SV_IREG_PC_ENABLE, sonic->enable);
}
} else {
result = -EINVAL;
}
spin_unlock(&sonic->reg_lock);
return result;
}
static irqreturn_t snd_sonicvibes_interrupt(int irq, void *dev_id)
{
struct sonicvibes *sonic = dev_id;
unsigned char status;
status = inb(SV_REG(sonic, STATUS));
if (!(status & (SV_DMAA_IRQ | SV_DMAC_IRQ | SV_MIDI_IRQ)))
return IRQ_NONE;
if (status == 0xff) { /* failure */
outb(sonic->irqmask = ~0, SV_REG(sonic, IRQMASK));
snd_printk(KERN_ERR "IRQ failure - interrupts disabled!!\n");
return IRQ_HANDLED;
}
if (sonic->pcm) {
if (status & SV_DMAA_IRQ)
snd_pcm_period_elapsed(sonic->playback_substream);
if (status & SV_DMAC_IRQ)
snd_pcm_period_elapsed(sonic->capture_substream);
}
if (sonic->rmidi) {
if (status & SV_MIDI_IRQ)
snd_mpu401_uart_interrupt(irq, sonic->rmidi->private_data);
}
if (status & SV_UD_IRQ) {
unsigned char udreg;
int vol, oleft, oright, mleft, mright;
spin_lock(&sonic->reg_lock);
udreg = snd_sonicvibes_in1(sonic, SV_IREG_UD_BUTTON);
vol = udreg & 0x3f;
if (!(udreg & 0x40))
vol = -vol;
oleft = mleft = snd_sonicvibes_in1(sonic, SV_IREG_LEFT_ANALOG);
oright = mright = snd_sonicvibes_in1(sonic, SV_IREG_RIGHT_ANALOG);
oleft &= 0x1f;
oright &= 0x1f;
oleft += vol;
if (oleft < 0)
oleft = 0;
if (oleft > 0x1f)
oleft = 0x1f;
oright += vol;
if (oright < 0)
oright = 0;
if (oright > 0x1f)
oright = 0x1f;
if (udreg & 0x80) {
mleft ^= 0x80;
mright ^= 0x80;
}
oleft |= mleft & 0x80;
oright |= mright & 0x80;
snd_sonicvibes_out1(sonic, SV_IREG_LEFT_ANALOG, oleft);
snd_sonicvibes_out1(sonic, SV_IREG_RIGHT_ANALOG, oright);
spin_unlock(&sonic->reg_lock);
snd_ctl_notify(sonic->card, SNDRV_CTL_EVENT_MASK_VALUE, &sonic->master_mute->id);
snd_ctl_notify(sonic->card, SNDRV_CTL_EVENT_MASK_VALUE, &sonic->master_volume->id);
}
return IRQ_HANDLED;
}
/*
* PCM part
*/
static int snd_sonicvibes_playback_trigger(struct snd_pcm_substream *substream,
int cmd)
{
struct sonicvibes *sonic = snd_pcm_substream_chip(substream);
return snd_sonicvibes_trigger(sonic, 1, cmd);
}
static int snd_sonicvibes_capture_trigger(struct snd_pcm_substream *substream,
int cmd)
{
struct sonicvibes *sonic = snd_pcm_substream_chip(substream);
return snd_sonicvibes_trigger(sonic, 2, cmd);
}
static int snd_sonicvibes_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *hw_params)
{
return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
}
static int snd_sonicvibes_hw_free(struct snd_pcm_substream *substream)
{
return snd_pcm_lib_free_pages(substream);
}
static int snd_sonicvibes_playback_prepare(struct snd_pcm_substream *substream)
{
struct sonicvibes *sonic = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime;
unsigned char fmt = 0;
unsigned int size = snd_pcm_lib_buffer_bytes(substream);
unsigned int count = snd_pcm_lib_period_bytes(substream);
sonic->p_dma_size = size;
count--;
if (runtime->channels > 1)
fmt |= 1;
if (snd_pcm_format_width(runtime->format) == 16)
fmt |= 2;
snd_sonicvibes_setfmt(sonic, ~3, fmt);
snd_sonicvibes_set_dac_rate(sonic, runtime->rate);
spin_lock_irq(&sonic->reg_lock);
snd_sonicvibes_setdmaa(sonic, runtime->dma_addr, size);
snd_sonicvibes_out1(sonic, SV_IREG_DMA_A_UPPER, count >> 8);
snd_sonicvibes_out1(sonic, SV_IREG_DMA_A_LOWER, count);
spin_unlock_irq(&sonic->reg_lock);
return 0;
}
static int snd_sonicvibes_capture_prepare(struct snd_pcm_substream *substream)
{
struct sonicvibes *sonic = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime;
unsigned char fmt = 0;
unsigned int size = snd_pcm_lib_buffer_bytes(substream);
unsigned int count = snd_pcm_lib_period_bytes(substream);
sonic->c_dma_size = size;
count >>= 1;
count--;
if (runtime->channels > 1)
fmt |= 0x10;
if (snd_pcm_format_width(runtime->format) == 16)
fmt |= 0x20;
snd_sonicvibes_setfmt(sonic, ~0x30, fmt);
snd_sonicvibes_set_adc_rate(sonic, runtime->rate);
spin_lock_irq(&sonic->reg_lock);
snd_sonicvibes_setdmac(sonic, runtime->dma_addr, size);
snd_sonicvibes_out1(sonic, SV_IREG_DMA_C_UPPER, count >> 8);
snd_sonicvibes_out1(sonic, SV_IREG_DMA_C_LOWER, count);
spin_unlock_irq(&sonic->reg_lock);
return 0;
}
static snd_pcm_uframes_t snd_sonicvibes_playback_pointer(struct snd_pcm_substream *substream)
{
struct sonicvibes *sonic = snd_pcm_substream_chip(substream);
size_t ptr;
if (!(sonic->enable & 1))
return 0;
ptr = sonic->p_dma_size - snd_sonicvibes_getdmaa(sonic);
return bytes_to_frames(substream->runtime, ptr);
}
static snd_pcm_uframes_t snd_sonicvibes_capture_pointer(struct snd_pcm_substream *substream)
{
struct sonicvibes *sonic = snd_pcm_substream_chip(substream);
size_t ptr;
if (!(sonic->enable & 2))
return 0;
ptr = sonic->c_dma_size - snd_sonicvibes_getdmac(sonic);
return bytes_to_frames(substream->runtime, ptr);
}
static struct snd_pcm_hardware snd_sonicvibes_playback =
{
.info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
SNDRV_PCM_INFO_BLOCK_TRANSFER |
SNDRV_PCM_INFO_MMAP_VALID),
.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
.rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
.rate_min = 4000,
.rate_max = 48000,
.channels_min = 1,
.channels_max = 2,
.buffer_bytes_max = (128*1024),
.period_bytes_min = 32,
.period_bytes_max = (128*1024),
.periods_min = 1,
.periods_max = 1024,
.fifo_size = 0,
};
static struct snd_pcm_hardware snd_sonicvibes_capture =
{
.info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
SNDRV_PCM_INFO_BLOCK_TRANSFER |
SNDRV_PCM_INFO_MMAP_VALID),
.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
.rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
.rate_min = 4000,
.rate_max = 48000,
.channels_min = 1,
.channels_max = 2,
.buffer_bytes_max = (128*1024),
.period_bytes_min = 32,
.period_bytes_max = (128*1024),
.periods_min = 1,
.periods_max = 1024,
.fifo_size = 0,
};
static int snd_sonicvibes_playback_open(struct snd_pcm_substream *substream)
{
struct sonicvibes *sonic = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime;
sonic->mode |= SV_MODE_PLAY;
sonic->playback_substream = substream;
runtime->hw = snd_sonicvibes_playback;
snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, snd_sonicvibes_hw_constraint_dac_rate, NULL, SNDRV_PCM_HW_PARAM_RATE, -1);
return 0;
}
static int snd_sonicvibes_capture_open(struct snd_pcm_substream *substream)
{
struct sonicvibes *sonic = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime;
sonic->mode |= SV_MODE_CAPTURE;
sonic->capture_substream = substream;
runtime->hw = snd_sonicvibes_capture;
snd_pcm_hw_constraint_ratdens(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
&snd_sonicvibes_hw_constraints_adc_clock);
return 0;
}
static int snd_sonicvibes_playback_close(struct snd_pcm_substream *substream)
{
struct sonicvibes *sonic = snd_pcm_substream_chip(substream);
sonic->playback_substream = NULL;
sonic->mode &= ~SV_MODE_PLAY;
return 0;
}
static int snd_sonicvibes_capture_close(struct snd_pcm_substream *substream)
{
struct sonicvibes *sonic = snd_pcm_substream_chip(substream);
sonic->capture_substream = NULL;
sonic->mode &= ~SV_MODE_CAPTURE;
return 0;
}
static struct snd_pcm_ops snd_sonicvibes_playback_ops = {
.open = snd_sonicvibes_playback_open,
.close = snd_sonicvibes_playback_close,
.ioctl = snd_pcm_lib_ioctl,
.hw_params = snd_sonicvibes_hw_params,
.hw_free = snd_sonicvibes_hw_free,
.prepare = snd_sonicvibes_playback_prepare,
.trigger = snd_sonicvibes_playback_trigger,
.pointer = snd_sonicvibes_playback_pointer,
};
static struct snd_pcm_ops snd_sonicvibes_capture_ops = {
.open = snd_sonicvibes_capture_open,
.close = snd_sonicvibes_capture_close,
.ioctl = snd_pcm_lib_ioctl,
.hw_params = snd_sonicvibes_hw_params,
.hw_free = snd_sonicvibes_hw_free,
.prepare = snd_sonicvibes_capture_prepare,
.trigger = snd_sonicvibes_capture_trigger,
.pointer = snd_sonicvibes_capture_pointer,
};
static int __devinit snd_sonicvibes_pcm(struct sonicvibes * sonic, int device, struct snd_pcm ** rpcm)
{
struct snd_pcm *pcm;
int err;
if ((err = snd_pcm_new(sonic->card, "s3_86c617", device, 1, 1, &pcm)) < 0)
return err;
snd_assert(pcm != NULL, return -EINVAL);
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_sonicvibes_playback_ops);
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_sonicvibes_capture_ops);
pcm->private_data = sonic;
pcm->info_flags = 0;
strcpy(pcm->name, "S3 SonicVibes");
sonic->pcm = pcm;
snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
snd_dma_pci_data(sonic->pci), 64*1024, 128*1024);
if (rpcm)
*rpcm = pcm;
return 0;
}
/*
* Mixer part
*/
#define SONICVIBES_MUX(xname, xindex) \
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
.info = snd_sonicvibes_info_mux, \
.get = snd_sonicvibes_get_mux, .put = snd_sonicvibes_put_mux }
static int snd_sonicvibes_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
{
static char *texts[7] = {
"CD", "PCM", "Aux1", "Line", "Aux0", "Mic", "Mix"
};
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
uinfo->count = 2;
uinfo->value.enumerated.items = 7;
if (uinfo->value.enumerated.item >= 7)
uinfo->value.enumerated.item = 6;
strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
return 0;
}
static int snd_sonicvibes_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{
struct sonicvibes *sonic = snd_kcontrol_chip(kcontrol);
spin_lock_irq(&sonic->reg_lock);
ucontrol->value.enumerated.item[0] = ((snd_sonicvibes_in1(sonic, SV_IREG_LEFT_ADC) & SV_RECSRC_OUT) >> 5) - 1;
ucontrol->value.enumerated.item[1] = ((snd_sonicvibes_in1(sonic, SV_IREG_RIGHT_ADC) & SV_RECSRC_OUT) >> 5) - 1;
spin_unlock_irq(&sonic->reg_lock);
return 0;
}
static int snd_sonicvibes_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{
struct sonicvibes *sonic = snd_kcontrol_chip(kcontrol);
unsigned short left, right, oval1, oval2;
int change;
if (ucontrol->value.enumerated.item[0] >= 7 ||
ucontrol->value.enumerated.item[1] >= 7)
return -EINVAL;
left = (ucontrol->value.enumerated.item[0] + 1) << 5;
right = (ucontrol->value.enumerated.item[1] + 1) << 5;
spin_lock_irq(&sonic->reg_lock);
oval1 = snd_sonicvibes_in1(sonic, SV_IREG_LEFT_ADC);
oval2 = snd_sonicvibes_in1(sonic, SV_IREG_RIGHT_ADC);
left = (oval1 & ~SV_RECSRC_OUT) | left;
right = (oval2 & ~SV_RECSRC_OUT) | right;
change = left != oval1 || right != oval2;
snd_sonicvibes_out1(sonic, SV_IREG_LEFT_ADC, left);
snd_sonicvibes_out1(sonic, SV_IREG_RIGHT_ADC, right);
spin_unlock_irq(&sonic->reg_lock);
return change;
}
#define SONICVIBES_SINGLE(xname, xindex, reg, shift, mask, invert) \
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
.info = snd_sonicvibes_info_single, \
.get = snd_sonicvibes_get_single, .put = snd_sonicvibes_put_single, \
.private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
static int snd_sonicvibes_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
{
int mask = (kcontrol->private_value >> 16) & 0xff;
uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 1;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = mask;
return 0;
}
static int snd_sonicvibes_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{
struct sonicvibes *sonic = snd_kcontrol_chip(kcontrol);
int reg = kcontrol->private_value & 0xff;
int shift = (kcontrol->private_value >> 8) & 0xff;
int mask = (kcontrol->private_value >> 16) & 0xff;
int invert = (kcontrol->private_value >> 24) & 0xff;
spin_lock_irq(&sonic->reg_lock);
ucontrol->value.integer.value[0] = (snd_sonicvibes_in1(sonic, reg)>> shift) & mask;
spin_unlock_irq(&sonic->reg_lock);
if (invert)
ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
return 0;
}
static int snd_sonicvibes_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{
struct sonicvibes *sonic = snd_kcontrol_chip(kcontrol);
int reg = kcontrol->private_value & 0xff;
int shift = (kcontrol->private_value >> 8) & 0xff;
int mask = (kcontrol->private_value >> 16) & 0xff;
int invert = (kcontrol->private_value >> 24) & 0xff;
int change;
unsigned short val, oval;
val = (ucontrol->value.integer.value[0] & mask);
if (invert)
val = mask - val;
val <<= shift;
spin_lock_irq(&sonic->reg_lock);
oval = snd_sonicvibes_in1(sonic, reg);
val = (oval & ~(mask << shift)) | val;
change = val != oval;
snd_sonicvibes_out1(sonic, reg, val);
spin_unlock_irq(&sonic->reg_lock);
return change;
}
#define SONICVIBES_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
.info = snd_sonicvibes_info_double, \
.get = snd_sonicvibes_get_double, .put = snd_sonicvibes_put_double, \
.private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
static int snd_sonicvibes_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
{
int mask = (kcontrol->private_value >> 24) & 0xff;
uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 2;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = mask;
return 0;
}