summaryrefslogtreecommitdiff
path: root/recipes/linux/linux-kirkwood/0003-ARM-Kirkwood-Sound-Sound-driver-added.patch
blob: 2fa1df330a8a5d531471e4ef94ad9c9788bdd42c (plain)
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
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
From f2830dc0470513c5daa22360c63129bf9f578e59 Mon Sep 17 00:00:00 2001
From: Tanmay Upadhyay <tanmay.upadhyay@einfochips.com>
Date: Tue, 24 Nov 2009 21:49:24 +0530
Subject: [PATCH] ARM: Kirkwood: Sound: Sound driver added

The driver is based on the Marvell kirkwood sound driver available in
2.6.22.18 kernel.

Signed-off-by: Tanmay Upadhyay <tanmay.upadhyay@einfochips.com>
---
 arch/arm/mach-kirkwood/common.c                |   39 +
 arch/arm/mach-kirkwood/common.h                |    2 +
 arch/arm/mach-kirkwood/include/mach/kirkwood.h |    3 +
 arch/arm/mach-kirkwood/openrd_client-setup.c   |   24 +
 include/linux/mv88fx_audio.h                   |  111 ++
 sound/soc/Kconfig                              |    1 +
 sound/soc/Makefile                             |    1 +
 sound/soc/kirkwood/Kconfig                     |   37 +
 sound/soc/kirkwood/Makefile                    |    7 +
 sound/soc/kirkwood/cs42l51.c                   |  303 +++++
 sound/soc/kirkwood/cs42l51.h                   |   54 +
 sound/soc/kirkwood/kirkwood_audio_hal.c        |  821 +++++++++++++
 sound/soc/kirkwood/kirkwood_audio_hal.h        |  109 ++
 sound/soc/kirkwood/kirkwood_audio_regs.h       |  310 +++++
 sound/soc/kirkwood/kirkwood_pcm.c              | 1495 ++++++++++++++++++++++++
 15 files changed, 3317 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/mv88fx_audio.h
 create mode 100644 sound/soc/kirkwood/Kconfig
 create mode 100644 sound/soc/kirkwood/Makefile
 create mode 100644 sound/soc/kirkwood/cs42l51.c
 create mode 100644 sound/soc/kirkwood/cs42l51.h
 create mode 100644 sound/soc/kirkwood/kirkwood_audio_hal.c
 create mode 100644 sound/soc/kirkwood/kirkwood_audio_hal.h
 create mode 100644 sound/soc/kirkwood/kirkwood_audio_regs.h
 create mode 100644 sound/soc/kirkwood/kirkwood_pcm.c

diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
index 242dd07..606514f 100644
--- a/arch/arm/mach-kirkwood/common.c
+++ b/arch/arm/mach-kirkwood/common.c
@@ -15,6 +15,7 @@
 #include <linux/mbus.h>
 #include <linux/mv643xx_eth.h>
 #include <linux/mv643xx_i2c.h>
+#include <linux/mv88fx_audio.h>
 #include <linux/ata_platform.h>
 #include <linux/mtd/nand.h>
 #include <linux/spi/orion_spi.h>
@@ -977,3 +978,41 @@ static int __init kirkwood_clock_gate(void)
 	return 0;
 }
 late_initcall(kirkwood_clock_gate);
+
+/*****************************************************************************
+ * Audio
+ ****************************************************************************/
+
+static struct resource kirkwood_audio_resources[] = {
+	[0] = {
+		.start	= AUDIO_PHYS_BASE,
+		.end	= AUDIO_PHYS_BASE + SZ_16K - 1,
+		.flags	= IORESOURCE_MEM,
+	},
+	[1] = {
+		.start	= IRQ_KIRKWOOD_I2S,
+		.end	= IRQ_KIRKWOOD_I2S,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+static u64 kirkwood_audio_dmamask = 0xFFFFFFFFUL;
+
+static struct platform_device kirkwood_audio = {
+	.name		= MV88FX_AUDIO_NAME,
+	.id		= -1,
+	.num_resources	= ARRAY_SIZE(kirkwood_audio_resources),
+	.resource	= kirkwood_audio_resources,
+	.dev		= {
+		.dma_mask = &kirkwood_audio_dmamask,
+		.coherent_dma_mask = 0xffffffff,
+	},
+};
+
+void __init kirkwood_audio_init(struct mv88fx_snd_platform_data *audio_data)
+{
+	kirkwood_clk_ctrl |= CGC_AUDIO;
+	kirkwood_audio.dev.platform_data = audio_data;
+
+	platform_device_register(&kirkwood_audio);
+}
diff --git a/arch/arm/mach-kirkwood/common.h b/arch/arm/mach-kirkwood/common.h
index d7de434..b79a25c 100644
--- a/arch/arm/mach-kirkwood/common.h
+++ b/arch/arm/mach-kirkwood/common.h
@@ -16,6 +16,7 @@ struct mv643xx_eth_platform_data;
 struct mv_sata_platform_data;
 struct mvsdio_platform_data;
 struct mtd_partition;
+struct mv88fx_snd_platform_data;
 
 /*
  * Basic Kirkwood init functions used early by machine-setup.
@@ -41,6 +42,7 @@ void kirkwood_i2c_init(void);
 void kirkwood_uart0_init(void);
 void kirkwood_uart1_init(void);
 void kirkwood_nand_init(struct mtd_partition *parts, int nr_parts, int delay);
+void kirkwood_audio_init(struct mv88fx_snd_platform_data *audio_data);
 
 extern int kirkwood_tclk;
 extern struct sys_timer kirkwood_timer;
diff --git a/arch/arm/mach-kirkwood/include/mach/kirkwood.h b/arch/arm/mach-kirkwood/include/mach/kirkwood.h
index a15cf0e..838151d 100644
--- a/arch/arm/mach-kirkwood/include/mach/kirkwood.h
+++ b/arch/arm/mach-kirkwood/include/mach/kirkwood.h
@@ -96,6 +96,9 @@
 
 #define SDIO_PHYS_BASE		(KIRKWOOD_REGS_PHYS_BASE | 0x90000)
 
+#define AUDIO_PHYS_BASE		(KIRKWOOD_REGS_PHYS_BASE | 0xA0000)
+#define AUDIO_VIRT_BASE		(KIRKWOOD_REGS_VIRT_BASE | 0xA0000)
+
 /*
  * Supported devices and revisions.
  */
diff --git a/arch/arm/mach-kirkwood/openrd_client-setup.c b/arch/arm/mach-kirkwood/openrd_client-setup.c
index 63b4a2c..2ed080b 100644
--- a/arch/arm/mach-kirkwood/openrd_client-setup.c
+++ b/arch/arm/mach-kirkwood/openrd_client-setup.c
@@ -14,6 +14,7 @@
 #include <linux/mtd/partitions.h>
 #include <linux/ata_platform.h>
 #include <linux/mv643xx_eth.h>
+#include <linux/mv88fx_audio.h>
 #include <linux/gpio.h>
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
@@ -59,6 +60,23 @@ static unsigned int openrd_client_mpp_config[] __initdata = {
 	0
 };
 
+#if defined(CONFIG_SND_MV88FX_SOC) || defined(CONFIG_SND_MV88FX_SOC_MODULE)
+static struct mv88fx_snd_platform_data openrd_client_audio_data = {
+	.i2c_bus_no  = 0,
+	.i2c_address = 0x4A,
+/* 0 - NA, 1 - mono, 2 - stereo */
+#ifdef CONFIG_SND_MV88FX_SOC_I2S
+	.i2s_rec     = 1,
+	.i2s_play    = 2,
+#else
+	.spdif_rec   = 1,
+	.spdif_play  = 2,
+#endif
+	.dram        = &kirkwood_mbus_dram_info,
+	.base_offset = AUDIO_PHYS_BASE - KIRKWOOD_REGS_PHYS_BASE,
+};
+#endif
+
 static void __init openrd_client_init(void)
 {
 	/*
@@ -80,6 +98,12 @@ static void __init openrd_client_init(void)
 	kirkwood_sdio_init(&openrd_client_mvsdio_data);
 
 	kirkwood_i2c_init();
+#if defined(CONFIG_SND_MV88FX_SOC) || defined(CONFIG_SND_MV88FX_SOC_MODULE)
+	/* If built as a part of kernel or as a module
+	 * initialize audio */
+	openrd_client_audio_data.tclk = kirkwood_tclk,
+	kirkwood_audio_init(&openrd_client_audio_data);
+#endif
 }
 
 static int __init openrd_client_pcie_init(void)
diff --git a/include/linux/mv88fx_audio.h b/include/linux/mv88fx_audio.h
new file mode 100644
index 0000000..6d36a3f
--- /dev/null
+++ b/include/linux/mv88fx_audio.h
@@ -0,0 +1,111 @@
+/*
+ *
+ *	Marvell Orion Alsa Sound driver
+ *
+ *	Author: Maen Suleiman
+ *	Copyright (C) 2008 Marvell Ltd.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#ifndef __LINUX_MV88FX_SND_H
+#define __LINUX_MV88FX_SND_H
+
+#include <linux/mbus.h>
+
+#define MV88FX_AUDIO_NAME   "mv88fx_snd"
+
+#undef MV88FX_SND_DEBUG
+#ifdef MV88FX_SND_DEBUG
+#define mv88fx_snd_debug(fmt, arg...) printk(KERN_DEBUG fmt, ##arg)
+#else
+	#define mv88fx_snd_debug(a...)
+#endif
+
+#define MV_AUDIO_MAX_ADDR_DECODE_WIN      2
+#define MV_AUDIO_RECORD_WIN_NUM           0
+#define MV_AUDIO_PLAYBACK_WIN_NUM         1
+
+#define MV_AUDIO_WIN_CTRL_REG(win)        (0xA04 + ((win)<<3))
+#define MV_AUDIO_WIN_BASE_REG(win)        (0xA00 + ((win)<<3))
+
+struct mv88fx_snd_platform_data {
+	u8  i2c_bus_no;
+	u16 i2c_address;
+	u32 spdif_rec;
+	u32 spdif_play;
+	u32 i2s_rec;
+	u32 i2s_play;
+	u32 tclk;
+	u32 base_offset;
+	struct mbus_dram_target_info *dram;
+};
+
+struct mv88fx_snd_stream {
+	struct snd_pcm_substream *substream;
+	struct device          *dev;
+	int    direction;            /* playback or capture */
+	#define PLAYBACK        0
+	#define CAPTURE         1
+	unsigned int    dig_mode;    /* i2s,spdif,both */
+	#define I2S             1
+	#define SPDIF           2
+	int stereo;                  /* mono, stereo */
+	int mono_mode;               /* both mono, left mono, right mono */
+	#define MONO_BOTH       0
+	#define MONO_LEFT       1
+	#define MONO_RIGHT      2
+	int clock_src;
+	#define DCO_CLOCK	0
+	#define SPCR_CLOCK	1
+	#define EXTERN_CLOCK	2
+	int rate;
+	int stat_mem;                /* Channel status source*/
+	int format;
+	#define SAMPLE_32IN32   0
+	#define SAMPLE_24IN32   1
+	#define SAMPLE_20IN32   2
+	#define SAMPLE_16IN32   3
+	#define SAMPLE_16IN16   4
+	unsigned int  dma_addr;
+	unsigned int  dma_size;
+	unsigned int  period_size;
+	unsigned int  spdif_status[4]; /* SPDIF status */
+	unsigned char *area;           /* virtual pointer */
+	dma_addr_t    addr;            /* physical address */
+};
+
+struct mv88fx_snd_chip {
+	struct mv88fx_snd_stream *stream[2];          /* run time values*/
+	struct mv88fx_snd_stream *stream_defaults[2]; /* default values*/
+	spinlock_t      reg_lock;	/* Register access spinlock */
+	struct resource	*res;		/* resource for IRQ and base*/
+	void __iomem	*base;		/* Audio base address of the host */
+	unsigned int    audio_offset;   /* Offset to audio base register
+					 * from internal base register */
+	int irq;
+	int loopback;                   /* When Loopback is enabled, playback
+					 * data is looped back to be recorded */
+	int ch_stat_valid;              /* Playback SPDIF channel validity bit
+					 * value when REG selected */
+	int burst;                      /* DMA Burst Size */
+
+	#define SPDIF_MEM_STAT         0
+	#define SPDIF_REG_STAT         1
+	unsigned int dco_ctrl_offst;
+	int	pcm_mode;               /* pcm, nonpcm*/
+	#define PCM             0
+	#define NON_PCM         1
+	int     stereo;
+};
+
+#define MV88FX_SND_MIN_PERIODS		8
+#define MV88FX_SND_MAX_PERIODS		16
+#define	MV88FX_SND_MIN_PERIOD_BYTES	0x4000
+#define	MV88FX_SND_MAX_PERIOD_BYTES	0x4000
+
+#endif /* __LINUX_MV88FX_SND_H */
diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig
index b1749bc..9fc88d8 100644
--- a/sound/soc/Kconfig
+++ b/sound/soc/Kconfig
@@ -36,6 +36,7 @@ source "sound/soc/s3c24xx/Kconfig"
 source "sound/soc/s6000/Kconfig"
 source "sound/soc/sh/Kconfig"
 source "sound/soc/txx9/Kconfig"
+source "sound/soc/kirkwood/Kconfig"
 
 # Supported codecs
 source "sound/soc/codecs/Kconfig"
diff --git a/sound/soc/Makefile b/sound/soc/Makefile
index 1470141..6c39266 100644
--- a/sound/soc/Makefile
+++ b/sound/soc/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_SND_SOC)	+= s3c24xx/
 obj-$(CONFIG_SND_SOC)	+= s6000/
 obj-$(CONFIG_SND_SOC)	+= sh/
 obj-$(CONFIG_SND_SOC)	+= txx9/
+obj-$(CONFIG_SND_SOC)	+= kirkwood/
diff --git a/sound/soc/kirkwood/Kconfig b/sound/soc/kirkwood/Kconfig
new file mode 100644
index 0000000..df4d527
--- /dev/null
+++ b/sound/soc/kirkwood/Kconfig
@@ -0,0 +1,37 @@
+config SND_MV88FX_SOC
+	tristate "SoC Audio for the Marvell 88FX chip"
+	depends on ARCH_KIRKWOOD
+	help
+	  Say Y or M if you want to add audio support for Marvell 88FX SoCs:
+	  88F6180, 88F6192 and 88F6281
+
+choice
+	prompt "Audio Interface"
+	default SND_MV88FX_SOC_I2S
+	depends on SND_MV88FX_SOC
+
+config SND_MV88FX_SOC_I2S
+	bool "I2S"
+	help
+	  Select this option if your board uses I2S interface to communicate
+	  with the audio codec
+
+config SND_MV88FX_SOC_SPDIF
+	bool "SPDIF"
+	help
+	  Select this option if your board uses SPDIF interface to communicate
+	  with the audio codec
+
+endchoice
+
+choice
+	prompt "Codec IC"
+	default SND_SOC_CS42L51
+	depends on SND_MV88FX_SOC
+
+config SND_SOC_CS42L51
+	bool "CS42L51"
+	help
+	  Select this option if your board has audio codec CS42L51
+
+endchoice
diff --git a/sound/soc/kirkwood/Makefile b/sound/soc/kirkwood/Makefile
new file mode 100644
index 0000000..57674ad
--- /dev/null
+++ b/sound/soc/kirkwood/Makefile
@@ -0,0 +1,7 @@
+
+snd-soc-kirkwood-objs := kirkwood_pcm.o kirkwood_audio_hal.o
+ifdef CONFIG_SND_SOC_CS42L51
+snd-soc-kirkwood-objs += cs42l51.o
+endif
+
+obj-$(CONFIG_SND_MV88FX_SOC) += snd-soc-kirkwood.o
diff --git a/sound/soc/kirkwood/cs42l51.c b/sound/soc/kirkwood/cs42l51.c
new file mode 100644
index 0000000..08d3028
--- /dev/null
+++ b/sound/soc/kirkwood/cs42l51.c
@@ -0,0 +1,303 @@
+/*
+ *
+ *	Marvell Orion Alsa Sound driver
+ *
+ *	Author: Maen Suleiman
+ *	Copyright (C) 2008 Marvell Ltd.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#include <linux/ioport.h>
+#include <linux/platform_device.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/version.h>
+#include <linux/i2c.h>
+#include <sound/core.h>
+#include <sound/initval.h>
+#include <sound/control.h>
+#include <sound/pcm.h>
+#include <sound/asoundef.h>
+#include <sound/asound.h>
+
+#include "cs42l51.h"
+
+/* FIXME: This code is not written in driver module style. This is written as
+ *        helper for SOC driver */
+
+static struct i2c_client *client;
+
+static int cs42l51_add_i2c_device(unsigned char i2c_bus_no,
+				  unsigned short i2c_add)
+{
+	struct i2c_board_info info;
+	struct i2c_adapter *adapter;
+
+	memset(&info, 0, sizeof(struct i2c_board_info));
+	info.addr = i2c_add;
+	strlcpy(info.type, "cs42l51", I2C_NAME_SIZE);
+
+	adapter = i2c_get_adapter(i2c_bus_no);
+	if (!adapter) {
+		snd_printk("can't get i2c adapter\n");
+		return -ENODEV;
+	}
+
+	client = i2c_new_device(adapter, &info);
+	i2c_put_adapter(adapter);
+	if (!client) {
+		snd_printk("can't add i2c device\n");
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
+void cs42l51_del_i2c_device(void)
+{
+	if (client)
+		i2c_unregister_device(client);
+	client = NULL;
+}
+
+/*
+ * offset: Register offset to start reading with
+ * buf   : Pointer to the buffer to store the read data
+ * num   : Number of registers to read
+ *
+ * Returns -ve errorno else number of registers read
+ */
+
+static int cs42l51_reg_read(unsigned char offset, unsigned char *buf, int num)
+{
+	int ret = 0;
+
+	/* Set autoincrement bit */
+	offset |= CODEC_INCR_ADDR;
+
+	/* Send register offset */
+	ret = i2c_master_send(client, &offset, 1);
+	if (ret != 1) {
+		snd_printd("Could not write register offset\n");
+		return 0;
+	}
+
+	return i2c_master_recv(client, buf, num);
+}
+
+/*
+ * offset: Register offset to write
+ * data  : Data to be written
+ *
+ * Returns -ve errorno else number of registers written (=1)
+ */
+
+static int cs42l51_reg_write(unsigned char offset, unsigned char data)
+{
+	int ret = 0;
+	unsigned char buf[2];
+
+	buf[0] = offset;
+	buf[1] = data;
+
+	/* Send register offset & data */
+	ret = i2c_master_send(client, &buf[0], 2);
+
+	return (ret == 2) ? 1 : ret;
+}
+
+static int codec_init(int adc_mode, int digital_if_format,
+	       unsigned char i2c_bus_no, unsigned short i2c_add)
+{
+	unsigned char reg_data;
+
+	if (cs42l51_add_i2c_device(i2c_bus_no, i2c_add))
+		return 1;
+
+	if (cs42l51_reg_read(CODEC_ID_REG, &reg_data, 1) < 0)
+		goto codec_init_error;
+
+	if (CODEC_CHIP_ID != (reg_data >> 3) ||
+	    CODEC_REV_ID  != (reg_data & 0x7)) {
+		snd_printd("Error: Invalid Cirrus Logic chip/rev ID!\n");
+		return 1;
+	}
+
+	if (cs42l51_reg_read(CODEC_IF_CTRL_REG, &reg_data, 1) < 0)
+		goto codec_init_error;
+
+	reg_data = (reg_data & ~(0x7<<3)) | (digital_if_format << 3);
+
+	if (LEFT_JUSTIFIED_MODE == adc_mode)
+		reg_data &= (~0x4);
+	else
+		reg_data |= 0x4;
+
+	if (cs42l51_reg_write(CODEC_IF_CTRL_REG, reg_data) < 0)
+		goto codec_init_error;
+
+	return 0;
+
+codec_init_error:
+	snd_printd("I2C error\n");
+	return 1;
+}
+
+/*
+ * Initialize the audio decoder.
+ */
+
+int cs42l51_init(int adc_mode, int digital_if_format, int rec,
+		 unsigned char i2c_bus_no, unsigned short i2c_add)
+{
+	if (codec_init(adc_mode, digital_if_format, i2c_bus_no, i2c_add)) {
+		snd_printk("Error: Audio Codec init failed\n");
+		return 1;
+	}
+
+	/* Use the signal processor */
+	if (cs42l51_reg_write(0x9, 0x40) < 0)
+		goto error;
+
+	/* Unmute PCM-A & PCM-B and set default */
+	if (cs42l51_reg_write(0x10, 0x60) < 0)
+		goto error;
+	if (cs42l51_reg_write(0x11, 0x60) < 0)
+		goto error;
+
+	/* default for AOUTx */
+	if (cs42l51_reg_write(0x16, 0x05) < 0)
+		goto error;
+	if (cs42l51_reg_write(0x17, 0x05) < 0)
+		goto error;
+
+	/* swap channels */
+	if (cs42l51_reg_write(0x18, 0xff) < 0)
+		goto error;
+
+	/* MIC Power Control: power down mIC in channel B, power on channel A
+	 * Recommended seq. in datasheet:
+	 *  1. Enable the PDN bit
+	 *  2. Enable power-down for the selected channels
+	 *  3. Disable the PDN bit */
+
+	/* Note: Tested for mono recording only */
+	if (!rec) {
+		/* Enable power down */
+		if (cs42l51_reg_write(0x2, 0x11) < 0)
+			goto error;
+
+		/* No record - Power down both channels */
+		if (cs42l51_reg_write(0x2, 0x17) < 0)
+			goto error;
+
+		/* Disable power down */
+		if (cs42l51_reg_write(0x2, 0x16) < 0)
+			goto error;
+	} else {
+		if (rec == 2) {
+			/* Setreo recording - by default both channels are up */
+
+			/* MIC In channel selection - Select channel 3
+			 *                            unmute both channels */
+			if (cs42l51_reg_write(0x7, 0xF0) < 0)
+				goto error;
+
+			/* Power up mic pre-amplifier for both channels */
+			if (cs42l51_reg_write(0x3, 0xA0) < 0)
+				goto error;
+		} else {
+			/* Enable power down */
+			if (cs42l51_reg_write(0x2, 0x11) < 0)
+				goto error;
+
+			/* Mono recording - Power down Channel B */
+			if (cs42l51_reg_write(0x2, 0x15) < 0)
+				goto error;
+
+			/* Disable power down */
+			if (cs42l51_reg_write(0x2, 0x14) < 0)
+				goto error;
+
+			/* MIC In channel selection - Select channel 3
+			 *                            Mute Channel B */
+			if (cs42l51_reg_write(0x7, 0xF2) < 0)
+				goto error;
+
+			/* Power down mic pre-amplifier for Channel B*/
+			if (cs42l51_reg_write(0x3, 0xA8) < 0)
+				goto error;
+		}
+	}
+
+	return 0;
+error:
+	snd_printk("I2C error\n");
+	return 1;
+}
+
+#define AUD_NUM_VOLUME_STEPS  (40)
+static unsigned char auddec_volume_mapping[AUD_NUM_VOLUME_STEPS] = {
+	0x19,	0xB2,	0xB7,	0xBD,	0xC3,	0xC9,	0xCF,	0xD5,
+	0xD8,	0xE1,	0xE7,	0xED,	0xF3,	0xF9,	0xFF,	0x00,
+	0x01,	0x02,	0x03,	0x04,	0x05,	0x06,	0x07,	0x08,
+	0x09,	0x0A,	0x0B,	0x0C,	0x0D,	0x0E,	0x0F,	0x10,
+	0x11,	0x12,	0x13,	0x14,	0x15,	0x16,	0x17,	0x18
+};
+
+
+/*
+ * Get the audio decoder volume for both channels.
+ * 0 is lowest volume, AUD_NUM_VOLUME_STEPS-1 is the highest volume.
+ */
+
+void cs42l51_vol_get(unsigned char *vol_list)
+{
+	unsigned char reg_data[2];
+	unsigned char i, vol_idx = 0;
+
+	if (cs42l51_reg_read(0x16 + vol_idx, reg_data, 2) < 0) {
+		snd_printd("I2C error\n");
+		snd_printk("Couldn't get volume\n");
+		return;
+	}
+
+	for (; vol_idx < 2; vol_idx++) {
+		/* Look for the index that mapps to this dB value.  */
+		for (i = 0; i < AUD_NUM_VOLUME_STEPS; i++) {
+			if (reg_data[vol_idx] == auddec_volume_mapping[i])
+				break;
+			if ((auddec_volume_mapping[i] >
+			      auddec_volume_mapping[AUD_NUM_VOLUME_STEPS-1])
+			    && (reg_data[vol_idx] > auddec_volume_mapping[i])
+			    && (reg_data[vol_idx] < auddec_volume_mapping[i+1]))
+				break;
+		}
+		vol_list[vol_idx] = i;
+	}
+}
+
+/*
+ * Set the audio decoder volume for both channels.
+ * 0 is lowest volume, AUD_NUM_VOLUME_STEPS-1 is the highest volume.
+ */
+void cs42l51_vol_set(unsigned char *vol_list)
+{
+	unsigned int  vol_idx;
+
+	for (vol_idx = 0; vol_idx < 2; vol_idx++) {
+		if (vol_list[vol_idx] >= AUD_NUM_VOLUME_STEPS)
+			vol_list[vol_idx] = AUD_NUM_VOLUME_STEPS - 1;
+
+		if (cs42l51_reg_write(0x16 + vol_idx,
+		    auddec_volume_mapping[vol_list[vol_idx]]) < 0) {
+			snd_printd("I2C error\n");
+			snd_printk("Couldn't set volume\n");
+			return;
+		}
+	}
+}
diff --git a/sound/soc/kirkwood/cs42l51.h b/sound/soc/kirkwood/cs42l51.h
new file mode 100644
index 0000000..fbfca94
--- /dev/null
+++ b/sound/soc/kirkwood/cs42l51.h
@@ -0,0 +1,54 @@
+/*
+ * Audio codec CS42L51 data definition file
+ */
+
+#ifndef _CS42L51_H_
+#define _CS42L51_H_
+
+#define CODEC_CHIP_ID   0x1B
+#define CODEC_REV_ID    0x1
+
+#define CODEC_ID_REG                    0x1
+#define CODEC_IF_CTRL_REG               0x4
+#define CODEC_ADC_INPUT_INV_MUTE_REG    0x7
+#define CODEC_DAC_OUTPUT_CTRL_REG       0x8
+#define CODEC_DAC_CTRL_REG              0x9
+#define CODEC_PGAA_VOL_CTRL_REG         0xa
+#define CODEC_TONE_CTRL_REG             0x15
+#define CODEC_VOL_OUTA_CTRL_REG         0x16
+
+/* Set bit # 7 to 1 to get into auto incremental addressing mode */
+#define CODEC_INCR_ADDR                 0x80
+
+#define FALSE 0
+#define TRUE  1
+
+/* Selects the digital interface format used for the data in on SDIN. */
+enum dac_digital_if_format {
+	L_JUSTIFIED_UP_TO_24_BIT,
+	I2S_UP_TO_24_BIT,
+	R_JUSTIFIED_UP_TO_24_BIT,
+	R_JUSTIFIED_20_BIT,
+	R_JUSTIFIED_18_BIT,
+	R_JUSTIFIED_16_BIT
+
+};
+
+/* Selects either the I2S or Left-Justified digital interface format for the
+   data on SDOUT. */
+enum adc_mode {
+	LEFT_JUSTIFIED_MODE,
+	I2S_MODE
+};
+
+/* Initialize the Cirrus Logic device */
+int cs42l51_init(int adc_mode, int digital_if_format, int rec,
+		 unsigned char i2c_bus_no, unsigned short i2c_add);
+
+/* Function to control output volume (playback) */
+void cs42l51_vol_get(unsigned char *vol_list);
+void cs42l51_vol_set(unsigned char *vol_list);
+
+void cs42l51_del_i2c_device(void);
+#endif  /* _CS42L51_H_ */
+
diff --git a/sound/soc/kirkwood/kirkwood_audio_hal.c b/sound/soc/kirkwood/kirkwood_audio_hal.c
new file mode 100644
index 0000000..31d5144
--- /dev/null
+++ b/sound/soc/kirkwood/kirkwood_audio_hal.c
@@ -0,0 +1,821 @@
+/*
+ * Sound driver for Marvell Kirkwood family SOCs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#include <linux/io.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <linux/spinlock.h>
+#include <linux/mv88fx_audio.h>
+#include "kirkwood_audio_hal.h"
+
+static void mv_audio_init(void __iomem *base);
+static void audio_setup_wins(void __iomem *base,
+			     struct mbus_dram_target_info *dram);
+static int set_window_as_per_baseadd(void __iomem *base, unsigned int baseadd,
+				     unsigned int audio_offset, int win_num);
+
+/* Clocks Control and Status related*/
+static int mv_audio_dco_ctrl_set(struct mv_audio_freq_data *dcoCtrl,
+			  void __iomem *base);
+
+/* Audio PlayBack related*/
+static int mv_audio_playback_control_set(void __iomem *base, unsigned int
+			 audio_offset, struct mv_audio_playback_ctrl *ctrl);
+
+/* Audio SPDIF PlayBack related*/
+static void mv_spdif_playback_ctrl_set(void __iomem *base,
+					struct mv_spdif_playback_ctrl *ctrl);
+
+/* Audio I2S PlayBack related*/
+static int mv_i2s_playback_ctrl_set(void __iomem *base,
+				struct mv_i2s_playback_ctrl *ctrl);
+
+/* Audio Recording*/
+static int  mv_audio_record_control_set(struct mv_audio_record_ctrl *ctrl,
+				unsigned int audio_offset, void __iomem *base);
+
+/* SPDIF Recording Related*/
+static int spdif_record_tclock_set(void __iomem *base, unsigned int tclk);
+
+/* I2S Recording Related*/
+static int mv_i2s_record_cntrl_set(struct mv_i2s_record_ctrl *ctrl,
+				   void __iomem *base);
+
+static inline unsigned int audio_burst_bytes_num_get(int burst)
+{
+	switch (burst) {
+	case AUDIO_32BYTE_BURST:
+		return 32;
+	case AUDIO_128BYTE_BURST:
+		return 128;
+	default:
+		return 0xffffffff;
+	}
+}
+
+int mv88fx_snd_hw_init(struct snd_card *card)
+{
+	void __iomem *base = chip->base;
+	struct mv88fx_snd_platform_data *platform_data =
+	 card->dev->platform_data;
+
+	if (platform_data->i2s_rec || platform_data->i2s_play)
+		if (codec_init(I2S_MODE, I2S_UP_TO_24_BIT,
+		    platform_data->i2s_rec, platform_data->i2c_bus_no,
+		    platform_data->i2c_address)) {
+			snd_printk("Initializing CS42L51 failed\n");
+			return 1;
+	}
+
+	writel(0xffffffff, (base + MV_AUDIO_INT_CAUSE_REG));
+	writel(0, (base + MV_AUDIO_INT_MASK_REG));
+	writel(0, (base + MV_AUDIO_SPDIF_REC_INT_CAUSE_MASK_REG));
+
+	mv_audio_init(base);
+
+	audio_setup_wins(base, platform_data->dram);
+
+	/* Disable all playback/recording */
+	writel(readl(base + MV_AUDIO_PLAYBACK_CTRL_REG) &
+	       (~(APCR_PLAY_I2S_ENABLE_MASK | APCR_PLAY_SPDIF_ENABLE_MASK)),
+	       (base + MV_AUDIO_PLAYBACK_CTRL_REG));
+
+	writel(readl(base + MV_AUDIO_RECORD_CTRL_REG) &
+	       (~(ARCR_RECORD_SPDIF_EN_MASK | ARCR_RECORD_I2S_EN_MASK)),
+	       (base + MV_AUDIO_RECORD_CTRL_REG));
+
+	if (spdif_record_tclock_set(base, platform_data->tclk)) {
+		snd_printk("Marvell ALSA driver ERR. SPDIF clock set failed\n");
+		return 1;
+	}
+
+	return 0;
+}
+
+int mv88fx_snd_hw_playback_set(struct mv88fx_snd_chip *chip)
+{
+	struct mv88fx_snd_stream *audio_stream = chip->stream[PLAYBACK];
+	struct snd_pcm_substream *substream = audio_stream->substream;
+	struct snd_pcm_runtime *runtime = substream->runtime;
+
+	struct mv_audio_playback_ctrl	pcm_play_ctrl;
+	struct mv_i2s_playback_ctrl    i2s_play_ctrl;
+	struct mv_spdif_playback_ctrl  spdif_play_ctrl;
+	struct mv_audio_freq_data      dco_ctrl;
+
+	dco_ctrl.offset = chip->dco_ctrl_offst;
+
+	switch (audio_stream->rate) {
+	case 44100:
+		dco_ctrl.baseFreq = AUDIO_FREQ_44_1KH;
+		break;
+	case 48000:
+		dco_ctrl.baseFreq = AUDIO_FREQ_48KH;
+		break;
+	case 96000:
+		dco_ctrl.baseFreq = AUDIO_FREQ_96KH;
+		break;
+	default:
+		snd_printk("Requested rate %d is not supported\n",
+			   runtime->rate); return -1;
+	}
+
+	pcm_play_ctrl.burst = (chip->burst == 128) ? AUDIO_128BYTE_BURST :
+						     AUDIO_32BYTE_BURST;
+
+	pcm_play_ctrl.loopBack = chip->loopback;
+
+	if (audio_stream->stereo) {
+		pcm_play_ctrl.monoMode = AUDIO_PLAY_MONO_OFF;
+	} else {
+		switch (audio_stream->mono_mode) {
+		case MONO_LEFT:
+			pcm_play_ctrl.monoMode = AUDIO_PLAY_LEFT_MONO;
+			break;
+		case MONO_RIGHT:
+			pcm_play_ctrl.monoMode = AUDIO_PLAY_RIGHT_MONO;
+			break;
+		case MONO_BOTH:
+		default:
+			pcm_play_ctrl.monoMode = AUDIO_PLAY_BOTH_MONO;
+			break;
+		}
+	}
+
+	if (audio_stream->format == SAMPLE_16IN16) {
+		pcm_play_ctrl.sampleSize = SAMPLE_16BIT;
+		i2s_play_ctrl.sampleSize = SAMPLE_16BIT;
+	} else if (audio_stream->format == SAMPLE_24IN32) {
+		pcm_play_ctrl.sampleSize = SAMPLE_24BIT;
+		i2s_play_ctrl.sampleSize = SAMPLE_24BIT;
+	} else if (audio_stream->format == SAMPLE_32IN32) {
+		pcm_play_ctrl.sampleSize = SAMPLE_32BIT;
+		i2s_play_ctrl.sampleSize = SAMPLE_32BIT;
+	} else {
+		snd_printk("Requested format %d is not supported\n",
+			   runtime->format);
+		return -1;
+	}
+
+	/* buffer and period sizes in frame */
+	pcm_play_ctrl.bufferPhyBase = audio_stream->dma_addr;
+	pcm_play_ctrl.bufferSize = audio_stream->dma_size;
+	pcm_play_ctrl.intByteCount = audio_stream->period_size;
+
+	/* I2S playback streem stuff */
+	/*i2s_play_ctrl.sampleSize = pcm_play_ctrl.sampleSize;*/
+	i2s_play_ctrl.justification = I2S_JUSTIFIED;
+	i2s_play_ctrl.sendLastFrame = 0;
+
+	spdif_play_ctrl.nonPcm = FALSE;
+
+	spdif_play_ctrl.validity = chip->ch_stat_valid;
+
+	if (audio_stream->stat_mem) {
+		spdif_play_ctrl.userBitsFromMemory = TRUE;
+		spdif_play_ctrl.validityFromMemory = TRUE;
+		spdif_play_ctrl.blockStartInternally = FALSE;
+	} else {
+		spdif_play_ctrl.userBitsFromMemory = FALSE;
+		spdif_play_ctrl.validityFromMemory = FALSE;
+		spdif_play_ctrl.blockStartInternally = TRUE;
+	}
+
+	/* If this is non-PCM sound, mute I2S channel */
+	spin_lock_irq(&chip->reg_lock);
+
+	if (!(readl(chip->base + MV_AUDIO_PLAYBACK_CTRL_REG) &
+	      (APCR_PLAY_I2S_ENABLE_MASK | APCR_PLAY_SPDIF_ENABLE_MASK))) {
+
+		if (mv_audio_dco_ctrl_set(&dco_ctrl, chip->base)) {
+			snd_printk("Failed to initialize DCO clock control.\n");
+			goto error;
+		}
+	}
+
+	if (audio_stream->clock_src == DCO_CLOCK)
+		while ((readl(chip->base + MV_AUDIO_SPCR_DCO_STATUS_REG) &
+		ASDSR_DCO_LOCK_MASK) == 0)
+			cpu_relax();
+	else if (audio_stream->clock_src == SPCR_CLOCK)
+		while ((readl(chip->base + MV_AUDIO_SPCR_DCO_STATUS_REG) &
+		ASDSR_SPCR_LOCK_MASK) == 0)
+			cpu_relax();
+
+	if (mv_audio_playback_control_set(chip->base, chip->audio_offset,
+					&pcm_play_ctrl)) {
+		snd_printk("Failed to initialize PCM playback control.\n");
+		goto error;
+	}
+
+	if (mv_i2s_playback_ctrl_set(chip->base, &i2s_play_ctrl)) {
+		snd_printk("Failed to initialize I2S playback control.\n");
+		goto error;
+	}
+
+	mv_spdif_playback_ctrl_set(chip->base, &spdif_play_ctrl);
+
+	spin_unlock_irq(&chip->reg_lock);
+
+	return 0;
+error:
+	spin_unlock_irq(&chip->reg_lock);
+	return -1;
+}
+
+int mv88fx_snd_hw_capture_set(struct mv88fx_snd_chip *chip)
+{
+	struct mv88fx_snd_stream *audio_stream = chip->stream[CAPTURE];
+	struct snd_pcm_substream *substream = audio_stream->substream;
+	struct snd_pcm_runtime *runtime = substream->runtime;
+
+	struct mv_audio_record_ctrl pcm_rec_ctrl;
+	struct mv_i2s_record_ctrl   i2s_rec_ctrl;
+	struct mv_audio_freq_data   dco_ctrl;
+
+	dco_ctrl.offset = chip->dco_ctrl_offst;
+
+	switch (audio_stream->rate) {
+	case 44100:
+		dco_ctrl.baseFreq = AUDIO_FREQ_44_1KH;
+		break;
+	case 48000:
+		dco_ctrl.baseFreq = AUDIO_FREQ_48KH;
+		break;
+	case 96000:
+		dco_ctrl.baseFreq = AUDIO_FREQ_96KH;
+		break;
+	default:
+		snd_printk("Requested rate %d is not supported\n",
+			   runtime->rate); return -1;
+	}
+
+	pcm_rec_ctrl.burst = (chip->burst == 128) ? AUDIO_128BYTE_BURST :
+						    AUDIO_32BYTE_BURST;
+
+	if (audio_stream->format == SAMPLE_16IN16) {
+		pcm_rec_ctrl.sampleSize = SAMPLE_16BIT;
+	} else if (audio_stream->format == SAMPLE_24IN32) {
+		pcm_rec_ctrl.sampleSize = SAMPLE_24BIT;
+	} else if (audio_stream->format == SAMPLE_32IN32) {
+		pcm_rec_ctrl.sampleSize = SAMPLE_32BIT;
+	} else {
+		snd_printk("Requested format %d is not supported\n",
+			   runtime->format);
+		return -1;
+	}
+
+	/* If request for tereo record comes on the boards that doesn't
+	 * support stereo recording */
+	if ((!chip->stereo) && audio_stream->stereo) {
+		snd_printk("Stereo recording is not supported\n");
+		return -1;
+	}
+
+	pcm_rec_ctrl.mono = (audio_stream->stereo) ? FALSE : TRUE;
+
+	if (pcm_rec_ctrl.mono) {
+		switch (audio_stream->mono_mode) {
+		case MONO_LEFT:
+			pcm_rec_ctrl.monoChannel = AUDIO_REC_LEFT_MONO;
+			break;
+		default:
+		case MONO_RIGHT:
+			pcm_rec_ctrl.monoChannel = AUDIO_REC_RIGHT_MONO;
+			break;
+		}
+
+	} else {
+		pcm_rec_ctrl.monoChannel = AUDIO_REC_LEFT_MONO;
+	}
+
+
+	pcm_rec_ctrl.bufferPhyBase = audio_stream->dma_addr;
+	pcm_rec_ctrl.bufferSize = audio_stream->dma_size;
+
+	pcm_rec_ctrl.intByteCount = audio_stream->period_size;
+
+	/* I2S record streem stuff */
+	i2s_rec_ctrl.sample = pcm_rec_ctrl.sampleSize;
+	i2s_rec_ctrl.justf = I2S_JUSTIFIED;
+
+	spin_lock_irq(&chip->reg_lock);
+
+	/* set clock only if record is not enabled*/
+	if (!(readl(chip->base + MV_AUDIO_RECORD_CTRL_REG) &
+	     (ARCR_RECORD_SPDIF_EN_MASK | ARCR_RECORD_I2S_EN_MASK))) {
+
+		if (mv_audio_dco_ctrl_set(&dco_ctrl, chip->base)) {
+			snd_printk("Failed to initialize DCO clock control.\n");
+			return -1;
+		}
+	}
+
+	if (mv_audio_record_control_set(&pcm_rec_ctrl, chip->audio_offset,
+					chip->base)) {
+		snd_printk("Failed to initialize PCM record control.\n");
+		return -1;
+	}
+
+	if (mv_i2s_record_cntrl_set(&i2s_rec_ctrl, chip->base)) {
+		snd_printk("Failed to initialize I2S record control.\n");
+		return -1;
+	}
+	spin_unlock_irq(&chip->reg_lock);
+
+	return 0;
+}
+
+static void mv_audio_init(void __iomem *base)
+{
+	int timeout = 10000000;
+	unsigned int reg_data;
+
+	reg_data = readl(base + 0x1200);
+	reg_data &= (~(0x333FF8));
+	reg_data |= 0x111D18;
+
+	writel(reg_data, base + 0x1200);
+
+	do {
+		timeout--;
+	} while (timeout);
+
+	reg_data = readl(base + 0x1200);
+	reg_data &= (~(0x333FF8));
+	reg_data |= 0x111D18;
+
+	writel(reg_data, base + 0x1200);
+}
+
+static void audio_setup_wins(void __iomem *base,
+			     struct mbus_dram_target_info *dram)
+{
+	int win_num;
+
+	/* First disable and clear windows */
+	for (win_num = 0; win_num < MV_AUDIO_MAX_ADDR_DECODE_WIN; win_num++) {
+		writel(0, base + MV_AUDIO_WIN_CTRL_REG(win_num));
+		writel(0, base + MV_AUDIO_WIN_BASE_REG(win_num));
+	}
+
+	/* Setup windows for DDR */
+	for (win_num = 0; win_num < MV_AUDIO_MAX_ADDR_DECODE_WIN; win_num++) {
+		/* We will set the Window to DRAM_CS1 in default */
+		struct mbus_dram_window *cs = &dram->cs[1];
+
+		writel(cs->base & 0xffff0000,
+		       base + MV_AUDIO_WIN_BASE_REG(win_num));
+		writel(((cs->size - 1) & 0xffff0000) |
+		       (cs->mbus_attr << 8) |
+		       (dram->mbus_dram_target_id << 4) | 1,
+			base + MV_AUDIO_WIN_CTRL_REG(win_num));
+	}
+}
+
+#define MV_BOARD_TCLK_133MHZ    133333333
+#define MV_BOARD_TCLK_150MHZ    150000000
+#define MV_BOARD_TCLK_166MHZ    166666667
+#define MV_BOARD_TCLK_200MHZ    200000000
+
+static int spdif_record_tclock_set(void __iomem *base, unsigned int tclk)
+{
+	unsigned int reg_data;
+
+	reg_data = readl(base + MV_AUDIO_SPDIF_REC_GEN_REG);
+
+	switch (tclk) {
+	case MV_BOARD_TCLK_133MHZ:
+		reg_data |= ASRGR_CORE_CLK_FREQ_133MHZ;
+		break;
+	case MV_BOARD_TCLK_150MHZ:
+		reg_data |= ASRGR_CORE_CLK_FREQ_150MHZ;
+		break;
+	case MV_BOARD_TCLK_166MHZ:
+		reg_data |= ASRGR_CORE_CLK_FREQ_166MHZ;
+		break;
+	case MV_BOARD_TCLK_200MHZ:
+		reg_data |= ASRGR_CORE_CLK_FREQ_200MHZ;
+		break;
+	default:
+		snd_printk("Not supported core clock %d\n", tclk);
+		return 1;
+	}
+
+	writel(reg_data, base + MV_AUDIO_SPDIF_REC_GEN_REG);
+
+	return 0;
+}
+
+static int  mv_audio_record_control_set(struct mv_audio_record_ctrl *ctrl,
+				unsigned int audio_offset, void __iomem *base)
+{
+	unsigned int reg, buff_start, buff_end;
+	unsigned int win_base, win_size;
+
+	if (ctrl->monoChannel > AUDIO_REC_RIGHT_MONO) {
+		snd_printk("Error: Illegal monoChannel %x\n",
+			   ctrl->monoChannel);
+
+		return 1;
+	}
+
+	if ((ctrl->burst != AUDIO_32BYTE_BURST) &&
+	    (ctrl->burst != AUDIO_128BYTE_BURST)) {
+		snd_printk("Error: Illegal burst %x\n",
+			   ctrl->burst);
+
+		return 1;
+	}
+
+	if (ctrl->bufferPhyBase & (MV_AUDIO_BUFFER_MIN_ALIGN - 1)) {
+		snd_printk("Error bufferPhyBase is not aligned to 0x%x"\
+			  " bytes\n", MV_AUDIO_BUFFER_MIN_ALIGN);
+
+		return 1;
+	}
+
+	if ((ctrl->bufferSize <= audio_burst_bytes_num_get(ctrl->burst)) |
+	    (ctrl->bufferSize & (audio_burst_bytes_num_get(ctrl->burst) - 1)) ||
+	    (ctrl->bufferSize > AUDIO_REG_TO_SIZE(APBBCR_SIZE_MAX))) {
+		snd_printk("Error bufferSize smaller than or not multiple "\
+			  "of 0x%x bytes or larger than 0x%x\n",
+			  audio_burst_bytes_num_get(ctrl->burst),
+			  AUDIO_REG_TO_SIZE(APBBCR_SIZE_MAX));
+
+		return 1;
+	}
+
+	reg = readl(base + MV_AUDIO_RECORD_CTRL_REG);
+	reg &= ~(ARCR_RECORD_BURST_SIZE_MASK | ARCR_RECORDED_MONO_CHNL_MASK |
+		 ARCR_RECORD_SAMPLE_SIZE_MASK);
+
+	switch (ctrl->sampleSize) {
+	case SAMPLE_16BIT:
+	case SAMPLE_16BIT_NON_COMPACT:
+	case SAMPLE_20BIT:
+	case SAMPLE_24BIT:
+	case SAMPLE_32BIT:
+		reg |= ctrl->sampleSize << ARCR_RECORD_SAMPLE_SIZE_OFFS;
+		break;
+	default:
+		snd_printk("Error: Illegal sampleSize %x\n",
+			   ctrl->sampleSize);
+
+		return 1;
+	}
+
+	reg |= ctrl->burst << ARCR_RECORD_BURST_SIZE_OFFS;
+	reg |= ctrl->monoChannel << ARCR_RECORDED_MONO_CHNL_OFFS;
+
+	if (ctrl->mono)
+		reg |= ARCR_RECORD_MONO_MASK;
+	else
+		reg &= (~ARCR_RECORD_MONO_MASK);
+
+	writel(reg, base + MV_AUDIO_RECORD_CTRL_REG);
+
+	/* Get the details of the Record address window*/
+	win_base = readl(base + MV_AUDIO_WIN_BASE_REG(MV_AUDIO_RECORD_WIN_NUM));
+	win_size = readl(base + MV_AUDIO_WIN_CTRL_REG(MV_AUDIO_RECORD_WIN_NUM));
+
+	/* Window size bits are 31:16. Where size =
+	 * (2 ^ no of ones) * 64 KB. e.g. 0x0FF says 16MB */
+	win_size = ((win_size >> 16) + 1) << 16;
+
+	buff_start = ctrl->bufferPhyBase;
+	buff_end   = buff_start + ctrl->bufferSize - 1;
+
+	/* If buffer address is not within window boundries then try to set a
+	 * new value to the Record window by geting the target of where the
+	 * buffer exist, if the buffer is within the window of the new target
+	 * then set the Record window to that target else return Fail
+	 */
+
+	if (!(((buff_start >= win_base) &&
+	     (buff_start <= (win_base + win_size - 1))) ||
+	     ((buff_end >= win_base) &&
+	     (buff_end <= (win_base + win_size - 1))))) {
+		snd_printd("Audio record buffer is not within window");
+
+		/* Set the window for the buffer that user require
+		   for the palyback\recording window to the target window */
+		if (set_window_as_per_baseadd(base, ctrl->bufferPhyBase,
+				audio_offset, MV_AUDIO_RECORD_WIN_NUM)) {
+			snd_printk("Playback buffer (%#x) is not "
+				  "within a valid target\n",
+				  ctrl->bufferPhyBase);
+			return 1;
+		}
+	}
+
+	/* Set the interrupt byte count */
+	reg = ctrl->intByteCount & ARBCI_BYTE_COUNT_MASK;
+	writel(reg, base + MV_AUDIO_RECORD_BYTE_CNTR_INT_REG);
+
+	writel(ctrl->bufferPhyBase, base + MV_AUDIO_RECORD_START_ADDR_REG);
+	writel(AUDIO_SIZE_TO_REG(ctrl->bufferSize),
+	       base + MV_AUDIO_RECORD_BUFF_SIZE_REG);
+
+
+	return 0;
+}
+
+static int mv_i2s_record_cntrl_set(struct mv_i2s_record_ctrl *ctrl,
+				   void __iomem *base)
+{
+	unsigned int reg;
+
+	reg = readl(base + MV_AUDIO_I2S_REC_CTRL_REG);
+	reg &= ~(AIRCR_I2S_RECORD_JUSTF_MASK|AIRCR_I2S_SAMPLE_SIZE_MASK);
+
+	switch (ctrl->justf) {
+	case I2S_JUSTIFIED:
+	case LEFT_JUSTIFIED:
+	case RIGHT_JUSTIFIED:
+	case RISE_BIT_CLCK_JUSTIFIED:
+		reg |= ctrl->justf << AIRCR_I2S_RECORD_JUSTF_OFFS;
+		break;
+	default:
+		return 1;
+	}
+
+	reg |= ctrl->sample << AIRCR_I2S_SAMPLE_SIZE_OFFS;
+
+	writel(reg, base + MV_AUDIO_I2S_REC_CTRL_REG);
+	return 0;
+}
+
+/* We trust the value set in the window registers and don't check them.
+ * As there is some value already present in the register, we assume
+ * base and size are aligned */
+
+static int set_window_as_per_baseadd(void __iomem *base, unsigned int baseadd,
+				     unsigned int audio_offset, int win_num)
+{
+	int dram_cs, win;
+	unsigned int win_base, win_size, size;
+	unsigned char dram_attr[4] = {0x0E, 0x0D, 0x0B, 0x07};
+
+	/* Base passed is Audio base address. Audio base address is
+	 * Internal register base address + audio_offset */
+	void __iomem *internal_reg_base = base - audio_offset;
+
+	for (dram_cs = 0; dram_cs < 4; dram_cs++) {
+		win_base = readl(internal_reg_base + 0x1500 + (8 * dram_cs));
+		win_size = readl(internal_reg_base + 0x1504 + (8 * dram_cs));
+
+		/* skip if window is disabled */
+		if (!(win_size & 1))
+			continue;
+
+		/* Window size bits are 31:24. Where size =
+		 * (2 ^ no of ones) * 16 MB. e.g. 0x0F says 256MB */
+		size = ((win_size >> 24) + 1) << 24;
+
+		if ((baseadd >= win_base) && (baseadd < (win_base + size))) {
+			snd_printd("DRAM window %d set for %s window",
+				  dram_cs, win_num ? "plaback" : "record");
+			writel(win_base,
+			base + MV_AUDIO_WIN_BASE_REG(win_num));
+
+			/* DRAM window ctrl regs are bit different than Audio
+			 * Set size, attribute and target ID */
+			win_size = ((size - 1) & 0xffff0000) | 1;
+			win_size |= (dram_attr[dram_cs] << 8); /* Atribute */
+			win_size &= (~(0xF << 4));             /* Target ID */
+
+			writel(win_size,
+			base + MV_AUDIO_WIN_CTRL_REG(win_num));
+			snd_printd("win_base 0x%08x\twin_size 0x%08x",
+				  win_base, win_size);
+			return 0;
+		}
+	}
+
+	for (win = 0; win < 8; win++) {
+		win_base = readl(internal_reg_base + 0x2004 + (0x10 * win));
+		win_size = readl(internal_reg_base + 0x2008 + (0x10 * win));
+
+		/* skip if window is disabled */
+		if (!(win_size & 1))
+			continue;
+
+		/* Window size bits are 31:16. Where size =
+		 * (2 ^ no of ones) * 64 KB. e.g. 0x0FF says 16MB */
+		size = ((win_size >> 16) + 1) << 16;
+		if ((baseadd >= win_base) && (baseadd < (win_base + size))) {
+			snd_printd("CPU window %d set for %s window",
+				  win_base, win_num ? "plaback" : "record");
+			writel(win_base,
+			base + MV_AUDIO_WIN_BASE_REG(win_num));
+			writel(win_size,
+			base + MV_AUDIO_WIN_CTRL_REG(win_num));
+			return 0;
+		}
+	}
+
+	return 1;
+}
+
+static int mv_audio_playback_control_set(void __iomem *base, unsigned int
+			 audio_offset, struct mv_audio_playback_ctrl *ctrl)
+{
+	unsigned int reg, buff_start, buff_end;
+	unsigned int win_base, win_size;
+
+	if (ctrl->monoMode >= AUDIO_PLAY_OTHER_MONO) {
+		snd_printk("Error: Illegal monoMode %x\n", ctrl->monoMode);
+		return 1;
+	}
+
+	if ((ctrl->burst != AUDIO_32BYTE_BURST) &&
+	    (ctrl->burst != AUDIO_128BYTE_BURST)) {
+		snd_printk("Error: Illegal burst %x\n", ctrl->burst);
+		return 1;
+	}
+
+	if (ctrl->bufferPhyBase & (MV_AUDIO_BUFFER_MIN_ALIGN - 1)) {
+		snd_printk("Error, bufferPhyBase is not aligned to 0x%x "\
+			  "bytes\n", MV_AUDIO_BUFFER_MIN_ALIGN);
+		return 1;
+	}
+
+	if ((ctrl->bufferSize <= audio_burst_bytes_num_get(ctrl->burst)) ||
+	    (ctrl->bufferSize & (audio_burst_bytes_num_get(ctrl->burst) - 1)) ||
+	    (ctrl->bufferSize > AUDIO_REG_TO_SIZE(APBBCR_SIZE_MAX))) {
+		snd_printk("Error, bufferSize smaller than or not multiple "\
+			  "of 0x%x bytes or larger than 0x%x",
+			  audio_burst_bytes_num_get(ctrl->burst),
+			  AUDIO_REG_TO_SIZE(APBBCR_SIZE_MAX));
+		return 1;
+	}
+
+	reg = readl(base + MV_AUDIO_PLAYBACK_CTRL_REG);
+	reg &= ~(APCR_PLAY_BURST_SIZE_MASK | APCR_LOOPBACK_MASK |
+		 APCR_PLAY_MONO_MASK | APCR_PLAY_SAMPLE_SIZE_MASK);
+	reg |= ctrl->burst << APCR_PLAY_BURST_SIZE_OFFS;
+	reg |= ctrl->loopBack << APCR_LOOPBACK_OFFS;
+	reg |= ctrl->monoMode << APCR_PLAY_MONO_OFFS;
+	reg |= ctrl->sampleSize << APCR_PLAY_SAMPLE_SIZE_OFFS;
+	writel(reg, base + MV_AUDIO_PLAYBACK_CTRL_REG);
+
+	/* Get the details of the Playback address window*/
+	win_base = readl(base +
+			 MV_AUDIO_WIN_BASE_REG(MV_AUDIO_PLAYBACK_WIN_NUM));
+	win_size = readl(base +
+			 MV_AUDIO_WIN_CTRL_REG(MV_AUDIO_PLAYBACK_WIN_NUM));
+
+	/* Window size bits are 31:16. Where size =
+	 * (2 ^ no of ones) * 64 KB. e.g. 0x0FF says 16MB */
+	win_size = ((win_size >> 16) + 1) << 16;
+
+	buff_start = ctrl->bufferPhyBase;
+	buff_end   = buff_start + ctrl->bufferSize - 1;
+
+	/* If Playback window is not enabled or buffer address is not within
+	 * window boundries then try to set a new value to the Playback window*/
+
+	if (!(((buff_start >= win_base) &&
+	     (buff_start <= (win_base + win_size - 1))) ||
+	     ((buff_end >= win_base) &&
+	     (buff_end <= (win_base + win_size - 1))))) {
+		snd_printd("Audio playback buffer is not within window\n");
+
+		/* Set the window for the buffer that user require
+		   for the palyback\recording window to the target window */
+		if (set_window_as_per_baseadd(base, ctrl->bufferPhyBase,
+				audio_offset, MV_AUDIO_PLAYBACK_WIN_NUM)) {
+			snd_printk("Record buffer (%#x) is not "
+				  "within a valid target\n",
+				  ctrl->bufferPhyBase);
+			return 1;
+		}
+	}
+
+	/* Set the interrupt byte count */
+	reg = ctrl->intByteCount & APBCI_BYTE_COUNT_MASK;
+	writel(reg, base + MV_AUDIO_PLAYBACK_BYTE_CNTR_INT_REG);
+
+	writel(ctrl->bufferPhyBase,
+	       base + MV_AUDIO_PLAYBACK_BUFF_START_REG);
+	writel(AUDIO_SIZE_TO_REG(ctrl->bufferSize),
+	       base + MV_AUDIO_PLAYBACK_BUFF_SIZE_REG);
+
+	return 0;
+}
+
+static int mv_i2s_playback_ctrl_set(void __iomem *base,
+				    struct mv_i2s_playback_ctrl *ctrl)
+{
+	unsigned int reg_data;
+
+	reg_data = readl(base + MV_AUDIO_I2S_PLAY_CTRL_REG);
+	reg_data &= ~(AIPCR_I2S_PB_JUSTF_MASK | AIPCR_I2S_PB_SAMPLE_SIZE_MASK);
+
+	if (ctrl->sampleSize > SAMPLE_16BIT) {
+		snd_printk("Illigal sample size\n");
+		return 1;
+	}
+
+	reg_data |= ctrl->sampleSize << AIPCR_I2S_PB_SAMPLE_SIZE_OFFS;
+
+	if (ctrl->sendLastFrame)
+		reg_data |= AIPCR_I2S_SEND_LAST_FRM_MASK;
+	else
+		reg_data &= ~AIPCR_I2S_SEND_LAST_FRM_MASK;
+
+	switch (ctrl->justification) {
+	case I2S_JUSTIFIED:
+	case LEFT_JUSTIFIED:
+	case RIGHT_JUSTIFIED:
+		reg_data |= ctrl->justification << AIPCR_I2S_PB_JUSTF_OFFS;
+		break;
+	default:
+		snd_printk("Illigal justification value\n");
+		return 1;
+	}
+
+	writel(reg_data, base + MV_AUDIO_I2S_PLAY_CTRL_REG);
+
+	return 0;
+}
+
+static void mv_spdif_playback_ctrl_set(void __iomem *base,
+					struct mv_spdif_playback_ctrl *ctrl)
+{
+	unsigned int reg_data;
+
+	reg_data = readl(base + MV_AUDIO_SPDIF_PLAY_CTRL_REG);
+
+	if (ctrl->blockStartInternally)
+		reg_data |= ASPCR_SPDIF_BLOCK_START_MASK;
+	else
+		reg_data &= ~ASPCR_SPDIF_BLOCK_START_MASK;
+
+	if (ctrl->validityFromMemory)
+		reg_data |= ASPCR_SPDIF_PB_EN_MEM_VALIDITY_MASK;
+	else
+		reg_data &= ~ASPCR_SPDIF_PB_EN_MEM_VALIDITY_MASK;
+
+	if (ctrl->userBitsFromMemory)
+		reg_data |= ASPCR_SPDIF_PB_MEM_USR_EN_MASK;
+	else
+		reg_data &= ~ASPCR_SPDIF_PB_MEM_USR_EN_MASK;
+
+	if (ctrl->validity)
+		reg_data |= ASPCR_SPDIF_PB_REG_VALIDITY_MASK;
+	else
+		reg_data &= ~ASPCR_SPDIF_PB_REG_VALIDITY_MASK;
+
+	if (ctrl->nonPcm)
+		reg_data |= ASPCR_SPDIF_PB_NONPCM_MASK;
+	else
+		reg_data &= ~ASPCR_SPDIF_PB_NONPCM_MASK;
+
+	writel(reg_data, base + MV_AUDIO_SPDIF_PLAY_CTRL_REG);
+}
+
+static int mv_audio_dco_ctrl_set(struct mv_audio_freq_data *dcoCtrl,
+				 void __iomem *base)
+{
+	unsigned int reg;
+
+	/* Check parameters*/
+	if (dcoCtrl->baseFreq > AUDIO_FREQ_96KH) {
+		snd_printk("dcoCtrl->baseFreq value (0x%x) invalid\n",
+			   dcoCtrl->baseFreq);
+		return 1;
+	}
+
+	if ((dcoCtrl->offset > 0xFD0) || (dcoCtrl->offset < 0x20)) {
+		snd_printk("dcoCtrl->offset value (0x%x) invalid\n",
+			   dcoCtrl->baseFreq);
+		return 1;
+	}
+
+	reg = readl(base + MV_AUDIO_DCO_CTRL_REG);
+
+	reg &= ~(ADCR_DCO_CTRL_FS_MASK | ADCR_DCO_CTRL_OFFSET_MASK);
+	reg |= ((dcoCtrl->baseFreq << ADCR_DCO_CTRL_FS_OFFS)  |
+		(dcoCtrl->offset << ADCR_DCO_CTRL_OFFSET_OFFS));
+
+	writel(reg, base + MV_AUDIO_DCO_CTRL_REG);
+
+	return 0;
+}
diff --git a/sound/soc/kirkwood/kirkwood_audio_hal.h b/sound/soc/kirkwood/kirkwood_audio_hal.h
new file mode 100644
index 0000000..ce08102
--- /dev/null
+++ b/sound/soc/kirkwood/kirkwood_audio_hal.h
@@ -0,0 +1,109 @@
+/*
+ * Sound driver data definition file for Marvell Kirkwood family SOCs
+ */
+
+#ifndef __AUDIO_HAL_H
+#define __AUDIO_HAL_H
+
+#include "kirkwood_audio_regs.h"
+
+#ifdef CONFIG_SND_SOC_CS42L51
+#include "cs42l51.h"
+
+#define codec_init           cs42l51_init
+#define codec_vol_get        cs42l51_vol_get
+#define codec_vol_set        cs42l51_vol_set
+#define codec_del_i2c_device cs42l51_del_i2c_device
+#endif
+
+#define CODEC_I2C_BUS_NO 0
+#define CODEC_I2C_ADD    0x4A
+
+/*********************************/
+/* General enums and structures */
+/*******************************/
+/* Type of Audio operations*/
+enum mv_audio_operation {
+	AUDIO_PLAYBACK = 0,
+	AUDIO_RECORD = 1
+};
+
+struct mv_audio_freq_data{
+	int baseFreq; /* Control FS, selects the base frequency
+		       * of the DCO */
+	u32 offset;   /* Offset control in which each step equals to
+		       * 0.9536 ppm */
+};
+
+
+/***********************************/
+/* Play Back related structures   */
+/*********************************/
+
+struct mv_audio_playback_ctrl {
+	int          burst;         /* Specifies the Burst Size of the DMA */
+	bool         loopBack;      /* When Loopback is enabled, playback data
+				     * is looped back to be recorded */
+	int          monoMode;      /* Mono Mode is used */
+	unsigned int bufferPhyBase; /* Physical Address of DMA buffer */
+	unsigned int bufferSize;    /* Size of DMA buffer */
+	unsigned int intByteCount;  /* Number of bytes after which an
+				     * interrupt will be issued.*/
+	int    sampleSize;          /* Playback Sample Size*/
+};
+
+struct mv_spdif_playback_ctrl {
+	bool nonPcm;                /* PCM or non-PCM mode*/
+	bool validity;              /* Validity bit value when using
+				     * registers (userBitsFromMemory=0) */
+	bool underrunData;          /* If true send last frame on mute/pause/
+				     * underrun otherwise send 24 binary */
+	bool userBitsFromMemory;    /* otherwise from intenal registers */
+	bool validityFromMemory;    /* otherwise from internal registers */
+	bool blockStartInternally;  /* When user and valid bits are form
+				     * registers then this bit should be zero */
+};
+
+struct mv_i2s_playback_ctrl {
+	int  sampleSize;
+	int  justification;
+	bool sendLastFrame; /* If true send last frame on
+			     * mute/pause/underrun
+			     * otherwise send 64 binary*/
+};
+
+
+/*********************************/
+/* Recording  related structures */
+/*********************************/
+
+struct mv_audio_record_ctrl {
+	int  burst;          /* Recording DMA Burst Size */
+	int  sampleSize;     /*Recording Sample Size */
+	bool mono;           /* If true then recording mono else
+			      * recording stereo */
+	int  monoChannel;    /* Left or right moono */
+	u32  bufferPhyBase;  /* Physical Address of DMA buffer */
+	u32  bufferSize;     /* Size of DMA buffer */
+
+	u32  intByteCount;   /* Number of bytes after which an
+			      * interrupt will be issued.*/
+
+};
+
+struct mv_i2s_record_ctrl {
+	int  sample; /* I2S Recording Sample Size*/
+	int  justf;
+};
+
+/******************/
+/* Functions API */
+/****************/
+
+extern struct mv88fx_snd_chip *chip;
+
+int mv88fx_snd_hw_init(struct snd_card *card);
+int mv88fx_snd_hw_capture_set(struct mv88fx_snd_chip *chip);
+int mv88fx_snd_hw_playback_set(struct mv88fx_snd_chip *chip);
+
+#endif
diff --git a/sound/soc/kirkwood/kirkwood_audio_regs.h b/sound/soc/kirkwood/kirkwood_audio_regs.h
new file mode 100644
index 0000000..1d3df15
--- /dev/null
+++ b/sound/soc/kirkwood/kirkwood_audio_regs.h
@@ -0,0 +1,310 @@
+/*
+ * Audio registers for Marvell Kirkwood family SOCs
+ */
+
+#ifndef __KW_AUDIO_REGS_H
+#define __KW_AUDIO_REGS_H
+
+enum mv_audio_freq {
+	AUDIO_FREQ_44_1KH = 0,        /* 11.2896Mhz */
+	AUDIO_FREQ_48KH = 1,          /* 12.288Mhz */
+	AUDIO_FREQ_96KH = 2,          /* 24.576Mhz */
+	AUDIO_FREQ_LOWER_44_1KH = 3 , /* Lower than 11.2896MHz */
+	AUDIO_FREQ_HIGHER_96KH = 4,   /* Higher than 24.576MHz */
+	AUDIO_FREQ_OTHER = 7,         /* Other frequency */
+};
+
+enum mv_audio_burst_size {
+	AUDIO_32BYTE_BURST = 1,
+	AUDIO_128BYTE_BURST = 2,
+};
+
+enum mv_audio_playback_mono {
+	AUDIO_PLAY_MONO_OFF = 0,
+	AUDIO_PLAY_LEFT_MONO = 1,
+	AUDIO_PLAY_RIGHT_MONO = 2,
+	AUDIO_PLAY_BOTH_MONO = 3,
+	AUDIO_PLAY_OTHER_MONO = 4
+};
+
+enum mv_audio_record_mono {
+	AUDIO_REC_LEFT_MONO = 0,
+	AUDIO_REC_RIGHT_MONO = 1,
+};
+
+enum mv_audio_sample_size {
+	SAMPLE_32BIT = 0,
+	SAMPLE_24BIT = 1,
+	SAMPLE_20BIT = 2,
+	SAMPLE_16BIT = 3,
+	SAMPLE_16BIT_NON_COMPACT = 7
+};
+
+enum mv_audio_i2s_justification {
+	LEFT_JUSTIFIED = 0,
+	I2S_JUSTIFIED = 5,
+	RISE_BIT_CLCK_JUSTIFIED = 7,
+	RIGHT_JUSTIFIED = 8,
+};
+
+#define APBBCR_SIZE_MAX                    0x3FFFFF
+#define APBBCR_SIZE_SHIFT                  0x2
+
+#define AUDIO_REG_TO_SIZE(reg)             (((reg) + 1) << APBBCR_SIZE_SHIFT)
+#define AUDIO_SIZE_TO_REG(size)            (((size) >> APBBCR_SIZE_SHIFT) - 1)
+
+#define MV_AUDIO_BUFFER_MIN_ALIGN          0x8
+
+/********************/
+/* Clocking Control*/
+/*******************/
+
+#define MV_AUDIO_DCO_CTRL_REG              0x1204
+#define MV_AUDIO_SPCR_DCO_STATUS_REG       0x120c
+#define MV_AUDIO_SAMPLE_CNTR_CTRL_REG      0x1220
+#define MV_AUDIO_PLAYBACK_SAMPLE_CNTR_REG  0x1224
+#define MV_AUDIO_RECORD_SAMPLE_CNTR_REG    0x1228
+#define MV_AUDIO_CLOCK_CTRL_REG            0x1230
+
+/* MV_AUDIO_DCO_CTRL_REG */
+#define ADCR_DCO_CTRL_FS_OFFS              0
+#define ADCR_DCO_CTRL_FS_MASK              (0x3 << ADCR_DCO_CTRL_FS_OFFS)
+#define ADCR_DCO_CTRL_FS_44_1KHZ           (0x0 << ADCR_DCO_CTRL_FS_OFFS)
+#define ADCR_DCO_CTRL_FS_48KHZ             (0x1 << ADCR_DCO_CTRL_FS_OFFS)
+#define ADCR_DCO_CTRL_FS_96KHZ             (0x2 << ADCR_DCO_CTRL_FS_OFFS)
+
+
+#define ADCR_DCO_CTRL_OFFSET_OFFS          2
+#define ADCR_DCO_CTRL_OFFSET_MASK          (0xfff << ADCR_DCO_CTRL_OFFSET_OFFS)
+
+/* MV_AUDIO_SPCR_DCO_STATUS_REG */
+#define ASDSR_SPCR_CTRLFS_OFFS             0
+#define ASDSR_SPCR_CTRLFS_MASK             (0x7 << ASDSR_SPCR_CTRLFS_OFFS)
+#define ASDSR_SPCR_CTRLFS_44_1KHZ          (0x0 << ASDSR_SPCR_CTRLFS_OFFS)
+#define ASDSR_SPCR_CTRLFS_48KHZ            (0x1 << ASDSR_SPCR_CTRLFS_OFFS)
+#define ASDSR_SPCR_CTRLFS_96KHZ            (0x2 << ASDSR_SPCR_CTRLFS_OFFS)
+#define ASDSR_SPCR_CTRLFS_44_1KHZ_LESS     (0x3 << ASDSR_SPCR_CTRLFS_OFFS)
+#define ASDSR_SPCR_CTRLFS_96KHZ_MORE       (0x4 << ASDSR_SPCR_CTRLFS_OFFS)
+#define ASDSR_SPCR_CTRLFS_OTHER            (0x7 << ASDSR_SPCR_CTRLFS_OFFS)
+
+
+#define ASDSR_SPCR_CTRLOFFSET_OFFS         3
+#define ASDSR_SPCR_CTRLOFFSET_MASK         (0xfff << ASDSR_SPCR_CTRLOFFSET_OFFS)
+
+#define ASDSR_SPCR_LOCK_OFFS               15
+#define ASDSR_SPCR_LOCK_MASK               (0x1 << ASDSR_SPCR_LOCK_OFFS)
+
+#define ASDSR_DCO_LOCK_OFFS                16
+#define ASDSR_DCO_LOCK_MASK                (0x1 << ASDSR_DCO_LOCK_OFFS)
+
+#define ASDSR_PLL_LOCK_OFFS                17
+#define ASDSR_PLL_LOCK_MASK                (0x1 << ASDSR_PLL_LOCK_OFFS)
+
+/*MV_AUDIO_SAMPLE_CNTR_CTRL_REG */
+
+#define ASCCR_CLR_PLAY_CNTR_OFFS           9
+#define ASCCR_CLR_PLAY_CNTR_MASK           (0x1 << ASCCR_CLR_PLAY_CNTR_OFFS)
+
+#define ASCCR_CLR_REC_CNTR_OFFS            8
+#define ASCCR_CLR_REC_CNTR_MASK            (0x1 << ASCCR_CLR_REC_CNTR_OFFS)
+
+#define ASCCR_ACTIVE_PLAY_CNTR_OFFS        1
+#define ASCCR_ACTIVE_PLAY_CNTR_MASK        (0x1 << ASCCR_ACTIVE_PLAY_CNTR_OFFS)
+
+#define ASCCR_ACTIVE_REC_CNTR_OFFS         0
+#define ASCCR_ACTIVE_REC_CNTR_MASK         (0x1 << ASCCR_ACTIVE_REC_CNTR_OFFS)
+
+/* MV_AUDIO_CLOCK_CTRL_REG */
+#define ACCR_MCLK_SOURCE_OFFS              0
+#define ACCR_MCLK_SOURCE_MASK              (0x3 << ACCR_MCLK_SOURCE_OFFS)
+#define ACCR_MCLK_SOURCE_DCO               (0x0 << ACCR_MCLK_SOURCE_OFFS)
+#define ACCR_MCLK_SOURCE_SPCR              (0x2 << ACCR_MCLK_SOURCE_OFFS)
+#define ACCR_MCLK_SOURCE_EXT               (0x3 << ACCR_MCLK_SOURCE_OFFS)
+
+
+/*********************/
+/* Interrupts       */
+/*******************/
+#define MV_AUDIO_ERROR_CAUSE_REG            0x1300
+#define MV_AUDIO_ERROR_MASK_REG             0x1304
+#define MV_AUDIO_INT_CAUSE_REG              0x1308
+#define MV_AUDIO_INT_MASK_REG               0x130C
+#define MV_AUDIO_RECORD_BYTE_CNTR_INT_REG   0x1310
+#define MV_AUDIO_PLAYBACK_BYTE_CNTR_INT_REG 0x1314
+
+/* MV_AUDIO_INT_CAUSE_REG*/
+#define AICR_RECORD_BYTES_INT               (0x1 << 13)
+#define AICR_PLAY_BYTES_INT                 (0x1 << 14)
+
+#define ARBCI_BYTE_COUNT_MASK               0xFFFFFF
+#define APBCI_BYTE_COUNT_MASK               0xFFFFFF
+
+/*********************/
+/* Audio Playback   */
+/*******************/
+/* General */
+#define MV_AUDIO_PLAYBACK_CTRL_REG           0x1100
+#define MV_AUDIO_PLAYBACK_BUFF_START_REG     0x1104
+#define MV_AUDIO_PLAYBACK_BUFF_SIZE_REG      0x1108
+#define MV_AUDIO_PLAYBACK_BUFF_BYTE_CNTR_REG 0x110c
+
+/* SPDIF */
+#define MV_AUDIO_SPDIF_PLAY_CTRL_REG         0x2204
+#define MV_AUDIO_SPDIF_PLAY_CH_STATUS_LEFT_REG(ind) \
+	(0x2280 + (ind << 2))
+#define MV_AUDIO_SPDIF_PLAY_CH_STATUS_RIGHT_REG(ind) \
+	(0x22a0 + (ind << 2))
+#define MV_AUDIO_SPDIF_PLAY_USR_BITS_LEFT_REG(ind) \
+	(0x22c0 + (ind << 2))
+#define MV_AUDIO_SPDIF_PLAY_USR_BITS_RIGHT_REG(ind) \
+	(0x22e0 + (ind << 2))
+
+/* I2S */
+#define MV_AUDIO_I2S_PLAY_CTRL_REG           0x2508
+
+
+/* MV_AUDIO_PLAYBACK_CTRL_REG */
+#define APCR_PLAY_SAMPLE_SIZE_OFFS  0
+#define APCR_PLAY_SAMPLE_SIZE_MASK  (0x7 << APCR_PLAY_SAMPLE_SIZE_OFFS)
+
+#define APCR_PLAY_I2S_ENABLE_OFFS   3
+#define APCR_PLAY_I2S_ENABLE_MASK   (0x1 << APCR_PLAY_I2S_ENABLE_OFFS)
+
+#define APCR_PLAY_SPDIF_ENABLE_OFFS 4
+#define APCR_PLAY_SPDIF_ENABLE_MASK (0x1 << APCR_PLAY_SPDIF_ENABLE_OFFS)
+
+#define APCR_PLAY_MONO_OFFS         5
+#define APCR_PLAY_MONO_MASK         (0x3 << APCR_PLAY_MONO_OFFS)
+
+#define APCR_PLAY_I2S_MUTE_OFFS     7
+#define APCR_PLAY_I2S_MUTE_MASK     (0x1 << APCR_PLAY_I2S_MUTE_OFFS)
+
+#define APCR_PLAY_SPDIF_MUTE_OFFS   8
+#define APCR_PLAY_SPDIF_MUTE_MASK   (0x1 << APCR_PLAY_SPDIF_MUTE_OFFS)
+
+#define APCR_PLAY_PAUSE_OFFS        9
+#define APCR_PLAY_PAUSE_MASK        (0x1 << APCR_PLAY_PAUSE_OFFS)
+
+#define APCR_LOOPBACK_OFFS          10
+#define APCR_LOOPBACK_MASK          (0x1 << APCR_LOOPBACK_OFFS)
+
+#define APCR_PLAY_BURST_SIZE_OFFS   11
+#define APCR_PLAY_BURST_SIZE_MASK   (0x3 << APCR_PLAY_BURST_SIZE_OFFS)
+
+#define APCR_PLAY_BUSY_OFFS         16
+#define APCR_PLAY_BUSY_MASK         (0x1 << APCR_PLAY_BUSY_OFFS)
+
+/* MV_AUDIO_PLAYBACK_BUFF_BYTE_CNTR_REG */
+#define APBBCR_SIZE_MAX             0x3FFFFF
+#define APBBCR_SIZE_SHIFT           0x2
+
+
+/* MV_AUDIO_SPDIF_PLAY_CTRL_REG */
+#define ASPCR_SPDIF_BLOCK_START_OFFS  0x0
+#define ASPCR_SPDIF_BLOCK_START_MASK  (0x1 << ASPCR_SPDIF_BLOCK_START_OFFS)
+
+#define ASPCR_SPDIF_PB_EN_MEM_VALIDITY_OFFS  0x1
+#define ASPCR_SPDIF_PB_EN_MEM_VALIDITY_MASK  (0x1 << \
+					ASPCR_SPDIF_PB_EN_MEM_VALIDITY_OFFS)
+
+#define ASPCR_SPDIF_PB_MEM_USR_EN_OFFS 0x2
+#define ASPCR_SPDIF_PB_MEM_USR_EN_MASK (0x1 << ASPCR_SPDIF_PB_MEM_USR_EN_OFFS)
+
+#define ASPCR_SPDIF_UNDERRUN_DATA_OFFS 0x5
+#define ASPCR_SPDIF_UNDERRUN_DATA_MASK (0x1 << ASPCR_SPDIF_UNDERRUN_DATA_OFFS)
+
+#define ASPCR_SPDIF_PB_REG_VALIDITY_OFFS 16
+#define ASPCR_SPDIF_PB_REG_VALIDITY_MASK (0x1 << \
+					ASPCR_SPDIF_PB_REG_VALIDITY_OFFS)
+
+#define ASPCR_SPDIF_PB_NONPCM_OFFS     17
+#define ASPCR_SPDIF_PB_NONPCM_MASK     (0x1 << ASPCR_SPDIF_PB_NONPCM_OFFS)
+
+
+/* MV_AUDIO_I2S_PLAY_CTRL_REG */
+#define AIPCR_I2S_SEND_LAST_FRM_OFFS   23
+#define AIPCR_I2S_SEND_LAST_FRM_MASK   (1 << AIPCR_I2S_SEND_LAST_FRM_OFFS)
+
+#define AIPCR_I2S_PB_JUSTF_OFFS        26
+#define AIPCR_I2S_PB_JUSTF_MASK        (0xf << AIPCR_I2S_PB_JUSTF_OFFS)
+
+#define AIPCR_I2S_PB_SAMPLE_SIZE_OFFS  30
+#define AIPCR_I2S_PB_SAMPLE_SIZE_MASK  (0x3 << AIPCR_I2S_PB_SAMPLE_SIZE_OFFS)
+
+/*********************/
+/* Audio Recordnig  */
+/*******************/
+/* General */
+#define MV_AUDIO_RECORD_CTRL_REG             0x1000
+#define MV_AUDIO_RECORD_START_ADDR_REG       0x1004
+#define MV_AUDIO_RECORD_BUFF_SIZE_REG        0x1008
+#define MV_AUDIO_RECORD_BUF_BYTE_CNTR_REG    0x100C
+
+/* SPDIF */
+#define MV_AUDIO_SPDIF_REC_GEN_REG            0x2004
+#define MV_AUDIO_SPDIF_REC_INT_CAUSE_MASK_REG 0x2008
+#define MV_AUDIO_SPDIF_REC_CH_STATUS_LEFT_REG(ind) \
+	(0x2180 + ((ind) << 2))
+#define MV_AUDIO_SPDIF_REC_CH_STATUS_RIGHT_REG(ind) \
+	(0x21a0 + ((ind) << 2))
+#define MV_AUDIO_SPDIF_REC_USR_BITS_LEFT_REG(ind) \
+	(0x21c0 + ((ind) << 2))
+#define MV_AUDIO_SPDIF_REC_USR_BITS_RIGHT_REG(ind) \
+	(0x21e0 + ((ind) << 2))
+
+/* I2S */
+#define MV_AUDIO_I2S_REC_CTRL_REG            0x2408
+
+
+/* MV_AUDIO_RECORD_CTRL_REG*/
+#define ARCR_RECORD_SAMPLE_SIZE_OFFS 0
+#define ARCR_RECORD_SAMPLE_SIZE_MASK (0x7 << ARCR_RECORD_SAMPLE_SIZE_OFFS)
+
+#define ARCR_RECORDED_MONO_CHNL_OFFS 3
+#define ARCR_RECORDED_MONO_CHNL_MASK (0x1 << ARCR_RECORDED_MONO_CHNL_OFFS)
+
+#define ARCR_RECORD_MONO_OFFS        4
+#define ARCR_RECORD_MONO_MASK        (0x1 << ARCR_RECORD_MONO_OFFS)
+
+#define ARCR_RECORD_BURST_SIZE_OFFS  5
+#define ARCR_RECORD_BURST_SIZE_MASK  (0x3 << ARCR_RECORD_BURST_SIZE_OFFS)
+
+#define ARCR_RECORD_MUTE_OFFS        8
+#define ARCR_RECORD_MUTE_MASK        (0x1 << ARCR_RECORD_MUTE_OFFS)
+
+#define ARCR_RECORD_PAUSE_OFFS       9
+#define ARCR_RECORD_PAUSE_MASK       (0x1 << ARCR_RECORD_PAUSE_OFFS)
+
+#define ARCR_RECORD_I2S_EN_OFFS      10
+#define ARCR_RECORD_I2S_EN_MASK      (0x1 << ARCR_RECORD_I2S_EN_OFFS)
+
+#define ARCR_RECORD_SPDIF_EN_OFFS    11
+#define ARCR_RECORD_SPDIF_EN_MASK    (0x1 << ARCR_RECORD_SPDIF_EN_OFFS)
+
+
+/* MV_AUDIO_SPDIF_REC_GEN_REG*/
+#define ASRGR_CORE_CLK_FREQ_OFFS     1
+#define ASRGR_CORE_CLK_FREQ_MASK     (0x3 << ASRGR_CORE_CLK_FREQ_OFFS)
+#define ASRGR_CORE_CLK_FREQ_133MHZ   (0x0 << ASRGR_CORE_CLK_FREQ_OFFS)
+#define ASRGR_CORE_CLK_FREQ_150MHZ   (0x1 << ASRGR_CORE_CLK_FREQ_OFFS)
+#define ASRGR_CORE_CLK_FREQ_166MHZ   (0x2 << ASRGR_CORE_CLK_FREQ_OFFS)
+#define ASRGR_CORE_CLK_FREQ_200MHZ   (0x3 << ASRGR_CORE_CLK_FREQ_OFFS)
+
+#define ASRGR_VALID_PCM_INFO_OFFS    7
+#define ASRGR_VALID_PCM_INFO_MASK    (0x1 << ASRGR_VALID_PCM_INFO_OFFS)
+
+#define ASRGR_SAMPLE_FREQ_OFFS       8
+#define ASRGR_SAMPLE_FREQ_MASK       (0xf << ASRGR_SAMPLE_FREQ_OFFS)
+
+#define ASRGR_NON_PCM_OFFS           14
+#define ASRGR_NON_PCM_MASK           (1 << ASRGR_NON_PCM_OFFS)
+
+/* MV_AUDIO_I2S_REC_CTRL_REG*/
+#define AIRCR_I2S_RECORD_JUSTF_OFFS  26
+#define AIRCR_I2S_RECORD_JUSTF_MASK  (0xf << AIRCR_I2S_RECORD_JUSTF_OFFS)
+
+#define AIRCR_I2S_SAMPLE_SIZE_OFFS   30
+#define AIRCR_I2S_SAMPLE_SIZE_MASK   (0x3 << AIRCR_I2S_SAMPLE_SIZE_OFFS)
+
+#endif /* __KW_AUDIO_REGS_H */
+
diff --git a/sound/soc/kirkwood/kirkwood_pcm.c b/sound/soc/kirkwood/kirkwood_pcm.c
new file mode 100644
index 0000000..5ed13bf
--- /dev/null
+++ b/sound/soc/kirkwood/kirkwood_pcm.c
@@ -0,0 +1,1495 @@
+/*
+ *
+ *	Marvell Orion Alsa Sound driver
+ *
+ *	Author: Maen Suleiman
+ *	Copyright (C) 2008 Marvell Ltd.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/interrupt.h>
+#include <linux/dma-mapping.h>
+#include <linux/platform_device.h>
+#include <linux/mv88fx_audio.h>
+
+#include <sound/core.h>
+#include <sound/control.h>
+#include <sound/pcm.h>
+#include <sound/asoundef.h>
+
+#include "kirkwood_audio_hal.h"
+
+struct mv88fx_snd_chip *chip;
+
+static int test_memory(struct mbus_dram_target_info *dram_info,
+			unsigned int base, unsigned int size)
+{
+	int i;
+
+	for (i = 0; i <= dram_info->num_cs; i++) {
+
+		/* check if we get to end */
+		if ((dram_info->cs[i].base == 0) &&
+		    (dram_info->cs[i].size == 0))
+			break;
+
+		/* check if we fit into one memory window only */
+		if ((base >= dram_info->cs[i].base) &&
+		    ((base + size) <= dram_info->cs[i].base +
+				      dram_info->cs[i].size))
+			return 1;
+	}
+
+	return 0;
+}
+
+static void devdma_hw_free(struct snd_pcm_substream *substream)
+{
+	struct snd_pcm_runtime *runtime = substream->runtime;
+	struct snd_dma_buffer *buf = runtime->dma_buffer_p;
+
+	if (runtime->dma_area == NULL)
+		return;
+
+	if (buf != &substream->dma_buffer)
+		kfree(runtime->dma_buffer_p);
+
+	snd_pcm_set_runtime_buffer(substream, NULL);
+}
+
+static int devdma_hw_alloc(struct device *dev, struct snd_pcm_substream
+			   *substream, size_t size)
+{
+	struct snd_pcm_runtime *runtime = substream->runtime;
+	struct snd_dma_buffer *buf = runtime->dma_buffer_p;
+	struct mv88fx_snd_stream *audio_stream =
+	       snd_pcm_substream_chip(substream);
+
+	int ret = 0;
+
+	if (buf) {
+		if (buf->bytes >= size) {
+			snd_printd("buf->bytes >= size\n");
+			goto out;
+		}
+		devdma_hw_free(substream);
+	}
+
+	if (substream->dma_buffer.area != NULL &&
+	    substream->dma_buffer.bytes >= size) {
+		buf = &substream->dma_buffer;
+	} else {
+		buf = kmalloc(sizeof(struct snd_dma_buffer), GFP_KERNEL);
+		if (!buf) {
+			snd_printk("buf == NULL\n");
+			goto nomem;
+		}
+
+		buf->dev.type = SNDRV_DMA_TYPE_DEV;
+		buf->dev.dev = dev;
+		buf->area = audio_stream->area;
+		buf->addr = audio_stream->addr;
+		buf->bytes = size;
+		buf->private_data = NULL;
+
+		if (!buf->area) {
+			snd_printk("buf->area == NULL\n");
+			goto free;
+		}
+	}
+
+	snd_pcm_set_runtime_buffer(substream, buf);
+	ret = 1;
+out:
+	runtime->dma_bytes = size;
+	return ret;
+
+free:
+	kfree(buf);
+nomem:
+	return -ENOMEM;
+}
+
+static int devdma_mmap(struct device *dev, struct snd_pcm_substream *substream,
+			struct vm_area_struct *vma)
+{
+	struct snd_pcm_runtime *runtime = substream->runtime;
+	return dma_mmap_coherent(dev, vma, runtime->dma_area,
+		      runtime->dma_addr, runtime->dma_bytes);
+}
+
+/*
+ * hw preparation for spdif
+ */
+
+static int mv88fx_snd_spdif_mask_info(struct snd_kcontrol *kcontrol,
+				      struct snd_ctl_elem_info *uinfo)
+{
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
+	uinfo->count = 1;
+	return 0;
+}
+
+static int mv88fx_snd_spdif_mask_get(struct snd_kcontrol *kcontrol,
+				     struct snd_ctl_elem_value *ucontrol)
+{
+	ucontrol->value.iec958.status[0] = 0xff;
+	ucontrol->value.iec958.status[1] = 0xff;
+	ucontrol->value.iec958.status[2] = 0xff;
+	ucontrol->value.iec958.status[3] = 0xff;
+	return 0;
+}
+
+static struct snd_kcontrol_new mv88fx_snd_spdif_mask = {
+	.access = SNDRV_CTL_ELEM_ACCESS_READ,
+	.iface  = SNDRV_CTL_ELEM_IFACE_PCM,
+	.name   = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
+	.info   = mv88fx_snd_spdif_mask_info,
+	.get    = mv88fx_snd_spdif_mask_get,
+};
+
+static int mv88fx_snd_spdif_stream_info(struct snd_kcontrol *kcontrol,
+					struct snd_ctl_elem_info *uinfo)
+{
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
+	uinfo->count = 1;
+	return 0;
+}
+
+static int mv88fx_snd_spdif_stream_get(struct snd_kcontrol *kcontrol,
+				       struct snd_ctl_elem_value *ucontrol)
+{
+	struct mv88fx_snd_chip *chip = snd_kcontrol_chip(kcontrol);
+	int i, word;
+
+	spin_lock_irq(&chip->reg_lock);
+
+	for (word = 0; word < 4; word++) {
+		chip->stream[PLAYBACK]->spdif_status[word] =
+		readl(chip->base +
+		MV_AUDIO_SPDIF_PLAY_CH_STATUS_LEFT_REG(word));
+
+		for (i = 0; i < 4; i++)
+			ucontrol->value.iec958.status[word + i] =
+			(chip->stream[PLAYBACK]->spdif_status[word] >>
+			 (i * 8)) & 0xff;
+	}
+
+	spin_unlock_irq(&chip->reg_lock);
+	return 0;
+}
+
+static int mv88fx_snd_spdif_stream_put(struct snd_kcontrol *kcontrol,
+				       struct snd_ctl_elem_value *ucontrol)
+{
+	struct mv88fx_snd_chip *chip = snd_kcontrol_chip(kcontrol);
+	int i, change = 0, word;
+
+	spin_lock_irq(&chip->reg_lock);
+
+	for (word = 0; word < 4; word++) {
+		for (i = 0; i < 4; i++) {
+			chip->stream[PLAYBACK]->spdif_status[word] |=
+			ucontrol->value.iec958.status[word + i] << (i * 8);
+		}
+
+		writel(chip->stream[PLAYBACK]->spdif_status[word],
+		chip->base + MV_AUDIO_SPDIF_PLAY_CH_STATUS_LEFT_REG(word));
+
+		writel(chip->stream[PLAYBACK]->spdif_status[word],
+		chip->base + MV_AUDIO_SPDIF_PLAY_CH_STATUS_RIGHT_REG(word));
+	}
+
+	if (chip->stream[PLAYBACK]->spdif_status[0] & IEC958_AES0_NONAUDIO)
+		chip->pcm_mode = NON_PCM;
+
+	spin_unlock_irq(&chip->reg_lock);
+
+	return change;
+}
+
+static struct snd_kcontrol_new mv88fx_snd_spdif_stream = {
+	.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
+		  SNDRV_CTL_ELEM_ACCESS_INACTIVE,
+	.iface  = SNDRV_CTL_ELEM_IFACE_PCM,
+	.name   = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
+	.info   = mv88fx_snd_spdif_stream_info,
+	.get    = mv88fx_snd_spdif_stream_get,
+	.put    = mv88fx_snd_spdif_stream_put
+};
+
+
+static int mv88fx_snd_spdif_default_info(struct snd_kcontrol *kcontrol,
+					 struct snd_ctl_elem_info *uinfo)
+{
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
+	uinfo->count = 1;
+	return 0;
+}
+
+static int mv88fx_snd_spdif_default_get(struct snd_kcontrol *kcontrol,
+					struct snd_ctl_elem_value *ucontrol)
+{
+	struct mv88fx_snd_chip *chip = snd_kcontrol_chip(kcontrol);
+	int i, word;
+
+	spin_lock_irq(&chip->reg_lock);
+
+	for (word = 0; word < 4; word++) {
+		chip->stream_defaults[PLAYBACK]->spdif_status[word] =
+		readl(chip->base +
+		MV_AUDIO_SPDIF_PLAY_CH_STATUS_LEFT_REG(word));
+
+		for (i = 0; i < 4; i++)
+			ucontrol->value.iec958.status[word + i] =
+			(chip->stream_defaults[PLAYBACK]->spdif_status[word] >>
+			 (i * 8)) & 0xff;
+	}
+
+	spin_unlock_irq(&chip->reg_lock);
+
+	return 0;
+}
+
+static int mv88fx_snd_spdif_default_put(struct snd_kcontrol *kcontrol,
+					struct snd_ctl_elem_value *ucontrol)
+{
+	struct mv88fx_snd_chip *chip = snd_kcontrol_chip(kcontrol);
+	int i, change = 0, word;
+
+	spin_lock_irq(&chip->reg_lock);
+
+	for (word = 0; word < 4; word++) {
+		for (i = 0; i < 4; i++) {
+			chip->stream_defaults[PLAYBACK]->spdif_status[word] |=
+			ucontrol->value.iec958.status[word + i] << (i * 8);
+		}
+
+		writel(chip->stream_defaults[PLAYBACK]->spdif_status[word],
+		chip->base + MV_AUDIO_SPDIF_PLAY_CH_STATUS_LEFT_REG(word));
+
+		writel(chip->stream_defaults[PLAYBACK]->spdif_status[word],
+		chip->base + MV_AUDIO_SPDIF_PLAY_CH_STATUS_RIGHT_REG(word));
+	}
+
+	if (chip->stream_defaults[PLAYBACK]->spdif_status[0] &
+	    IEC958_AES0_NONAUDIO)
+		chip->pcm_mode = NON_PCM;
+
+	spin_unlock_irq(&chip->reg_lock);
+
+	return change;
+}
+
+/* static struct snd_kcontrol_new mv88fx_snd_spdif_default __devinitdata = */
+static struct snd_kcontrol_new mv88fx_snd_spdif_default = {
+	.iface = SNDRV_CTL_ELEM_IFACE_PCM,
+	.name  = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
+	.info  = mv88fx_snd_spdif_default_info,
+	.get   = mv88fx_snd_spdif_default_get,
+	.put   = mv88fx_snd_spdif_default_put
+};
+
+static unsigned char mv88fx_snd_vol[2];
+
+static int mv88fx_snd_mixer_vol_info(struct snd_kcontrol *kcontrol,
+				     struct snd_ctl_elem_info *uinfo)
+{
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+	uinfo->count = 2;
+	uinfo->value.integer.min = 0;
+	uinfo->value.integer.max = 39;
+	return 0;
+}
+
+static int mv88fx_snd_mixer_vol_get(struct snd_kcontrol *kcontrol,
+				    struct snd_ctl_elem_value *ucontrol)
+{
+	codec_vol_get(mv88fx_snd_vol);
+
+	ucontrol->value.integer.value[0] = (long)mv88fx_snd_vol[0];
+	ucontrol->value.integer.value[1] = (long)mv88fx_snd_vol[1];
+
+	return 0;
+}
+
+static int mv88fx_snd_mixer_vol_put(struct snd_kcontrol *kcontrol,
+				    struct snd_ctl_elem_value *ucontrol)
+{
+	mv88fx_snd_vol[0] = (unsigned char)ucontrol->value.integer.value[0];
+	mv88fx_snd_vol[1] = (unsigned char)ucontrol->value.integer.value[1];
+
+	codec_vol_set(mv88fx_snd_vol);
+
+	return 0;
+}
+
+static struct snd_kcontrol_new mv88fx_snd_dac_vol = {
+	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+	.name  = "Playback DAC Volume",
+	.info  = mv88fx_snd_mixer_vol_info,
+	.get   = mv88fx_snd_mixer_vol_get,
+	.put   = mv88fx_snd_mixer_vol_put
+};
+
+struct mv88fx_snd_mixer_enum {
+	char         **names; /* enum names*/
+	int          *values; /* values to be updated*/
+	unsigned int count;   /* number of elements */
+	void         *rec;    /* field to be updated*/
+};
+
+static int mv88fx_snd_mixer_enum_info(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_info *uinfo)
+{
+	struct mv88fx_snd_mixer_enum *mixer_enum =
+	(struct mv88fx_snd_mixer_enum *)kcontrol->private_value;
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+	uinfo->count = 1;
+	uinfo->value.enumerated.items = mixer_enum->count;
+
+	if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
+		uinfo->value.enumerated.item--;
+
+	strcpy(uinfo->value.enumerated.name,
+			mixer_enum->names[uinfo->value.enumerated.item]);
+
+	return 0;
+}
+
+static int mv88fx_snd_mixer_enum_get(struct snd_kcontrol *kcontrol,
+			       struct snd_ctl_elem_value *ucontrol)
+{
+	struct mv88fx_snd_mixer_enum *mixer_enum =
+	(struct mv88fx_snd_mixer_enum *)kcontrol->private_value;
+	unsigned int val, i;
+
+	val = *(unsigned int *)mixer_enum->rec;
+
+	for (i = 0; i < mixer_enum->count; i++) {
+
+		if (val == (unsigned int)mixer_enum->values[i]) {
+			ucontrol->value.enumerated.item[0] = i;
+			break;
+		}
+	}
+
+	return 0;
+}
+
+static int mv88fx_snd_mixer_enum_put(struct snd_kcontrol *kcontrol,
+			       struct snd_ctl_elem_value *ucontrol)
+{
+	unsigned int val, *rec, i;
+	struct mv88fx_snd_mixer_enum *mixer_enum =
+	(struct mv88fx_snd_mixer_enum *)kcontrol->private_value;
+
+	rec = (unsigned int *)mixer_enum->rec;
+	val = ucontrol->value.enumerated.item[0];
+
+	if (val > mixer_enum->count)
+		val = mixer_enum->count;
+
+	for (i = 0; i < mixer_enum->count; i++) {
+
+		if (val ==  i) {
+			*rec = (unsigned int)mixer_enum->values[i];
+			break;
+		}
+	}
+
+	return 0;
+}
+
+#define MV88FX_PCM_MIXER_ENUM(xname, xindex, value) \
+{ .iface         = SNDRV_CTL_ELEM_IFACE_MIXER, \
+  .name          = xname, \
+  .index         = xindex, \
+  .info          = mv88fx_snd_mixer_enum_info, \
+  .get           = mv88fx_snd_mixer_enum_get, \
+  .put           = mv88fx_snd_mixer_enum_put, \
+  .private_value = (unsigned long)value, \
+}
+
+static char *playback_src_mixer_names[] = {"SPDIF", "I2S", "SPDIF And I2S"};
+static int playback_src_mixer_values[] = { SPDIF, I2S, (SPDIF | I2S)};
+
+static struct mv88fx_snd_mixer_enum playback_src_mixer = {
+	.names	= playback_src_mixer_names,
+	.values	= playback_src_mixer_values,
+	.count	= 3,
+};
+
+static char *playback_mono_mixer_names[] = {"Mono Both", "Mono Left",
+						"Mono Right"};
+static int playback_mono_mixer_values[] = { MONO_BOTH, MONO_LEFT, MONO_RIGHT};
+
+static struct mv88fx_snd_mixer_enum playback_mono_mixer = {
+	.names	= playback_mono_mixer_names,
+	.values	= playback_mono_mixer_values,
+	.count	= 3,
+};
+
+static char *capture_src_mixer_names[] = {"SPDIF", "I2S"};
+static int capture_src_mixer_values[] = { SPDIF, I2S};
+
+static struct mv88fx_snd_mixer_enum capture_src_mixer = {
+	.names	= capture_src_mixer_names,
+	.values	= capture_src_mixer_values,
+	.count	= 2,
+};
+
+static char *capture_mono_mixer_names[] = {"Mono Left", "Mono Right"};
+static int capture_mono_mixer_values[] = { MONO_LEFT, MONO_RIGHT};
+
+static struct mv88fx_snd_mixer_enum capture_mono_mixer	= {
+	.names	= capture_mono_mixer_names,
+	.values	= capture_mono_mixer_values,
+	.count	= 2,
+};
+
+static struct snd_kcontrol_new mv88fx_snd_mixers[] = {
+	MV88FX_PCM_MIXER_ENUM("Playback output type", 0, &playback_src_mixer),
+
+	MV88FX_PCM_MIXER_ENUM("Playback mono type", 0, &playback_mono_mixer),
+
+	MV88FX_PCM_MIXER_ENUM("Capture input Type", 0, &capture_src_mixer),
+
+	MV88FX_PCM_MIXER_ENUM("Capture mono type", 0, &capture_mono_mixer),
+};
+
+#define	PLAYBACK_MIX_INDX       0
+#define PLAYBACK_MONO_MIX_INDX  1
+#define CAPTURE_MIX_INDX        2
+#define	CAPTURE_MONO_MIX_INDX   3
+
+static int mv88fx_snd_ctrl_new(struct snd_card *card)
+{
+	struct mv88fx_snd_platform_data *pdata = card->dev->platform_data;
+	int err = 0;
+
+	playback_src_mixer.rec = &chip->stream_defaults[PLAYBACK]->dig_mode;
+	playback_mono_mixer.rec = &chip->stream_defaults[PLAYBACK]->mono_mode;
+
+	capture_src_mixer.rec = &chip->stream_defaults[CAPTURE]->dig_mode;
+	capture_mono_mixer.rec = &chip->stream_defaults[CAPTURE]->mono_mode;
+
+	if ((pdata->i2s_play) && (pdata->spdif_play)) {
+		err = snd_ctl_add(card,
+		      snd_ctl_new1(&mv88fx_snd_mixers[PLAYBACK_MIX_INDX],
+		      chip));
+		if (err < 0)
+			return err;
+	}
+
+	err = snd_ctl_add(card,
+	      snd_ctl_new1(&mv88fx_snd_mixers[PLAYBACK_MONO_MIX_INDX], chip));
+	if (err < 0)
+		return err;
+
+	if ((pdata->i2s_rec) && (pdata->spdif_rec)) {
+		err = snd_ctl_add(card,
+		snd_ctl_new1(&mv88fx_snd_mixers[CAPTURE_MIX_INDX], chip));
+		if (err < 0)
+			return err;
+	}
+
+	err = snd_ctl_add(card, snd_ctl_new1(
+		&mv88fx_snd_mixers[CAPTURE_MONO_MIX_INDX], chip));
+	if (err < 0)
+		return err;
+
+	if (pdata->i2s_play) {
+		err = snd_ctl_add(card, snd_ctl_new1(&mv88fx_snd_dac_vol,
+				  chip));
+		if (err < 0)
+			return err;
+	}
+
+	err = snd_ctl_add(card, snd_ctl_new1(&mv88fx_snd_spdif_mask,
+			  chip));
+	if (err < 0)
+		return err;
+
+	err = snd_ctl_add(card, snd_ctl_new1(&mv88fx_snd_spdif_default,
+			  chip));
+	if (err < 0)
+		return err;
+
+	err = snd_ctl_add(card, snd_ctl_new1(&mv88fx_snd_spdif_stream,
+			  chip));
+	return err;
+}
+
+static struct snd_pcm_hardware mv88fx_snd_capture_hw = {
+	.info = (SNDRV_PCM_INFO_INTERLEAVED |
+		 SNDRV_PCM_INFO_MMAP |
+		 SNDRV_PCM_INFO_MMAP_VALID |
+		 SNDRV_PCM_INFO_BLOCK_TRANSFER |
+		 SNDRV_PCM_INFO_PAUSE),
+
+	.formats = (SNDRV_PCM_FMTBIT_S16_LE |
+		    SNDRV_PCM_FMTBIT_S24_LE |
+		    SNDRV_PCM_FMTBIT_S32_LE),
+
+	.rates = (SNDRV_PCM_RATE_44100 |
+		  SNDRV_PCM_RATE_48000 |
+		  SNDRV_PCM_RATE_96000),
+
+	.rate_min = 44100,
+	.rate_max = 96000,
+	.channels_min = 1,
+	.channels_max = 2,
+	.buffer_bytes_max = (16*1024*1024),
+	.period_bytes_min = MV88FX_SND_MIN_PERIOD_BYTES,
+	.period_bytes_max = MV88FX_SND_MAX_PERIOD_BYTES,
+	.periods_min = MV88FX_SND_MIN_PERIODS,
+	.periods_max = MV88FX_SND_MAX_PERIODS,
+	.fifo_size = 0,
+};
+
+static int mv88fx_snd_capture_open(struct snd_pcm_substream *substream)
+{
+	int err;
+
+	chip->stream_defaults[CAPTURE]->substream = substream;
+	chip->stream_defaults[CAPTURE]->direction = CAPTURE;
+	substream->private_data = chip->stream_defaults[CAPTURE];
+	substream->runtime->hw = mv88fx_snd_capture_hw;
+
+	if (chip->stream_defaults[CAPTURE]->dig_mode & SPDIF)
+		substream->runtime->hw.formats &= ~SNDRV_PCM_FMTBIT_S32_LE;
+
+	/* check if playback is already running with specific rate */
+	if (chip->stream[PLAYBACK]->rate) {
+		switch (chip->stream[PLAYBACK]->rate) {
+		case 44100:
+			substream->runtime->hw.rates = SNDRV_PCM_RATE_44100;
+			break;
+		case 48000:
+			substream->runtime->hw.rates = SNDRV_PCM_RATE_48000;
+			break;
+		case 96000:
+			substream->runtime->hw.rates = SNDRV_PCM_RATE_96000;
+			break;
+		}
+	}
+
+	err = snd_pcm_hw_constraint_minmax(substream->runtime,
+					   SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
+					   chip->burst * 2,
+					   AUDIO_REG_TO_SIZE(APBBCR_SIZE_MAX));
+	if (err < 0)
+		return err;
+
+	err = snd_pcm_hw_constraint_step(substream->runtime, 0,
+					 SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
+					 chip->burst);
+	if (err < 0)
+		return err;
+
+	err = snd_pcm_hw_constraint_step(substream->runtime, 0,
+					 SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
+					 chip->burst);
+	if (err < 0)
+		return err;
+
+	err = snd_pcm_hw_constraint_minmax(substream->runtime,
+					   SNDRV_PCM_HW_PARAM_PERIODS,
+					   MV88FX_SND_MIN_PERIODS,
+					   MV88FX_SND_MAX_PERIODS);
+	if (err < 0)
+		return err;
+
+	err = snd_pcm_hw_constraint_integer(substream->runtime,
+					    SNDRV_PCM_HW_PARAM_PERIODS);
+	if (err < 0)
+		return err;
+
+	return 0;
+}
+
+static int mv88fx_snd_capture_close(struct snd_pcm_substream *substream)
+{
+	chip->stream_defaults[CAPTURE]->substream = NULL;
+	memset(chip->stream[CAPTURE], 0, sizeof(struct mv88fx_snd_stream));
+
+	return 0;
+}
+
+static int mv88fx_snd_capture_hw_params(struct snd_pcm_substream *substream,
+					struct snd_pcm_hw_params *params)
+{
+	struct mv88fx_snd_stream *audio_stream =
+				  snd_pcm_substream_chip(substream);
+
+	return devdma_hw_alloc(audio_stream->dev, substream,
+			       params_buffer_bytes(params));
+}
+
+static int mv88fx_snd_capture_hw_free(struct snd_pcm_substream *substream)
+{
+	/*
+	 * Clear out the DMA and any allocated buffers.
+	 */
+	devdma_hw_free(substream);
+	return 0;
+}
+
+static int mv88fx_snd_capture_prepare(struct snd_pcm_substream *substream)
+{
+	struct snd_pcm_runtime *runtime = substream->runtime;
+
+	struct mv88fx_snd_stream *audio_stream =
+				  snd_pcm_substream_chip(substream);
+
+	audio_stream->rate = runtime->rate;
+	audio_stream->stereo = (runtime->channels == 1) ? 0 : 1;
+
+	if (runtime->format == SNDRV_PCM_FORMAT_S16_LE) {
+		audio_stream->format = SAMPLE_16IN16;
+	} else if (runtime->format == SNDRV_PCM_FORMAT_S24_LE) {
+		audio_stream->format = SAMPLE_24IN32;
+	} else if (runtime->format == SNDRV_PCM_FORMAT_S32_LE) {
+		audio_stream->format = SAMPLE_32IN32;
+	} else {
+		snd_printk("Requested format %d is not supported\n",
+				runtime->format);
+		return -1;
+	}
+
+	/* buffer and period sizes in frame */
+	audio_stream->dma_addr = runtime->dma_addr;
+	audio_stream->dma_size = frames_to_bytes(runtime, runtime->buffer_size);
+	audio_stream->period_size =
+				 frames_to_bytes(runtime, runtime->period_size);
+
+	memcpy(chip->stream[CAPTURE], chip->stream_defaults[CAPTURE],
+	       sizeof(struct mv88fx_snd_stream));
+
+	return mv88fx_snd_hw_capture_set(chip);
+}
+
+static int mv88fx_snd_capture_trigger(struct snd_pcm_substream *substream,
+				      int cmd)
+{
+	struct mv88fx_snd_stream *audio_stream =
+				 snd_pcm_substream_chip(substream);
+	int result = 0;
+	unsigned int reg_data;
+
+	spin_lock(&chip->reg_lock);
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+		/* FIXME: should check if busy before */
+
+		/* make sure the dma in pause state*/
+		reg_data = readl(chip->base + MV_AUDIO_RECORD_CTRL_REG);
+		reg_data |= ARCR_RECORD_PAUSE_MASK;
+		writel(reg_data, chip->base + MV_AUDIO_RECORD_CTRL_REG);
+
+		/* enable interrupt */
+		reg_data = readl(chip->base + MV_AUDIO_INT_MASK_REG);
+		reg_data |= AICR_RECORD_BYTES_INT;
+		writel(reg_data, chip->base + MV_AUDIO_INT_MASK_REG);
+
+		reg_data = readl(chip->base + MV_AUDIO_RECORD_CTRL_REG);
+
+		/* enable dma */
+		if (audio_stream->dig_mode & I2S)
+			reg_data |= ARCR_RECORD_I2S_EN_MASK;
+
+		if (audio_stream->dig_mode & SPDIF)
+			reg_data |= ARCR_RECORD_SPDIF_EN_MASK;
+
+		/* start dma */
+		reg_data &= (~ARCR_RECORD_PAUSE_MASK);
+		writel(reg_data, chip->base + MV_AUDIO_RECORD_CTRL_REG);
+		break;
+
+	case SNDRV_PCM_TRIGGER_STOP:
+
+		/* make sure the dma in pause state */
+		reg_data = readl(chip->base + MV_AUDIO_RECORD_CTRL_REG);
+		reg_data |= ARCR_RECORD_PAUSE_MASK;
+		writel(reg_data, chip->base + MV_AUDIO_RECORD_CTRL_REG);
+
+		/* disable interrupt */
+		reg_data = readl(chip->base + MV_AUDIO_INT_MASK_REG);
+		reg_data &= (~AICR_RECORD_BYTES_INT);
+		writel(reg_data, chip->base + MV_AUDIO_INT_MASK_REG);
+
+		/* always stop both I2S and SPDIF */
+		reg_data = readl(chip->base + MV_AUDIO_RECORD_CTRL_REG);
+		reg_data &= (~(ARCR_RECORD_I2S_EN_MASK |
+			       ARCR_RECORD_SPDIF_EN_MASK));
+		writel(reg_data, chip->base + MV_AUDIO_RECORD_CTRL_REG);
+
+		/* FIXME: should check if busy after */
+
+		break;
+
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+		reg_data = readl(chip->base + MV_AUDIO_RECORD_CTRL_REG);
+		reg_data |= ARCR_RECORD_PAUSE_MASK;
+		writel(reg_data, chip->base + MV_AUDIO_RECORD_CTRL_REG);
+		break;
+
+	case SNDRV_PCM_TRIGGER_RESUME:
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+		reg_data = readl(chip->base + MV_AUDIO_RECORD_CTRL_REG);
+		reg_data &= (~ARCR_RECORD_PAUSE_MASK);
+		writel(reg_data, chip->base + MV_AUDIO_RECORD_CTRL_REG);
+		break;
+
+	default:
+		result = -EINVAL;
+		break;
+	}
+
+	spin_unlock(&chip->reg_lock);
+	return result;
+}
+
+static snd_pcm_uframes_t mv88fx_snd_capture_pointer(struct snd_pcm_substream
+						    *substream)
+{
+	return bytes_to_frames(substream->runtime,
+	(ssize_t)readl(chip->base + MV_AUDIO_RECORD_BUF_BYTE_CNTR_REG));
+}
+
+static int mv88fx_snd_capture_mmap(struct snd_pcm_substream *substream,
+			    struct vm_area_struct *vma)
+{
+	return devdma_mmap(NULL, substream, vma);
+}
+
+static struct snd_pcm_ops mv88fx_snd_capture_ops = {
+	.open      = mv88fx_snd_capture_open,
+	.close     = mv88fx_snd_capture_close,
+	.ioctl     = snd_pcm_lib_ioctl,
+	.hw_params = mv88fx_snd_capture_hw_params,
+	.hw_free   = mv88fx_snd_capture_hw_free,
+	.prepare   = mv88fx_snd_capture_prepare,
+	.trigger   = mv88fx_snd_capture_trigger,
+	.pointer   = mv88fx_snd_capture_pointer,
+	.mmap      = mv88fx_snd_capture_mmap,
+};
+
+static struct snd_pcm_hardware mv88fx_snd_playback_hw = {
+	.info = (SNDRV_PCM_INFO_INTERLEAVED |
+		 SNDRV_PCM_INFO_MMAP |
+		 SNDRV_PCM_INFO_MMAP_VALID |
+		 SNDRV_PCM_INFO_BLOCK_TRANSFER |
+		 SNDRV_PCM_INFO_PAUSE),
+	.formats = (SNDRV_PCM_FMTBIT_S16_LE |
+		    SNDRV_PCM_FMTBIT_S24_LE |
+		    SNDRV_PCM_FMTBIT_S32_LE),
+	.rates = (SNDRV_PCM_RATE_44100 |
+		  SNDRV_PCM_RATE_48000 |
+		  SNDRV_PCM_RATE_96000),
+
+	.rate_min = 44100,
+	.rate_max = 96000,
+	.channels_min = 1,
+	.channels_max = 2,
+	.buffer_bytes_max = (16*1024*1024),
+	.period_bytes_min = MV88FX_SND_MIN_PERIOD_BYTES,
+	.period_bytes_max = MV88FX_SND_MAX_PERIOD_BYTES,
+	.periods_min = MV88FX_SND_MIN_PERIODS,
+	.periods_max = MV88FX_SND_MAX_PERIODS,
+	.fifo_size = 0,
+};
+
+static int mv88fx_snd_playback_open(struct snd_pcm_substream *substream)
+{
+	int err = 0;
+
+	chip->stream_defaults[PLAYBACK]->substream = substream;
+	chip->stream_defaults[PLAYBACK]->direction = PLAYBACK;
+	substream->private_data = chip->stream_defaults[PLAYBACK];
+	substream->runtime->hw = mv88fx_snd_playback_hw;
+
+	if (chip->stream_defaults[PLAYBACK]->dig_mode & SPDIF)
+		substream->runtime->hw.formats &= ~SNDRV_PCM_FMTBIT_S32_LE;
+
+	/* check if capture is already running with specific rate */
+	if (chip->stream[CAPTURE]->rate) {
+		switch (chip->stream[CAPTURE]->rate) {
+		case 44100:
+			substream->runtime->hw.rates = SNDRV_PCM_RATE_44100;
+			break;
+		case 48000:
+			substream->runtime->hw.rates = SNDRV_PCM_RATE_48000;
+			break;
+		case 96000:
+			substream->runtime->hw.rates = SNDRV_PCM_RATE_96000;
+			break;
+
+		}
+	}
+
+	err = snd_pcm_hw_constraint_minmax(substream->runtime,
+					   SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
+					   chip->burst * 2,
+					   AUDIO_REG_TO_SIZE(APBBCR_SIZE_MAX));
+	if (err < 0)
+		return err;
+
+	err = snd_pcm_hw_constraint_step(substream->runtime, 0,
+					 SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
+					 chip->burst);
+	if (err < 0)
+		return err;
+
+	err = snd_pcm_hw_constraint_step(substream->runtime, 0,
+					 SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
+					 chip->burst);
+	if (err < 0)
+		return err;
+
+	err = snd_pcm_hw_constraint_minmax(substream->runtime,
+					   SNDRV_PCM_HW_PARAM_PERIODS,
+					   MV88FX_SND_MIN_PERIODS,
+					   MV88FX_SND_MAX_PERIODS);
+	if (err < 0)
+		return err;
+
+	err = snd_pcm_hw_constraint_integer(substream->runtime,
+					    SNDRV_PCM_HW_PARAM_PERIODS);
+
+	if (err < 0)
+		return err;
+
+	return 0;
+}
+
+static int mv88fx_snd_playback_close(struct snd_pcm_substream *substream)
+{
+	int i;
+
+	chip->stream_defaults[PLAYBACK]->substream = NULL;
+	chip->pcm_mode = PCM;
+
+	for (i = 0; i < 4; i++) {
+		chip->stream_defaults[PLAYBACK]->spdif_status[i] = 0;
+		chip->stream[PLAYBACK]->spdif_status[i] = 0;
+
+		writel(chip->stream_defaults[PLAYBACK]->spdif_status[i],
+		       chip->base + MV_AUDIO_SPDIF_PLAY_CH_STATUS_LEFT_REG(i));
+		writel(chip->stream_defaults[PLAYBACK]->spdif_status[i],
+		       chip->base + MV_AUDIO_SPDIF_PLAY_CH_STATUS_RIGHT_REG(i));
+	}
+
+	memset(chip->stream[PLAYBACK], 0, sizeof(struct mv88fx_snd_stream));
+
+	return 0;
+}
+
+static int mv88fx_snd_playback_hw_params(struct snd_pcm_substream *substream,
+					 struct snd_pcm_hw_params *params)
+{
+	struct mv88fx_snd_stream *audio_stream =
+				 snd_pcm_substream_chip(substream);
+
+	return devdma_hw_alloc(audio_stream->dev, substream,
+			params_buffer_bytes(params));
+}
+
+static int mv88fx_snd_playback_hw_free(struct snd_pcm_substream *substream)
+{
+	/*
+	 * Clear out the DMA and any allocated buffers.
+	 */
+	devdma_hw_free(substream);
+	return 0;
+}
+
+static int mv88fx_snd_playback_prepare(struct snd_pcm_substream *substream)
+{
+	struct snd_pcm_runtime *runtime = substream->runtime;
+
+	struct mv88fx_snd_stream *audio_stream =
+				  snd_pcm_substream_chip(substream);
+
+	if ((audio_stream->dig_mode == I2S) &&
+	    (chip->pcm_mode == NON_PCM))
+		return -1;
+
+	audio_stream->rate = runtime->rate;
+	audio_stream->stereo = (runtime->channels == 1) ? 0 : 1;
+
+	if (runtime->format == SNDRV_PCM_FORMAT_S16_LE) {
+		audio_stream->format = SAMPLE_16IN16;
+	} else if (runtime->format == SNDRV_PCM_FORMAT_S24_LE) {
+		audio_stream->format = SAMPLE_24IN32;
+	} else if (runtime->format == SNDRV_PCM_FORMAT_S32_LE) {
+		audio_stream->format = SAMPLE_32IN32;
+	} else {
+		snd_printk("Requested format %d is not supported\n",
+				runtime->format);
+		return -1;
+	}
+
+	/* buffer and period sizes in frame */
+	audio_stream->dma_addr = runtime->dma_addr;
+	audio_stream->dma_size = frames_to_bytes(runtime, runtime->buffer_size);
+	audio_stream->period_size =
+				 frames_to_bytes(runtime, runtime->period_size);
+
+	memcpy(chip->stream[PLAYBACK], chip->stream_defaults[PLAYBACK],
+	       sizeof(struct mv88fx_snd_stream));
+
+	return mv88fx_snd_hw_playback_set(chip);
+}
+
+static int mv88fx_snd_playback_trigger(struct snd_pcm_substream *substream,
+				       int cmd)
+{
+	struct mv88fx_snd_stream *audio_stream =
+				 snd_pcm_substream_chip(substream);
+	int result = 0;
+	unsigned int reg_data;
+
+	spin_lock(&chip->reg_lock);
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+		/* enable interrupt */
+		reg_data = readl(chip->base + MV_AUDIO_INT_MASK_REG);
+		reg_data |= AICR_PLAY_BYTES_INT;
+		writel(reg_data, chip->base + MV_AUDIO_INT_MASK_REG);
+
+		/* make sure the dma in pause state*/
+		reg_data = readl(chip->base +
+				 MV_AUDIO_PLAYBACK_CTRL_REG);
+		reg_data |= APCR_PLAY_PAUSE_MASK;
+		writel(reg_data, chip->base +
+				 MV_AUDIO_PLAYBACK_CTRL_REG);
+
+		/* enable dma */
+		if ((audio_stream->dig_mode & I2S) &&
+		    (chip->pcm_mode == PCM))
+			reg_data |= APCR_PLAY_I2S_ENABLE_MASK;
+
+		if (audio_stream->dig_mode & SPDIF)
+			reg_data |= APCR_PLAY_SPDIF_ENABLE_MASK;
+
+		/* start dma */
+		reg_data &= (~APCR_PLAY_PAUSE_MASK);
+		writel(reg_data, chip->base + MV_AUDIO_PLAYBACK_CTRL_REG);
+
+		break;
+
+	case SNDRV_PCM_TRIGGER_STOP:
+
+		/* disable interrupt */
+		reg_data = readl(chip->base + MV_AUDIO_INT_MASK_REG);
+		reg_data &= (~AICR_PLAY_BYTES_INT);
+		writel(reg_data, chip->base + MV_AUDIO_INT_MASK_REG);
+
+		/* make sure the dma in pause state*/
+		reg_data = readl(chip->base +
+				 MV_AUDIO_PLAYBACK_CTRL_REG);
+		reg_data |= APCR_PLAY_PAUSE_MASK;
+
+		/* always stop both I2S and SPDIF*/
+		reg_data &= (~(APCR_PLAY_I2S_ENABLE_MASK |
+			       APCR_PLAY_SPDIF_ENABLE_MASK));
+		writel(reg_data, chip->base +
+				 MV_AUDIO_PLAYBACK_CTRL_REG);
+
+		/* check if busy twice*/
+		while (readl(chip->base + MV_AUDIO_PLAYBACK_CTRL_REG) &
+		APCR_PLAY_BUSY_MASK)
+			cpu_relax();
+		while (readl(chip->base + MV_AUDIO_PLAYBACK_CTRL_REG) &
+		APCR_PLAY_BUSY_MASK)
+			cpu_relax();
+		break;
+
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+		reg_data = readl(chip->base +
+				 MV_AUDIO_PLAYBACK_CTRL_REG);
+		reg_data |= APCR_PLAY_PAUSE_MASK;
+		writel(reg_data, chip->base +
+				 MV_AUDIO_PLAYBACK_CTRL_REG);
+		break;
+
+	case SNDRV_PCM_TRIGGER_RESUME:
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+		reg_data = readl(chip->base +
+				 MV_AUDIO_PLAYBACK_CTRL_REG);
+		reg_data &= (~APCR_PLAY_PAUSE_MASK);
+		writel(reg_data, chip->base +
+				 MV_AUDIO_PLAYBACK_CTRL_REG);
+
+		break;
+
+	default:
+		result = -EINVAL;
+	}
+
+	spin_unlock(&chip->reg_lock);
+	return result;
+}
+
+
+static snd_pcm_uframes_t mv88fx_snd_playback_pointer(struct snd_pcm_substream
+						     *substream)
+{
+	return bytes_to_frames(substream->runtime,
+	(ssize_t)readl(chip->base + MV_AUDIO_PLAYBACK_BUFF_BYTE_CNTR_REG));
+}
+
+static int mv88fx_snd_playback_mmap(struct snd_pcm_substream *substream,
+			     struct vm_area_struct *vma)
+{
+	return devdma_mmap(NULL, substream, vma);
+}
+
+
+static struct snd_pcm_ops mv88fx_snd_playback_ops = {
+	.open      = mv88fx_snd_playback_open,
+	.close     = mv88fx_snd_playback_close,
+	.ioctl     = snd_pcm_lib_ioctl,
+	.hw_params = mv88fx_snd_playback_hw_params,
+	.hw_free   = mv88fx_snd_playback_hw_free,
+	.prepare   = mv88fx_snd_playback_prepare,
+	.trigger   = mv88fx_snd_playback_trigger,
+	.pointer   = mv88fx_snd_playback_pointer,
+	.mmap      = mv88fx_snd_playback_mmap,
+};
+
+static int __init mv88fx_snd_pcm_new(struct snd_card *card)
+{
+	struct snd_pcm *pcm;
+	struct mv88fx_snd_platform_data *pdata = card->dev->platform_data;
+	int err, i;
+
+	snd_printd("card->dev=0x%x\n", (unsigned int)card->dev);
+
+	err = snd_pcm_new(card, "Marvell mv88fx_snd IEC958 and I2S", 0, 1, 1,
+			  &pcm);
+	if (err < 0)
+		return err;
+
+	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
+			&mv88fx_snd_playback_ops);
+
+	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
+			&mv88fx_snd_capture_ops);
+
+	if ((pdata->i2s_play) && (pdata->spdif_play))
+		chip->stream_defaults[PLAYBACK]->dig_mode = (SPDIF | I2S);
+	else if (pdata->i2s_play)
+		chip->stream_defaults[PLAYBACK]->dig_mode = I2S;
+	else if (pdata->spdif_play)
+		chip->stream_defaults[PLAYBACK]->dig_mode = SPDIF;
+	else
+		chip->stream_defaults[PLAYBACK]->dig_mode = 0;
+
+	chip->stream_defaults[PLAYBACK]->mono_mode = MONO_BOTH;
+	chip->pcm_mode = PCM;
+	chip->stream_defaults[PLAYBACK]->stat_mem = 0;
+	chip->stream_defaults[PLAYBACK]->clock_src = DCO_CLOCK;
+
+	if (pdata->i2s_rec)
+		chip->stream_defaults[CAPTURE]->dig_mode = I2S;
+	else if (pdata->spdif_rec)
+		chip->stream_defaults[CAPTURE]->dig_mode = SPDIF;
+	else
+		chip->stream_defaults[CAPTURE]->dig_mode = 0;
+
+	chip->stream_defaults[CAPTURE]->mono_mode = MONO_LEFT;
+	chip->pcm_mode = PCM;
+	chip->stream_defaults[CAPTURE]->stat_mem = 0;
+	chip->stream_defaults[CAPTURE]->clock_src = DCO_CLOCK;
+
+	for (i = 0; i < 4; i++) {
+		chip->stream_defaults[PLAYBACK]->spdif_status[i] = 0;
+		chip->stream[PLAYBACK]->spdif_status[i] = 0;
+
+		writel(chip->stream_defaults[PLAYBACK]->spdif_status[i],
+		       chip->base + MV_AUDIO_SPDIF_PLAY_CH_STATUS_LEFT_REG(i));
+
+		writel(chip->stream_defaults[PLAYBACK]->spdif_status[i],
+		       chip->base + MV_AUDIO_SPDIF_PLAY_CH_STATUS_RIGHT_REG(i));
+
+		writel(0, chip->base +
+			  MV_AUDIO_SPDIF_PLAY_USR_BITS_LEFT_REG(i));
+
+		writel(0, chip->base +
+			  MV_AUDIO_SPDIF_PLAY_USR_BITS_RIGHT_REG(i));
+	}
+
+	pcm->private_data = chip;
+	pcm->info_flags = 0;
+	strcpy(pcm->name, "Marvell mv88fx_snd IEC958 and I2S");
+
+	return 0;
+}
+
+static irqreturn_t mv88fx_snd_interrupt(int irq, void *dev_id)
+{
+	struct mv88fx_snd_chip *chip = dev_id;
+	struct mv88fx_snd_stream *play_stream = chip->stream_defaults[PLAYBACK];
+	struct mv88fx_snd_stream *capture_stream =
+						chip->stream_defaults[CAPTURE];
+
+	unsigned int status, mask;
+
+	spin_lock(&chip->reg_lock);
+
+	/* read the active interrupt */
+	mask = readl(chip->base + MV_AUDIO_INT_MASK_REG);
+	status = readl(chip->base + MV_AUDIO_INT_CAUSE_REG) & mask;
+
+	do {
+		if (status & ~(AICR_RECORD_BYTES_INT|AICR_PLAY_BYTES_INT)) {
+			spin_unlock(&chip->reg_lock);
+			snd_BUG(); /* FIXME: should enable error interrupts*/
+			return IRQ_NONE;
+		}
+
+		/* acknowledge interrupt */
+		writel(status, chip->base + MV_AUDIO_INT_CAUSE_REG);
+
+		/* This is record event */
+		if (status & AICR_RECORD_BYTES_INT)
+			snd_pcm_period_elapsed(capture_stream->substream);
+
+		/* This is play event */
+		if (status & AICR_PLAY_BYTES_INT)
+			snd_pcm_period_elapsed(play_stream->substream);
+
+		/* read the active interrupt */
+		mask = readl(chip->base + MV_AUDIO_INT_MASK_REG);
+		status = readl(chip->base + MV_AUDIO_INT_CAUSE_REG) & mask;
+	} while (status);
+
+	spin_unlock(&chip->reg_lock);
+
+	return IRQ_HANDLED;
+}
+
+static void mv88fx_snd_free(struct snd_card *card)
+{
+	struct mv88fx_snd_chip *chip = card->private_data;
+
+	/* free irq */
+	free_irq(chip->irq, (void *)chip);
+
+	snd_printd("chip->res =0x%x\n", (unsigned int)chip->res);
+
+	if (chip->base)
+		iounmap(chip->base);
+
+	if (chip->res)
+		release_resource(chip->res);
+
+	chip->res = NULL;
+
+	/* Free memory allocated for streems */
+	if (chip->stream_defaults[PLAYBACK]->area)
+		dma_free_coherent(card->dev,
+			 MV88FX_SND_MAX_PERIODS * MV88FX_SND_MAX_PERIOD_BYTES,
+			 chip->stream_defaults[PLAYBACK]->area,
+			 chip->stream_defaults[PLAYBACK]->addr);
+
+	if (chip->stream_defaults[CAPTURE]->area)
+		dma_free_coherent(card->dev,
+			 MV88FX_SND_MAX_PERIODS * MV88FX_SND_MAX_PERIOD_BYTES,
+			 chip->stream_defaults[CAPTURE]->area,
+			 chip->stream_defaults[CAPTURE]->addr);
+
+	kfree(chip->stream_defaults[PLAYBACK]);
+	chip->stream_defaults[PLAYBACK] = NULL;
+
+	kfree(chip->stream[PLAYBACK]);
+	chip->stream[PLAYBACK] = NULL;
+
+	kfree(chip->stream_defaults[CAPTURE]);
+	chip->stream_defaults[CAPTURE] = NULL;
+
+	kfree(chip->stream[CAPTURE]);
+	chip->stream[CAPTURE] = NULL;
+
+	chip = NULL;
+}
+
+static int mv88fx_snd_probe(struct platform_device *dev)
+{
+	int err = 0, irq = NO_IRQ;
+	struct snd_card *card = NULL;
+	struct resource *r = NULL;
+	static struct snd_device_ops ops = {
+		.dev_free =	NULL,
+	};
+	struct mv88fx_snd_platform_data *pdata = NULL;
+
+	err = snd_card_create(-1, "mv88fx_snd", THIS_MODULE,
+		       sizeof(struct mv88fx_snd_chip), &card);
+
+	if (err) {
+		snd_printk("snd_card_create failed\n");
+		return err;
+	}
+
+	card->dev = &dev->dev;
+	chip = card->private_data;
+	card->private_free = mv88fx_snd_free;
+
+	pdata = (struct mv88fx_snd_platform_data *)dev->dev.platform_data;
+
+	if (pdata->i2s_rec == 2 || pdata->spdif_rec == 2)
+		chip->stereo = 1;
+	else
+		chip->stereo = 0;
+
+	chip->audio_offset = pdata->base_offset;
+
+	r = platform_get_resource(dev, IORESOURCE_MEM, 0);
+	if (!r) {
+		snd_printk("platform_get_resource failed\n");
+		err = -ENXIO;
+		goto error;
+	}
+
+	snd_printd("chip->res =0x%x\n", (unsigned int)chip->res);
+
+	r = request_mem_region(r->start, SZ_16K, MV88FX_AUDIO_NAME);
+	if (!r) {
+		snd_printk("request_mem_region failed\n");
+		err = -EBUSY;
+		goto error;
+	}
+	chip->res = r;
+
+	chip->base = ioremap(r->start, SZ_16K);
+
+	if (!chip->base) {
+		snd_printk("ioremap failed\n");
+		err = -ENOMEM;
+		goto error;
+	}
+
+	snd_printd("chip->base=0x%x r->start0x%x\n",
+			 (unsigned int)chip->base, r->start);
+
+	irq = platform_get_irq(dev, 0);
+	if (irq == NO_IRQ) {
+		snd_printk("platform_get_irq failed\n");
+		err = -ENXIO;
+		goto error;
+	}
+
+	snd_printd("card = 0x%x dev 0x%x\n",
+			 (unsigned int)card, (unsigned int)dev);
+	strncpy(card->driver, dev->dev.driver->name, sizeof(card->driver));
+
+	/* Allocate memory for our device */
+	chip->stream_defaults[PLAYBACK] =
+			  kzalloc(sizeof(struct mv88fx_snd_stream), GFP_KERNEL);
+
+	if (chip->stream_defaults[PLAYBACK] == NULL) {
+		snd_printk("kzalloc failed for default playback\n");
+		err = -ENOMEM;
+		goto error;
+	}
+
+	chip->stream_defaults[PLAYBACK]->direction = PLAYBACK;
+	chip->stream_defaults[PLAYBACK]->dev = card->dev;
+
+	chip->stream[PLAYBACK] = kzalloc(sizeof(struct mv88fx_snd_stream),
+					 GFP_KERNEL);
+
+	if (chip->stream[PLAYBACK] == NULL) {
+		snd_printk("kzalloc failed for runtime playback\n");
+		err = -ENOMEM;
+		goto error;
+	}
+
+	chip->stream_defaults[CAPTURE] =
+			 kzalloc(sizeof(struct mv88fx_snd_stream), GFP_KERNEL);
+
+	if (chip->stream_defaults[CAPTURE] == NULL) {
+		snd_printk("kzalloc failed for capture\n");
+		err = -ENOMEM;
+		goto error;
+	}
+
+	chip->stream_defaults[CAPTURE]->direction = CAPTURE;
+	chip->stream_defaults[CAPTURE]->dev = card->dev;
+
+	chip->stream[CAPTURE] = kzalloc(sizeof(struct mv88fx_snd_stream),
+					GFP_KERNEL);
+
+	if (chip->stream[CAPTURE] == NULL) {
+		snd_printk("kzalloc failed for runtime capture\n");
+		err = -ENOMEM;
+		goto error;
+	}
+
+	chip->irq = irq;
+	chip->stream_defaults[PLAYBACK]->area =
+	dma_alloc_coherent(&dev->dev,
+			   MV88FX_SND_MAX_PERIODS * MV88FX_SND_MAX_PERIOD_BYTES,
+			   &chip->stream_defaults[PLAYBACK]->addr,
+			   GFP_KERNEL);
+
+	if (!chip->stream_defaults[PLAYBACK]->area) {
+		snd_printk("dma_alloc_coherent failed for playback buffer\n");
+		err = -ENOMEM;
+		goto error;
+	}
+
+	if (0 == test_memory(pdata->dram,
+	  (unsigned int)chip->stream_defaults[PLAYBACK]->addr,
+	  (unsigned int)MV88FX_SND_MAX_PERIODS * MV88FX_SND_MAX_PERIOD_BYTES)) {
+
+		snd_printk("error: playback buffer not in one memory window\n");
+		err = -ENOMEM;
+		goto error;
+	}
+
+	chip->stream_defaults[CAPTURE]->area =
+	dma_alloc_coherent(&dev->dev,
+			   MV88FX_SND_MAX_PERIODS * MV88FX_SND_MAX_PERIOD_BYTES,
+			   &chip->stream_defaults[CAPTURE]->addr,
+			   GFP_KERNEL);
+
+	if (!chip->stream_defaults[CAPTURE]->area) {
+		snd_printk("dma_alloc_coherent failed for capture buffer\n");
+		err = -ENOMEM;
+		goto error;
+	}
+
+	if (0 == test_memory(pdata->dram,
+	  (unsigned int)chip->stream_defaults[CAPTURE]->addr,
+	  (unsigned int)MV88FX_SND_MAX_PERIODS * MV88FX_SND_MAX_PERIOD_BYTES)) {
+
+		snd_printk("error: playback buffer not in one memory window\n");
+		err = -ENOMEM;
+		goto error;
+	}
+
+	if (request_irq(chip->irq, mv88fx_snd_interrupt, 0, MV88FX_AUDIO_NAME,
+	    (void *)chip)) {
+
+		snd_printk("Unable to grab IRQ %d\n", chip->irq);
+		err = -ENOMEM;
+		goto error;
+	}
+
+	chip->ch_stat_valid = 1;
+	chip->burst = 128;
+	chip->loopback = 0;
+	chip->dco_ctrl_offst = 0x800;
+
+	err = mv88fx_snd_hw_init(card);
+	if (err) {
+		snd_printk("mv88fx_snd_hw_init failed\n");
+		err = -ENOMEM;
+		goto error;
+	}
+
+	/* Set default values */
+	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
+	if (err < 0) {
+		snd_printk("Creating chip device failed.\n");
+		err = -ENOMEM;
+		goto error;
+	}
+
+	/* create pcm devices */
+	err = mv88fx_snd_pcm_new(card);
+	if (err < 0) {
+		snd_printk("Creating PCM device failed.\n");
+		err = -ENOMEM;
+		goto error;
+	}
+	/* create controll interfaces & switches */
+	err = mv88fx_snd_ctrl_new(card);
+	if (err < 0) {
+		snd_printk("Creating non-PCM device failed.\n");
+		err = -ENOMEM;
+		goto error;
+	}
+
+	strcpy(card->driver, "mv88fx_snd");
+	strcpy(card->shortname, "Marvell mv88fx_snd");
+	sprintf(card->longname, "Marvell mv88fx_snd ALSA driver");
+
+	err = snd_card_register(card);
+	if (err < 0) {
+		snd_printk("Card registeration failed.\n");
+		err = -ENOMEM;
+		goto error;
+	}
+
+	/* if (dma_set_mask(&dev->dev, 0xFFFFFFUL) < 0) { */
+	if (dma_set_mask(&dev->dev, 0xFFFFFFFFUL) < 0) {
+		snd_printk("Could not set DMA mask\n");
+		goto error;
+	}
+
+	platform_set_drvdata(dev, card);
+	return 0;
+error:
+	if (card)
+		snd_card_free(card);
+	platform_set_drvdata(dev, NULL);
+	return err;
+}
+
+static int mv88fx_snd_remove(struct platform_device *dev)
+{
+	struct snd_card *card = platform_get_drvdata(dev);
+
+	if (card)
+		snd_card_free(card);
+
+	/* FIXME: Once "../codecs/cs42l51.c" is fixed to behave as a module
+	 *        this should be removed */
+	codec_del_i2c_device();
+
+	platform_set_drvdata(dev, NULL);
+	return 0;
+}
+
+#define mv88fx_snd_resume     NULL
+#define mv88fx_snd_suspend    NULL
+
+static struct platform_driver mv88fx_snd_driver = {
+	.probe   = mv88fx_snd_probe,
+	.remove  = mv88fx_snd_remove,
+	.suspend = mv88fx_snd_suspend,
+	.resume  = mv88fx_snd_resume,
+	.driver  = { .name = MV88FX_AUDIO_NAME,},
+};
+
+static int __init mv88fx_snd_init(void)
+{
+	return platform_driver_register(&mv88fx_snd_driver);
+}
+
+static void __exit mv88fx_snd_exit(void)
+{
+	platform_driver_unregister(&mv88fx_snd_driver);
+}
+
+MODULE_AUTHOR("Maen Suleiman <maen@marvell.com>");
+MODULE_DESCRIPTION("Marvell MV88Fx Alsa Sound driver");
+MODULE_LICENSE("GPL");
+
+module_init(mv88fx_snd_init);
+module_exit(mv88fx_snd_exit);
+
-- 
1.6.5.2