summaryrefslogtreecommitdiffstats
path: root/meta/recipes-kernel/linux/linux-netbook-2.6.33.2/linux-2.6.34-moorestown-audio-driver-6.0-1-8.patch
blob: 795bf1a3b650ce35cd21f1fae7055c4f0259c216 (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
From c3cccfca9868aaf6e67a77c46a859a18d6384492 Mon Sep 17 00:00:00 2001
From: R, Dharageswari <dharageswari.r@intel.com>
Date: Thu, 29 Apr 2010 20:14:06 +0530
Subject: [PATCH] ADR-Post-Beta-0.05.002.03-1/8-Adding Moorestown Audio Drivers - SST driver

This patch is the first patch in the series of eight patches which add up SST
driver and MAD driver. The SST driver is a driver for the SST DSP engine.This
patch adds the SST driver main file intel_sst.c which contains the init, exit,
probe, interrupt routine, as well as PCI suspend and resume implementations.
intel_sst_dsp.c file implements the SST FW initialization as well as FW and
library download steps.This patch also contains the intel_lpe.h header file
which is placed in include folder for MAD driver (ALSA Sound card driver for
Moorestown given in patch 7/8) to use. This file contains the definition of
interfaces exposed by SST drivers along with definition of all the controls
for the sound card to be used by MAD Driver

Signed-off-by: Vinod Koul <vinod.koul@intel.com>

	new file:   include/sound/intel_lpe.h
	new file:   sound/pci/sst/intel_sst.c
	new file:   sound/pci/sst/intel_sst_dsp.c
Patch-mainline: 2.6.35?
---
 include/sound/intel_lpe.h     |  148 +++++++++
 sound/pci/sst/intel_sst.c     |  527 ++++++++++++++++++++++++++++++
 sound/pci/sst/intel_sst_dsp.c |  706 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1381 insertions(+), 0 deletions(-)
 create mode 100644 include/sound/intel_lpe.h
 create mode 100644 sound/pci/sst/intel_sst.c
 create mode 100644 sound/pci/sst/intel_sst_dsp.c

diff --git a/include/sound/intel_lpe.h b/include/sound/intel_lpe.h
new file mode 100644
index 0000000..70e7a1f
--- /dev/null
+++ b/include/sound/intel_lpe.h
@@ -0,0 +1,148 @@
+#ifndef __INTEL_SST_H__
+#define __INTEL_SST_H__
+/*
+ *  intel_lpe.h - Intel SST Driver for audio engine
+ *
+ *  Copyright (C) 2008-10 	Intel Corporation
+ *  Authors:	Vinod Koul <vinod.koul@intel.com>
+ *  			Harsha Priya <priya.harsha@intel.com>
+ *				Dharageswari R <dharageswari.r@intel.com>
+ *				KP Jeeja <jeeja.kp@intel.com>
+ *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This driver exposes the audio engine functionalities to the ALSA
+ *	and middleware.
+ *  This file is shared between the SST and MAD drivers
+ */
+
+#define SST_CARD_NAMES "intel_mid_card"
+
+/* control list Pmic & Lpe */
+/* Input controls */
+enum port_status {
+	ACTIVATE = 1,
+	DEACTIVATE,
+};
+
+/* Card states */
+enum sst_card_states {
+	SND_CARD_UN_INIT = 0,
+	SND_CARD_INIT_DONE,
+};
+
+enum sst_controls {
+	SST_SND_ALLOC =			0x1000,
+	SST_SND_PAUSE =			0x1001,
+	SST_SND_RESUME =		0x1002,
+	SST_SND_DROP =			0x1003,
+	SST_SND_FREE =			0x1004,
+	SST_SND_BUFFER_POINTER =	0x1005,
+	SST_SND_STREAM_INIT =		0x1006,
+	SST_SND_START	 =		0x1007,
+	SST_SND_STREAM_PROCESS = 	0x1008,
+	SST_MAX_CONTROLS =		0x1008,
+	SST_CONTROL_BASE =		0x1000,
+	SST_ENABLE_RX_TIME_SLOT = 0x1009,
+
+};
+
+struct pcm_stream_info {
+	int str_id;
+	void *mad_substream;
+	void (*period_elapsed) (void *mad_substream);
+	unsigned long long buffer_ptr;
+	int sfreq;
+};
+
+struct stream_buffer {
+	unsigned long	addr;
+	int		length;
+};
+
+static inline long sst_get_time(void)
+{
+	 struct timeval t;
+	 do_gettimeofday(&t);
+	 return t.tv_usec;
+}
+
+#ifndef CONFIG_SND_AUDIO_DBG_PRINT
+#define printk(format, arg...) do {} while (0);
+#endif
+
+struct snd_pmic_ops {
+	int card_status;
+	int num_channel;
+	int input_dev_id;
+	int mute_status;
+	int output_dev_id;
+	int (*set_input_dev) (u8 value);
+	int (*set_output_dev) (u8 value);
+
+	int (*set_mute) (int dev_id, u8 value);
+	int (*get_mute) (int dev_id, u8 *value);
+
+	int (*set_vol) (int dev_id, u8 value);
+	int (*get_vol) (int dev_id, u8 *value);
+
+	int (*init_card) (void);
+	int (*set_pcm_audio_params) (int sfreq, int word_size ,int num_channel);
+	int (*set_pcm_voice_params) (void);
+	int (*set_voice_port) (int status);
+	int (*set_audio_port) (int status);
+
+	int (*power_up_pmic_pb) (unsigned int port);
+	int (*power_up_pmic_cp) (unsigned int port);
+	int (*power_down_pmic_pb) (void);
+	int (*power_down_pmic_cp) (void);
+	int (*power_down_pmic) (void);
+};
+
+struct intel_sst_card_ops {
+	char *module_name;
+	int  vendor_id;
+	int (*control_set) (int control_element, void *value);
+	int (*send_buffer) (int str_id, struct stream_buffer *mad_buf);
+	struct snd_pmic_ops *scard_ops;
+};
+
+/* periphral interrupt interface */
+enum lpe_periphral {
+	LPE_DMA = 1,
+	LPE_SSP0,
+	LPE_SSP1
+};
+
+/* modified for generic access */
+struct sc_reg_access {
+	u16 reg_addr;
+	u8 value;
+	u8 mask;
+};
+enum sc_reg_access_type {
+	PMIC_READ = 0,
+	PMIC_WRITE,
+	PMIC_READ_MODIFY,
+};
+
+int register_sst_card(struct intel_sst_card_ops *card);
+void unregister_sst_card(struct intel_sst_card_ops *card);
+int lpe_mask_periphral_intr(enum lpe_periphral device);
+int lpe_unmask_periphral_intr(enum lpe_periphral device);
+int lpe_periphral_intr_status(enum lpe_periphral device, int *status);
+#endif /* __INTEL_SST_H__ */
diff --git a/sound/pci/sst/intel_sst.c b/sound/pci/sst/intel_sst.c
new file mode 100644
index 0000000..c6e68b8
--- /dev/null
+++ b/sound/pci/sst/intel_sst.c
@@ -0,0 +1,527 @@
+/*
+ *  intel_sst.c - Intel SST Driver for audio engine
+ *
+ *  Copyright (C) 2008-10	Intel Corp
+ *  Authors:	Vinod Koul <vinod.koul@intel.com>
+ *				Harsha Priya <priya.harsha@intel.com>
+ *				Dharageswari R <dharageswari.r@intel.com>
+ *				KP Jeeja <jeeja.kp@intel.com>
+ *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This driver exposes the audio engine functionalities to the ALSA
+ * 	 and middleware.
+ *
+ *  This file contains all init functions
+ */
+
+#include <linux/cdev.h>
+#include <linux/pci.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/syscalls.h>
+#include <linux/fs.h>
+#include <linux/file.h>
+#include <linux/interrupt.h>
+#include <linux/list.h>
+#include <linux/workqueue.h>
+#include <linux/firmware.h>
+#include <linux/mutex.h>
+#include <linux/delay.h>
+#include <linux/sched.h>
+#ifdef CONFIG_MSTWN_POWER_MGMT
+#include <linux/intel_mid.h>
+#endif
+#include <sound/intel_lpe.h>
+#include <sound/intel_sst_ioctl.h>
+#include "intel_sst_fw_ipc.h"
+#include "intel_sst_common.h"
+
+
+MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
+MODULE_DESCRIPTION("Intel (R) Moorestown Audio Engine Driver");
+MODULE_LICENSE("GPL v2");
+MODULE_VERSION(SST_DRIVER_VERSION);
+
+struct intel_sst_drv *sst_drv_ctx;
+
+/* fops Routines */
+static const struct file_operations intel_sst_fops = {
+	.owner = THIS_MODULE,
+	.open = intel_sst_open,
+	.release = intel_sst_release,
+	.read = intel_sst_read,
+	.write = intel_sst_write,
+	.ioctl = intel_sst_ioctl,
+	.mmap = intel_sst_mmap,
+	.aio_read = intel_sst_aio_read,
+	.aio_write = intel_sst_aio_write,
+};
+
+spinlock_t pe_slock;
+unsigned int pe_inprogress = 0;
+
+/**
+* intel_sst_interrupt - Interrupt service routine for SST
+* @irq:		irq number of interrupt
+* @dev_id:	pointer to device structre
+*
+* This function is called by OS when SST device raises
+* an interrupt. This will be result of write in IPC register
+* Source can be busy or done interrupt
+*/
+static irqreturn_t intel_sst_interrupt(int irq, void *context)
+{
+	union interrupt_reg 	isr;
+	union ipc_header 	header;
+	union  interrupt_reg imr;
+	struct intel_sst_drv *drv = (struct intel_sst_drv *) context;
+	unsigned int size = 0;
+	int str_id;
+        struct stream_info *stream ;
+
+
+	/* Interrupt arrived, check src */
+	isr.full = readl(drv->shim + SST_ISRX);
+
+	if (isr.part.busy_interrupt) {
+		header.full = readl(drv->shim + SST_IPCD);
+		if (header.part.large)
+			size = header.part.data;
+		if (header.part.msg_id & REPLY_MSG) {
+			sst_drv_ctx->ipc_process_msg.header = header;
+
+			if (header.part.msg_id == IPC_SST_PERIOD_ELAPSED) {
+		   	  	sst_clear_interrupt();
+
+                                /*spin_lock(&pe_slock);*/
+                                if (pe_inprogress == 1) {
+                                        /*spin_unlock(&pe_slock);*/
+                                        return IRQ_HANDLED;
+                                }
+
+                                pe_inprogress = 1;
+                                //spin_unlock(&pe_slock);
+
+			        str_id = header.part.str_id;
+                                stream = &sst_drv_ctx->streams[str_id];
+				if (stream->period_elapsed)
+					stream->period_elapsed(stream->pcm_substream);
+                                //spin_lock(&pe_slock);
+                                pe_inprogress = 0;
+                                //spin_unlock(&pe_slock);
+				return IRQ_HANDLED;
+			} else {
+				memcpy_fromio(sst_drv_ctx->ipc_process_msg.mailbox,
+					drv->mailbox + SST_MAILBOX_RCV, size);
+				queue_work(sst_drv_ctx->process_msg_wq,
+					&sst_drv_ctx->ipc_process_msg.wq);
+			}
+		} else {
+			sst_drv_ctx->ipc_process_reply.header = header;
+			memcpy_fromio(sst_drv_ctx->ipc_process_reply.mailbox,
+				drv->mailbox + SST_MAILBOX_RCV, size);
+			queue_work(sst_drv_ctx->process_reply_wq,
+					&sst_drv_ctx->ipc_process_reply.wq);
+		}
+		/* mask busy inetrrupt */
+		imr.full = readl(drv->shim + SST_IMRX);
+		imr.part.busy_interrupt = 1;
+		/* dummy register for shim workaround */
+		writel(imr.full, sst_drv_ctx->shim + SST_ISRD);
+		writel(imr.full, drv->shim + SST_IMRX);
+		return IRQ_HANDLED;
+	} else if (isr.part.done_interrupt) {
+		/* Clear done bit */
+		header.full = readl(drv->shim + SST_IPCX);
+		header.part.done = 0;
+		/* dummy register for shim workaround */
+		writel(header.full, sst_drv_ctx->shim + SST_ISRD);
+		writel(header.full, drv->shim + SST_IPCX);
+		/* write 1 to clear status register */;
+		isr.part.done_interrupt = 1;
+		/* dummy register for shim workaround */
+		writel(isr.full, sst_drv_ctx->shim + SST_ISRD);
+		writel(isr.full, drv->shim + SST_ISRX);
+		queue_work(sst_drv_ctx->post_msg_wq,
+			&sst_drv_ctx->ipc_post_msg.wq);
+		return IRQ_HANDLED;
+	} else
+		return IRQ_NONE;
+
+}
+
+
+/* PCI Routines */
+
+static struct pci_device_id intel_sst_ids[] = {
+	{ 0x8086, 0x080A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+	{ 0, }
+};
+MODULE_DEVICE_TABLE(pci, intel_sst_ids);
+
+
+/*
+* intel_sst_probe - PCI probe function
+* @pci:	PCI device structure
+* @pci_id:	PCI device ID structure
+*
+* This function is called by OS when a device is found
+* This enables the device, interrupt etc
+*/
+static int __devinit intel_sst_probe(struct pci_dev *pci,
+			const struct pci_device_id *pci_id)
+{
+	int i, ret = 0;
+	static struct mutex drv_ctx_lock;
+	mutex_init(&drv_ctx_lock);
+
+	mutex_lock(&drv_ctx_lock);
+	if (sst_drv_ctx) {
+		printk(KERN_ERR
+		"SST ERR: Only one sst handle is supported\n");
+		mutex_unlock(&drv_ctx_lock);
+		return -EBUSY;
+	}
+
+	sst_drv_ctx = kzalloc(sizeof(*sst_drv_ctx), GFP_KERNEL);
+	if (!sst_drv_ctx) {
+		printk(KERN_ERR
+		"SST ERR: intel_sst malloc fail\n");
+			mutex_unlock(&drv_ctx_lock);
+		return -ENOMEM;
+	}
+	mutex_unlock(&drv_ctx_lock);
+
+	mutex_init(&sst_drv_ctx->stream_cnt_lock);
+	sst_drv_ctx->pmic_state = SND_MAD_UN_INIT;
+
+	mutex_lock(&sst_drv_ctx->stream_cnt_lock);
+	sst_drv_ctx->stream_cnt = 0;
+	sst_drv_ctx->encoded_cnt = 0;
+	sst_drv_ctx->am_cnt = 0;
+	mutex_unlock(&sst_drv_ctx->stream_cnt_lock);
+	sst_drv_ctx->pb_streams = 0;
+	sst_drv_ctx->cp_streams = 0;
+	sst_drv_ctx->unique_id = 0;
+	sst_drv_ctx->pmic_port_instance = SST_DEFAULT_PMIC_PORT;
+
+	INIT_LIST_HEAD(&sst_drv_ctx->ipc_dispatch_list);
+	INIT_WORK(&sst_drv_ctx->ipc_post_msg.wq, sst_post_message);
+	INIT_WORK(&sst_drv_ctx->ipc_process_msg.wq, sst_process_message);
+	INIT_WORK(&sst_drv_ctx->ipc_process_reply.wq, sst_process_reply);
+	INIT_WORK(&sst_drv_ctx->mad_ops.wq, sst_process_mad_ops);
+	init_waitqueue_head(&sst_drv_ctx->wait_queue);
+
+	sst_drv_ctx->mad_wq = create_workqueue("sst_mad_wq");
+	if (!sst_drv_ctx->mad_wq)
+		goto do_free_drv_ctx;
+	sst_drv_ctx->post_msg_wq = create_workqueue("sst_post_msg_wq");
+	if (!sst_drv_ctx->post_msg_wq)
+		goto free_mad_wq;
+	sst_drv_ctx->process_msg_wq = create_workqueue("sst_process_msg_wqq");
+	if (!sst_drv_ctx->process_msg_wq)
+		goto free_post_msg_wq;
+	sst_drv_ctx->process_reply_wq = create_workqueue("sst_proces_reply_wq");
+	if (!sst_drv_ctx->process_reply_wq)
+		goto free_process_msg_wq;
+
+	for (i = 0; i < MAX_ACTIVE_STREAM; i++) {
+		sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
+		sst_drv_ctx->alloc_block[i].ops_block.condition = false;
+	}
+	mutex_init(&sst_drv_ctx->list_lock);
+
+	for (i = 1; i < MAX_NUM_STREAMS; i++) {
+		struct stream_info *stream = &sst_drv_ctx->streams[i];
+		INIT_LIST_HEAD(&stream->bufs);
+		mutex_init(&stream->lock);
+		spin_lock_init(&stream->pcm_lock);
+	}
+	sst_drv_ctx->mmap_mem = NULL;
+	sst_drv_ctx->mmap_len = SST_MMAP_PAGES * PAGE_SIZE;
+	while (sst_drv_ctx->mmap_len > 0) {
+		sst_drv_ctx->mmap_mem =
+			kzalloc(sst_drv_ctx->mmap_len, GFP_KERNEL);
+		if (sst_drv_ctx->mmap_mem) {
+			printk(KERN_DEBUG "SST DBG:Got memory %p size 0x%x \n",
+				sst_drv_ctx->mmap_mem,
+				sst_drv_ctx->mmap_len);
+			break;
+		}
+		sst_drv_ctx->mmap_len -= (SST_MMAP_STEP * PAGE_SIZE);
+		if (sst_drv_ctx->mmap_len <= 0) {
+			printk(KERN_ERR
+			"SST ERR: Couldnt get any +\
+			mem...abort!!\n");
+			ret = -ENOMEM;
+			goto free_process_reply_wq;
+		}
+		printk(KERN_DEBUG "SST DBG:Failed...trying %d\n", \
+		sst_drv_ctx->mmap_len);
+	}
+
+	/* Init the device */
+	ret = pci_enable_device(pci);
+	if (ret) {
+		printk(KERN_ERR
+		"SST ERR: device cant be enabled\n");
+		goto do_free_mem;
+	}
+	sst_drv_ctx->pci = pci_dev_get(pci);
+	ret = pci_request_regions(pci, SST_DRV_NAME);
+	if (ret)
+		goto do_disable_device;
+	/* map registers */
+	/* SST Shim */
+	sst_drv_ctx->shim_phy_add =
+			(unsigned long) pci_resource_start(pci, 1);
+	sst_drv_ctx->shim = pci_ioremap_bar(pci, 1);
+	if (!sst_drv_ctx->shim)
+		goto do_release_regions;
+	printk(KERN_DEBUG "SST DBG:SST Shim Ptr %p \n", sst_drv_ctx->shim);
+
+	/* Shared SRAM */
+	sst_drv_ctx->mailbox = pci_ioremap_bar(pci, 2);
+	if (!sst_drv_ctx->mailbox)
+		goto do_unmap_shim;
+	printk(KERN_DEBUG "SST DBG:SRAM Ptr %p \n", sst_drv_ctx->mailbox);
+
+	/* IRAM */
+	sst_drv_ctx->iram = pci_ioremap_bar(pci, 3);
+	if (!sst_drv_ctx->iram)
+		goto do_unmap_sram;
+	printk(KERN_DEBUG "SST DBG:IRAM Ptr %p \n", sst_drv_ctx->iram);
+
+	/* DRAM */
+	sst_drv_ctx->dram = pci_ioremap_bar(pci, 4);
+	if (!sst_drv_ctx->dram)
+		goto do_unmap_iram;
+	printk(KERN_DEBUG "SST DBG:DRAM Ptr %p \n", sst_drv_ctx->dram);
+
+	sst_drv_ctx->sst_state = SST_UN_INIT;
+	/* Register the ISR */
+	ret = request_irq(pci->irq, intel_sst_interrupt,
+		IRQF_SHARED, SST_DRV_NAME, sst_drv_ctx);
+	if (ret)
+		goto do_unmap_dram;
+	printk(KERN_DEBUG "SST DBG:Registered IRQ 0x%x\n", pci->irq);
+
+	/* Register with /dev */
+	ret = register_chrdev(INTEL_SST_MAJOR, SST_DRV_NAME, &intel_sst_fops);
+	if (ret) {
+		printk(KERN_ERR
+		"SST ERR: couldn't register +\
+		device number\n");
+		goto do_free_irq;
+	}
+
+    sst_drv_ctx->lpe_stalled = 0;
+	printk(KERN_DEBUG "SST DBG:...successfully done!!!\n");
+	return ret;
+
+do_free_irq:
+	free_irq(pci->irq, sst_drv_ctx);
+do_unmap_dram:
+	iounmap(sst_drv_ctx->dram);
+do_unmap_iram:
+	iounmap(sst_drv_ctx->iram);
+do_unmap_sram:
+	iounmap(sst_drv_ctx->mailbox);
+do_unmap_shim:
+	iounmap(sst_drv_ctx->shim);
+do_release_regions:
+	pci_release_regions(pci);
+do_disable_device:
+	pci_disable_device(pci);
+do_free_mem:
+	kfree(sst_drv_ctx->mmap_mem);
+free_process_reply_wq:
+	destroy_workqueue(sst_drv_ctx->process_reply_wq);
+free_process_msg_wq:
+	destroy_workqueue(sst_drv_ctx->process_msg_wq);
+free_post_msg_wq:
+	destroy_workqueue(sst_drv_ctx->post_msg_wq);
+free_mad_wq:
+	destroy_workqueue(sst_drv_ctx->mad_wq);
+do_free_drv_ctx:
+	kfree(sst_drv_ctx);
+	printk(KERN_ERR
+	"SST ERR: Probe failed with 0x%x \n", ret);
+	return ret;
+}
+
+/**
+* intel_sst_remove - PCI remove function
+* @pci:		PCI device structure
+*
+* This function is called by OS when a device is unloaded
+* This frees the interrupt etc
+*/
+static void __devexit intel_sst_remove(struct pci_dev *pci)
+{
+	pci_dev_put(sst_drv_ctx->pci);
+	sst_drv_ctx->sst_state = SST_UN_INIT;
+	unregister_chrdev(INTEL_SST_MAJOR, SST_DRV_NAME);
+	free_irq(pci->irq, sst_drv_ctx);
+	iounmap(sst_drv_ctx->dram);
+	iounmap(sst_drv_ctx->iram);
+	iounmap(sst_drv_ctx->mailbox);
+	iounmap(sst_drv_ctx->shim);
+	sst_drv_ctx->pmic_state = SND_MAD_UN_INIT;
+	kfree(sst_drv_ctx->mmap_mem);
+	destroy_workqueue(sst_drv_ctx->process_reply_wq);
+	destroy_workqueue(sst_drv_ctx->process_msg_wq);
+	destroy_workqueue(sst_drv_ctx->post_msg_wq);
+	destroy_workqueue(sst_drv_ctx->mad_wq);
+	kfree(sst_drv_ctx);
+	pci_release_region(pci, 2);
+	pci_release_region(pci, 3);
+	pci_release_region(pci, 4);
+	pci_release_region(pci, 5);
+	pci_set_drvdata(pci, NULL);
+}
+
+/* Power Management */
+
+/**
+* intel_sst_suspend - PCI suspend function
+* @pci:		PCI device structure
+* @state:	PM message
+*
+* This function is called by OS when a power event occurs
+*/
+static int intel_sst_suspend(struct pci_dev *pci, pm_message_t state)
+{
+	int i;
+	printk(KERN_DEBUG "SST DBG:intel_sst_suspend called\n");
+
+	/* Pause all running streams */
+	for (i = 1; i < MAX_NUM_STREAMS; i++) {
+		if (sst_drv_ctx->streams[i].status == STREAM_RUNNING) {
+			sst_drv_ctx->active_streams[i] = true;
+			sst_pause_stream(i);
+		} else
+			sst_drv_ctx->active_streams[i] = false;
+	}
+
+	pci_set_drvdata(pci, sst_drv_ctx);
+
+	/* Send msg to FW FIXME */
+
+	/* Disable everything */
+	/* free_irq(pci->irq, sst_drv_ctx); */
+	pci_disable_device(pci);
+	pci_save_state(pci);
+	pci_set_power_state(pci, pci_choose_state(pci, state));
+	return 0;
+}
+
+/**
+* intel_sst_resume - PCI resume function
+* @pci:		PCI device structure
+* @state:	PM message
+*
+* This function is called by OS when a power event occurs
+*/
+static int intel_sst_resume(struct pci_dev *pci)
+{
+	int i;
+
+	printk(KERN_DEBUG "SST DBG:\nintel_sst_resume called\n");
+	sst_drv_ctx = pci_get_drvdata(pci);
+	if (pci->irq)
+		printk(KERN_DEBUG "SST DBG:irq %d \n", pci->irq);
+
+	pci_set_power_state(pci, PCI_D0);
+	pci_restore_state(pci);
+
+	/* ret = request_irq(pci->irq, intel_sst_interrupt,
+		IRQF_SHARED, "intel_sst_engine", sst_drv_ctx);
+	if (ret) {
+		return ret;
+	} */
+
+	/* Send msg to FW FIXME */
+
+	/* Start all paused streams */
+	for (i = 1; i < MAX_NUM_STREAMS; i++) {
+		if (sst_drv_ctx->active_streams[i] == true)
+			sst_resume_stream(i);
+	}
+	return 0;
+}
+
+
+static struct pci_driver driver = {
+	.name = SST_DRV_NAME,
+	.id_table = intel_sst_ids,
+	.probe = intel_sst_probe,
+	.remove = __devexit_p(intel_sst_remove),
+	.suspend = intel_sst_suspend,
+	.resume = intel_sst_resume,
+};
+
+/**
+* intel_sst_init - Module init function
+*
+* Registers with PCI
+* Registers with /dev
+*Init all data strutures
+*/
+static int __init intel_sst_init(void)
+{
+	/* Init all variables, data structure etc....*/
+	int ret = 0;
+	printk(KERN_ERR
+	"INFO: ******** SST DRIVER +\
+	loading.. Ver: %s\n", SST_DRIVER_VERSION);
+
+	/* Register with PCI */
+	ret = pci_register_driver(&driver);
+	if (ret)
+		printk(KERN_ERR
+		"SST ERR: PCI register failed \n");
+	sst_spi_mode_enable();
+	return ret;
+}
+
+/**
+* intel_sst_exit - Module exit function
+*
+* Unregisters with PCI
+* Unregisters with /dev
+* Frees all data strutures
+*/
+static void __exit intel_sst_exit(void)
+{
+	int i;
+
+	for (i = 0; i < MAX_NUM_STREAMS; i++)
+		sst_free_stream(i);
+
+	/* Send msg to FW TBD */
+	pci_unregister_driver(&driver);
+
+	flush_scheduled_work();
+	printk(KERN_DEBUG "SST DBG:...unloaded\n");
+	return;
+}
+
+module_init(intel_sst_init);
+module_exit(intel_sst_exit);
diff --git a/sound/pci/sst/intel_sst_dsp.c b/sound/pci/sst/intel_sst_dsp.c
new file mode 100644
index 0000000..bc78918
--- /dev/null
+++ b/sound/pci/sst/intel_sst_dsp.c
@@ -0,0 +1,706 @@
+/*
+ *  intel_sst_dsp.h - Intel SST Driver for audio engine
+ *
+ *  Copyright (C) 2008-10	Intel Corp
+ *  Authors:	Vinod Koul <vinod.koul@intel.com>
+ *				Harsha Priya <priya.harsha@intel.com>
+ *				Dharageswari R <dharageswari.r@intel.com>
+ *				KP Jeeja <jeeja.kp@intel.com>
+ *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This driver exposes the audio engine functionalities to the ALSA
+ * 	 and middleware.
+ *
+ *  This file contains all dsp controlling functions like firmware download,
+ * setting/resetting dsp cores, etc
+ */
+#include <linux/cdev.h>
+#include <linux/pci.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/syscalls.h>
+#include <linux/fs.h>
+#include <linux/file.h>
+#include <linux/interrupt.h>
+#include <linux/list.h>
+#include <linux/workqueue.h>
+#include <linux/firmware.h>
+#include <linux/mutex.h>
+#include <linux/delay.h>
+#include <linux/sched.h>
+#include <asm/ipc_defs.h>
+#include <sound/intel_lpe.h>
+#include <sound/intel_sst_ioctl.h>
+#include "intel_sst_fw_ipc.h"
+#include "intel_sst_common.h"
+
+
+MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
+MODULE_DESCRIPTION("Intel (R) Moorestown Audio Engine Driver");
+MODULE_LICENSE("GPL v2");
+MODULE_VERSION(SST_DRIVER_VERSION);
+
+/**
+* this function writes registers through SCU IPC
+*/
+static int sst_scu_ipc_write(u32 addr, u32 value)
+{
+	int retval = 0, retry = 3;
+	struct ipc_reg_data ipc_reg = {0};
+
+	ipc_reg.address = addr;
+	ipc_reg.data = value;
+	ipc_reg.ioc = 1;
+
+	while (retry) {
+		retval = mrst_ipc_write32(&ipc_reg);
+		if (!retval)
+			break;
+		retry--;
+		/* error */
+		printk(KERN_ERR "SST ERR: IPC +\
+			write failed %x\n", retval);
+	}
+	return retval;
+}
+
+/**
+* this function reads registers through SCU IPC
+*/
+static int sst_scu_ipc_read(u32 addr, u32 *value)
+{
+	int retval = 0, retry = 3;
+	struct ipc_reg_data ipc_reg = {0};
+
+	ipc_reg.address = addr;
+	ipc_reg.data = 0;
+	ipc_reg.ioc = 1;
+
+	while (retry) {
+		retval = mrst_ipc_read32(&ipc_reg);
+		if (!retval)
+			break;
+		retry--;
+		printk(KERN_ERR
+			"SST ERR: IPC read failed %x\n ", retval);
+	}
+	*value = ipc_reg.data;
+	printk(KERN_DEBUG "SST DBG:The read value +\
+		from the mrst_ipc is ::0x%08x\n", *value);
+	return retval;
+}
+/**
+* Resetting SST DSP
+*/
+static int intel_sst_reset_dsp(void)
+{
+	union config_status_reg csr;
+	int retval;
+	unsigned int value = 0;
+
+	retval = sst_scu_ipc_read(CHIP_REV_REG, &value);
+	if (retval)
+		return retval;
+
+#if 0
+	/* A2-CHANGES */
+	if (((value & CHIP_REV_ADDR) >> 3) == CHIP_REV_A1) {
+		sst_drv_ctx->chip_rev_id = CHIP_A1_50;
+	/* SCU FW Changes*/
+		retval = sst_scu_ipc_write(AUD_SHIM_BASE_ADDR,
+				AUD_SHIM_RATIO_1_1);
+	} else {
+		if (DSP_CLOCK_SPEED == CLK_100MHZ) {
+			sst_drv_ctx->chip_rev_id = CHIP_A2_100;
+	/* SCU FW Changes*/
+			retval = sst_scu_ipc_write(AUD_SHIM_BASE_ADDR,
+				AUD_SHIM_RATIO);
+		} else if (DSP_CLOCK_SPEED == CLK_50MHZ) {
+			sst_drv_ctx->chip_rev_id = CHIP_A2_50;
+	/* SCU FW Changes*/
+
+			retval = sst_scu_ipc_write(AUD_SHIM_BASE_ADDR,
+				AUD_SHIM_RATIO_1_1);
+		} else {
+			printk(KERN_ERR "SST ERR: +\
+				Invalid clock speed\n ");
+			return -EIO;
+		}
+	} /*else {
+		printk(KERN_ERR
+		"SST ERR: Invalid chip revision Type\n");
+		return -EIO;
+	}*/
+#endif
+	/* to fix SPI driver bug, which sets to 1 */
+	csr.full = 0x3a2;
+	writel(csr.full, sst_drv_ctx->shim + SST_ISRX);
+	writel(csr.full, sst_drv_ctx->shim + SST_CSR);
+	/* ----------- */
+
+	csr.full = readl(sst_drv_ctx->shim + SST_CSR);
+	csr.part.strb_cntr_rst = 0;
+	csr.part.run_stall = 0x1;
+	csr.part.bypass = 0x7;
+	csr.part.sst_reset = 0x1;
+	writel(csr.full, sst_drv_ctx->shim + SST_ISRX);
+	writel(csr.full, sst_drv_ctx->shim + SST_CSR);
+
+	printk(KERN_DEBUG "SST DBG:Chip version +\
+		is:: %d\n", value);
+	return retval;
+}
+
+/**
+* Start the SST DSP processor
+*/
+static int sst_start(void)
+{
+	union config_status_reg csr;
+
+	csr.full = readl(sst_drv_ctx->shim + SST_CSR);
+	csr.part.bypass = 0;
+	writel(csr.full, sst_drv_ctx->shim + SST_ISRX);
+	writel(csr.full, sst_drv_ctx->shim + SST_CSR);
+
+#if 0
+	retval = sst_scu_ipc_write(
+			sst_drv_ctx->shim_phy_add + SST_CSR, csr.full);
+	if (retval != 0)
+		printk(KERN_ERR
+			"SST ERR: scu ipc write start failed %d ", retval);
+	csr.full = readl(sst_drv_ctx->shim + SST_CSR);
+	csr.part.sst_reset = 0;
+	csr.part.run_stall = 0;
+	if ((sst_drv_ctx->chip_rev_id == CHIP_A2_50) ||
+			(sst_drv_ctx->chip_rev_id == CHIP_A2_100)) {
+		csr.part.strb_cntr_rst = 1;
+		if (sst_drv_ctx->chip_rev_id == CHIP_A2_100)
+			csr.part.sst_clk = 1;
+	}
+#endif
+	csr.part.run_stall = 0;
+	csr.part.sst_reset = 0;
+	csr.part.strb_cntr_rst = 1;
+	printk(KERN_DEBUG "SST DBG:Setting SST to execute 0x%x \n", csr.full);
+	writel(csr.full, sst_drv_ctx->shim + SST_ISRX);
+	writel(csr.full, sst_drv_ctx->shim + SST_CSR);
+
+#if 0
+	return sst_scu_ipc_write(
+			sst_drv_ctx->shim_phy_add + SST_CSR, csr.full);
+#endif
+	return 0;
+}
+
+/**
+* Parse modules that need to be placed in SST IRAM and DRAM
+*/
+static int sst_parse_module(struct fw_module_header *module)
+{
+	struct dma_block_info *block;
+	u32 count;
+	void __iomem *ram;
+
+	printk(KERN_DEBUG "SST DBG:module sign=%s sz=0x%x blks=0x%x typ=0x%x ep=0x%x sz=0x%x\n",
+			module->signature, module->mod_size,
+			module->blocks, module->type,
+			module->entry_point, sizeof(*module));
+
+	block = (void *)module + sizeof(*module);
+
+	for (count = 0; count < module->blocks; count++) {
+		if (block->size <= 0) {
+			printk(KERN_ERR "SST ERR: +\
+				block size invalid\n ");
+			return -EINVAL;
+		}
+		switch (block->type) {
+		case SST_IRAM:
+			ram = sst_drv_ctx->iram;
+			break;
+		case SST_DRAM:
+			ram = sst_drv_ctx->dram;
+			break;
+		default:
+			printk(KERN_ERR
+				"SST ERR:wrng ram typ0x%x +\
+				inblock0x%x\n", block->type, count);
+			return -EINVAL;
+		}
+		memcpy_toio(ram + block->ram_offset,
+				(void *)block + sizeof(*block), block->size);
+		block = (void *)block + sizeof(*block) + block->size;
+	}
+	return 0;
+}
+
+/**
+* sst_parse_fw_image - FW parse and load
+* This function is called to parse and download the FW image
+*/
+static int sst_parse_fw_image(const struct firmware *sst_fw)
+{
+	struct fw_header *header;
+	u32 count;
+	int ret_val;
+	struct fw_module_header *module;
+
+	BUG_ON(!sst_fw);
+
+	/* Read the header information from the data pointer */
+	header = (struct fw_header *)sst_fw->data;
+
+	/* verify FW */
+	if ((strncmp(header->signature, SST_FW_SIGN, 4) != 0) ||
+			(sst_fw->size != header->file_size + sizeof(*header))) {
+		/* Invalid FW signature */
+		printk(KERN_ERR
+			"SST ERR: InvalidFW sgn/filesiz mismtch\n ");
+		return -EINVAL;
+	}
+	printk(KERN_DEBUG "SST DBG:header sign=%s size=0x%x modules=0x%x fmt=0x%x size=0x%x\n",
+			header->signature, header->file_size, header->modules,
+			header->file_format, sizeof(*header));
+	module = (void *)sst_fw->data + sizeof(*header);
+	for (count = 0; count < header->modules; count++) {
+		/* module */
+		ret_val = sst_parse_module(module);
+		if (ret_val)
+			return ret_val;
+		module = (void *)module + sizeof(*module) + module->mod_size ;
+	}
+
+	printk(KERN_DEBUG "SST DBG:done....\n");
+	return 0;
+}
+
+/**
+* sst_load_fw - function to reset FW
+* @fw:		Pointer to loaded FW
+* This function is called when the FW is loaded
+*/
+int sst_load_fw(const struct firmware *fw, void *context)
+{
+	int ret_val;
+
+	printk(KERN_DEBUG "SST DBG:called \n");
+	BUG_ON(!fw);
+
+	/* TBD: Checksum, tamper check etc */
+	ret_val = intel_sst_reset_dsp();
+	if (ret_val)
+		return ret_val;
+	/* putting the sst state to init */
+	sst_drv_ctx->sst_state = SST_UN_INIT;
+
+	ret_val = sst_parse_fw_image(fw);
+	if (ret_val)
+		return ret_val;
+
+	sst_drv_ctx->sst_state = SST_FW_LOADED;
+	/*  7. ask scu to reset the bypass bits */
+	/*  8.bring sst out of reset  */
+	ret_val = sst_start();
+	if (ret_val)
+		return ret_val;
+
+	printk(KERN_DEBUG "SST DBG:...successful!!!\n");
+	return ret_val;
+}
+
+/**
+* This function is called when any codec/post processing library
+* needs to be downloaded
+*/
+static int sst_download_library(const struct firmware *fw_lib,
+				struct snd_sst_lib_download_info *lib)
+{
+	/* send IPC message and wait */
+	int i;
+	u8 pvt_id;
+	struct ipc_post *msg = NULL;
+	union config_status_reg csr;
+	struct snd_sst_str_type str_type = {0};
+	int retval = 0;
+
+	if (sst_create_large_msg(&msg))
+		return -ENOMEM;
+
+	pvt_id = sst_assign_pvt_id(sst_drv_ctx);
+	i = sst_get_block_stream(sst_drv_ctx);
+	printk(KERN_DEBUG "SST DBG:alloc block +\
+		allocated = %d, pvt_id %d\n", i, pvt_id);
+	if (i < 0) {
+		kfree(msg);
+		return -ENOMEM;
+	}
+	sst_drv_ctx->alloc_block[i].sst_id = pvt_id;
+	sst_fill_header(&msg->header, IPC_IA_PREP_LIB_DNLD, 1, 0);
+	msg->header.part.data = sizeof(u32) + sizeof(str_type);
+	str_type.codec_type = lib->dload_lib.lib_info.lib_type;
+	str_type.pvt_id = pvt_id;
+	memcpy(msg->mailbox_data, &msg->header, sizeof(u32));
+	memcpy(msg->mailbox_data + sizeof(u32), &str_type, sizeof(str_type));
+	mutex_lock(&sst_drv_ctx->list_lock);
+	list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list);
+	mutex_unlock(&sst_drv_ctx->list_lock);
+	sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
+	retval = sst_wait_timeout(sst_drv_ctx, &sst_drv_ctx->alloc_block[i]);
+	if (retval) {
+		/* error */
+		sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
+		printk(KERN_ERR
+			"SST ERR: Prep codec downloaded failed %d\n", retval);
+		return -EIO;
+	}
+	printk(KERN_DEBUG "SST DBG:FW responded, ready for download now...\n");
+	/* downloading on success */
+	sst_drv_ctx->sst_state = SST_FW_LOADED;
+	csr.full = readl(sst_drv_ctx->shim + SST_CSR);
+	printk(KERN_DEBUG "SST DBG:CSR reg 0x%x \n", csr.full);
+	csr.part.run_stall = 1;
+	printk(KERN_DEBUG "SST DBG:HALT CSR reg setting to 0x%x \n", csr.full);
+	writel(csr.full, sst_drv_ctx->shim + SST_ISRX);
+	writel(csr.full, sst_drv_ctx->shim + SST_CSR);
+#if 0
+	retval = sst_scu_ipc_write(
+			sst_drv_ctx->shim_phy_add + SST_CSR, csr.full);
+	if (retval) {
+		/* error */
+		sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
+		printk(KERN_ERR
+			"SST ERR: IPC failed to Halt SST 0x%x\n", retval);
+		return -EAGAIN;
+	}
+#endif
+	csr.full = readl(sst_drv_ctx->shim + SST_CSR);
+	csr.part.bypass = 0x7;
+	printk(KERN_DEBUG "SST DBG:Bypass CSR reg +\
+		setting to 0x%x \n", csr.full);
+	writel(csr.full, sst_drv_ctx->shim + SST_ISRX);
+	writel(csr.full, sst_drv_ctx->shim + SST_CSR);
+#if 0
+	retval = sst_scu_ipc_write(
+			sst_drv_ctx->shim_phy_add + SST_CSR, csr.full);
+	if (retval) {
+		/* error */
+		sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
+		printk(KERN_ERR
+			"SST ERR: IPC failed to Bypass SST 0x%x\n", retval);
+		csr.part.bypass = 0x0;
+		/* bring LPE out of run stall */
+		/* send error mesages to FW- TBD FIXME */
+		csr.part.run_stall = 0x0;
+		printk(KERN_DEBUG "SST DBG:Bypass CSR reg +\
+			setting to 0x%x \n", csr.full);
+		retval = sst_scu_ipc_write(sst_drv_ctx->shim_phy_add + SST_CSR,
+			       csr.full);
+		if (retval) {
+			/* prepare to download firmware again
+			for the next time TBD FIXME
+			sst_drv_ctx->sst_state = SST_UN_INIT;*/
+		}
+		return -EAGAIN;
+	}
+#endif
+	sst_parse_fw_image(fw_lib);
+
+	/* set the FW to running again */
+	csr.full = readl(sst_drv_ctx->shim + SST_CSR);
+	csr.part.bypass = 0x0;
+	printk(KERN_DEBUG "SST DBG:Bypass CSR reg +\
+			setting to 0x%x \n", csr.full);
+	writel(csr.full, sst_drv_ctx->shim + SST_ISRX);
+	writel(csr.full, sst_drv_ctx->shim + SST_CSR);
+#if 0
+	retval = sst_scu_ipc_write(
+			sst_drv_ctx->shim_phy_add + SST_CSR, csr.full);
+	if (retval) {
+		sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
+		printk(KERN_ERR\
+			"SST ERR: BypassCSR regclear failed 0x%x\n", retval);
+		/* bring LPE out of run stall */
+		/* send error mesages to FW- TBD FIXME */
+		csr.part.run_stall = 0x0;
+		printk(KERN_DEBUG "SST DBG:Bypass CSR +\
+			reg setting to 0x%x \n", csr.full);
+		retval = sst_scu_ipc_write(sst_drv_ctx->shim_phy_add + SST_CSR,
+			       csr.full);
+		if (retval) {
+			/* prepare to download firmware again
+			for the next time TBD FIXME
+			sst_drv_ctx->sst_state = SST_UN_INIT;*/
+		}
+		return -EAGAIN;
+	}
+#endif
+	csr.full = readl(sst_drv_ctx->shim + SST_CSR);
+	csr.part.run_stall = 0;
+	printk(KERN_DEBUG "SST DBG:Stalll CSR reg +\
+			setting to 0x%x \n", csr.full);
+	writel(csr.full, sst_drv_ctx->shim + SST_ISRX);
+	writel(csr.full, sst_drv_ctx->shim + SST_CSR);
+#if 0
+	retval = sst_scu_ipc_write(
+			sst_drv_ctx->shim_phy_add + SST_CSR, csr.full);
+	if (retval) {
+		sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
+		printk(KERN_ERR
+			"SST ERR: Stall CSR reg clear failed 0x%x \n", retval);
+		if (retval) {
+			/* prepare to download firmware again
+			for the next time TBD FIXME
+			sst_drv_ctx->sst_state = SST_UN_INIT;*/
+		}
+		return -EAGAIN;
+	}
+#endif
+	/* send download complete and wait */
+	if (sst_create_large_msg(&msg)) {
+		sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
+		return -ENOMEM;
+	}
+
+	sst_fill_header(&msg->header, IPC_IA_LIB_DNLD_CMPLT, 1, 0);
+	msg->header.part.data = sizeof(u32) + sizeof(*lib);
+	lib->pvt_id = pvt_id;
+	memcpy(msg->mailbox_data, &msg->header, sizeof(u32));
+	memcpy(msg->mailbox_data + sizeof(u32), lib, sizeof(*lib));
+	mutex_lock(&sst_drv_ctx->list_lock);
+	list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list);
+	mutex_unlock(&sst_drv_ctx->list_lock);
+	sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
+	printk(KERN_DEBUG "SST DBG:Waiting for FW to respond on Download complete \n");
+	sst_drv_ctx->alloc_block[i].ops_block.condition = false;
+	retval = sst_wait_timeout(sst_drv_ctx, &sst_drv_ctx->alloc_block[i]);
+	if (retval) {
+		/* error */
+		sst_drv_ctx->sst_state = SST_FW_RUNNING;
+		/* shouldnt we set it to error state??? TBD */
+		sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
+		return -EIO;
+	}
+
+	printk(KERN_DEBUG "SST DBG:FW responded sucess on Download complete \n");
+	sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
+	sst_drv_ctx->sst_state = SST_FW_RUNNING;
+	return 0;
+
+}
+
+/**
+* This function is called befoer downloading the codec/postprocessing
+* library is set for download to SST DSP
+*/
+static int sst_validate_library(const struct firmware *fw_lib,
+		struct lib_slot_info *slot,
+		u32 *entry_point)
+{
+	struct fw_header *header;
+	struct fw_module_header *module;
+	struct dma_block_info *block;
+	unsigned int n_blk, isize = 0, dsize = 0;
+	int err = 0;
+
+	header = (struct fw_header *)fw_lib->data;
+	if (header->modules != 1) {
+		printk(KERN_ERR\
+			"SST ERR: Module no mismatch found\n ");
+		err = -EINVAL;
+		goto exit;
+	}
+	module = (void *)fw_lib->data + sizeof(*header);
+	*entry_point = module->entry_point;
+	printk(KERN_DEBUG "SST DBG:Module entry point 0x%x \n", *entry_point);
+	printk(KERN_DEBUG "SST DBG:Module Sign %s, Size 0x%x, Blocks 0x%x Type 0x%x \n",
+		module->signature, module->mod_size,
+		module->blocks, module->type);
+
+	block = (void *)module + sizeof(*module);
+	for (n_blk = 0; n_blk < module->blocks; n_blk++) {
+		switch (block->type) {
+		case SST_IRAM:
+			isize += block->size;
+			break;
+		case SST_DRAM:
+			dsize += block->size;
+			break;
+		default:
+			printk(KERN_ERR
+				"SST ERR: Invalid blk type for 0x%x\n ", n_blk);
+			err = -EINVAL;
+			goto exit;
+		}
+		block = (void *)block + sizeof(*block) + block->size;
+	}
+	if (isize > slot->iram_size || dsize > slot->dram_size) {
+		printk(KERN_ERR
+			"SST ERR: library exceeds size allocated \n");
+		err = -EINVAL;
+		goto exit;
+	} else
+		printk(KERN_DEBUG "SST DBG:Library is safe for download...\n");
+
+	printk(KERN_DEBUG "SST DBG:iram 0x%x, dram 0x%x, allowed iram 0x%x, allowed dram 0x%x\n",
+		isize, dsize, slot->iram_size, slot->dram_size);
+exit:
+	return err;
+
+}
+
+/**
+* This function is called when FW requests for a particular libary download
+* This function prepares the library to download
+*/
+int sst_load_library(struct snd_sst_lib_download *lib, u8 ops, u32 pvt_id)
+{
+	char buf[20];
+	const char *type, *dir;
+	int len = 0, error = 0;
+	u32 entry_point;
+	const struct firmware *fw_lib;
+	struct snd_sst_lib_download_info dload_info = {{{0},},};
+
+	memset(buf, 0, sizeof(buf));
+
+	printk(KERN_DEBUG "SST DBG:Lib Type 0x%x, Slot 0x%x, ops 0x%x \n",
+			lib->lib_info.lib_type, lib->slot_info.slot_num, ops);
+	printk(KERN_DEBUG "SST DBG:Version 0x%x, name %s, caps 0x%x media type 0x%x \n",
+		lib->lib_info.lib_version, lib->lib_info.lib_name,
+		lib->lib_info.lib_caps, lib->lib_info.media_type);
+
+	printk(KERN_DEBUG "SST DBG:IRAM Size 0x%x, offset 0x%x, DRAM Size 0x%x, offset 0x%x \n",
+		lib->slot_info.iram_size, lib->slot_info.iram_offset,
+		lib->slot_info.dram_size, lib->slot_info.dram_offset);
+
+	switch (lib->lib_info.lib_type) {
+	case SST_CODEC_TYPE_MP3:
+		type = "mp3_";
+		break;
+	case SST_CODEC_TYPE_AAC:
+		type = "aac_";
+		break;
+	case SST_CODEC_TYPE_AACP:
+		type = "aac_v1_";
+		break;
+	case SST_CODEC_TYPE_eAACP:
+		type = "aac_v2_";
+		break;
+	case SST_CODEC_TYPE_WMA9:
+		type = "wma9_";
+		break;
+	default:
+		printk(KERN_ERR "SST ERR: +\
+			Invalid codec type \n");
+		error = -EINVAL;
+		goto wake;
+	}
+
+	if (ops == STREAM_OPS_CAPTURE)
+		dir = "enc_";
+	else
+		dir = "dec_";
+	strncpy(buf, type, strlen(type));
+	strncpy(buf + strlen(type), dir, strlen(dir));
+	len = strlen(type) + strlen(dir);
+	len += snprintf(buf + len, sizeof(buf) - len, "%d",
+			lib->slot_info.slot_num);
+	len += snprintf(buf + len, sizeof(buf) - len, ".bin");
+
+	printk(KERN_DEBUG "SST DBG:Requesting %s \n", buf);
+
+	error = request_firmware(&fw_lib, buf, &sst_drv_ctx->pci->dev);
+	if (error) {
+		printk(KERN_ERR
+			"SST ERR: library load failed %d \n", error);
+		goto wake;
+	}
+	error = sst_validate_library(fw_lib, &lib->slot_info, &entry_point);
+	if (error)
+		goto wake_free;
+
+	lib->mod_entry_pt = entry_point;
+	memcpy(&dload_info.dload_lib, lib, sizeof(*lib));
+	error = sst_download_library(fw_lib, &dload_info);
+	if (error)
+		goto wake_free;
+
+	/* lib is downloaded and init send alloc again */
+	printk(KERN_DEBUG "SST DBG:Library is downloaded now... \n");
+wake_free:
+	/* sst_wake_up_alloc_block(sst_drv_ctx, pvt_id, error, NULL); */
+	release_firmware(fw_lib);
+wake:
+	return error;
+}
+
+/* This Function set the bit banging*/
+int sst_spi_mode_enable()
+{
+
+   void __iomem *logical_ptr_to_bang;
+   u32 regbase = SPI_MODE_ENABLE_BASE_ADDR, range = 0x38;
+   u32 data;
+   u32 mask = 0x400000;
+   int retval;
+   int i = 0;
+
+
+   logical_ptr_to_bang = ioremap_nocache(regbase, range);
+   if (!logical_ptr_to_bang) {
+		dev_err(&sst_drv_ctx->pci->dev, \
+			"SST ERR: SSP0 bit bang -IOREMAP Failed \n");
+		return -1;
+   }
+
+    /* spi mode enable */
+   iowrite32(0x0000000f, logical_ptr_to_bang);
+   iowrite32(0x33301dc3, logical_ptr_to_bang + 0x4);
+   iowrite32(0x02010007, logical_ptr_to_bang + 0x2c);
+   iowrite32(0x00000000, logical_ptr_to_bang + 0x30);
+   iowrite32(0x00000000, logical_ptr_to_bang + 0x34);
+   iowrite32(0x0000008f, logical_ptr_to_bang);
+
+
+   retval = sst_scu_ipc_write(0xff12b004, 0x3);
+   retval = sst_scu_ipc_write(0xff12b000, 0x01070034);
+   retval = sst_scu_ipc_write(0xff12b004, 0x99);
+   retval = sst_scu_ipc_write(0xff12b000, 0x01070038);
+
+   data = ioread32(logical_ptr_to_bang+0x8);
+   dev_err(&sst_drv_ctx->pci->dev,\
+	"SST ERR: SSP0 bit bang SSCR val = 0x%08x \n", data);
+   data = data & mask;
+   while (data == mask) {
+	retval = sst_scu_ipc_write(0xff12b004, 0x3);
+	retval = sst_scu_ipc_write(0xff12b000, 0x01070034);
+	retval = sst_scu_ipc_write(0xff12b004, 0x2);
+	retval = sst_scu_ipc_write(0xff12b000, 0x01070034);
+	data  = ioread32(logical_ptr_to_bang+0x8);
+	data  = data & mask;
+	i++;
+    }
+   dev_err(&sst_drv_ctx->pci->dev,  \
+	"SST ERR: SSP0 bit bang while loop counter= %4d \n ", i);
+   retval = sst_scu_ipc_write(0xff12b004, 0x0);
+   retval = sst_scu_ipc_write(0xff12b000, 0x01070038);
+
+   return retval;
+}
-- 
1.6.2.2