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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
|
/*
* wm8994_extensions.c -- WM8994 ALSA Soc Audio driver related extensions
*
* Copyright (C) 2010/11 François SIMOND / twitter & XDA-developers @supercurio
*
* 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.
*
*/
#include <sound/soc.h>
#include <linux/delay.h>
#include <linux/miscdevice.h>
#include <linux/version.h>
#include "wm8994_extensions.h"
#ifndef MODULE
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35) && !defined(GALAXY_TAB)
#include "wm8994_samsung.h"
#else
#include "wm8994.h"
#endif
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35) && !defined(GALAXY_TAB)
#include "../wm8994_samsung.h"
#else
#include "../wm8994.h"
#endif
#endif
#define SUBJECT "wm8994_extensions.c"
bool bypass_write_extension = false;
short unsigned int debug_log_level = LOG_OFF;
#ifdef CONFIG_SND_WM8994_EXTENSIONS_HP_LEVEL_CONTROL
unsigned short hp_level[2] = { CONFIG_SND_WM8994_EXTENSIONS_HP_LEVEL,
CONFIG_SND_WM8994_EXTENSIONS_HP_LEVEL };
#endif
#ifdef CONFIG_SND_WM8994_EXTENSIONS_FM
bool fm_radio_headset_restore_bass = true;
bool fm_radio_headset_restore_highs = true;
bool fm_radio_headset_normalize_gain = true;
#endif
#ifdef CONFIG_SND_WM8994_EXTENSIONS_RECORD_PRESETS
unsigned short recording_preset = 1;
unsigned short origin_recgain;
unsigned short origin_recgain_mixer;
#endif
#ifdef NEXUS_S
bool speaker_tuning = false;
#endif
// global active or kill switch
bool enable = false;
bool dac_osr128 = true;
bool adc_osr128 = false;
#ifndef GALAXY_TAB_TEGRA
bool fll_tuning = true;
#endif
bool dac_direct = true;
bool mono_downmix = false;
// equalizer
// digital gain value in mili dB
int digital_gain = 0;
bool headphone_eq = false;
short eq_gains[5] = { 0, 0, 0, 0, 0 };
short eq_bands[5] = { 3, 4, 4, 4, 3 };
char eq_band_coef_names[][2] = { "A", "B", "C", "PG" };
unsigned int eq_band_values[5][4] = {
{0x0FCA, 0x0400, 0x00D8},
{0x1EB5, 0xF145, 0x0B75, 0x01C5},
{0x1C58, 0xF373, 0x0A54, 0x0558},
{0x168E, 0xF829, 0x07AD, 0x1103},
{0x0564, 0x0559, 0x4000}
};
// 3D effect
bool stereo_expansion = false;
short unsigned int stereo_expansion_gain = 16;
#ifdef CONFIG_PHONE_ARIES_CDMA
// call volume boost hack
extern unsigned short incall_boost_rcv;
extern unsigned short incall_boost_bt;
extern unsigned short incall_boost_spk;
extern unsigned short incall_boost_hp;
// mic gain control hack
extern unsigned short incall_mic_gain_rcv;
extern unsigned short incall_mic_gain_spk;
extern unsigned short incall_mic_gain_hp;
extern unsigned short incall_mic_gain_hp_no_mic;
#endif
// keep here a pointer to the codec structure
struct snd_soc_codec *codec;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0)
#define DECLARE_WM8994(codec) struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
#define DECLARE_WM8994(codec) struct wm8994_priv *wm8994 = codec->drvdata;
#else
#define DECLARE_WM8994(codec) struct wm8994_priv *wm8994 = codec->private_data;
#endif
bool debug_log(short unsigned int level)
{
if (debug_log_level >= level)
return true;
return false;
}
#ifdef CONFIG_SND_WM8994_EXTENSIONS_HP_LEVEL_CONTROL
int hpvol(int channel)
{
int vol;
vol = hp_level[channel];
if (is_path_media_or_fm_no_call_no_record()) {
// negative digital gain compensation
if (digital_gain < 0)
vol = (vol - ((digital_gain / 100) + 5) / 10);
if (vol > 62)
return 62;
}
return vol;
}
void write_hpvol(unsigned short l, unsigned short r)
{
unsigned short val;
// we don't need the Volume Update flag when sending the first volume
val = (WM8994_HPOUT1L_MUTE_N | l);
val |= WM8994_HPOUT1L_ZC;
wm8994_write(codec, WM8994_LEFT_OUTPUT_VOLUME, val);
// this time we write the right volume plus the Volume Update flag.
// This way, both volume are set at the same time
val = (WM8994_HPOUT1_VU | WM8994_HPOUT1R_MUTE_N | r);
val |= WM8994_HPOUT1L_ZC;
wm8994_write(codec, WM8994_RIGHT_OUTPUT_VOLUME, val);
}
void update_hpvol(bool with_fade)
{
unsigned short val;
unsigned short i;
short steps;
int hp_level_old[2];
unsigned short hp_level_registers[2] = { WM8994_LEFT_OUTPUT_VOLUME,
WM8994_RIGHT_OUTPUT_VOLUME };
DECLARE_WM8994(codec);
// don't affect headphone amplifier volume
// when not on heapdhones or if call is active
if (!is_path(HEADPHONES)
|| (wm8994->codec_state & CALL_ACTIVE))
return;
if (!with_fade) {
bypass_write_extension = true;
write_hpvol(hpvol(0), hpvol(1));
bypass_write_extension = false;
return;
}
// read previous levels
for (i = 0; i < 2; i++) {
val = wm8994_read(codec, hp_level_registers[i]);
val &= ~(WM8994_HPOUT1_VU_MASK);
val &= ~(WM8994_HPOUT1L_ZC_MASK);
val &= ~(WM8994_HPOUT1L_MUTE_N_MASK);
hp_level_old[i] = val + (digital_gain / 1000);
if (hp_level_old[i] < 0)
hp_level_old[i] = 0;
if (debug_log(LOG_INFOS))
printk("wm8994_extensions: previous hp_level[%hu]: %d\n",
i, hp_level_old[i]);
}
// calculate number of steps for volume fade
steps = hp_level[0] - hp_level_old[0];
if (debug_log(LOG_INFOS))
printk("wm8994_extensions: volume change steps: %hd "
"start: %hu, end: %hu\n",
steps,
hp_level_old[0],
hp_level[0]);
while (steps != 0) {
if (hp_level[0] < hp_level_old[0])
steps++;
else
steps--;
if (debug_log(LOG_INFOS))
printk("wm8994_extensions: volume: %hu\n",
(hpvol(0) - steps));
bypass_write_extension = true;
write_hpvol(hpvol(0) - steps, hpvol(1) - steps);
bypass_write_extension = false;
if (steps != 0)
udelay(1000);
}
}
#endif
#ifdef CONFIG_SND_WM8994_EXTENSIONS_FM
void update_fm_radio_headset_restore_freqs(bool with_mute)
{
unsigned short val;
DECLARE_WM8994(codec);
bypass_write_extension = true;
// apply only when FM radio is active
if (wm8994->fmradio_path == FMR_OFF)
return;
if (with_mute) {
wm8994_write(codec, WM8994_AIF2_DAC_FILTERS_1,
WM8994_AIF2DAC_MUTE |
WM8994_AIF2DAC_MUTERATE |
WM8994_AIF2DAC_UNMUTE_RAMP |
WM8994_AIF2DAC_DEEMP_MASK);
msleep(180);
}
if (fm_radio_headset_restore_bass) {
// disable Sidetone high-pass filter
// was designed for voice and not FM radio
wm8994_write(codec, WM8994_SIDETONE, 0x0000);
// disable 4FS ultrasonic mode and
// restore the hi-fi <4Hz hi pass filter
wm8994_write(codec, WM8994_AIF2_ADC_FILTERS,
WM8994_AIF2ADCL_HPF |
WM8994_AIF2ADCR_HPF);
} else {
// default settings in GT-I9000 Froyo XXJPX kernel sources
wm8994_write(codec, WM8994_SIDETONE, 0x01c0);
wm8994_write(codec, WM8994_AIF2_ADC_FILTERS, 0xF800);
}
if (fm_radio_headset_restore_highs) {
val = wm8994_read(codec, WM8994_AIF2_DAC_FILTERS_1);
val &= ~(WM8994_AIF2DAC_DEEMP_MASK);
wm8994_write(codec, WM8994_AIF2_DAC_FILTERS_1, val);
} else {
wm8994_write(codec, WM8994_AIF2_DAC_FILTERS_1, 0x0036);
}
// un-mute
if (with_mute) {
val = wm8994_read(codec, WM8994_AIF2_DAC_FILTERS_1);
val &= ~(WM8994_AIF2DAC_MUTE_MASK);
wm8994_write(codec, WM8994_AIF2_DAC_FILTERS_1, val);
}
bypass_write_extension = false;
}
void update_fm_radio_headset_normalize_gain(bool with_mute)
{
DECLARE_WM8994(codec);
bypass_write_extension = true;
// apply only when FM radio is active
if (wm8994->fmradio_path == FMR_OFF)
return;
if (fm_radio_headset_normalize_gain) {
// Bumped volume, change with Zero Cross
wm8994_write(codec, WM8994_LEFT_LINE_INPUT_3_4_VOLUME, 0x52);
wm8994_write(codec, WM8994_RIGHT_LINE_INPUT_3_4_VOLUME, 0x152);
wm8994_write(codec, WM8994_AIF2_DRC_2, 0x0840);
wm8994_write(codec, WM8994_AIF2_DRC_3, 0x2408);
wm8994_write(codec, WM8994_AIF2_DRC_4, 0x0082);
wm8994_write(codec, WM8994_AIF2_DRC_5, 0x0100);
wm8994_write(codec, WM8994_AIF2_DRC_1, 0x019C);
} else {
// Original volume, change with Zero Cross
wm8994_write(codec, WM8994_LEFT_LINE_INPUT_3_4_VOLUME, 0x4B);
wm8994_write(codec, WM8994_RIGHT_LINE_INPUT_3_4_VOLUME, 0x14B);
wm8994_write(codec, WM8994_AIF2_DRC_2, 0x0840);
wm8994_write(codec, WM8994_AIF2_DRC_3, 0x2400);
wm8994_write(codec, WM8994_AIF2_DRC_4, 0x0000);
wm8994_write(codec, WM8994_AIF2_DRC_5, 0x0000);
wm8994_write(codec, WM8994_AIF2_DRC_1, 0x019C);
}
bypass_write_extension = false;
}
#endif
#ifdef CONFIG_SND_WM8994_EXTENSIONS_RECORD_PRESETS
void update_recording_preset(bool with_mute)
{
if (!is_path(MAIN_MICROPHONE))
return;
switch (recording_preset) {
case 0:
// Original:
// On Galaxy S: IN1L_VOL1=11000 (+19.5 dB)
// On Nexus S: variable value
wm8994_write(codec, WM8994_LEFT_LINE_INPUT_1_2_VOLUME,
WM8994_IN1L_VU | origin_recgain);
wm8994_write(codec, WM8994_INPUT_MIXER_3, origin_recgain_mixer);
// DRC disabled
wm8994_write(codec, WM8994_AIF1_DRC1_1, 0x0080);
break;
case 2:
// High sensitivy:
// Original - 4.5 dB, IN1L_VOL1=10101 (+15 dB)
wm8994_write(codec, WM8994_LEFT_LINE_INPUT_1_2_VOLUME, 0x0115);
wm8994_write(codec, WM8994_INPUT_MIXER_3,
WM8994_IN1L_TO_MIXINL |
WM8994_IN1L_MIXINL_VOL);
// DRC Input: -6dB, Ouptut -3.75dB
// Above knee 1/8, Below knee 1/2
// Max gain 24 / Min gain -12
wm8994_write(codec, WM8994_AIF1_DRC1_1,
WM8994_AIF1DRC1_SIG_DET_MODE |
WM8994_AIF1DRC1_QR |
WM8994_AIF1DRC1_ANTICLIP |
WM8994_AIF1ADC1L_DRC_ENA);
wm8994_write(codec, WM8994_AIF1_DRC1_2, 0x0426);
wm8994_write(codec, WM8994_AIF1_DRC1_3, 0x0019);
wm8994_write(codec, WM8994_AIF1_DRC1_4, 0x0105);
break;
case 3:
// Concert new: IN1L_VOL1=10110 (+4.5 dB)
// +30dB input mixer gain deactivated
wm8994_write(codec, WM8994_LEFT_LINE_INPUT_1_2_VOLUME, 0x010F);
wm8994_write(codec, WM8994_INPUT_MIXER_3,
WM8994_IN1L_TO_MIXINL);
// DRC Input: -4.5dB, Ouptut -6.75dB
// Above knee 1/4, Below knee 1/2
// Max gain 24 / Min gain -12
wm8994_write(codec, WM8994_AIF1_DRC1_1,
WM8994_AIF1DRC1_SIG_DET_MODE |
WM8994_AIF1DRC1_QR |
WM8994_AIF1DRC1_ANTICLIP |
WM8994_AIF1ADC1L_DRC_ENA);
wm8994_write(codec, WM8994_AIF1_DRC1_2, 0x0846);
wm8994_write(codec, WM8994_AIF1_DRC1_3, 0x0011);
wm8994_write(codec, WM8994_AIF1_DRC1_4, 0x00C9);
break;
case 4:
// ULTRA LOUD:
// Original - 36 dB - 30 dB IN1L_VOL1=00000 (-16.5 dB)
// +30dB input mixer gain deactivated
wm8994_write(codec, WM8994_LEFT_LINE_INPUT_1_2_VOLUME, 0x0100);
wm8994_write(codec, WM8994_INPUT_MIXER_3,
WM8994_IN1L_TO_MIXINL);
// DRC Input: -7.5dB, Ouptut -6dB
// Above knee 1/8, Below knee 1/4
// Max gain 36 / Min gain -12
wm8994_write(codec, WM8994_AIF1_DRC1_1,
WM8994_AIF1DRC1_SIG_DET_MODE |
WM8994_AIF1DRC1_QR |
WM8994_AIF1DRC1_ANTICLIP |
WM8994_AIF1ADC1L_DRC_ENA);
wm8994_write(codec, WM8994_AIF1_DRC1_2, 0x0847);
wm8994_write(codec, WM8994_AIF1_DRC1_3, 0x001A);
wm8994_write(codec, WM8994_AIF1_DRC1_4, 0x00C9);
break;
default:
// make sure recording_preset is the default
recording_preset = 1;
// New Balanced: Original - 16.5 dB
// IN1L_VOL1=01101 (+27 dB)
// +30dB input mixer gain deactivated
wm8994_write(codec, WM8994_LEFT_LINE_INPUT_1_2_VOLUME, 0x055D);
wm8994_write(codec, WM8994_INPUT_MIXER_3,
WM8994_IN1L_TO_MIXINL);
// DRC Input: -18.5dB, Ouptut -9dB
// Above knee 1/8, Below knee 1/2
// Max gain 18 / Min gain -12
wm8994_write(codec, WM8994_AIF1_DRC1_1,
WM8994_AIF1DRC1_SIG_DET_MODE |
WM8994_AIF1DRC1_QR |
WM8994_AIF1DRC1_ANTICLIP |
WM8994_AIF1ADC1L_DRC_ENA);
wm8994_write(codec, WM8994_AIF1_DRC1_2, 0x0845);
wm8994_write(codec, WM8994_AIF1_DRC1_3, 0x0019);
wm8994_write(codec, WM8994_AIF1_DRC1_4, 0x030C);
break;
}
}
#endif
bool is_path(int unified_path)
{
DECLARE_WM8994(codec);
switch (unified_path) {
// speaker
case SPEAKER:
#ifdef GALAXY_TAB
return (wm8994->cur_path == SPK
|| wm8994->cur_path == RING_SPK
|| wm8994->fmradio_path == FMR_SPK
|| wm8994->fmradio_path == FMR_SPK_MIX);
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
return (wm8994->cur_path == SPK
|| wm8994->cur_path == SPK_HP);
#else
return (wm8994->cur_path == SPK
|| wm8994->cur_path == RING_SPK);
#endif
#endif
// headphones
case HEADPHONES:
#ifdef NEXUS_S
return (wm8994->cur_path == HP
|| wm8994->cur_path == HP_NO_MIC);
#else
#ifdef GALAXY_TAB
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
return (wm8994->cur_path == HP
|| wm8994->cur_path == HP_NO_MIC);
#else
return (wm8994->cur_path == HP3P
|| wm8994->cur_path == HP4P
|| wm8994->fmradio_path == FMR_HP);
#endif
#else
#ifdef M110S
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
return (wm8994->cur_path == HP
|| wm8994->cur_path == HP_NO_MIC);
#else
return (wm8994->cur_path == HP);
#endif
#else
#ifdef GALAXY_TAB_TEGRA
return (wm8994->cur_path == HP
|| wm8994->cur_path == HP_NO_MIC);
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
return (wm8994->cur_path == HP
|| wm8994->cur_path == HP_NO_MIC
|| wm8994->fmradio_path == FMR_HP);
#else
return (wm8994->cur_path == HP
|| wm8994->fmradio_path == FMR_HP);
#endif
#endif
#endif
#endif
#endif
// FM Radio on headphones
case RADIO_HEADPHONES:
#ifdef M110S
return false;
#else
#ifdef GALAXY_TAB_TEGRA
return false;
#else
#ifdef GALAXY_TAB
return false;
#else
return (wm8994->codec_state & FMRADIO_ACTIVE)
&& (wm8994->fmradio_path == FMR_HP);
#endif
#endif
#endif
// Standard recording presets
// for M110S Gingerbread: added check non call
case MAIN_MICROPHONE:
return (wm8994->codec_state & CAPTURE_ACTIVE)
&& (wm8994->rec_path == MAIN)
&& !(wm8994->codec_state & CALL_ACTIVE);
}
return false;
}
bool is_path_media_or_fm_no_call_no_record()
{
DECLARE_WM8994(codec);
if ((is_path(HEADPHONES)
&& (wm8994->codec_state & PLAYBACK_ACTIVE)
&& (wm8994->stream_state & PCM_STREAM_PLAYBACK)
&& !(wm8994->codec_state & CALL_ACTIVE)
&& (wm8994->rec_path == MIC_OFF)
) || is_path(RADIO_HEADPHONES))
return true;
return false;
}
#ifdef NEXUS_S
void update_speaker_tuning(bool with_mute)
{
DECLARE_WM8994(codec);
if (!(is_path(SPEAKER) || (wm8994->codec_state & CALL_ACTIVE)))
return;
if (speaker_tuning) {
// DRC settings
wm8994_write(codec, WM8994_AIF1_DRC1_3, 0x0010);
wm8994_write(codec, WM8994_AIF1_DRC1_4, 0x00EB);
// hardware EQ
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_GAINS_1, 0x041D);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_GAINS_2, 0x4C00);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_1_A, 0x0FE3);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_1_B, 0x0403);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_1_PG, 0x0074);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_2_A, 0x1F03);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_2_B, 0xF0F9);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_2_C, 0x040A);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_2_PG, 0x03DA);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_3_A, 0x1ED2);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_3_B, 0xF11A);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_3_C, 0x040A);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_3_PG, 0x045D);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_4_A, 0x0E76);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_4_B, 0xFCE4);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_4_C, 0x040A);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_4_PG, 0x330D);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_5_A, 0xFC8F);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_5_B, 0x0400);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_5_PG, 0x323C);
// Speaker Boost tuning
wm8994_write(codec, WM8994_CLASSD, 0x0170);
} else {
// DRC settings
wm8994_write(codec, WM8994_AIF1_DRC1_3, 0x0028);
wm8994_write(codec, WM8994_AIF1_DRC1_4, 0x0186);
// hardware EQ
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_GAINS_1, 0x0019);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_GAINS_2, 0x6280);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_1_A, 0x0FC3);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_1_B, 0x03FD);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_1_PG, 0x00F4);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_2_A, 0x1F30);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_2_B, 0xF0CD);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_2_C, 0x040A);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_2_PG, 0x032C);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_3_A, 0x1C52);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_3_B, 0xF379);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_3_C, 0x040A);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_BAND_3_PG, 0x0DC1);
wm8994_write(codec, WM8994_CLASSD, 0x0170);
// Speaker Boost tuning
wm8994_write(codec, WM8994_CLASSD, 0x0168);
}
}
#endif
unsigned short osr128_get_value(unsigned short val)
{
if (dac_osr128 == 1)
val |= WM8994_DAC_OSR128;
else
val &= ~WM8994_DAC_OSR128;
if (adc_osr128 == 1)
val |= WM8994_ADC_OSR128;
else
val &= ~WM8994_ADC_OSR128;
if (debug_log(LOG_INFOS))
printk("wm8994_extensions: %s %s %s %d\n",
__func__,
dac_osr128 ? "dac_osr128" : "",
adc_osr128 ? "adc_osr128" : "",
val);
return val;
}
void update_osr128(bool with_mute)
{
unsigned short val;
val = osr128_get_value(wm8994_read(codec, WM8994_OVERSAMPLING));
bypass_write_extension = true;
wm8994_write(codec, WM8994_OVERSAMPLING, val);
bypass_write_extension = false;
}
#ifndef GALAXY_TAB_TEGRA
unsigned short fll_tuning_get_value(unsigned short val)
{
val = (val >> WM8994_FLL1_GAIN_WIDTH << WM8994_FLL1_GAIN_WIDTH);
if (fll_tuning == 1)
val |= 5;
return val;
}
void update_fll_tuning(bool with_mute)
{
unsigned short val;
val = fll_tuning_get_value(wm8994_read(codec, WM8994_FLL1_CONTROL_4));
bypass_write_extension = true;
wm8994_write(codec, WM8994_FLL1_CONTROL_4, val);
bypass_write_extension = false;
}
#endif
unsigned short mono_downmix_get_value(unsigned short val, bool can_reverse)
{
DECLARE_WM8994(codec);
// Takes care not switching to Stereo on speaker or during a call
if (!is_path(SPEAKER) && !(wm8994->codec_state & CALL_ACTIVE)) {
if (mono_downmix) {
val |= WM8994_AIF1DAC1_MONO;
} else {
if (can_reverse)
val &= ~WM8994_AIF1DAC1_MONO;
}
}
return val;
}
void update_mono_downmix(bool with_mute)
{
unsigned short val1, val2, val3;
val1 = mono_downmix_get_value(wm8994_read
(codec, WM8994_AIF1_DAC1_FILTERS_1),
true);
val2 = mono_downmix_get_value(wm8994_read
(codec, WM8994_AIF1_DAC2_FILTERS_1),
true);
val3 = mono_downmix_get_value(wm8994_read
(codec, WM8994_AIF2_DAC_FILTERS_1),
true);
bypass_write_extension = true;
wm8994_write(codec, WM8994_AIF1_DAC1_FILTERS_1, val1);
wm8994_write(codec, WM8994_AIF1_DAC2_FILTERS_1, val2);
wm8994_write(codec, WM8994_AIF2_DAC_FILTERS_1, val3);
bypass_write_extension = false;
}
unsigned short dac_direct_get_value(unsigned short val, bool can_reverse)
{
if (is_path_media_or_fm_no_call_no_record()) {
if (dac_direct) {
if (val == WM8994_DAC1L_TO_MIXOUTL)
return WM8994_DAC1L_TO_HPOUT1L;
} else {
if (val == WM8994_DAC1L_TO_HPOUT1L && can_reverse)
return WM8994_DAC1L_TO_MIXOUTL;
}
}
return val;
}
void update_dac_direct(bool with_mute)
{
unsigned short val1, val2;
val1 = dac_direct_get_value(wm8994_read(codec,
WM8994_OUTPUT_MIXER_1), true);
val2 = dac_direct_get_value(wm8994_read(codec,
WM8994_OUTPUT_MIXER_2), true);
bypass_write_extension = true;
wm8994_write(codec, WM8994_OUTPUT_MIXER_1, val1);
wm8994_write(codec, WM8994_OUTPUT_MIXER_2, val2);
bypass_write_extension = false;
}
unsigned short digital_gain_get_value(unsigned short val)
{
// AIF gain to 0dB
int aif_gain = 0xC0;
int i;
int step = -375;
if (is_path_media_or_fm_no_call_no_record()) {
if (digital_gain <= 0) {
// clear the actual DAC volume for this value
val &= ~(WM8994_DAC1R_VOL_MASK);
// calculation with round
i = ((digital_gain * 10 / step) + 5) / 10;
aif_gain -= i;
val |= aif_gain;
if (debug_log(LOG_INFOS))
printk("wm8994_extensions: digital gain: %d mdB, "
"%d mdB steps: %d, "
"real AIF gain: %d mdB\n",
digital_gain, step, i, i * step);
}
}
return val;
}
void update_digital_gain(bool with_mute)
{
unsigned short val1, val2;
val1 = digital_gain_get_value(wm8994_read(codec,
WM8994_AIF1_DAC1_LEFT_VOLUME));
val2 = digital_gain_get_value(wm8994_read(codec,
WM8994_AIF1_DAC1_RIGHT_VOLUME));
bypass_write_extension = true;
wm8994_write(codec, WM8994_AIF1_DAC1_LEFT_VOLUME,
WM8994_DAC1_VU | val1);
wm8994_write(codec, WM8994_AIF1_DAC1_RIGHT_VOLUME,
WM8994_DAC1_VU | val2);
bypass_write_extension = false;
}
void update_headphone_eq(bool update_bands)
{
int gains_1;
int gains_2;
if (!is_path_media_or_fm_no_call_no_record()) {
// don't apply the EQ
return;
}
if (debug_log(LOG_INFOS))
printk("wm8994_extensions: EQ gains (dB): %hd, %hd, %hd, %hd, %hd\n",
eq_gains[0], eq_gains[1], eq_gains[2],
eq_gains[3], eq_gains[4]);
gains_1 =
((eq_gains[0] + 12) << WM8994_AIF1DAC1_EQ_B1_GAIN_SHIFT) |
((eq_gains[1] + 12) << WM8994_AIF1DAC1_EQ_B2_GAIN_SHIFT) |
((eq_gains[2] + 12) << WM8994_AIF1DAC1_EQ_B3_GAIN_SHIFT) |
headphone_eq;
gains_2 =
((eq_gains[3] + 12) << WM8994_AIF1DAC1_EQ_B4_GAIN_SHIFT) |
((eq_gains[4] + 12) << WM8994_AIF1DAC1_EQ_B5_GAIN_SHIFT);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_GAINS_1, gains_1);
wm8994_write(codec, WM8994_AIF1_DAC1_EQ_GAINS_2, gains_2);
// don't send EQ configuration if its not enabled
if (!headphone_eq)
return;
if (update_bands)
update_headphone_eq_bands();
}
void update_headphone_eq_bands()
{
int i;
int j;
int k = 0;
int first_reg = WM8994_AIF1_DAC1_EQ_BAND_1_A;
for (i = 0; i < ARRAY_SIZE(eq_band_values); i++) {
if (debug_log(LOG_INFOS))
printk("wm8994_extensions: send EQ Band %d\n", i + 1);
for (j = 0; j < eq_bands[i]; j++) {
wm8994_write(codec,
first_reg + k, eq_band_values[i][j]);
k++;
}
}
}
void smooth_apply_eq_band_gain(int band, int start, int end, bool current_state)
{
if (debug_log(LOG_INFOS))
printk("wm8994_extensions: EQ smooth transition for Band %d "
"from %d to %d\n", band + 1, start, end);
if (start == end) {
if (end != 0)
update_headphone_eq(true);
else
update_headphone_eq(false);
return;
}
if (current_state)
update_headphone_eq_bands();
while (start != end) {
if (start < end)
start++;
else
start--;
eq_gains[band] = start;
update_headphone_eq(false);
}
}
void update_stereo_expansion(bool with_mute)
{
short unsigned int val;
val = wm8994_read(codec, WM8994_AIF1_DAC1_FILTERS_2);
if (stereo_expansion) {
val &= ~(WM8994_AIF1DAC1_3D_GAIN_MASK);
val |= (stereo_expansion_gain << WM8994_AIF1DAC1_3D_GAIN_SHIFT);
}
val &= ~(WM8994_AIF1DAC1_3D_ENA_MASK);
val |= (stereo_expansion << WM8994_AIF1DAC1_3D_ENA_SHIFT);
wm8994_write(codec, WM8994_AIF1_DAC1_FILTERS_2, val);
}
void load_current_eq_values()
{
int i;
int j;
int k = 0;
int first_reg = WM8994_AIF1_DAC1_EQ_BAND_1_A;
for (i = 0; i < ARRAY_SIZE(eq_band_values); i++)
for (j = 0; j < eq_bands[i]; j++) {
eq_band_values[i][j] =
wm8994_read(codec, first_reg + k);
k++;
}
}
void apply_saturation_prevention_drc()
{
unsigned short val;
unsigned short drc_gain = 0;
int i;
int step = 750;
// don't apply the limiter if not playing media
// (exclude FM radio, it has its own DRC settings)
if (!is_path_media_or_fm_no_call_no_record()
|| is_path(RADIO_HEADPHONES))
return;
// don't apply the limiter without stereo_expansion or headphone_eq
// or a positive digital gain
if (!(stereo_expansion
|| headphone_eq
|| digital_gain >= 0))
return;
if (debug_log(LOG_INFOS))
printk("wm8994_extensions: apply saturation prevention DRC\n");
// configure the DRC to avoid saturation: not actually compress signal
// gain is unmodified. Should affect only what's higher than 0 dBFS
// tune Attack & Decacy values
val = wm8994_read(codec, WM8994_AIF1_DRC1_2);
val &= ~(WM8994_AIF1DRC1_ATK_MASK);
val &= ~(WM8994_AIF1DRC1_DCY_MASK);
val |= (0x1 << WM8994_AIF1DRC1_ATK_SHIFT);
val |= (0x4 << WM8994_AIF1DRC1_DCY_SHIFT);
// set DRC maximum gain to 36 dB
val &= ~(WM8994_AIF1DRC1_MAXGAIN_MASK);
val |= (0x3 << WM8994_AIF1DRC1_MAXGAIN_SHIFT);
wm8994_write(codec, WM8994_AIF1_DRC1_2, val);
// Above knee: flat (what really avoid the saturation)
val = wm8994_read(codec, WM8994_AIF1_DRC1_3);
val |= (0x5 << WM8994_AIF1DRC1_HI_COMP_SHIFT);
wm8994_write(codec, WM8994_AIF1_DRC1_3, val);
val = wm8994_read(codec, WM8994_AIF1_DRC1_1);
// disable Quick Release and Anti Clip
// both do do more harm than good for this particular usage
val &= ~(WM8994_AIF1DRC1_QR_MASK);
val &= ~(WM8994_AIF1DRC1_ANTICLIP_MASK);
// enable DRC
val &= ~(WM8994_AIF1DAC1_DRC_ENA_MASK);
val |= WM8994_AIF1DAC1_DRC_ENA;
wm8994_write(codec, WM8994_AIF1_DRC1_1, val);
val = wm8994_read(codec, WM8994_AIF1_DRC1_4);
val &= ~(WM8994_AIF1DRC1_KNEE_IP_MASK);
if (digital_gain >= 0) {
// deal with positive digital gains
i = ((digital_gain * 10 / step) + 5) / 10;
drc_gain += i;
val |= (drc_gain << WM8994_AIF1DRC1_KNEE_IP_SHIFT);
if (debug_log(LOG_INFOS))
printk("wm8994_extensions: digital gain: %d mdB, "
"%d mdB steps: %d, real DRC gain: %d mdB\n",
digital_gain, step, i, i * step);
}
wm8994_write(codec, WM8994_AIF1_DRC1_4, val);
}
/*
*
* Declaring the controling misc devices
*
*/
static ssize_t debug_log_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return sprintf(buf, "%u\n", debug_log_level);
}
static ssize_t debug_log_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
sscanf(buf, "%hu", &debug_log_level);
return size;
}
#ifdef CONFIG_SND_WM8994_EXTENSIONS_HP_LEVEL_CONTROL
static ssize_t headphone_amplifier_level_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
// output median of left and right headphone amplifier volumes
return sprintf(buf, "%u\n", (hp_level[0] + hp_level[1]) / 2);
}
static ssize_t headphone_amplifier_level_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
unsigned short vol;
if (sscanf(buf, "%hu", &vol) == 1) {
// hard limit to 62 because 63 introduces distortions
if (vol > 62)
vol = 62;
// left and right are set to the same volumes by this control
hp_level[0] = hp_level[1] = vol;
update_digital_gain(false);
update_hpvol(true);
}
return size;
}
#endif
#define DECLARE_BOOL_SHOW(name) \
static ssize_t name##_show(struct device *dev, \
struct device_attribute *attr, char *buf) \
{ \
return sprintf(buf,"%u\n",(name ? 1 : 0)); \
}
#define DECLARE_BOOL_STORE_UPDATE_WITH_MUTE(name, updater, with_mute) \
static ssize_t name##_store(struct device *dev, struct device_attribute *attr, \
const char *buf, size_t size) \
{ \
unsigned short state; \
if (sscanf(buf, "%hu", &state) == 1) { \
name = state == 0 ? false : true; \
if (debug_log(LOG_INFOS)) \
printk("wm8994_extensions: %s: %u\n", #updater, state); \
updater(with_mute); \
} \
return size; \
}
#ifdef NEXUS_S
DECLARE_BOOL_SHOW(speaker_tuning);
DECLARE_BOOL_STORE_UPDATE_WITH_MUTE(speaker_tuning,
update_speaker_tuning,
false);
#endif
#ifdef CONFIG_SND_WM8994_EXTENSIONS_FM
DECLARE_BOOL_SHOW(fm_radio_headset_restore_bass);
DECLARE_BOOL_STORE_UPDATE_WITH_MUTE(fm_radio_headset_restore_bass,
update_fm_radio_headset_restore_freqs,
true);
DECLARE_BOOL_SHOW(fm_radio_headset_restore_highs);
DECLARE_BOOL_STORE_UPDATE_WITH_MUTE(fm_radio_headset_restore_highs,
update_fm_radio_headset_restore_freqs,
true);
DECLARE_BOOL_SHOW(fm_radio_headset_normalize_gain);
DECLARE_BOOL_STORE_UPDATE_WITH_MUTE(fm_radio_headset_normalize_gain,
update_fm_radio_headset_normalize_gain,
false);
#endif
#ifdef CONFIG_SND_WM8994_EXTENSIONS_RECORD_PRESETS
static ssize_t recording_preset_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%d\n", recording_preset);
}
static ssize_t recording_preset_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
unsigned short preset_number;
if (sscanf(buf, "%hu", &preset_number) == 1) {
recording_preset = preset_number;
update_recording_preset(false);
}
return size;
}
#endif
DECLARE_BOOL_SHOW(dac_osr128);
DECLARE_BOOL_STORE_UPDATE_WITH_MUTE(dac_osr128,
update_osr128,
false);
DECLARE_BOOL_SHOW(adc_osr128);
DECLARE_BOOL_STORE_UPDATE_WITH_MUTE(adc_osr128,
update_osr128,
false);
#ifndef GALAXY_TAB_TEGRA
DECLARE_BOOL_SHOW(fll_tuning);
DECLARE_BOOL_STORE_UPDATE_WITH_MUTE(fll_tuning,
update_fll_tuning,
false);
#endif
DECLARE_BOOL_SHOW(mono_downmix);
DECLARE_BOOL_STORE_UPDATE_WITH_MUTE(mono_downmix,
update_mono_downmix,
false);
DECLARE_BOOL_SHOW(dac_direct);
DECLARE_BOOL_STORE_UPDATE_WITH_MUTE(dac_direct,
update_dac_direct,
false);
#ifdef CONFIG_PHONE_ARIES_CDMA
static ssize_t incall_boost_rcv_show(struct device* dev, struct device_attribute* attr,
char* buf)
{
return sprintf( buf, "%d\n", incall_boost_rcv >> WM8994_AIF2DAC_BOOST_SHIFT );
}
static ssize_t incall_boost_rcv_store( struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size )
{
unsigned short newval = 2;
if ( sscanf( buf, "%hd", &newval ) == 1 )
{
if ( newval > 3 )
{
newval = 3;
}
incall_boost_rcv = newval << WM8994_AIF2DAC_BOOST_SHIFT;
wm8994_write(codec, WM8994_AIF2_CONTROL_2, incall_boost_rcv);
}
return size;
}
static ssize_t incall_boost_bt_show(struct device* dev, struct device_attribute* attr,
char* buf)
{
return sprintf( buf, "%d\n", incall_boost_bt >> WM8994_AIF2DAC_BOOST_SHIFT );
}
static ssize_t incall_boost_bt_store( struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size )
{
unsigned short newval = 2;
if ( sscanf( buf, "%hd", &newval ) == 1 )
{
if ( newval > 3 )
{
newval = 3;
}
incall_boost_bt = newval << WM8994_AIF2DAC_BOOST_SHIFT;
wm8994_write(codec, WM8994_AIF2_CONTROL_2, incall_boost_bt);
}
return size;
}
static ssize_t incall_boost_spk_show(struct device* dev, struct device_attribute* attr,
char* buf)
{
return sprintf( buf, "%d\n", incall_boost_spk >> WM8994_AIF2DAC_BOOST_SHIFT );
}
static ssize_t incall_boost_spk_store( struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size )
{
unsigned short newval = 2;
if ( sscanf( buf, "%hd", &newval ) == 1 )
{
if ( newval > 3 )
{
newval = 3;
}
incall_boost_spk = newval << WM8994_AIF2DAC_BOOST_SHIFT;
wm8994_write(codec, WM8994_AIF2_CONTROL_2, incall_boost_spk);
}
return size;
}
static ssize_t incall_boost_hp_show(struct device* dev, struct device_attribute* attr,
char* buf)
{
return sprintf( buf, "%d\n", incall_boost_hp >> WM8994_AIF2DAC_BOOST_SHIFT );
}
static ssize_t incall_boost_hp_store( struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size )
{
unsigned short newval = 2;
if ( sscanf( buf, "%hd", &newval ) == 1 )
{
if ( newval > 3 )
{
newval = 3;
}
incall_boost_hp = newval << WM8994_AIF2DAC_BOOST_SHIFT;
wm8994_write(codec, WM8994_AIF2_CONTROL_2, incall_boost_hp);
}
return size;
}
void update_mic_gain(unsigned short gain)
{
unsigned short val = wm8994_read(codec, WM8994_LEFT_LINE_INPUT_1_2_VOLUME );
val &= ~WM8994_IN1L_VOL_MASK;
val |= WM8994_IN1L_VU | gain;
wm8994_write(codec, WM8994_LEFT_LINE_INPUT_1_2_VOLUME, val);
}
static ssize_t incall_mic_gain_rcv_show( struct device* dev,
struct device_attribute* attr,
char* buf)
{
return sprintf( buf, "%d\n", incall_mic_gain_rcv );
}
static ssize_t incall_mic_gain_rcv_store( struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
DECLARE_WM8994(codec);
unsigned short newGain = 0;
if ( sscanf( buf, "%hd", &newGain ) == 1 )
{
if ( newGain > 0x1f )
{
newGain = 0x1f;
}
incall_mic_gain_rcv = newGain;
if ( wm8994->codec_state & CALL_ACTIVE &&
wm8994->cur_path == RCV )
{
update_mic_gain(incall_mic_gain_rcv);
}
}
return size;
}
static ssize_t incall_mic_gain_spk_show( struct device* dev,
struct device_attribute* attr,
char* buf)
{
return sprintf( buf, "%d\n", incall_mic_gain_spk );
}
static ssize_t incall_mic_gain_spk_store( struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
DECLARE_WM8994(codec);
unsigned short newGain = 0;
if ( sscanf( buf, "%hd", &newGain ) == 1 )
{
if ( newGain > 0x1f )
{
newGain = 0x1f;
}
incall_mic_gain_spk = newGain;
if ( wm8994->codec_state & CALL_ACTIVE &&
wm8994->cur_path == SPK )
{
update_mic_gain(incall_mic_gain_spk);
}
}
return size;
}
static ssize_t incall_mic_gain_hp_show( struct device* dev,
struct device_attribute* attr,
char* buf)
{
return sprintf( buf, "%d\n", incall_mic_gain_hp );
}
static ssize_t incall_mic_gain_hp_store( struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
DECLARE_WM8994(codec);
unsigned short newGain = 0;
if ( sscanf( buf, "%hd", &newGain ) == 1 )
{
if ( newGain > 0x1f )
{
newGain = 0x1f;
}
incall_mic_gain_hp = newGain;
if ( wm8994->codec_state & CALL_ACTIVE &&
wm8994->cur_path == HP )
{
update_mic_gain(incall_mic_gain_hp);
}
}
return size;
}
static ssize_t incall_mic_gain_hp_no_mic_show( struct device* dev,
struct device_attribute* attr,
char* buf)
{
return sprintf( buf, "%d\n", incall_mic_gain_hp_no_mic );
}
static ssize_t incall_mic_gain_hp_no_mic_store( struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
DECLARE_WM8994(codec);
unsigned short newGain = 0;
if ( sscanf( buf, "%hd", &newGain ) == 1 )
{
if ( newGain > 0x1f )
{
newGain = 0x1f;
}
incall_mic_gain_hp_no_mic = newGain;
if ( wm8994->codec_state & CALL_ACTIVE &&
wm8994->cur_path == HP_NO_MIC )
{
update_mic_gain(incall_mic_gain_hp_no_mic);
}
}
return size;
}
#endif
static ssize_t digital_gain_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%d\n", digital_gain);
}
static ssize_t digital_gain_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
int new_digital_gain;
if (sscanf(buf, "%d", &new_digital_gain) == 1) {
if (new_digital_gain <= 36000 && new_digital_gain >= -71625) {
if (new_digital_gain > digital_gain) {
// reduce analog volume first
digital_gain = new_digital_gain;
#ifdef CONFIG_SND_WM8994_EXTENSIONS_HP_LEVEL_CONTROL
update_hpvol(false);
#endif
update_digital_gain(false);
} else {
// reduce digital volume first
digital_gain = new_digital_gain;
update_digital_gain(false);
#ifdef CONFIG_SND_WM8994_EXTENSIONS_HP_LEVEL_CONTROL
update_hpvol(false);
#endif
}
}
apply_saturation_prevention_drc();
}
return size;
}
DECLARE_BOOL_SHOW(headphone_eq);
#define DECLARE_EQ_GAIN_SHOW(band) \
static ssize_t headphone_eq_b##band##_gain_show(struct device *dev, \
struct device_attribute *attr, \
char *buf) \
{ \
return sprintf(buf, "%d\n", eq_gains[band - 1]); \
}
#define DECLARE_EQ_GAIN_STORE(band) \
static ssize_t headphone_eq_b##band##_gain_store(struct device *dev, \
struct device_attribute *attr, \
const char *buf, size_t size) \
{ \
short new_gain; \
if (sscanf(buf, "%hd", &new_gain) == 1) { \
if (new_gain >= -12 && new_gain <= 12) { \
smooth_apply_eq_band_gain(band - 1, \
eq_gains[band - 1], \
new_gain, \
headphone_eq); \
eq_gains[band - 1] = new_gain; \
} \
} \
return size; \
}
static ssize_t headphone_eq_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
unsigned short state;
bool current_state;
int i;
short eq_gains_copy[ARRAY_SIZE(eq_gains)];
if (sscanf(buf, "%hu", &state) == 1) {
current_state = state == 0 ? false : true;
if (debug_log(LOG_INFOS))
printk("wm8994_extensions: EQ activation: %u\n", state);
if (current_state) {
// fade from 0dB each EQ band
headphone_eq = current_state;
for (i = 0; i < ARRAY_SIZE(eq_bands); i++)
smooth_apply_eq_band_gain(i, 0, eq_gains[i],
current_state);
} else {
// fade to 0dB each EQ band
for (i = 0; i < ARRAY_SIZE(eq_bands); i++) {
eq_gains_copy[i] = eq_gains[i];
smooth_apply_eq_band_gain(i, eq_gains[i], 0,
current_state);
}
// restore original gains in driver memory not codec
for (i = 0; i < ARRAY_SIZE(eq_bands); i++)
eq_gains[i] = eq_gains_copy[i];
headphone_eq = current_state;
}
}
return size;
}
DECLARE_EQ_GAIN_SHOW(1);
DECLARE_EQ_GAIN_STORE(1);
DECLARE_EQ_GAIN_SHOW(2);
DECLARE_EQ_GAIN_STORE(2);
DECLARE_EQ_GAIN_SHOW(3);
DECLARE_EQ_GAIN_STORE(3);
DECLARE_EQ_GAIN_SHOW(4);
DECLARE_EQ_GAIN_STORE(4);
DECLARE_EQ_GAIN_SHOW(5);
DECLARE_EQ_GAIN_STORE(5);
static ssize_t headphone_eq_bands_values_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
int i;
int j;
int k = 0;
int first_reg = WM8994_AIF1_DAC1_EQ_BAND_1_A;
int bands_size = ARRAY_SIZE(eq_bands);
char *name;
for (i = 0; i < bands_size; i++)
for (j = 0; j < eq_bands[i]; j++) {
// display 3-coef bands properly (hi & lo shelf)
if (j + 1 == eq_bands[i])
name = eq_band_coef_names[3];
else
name = eq_band_coef_names[j];
sprintf(buf, "%s%d %s 0x%04X\n", buf,
i + 1, name,
wm8994_read(codec, first_reg + k));
k++;
}
return sprintf(buf, "%s", buf);
}
static ssize_t headphone_eq_bands_values_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
int i;
short unsigned int val;
short unsigned int band;
char coef_name[2];
unsigned int bytes_read = 0;
while (sscanf(buf, "%hu %s %hx%n",
&band, coef_name, &val, &bytes_read) == 3) {
buf += bytes_read;
if (band < 1 || band > 5)
continue;
for (i = 0; i < ARRAY_SIZE(eq_band_coef_names); i++) {
// loop through band coefficient letters
if (strncmp(eq_band_coef_names[i], coef_name, 2) == 0) {
if (eq_bands[band - 1] == 3 && i == 3)
// deal with high and low shelves
eq_band_values[band - 1][2] = val;
else
// parametric bands
eq_band_values[band - 1][i] = val;
if (debug_log(LOG_INFOS))
printk("wm8994_extensions: read EQ from "
"sysfs: EQ Band %hd %s: 0x%04X\n"
, band, coef_name, val);
break;
}
}
}
return size;
}
DECLARE_BOOL_SHOW(stereo_expansion);
DECLARE_BOOL_STORE_UPDATE_WITH_MUTE(stereo_expansion,
update_stereo_expansion,
false);
static ssize_t stereo_expansion_gain_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return sprintf(buf, "%u\n", stereo_expansion_gain);
}
static ssize_t stereo_expansion_gain_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
short unsigned val;
if (sscanf(buf, "%hu", &val) == 1)
if (val >= 0 && val < 32) {
stereo_expansion_gain = val;
update_stereo_expansion(false);
}
return size;
}
#ifdef CONFIG_SND_WM8994_EXTENSIONS_DEVELOPMENT
static ssize_t show_wm8994_register_dump(struct device *dev,
struct device_attribute *attr,
char *buf)
{
// modified version of register_dump from wm8994_aries.c
// r = wm8994 register
int r;
for (r = 0; r <= 0x6; r++)
sprintf(buf, "0x%X 0x%X\n", r, wm8994_read(codec, r));
sprintf(buf, "%s0x%X 0x%X\n", buf, 0x15, wm8994_read(codec, 0x15));
for (r = 0x18; r <= 0x3C; r++)
sprintf(buf, "%s0x%X 0x%X\n", buf, r, wm8994_read(codec, r));
sprintf(buf, "%s0x%X 0x%X\n", buf, 0x4C, wm8994_read(codec, 0x4C));
for (r = 0x51; r <= 0x5C; r++)
sprintf(buf, "%s0x%X 0x%X\n", buf, r, wm8994_read(codec, r));
sprintf(buf, "%s0x%X 0x%X\n", buf, 0x60, wm8994_read(codec, 0x60));
sprintf(buf, "%s0x%X 0x%X\n", buf, 0x101, wm8994_read(codec, 0x101));
sprintf(buf, "%s0x%X 0x%X\n", buf, 0x110, wm8994_read(codec, 0x110));
sprintf(buf, "%s0x%X 0x%X\n", buf, 0x111, wm8994_read(codec, 0x111));
for (r = 0x200; r <= 0x212; r++)
sprintf(buf, "%s0x%X 0x%X\n", buf, r, wm8994_read(codec, r));
for (r = 0x220; r <= 0x224; r++)
sprintf(buf, "%s0x%X 0x%X\n", buf, r, wm8994_read(codec, r));
for (r = 0x240; r <= 0x244; r++)
sprintf(buf, "%s0x%X 0x%X\n", buf, r, wm8994_read(codec, r));
for (r = 0x300; r <= 0x317; r++)
sprintf(buf, "%s0x%X 0x%X\n", buf, r, wm8994_read(codec, r));
for (r = 0x400; r <= 0x411; r++)
sprintf(buf, "%s0x%X 0x%X\n", buf, r, wm8994_read(codec, r));
for (r = 0x420; r <= 0x423; r++)
sprintf(buf, "%s0x%X 0x%X\n", buf, r, wm8994_read(codec, r));
for (r = 0x440; r <= 0x444; r++)
sprintf(buf, "%s0x%X 0x%X\n", buf, r, wm8994_read(codec, r));
for (r = 0x450; r <= 0x454; r++)
sprintf(buf, "%s0x%X 0x%X\n", buf, r, wm8994_read(codec, r));
for (r = 0x480; r <= 0x493; r++)
sprintf(buf, "%s0x%X 0x%X\n", buf, r, wm8994_read(codec, r));
for (r = 0x4A0; r <= 0x4B3; r++)
sprintf(buf, "%s0x%X 0x%X\n", buf, r, wm8994_read(codec, r));
for (r = 0x500; r <= 0x503; r++)
sprintf(buf, "%s0x%X 0x%X\n", buf, r, wm8994_read(codec, r));
sprintf(buf, "%s0x%X 0x%X\n", buf, 0x510, wm8994_read(codec, 0x510));
sprintf(buf, "%s0x%X 0x%X\n", buf, 0x520, wm8994_read(codec, 0x520));
sprintf(buf, "%s0x%X 0x%X\n", buf, 0x521, wm8994_read(codec, 0x521));
for (r = 0x540; r <= 0x544; r++)
sprintf(buf, "%s0x%X 0x%X\n", buf, r, wm8994_read(codec, r));
for (r = 0x580; r <= 0x593; r++)
sprintf(buf, "%s0x%X 0x%X\n", buf, r, wm8994_read(codec, r));
for (r = 0x600; r <= 0x614; r++)
sprintf(buf, "%s0x%X 0x%X\n", buf, r, wm8994_read(codec, r));
sprintf(buf, "%s0x%X 0x%X\n", buf, 0x620, wm8994_read(codec, 0x620));
sprintf(buf, "%s0x%X 0x%X\n", buf, 0x621, wm8994_read(codec, 0x621));
for (r = 0x700; r <= 0x70A; r++)
sprintf(buf, "%s0x%X 0x%X\n", buf, r, wm8994_read(codec, r));
return sprintf(buf, "%s", buf);
}
static ssize_t store_wm8994_write(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
short unsigned int reg = 0;
short unsigned int val = 0;
int unsigned bytes_read = 0;
while (sscanf(buf, "%hx %hx%n", ®, &val, &bytes_read) == 2) {
buf += bytes_read;
if (debug_log(LOG_INFOS))
printk("wm8994_extensions: read from sysfs: %X, %X\n",
reg, val);
bypass_write_extension = true;
wm8994_write(codec, reg, val);
bypass_write_extension = false;
}
return size;
}
#endif
static ssize_t wm8994_extensions_version(struct device *dev,
struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%u\n", WM8994_EXTENSIONS_VERSION);
}
DECLARE_BOOL_SHOW(enable);
static ssize_t enable_store(struct device *dev,
struct device_attribute *attr, const char *buf,
size_t size)
{
unsigned short state;
bool bool_state;
if (sscanf(buf, "%hu", &state) == 1) {
bool_state = state == 0 ? false : true;
if (state != enable) {
enable = bool_state;
update_enable();
}
}
return size;
}
static DEVICE_ATTR(debug_log, S_IRUGO | S_IWUGO,
debug_log_show,
debug_log_store);
#ifdef CONFIG_SND_WM8994_EXTENSIONS_HP_LEVEL_CONTROL
static DEVICE_ATTR(headphone_amplifier_level, S_IRUGO | S_IWUGO,
headphone_amplifier_level_show,
headphone_amplifier_level_store);
#endif
#ifdef NEXUS_S
static DEVICE_ATTR(speaker_tuning, S_IRUGO | S_IWUGO,
speaker_tuning_show,
speaker_tuning_store);
#endif
#ifdef CONFIG_SND_WM8994_EXTENSIONS_FM
static DEVICE_ATTR(fm_radio_headset_restore_bass, S_IRUGO | S_IWUGO,
fm_radio_headset_restore_bass_show,
fm_radio_headset_restore_bass_store);
static DEVICE_ATTR(fm_radio_headset_restore_highs, S_IRUGO | S_IWUGO,
fm_radio_headset_restore_highs_show,
fm_radio_headset_restore_highs_store);
static DEVICE_ATTR(fm_radio_headset_normalize_gain, S_IRUGO | S_IWUGO,
fm_radio_headset_normalize_gain_show,
fm_radio_headset_normalize_gain_store);
#endif
#ifdef CONFIG_SND_WM8994_EXTENSIONS_RECORD_PRESETS
static DEVICE_ATTR(recording_preset, S_IRUGO | S_IWUGO,
recording_preset_show,
recording_preset_store);
#endif
#ifdef CONFIG_PHONE_ARIES_CDMA
static DEVICE_ATTR(incall_boost_rcv, S_IRUGO | S_IWUGO,
incall_boost_rcv_show,
incall_boost_rcv_store);
static DEVICE_ATTR(incall_boost_bt, S_IRUGO | S_IWUGO,
incall_boost_bt_show,
incall_boost_bt_store);
static DEVICE_ATTR(incall_boost_spk, S_IRUGO | S_IWUGO,
incall_boost_spk_show,
incall_boost_spk_store);
static DEVICE_ATTR(incall_boost_hp, S_IRUGO | S_IWUGO,
incall_boost_hp_show,
incall_boost_hp_store);
static DEVICE_ATTR(incall_mic_gain_rcv, S_IRUGO | S_IWUGO,
incall_mic_gain_rcv_show,
incall_mic_gain_rcv_store);
static DEVICE_ATTR(incall_mic_gain_spk, S_IRUGO | S_IWUGO,
incall_mic_gain_spk_show,
incall_mic_gain_spk_store);
static DEVICE_ATTR(incall_mic_gain_hp, S_IRUGO | S_IWUGO,
incall_mic_gain_hp_show,
incall_mic_gain_hp_store);
static DEVICE_ATTR(incall_mic_gain_hp_no_mic, S_IRUGO | S_IWUGO,
incall_mic_gain_hp_no_mic_show,
incall_mic_gain_hp_no_mic_store);
#endif
static DEVICE_ATTR(dac_osr128, S_IRUGO | S_IWUGO,
dac_osr128_show,
dac_osr128_store);
static DEVICE_ATTR(adc_osr128, S_IRUGO | S_IWUGO,
adc_osr128_show,
adc_osr128_store);
#ifndef GALAXY_TAB_TEGRA
static DEVICE_ATTR(fll_tuning, S_IRUGO | S_IWUGO,
fll_tuning_show,
fll_tuning_store);
#endif
static DEVICE_ATTR(dac_direct, S_IRUGO | S_IWUGO,
dac_direct_show,
dac_direct_store);
static DEVICE_ATTR(digital_gain, S_IRUGO | S_IWUGO,
digital_gain_show,
digital_gain_store);
static DEVICE_ATTR(headphone_eq, S_IRUGO | S_IWUGO,
headphone_eq_show,
headphone_eq_store);
static DEVICE_ATTR(headphone_eq_b1_gain, S_IRUGO | S_IWUGO,
headphone_eq_b1_gain_show,
headphone_eq_b1_gain_store);
static DEVICE_ATTR(headphone_eq_b2_gain, S_IRUGO | S_IWUGO,
headphone_eq_b2_gain_show,
headphone_eq_b2_gain_store);
static DEVICE_ATTR(headphone_eq_b3_gain, S_IRUGO | S_IWUGO,
headphone_eq_b3_gain_show,
headphone_eq_b3_gain_store);
static DEVICE_ATTR(headphone_eq_b4_gain, S_IRUGO | S_IWUGO,
headphone_eq_b4_gain_show,
headphone_eq_b4_gain_store);
static DEVICE_ATTR(headphone_eq_b5_gain, S_IRUGO | S_IWUGO,
headphone_eq_b5_gain_show,
headphone_eq_b5_gain_store);
static DEVICE_ATTR(headphone_eq_bands_values, S_IRUGO | S_IWUGO,
headphone_eq_bands_values_show,
headphone_eq_bands_values_store);
static DEVICE_ATTR(stereo_expansion, S_IRUGO | S_IWUGO,
stereo_expansion_show,
stereo_expansion_store);
static DEVICE_ATTR(stereo_expansion_gain, S_IRUGO | S_IWUGO,
stereo_expansion_gain_show,
stereo_expansion_gain_store);
static DEVICE_ATTR(mono_downmix, S_IRUGO | S_IWUGO,
mono_downmix_show,
mono_downmix_store);
#ifdef CONFIG_SND_WM8994_EXTENSIONS_DEVELOPMENT
static DEVICE_ATTR(wm8994_register_dump, S_IRUGO,
show_wm8994_register_dump,
NULL);
static DEVICE_ATTR(wm8994_write, S_IWUSR,
NULL,
store_wm8994_write);
#endif
static DEVICE_ATTR(version, S_IRUGO,
wm8994_extensions_version,
NULL);
static DEVICE_ATTR(enable, S_IRUGO | S_IWUGO,
enable_show,
enable_store);
static struct attribute *wm8994_extensions_attributes[] = {
&dev_attr_debug_log.attr,
#ifdef CONFIG_SND_WM8994_EXTENSIONS_HP_LEVEL_CONTROL
&dev_attr_headphone_amplifier_level.attr,
#endif
#ifdef NEXUS_S
&dev_attr_speaker_tuning.attr,
#endif
#ifdef CONFIG_SND_WM8994_EXTENSIONS_FM
&dev_attr_fm_radio_headset_restore_bass.attr,
&dev_attr_fm_radio_headset_restore_highs.attr,
&dev_attr_fm_radio_headset_normalize_gain.attr,
#endif
#ifdef CONFIG_SND_WM8994_EXTENSIONS_RECORD_PRESETS
&dev_attr_recording_preset.attr,
#endif
#ifdef CONFIG_PHONE_ARIES_CDMA
&dev_attr_incall_boost_rcv.attr,
&dev_attr_incall_boost_bt.attr,
&dev_attr_incall_boost_spk.attr,
&dev_attr_incall_boost_hp.attr,
&dev_attr_incall_mic_gain_rcv.attr,
&dev_attr_incall_mic_gain_spk.attr,
&dev_attr_incall_mic_gain_hp.attr,
&dev_attr_incall_mic_gain_hp_no_mic.attr,
#endif
&dev_attr_dac_osr128.attr,
&dev_attr_adc_osr128.attr,
#ifndef GALAXY_TAB_TEGRA
&dev_attr_fll_tuning.attr,
#endif
&dev_attr_dac_direct.attr,
&dev_attr_digital_gain.attr,
&dev_attr_headphone_eq.attr,
&dev_attr_headphone_eq_b1_gain.attr,
&dev_attr_headphone_eq_b2_gain.attr,
&dev_attr_headphone_eq_b3_gain.attr,
&dev_attr_headphone_eq_b4_gain.attr,
&dev_attr_headphone_eq_b5_gain.attr,
&dev_attr_headphone_eq_bands_values.attr,
&dev_attr_stereo_expansion.attr,
&dev_attr_stereo_expansion_gain.attr,
&dev_attr_mono_downmix.attr,
#ifdef CONFIG_SND_WM8994_EXTENSIONS_DEVELOPMENT
&dev_attr_wm8994_register_dump.attr,
&dev_attr_wm8994_write.attr,
#endif
&dev_attr_version.attr,
NULL
};
static struct attribute *wm8994_extensions_control_attributes[] = {
&dev_attr_enable.attr,
NULL
};
static struct attribute_group wm8994_extensions_group = {
.attrs = wm8994_extensions_attributes,
};
static struct attribute_group wm8994_extensions_control_group = {
.attrs = wm8994_extensions_control_attributes,
};
static struct miscdevice wm8994_extensions_device = {
.minor = MISC_DYNAMIC_MINOR,
.name = "voodoo_sound",
};
static struct miscdevice wm8994_extensions_control_device = {
.minor = MISC_DYNAMIC_MINOR,
.name = "voodoo_sound_control",
};
void wm8994_extensions_pcm_remove()
{
printk("wm8994_extensions: removing driver v%d\n", WM8994_EXTENSIONS_VERSION);
sysfs_remove_group(&wm8994_extensions_device.this_device->kobj,
&wm8994_extensions_group);
misc_deregister(&wm8994_extensions_device);
}
void update_enable()
{
if (enable) {
printk("wm8994_extensions: initializing driver v%d\n",
WM8994_EXTENSIONS_VERSION);
#ifdef CONFIG_SND_WM8994_EXTENSIONS_DEVELOPMENT
printk("wm8994_extensions: codec development tools enabled\n");
#endif
misc_register(&wm8994_extensions_device);
if (sysfs_create_group(&wm8994_extensions_device.this_device->kobj,
&wm8994_extensions_group) < 0) {
printk("%s sysfs_create_group fail\n", __FUNCTION__);
pr_err("Failed to create sysfs group for (%s)!\n",
wm8994_extensions_device.name);
}
} else
wm8994_extensions_pcm_remove();
}
/*
*
* Driver Hooks
*
*/
#ifdef CONFIG_SND_WM8994_EXTENSIONS_FM
void wm8994_extensions_fmradio_headset()
{
// global kill switch
if (!enable)
return;
if (!fm_radio_headset_restore_bass
&& !fm_radio_headset_restore_highs
&& !fm_radio_headset_normalize_gain)
return;
update_fm_radio_headset_restore_freqs(false);
update_fm_radio_headset_normalize_gain(false);
}
#endif
#ifdef CONFIG_SND_WM8994_EXTENSIONS_RECORD_PRESETS
void wm8994_extensions_record_main_mic()
{
// global kill switch
if (!enable)
return;
if (recording_preset == 0)
return;
origin_recgain = wm8994_read(codec, WM8994_LEFT_LINE_INPUT_1_2_VOLUME);
origin_recgain_mixer = wm8994_read(codec, WM8994_INPUT_MIXER_3);
update_recording_preset(false);
}
#endif
#ifdef NEXUS_S
void wm8994_extensions_playback_speaker()
{
// global kill switch
if (!enable)
return;
if (!speaker_tuning)
return;
update_speaker_tuning(false);
}
#endif
unsigned int wm8994_extensions_write(struct snd_soc_codec *codec_,
unsigned int reg, unsigned int value)
{
DECLARE_WM8994(codec_);
// global kill switch
if (!enable)
return value;
// modify some registers before those being written to the codec
// be sure our pointer to codec is up to date
codec = codec_;
if (!bypass_write_extension) {
#ifdef CONFIG_SND_WM8994_EXTENSIONS_HP_LEVEL_CONTROL
if (is_path(HEADPHONES)
&& !(wm8994->codec_state & CALL_ACTIVE)) {
if (reg == WM8994_LEFT_OUTPUT_VOLUME)
value =
(WM8994_HPOUT1_VU |
WM8994_HPOUT1L_MUTE_N |
hpvol(0));
if (reg == WM8994_RIGHT_OUTPUT_VOLUME)
value =
(WM8994_HPOUT1_VU |
WM8994_HPOUT1R_MUTE_N |
hpvol(1));
}
#endif
#ifdef CONFIG_SND_WM8994_EXTENSIONS_FM
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
// FM tuning virtual hook for Gingerbread
if (is_path(RADIO_HEADPHONES)) {
if (reg == WM8994_AIF2_DRC_1
|| reg == WM8994_AIF2_DAC_FILTERS_1)
wm8994_extensions_fmradio_headset();
}
#else
// FM tuning virtual hook for Froyo
if (is_path(RADIO_HEADPHONES)) {
if (reg == WM8994_INPUT_MIXER_2
|| reg == WM8994_AIF2_DRC_1
|| reg == WM8994_ANALOGUE_HP_1)
wm8994_extensions_fmradio_headset();
}
#endif
#endif
// global Oversampling tuning
if (reg == WM8994_OVERSAMPLING)
value = osr128_get_value(value);
#ifndef GALAXY_TAB_TEGRA
// global Anti-Jitter tuning
if (reg == WM8994_FLL1_CONTROL_4)
value = fll_tuning_get_value(value);
#endif
// global Mono downmix tuning
if (reg == WM8994_AIF1_DAC1_FILTERS_1
|| reg == WM8994_AIF1_DAC2_FILTERS_1
|| reg == WM8994_AIF2_DAC_FILTERS_1)
value = mono_downmix_get_value(value, false);
// DAC direct tuning virtual hook
if (reg == WM8994_OUTPUT_MIXER_1
|| reg == WM8994_OUTPUT_MIXER_2)
value = dac_direct_get_value(value, false);
// Digital Headroom virtual hook
if (reg == WM8994_AIF1_DAC1_LEFT_VOLUME
|| reg == WM8994_AIF1_DAC1_RIGHT_VOLUME)
value = digital_gain_get_value(value);
// Headphones EQ & 3D virtual hook
if (reg == WM8994_AIF1_DAC1_FILTERS_1
|| reg == WM8994_AIF1_DAC2_FILTERS_1
|| reg == WM8994_AIF2_DAC_FILTERS_1) {
bypass_write_extension = true;
apply_saturation_prevention_drc();
update_headphone_eq(true);
update_stereo_expansion(false);
bypass_write_extension = false;
}
}
if (debug_log(LOG_VERBOSE))
printk("wm8994_extensions: wm8994_write 0x%03X 0x%04X "
// log every write to dmesg
#ifdef NEXUS_S
"codec_state=%u, stream_state=%u, "
"cur_path=%i, rec_path=%i, "
"power_state=%i\n",
reg, value,
wm8994->codec_state, wm8994->stream_state,
wm8994->cur_path, wm8994->rec_path,
wm8994->power_state);
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
"codec_state=%u, stream_state=%u, "
"cur_path=%i, rec_path=%i, "
#if !defined(M110S) && !defined(GALAXY_TAB_TEGRA)
"fmradio_path=%i, fmr_mix_path=%i, "
#endif
#ifndef GALAXY_TAB
"input_source=%i, "
#endif
#if !defined(M110S) && !defined(GALAXY_TAB_TEGRA) && !defined(GALAXY_TAB)
"output_source=%i, "
#endif
"power_state=%i\n",
reg, value,
wm8994->codec_state, wm8994->stream_state,
#if !defined(M110S) && !defined(GALAXY_TAB_TEGRA)
wm8994->fmradio_path, wm8994->fmr_mix_path,
#endif
wm8994->cur_path, wm8994->rec_path,
#ifndef GALAXY_TAB
wm8994->input_source,
#endif
#if !defined(M110S) && !defined(GALAXY_TAB_TEGRA) && !defined(GALAXY_TAB)
wm8994->output_source,
#endif
wm8994->power_state);
#else
"codec_state=%u, stream_state=%u, "
"cur_path=%i, rec_path=%i, "
#if !defined(M110S) && !defined(GALAXY_TAB_TEGRA)
"fmradio_path=%i, fmr_mix_path=%i, "
#endif
#ifdef CONFIG_S5PC110_KEPLER_BOARD
"call_record_path=%i, call_record_ch=%i, "
"AUDIENCE_state=%i, "
"Fac_SUB_MIC_state=%i, TTY_state=%i, "
#endif
"power_state=%i, "
#if !defined(M110S) && !defined(GALAXY_TAB_TEGRA)
"recognition_active=%i, ringtone_active=%i"
#endif
"\n",
reg, value,
wm8994->codec_state, wm8994->stream_state,
wm8994->cur_path, wm8994->rec_path,
#if !defined(M110S) && !defined(GALAXY_TAB_TEGRA)
wm8994->fmradio_path, wm8994->fmr_mix_path,
#endif
#ifdef CONFIG_S5PC110_KEPLER_BOARD
wm8994->call_record_path, wm8994->call_record_ch,
wm8994->AUDIENCE_state,
wm8994->Fac_SUB_MIC_state, wm8994->TTY_state,
#endif
wm8994->power_state
#if !defined(M110S) && !defined(GALAXY_TAB_TEGRA)
,wm8994->recognition_active,
wm8994->ringtone_active
#endif
);
#endif
#endif
return value;
}
void wm8994_extensions_pcm_probe(struct snd_soc_codec *codec_)
{
enable = true;
update_enable();
misc_register(&wm8994_extensions_control_device);
if (sysfs_create_group(&wm8994_extensions_control_device.this_device->kobj,
&wm8994_extensions_control_group) < 0) {
printk("%s sysfs_create_group fail\n", __FUNCTION__);
pr_err("Failed to create sysfs group for device (%s)!\n",
wm8994_extensions_control_device.name);
}
// make a copy of the codec pointer
codec = codec_;
// initialize eq_band_values[] from default codec EQ values
load_current_eq_values();
}
|