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
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
|
From 3657fc661cea2b120a7516cb66002fcd3af34e35 Mon Sep 17 00:00:00 2001
From: R, Dharageswari <dharageswari.r@intel.com>
Date: Thu, 29 Apr 2010 20:23:41 +0530
Subject: [PATCH] ADR-Post-Beta-0.05.002.03-3/8-Moorestown Audio Drivers: SST interface modules
This patch adds the SST driver interface module. Interface module is the
one which talks to upper/other layer in the SST Driver
intel_sst_interface.c - implements the MAD driver registration & deregistration
functions. SST driver is also a character driver, so that player/middleware can
communicate with SST driver. All char driver routines like open, close, read,
write and ioctl are implemented here. The ioctl operations are used by
middleware/players to open/close, control and configure astream as well as to
transfer the data.
intel_sst_ioctl.h - exposes the IOCTL definition for players/middleware
as well as the various structure for passing stream parameters
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
new file: include/sound/intel_sst_ioctl.h
new file: sound/pci/sst/intel_sst_interface.c
Patch-mainline: 2.6.35?
---
include/sound/intel_sst_ioctl.h | 390 +++++++
sound/pci/sst/intel_sst_interface.c | 2099 +++++++++++++++++++++++++++++++++++
2 files changed, 2489 insertions(+), 0 deletions(-)
create mode 100644 include/sound/intel_sst_ioctl.h
create mode 100644 sound/pci/sst/intel_sst_interface.c
diff --git a/include/sound/intel_sst_ioctl.h b/include/sound/intel_sst_ioctl.h
new file mode 100644
index 0000000..442b388
--- /dev/null
+++ b/include/sound/intel_sst_ioctl.h
@@ -0,0 +1,390 @@
+#ifndef __INTEL_SST_IOCTL_H__
+#define __INTEL_SST_IOCTL_H__
+/*
+ * intel_sst_ipc.h - Intel SST Driver for audio engine
+ *
+ * Copyright (C) 2008-10 Intel Corporation
+ * Authors: Vinod Koul <vinod.koul@intel.com>
+ * Harsha Priya <priya.harsha@intel.com>
+ * Dharageswari R <dharageswari.r@intel.com>
+ * KP Jeeja <jeeja.kp@intel.com>
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * This file defines all sst ioctls
+ */
+
+/* codec and post/pre processing related info */
+
+enum sst_codec_types {
+/* AUDIO/MUSIC CODEC Type Definitions */
+ SST_CODEC_TYPE_UNKNOWN = 0,
+ SST_CODEC_TYPE_PCM, /* Pass through Audio codec */
+ SST_CODEC_TYPE_MP3,
+ SST_CODEC_TYPE_MP24,
+ SST_CODEC_TYPE_AAC,
+ SST_CODEC_TYPE_AACP,
+ SST_CODEC_TYPE_eAACP,
+ SST_CODEC_TYPE_WMA9,
+ SST_CODEC_TYPE_WMA10,
+ SST_CODEC_TYPE_WMA10P,
+ SST_CODEC_TYPE_RA,
+ SST_CODEC_TYPE_DDAC3,
+ SST_CODEC_TYPE_STEREO_TRUE_HD,
+ SST_CODEC_TYPE_STEREO_HD_PLUS,
+
+ /* VOICE CODEC Type Definitions */
+ SST_CODEC_TYPE_VOICE_PCM = 0x21, /* Pass through voice codec */
+ SST_CODEC_SRC = 0x64,
+ SST_CODEC_MIXER = 0x65,
+ SST_CODEC_DOWN_MIXER = 0x66,
+ SST_CODEC_VOLUME_CONTROL = 0x67,
+ SST_CODEC_OEM1 = 0xC8,
+ SST_CODEC_OEM2 = 0xC9,
+};
+
+enum snd_sst_stream_ops {
+ STREAM_OPS_PLAYBACK = 0, /* Decode */
+ STREAM_OPS_CAPTURE, /* Encode */
+ STREAM_OPS_PLAYBACK_DRM, /* Play Audio/Voice */
+ STREAM_OPS_PLAYBACK_ALERT, /* Play Audio/Voice */
+ STREAM_OPS_CAPTURE_VOICE_CALL, /* CSV Voice recording */
+};
+
+enum stream_type {
+ STREAM_TYPE_MUSIC = 1,
+ STREAM_TYPE_VOICE
+};
+
+/* Firmware Version info */
+struct snd_sst_fw_version {
+ __u8 build; /* build number*/
+ __u8 minor; /* minor number*/
+ __u8 major; /* major number*/
+ __u8 type; /* build type */
+};
+
+/* Port info structure */
+struct snd_sst_port_info {
+ __u16 port_type;
+ __u16 reserved;
+};
+
+/* Mixer info structure */
+struct snd_sst_mix_info {
+ __u16 max_streams;
+ __u16 reserved;
+};
+
+/* PCM Parameters */
+struct snd_pcm_params {
+ __u16 codec; /* codec type */
+ __u8 num_chan; /* 1=Mono, 2=Stereo */
+ __u8 pcm_wd_sz; /* 16/24 - bit*/
+ __u32 brate; /* Bitrate in bits per second */
+ __u32 sfreq; /* Sampling rate in Hz */
+// __u16 frame_size;
+// __u16 samples_per_frame; /* Frame size num samples per frame */
+ __u32 buffer_size;
+ __u32 period_count; /* period elapsed time count, in samples,*/
+};
+
+/* MP3 Music Parameters Message */
+struct snd_mp3_params {
+ __u16 codec;
+ __u8 num_chan; /* 1=Mono, 2=Stereo */
+ __u8 pcm_wd_sz; /* 16/24 - bit*/
+ __u32 brate; /* Use the hard coded value. */
+ __u32 sfreq; /* Sampling freq eg. 8000, 441000, 48000 */
+ __u8 crc_check; /* crc_check - disable (0) or enable (1) */
+ __u8 op_align; /* op align 0- 16 bit, 1- MSB, 2 LSB*/
+ __u16 reserved; /* Unused */
+};
+
+#define AAC_BIT_STREAM_ADTS 0
+#define AAC_BIT_STREAM_ADIF 1
+#define AAC_BIT_STREAM_RAW 2
+
+/* AAC Music Parameters Message */
+struct snd_aac_params {
+ __u16 codec;
+ __u8 num_chan; /* 1=Mono, 2=Stereo*/
+ __u8 pcm_wd_sz; /* 16/24 - bit*/
+ __u32 brate;
+ __u32 sfreq; /* Sampling freq eg. 8000, 441000, 48000 */
+ __u32 aac_srate; /* Plain AAC decoder operating sample rate */
+ __u8 mpg_id; /* 0=MPEG-2, 1=MPEG-4 */
+ __u8 bs_format; /* input bit stream format adts=0, adif=1, raw=2 */
+ __u8 aac_profile; /* 0=Main Profile, 1=LC profile, 3=SSR profile */
+ __u8 ext_chl; /* No.of external channels */
+ __u8 aot; /* Audio object type. 1=Main , 2=LC , 3=SSR, 4=SBR*/
+ __u8 op_align; /* output alignment 0=16 bit , 1=MSB, 2= LSB align */
+ __u8 brate_type; /* 0=CBR, 1=VBR */
+ __u8 crc_check; /* crc check 0= disable, 1=enable */
+ __s8 bit_stream_format[8]; /* input bit stream format adts/adif/raw */
+ __u8 jstereo; /* Joint stereo Flag */
+ __u8 sbr_present; /* 1 = SBR Present, 0 = SBR absent, for RAW */
+ __u8 downsample; /* 1 = Downsampling ON, 0 = Downsampling OFF */
+ __u8 num_syntc_elems; /* 1- Mono/stereo, 0 - Dual Mono, 0 - for raw */
+ __s8 syntc_id[2]; /* 0 for ID_SCE(Dula Mono), -1 for raw */
+ __s8 syntc_tag[2]; /* raw - -1 and 0 -16 for rest of the streams */
+ __u8 pce_present; /* Flag. 1- present 0 - not present, for RAW */
+ __u8 sbr_type; /* sbr_type: 0-plain aac, 1-aac-v1, 2-aac-v2 */
+ __u8 outchmode; /* 0- mono, 1-stereo, 2-dual mono 3-Parametric stereo */
+ __u8 ps_present;
+
+};
+
+/* WMA Music Parameters Message */
+struct snd_wma_params {
+ __u16 codec;
+ __u8 num_chan; /* 1=Mono, 2=Stereo */
+ __u8 pcm_wd_sz; /* 16/24 - bit*/
+ __u32 brate; /* Use the hard coded value. */
+ __u32 sfreq; /* Sampling freq eg. 8000, 441000, 48000 */
+ __u32 channel_mask; /* Channel Mask */
+ __u16 format_tag; /* Format Tag */
+ __u16 block_align; /* packet size */
+ __u16 wma_encode_opt;/* Encoder option */
+ __u8 op_align; /* op align 0- 16 bit, 1- MSB, 2 LSB */
+ __u8 pcm_src; /* input pcm bit width */
+};
+
+/* Pre processing param structure */
+struct snd_prp_params {
+ __u32 reserved; /* No pre-processing defined yet */
+};
+
+/* Post processing Capability info structure */
+struct snd_sst_postproc_info {
+ __u32 src_min; /* Supported SRC Min sampling freq */
+ __u32 src_max; /* Supported SRC Max sampling freq */
+ __u8 src; /* 0=Not supported, 1=Supported */
+ __u8 bass_boost; /* 0=Not Supported, 1=Supported */
+ __u8 stereo_widening; /* 0=Not Supported, 1=Supported */
+ __u8 volume_control; /* 0=Not Supported, 1=Supported */
+ __s16 min_vol; /* Minimum value of Volume in dB */
+ __s16 max_vol; /* Maximum value of Volume in dB */
+ __u8 mute_control; /* 0=No Mute, 1=Mute */
+ __u8 reserved1;
+ __u16 reserved2;
+};
+
+/* pre processing Capability info structure */
+struct snd_sst_prp_info {
+ __s16 min_vol; /* Minimum value of Volume in dB */
+ __s16 max_vol; /* Maximum value of Volume in dB */
+ __u8 volume_control; /* 0=Not Supported, 1=Supported */
+ __u8 reserved1; /* for 32 bit alignment */
+ __u16 reserved2; /* for 32 bit alignment */
+} __attribute__ ((packed));
+
+/* Firmware capabilities info */
+struct snd_sst_fw_info {
+ struct snd_sst_fw_version fw_version; /* Firmware version */
+ __u8 audio_codecs_supported[8]; /* Codecs supported by FW */
+ __u32 recommend_min_duration; /* Min duration for Lowpower Playback */
+ __u8 max_pcm_streams_supported; /* Max num of PCM streams supported */
+ __u8 max_enc_streams_supported; /* Max number of Encoded streams */
+ __u16 reserved; /* 32 bit alignment*/
+ struct snd_sst_postproc_info pop_info; /* Post processing capability */
+ struct snd_sst_prp_info prp_info; /* pre_processing mod cap info */
+ struct snd_sst_port_info port_info[2]; /* Port info */
+ struct snd_sst_mix_info mix_info; /* Mixer info */
+ __u32 min_input_buf; /* minmum i/p buffer for decode */
+};
+
+/* Add the codec parameter structures for new codecs to be supported */
+#define CODEC_PARAM_STRUCTURES \
+ struct snd_pcm_params pcm_params; \
+ struct snd_mp3_params mp3_params; \
+ struct snd_aac_params aac_params; \
+ struct snd_wma_params wma_params;
+
+/* Pre and Post Processing param structures */
+#define PPP_PARAM_STRUCTURES \
+ struct snd_prp_params prp_params;
+
+/* Codec params struture */
+union snd_sst_codec_params {
+ CODEC_PARAM_STRUCTURES;
+};
+
+/* Pre-processing params struture */
+union snd_sst_ppp_params{
+ PPP_PARAM_STRUCTURES;
+};
+
+struct snd_sst_stream_params {
+ union snd_sst_codec_params uc;
+} __attribute__ ((packed));
+
+struct snd_sst_params {
+ __u32 result;
+ __u32 stream_id;
+ __u8 codec;
+ __u8 ops;
+ __u8 stream_type;
+ struct snd_sst_stream_params sparams;
+};
+
+/* ioctl related stuff here */
+struct snd_sst_pmic_config {
+ __u32 sfreq; /* Sampling rate in Hz */
+ __u16 num_chan; /* Mono =1 or Stereo =2 */
+ __u16 pcm_wd_sz; /* Number of bits per sample */
+} __attribute__ ((packed));
+
+struct snd_sst_get_stream_params {
+ struct snd_sst_params codec_params;
+ struct snd_sst_pmic_config pcm_params;
+};
+
+enum snd_sst_target_type {
+ SND_SST_TARGET_PMIC = 1,
+ SND_SST_TARGET_LPE,
+ SND_SST_TARGET_OTHER,
+};
+
+enum snd_sst_device_type {
+ SND_SST_DEVICE_SSP = 1,
+ SND_SST_DEVICE_PCM,
+ SND_SST_DEVICE_OTHER,
+};
+
+/*enum snd_sst_device_mode {
+ SND_SST_PCM_MODE_I2S = 0,
+ SND_SST_PCM_MODE_PCM1,
+};*/
+enum snd_sst_device_mode {
+
+ SND_SST_DEV_MODE_PCM_MODE1 = 1, /*(1 16-bit word, bit-length frame sync)*/
+ SND_SST_DEV_MODE_PCM_MODE2,
+ SND_SST_DEV_MODE_PCM_MODE3,
+ SND_SST_DEV_MODE_PCM_MODE4_RIGHT_JUSTIFIED,
+ SND_SST_DEV_MODE_PCM_MODE4_LEFT_JUSTIFIED,
+ SND_SST_DEV_MODE_PCM_MODE4_I2S, /*(I2S mode, 16-bit words)*/
+};
+
+enum snd_sst_port_action {
+ SND_SST_PORT_PREPARE = 1,
+ SND_SST_PORT_ACTIVATE,
+};
+
+/* Target selection per device structure */
+struct snd_sst_slot_info {
+ __u8 mix_enable; /* Mixer enable or disable */
+ __u8 device_type;
+ __u8 device_instance; /* 0, 1, 2 */
+ __u8 target_type;
+ __u16 slot[2];
+ __u8 master;
+ __u8 action;
+ __u16 device_mode;
+ struct snd_sst_pmic_config pcm_params;
+} __attribute__ ((packed));
+
+#define SST_MAX_TARGET_DEVICES 3
+/* Target device list structure */
+struct snd_sst_target_device {
+ __u32 device_route;
+ struct snd_sst_slot_info devices[SST_MAX_TARGET_DEVICES];
+} __attribute__ ((packed));
+
+struct snd_sst_driver_info {
+ __u32 version; /* Version of the driver */
+ __u32 active_pcm_streams;
+ __u32 active_enc_streams;
+ __u32 max_pcm_streams;
+ __u32 max_enc_streams;
+ __u32 buf_per_stream;
+};
+
+struct snd_sst_vol {
+ __u32 stream_id;
+ __s32 volume;
+ __u32 ramp_duration;
+ __u32 ramp_type; /* Ramp type, default=0 */
+};
+
+struct snd_sst_mute {
+ __u32 stream_id;
+ __u32 mute;
+};
+
+enum snd_sst_buff_type {
+ SST_BUF_USER = 1,
+ SST_BUF_MMAP,
+ SST_BUF_RAR,
+};
+
+struct snd_sst_mmap_buff_entry {
+ unsigned int offset;
+ unsigned int size;
+};
+
+struct snd_sst_mmap_buffs {
+ unsigned int entries;
+ enum snd_sst_buff_type type;
+ struct snd_sst_mmap_buff_entry *buff;
+};
+
+struct snd_sst_buff_entry {
+ void *buffer;
+ unsigned int size;
+};
+
+struct snd_sst_buffs {
+ unsigned int entries;
+ __u8 type;
+ struct snd_sst_buff_entry *buff_entry;
+};
+
+struct snd_sst_dbufs {
+ unsigned long long input_bytes_consumed;
+ unsigned long long output_bytes_produced;
+ struct snd_sst_buffs *ibufs;
+ struct snd_sst_buffs *obufs;
+};
+
+/*IOCTL defined here */
+/*SST MMF IOCTLS only */
+#define SNDRV_SST_STREAM_SET_PARAMS _IOR('L', 0x00, \
+ struct snd_sst_stream_params *)
+#define SNDRV_SST_STREAM_GET_PARAMS _IOWR('L', 0x01, \
+ struct snd_sst_get_stream_params *)
+#define SNDRV_SST_STREAM_GET_TSTAMP _IOWR('L', 0x02, __u64 *)
+#define SNDRV_SST_STREAM_DECODE _IOWR('L', 0x03, struct snd_sst_dbufs *)
+#define SNDRV_SST_STREAM_BYTES_DECODED _IOWR('L', 0x04, __u64 *)
+#define SNDRV_SST_STREAM_START _IO('A', 0x42)
+#define SNDRV_SST_STREAM_DROP _IO('A', 0x43)
+#define SNDRV_SST_STREAM_DRAIN _IO('A', 0x44)
+#define SNDRV_SST_STREAM_PAUSE _IOW('A', 0x45, int)
+#define SNDRV_SST_STREAM_RESUME _IO('A', 0x47)
+#define SNDRV_SST_MMAP_PLAY _IOW('L', 0x05, struct snd_sst_mmap_buffs *)
+#define SNDRV_SST_MMAP_CAPTURE _IOW('L', 0x06, struct snd_sst_mmap_buffs *)
+/*SST common ioctls */
+#define SNDRV_SST_DRIVER_INFO _IOR('L', 0x10, struct snd_sst_driver_info *)
+#define SNDRV_SST_SET_VOL _IOW('L', 0x11, struct snd_sst_vol *)
+#define SNDRV_SST_GET_VOL _IOW('L', 0x12, struct snd_sst_vol *)
+#define SNDRV_SST_MUTE _IOW('L', 0x13, struct snd_sst_mute *)
+/*AM Ioctly only */
+#define SNDRV_SST_FW_INFO _IOR('L', 0x20, struct snd_sst_fw_info *)
+#define SNDRV_SST_SET_TARGET_DEVICE _IOW('L', 0x21, \
+ struct snd_sst_target_device *)
+
+#endif /* __INTEL_SST_IOCTL_H__ */
diff --git a/sound/pci/sst/intel_sst_interface.c b/sound/pci/sst/intel_sst_interface.c
new file mode 100644
index 0000000..5f84245
--- /dev/null
+++ b/sound/pci/sst/intel_sst_interface.c
@@ -0,0 +1,2099 @@
+/*
+ * intel_sst_interface.c - Intel SST Driver for audio engine
+ *
+ * Copyright (C) 2008-10 Intel Corporation
+ * Authors: Vinod Koul <vinod.koul@intel.com>
+ * Harsha Priya <priya.harsha@intel.com>
+ * Dharageswari R <dharageswari.r@intel.com>
+ * KP Jeeja <jeeja.kp@intel.com>
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ * This driver exposes the audio engine functionalities to the ALSA
+ * and middleware.
+ * Upper layer interfaces (MAD driver, MMF) to SST driver
+ */
+
+#include <linux/cdev.h>
+#include <linux/pci.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/syscalls.h>
+#include <linux/delay.h>
+#include <linux/fs.h>
+#include <linux/file.h>
+#include <linux/fcntl.h>
+#include <linux/uaccess.h>
+#include <linux/interrupt.h>
+#include <linux/list.h>
+#include <linux/slab.h>
+#include <linux/mm.h>
+#include <linux/workqueue.h>
+#include <linux/pci.h>
+#include <linux/firmware.h>
+#include <linux/ioctl.h>
+#include <linux/rar/rar_register.h>
+#include <linux/rar/memrar.h>
+#include <asm/div64.h>
+#include <sound/intel_lpe.h>
+#include <sound/intel_sst_ioctl.h>
+#include "intel_sst_fw_ipc.h"
+#include "intel_sst_common.h"
+
+#define AM_MODULE 1
+#define STREAM_MODULE 0
+
+/**
+* This function is called when the FW needs to be downloaded to SST DSP engine
+*/
+static int sst_download_fw(void)
+{
+ int retval;
+ const struct firmware *fw_sst;
+
+ printk(KERN_DEBUG "SST DBG:SST Downloading FW now...\n");
+ retval = request_firmware(&fw_sst,
+ SST_FW_STD_FILENAME,
+ &sst_drv_ctx->pci->dev);
+ if (retval) {
+ printk(KERN_ERR
+ "SST ERR: req fw failed %d \n", retval);
+ return retval;
+ }
+ sst_drv_ctx->alloc_block[0].sst_id = FW_DWNL_ID;
+ retval = sst_load_fw(fw_sst, NULL);
+ if (retval)
+ goto end_restore;
+
+ sst_drv_ctx->alloc_block[0].ops_block.condition = false;
+ retval = sst_wait_timeout(sst_drv_ctx, &sst_drv_ctx->alloc_block[0]);
+ if (retval)
+ printk(KERN_ERR
+ "SST ERR: fw download failed %d \n" , retval);
+end_restore:
+ release_firmware(fw_sst);
+ sst_drv_ctx->alloc_block[0].sst_id = BLOCK_UNINIT;
+ return retval;
+}
+
+/**
+* intel_sst_open - opens a handle to driver
+* @i_node: inode structure
+* @file_ptr:pointer to file
+*
+* This function is called by OS when a user space component
+* tries to get a driver handle. Only one handle at a time
+* will be allowed
+*/
+int intel_sst_open(struct inode *i_node, struct file *file_ptr)
+{
+ dev_t device = i_node->i_rdev;
+ unsigned int retval = 0;
+
+ if (sst_drv_ctx->pmic_state != SND_MAD_INIT_DONE) {
+ printk(KERN_ERR
+ "SST ERR: Sound card not availble \n ");
+ return -EIO;
+ }
+
+ if (sst_drv_ctx->sst_state == SST_UN_INIT) {
+ /* FW is not downloaded */
+ retval = sst_download_fw();
+ if (retval) {
+ printk(KERN_ERR
+ "SST ERR: FW download failed...abort\n");
+ return -ENODEV;
+ }
+ }
+ if (device == MKDEV(INTEL_SST_MAJOR, 0)) {
+ /* app open */
+ mutex_lock(&sst_drv_ctx->stream_cnt_lock);
+ if (sst_drv_ctx->encoded_cnt < MAX_ENC_STREAM) {
+ struct ioctl_pvt_data *data =
+ kzalloc(sizeof(struct ioctl_pvt_data),
+ GFP_KERNEL);
+ if (!data) {
+ printk(KERN_ERR
+ "SST ERR:error rsrvin data mry\n");
+ mutex_unlock(&sst_drv_ctx->stream_cnt_lock);
+ return -ENOMEM;
+ }
+
+
+ sst_drv_ctx->encoded_cnt++;
+ /*sst_drv_ctx->stream_cnt++;*/
+ mutex_unlock(&sst_drv_ctx->stream_cnt_lock);
+ data->pvt_id = sst_assign_pvt_id(sst_drv_ctx);
+ data->str_id = 0;
+ file_ptr->private_data = (void *)data;
+ printk(KERN_DEBUG "SST DBG:sst id allocated = %d!\n", data->pvt_id);
+ } else
+ retval = -EACCES;
+ } else if (device == MKDEV(INTEL_SST_MAJOR, 1)) {
+ /* audio manager open */
+ mutex_lock(&sst_drv_ctx->stream_cnt_lock);
+ if (sst_drv_ctx->am_cnt < MAX_AM_HANDLES) {
+ sst_drv_ctx->am_cnt++;
+ printk(KERN_DEBUG "SST DBG:AM handle opened...\n");
+ } else
+ retval = -EACCES;
+
+ mutex_unlock(&sst_drv_ctx->stream_cnt_lock);
+ } else
+ retval = -EINVAL;
+ return retval;
+}
+
+void free_stream_context(unsigned int str_id)
+{
+ struct stream_info *stream;
+
+ if (!sst_validate_strid(str_id)) {
+ /* str_id is valid, so stream is alloacted */
+ stream = &sst_drv_ctx->streams[str_id];
+ if (stream->ops == STREAM_OPS_PLAYBACK ||
+ stream->ops == STREAM_OPS_PLAYBACK_DRM) {
+ sst_drv_ctx->pb_streams--;
+ if (sst_drv_ctx->pb_streams == 0 && sst_drv_ctx->cp_streams > 0)
+ sst_drv_ctx->scard_ops->power_down_pmic_pb();
+ } else if (stream->ops == STREAM_OPS_CAPTURE) {
+ sst_drv_ctx->cp_streams--;
+ if (sst_drv_ctx->cp_streams == 0 && sst_drv_ctx->pb_streams > 0)
+ sst_drv_ctx->scard_ops->power_down_pmic_cp();
+ }
+#ifdef CONFIG_MSTWN_POWER_MGMT
+ if(stream->codec == SST_CODEC_TYPE_MP3){
+ sst_drv_ctx->lpaudio_start--;
+ if(!sst_drv_ctx->lpaudio_start) {
+ sst_ospm_send_event(OSPM_EVENT_LPAUDIO_STOP);
+ printk(KERN_DEBUG "SST DBG:Free_stream:lpaudio_start:%d", sst_drv_ctx->lpaudio_start);
+ printk(KERN_DEBUG "SST DBG:Free_stream:Sending OSPM_EVENT_LPAUDIO_STOP...\n");
+ }
+ }else {
+ sst_drv_ctx->audio_start--;
+ if(!sst_drv_ctx->audio_start) {
+ sst_ospm_send_event(OSPM_EVENT_SUBSYS_STOP_PLAY);
+ printk(KERN_DEBUG "SST DBG:Free_stream:audio_start:%d", sst_drv_ctx->audio_start);
+ printk(KERN_DEBUG "SST DBG:Free_stream:Sending OSPM_EVENT_SUBSYS_STOP_PLAY...\n");
+ }
+ }
+#endif
+ if(sst_drv_ctx->pb_streams == 0 &&
+ sst_drv_ctx->cp_streams == 0) {
+ sst_drv_ctx->scard_ops->power_down_pmic();
+ }
+
+ if (sst_free_stream(str_id))
+ sst_clean_stream(&sst_drv_ctx->streams[str_id]);
+ }
+}
+
+/**
+* intel_sst_release - releases a handle to driver
+* @i_node: inode structure
+* @file_ptr: pointer to file
+*
+* This function is called by OS when a user space component
+* tries to release a driver handle.
+*/
+int intel_sst_release(struct inode *i_node, struct file *file_ptr)
+{
+ dev_t device = i_node->i_rdev;
+
+ printk(KERN_DEBUG "SST DBG:Release called \n");
+ if (device == MKDEV(INTEL_SST_MAJOR, 0)) {
+ struct ioctl_pvt_data *data =
+ (struct ioctl_pvt_data *)file_ptr->private_data;
+
+ /* app close */
+ printk(KERN_DEBUG "SST DBG:Closing app handle \n");
+ mutex_lock(&sst_drv_ctx->stream_cnt_lock);
+ sst_drv_ctx->encoded_cnt--;
+ sst_drv_ctx->stream_cnt--;
+ mutex_unlock(&sst_drv_ctx->stream_cnt_lock);
+ free_stream_context(data->str_id);
+ kfree(data);
+ } else if (device == MKDEV(INTEL_SST_MAJOR, 1)) {
+ /* audio manager close */
+ mutex_lock(&sst_drv_ctx->stream_cnt_lock);
+ sst_drv_ctx->am_cnt--;
+ mutex_unlock(&sst_drv_ctx->stream_cnt_lock);
+ printk(KERN_DEBUG "SST DBG:AM handle closed \n");
+ }
+ return 0;
+}
+
+/**
+* intel_sst_mmap - mmaps a kernel buffer to user space for copying data
+* @vma: vm area structure instance
+* @file_ptr: pointer to file
+*
+* This function is called by OS when a user space component
+* tries to get mmap memory from driver
+*/
+int intel_sst_mmap(struct file *file_ptr, struct vm_area_struct *vma)
+{
+ int retval, length;
+ struct ioctl_pvt_data *data =
+ (struct ioctl_pvt_data *)file_ptr->private_data;
+ int str_id = data->str_id;
+ void *mem_area;
+
+ retval = sst_validate_strid(str_id);
+ if (retval)
+ return -EINVAL;
+
+ length = vma->vm_end - vma->vm_start;
+ printk(KERN_DEBUG "SST DBG:called for stream %d length 0x%x\n", str_id, length);
+
+ if (length > sst_drv_ctx->mmap_len)
+ return -ENOMEM;
+ if (!sst_drv_ctx->mmap_mem)
+ return -EIO;
+
+ /* round it up to the page bondary */
+ /*mem_area = (void *)((((unsigned long)sst_drv_ctx->mmap_mem)
+ + PAGE_SIZE - 1) & PAGE_MASK);*/
+ mem_area = (void *) PAGE_ALIGN((unsigned int) sst_drv_ctx->mmap_mem);
+
+ /* map the whole physically contiguous area in one piece */
+ retval = remap_pfn_range(vma,
+ vma->vm_start,
+ virt_to_phys((void *)mem_area) >> PAGE_SHIFT,
+ length,
+ vma->vm_page_prot);
+ if (retval) {
+ sst_drv_ctx->streams[str_id].mmapped = false;
+ printk(KERN_ERR "SST ERR: mapping failed %d ",retval);
+ } else
+ sst_drv_ctx->streams[str_id].mmapped = true;
+
+ printk(KERN_DEBUG "SST DBG:mmap ret 0x%x \n", retval);
+ return retval;
+}
+
+/**
+* intel_sst_mmap_play_capture - sets mmap data buffers to play/capture
+*/
+static int intel_sst_mmap_play_capture(u32 str_id,
+ struct snd_sst_mmap_buffs *mmap_buf)
+{
+ struct sst_stream_bufs *bufs;
+ int retval, i;
+ struct stream_info *stream;
+ struct snd_sst_mmap_buff_entry *buf_entry;
+
+ printk(KERN_DEBUG "SST DBG:called for str_id %d \n", str_id);
+ retval = sst_validate_strid(str_id);
+ if (retval) {
+ printk(KERN_ERR "SST ERR: val +\
+ failed %d ", retval);
+ return -EINVAL;
+ }
+ BUG_ON(!mmap_buf);
+
+ stream = &sst_drv_ctx->streams[str_id];
+ if (stream->mmapped != true) {
+ printk(KERN_ERR "SST ERR: stream not mapped! ");
+ return -EIO;
+ }
+
+ if (stream->status == STREAM_UN_INIT ||
+ stream->status == STREAM_DECODE) {
+ printk(KERN_ERR
+ "SST ERR: BAD REQUEST!, streamstate +\
+ is %d\n", stream->status);
+ return -EBADRQC;
+ }
+ stream->curr_bytes = 0;
+ stream->cumm_bytes = 0;
+
+ printk(KERN_DEBUG "SST DBG:new buffers count %d status %d\n",
+ mmap_buf->entries, stream->status);
+ buf_entry = mmap_buf->buff;
+ for (i = 0; i < mmap_buf->entries; i++) {
+ BUG_ON(!buf_entry);
+ bufs = kzalloc(sizeof(*bufs), GFP_KERNEL);
+ if (!bufs) {
+ printk(KERN_ERR
+ "SST ERR: mem allocation failed \n ");
+ return -ENOMEM;
+ }
+ bufs->size = buf_entry->size;
+ bufs->offset = buf_entry->offset;
+ bufs->addr = sst_drv_ctx->mmap_mem;
+ bufs->in_use = false;
+ buf_entry++;
+ /* locking here */
+ mutex_lock(&stream->lock);
+ list_add_tail(&bufs->node, &stream->bufs);
+ mutex_unlock(&stream->lock);
+ }
+
+ mutex_lock(&stream->lock);
+ stream->data_blk.condition = false;
+ stream->data_blk.ret_code = 0;
+ if (stream->status == STREAM_INIT &&
+ stream->prev != STREAM_UN_INIT &&
+ stream->need_draining != true) {
+ stream->prev = stream->status;
+ stream->status = STREAM_RUNNING;
+ if (stream->ops == STREAM_OPS_PLAYBACK) {
+ printk(KERN_DEBUG "SST DBG:play frames...\n");
+ if (sst_play_frame(str_id) < 0) {
+ printk(KERN_ERR
+ "SST ERR: play frames failed \n");
+ mutex_unlock(&stream->lock);
+ return -EIO;
+ }
+ } else if (stream->ops == STREAM_OPS_CAPTURE) {
+ printk(KERN_DEBUG "SST DBG:capture frames...\n");
+ if (sst_capture_frame(str_id) < 0) {
+ printk(KERN_ERR
+ "SST ERR: capture frames failed \n");
+ mutex_unlock(&stream->lock);
+ return -EIO;
+ }
+ }
+ }
+ mutex_unlock(&stream->lock);
+ /* Block the call for reply */
+ if (!list_empty(&stream->bufs)) {
+ printk(KERN_DEBUG "SST DBG:ioctl waiting...\n");
+ stream->data_blk.on = true;
+ retval = sst_wait_interruptible(sst_drv_ctx,
+ &stream->data_blk);
+ }
+
+ if (retval >= 0)
+ retval = stream->cumm_bytes;
+ printk(KERN_DEBUG "SST DBG:end of play/rec +\
+ ioctl bytes = %d!!\n", retval);
+ return retval;
+}
+
+/**
+* intel_sst_play_capture - sets user data buffers to play/capture
+*/
+static int intel_sst_play_capture(struct stream_info *stream, int str_id)
+{
+ int retval;
+
+ stream->data_blk.ret_code = 0;
+ stream->data_blk.on = true;
+ stream->data_blk.condition = false;
+
+ mutex_lock(&stream->lock);
+ if (stream->status == STREAM_INIT && stream->prev != STREAM_UN_INIT) {
+ /* stream is started */
+ stream->prev = stream->status;
+ stream->status = STREAM_RUNNING;
+ }
+
+ if (stream->status == STREAM_INIT && stream->prev == STREAM_UN_INIT) {
+ /* stream is not started yet */
+ printk(KERN_DEBUG "SST DBG:Stream isnt started yet state %d, prev %d \n",
+ stream->status, stream->prev);
+ } else if ((stream->status == STREAM_RUNNING ||
+ stream->status == STREAM_PAUSED) &&
+ stream->need_draining != true) {
+ /* stream is started */
+ if (stream->ops == STREAM_OPS_PLAYBACK ||
+ stream->ops == STREAM_OPS_PLAYBACK_DRM) {
+ if (sst_play_frame(str_id) < 0) {
+ printk(KERN_ERR
+ "SST ERR: play frames failed \n");
+ mutex_unlock(&stream->lock);
+ return -EIO;
+ }
+ } else if (stream->ops == STREAM_OPS_CAPTURE) {
+ if (sst_capture_frame(str_id) < 0) {
+ printk(KERN_ERR
+ "SST ERR: capture frames failed \n ");
+ mutex_unlock(&stream->lock);
+ return -EIO;
+ }
+ }
+ } else {
+ printk(KERN_ERR
+ "SST ERR: Streamstate %d invalid,prev %d\n",\
+ stream->status, stream->prev);
+ mutex_unlock(&stream->lock);
+ return -EIO;
+ }
+ mutex_unlock(&stream->lock);
+ /* Block the call for reply */
+ printk(KERN_DEBUG "SST DBG:write waiting...\n");
+
+ retval = sst_wait_interruptible(sst_drv_ctx, &stream->data_blk);
+ if (retval) {
+ stream->status = STREAM_INIT;
+ printk(KERN_DEBUG "SST DBG:wait returned error...\n");
+ }
+ printk(KERN_DEBUG "SST DBG:write returning\n");
+ return retval;
+}
+
+/**
+* snd_sst_fill_kernel_list - fills kernel list with buffer addresses for
+* SST DSP driver to process
+*/
+static int snd_sst_fill_kernel_list(struct stream_info *stream,
+ const struct iovec *iovec, unsigned long nr_segs,
+ struct list_head *copy_to_list)
+{
+ struct sst_stream_bufs *stream_bufs;
+ unsigned long index, data_not_copied, mmap_len;
+ unsigned char *bufp;
+ unsigned long size, copied_size;
+ int retval = 0, add_to_list = 0;
+ static int sent_offset;
+ static unsigned long sent_index;
+
+ stream_bufs = kzalloc(sizeof(*stream_bufs), GFP_KERNEL);
+ if (!stream_bufs) {
+ printk(KERN_ERR
+ "SST ERR: memory allocation failed \n ");
+ return -ENOMEM;
+ }
+ stream_bufs->addr = sst_drv_ctx->mmap_mem;
+ if (stream->ops == STREAM_OPS_PLAYBACK_DRM) {
+ for (index = stream->sg_index; index < nr_segs; index++) {
+ __u32 rar_handle;
+ struct sst_stream_bufs *stream_bufs =
+ kzalloc(sizeof(*stream_bufs), GFP_KERNEL);
+
+ stream->sg_index = index;
+ if (!stream_bufs) {
+ printk(KERN_ERR
+ "SST ERR: mry alocation failed \n");
+ return -ENOMEM;
+ }
+ retval = copy_from_user((void *) &rar_handle,
+ iovec[index].iov_base,
+ sizeof(__u32));
+ if (retval != 0) {
+ printk(KERN_ERR
+ "SST ERR: copy from user +\
+ failed\n");
+ return -EIO;
+ }
+ stream_bufs->addr = (char *)rar_handle;
+ printk(KERN_DEBUG "SST DBG:rar handle +\
+ received = 0x%x\n", (__u32)stream_bufs->addr);
+ stream_bufs->in_use = false;
+ stream_bufs->size = iovec[0].iov_len;
+ printk(KERN_DEBUG "size = 0x%x", stream_bufs->size);
+ /* locking here */
+ mutex_lock(&stream->lock);
+ list_add_tail(&stream_bufs->node, &stream->bufs);
+ mutex_unlock(&stream->lock);
+ }
+ stream->sg_index = index;
+ return retval;
+ }
+ mmap_len = sst_drv_ctx->mmap_len;
+ stream_bufs->addr = sst_drv_ctx->mmap_mem;
+ bufp = stream->cur_ptr;
+
+ printk(KERN_DEBUG "SST DBG:mmap_len - %lx\n", mmap_len);
+ copied_size = 0;
+
+ if (!stream->sg_index)
+ sent_index = sent_offset = 0;
+
+ for (index = stream->sg_index; index < nr_segs; index++) {
+ stream->sg_index = index;
+ printk(KERN_DEBUG "SST DBG:index - %lx, cur_ptr - %p\n", index, stream->cur_ptr);
+ printk(KERN_DEBUG "SST DBG:base - %p, size - 0x%x\n", iovec[index].iov_base,
+ iovec[index].iov_len);
+ printk(KERN_DEBUG "SST DBG:bufp - %p\n", bufp);
+ if (!stream->cur_ptr)
+ bufp = iovec[index].iov_base;
+
+ size = ((unsigned long)iovec[index].iov_base
+ + iovec[index].iov_len) - (unsigned long) bufp;
+
+ printk(KERN_DEBUG "SST DBG:size - %lx\n", size);
+ if ((copied_size + size) > mmap_len)
+ size = mmap_len - copied_size;
+
+ printk(KERN_DEBUG "SST DBG:size - %lx\n", size);
+
+ if (stream->ops == STREAM_OPS_PLAYBACK) {
+ printk(KERN_DEBUG "SST DBG:Playback stream copying now....\n");
+ data_not_copied = copy_from_user(
+ (void *)(stream_bufs->addr + copied_size),
+ bufp, size);
+ if (data_not_copied > 0) {
+ /* Clean up the list and return error code */
+ printk(KERN_ERR
+ "SST ERR: cpyfrmusr not coped -%ld", data_not_copied);
+ retval = -EIO;
+ break;
+ }
+ } else if (stream->ops == STREAM_OPS_CAPTURE) {
+ struct snd_sst_user_cap_list *entry =
+ kzalloc(sizeof(*entry), GFP_KERNEL);
+
+ if (!entry) {
+ printk(KERN_ERR
+ "SST ERR: mem allocation failed \n");
+ /* FIXME cleanup prev */
+ return -ENOMEM;
+ }
+ entry->iov_index = index;
+ entry->iov_offset = (unsigned long) bufp -
+ (unsigned long)iovec[index].iov_base;
+ entry->offset = copied_size;
+ entry->size = size;
+ printk(KERN_DEBUG "SST DBG:ENTRY:ioindx %d,iooff %ld,koff %ld,ksz %ld \n",
+ entry->iov_index, entry->iov_offset,
+ entry->offset, entry->size);
+ list_add_tail(&entry->node, copy_to_list);
+ }
+
+ printk(KERN_DEBUG "SST DBG:cur_ptr - %lx\n", (unsigned long) stream->cur_ptr);
+ stream->cur_ptr = bufp + size;
+
+ if (((unsigned long)iovec[index].iov_base
+ + iovec[index].iov_len) < ((unsigned long)iovec[index].iov_base) ) {
+ printk(KERN_DEBUG "SST DBG:Buffer overflows");
+ return -EINVAL;
+ }
+
+ if (((unsigned long)iovec[index].iov_base
+ + iovec[index].iov_len) ==
+ (unsigned long)stream->cur_ptr) {
+ stream->cur_ptr = NULL;
+ stream->sg_index++;
+ }
+
+ copied_size += size;
+ printk(KERN_DEBUG "SST DBG:copied_size - %lx\n", copied_size);
+ if ((copied_size >= mmap_len) ||
+ (stream->sg_index == nr_segs)) {
+ add_to_list = 1;
+ }
+
+ if (add_to_list) {
+ stream_bufs->in_use = false;
+ stream_bufs->size = copied_size;
+ /* locking here */
+ mutex_lock(&stream->lock);
+ list_add_tail(&stream_bufs->node, &stream->bufs);
+ mutex_unlock(&stream->lock);
+ break;
+ }
+ }
+ return retval;
+}
+
+/**
+* snd_sst_copy_userbuf_capture - This function copies the captured data
+* returned from SST DSP engine to the user buffers
+*/
+static int snd_sst_copy_userbuf_capture(struct stream_info *stream,
+ const struct iovec *iovec,
+ struct list_head *copy_to_list)
+{
+ struct snd_sst_user_cap_list *entry, *_entry;
+ struct sst_stream_bufs *kbufs = NULL, *_kbufs;
+ int retval = 0;
+ unsigned long data_not_copied;
+
+ /* copy sent buffers */
+ /* FIXME optimze */
+ printk(KERN_DEBUG "SST DBG:capture stream copying to user now...\n");
+ list_for_each_entry_safe(kbufs, _kbufs, &stream->bufs, node) {
+ if (kbufs->in_use == true) {
+ /* copy to user */
+ list_for_each_entry_safe(entry, _entry,
+ copy_to_list, node) {
+ printk(KERN_DEBUG "SST DBG:filling now... \n");
+ printk(KERN_DEBUG "SST DBG:iindx %d,ioff %ld,koff %ld,ksz %ld \n",
+ entry->iov_index, entry->iov_offset,
+ entry->offset, entry->size);
+ printk(KERN_DEBUG "SST DBG:Copying at %p size %lx\n",
+ iovec[entry->iov_index].iov_base +
+ entry->iov_offset,
+ entry->size);
+ data_not_copied = copy_to_user((void *)
+ iovec[entry->iov_index].iov_base +
+ entry->iov_offset,
+ kbufs->addr + entry->offset,
+ entry->size);
+ if (data_not_copied > 0) {
+ /* Clean up the list and return error */
+ printk(KERN_ERR
+ "SST ERR: copy to user err -%ld\n ", data_not_copied);
+ retval = -EIO;
+ break;
+ }
+ list_del(&entry->node);
+ kfree(entry);
+ }
+ printk(KERN_DEBUG "SST DBG:coming out of loop\n");
+ }
+ }
+ printk(KERN_DEBUG "SST DBG:end of cap copy\n");
+ return retval;
+}
+
+/*
+ * snd_sst_userbufs_play_cap - constructs the list from user buffers
+ * @iovec: pointer to iovec structure
+ * @nr_segs: number entries in the iovec structure
+ * @str_id: stream id
+ * @stream: pointer to stream_info structure
+ * This function will traverse the user list and copy the data to the kernel
+ * space buffers.
+ */ /* FIXME cleanups in this fn no mem leaks due to link list */
+static int snd_sst_userbufs_play_cap(const struct iovec *iovec,
+ unsigned long nr_segs, unsigned int str_id,
+ struct stream_info *stream)
+{
+ int retval;
+ LIST_HEAD(copy_to_list);
+
+
+ retval = snd_sst_fill_kernel_list(stream, iovec, nr_segs,
+ ©_to_list);
+
+ retval = intel_sst_play_capture(stream, str_id);
+ if (retval < 0)
+ return retval;
+
+ if (stream->ops == STREAM_OPS_CAPTURE) {
+ retval = snd_sst_copy_userbuf_capture(stream, iovec,
+ ©_to_list);
+ }
+ return retval;
+}
+
+/**
+* intel_sst_read_write - This function is common function across read/write
+* for user buffers called from system calls
+*/
+static int intel_sst_read_write(unsigned int str_id, char __user *buf,
+ size_t count)
+{
+ int retval;
+ struct stream_info *stream;
+ struct iovec iovec;
+ unsigned long nr_segs;
+
+ retval = sst_validate_strid(str_id);
+ if (retval)
+ return -EINVAL;
+ stream = &sst_drv_ctx->streams[str_id];
+ if (stream->mmapped == true) {
+ printk(KERN_ERR
+ "SST ERR: user write and stream is mapped");
+ return -EIO;
+ }
+ if (!count) {
+ printk(KERN_ERR
+ "SST ERR: args invalid %d", retval);
+ return -EINVAL;
+ }
+ stream->curr_bytes = 0;
+ stream->cumm_bytes = 0;
+ /* copy user buf details */
+ printk(KERN_DEBUG "SST DBG:new buffers %p, copy size %d, status %d\n" ,
+ buf, (int) count, (int) stream->status);
+
+ stream->buf_type = SST_BUF_USER_STATIC;
+ iovec.iov_base = (void *)buf;
+ iovec.iov_len = count;
+ nr_segs = 1;
+
+ do {
+ retval = snd_sst_userbufs_play_cap(&iovec, nr_segs,
+ str_id, stream);
+
+ if (retval < 0)
+ break;
+
+ } while (stream->sg_index < nr_segs);
+
+ stream->sg_index = 0;
+ stream->cur_ptr = NULL;
+ if (retval >= 0)
+ retval = stream->cumm_bytes;
+ printk(KERN_DEBUG "SST DBG:end of play/rec bytes = %d!!\n", retval);
+ return retval;
+}
+
+/*
+ * intel_sst_write - This function is called when user tries to play out data
+ * @file_ptr: pointer to file
+ * @buf: user buffer to be played out
+ * @count: size of tthe buffer
+ * @offset: offset to start from
+ */
+int intel_sst_write(struct file *file_ptr, const char __user *buf,
+ size_t count, loff_t *offset)
+{
+ struct ioctl_pvt_data *data =
+ (struct ioctl_pvt_data *)file_ptr->private_data;
+ int str_id = data->str_id;
+ struct stream_info *stream = &sst_drv_ctx->streams[str_id];
+
+ printk(KERN_DEBUG "SST DBG:called for %d\n", str_id);
+ if (stream->status == STREAM_UN_INIT ||
+ stream->status == STREAM_DECODE) {
+ printk(KERN_ERR "SST ERR: BAD REQUEST ");
+ return -EBADRQC;
+ }
+ return intel_sst_read_write(str_id, (char __user *)buf, count);
+}
+
+/*
+ * intel_sst_aio_write - This function is called when user tries to play out
+ * multiple data buffers
+ * @kiocb: pointer to a structure containing file pointer
+ * @iov: list of user buffer to be played out
+ * @nr_segs: number of entries
+ * @offset: offset to start from
+ */
+ssize_t intel_sst_aio_write(struct kiocb *kiocb, const struct iovec *iov,
+ unsigned long nr_segs, loff_t offset)
+{
+ int retval;
+ struct ioctl_pvt_data *data =
+ (struct ioctl_pvt_data *)kiocb->ki_filp->private_data;
+ int str_id = data->str_id;
+ struct stream_info *stream;
+
+ printk(KERN_DEBUG "SST DBG:entry - %ld\n", nr_segs);
+
+ if (is_sync_kiocb(kiocb) == false) {
+ printk(KERN_ERR
+ "SST ERR: aio_writ frm userspace is not alowed\n");
+ return -EINVAL;
+ }
+
+ printk(KERN_DEBUG "SST DBG:called for str_id %d \n", str_id);
+ retval = sst_validate_strid(str_id);
+ if (retval) {
+ printk(KERN_ERR
+ "SST ERR: invalid stream id \n ");
+ return -EINVAL;
+ }
+ stream = &sst_drv_ctx->streams[str_id];
+ if (stream->mmapped == true) {
+ printk(KERN_ERR
+ "SST ERR: user write & stream is mapped");
+ return -EIO;
+ }
+ if (stream->status == STREAM_UN_INIT ||
+ stream->status == STREAM_DECODE) {
+ printk(KERN_ERR "SST ERR: BAD REQUEST");
+ return -EBADRQC;
+ }
+ stream->curr_bytes = 0;
+ stream->cumm_bytes = 0;
+ printk(KERN_DEBUG "SST DBG:new segs %ld, offset %d, status %d\n" ,
+ nr_segs, (int) offset, (int) stream->status);
+ stream->buf_type = SST_BUF_USER_STATIC;
+ do {
+ retval = snd_sst_userbufs_play_cap(iov, nr_segs,
+ str_id, stream);
+ if (retval < 0)
+ break;
+
+ } while (stream->sg_index < nr_segs);
+
+ stream->sg_index = 0;
+ stream->cur_ptr = NULL;
+ if (retval >= 0)
+ retval = stream->cumm_bytes;
+ printk(KERN_DEBUG "SST DBG:end of play/rec bytes = %d!!\n", retval);
+ return retval;
+}
+
+/*
+ * intel_sst_read - This function is called when user tries to capture data
+ * @file_ptr: pointer to file
+ * @buf: user buffer to be filled with captured data
+ * @count: size of tthe buffer
+ * @offset: offset to start from
+ */
+int intel_sst_read(struct file *file_ptr, char __user *buf,
+ size_t count, loff_t *offset)
+{
+ struct ioctl_pvt_data *data =
+ (struct ioctl_pvt_data *)file_ptr->private_data;
+ int str_id = data->str_id;
+ struct stream_info *stream = &sst_drv_ctx->streams[str_id];
+
+ printk(KERN_DEBUG "SST DBG:called for %d\n", str_id);
+ if (stream->status == STREAM_UN_INIT ||
+ stream->status == STREAM_DECODE) {
+ printk(KERN_ERR"SST ERR: BAD REQUEST!\n");
+ return -EBADRQC;
+ }
+ return intel_sst_read_write(str_id, buf, count);
+}
+
+/*
+ * intel_sst_aio_read - This function is called when user tries to capture out
+ * multiple data buffers
+ * @kiocb: pointer to a structure containing file pointer
+ * @iov: list of user buffer to be filled with captured
+ * @nr_segs: number of entries
+ * @offset: offset to start from
+ */
+
+ssize_t intel_sst_aio_read(struct kiocb *kiocb, const struct iovec *iov,
+ unsigned long nr_segs, loff_t offset)
+{
+ int retval;
+ struct ioctl_pvt_data *data =
+ (struct ioctl_pvt_data *)kiocb->ki_filp->private_data;
+ int str_id = data->str_id;
+ struct stream_info *stream;
+
+ printk(KERN_DEBUG "SST DBG:entry - %ld\n", nr_segs);
+
+ if (is_sync_kiocb(kiocb) == false) {
+ printk(KERN_DEBUG "SST DBG:aio_read from user space is not allowed\n");
+ return -EINVAL;
+ }
+
+ printk(KERN_DEBUG "SST DBG:called for str_id %d \n", str_id);
+ retval = sst_validate_strid(str_id);
+ if (retval)
+ return -EINVAL;
+ stream = &sst_drv_ctx->streams[str_id];
+ if (stream->mmapped == true) {
+ printk(KERN_ERR
+ "SST ERR: user write stream is mapped!!! ");
+ return -EIO;
+ }
+ if (stream->status == STREAM_UN_INIT ||
+ stream->status == STREAM_DECODE) {
+ printk(KERN_ERR "SST ERR: BAD REQUEST!\n ");
+ return -EBADRQC;
+ }
+ stream->curr_bytes = 0;
+ stream->cumm_bytes = 0;
+
+ printk(KERN_DEBUG "SST DBG:new segs %ld, offset %d, status %d\n" ,
+ nr_segs, (int) offset, (int) stream->status);
+ stream->buf_type = SST_BUF_USER_STATIC;
+ do {
+ retval = snd_sst_userbufs_play_cap(iov, nr_segs,
+ str_id, stream);
+ if (retval < 0)
+ break;
+
+ } while (stream->sg_index < nr_segs);
+
+ stream->sg_index = 0;
+ stream->cur_ptr = NULL;
+ if (retval >= 0)
+ retval = stream->cumm_bytes;
+ printk(KERN_DEBUG "SST DBG:end of play/rec bytes = %d!!\n", retval);
+ return retval;
+}
+
+/*
+ * sst_print_stream_params - prints the stream parameters (debug fn)
+ */
+static void sst_print_stream_params(struct snd_sst_get_stream_params *get_prm)
+{
+ printk(KERN_DEBUG "SST DBG:codec params:result =%d\n",
+ get_prm->codec_params.result);
+ printk(KERN_DEBUG "SST DBG:codec params:stream = %d\n",
+ get_prm->codec_params.stream_id);
+ printk(KERN_DEBUG "SST DBG:codec params:codec = %d\n",
+ get_prm->codec_params.codec);
+ printk(KERN_DEBUG "SST DBG:codec params:ops = %d\n",
+ get_prm->codec_params.ops);
+ printk(KERN_DEBUG "SST DBG:codec params:stream_type= %d\n",
+ get_prm->codec_params.stream_type);
+ printk(KERN_DEBUG "SST DBG:pcmparams:sfreq= %d\n",
+ get_prm->pcm_params.sfreq);
+ printk(KERN_DEBUG "SST DBG:pcmparams:num_chan= %d\n",
+ get_prm->pcm_params.num_chan);
+ printk(KERN_DEBUG "SST DBG:pcmparams:pcm_wd_sz= %d\n",
+ get_prm->pcm_params.pcm_wd_sz);
+ return;
+}
+
+/*
+ * sst_print_fw_info - prints the firmware information (debug fn)
+ */
+static void sst_print_fw_info(struct snd_sst_fw_info *fw_info)
+{
+ printk(KERN_DEBUG "SST DBG:build = %d\n", fw_info->fw_version.build);
+ printk(KERN_DEBUG "SST DBG:minor = %d\n", fw_info->fw_version.minor);
+ printk(KERN_DEBUG "SST DBG:major= %d\n", fw_info->fw_version.major);
+ printk(KERN_DEBUG "SST DBG:max pcm = %d\n", fw_info->max_pcm_streams_supported);
+ printk(KERN_DEBUG "SST DBG:max enc = %d\n", fw_info->max_enc_streams_supported);
+ printk(KERN_DEBUG "SST DBG:min input buf = %d\n", fw_info->min_input_buf);
+ printk(KERN_DEBUG "SST DBG:pop:src_min= %d\n", fw_info->pop_info.src_min);
+ printk(KERN_DEBUG "SST DBG:pop:src_max= %d\n", fw_info->pop_info.src_max);
+ printk(KERN_DEBUG "SST DBG:pop:src= %d\n", fw_info->pop_info.src);
+ printk(KERN_DEBUG "SST DBG:pop:bass_boost= %d\n", fw_info->pop_info.bass_boost);
+ printk(KERN_DEBUG "SST DBG:pop:stereo_widening= %d\n", fw_info->pop_info.stereo_widening);
+ printk(KERN_DEBUG "SST DBG:pop:volume_control= %d\n", fw_info->pop_info.volume_control);
+ printk(KERN_DEBUG "SST DBG:pop:min_vol= %d\n", fw_info->pop_info.min_vol);
+ printk(KERN_DEBUG "SST DBG:pop:max_vol= %d\n", fw_info->pop_info.max_vol);
+ printk(KERN_DEBUG "SST DBG:prp:min_vol= %d\n", fw_info->prp_info.min_vol);
+ printk(KERN_DEBUG "SST DBG:prp:max_vol= %d\n", fw_info->prp_info.max_vol);
+ printk(KERN_DEBUG "SST DBG:prp:volume_control= %d\n", fw_info->prp_info.volume_control);
+ printk(KERN_DEBUG "SST DBG:mix:max streams = %d\n", fw_info->mix_info.max_streams);
+ printk(KERN_DEBUG "SST DBG:port0:port_type = %d\n", fw_info->port_info[0].port_type);
+ printk(KERN_DEBUG "SST DBG:port1:port_type = %d\n", fw_info->port_info[1].port_type);
+ return;
+}
+
+/*
+ * sst_get_stream_allocated - this function gets a stream allocated with
+ * the given params
+ */
+static int sst_get_stream_allocated(struct snd_sst_params *str_param,
+ u32 block, u32 pvt_id)
+{
+ int retval;
+ retval = sst_alloc_stream((char *) &str_param->sparams, str_param->ops,
+ str_param->codec, pvt_id);
+ if (retval) {
+ printk(KERN_ERR
+ "SST ERR: sst_alloc_stream failed %d \n", retval);
+ return retval;
+ }
+ /* Block the call for reply */
+ retval = sst_wait_timeout(sst_drv_ctx,
+ &sst_drv_ctx->alloc_block[block]);
+
+ return retval;
+}
+
+/*
+ * set_port_params - this function sets the port parameters at Sound card end
+ */
+static void set_port_params(struct snd_sst_params *str_param,
+ enum snd_sst_stream_ops ops)
+{
+ /*int sfreq = str_param->sparams.uc.pcm_params.sfreq;
+ int word_size = str_param->sparams.uc.pcm_params.pcm_wd_sz;
+
+ printk(KERN_DEBUG "SST DBG:sampling frequency = %d wd_size = %d \n", sfreq, word_size);
+
+ if (ops == STREAM_OPS_PLAYBACK ||
+ ops == STREAM_OPS_PLAYBACK_DRM) {
+ printk(KERN_DEBUG "SST DBG:Setting playback path and port settings...\n");
+ sst_drv_ctx->scard_ops.set_pcm_audio_params(sfreq,
+ word_size);
+ } else if (ops == STREAM_OPS_CAPTURE) {
+ printk(KERN_DEBUG "SST DBG:Setting capture path...\n");
+ sst_drv_ctx->scard_ops->set_pcm_audio_params(sfreq, word_size);
+ }*/
+ return;
+}
+
+/*
+ * sst_get_sfreq - this function returns the frequency of the stream
+ */
+static int sst_get_sfreq(struct snd_sst_params *str_param)
+{
+ switch (str_param->codec) {
+ case SST_CODEC_TYPE_PCM:
+ return str_param->sparams.uc.pcm_params.sfreq;
+ case SST_CODEC_TYPE_MP3:
+ return str_param->sparams.uc.mp3_params.sfreq;
+ case SST_CODEC_TYPE_AAC:
+ return str_param->sparams.uc.aac_params.sfreq;;
+ case SST_CODEC_TYPE_WMA9:
+ return str_param->sparams.uc.wma_params.sfreq;;
+ default:
+ return 0;
+ }
+}
+
+/*
+ * sst_stalled - this function checks if the lpe is in stalled state
+ */
+int sst_stalled(void)
+{
+ int retry = 1000;
+ int retval = -1;
+
+ while(retry) {
+ if ( !sst_drv_ctx->lpe_stalled )
+ return 0;
+ //wait for time and re-check
+ mdelay(1);
+
+ retry--;
+ }
+
+ printk(KERN_DEBUG "SST DBG:LPE is in Stalled State\n");
+ return retval;
+}
+/*
+ * sst_get_stream - this function prepares for stream allocation
+ */
+static int sst_get_stream(struct snd_sst_params *str_param, u32 pvt_id)
+{
+ int i, retval;
+ struct stream_info *str_info;
+
+ /* stream is not allocated, we are allocating */
+ i = sst_get_block_stream(sst_drv_ctx);
+ printk(KERN_DEBUG "SST DBG:alloc block allocated = %d\n", i);
+ if (i < 0)
+ return -ENOMEM;
+ sst_drv_ctx->alloc_block[i].sst_id = pvt_id;
+
+ retval = sst_get_stream_allocated(str_param, i, pvt_id);
+ if (retval == -(SST_LIB_ERR_LIB_DNLD_REQUIRED)) {
+ /* codec download is required */
+ struct snd_sst_alloc_response *response =
+ sst_drv_ctx->alloc_block[i].ops_block.data;
+ printk(KERN_DEBUG "SST DBG:Codec is required.... trying that\n");
+ retval = sst_load_library(&response->lib_dnld,
+ str_param->ops, pvt_id);
+ kfree(response);
+
+ if (!retval) {
+ printk(KERN_DEBUG "SST DBG:codec was downloaded sucesfully \n");
+ printk(KERN_DEBUG "SST DBG:try alloac again\n");
+ sst_drv_ctx->alloc_block[i].ops_block.condition = false;
+
+ retval = sst_get_stream_allocated(str_param, i, pvt_id);
+
+ if (retval <= 0)
+ goto err;
+ set_port_params(str_param, str_param->ops);
+
+ printk(KERN_DEBUG "SST DBG:Allocation done stream id %d \n", retval);
+ } else {
+ printk(KERN_DEBUG "SST DBG:codec download failed \n");
+ retval = -EIO;
+ goto err;
+ }
+ } else if (retval <= 0)
+ goto err;
+ else
+ set_port_params(str_param, str_param->ops);
+
+ /* store sampling freq */
+ str_info = &sst_drv_ctx->streams[retval];
+ str_info->sfreq = sst_get_sfreq(str_param);
+
+ /* power on the analog, if reqd */
+ if (str_param->ops == STREAM_OPS_PLAYBACK ||
+ str_param->ops == STREAM_OPS_PLAYBACK_DRM) {
+
+ sst_drv_ctx->scard_ops->power_up_pmic_pb(
+ sst_drv_ctx->pmic_port_instance);
+ /*Only if the playback is MP3 - Send a message*/
+#ifdef CONFIG_MSTWN_POWER_MGMT
+ if(str_info->codec == SST_CODEC_TYPE_MP3) {
+ sst_ospm_send_event(OSPM_EVENT_LPAUDIO_START);
+ sst_drv_ctx->lpaudio_start++;
+ printk(KERN_DEBUG "SST DBG:lpaudio_start:%d", sst_drv_ctx->lpaudio_start);
+ printk(KERN_DEBUG "SST DBG:Sending OSPM_EVENT_LPAUDIO_START...\n");
+ }else {/*Only if the playback is non - MP3- Send a messageif not sent already*/
+ if(sst_drv_ctx->audio_start == 0) {
+ sst_ospm_send_event(OSPM_EVENT_SUBSYS_START_PLAY);
+ sst_drv_ctx->audio_start++;
+ printk(KERN_DEBUG "SST DBG:audio_start:%d", sst_drv_ctx->audio_start);
+ printk(KERN_DEBUG "SST DBG:Sending OSPM_EVENT_SUBSYS_START_PLAY...\n");
+
+ }
+ else {
+ sst_drv_ctx->audio_start++;
+ }
+ }
+#endif
+ sst_drv_ctx->pb_streams++;
+ } else if (str_param->ops == STREAM_OPS_CAPTURE) {
+
+ sst_drv_ctx->scard_ops->power_up_pmic_cp(
+ sst_drv_ctx->pmic_port_instance);
+ /*Send a messageif not sent already*/
+#ifdef CONFIG_MSTWN_POWER_MGMT
+ if(sst_drv_ctx->audio_start == 0) {
+ sst_ospm_send_event(OSPM_EVENT_SUBSYS_START_PLAY);
+ printk(KERN_DEBUG "SST DBG:audio_start:%d", sst_drv_ctx->audio_start);
+ printk(KERN_DEBUG "SST DBG:Sending OSPM_EVENT_SUBSYS_START_PLAY...\n");
+ sst_drv_ctx->audio_start++;
+ }else {
+ sst_drv_ctx->audio_start++;
+ }
+#endif
+ sst_drv_ctx->cp_streams++;
+ }
+
+err:
+ sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
+ return retval;
+}
+
+/**
+* intel_sst_ioctl - recieves the device ioctl's
+* @i_node: inode structure
+* @file_ptr: pointer to file
+* @cmd: Ioctl cmd
+* @arg: data
+*
+* This function is called by OS when a user space component
+* sends an Ioctl to SST driver
+*/
+int intel_sst_ioctl(struct inode *i_node, struct file *file_ptr,
+ unsigned int cmd, unsigned long arg)
+{
+ int retval = 0;
+ struct ioctl_pvt_data *data = NULL;
+ int str_id = 0, minor = 0;
+ dev_t device = i_node->i_rdev;
+
+ if (device == MKDEV(INTEL_SST_MAJOR, 0)) {
+ minor = 0;
+ data = (struct ioctl_pvt_data *)
+ file_ptr->private_data;
+ str_id = data->str_id;
+ } else if (device == MKDEV(INTEL_SST_MAJOR, 1))
+ minor = 1;
+ else
+ return -EINVAL;
+
+ if (sst_drv_ctx->sst_state != SST_FW_RUNNING) {
+ printk(KERN_ERR
+ "SST ERR: SST Not runng %d\n " , sst_drv_ctx->sst_state);
+ return -EBUSY;
+ }
+
+ switch (_IOC_NR(cmd)) {
+ case _IOC_NR(SNDRV_SST_STREAM_PAUSE):
+ printk(KERN_DEBUG "SST DBG:SNDRV_SST_IOCTL_PAUSE recieved for %d!\n", str_id);
+ if (minor != STREAM_MODULE) {
+ printk(KERN_ERR
+ "SST ERR: called for AM handle minor%d\n", minor);
+ retval = -EINVAL;
+ break;
+ }
+ retval = sst_pause_stream(str_id);
+ break;
+
+ case _IOC_NR(SNDRV_SST_STREAM_RESUME):
+ printk(KERN_DEBUG "SST DBG:SNDRV_SST_IOCTL_RESUME recieved!\n");
+ if (minor != STREAM_MODULE) {
+ printk(KERN_ERR
+ "SST ERR: caled for AM handle minor %d\n", minor);
+ retval = -EINVAL;
+ break;
+ }
+ retval = sst_resume_stream(str_id);
+ break;
+
+ case _IOC_NR(SNDRV_SST_STREAM_SET_PARAMS): {
+ struct snd_sst_params *str_param = (struct snd_sst_params *)arg;
+
+ printk(KERN_DEBUG "SST DBG:IOCTL_SET_PARAMS recieved!\n");
+ if (minor != STREAM_MODULE) {
+ printk(KERN_ERR
+ "SST ERR: caled for AM handle minor %d\n", minor);
+ retval = -EINVAL;
+ break;
+ }
+ sst_print_params(str_param);
+
+ if (!str_id) {
+ retval = sst_get_stream(str_param, data->pvt_id);
+ if (retval > 0) {
+ struct stream_info *str_info;
+ sst_drv_ctx->stream_cnt++;
+ data->str_id = retval;
+ str_info = &sst_drv_ctx->streams[retval];
+ str_info->src = SST_DRV;
+ retval = copy_to_user(&str_param->stream_id,
+ &retval, sizeof(__u32));
+ } else {
+ if (retval == -SST_ERR_INVALID_PARAMS)
+ retval = -EINVAL;
+ }
+ } else {
+ printk(KERN_DEBUG "SST DBG:SET_STREAM_PARAMS recieved!\n");
+ /* allocated set params only */
+ retval = sst_set_stream_param(str_id, str_param);
+ /* Block the call for reply */
+ if (!retval) {
+ int sfreq = 0, word_size = 0, num_channel = 0;
+ sfreq = str_param->sparams.uc.pcm_params.sfreq;
+ word_size = str_param->sparams.
+ uc.pcm_params.pcm_wd_sz;
+ num_channel = str_param->sparams.uc.pcm_params.num_chan;
+ if (str_param->ops == STREAM_OPS_CAPTURE) {
+ printk(KERN_DEBUG "SST DBG:SST sampling frequency= %d\n",
+ sfreq);
+ sst_drv_ctx->scard_ops->\
+ set_pcm_audio_params(sfreq, word_size, num_channel);
+ }
+ }
+ }
+ break;
+ }
+ case _IOC_NR(SNDRV_SST_SET_VOL): {
+ struct snd_sst_vol *set_vol;
+ struct snd_sst_vol *rec_vol = (struct snd_sst_vol *)arg;
+ printk(KERN_DEBUG "SST DBG:SNDRV_SST_SET_VOLUME recieved for %d!\n",
+ rec_vol->stream_id);
+ if (minor == STREAM_MODULE && rec_vol->stream_id == 0) {
+ printk(KERN_DEBUG "SST DBG:invalid operation!\n");
+ retval = -EPERM;
+ break;
+ }
+ set_vol = kzalloc(sizeof(*set_vol), GFP_ATOMIC);
+ if (!set_vol) {
+ printk(KERN_DEBUG "SST DBG:mem allocation failed\n");
+ retval = -ENOMEM;
+ break;
+ }
+ retval = copy_from_user(set_vol, rec_vol, sizeof(*set_vol));
+ if (retval) {
+ printk(KERN_DEBUG "SST DBG:copy failed\n");
+ retval = -EAGAIN;
+ break;
+ }
+ retval = sst_set_vol(set_vol);
+ kfree(set_vol);
+ break;
+ }
+ case _IOC_NR(SNDRV_SST_GET_VOL): {
+ struct snd_sst_vol *rec_vol = (struct snd_sst_vol *)arg;
+ struct snd_sst_vol get_vol;
+ printk(KERN_DEBUG "SST DBG:IOCTL_GET_VOLUME recieved for stream = %d!\n",
+ rec_vol->stream_id);
+ if (minor == STREAM_MODULE && rec_vol->stream_id == 0) {
+ printk(KERN_DEBUG "SST DBG:invalid operation!\n");
+ retval = -EPERM;
+ break;
+ }
+ get_vol.stream_id = rec_vol->stream_id;
+ retval = sst_get_vol(&get_vol);
+ if (retval) {
+ printk(KERN_ERR
+ "SST ERR: Get volume failed = %d\n", retval);
+ retval = -EIO;
+ break;
+ }
+ printk(KERN_DEBUG "SST DBG:id = %d\n, vol = %d, ramp_dur = %d, ramp_type=%d\n",
+ get_vol.stream_id, get_vol.volume,
+ get_vol.ramp_duration, get_vol.ramp_type);
+ retval = copy_to_user((struct snd_sst_vol *)arg,
+ &get_vol, sizeof(get_vol));
+ if (retval) {
+ printk(KERN_ERR
+ "SST ERR: copy to user failed %d\n", retval);
+ retval = -EIO;
+ break;
+ }
+ /*sst_print_get_vol_info(str_id, &get_vol);*/
+ break;
+ }
+
+ case _IOC_NR(SNDRV_SST_MUTE): {
+ struct snd_sst_mute *set_mute;
+ struct snd_sst_vol *rec_mute = (struct snd_sst_vol *)arg;
+ printk(KERN_DEBUG "SST DBG:SNDRV_SST_SET_VOLUME recieved for %d!\n",
+ rec_mute->stream_id);
+ if (minor == STREAM_MODULE && rec_mute->stream_id == 0) {
+ printk(KERN_DEBUG "SST DBG:invalid operation!\n");
+ retval = -EPERM;
+ break;
+ }
+ set_mute = kzalloc(sizeof(*set_mute), GFP_ATOMIC);
+ if (!set_mute) {
+ printk(KERN_DEBUG "SST DBG:mem allocation failed\n");
+ retval = -ENOMEM;
+ break;
+ }
+ retval = copy_from_user(set_mute, rec_mute, sizeof(*set_mute));
+ if (retval) {
+ printk(KERN_DEBUG "SST DBG:copy failed\n");
+ retval = -EAGAIN;
+ break;
+ }
+ retval = sst_set_mute(set_mute);
+ kfree(set_mute);
+ break;
+ }
+ case _IOC_NR(SNDRV_SST_STREAM_GET_PARAMS): {
+ struct snd_sst_get_stream_params get_params;
+
+ printk(KERN_DEBUG "SST DBG:IOCTL_GET_PARAMS recieved!\n");
+ if (minor != 0) {
+ printk(KERN_ERR
+ "SST ERR: called for AM handle minor %d\n", minor);
+ retval = -EINVAL;
+ break;
+ }
+
+ retval = sst_get_stream_params(str_id, &get_params);
+ if (retval) {
+ printk(KERN_ERR
+ "SST ERR: Get params failed = %d\n", retval);
+ retval = -EIO;
+ break;
+ }
+ retval = copy_to_user((struct snd_sst_get_stream_params *)arg,
+ &get_params, sizeof(get_params));
+ if (retval) {
+ printk(KERN_ERR
+ "SST ERR: copy to user failed %d\n" , retval);
+ retval = -EIO;
+ break;
+ }
+ sst_print_stream_params(&get_params);
+ break;
+ }
+
+ case _IOC_NR(SNDRV_SST_MMAP_PLAY):
+ case _IOC_NR(SNDRV_SST_MMAP_CAPTURE):
+ printk(KERN_DEBUG "SST DBG:SNDRV_SST_MMAP_PLAY/CAPTURE recieved!\n");
+ if (minor != STREAM_MODULE) {
+ printk(KERN_ERR
+ "SST ERR: called for AM handle minor %d\n" , minor);
+ retval = -EINVAL;
+ break;
+ }
+ retval = intel_sst_mmap_play_capture(str_id,
+ (struct snd_sst_mmap_buffs *)arg);
+ break;
+
+ case _IOC_NR(SNDRV_SST_STREAM_DROP):
+ printk(KERN_DEBUG "SST DBG:SNDRV_SST_IOCTL_DROP recieved!\n");
+ if (minor != STREAM_MODULE) {
+ retval = -EINVAL;
+ break;
+ }
+ retval = sst_drop_stream(str_id);
+ break;
+
+ case _IOC_NR(SNDRV_SST_STREAM_GET_TSTAMP): {
+ unsigned long long *ms = (unsigned long long *)arg;
+ struct snd_sst_tstamp tstamp = {0};
+ unsigned long long time, freq, mod;
+
+ printk(KERN_DEBUG "SST DBG:SNDRV_SST_STREAM_GET_TSTAMP recieved!\n");
+ if (minor != STREAM_MODULE) {
+ printk(KERN_ERR
+ "SST ERR: called for AM handle minor %d\n", minor);
+ retval = -EINVAL;
+ break;
+ }
+ memcpy_fromio(&tstamp,
+ ((void *)(sst_drv_ctx->mailbox + SST_TIME_STAMP)
+ +(str_id * sizeof(tstamp))),
+ sizeof(tstamp));
+ time = tstamp.samples_rendered;
+ printk(KERN_DEBUG "SST DBG:samples rendered! = 0x%llx\n", time);
+ freq = (unsigned long long) tstamp.sampling_frequency;
+ printk(KERN_DEBUG "SST DBG:freq = %llx\n", freq);
+ time = time * 1000; /* converting it to ms */
+ mod = do_div(time, freq);
+ printk(KERN_DEBUG "SST DBG:mod = 0x%llx\n", mod);
+ printk(KERN_DEBUG "SST DBG:msec = 0x%llx\n", time);
+ retval = copy_to_user(ms, &time, sizeof(*ms));
+ if (retval)
+ printk(KERN_ERR
+ "SST ERR: copy failed = %d\n", retval);
+ break;
+ }
+
+ case _IOC_NR(SNDRV_SST_STREAM_START):{
+ struct stream_info *stream;
+
+ printk(KERN_DEBUG "SST DBG:SNDRV_SST_STREAM_START recieved!\n");
+ if (minor != STREAM_MODULE) {
+ printk(KERN_ERR
+ "SST ERR: called for AM handle minor %d\n", minor);
+ retval = -EINVAL;
+ break;
+ }
+ retval = sst_validate_strid(str_id);
+ if (retval)
+ break;
+ stream = &sst_drv_ctx->streams[str_id];
+ mutex_lock(&stream->lock);
+ if (stream->status == STREAM_INIT &&
+ stream->need_draining != true) {
+ printk(KERN_DEBUG "SST DBG:calling play frames...\n");
+ stream->prev = stream->status;
+ stream->status = STREAM_RUNNING;
+ if (stream->ops == STREAM_OPS_PLAYBACK ||
+ stream->ops == STREAM_OPS_PLAYBACK_DRM) {
+ retval = sst_play_frame(str_id);
+ /*sst_ospm_send_event(
+ OSPM_EVENT_SUBSYS_START_PLAY);*/
+ } else if (stream->ops == STREAM_OPS_CAPTURE)
+ retval = sst_capture_frame(str_id);
+ else {
+ printk(KERN_ERR
+ "SST ERR: Invalid ops 0x%x\n" , stream->ops);
+ retval = -EINVAL;
+ mutex_unlock(
+ &sst_drv_ctx->streams[str_id].lock);
+ break;
+ }
+ if (retval < 0) {
+ printk(KERN_ERR
+ "SST ERR: play/cptur frame fail \n");
+ stream->status = STREAM_INIT;
+ mutex_unlock(
+ &sst_drv_ctx->streams[str_id].lock);
+ break;
+ }
+ } else {
+ printk(KERN_ERR
+ "SST ERR: Inv strt for stream%d state0x%x\n", \
+ str_id, stream->status);
+ retval = -EINVAL;
+ }
+ mutex_unlock(&sst_drv_ctx->streams[str_id].lock);
+ break;
+ }
+
+ case _IOC_NR(SNDRV_SST_SET_TARGET_DEVICE): {
+ struct snd_sst_target_device *target_device;
+
+ printk(KERN_DEBUG "SST DBG:SNDRV_SST_SET_TARGET_PLAYBACK DEVICE recieved!\n");
+ target_device = (struct snd_sst_target_device *)arg;
+ BUG_ON(!target_device);
+ if (minor != AM_MODULE) {
+ printk(KERN_ERR
+ "SST ERR: called for non AM handle minor %d\n", minor);
+ retval = -EINVAL;
+ break;
+ }
+ retval = sst_target_device_select(target_device);
+ break;
+ }
+
+ case _IOC_NR(SNDRV_SST_DRIVER_INFO): {
+ struct snd_sst_driver_info *info =
+ (struct snd_sst_driver_info *)arg;
+
+ printk(KERN_DEBUG "SST DBG:SNDRV_SST_DRIVER_INFO recived \n");
+ info->version = SST_VERSION_NUM;
+ /* hard coding, shud get sumhow later */
+ info->active_pcm_streams = sst_drv_ctx->stream_cnt -
+ sst_drv_ctx->encoded_cnt;
+ info->active_enc_streams = sst_drv_ctx->encoded_cnt;
+ info->max_pcm_streams = MAX_ACTIVE_STREAM - MAX_ENC_STREAM;
+ info->max_enc_streams = MAX_ENC_STREAM;
+ info->buf_per_stream = sst_drv_ctx->mmap_len;
+ break;
+ }
+
+ case _IOC_NR(SNDRV_SST_STREAM_DECODE): {
+ struct snd_sst_dbufs *param =
+ (struct snd_sst_dbufs *)arg, dbufs_local;
+ int i;
+ struct snd_sst_buffs ibufs, obufs;
+ struct snd_sst_buff_entry ibuf_temp[param->ibufs->entries],
+ obuf_temp[param->obufs->entries];
+
+ printk(KERN_DEBUG "SST DBG:SNDRV_SST_STREAM_DECODE recived \n");
+ if (minor != STREAM_MODULE) {
+ printk(KERN_ERR
+ "SST ERR: called for AM handle minor %d\n", minor);
+ retval = -EINVAL;
+ break;
+ }
+ if (!param) {
+ printk(KERN_ERR "SST ERR: null param passed\n");
+ retval = -EINVAL;
+ break;
+ }
+
+ dbufs_local.input_bytes_consumed = param->input_bytes_consumed;
+ dbufs_local.output_bytes_produced =
+ param->output_bytes_produced;
+ dbufs_local.ibufs = &ibufs;
+ dbufs_local.obufs = &obufs;
+ dbufs_local.ibufs->entries = param->ibufs->entries;
+ dbufs_local.ibufs->type = param->ibufs->type;
+ dbufs_local.obufs->entries = param->obufs->entries;
+ dbufs_local.obufs->type = param->obufs->type;
+
+ dbufs_local.ibufs->buff_entry = ibuf_temp;
+ for (i = 0; i < dbufs_local.ibufs->entries; i++) {
+ ibuf_temp[i].buffer =
+ param->ibufs->buff_entry[i].buffer;
+ ibuf_temp[i].size =
+ param->ibufs->buff_entry[i].size;
+ }
+ dbufs_local.obufs->buff_entry = obuf_temp;
+ for (i = 0; i < dbufs_local.obufs->entries; i++) {
+ obuf_temp[i].buffer =
+ param->obufs->buff_entry[i].buffer;
+ obuf_temp[i].size =
+ param->obufs->buff_entry[i].size;
+ }
+ retval = sst_decode(str_id, &dbufs_local);
+ if (retval) {
+ printk(KERN_ERR"SST ERR: decoding failed \n");
+ retval = -EAGAIN;
+ }
+ retval = copy_to_user(¶m->input_bytes_consumed,
+ &dbufs_local.input_bytes_consumed,
+ sizeof(unsigned long long));
+ if (retval) {
+ printk(KERN_ERR"SST ERR: copy to user failed \n");
+ retval = -EAGAIN;
+ break;
+ }
+ retval = copy_to_user(¶m->output_bytes_produced,
+ &dbufs_local.output_bytes_produced,
+ sizeof(unsigned long long));
+ if (retval) {
+ printk(KERN_ERR"SST ERR: copy to user failed \n");
+ retval = -EAGAIN;
+ break;
+ }
+ printk(KERN_DEBUG "SST DBG:input_bytes_consumed=%lld\n",
+ param->input_bytes_consumed);
+ printk(KERN_DEBUG "SST DBG:output_bytes_produced=%lld\n",
+ param->output_bytes_produced);
+ printk(KERN_DEBUG "SST DBG:ibufs->entries=%d\n", param->ibufs->entries);
+ printk(KERN_DEBUG "SST DBG:input_consumed = %lld, output_produced = %lld \n",
+ param->input_bytes_consumed,
+ param->output_bytes_produced);
+ printk(KERN_DEBUG "SST DBG:first ibufs size=%d\n",
+ param->ibufs->buff_entry[0].size);
+ printk(KERN_DEBUG "SST DBG:first ibufs addr=%p\n",
+ param->ibufs->buff_entry[0].buffer);
+ printk(KERN_DEBUG "SST DBG:obufs->entries=%d\n", param->obufs->entries);
+ printk(KERN_DEBUG "SST DBG:first obufs size=%d\n",
+ param->obufs->buff_entry[0].size);
+ printk(KERN_DEBUG "SST DBG:first obufs addr=%p\n",
+ param->obufs->buff_entry[0].buffer);
+ break;
+ }
+
+ case _IOC_NR(SNDRV_SST_STREAM_DRAIN):
+ printk(KERN_DEBUG "SST DBG:SNDRV_SST_STREAM_DRAIN recived \n");
+ if (minor != STREAM_MODULE) {
+ printk(KERN_ERR
+ "SST ERR: caled for AM handle minr %d\n", minor);
+ retval = -EINVAL;
+ break;
+ }
+ retval = sst_drain_stream(str_id);
+ break;
+
+ case _IOC_NR(SNDRV_SST_STREAM_BYTES_DECODED): {
+ unsigned long long *bytes = (unsigned long long *)arg;
+ struct snd_sst_tstamp tstamp = {0};
+
+ printk(KERN_DEBUG "SST DBG:SNDRV_SST_STREAM_BYTES_DECODED recieved!\n");
+ if (minor != STREAM_MODULE) {
+ printk(KERN_ERR
+ "SST ERR: caled for AM hndle minr %d\n", minor);
+ retval = -EINVAL;
+ break;
+ }
+ memcpy_fromio(&tstamp,
+ ((void *)(sst_drv_ctx->mailbox + SST_TIME_STAMP)
+ +(str_id * sizeof(tstamp))),
+ sizeof(tstamp));
+ retval = copy_to_user(bytes, &tstamp.bytes_processed,
+ sizeof(*bytes));
+ printk(KERN_DEBUG "SST DBG:bytes processed =%lld\n", tstamp.bytes_processed);
+ if (retval)
+ printk(KERN_ERR
+ "SST ERR: copy failed = %d\n", retval);
+ break;
+ }
+ case _IOC_NR(SNDRV_SST_FW_INFO): {
+ struct snd_sst_fw_info *fw_info;
+
+ printk(KERN_DEBUG "SST DBG:SNDRV_SST_FW_INFO recived \n");
+
+ fw_info = kzalloc(sizeof(*fw_info), GFP_ATOMIC);
+ if (!fw_info) {
+ printk(KERN_ERR "SST ERR: mem alocation fail\n");
+ retval = -ENOMEM;
+ break;
+ }
+ retval = sst_get_fw_info(fw_info);
+ if (retval) {
+ printk(KERN_ERR
+ "SST ERR: sst_get_fw_info fail = %d\n", retval);
+ kfree(fw_info);
+ break;
+ }
+ retval = copy_to_user((struct snd_sst_dbufs *)arg,
+ fw_info, sizeof(*fw_info));
+ if (retval) {
+ printk(KERN_ERR
+ "SST ERR: copy to user failed %d\n", retval);
+ kfree(fw_info);
+ retval = -EIO;
+ break;
+ }
+ sst_print_fw_info(fw_info);
+ kfree(fw_info);
+ break;
+ }
+ default:
+ printk(KERN_DEBUG "SST DBG:IOCTL not supported yet !\n");
+ retval = -ENOTTY;
+ }
+ printk(KERN_DEBUG "SST DBG:...complete ret code = %d\n", retval);
+
+ return retval;
+}
+
+/*
+ Intelmid driver interface Routines
+*/
+
+void sst_process_mad_ops(struct work_struct *work)
+{
+ struct mad_ops_wq *mad_ops =
+ container_of(work, struct mad_ops_wq, wq);
+ int retval = 0;
+ struct stream_info *stream;
+
+ switch (mad_ops->control_op) {
+ case SST_SND_PAUSE:
+ retval = sst_pause_stream(mad_ops->stream_id);
+ break;
+ case SST_SND_RESUME:
+ retval = sst_resume_stream(mad_ops->stream_id);
+ break;
+ case SST_SND_DROP:
+ retval = sst_drop_stream(mad_ops->stream_id);
+ break;
+ case SST_SND_STREAM_PROCESS:
+ printk(KERN_DEBUG "SST DBG:play/capt frames...\n");
+ stream = &sst_drv_ctx->streams[mad_ops->stream_id];
+ if (stream->status == STREAM_UN_INIT)
+ return;
+ stream->prev = stream->status;
+ stream->status = STREAM_RUNNING;
+ stream->data_blk.on = false;
+ if (stream->ops == STREAM_OPS_PLAYBACK)
+ retval = sst_play_frame(mad_ops->stream_id);
+ else if (stream->ops == STREAM_OPS_CAPTURE)
+ retval = sst_capture_frame(mad_ops->stream_id);
+ else
+ printk(KERN_ERR
+ "SST ERR: invalid stream ops invoked \n");
+ if (retval < 0)
+ printk(KERN_ERR
+ "SST ERR: play/captur frames failed \n");
+ break;
+ default:
+ printk(KERN_ERR
+ "SST ERR: wrong control_ops reported\n");
+ }
+ return;
+}
+/**
+* sst_control_set - Set Control params
+* @control_list: list of controls to be set
+*
+* This function is called by MID sound card driver to set
+* SST/Sound card controls. This is registered with MID driver
+*/
+int sst_control_set(int control_element, void *value)
+{
+ int retval = 0, str_id = 0, status;
+ struct stream_info *stream;
+
+ if (sst_drv_ctx->sst_state == SST_UN_INIT) {
+ /* FW is not downloaded */
+ printk(KERN_DEBUG "SST DBG:DSP Downloading FW now...\n");
+ retval = sst_download_fw();
+ if (retval) {
+ printk(KERN_ERR
+ "SST ERR: FW download failed = 0x%x, abort\n", retval);
+ return retval;
+ }
+ }
+
+ switch (control_element) {
+ case SST_SND_ALLOC: {
+ struct snd_sst_params *str_param;
+ int pcm_id = sst_assign_pvt_id(sst_drv_ctx);
+ struct stream_info *str_info;
+
+ str_param = (struct snd_sst_params *)value;
+ BUG_ON(!str_param);
+ sst_print_params(str_param);
+ retval = sst_get_stream(str_param, pcm_id);
+ if (retval >= 0)
+ sst_drv_ctx->stream_cnt++;
+ /*if (str_param->ops == STREAM_OPS_PLAYBACK ||
+ str_param->ops == STREAM_OPS_PLAYBACK_DRM)
+ sst_ospm_send_event(OSPM_EVENT_SUBSYS_START_PLAY);*/
+ str_info = &sst_drv_ctx->streams[retval];
+ str_info->src = MAD_DRV;
+ break;
+ }
+
+ case SST_SND_PAUSE:
+ case SST_SND_RESUME:
+ case SST_SND_DROP:
+ sst_drv_ctx->mad_ops.control_op = control_element;
+ sst_drv_ctx->mad_ops.stream_id = *(int *)value;
+ queue_work(sst_drv_ctx->mad_wq, &sst_drv_ctx->mad_ops.wq);
+ break;
+
+ case SST_SND_FREE:
+ str_id = *(int *)value;
+ stream = &sst_drv_ctx->streams[str_id];
+ free_stream_context(str_id);
+ stream->pcm_substream = NULL;
+ stream->period_elapsed = NULL;
+ sst_drv_ctx->stream_cnt--;
+ break;
+
+ case SST_SND_STREAM_INIT: {
+ struct pcm_stream_info *str_info;
+ struct stream_info *stream;
+
+ printk(KERN_DEBUG "SST DBG:stream init called\n");
+ str_info = (struct pcm_stream_info *)value;
+ str_id = str_info->str_id;
+ retval = sst_validate_strid(str_id);
+ if (retval)
+ break;
+
+ stream = &sst_drv_ctx->streams[str_id];
+ printk(KERN_DEBUG "SST DBG:setting the period ptrs\n");
+ stream->pcm_substream = str_info->mad_substream;
+ stream->period_elapsed = str_info->period_elapsed;
+ stream->sfreq = str_info->sfreq;
+ stream->prev = stream->status;
+ stream->status = STREAM_INIT;
+ break;
+ }
+
+ case SST_SND_BUFFER_POINTER: {
+ struct pcm_stream_info *stream_info;
+ struct snd_sst_tstamp fw_tstamp = {0,};
+ struct stream_info *stream;
+
+ // printk(KERN_DEBUG "SST DBG:buffer pointer query\n");
+
+ stream_info = (struct pcm_stream_info *)value;
+ str_id = stream_info->str_id;
+ retval = sst_validate_strid(str_id);
+ if (retval)
+ break;
+ stream = &sst_drv_ctx->streams[str_id];
+
+ if (!stream->pcm_substream)
+ break;
+ memcpy_fromio(&fw_tstamp,
+ ((void *)(sst_drv_ctx->mailbox + SST_TIME_STAMP)
+ +(str_id * sizeof(fw_tstamp))),
+ sizeof(fw_tstamp));
+
+ // printk(KERN_DEBUG "SST DBG:strid = %d\n", str_id);
+
+ if (stream->ops == STREAM_OPS_PLAYBACK)
+ stream_info->buffer_ptr = fw_tstamp.samples_rendered;
+ else
+ stream_info->buffer_ptr = fw_tstamp.samples_processed;
+ /* printk(KERN_DEBUG "SST DBG:samples played = %lld\n",
+ stream_info->buffer_ptr);
+ */
+ break;
+ }
+ case SST_ENABLE_RX_TIME_SLOT: {
+ status = *(int *)value;
+ sst_drv_ctx->rx_time_slot_status = status ;
+ printk(KERN_DEBUG "SST DBG:in case:: **********SST_ENABLE_RX_TIME_SLOT*********** \n");
+ sst_enable_rx_timeslot(status);
+ break;
+ }
+ default:
+ /* Illegal case */
+ printk(KERN_ERR"SST ERR: illegal req\n");
+ return -EINVAL;
+ }
+// printk(KERN_DEBUG "SST DBG:...complete ret code = %d\n", retval);
+
+ return retval;
+}
+
+
+/**
+* sst_send_data_to_HW - send data buffers
+* @buffer_data: user buffer
+*
+* This function is called by MID sound card driver to send buffer
+* to HW. This is registered with MID driver
+*/
+int sst_send_buffer_to_HW(int str_id, struct stream_buffer *mad_buf)
+{
+ /* recvd a buffer map it to stream */
+ /* this is a PCM stream and playback */
+ int retval = 0;
+ bool flag_add = false;
+ struct sst_stream_bufs *sst_buf = NULL, *_sst_buf;
+ struct stream_info *stream;
+
+ if (!mad_buf || !mad_buf->addr || !mad_buf->length) {
+ printk(KERN_ERR
+ "SST ERR: Null Ptr or buf size = 0\n");
+ return -EINVAL;
+ }
+
+ if (sst_drv_ctx->sst_state != SST_FW_RUNNING) {
+ printk(KERN_ERR
+ "SST ERR: SST Not runng: %d\n", sst_drv_ctx->sst_state);
+ return -EBUSY;
+ }
+
+ retval = sst_validate_strid(str_id);
+ if (retval < 0)
+ return -EINVAL;
+
+ stream = &sst_drv_ctx->streams[str_id];
+ printk(KERN_DEBUG "SST DBG:stream status = %d strid=%d\n", stream->status, str_id);
+ printk(KERN_DEBUG "SST DBG:stream codec = %d, prevstate=%d\n",
+ stream->codec, stream->prev);
+ if (stream->status == STREAM_UN_INIT) {
+ printk(KERN_ERR"SST ERR: BAD REQUEST!\n");
+ return -EBADRQC;
+ }
+ printk(KERN_DEBUG "SST DBG:received addr=0x%x size = 0x%x\n",
+ (unsigned int)mad_buf->addr, mad_buf->length);
+ /* list is not empty */
+ list_for_each_entry_safe(sst_buf, _sst_buf, &stream->bufs, node) {
+ if (sst_buf->in_use == true)
+ continue;
+ else if ((int) mad_buf->addr !=
+ (int)sst_buf->addr + sst_buf->size)
+ continue;
+ else {
+ sst_buf->size += mad_buf->length;
+ flag_add = true;
+ printk(KERN_DEBUG "SST DBG:inc addr = 0x%p, base = 0x%x inc_val = 0x%x\n",
+ sst_buf->addr, sst_buf->size, mad_buf->length);
+ break;
+ }
+ }
+
+ if (flag_add == false) {
+ sst_buf = kzalloc(sizeof(*sst_buf), GFP_ATOMIC);
+ if (!sst_buf)
+ return -ENOMEM;
+ sst_buf->size = mad_buf->length;
+ sst_buf->addr = (void *)mad_buf->addr;
+ sst_buf->offset = 0;
+ sst_buf->in_use = false;
+ /*adding without locking FIXME*/
+ if( in_interrupt()) {
+ list_add_tail(&sst_buf->node, &stream->bufs);
+ } else {
+ spin_lock(&stream->pcm_lock);
+ list_add_tail(&sst_buf->node, &stream->bufs);
+ spin_unlock(&stream->pcm_lock);
+ }
+
+
+ flag_add = true;
+ printk(KERN_DEBUG "SST DBG:entry added addr = 0x%x size = 0x%x\n",
+ (unsigned int)mad_buf->addr, mad_buf->length);
+ }
+
+ if (stream->status == STREAM_INIT) {
+ sst_drv_ctx->mad_ops.control_op = SST_SND_STREAM_PROCESS;
+ sst_drv_ctx->mad_ops.stream_id = str_id;
+ queue_work(sst_drv_ctx->mad_wq, &sst_drv_ctx->mad_ops.wq);
+ }
+
+ return retval;
+}
+
+struct intel_sst_card_ops sst_pmic_ops = {
+ .control_set = sst_control_set,
+ .send_buffer = sst_send_buffer_to_HW,
+};
+
+/**
+* register_sst_card- function for sound card to register
+* @card: pointer to structure of operations
+* This function is called card driver loads and is ready for registration
+*/
+int register_sst_card(struct intel_sst_card_ops *card)
+{
+
+ if (!card || !card->module_name) {
+ printk(KERN_ERR "SST ERR: Null Pointer Passed\n");
+ return -EINVAL;
+ }
+
+ if (sst_drv_ctx->pmic_state == SND_MAD_UN_INIT) {
+ /* register this driver */
+ if ((strncmp(SST_CARD_NAMES, card->module_name,
+ strlen(SST_CARD_NAMES))) == 0) {
+ sst_drv_ctx->pmic_vendor = card->vendor_id;
+ sst_drv_ctx->scard_ops = card->scard_ops;
+ sst_pmic_ops.module_name = card->module_name;
+ sst_drv_ctx->pmic_state = SND_MAD_INIT_DONE;
+ sst_drv_ctx->rx_time_slot_status = RX_TIMESLOT_UNINIT;
+ card->control_set = sst_pmic_ops.control_set;
+ card->send_buffer = sst_pmic_ops.send_buffer;
+ sst_drv_ctx->scard_ops->card_status = SND_CARD_UN_INIT;
+ /* initialize card to know good state */
+ /*sst_drv_ctx->scard_ops->init_card();*/
+ return 0;
+ } else {
+ printk(KERN_ERR
+ "SST ERR: strcmp failed %s \n", card->module_name);
+ return -EINVAL;
+ }
+
+ } else {
+ /* already registered a driver */
+ printk(KERN_ERR
+ "SST ERR: Repeat for register..denied\n");
+ return -EBADRQC;
+ }
+ return 0;
+}
+EXPORT_SYMBOL_GPL(register_sst_card);
+
+/**
+* unregister_sst_card- function for sound card to un-register
+* @card: pointer to structure of operations
+* This function is called when card driver unloads
+*/
+void unregister_sst_card(struct intel_sst_card_ops *card)
+{
+ if (sst_pmic_ops.module_name == card->module_name) {
+ /* unreg */
+ sst_pmic_ops.module_name = "";
+ sst_drv_ctx->pmic_state = SND_MAD_UN_INIT;
+ printk(KERN_DEBUG "SST DBG:Unregistered %s\n", card->module_name);
+ }
+ return;
+}
+EXPORT_SYMBOL_GPL(unregister_sst_card);
+
+/**
+* lpe_mask_periphral_intr- function to mask SST DSP peripheral interrupt
+* @device: device interrupt that needs masking
+*/
+int lpe_mask_periphral_intr(enum lpe_periphral device)
+{
+ union sst_pimr_reg pimr = {{0},};
+ if (!sst_drv_ctx)
+ return -EIO;
+
+ pimr.full = readl(sst_drv_ctx->shim + SST_PIMR);
+
+ switch (device) {
+ case LPE_DMA:
+ pimr.part.dmac_sc = 1;
+ /* dummy register for shim workaround */
+ writel(pimr.full, sst_drv_ctx->shim + SST_ISRD);
+ writel(pimr.full, sst_drv_ctx->shim + SST_PIMR);
+ break;
+
+ case LPE_SSP0:
+ break;
+
+ case LPE_SSP1:
+ break;
+
+ default:
+ break;
+ }
+ return 0;
+}
+EXPORT_SYMBOL_GPL(lpe_mask_periphral_intr);
+
+/**
+* lpe_unmask_periphral_intr- function to unmask SST DSP peripheral interrupt
+* @device: device interrupt that needs unmasking
+*/
+int lpe_unmask_periphral_intr(enum lpe_periphral device)
+{
+ union sst_pimr_reg pimr = {{0},};
+ if (!sst_drv_ctx)
+ return -EIO;
+
+ pimr.full = readl(sst_drv_ctx->shim + SST_PIMR);
+
+ switch (device) {
+ case LPE_DMA:
+ pimr.part.dmac_sc = 0;
+ /* dummy register for shim workaround */
+ writel(pimr.full, sst_drv_ctx->shim + SST_ISRD);
+ writel(pimr.full, sst_drv_ctx->shim + SST_PIMR);
+ break;
+
+ case LPE_SSP0:
+ break;
+
+ case LPE_SSP1:
+ break;
+
+ default:
+ break;
+ }
+ return 0;
+
+}
+EXPORT_SYMBOL_GPL(lpe_unmask_periphral_intr);
+
+/**
+* lpe_periphral_intr_status- function returns SST peripheral interrupt status
+* @device: device for which the status is enquired
+* @status: out parameters with the status of the peripheral device
+*/
+int lpe_periphral_intr_status(enum lpe_periphral device, int *status)
+{
+ union sst_pisr_reg pisr = {{0},};
+ if (!sst_drv_ctx)
+ return -EIO;
+
+ pisr.full = readl(sst_drv_ctx->shim + SST_PISR);
+
+ switch (device) {
+ case LPE_DMA:
+ *status = pisr.part.dmac;
+ break;
+
+ case LPE_SSP0:
+ break;
+
+ case LPE_SSP1:
+ break;
+
+ default:
+ break;
+ }
+ return 0;
+}
+EXPORT_SYMBOL_GPL(lpe_periphral_intr_status);
--
1.6.2.2
|