summaryrefslogtreecommitdiff
path: root/drivers/misc/tfa9887.c
blob: 70089615004703b71dff759671b8aaaa45848728 (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
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/err.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/i2c.h>
#include <linux/regmap.h>
#include <linux/tfa9887.h>
#include <sound/initval.h>
#include <linux/sysfs.h>
#include <linux/miscdevice.h>
#include <linux/delay.h>

#define STATUS_OK 0

void tegra_asoc_enable_clocks(void);
void tegra_asoc_disable_clocks(void);

static ssize_t tfa9887_cal_show(struct kobject *kobj,
		struct kobj_attribute *attr, char *buf);

static ssize_t tfa9887_cal_store(struct kobject *kobj,
		struct kobj_attribute *attr, const char *buf, size_t count);

static ssize_t tfa9887_config_show(struct kobject *kobj,
		struct kobj_attribute *attr, char *buf);

static ssize_t tfa9887_config_store(struct kobject *kobj,
		struct kobj_attribute *attr, const char *buf, size_t count);

static ssize_t tfa9887_vol_show(struct kobject *kobj,
		struct kobj_attribute *attr, char *buf);

static ssize_t tfa9887_vol_store(struct kobject *kobj,
		struct kobj_attribute *attr, const char *buf, size_t count);


static struct kobj_attribute tfa9887_config =
		__ATTR(config, 0660, tfa9887_config_show, tfa9887_config_store);

static struct kobj_attribute tfa9887_cal =
		__ATTR(cal, 0660, tfa9887_cal_show, tfa9887_cal_store);

static struct kobj_attribute tfa9887_vol =
		__ATTR(vol, 0660, tfa9887_vol_show, tfa9887_vol_store);

static struct kobject *tfa9887_kobj;

static struct tfa9887_priv *tfa9887R, *tfa9887L, *tfa9887R_byte, *tfa9887L_byte;

static int eq_mode, preset_mode, srate, vol_index;

static char calibdata[16];

static int calibration;

static int recalibration;

static int powerDown = 1;

unsigned int volume_step[5] = {0, 2, 4, 6, 12};

unsigned int volume_curve[16] = {0, 2, 4, 7, 7, 7, 11, 11,
								 11, 11, 11, 11, 11, 11, 11, 11};

/* begin binary data: */
unsigned char coldpatch_data[] = {/* 10 */
0x08, 0x00, 0x70, 0x00, 0x07, 0x81, 0x00, 0x00, 0x00, 0x01
};
/* end binary data. size = 10 bytes */

/* begin binary data: */

/* begin binary data: */
char n1d2_data[] = {/* 2380 */
0x03, 0x00, 0x70, 0x00, 0x01, 0xFB, 0x00, 0x71, 0x40
, 0x00, 0x38, 0x08, 0x0A, 0x6F, 0x9B, 0xA6, 0x7D, 0x04, 0xB0, 0xB6, 0x62, 0x88, 0x69, 0x7E
, 0xC4, 0x08, 0x6A, 0xBF, 0x54, 0xFC, 0xB5, 0x00, 0x58, 0x7F, 0x3B, 0x80, 0x01, 0x25, 0x30
, 0x50, 0x00, 0x80, 0x69, 0x5E, 0xD4, 0x3C, 0x3A, 0x90, 0x00, 0x0D, 0x72, 0x02, 0xC4, 0x80
, 0x6A, 0xBE, 0xD4, 0x3E, 0x30, 0x40, 0x00, 0x80, 0x3B, 0x80, 0x01, 0x00, 0xB0, 0xB2, 0xF6
, 0x48, 0x6A, 0x5E, 0x54, 0x3E, 0x3A, 0x80, 0x00, 0x80, 0x3B, 0x80, 0x01, 0x00, 0x9B, 0xA6
, 0xF8, 0x49, 0x39, 0x84, 0x80, 0x80, 0x92, 0x19, 0xFE, 0x9C, 0x3B, 0x62, 0x40, 0x1C, 0x9B
, 0x84, 0x54, 0x3D, 0x61, 0x40, 0x7E, 0x9C, 0x3B, 0x80, 0x07, 0xF1, 0xA6, 0xB6, 0x7E, 0x9C
, 0x3B, 0x00, 0x40, 0x21, 0xB5, 0x00, 0x58, 0x3F, 0x3B, 0x80, 0x08, 0x00, 0x9B, 0xA4, 0x7E
, 0x9C, 0x9B, 0xA4, 0x54, 0x3D, 0xA5, 0xB2, 0xD8, 0x3F, 0xB5, 0x00, 0x42, 0xC0, 0x3C, 0xD8
, 0x03, 0x00, 0x8B, 0x80, 0x7D, 0x7C, 0xB5, 0x00, 0x7E, 0x9C, 0x9B, 0x86, 0x7D, 0x04, 0x38
, 0x0A, 0x0A, 0x6F, 0xB0, 0xB2, 0xD4, 0x7E, 0x6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88, 0x3A, 0x91, 0xFF
, 0x43, 0xB5, 0x00, 0x42, 0x90, 0x96, 0xF4, 0xD5, 0x3D, 0x3A, 0x81, 0xFF, 0x41, 0x61, 0x48
, 0xFD, 0xA9, 0x3A, 0x88, 0x00, 0xAF, 0x61, 0x8A, 0x72, 0xE8, 0x6A, 0x7E, 0xC4, 0x00, 0x30
, 0x40, 0x00, 0x80, 0x30, 0x70, 0x02, 0xBC, 0x3B, 0x80, 0x1C, 0x5A, 0xB5, 0x00, 0x55, 0x7C
, 0xB5, 0x00, 0x54, 0x3D, 0x3A, 0x88, 0x00, 0x0F, 0x62, 0x24, 0x44, 0x0A, 0x3A, 0x91, 0xFF
, 0x4F, 0x30, 0x50, 0x00, 0x80, 0x3B, 0x80, 0x01, 0x25, 0xB5, 0x00, 0x55, 0x7D, 0x6A, 0xDE
, 0x54, 0xBD, 0x3A, 0x81, 0xFF, 0xF3, 0x72, 0x22, 0xC2, 0x84, 0x30, 0xA0, 0x0A, 0x70, 0x61
, 0x04, 0x42, 0x98, 0x7F, 0x2C, 0x76, 0x91, 0x38, 0x0C, 0x22, 0x08, 0x60, 0x08, 0x43, 0x48
, 0x69, 0x3F, 0x54, 0x7D, 0xB5, 0x00, 0x52, 0xFF, 0x3B, 0x80, 0x1B, 0x5B, 0x38, 0x01, 0x0A
, 0x6F, 0x30, 0x00, 0x00, 0x20, 0xB9, 0x00, 0x54, 0x3D, 0x9B, 0x2B, 0x55, 0x3C, 0xB0, 0x04
, 0x52, 0xBE, 0x38, 0x08, 0x22, 0x01, 0xA6, 0xD0, 0x52, 0x3F, 0x3A, 0x80, 0x00, 0x0F, 0x8B
, 0x80, 0x42, 0x50, 0x9B, 0xA2, 0x42, 0xC0, 0xFB, 0x00, 0x71, 0x40, 0x7C, 0x3A, 0x88, 0x00
, 0xB4, 0xB5, 0x00, 0x53, 0x7C, 0x31, 0x1F, 0xFF, 0xE9, 0x69, 0x3F, 0x44, 0x0D, 0x3B, 0x80
, 0x01, 0x25, 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 0x00, 0x30, 0xB0, 0x0B
, 0x66, 0x30, 0x50, 0x00, 0x80, 0x3B, 0x80, 0x02, 0xBE, 0xB5, 0x00, 0x62, 0x09, 0x7F, 0x4E
, 0x55, 0x3C, 0xB5, 0x00, 0x43, 0x10, 0x90, 0xDB, 0x54, 0xBD, 0x61, 0x44, 0x7E, 0x9C, 0xA2
, 0x17, 0x55, 0x39, 0x3A, 0x92, 0x00, 0xC8, 0x3A, 0x89, 0xFF, 0xBE, 0x3B, 0x43, 0x41, 0x49
, 0x6A, 0xBF, 0x54, 0xFD, 0x38, 0x12, 0x0B, 0x66, 0x30, 0x60, 0x00, 0x80, 0x30, 0x80, 0x12
, 0x00, 0x30, 0xA0, 0x01, 0x80, 0x3B, 0x80, 0x01, 0x1C, 0xB5, 0x00, 0x61, 0x46, 0xB5, 0x00
, 0x54, 0xB9, 0x30, 0x80, 0x01, 0x00, 0x30, 0x50, 0x01, 0x00, 0x30, 0x70, 0x00, 0x80, 0x3B
, 0x80, 0x1C, 0x3E, 0x38, 0x0C, 0x0B, 0x6B, 0x30, 0x90, 0x01, 0x80, 0x38, 0x0A, 0x22, 0x01
, 0x20, 0x80, 0x41, 0x28, 0x30, 0xA0, 0x01, 0x00, 0xB5, 0x00, 0x42, 0x11, 0xB5, 0x00, 0x43
, 0x08, 0xD4, 0xC8, 0x42, 0x11, 0x60, 0x24, 0xFE, 0x9C, 0x30, 0x90, 0x01, 0x00, 0x30, 0x50
, 0x00, 0x80, 0x30, 0xA0, 0x22, 0x29, 0x3B, 0x80, 0x02, 0x60, 0x30, 0x80, 0x01, 0x80, 0x30
, 0x80, 0x01, 0x00, 0x30, 0x50, 0x00, 0x80, 0x3B, 0x80, 0x00, 0xC1, 0x30, 0x90, 0x01, 0x00
, 0x30, 0x90, 0x01, 0x00, 0xB5, 0x00, 0x78, 0x09, 0x30, 0x50, 0x00, 0x3F, 0x3B, 0x80, 0x00
, 0x51, 0xFB, 0x00, 0x71, 0x41, 0x36, 0xB5, 0x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00, 0x42, 0xD0, 0x38, 0x0C, 0x22, 0x13, 0xB5, 0x00
, 0x42, 0x98, 0xD0, 0x35, 0x7E, 0x9C, 0x3A, 0x83, 0xFF, 0x57, 0x3F, 0x00, 0x71, 0x41, 0xF0
, 0xB5, 0x00, 0x18, 0x61, 0x3A, 0x90, 0x00, 0x9B, 0xD0, 0x4C, 0x62, 0x09, 0x30, 0x70, 0x00
, 0x80, 0xB5, 0x00, 0x55, 0x7D, 0x3B, 0x80, 0x00, 0xA9, 0x9B, 0xC6, 0x61, 0x40, 0x7F, 0x4E
, 0x54, 0xBD, 0x6A, 0x1F, 0x4C, 0x08, 0x3B, 0x80, 0x01, 0x0E, 0x30, 0x50, 0x00, 0x80, 0xB5
, 0x00, 0x58, 0x3F, 0x3C, 0xD8, 0x03, 0x00, 0x8B, 0x80, 0x7D, 0x7D, 0xB5, 0x00, 0x7E, 0x9C
, 0x03, 0x00, 0x70, 0x00, 0x03, 0x21, 0x00, 0x71, 0x0A, 0x6F, 0x00, 0x00, 0x01, 0x00, 0x00
, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00
, 0x02, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x2D, 0x00, 0x71, 0x0B, 0x60
, 0x00, 0xB8, 0x45, 0x7F, 0xEA, 0x29, 0x00, 0x00, 0x07, 0x40, 0x0F, 0x26, 0x3F, 0xFF, 0x9F
, 0x02, 0xCC, 0xCD, 0x00, 0x12, 0x00, 0x40, 0x00, 0x00, 0x01, 0x47, 0xAE, 0x00, 0x00, 0x00
, 0x02, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x08, 0x04, 0x00, 0x00, 0x0F, 0x00, 0x71
, 0x0A, 0x79, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x7E, 0x4D, 0xFE, 0x03
, 0x00, 0x70, 0x00, 0x05, 0x03, 0x00, 0x70, 0x00, 0x07, 0x7B, 0x00, 0x71, 0x03, 0x00, 0x00
, 0x00, 0x01, 0x00, 0x0B, 0x23, 0x00, 0x40, 0x00, 0x00, 0x3B, 0x80, 0x00, 0x00, 0x01, 0x00
, 0x0B, 0xAB, 0x00, 0x40, 0x24, 0x00, 0x3B, 0x80, 0x00, 0x00, 0x01, 0x00, 0x0D, 0xF5, 0x00
, 0x40, 0x3A, 0x00, 0x3B, 0x80, 0x00, 0x00, 0x01, 0x00, 0x0A, 0x6B, 0x00, 0x40, 0x97, 0x00
, 0x3B, 0x80, 0x00, 0x00, 0x01, 0x00, 0x05, 0xC6, 0x00, 0x40, 0xAB, 0x00, 0x3B, 0x80, 0x00
, 0x00, 0x01, 0x00, 0x0D, 0x24, 0x00, 0x40, 0xE2, 0x00, 0x3B, 0x80, 0x00, 0x00, 0x01, 0x00
, 0x12, 0x3A, 0x00, 0x7E, 0x9C, 0x00, 0xB5, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x7B, 0x00
, 0x41, 0xD0, 0x00, 0x3B, 0x80, 0x00, 0x00, 0x01, 0x00, 0x1B, 0xA7, 0x00, 0x41, 0xDD, 0x00
, 0x3B, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03
, 0x00, 0x70, 0x00, 0x00, 0x23, 0x00, 0x70, 0x00, 0x02, 0x00, 0x01, 0x00, 0x80, 0x03, 0xFF
, 0xFF, 0xF9, 0xFF, 0xFF, 0xF7, 0xFF, 0xFF, 0xF6, 0x00, 0x00, 0x1D, 0x00, 0x00, 0x1B, 0x00
, 0x00, 0x1B, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x1C, 0x03, 0x00, 0x70, 0x01
, 0x12
};
/* end binary data. size = 2380bytes */


/* begin binary data: */
/* TODO for now using left speaker modeal for both. Update to use seperate models for left
 and right speakers */
char speaker_data_left[] = {/* 423 */
	0x00, 0x01, 0x54, 0x00, 0x01, 0x15, 0x00, 0x00, 0xab, 0x00, 0x00, 0x29, 0x00, 0x00, 0x6a, 0x00,
	0x00, 0x5b, 0x00, 0x00, 0x21, 0xff, 0xff, 0x15, 0xff, 0xfe, 0xa0, 0xff, 0xfe, 0x77, 0xff, 0xfe,
	0xb1, 0xff, 0xff, 0x37, 0xff, 0xfe, 0x3d, 0xff, 0xfd, 0xf3, 0xff, 0xfc, 0x8a, 0xff, 0xfd, 0x21,
	0xff, 0xfc, 0x83, 0xff, 0xfe, 0x0a, 0xff, 0xfc, 0x67, 0xff, 0xfc, 0x95, 0xff, 0xfa, 0xe5, 0xff,
	0xfc, 0x58, 0xff, 0xfb, 0xa2, 0xff, 0xfd, 0x58, 0xff, 0xfc, 0x19, 0xff, 0xfb, 0xde, 0xff, 0xfb,
	0x29, 0xff, 0xfb, 0xac, 0xff, 0xfc, 0x0f, 0xff, 0xfe, 0x09, 0xff, 0xfd, 0xa4, 0xff, 0xfd, 0x31,
	0xff, 0xfc, 0x82, 0xff, 0xfd, 0x1a, 0xff, 0xff, 0x95, 0x00, 0x00, 0x7b, 0x00, 0x00, 0xe5, 0x00,
	0x00, 0x0b, 0xff, 0xff, 0x1a, 0xff, 0xff, 0xbe, 0x00, 0x02, 0x49, 0x00, 0x03, 0x99, 0x00, 0x02,
	0x3a, 0x00, 0x00, 0xea, 0xff, 0xff, 0x9b, 0xff, 0xff, 0xd1, 0x00, 0x02, 0x2d, 0x00, 0x04, 0x26,
	0x00, 0x01, 0x53, 0xff, 0xff, 0xc7, 0xff, 0xfc, 0x56, 0xff, 0xfc, 0xbc, 0xff, 0xff, 0x5f, 0x00,
	0x01, 0x54, 0xff, 0xfd, 0xb3, 0xff, 0xfa, 0x26, 0xff, 0xf6, 0xbd, 0xff, 0xf8, 0x4d, 0xff, 0xfb,
	0x92, 0xff, 0xfd, 0x6a, 0xff, 0xf9, 0x60, 0xff, 0xf5, 0x35, 0xff, 0xf2, 0x24, 0xff, 0xf5, 0x3b,
	0xff, 0xf9, 0xcf, 0xff, 0xfd, 0xa2, 0xff, 0xf8, 0x48, 0xff, 0xf2, 0xb0, 0xff, 0xf0, 0x2e, 0xff,
	0xf4, 0xa4, 0xff, 0xfc, 0x8b, 0x00, 0x00, 0x14, 0xff, 0xf9, 0xd3, 0xff, 0xf2, 0x68, 0xff, 0xf1,
	0x6a, 0xff, 0xf7, 0x4d, 0x00, 0x02, 0x98, 0x00, 0x06, 0x3e, 0xff, 0xff, 0xc6, 0xff, 0xf6, 0x5d,
	0xff, 0xf8, 0x59, 0x00, 0x01, 0x2d, 0x00, 0x12, 0x52, 0x00, 0x16, 0x72, 0x00, 0x0e, 0xe3, 0xff,
	0xff, 0xda, 0x00, 0x04, 0x4e, 0x00, 0x0d, 0x77, 0x00, 0x1e, 0xa6, 0x00, 0x1d, 0x7a, 0x00, 0x0b,
	0xb6, 0xff, 0xf1, 0xba, 0xff, 0xef, 0x61, 0xff, 0xf7, 0x8f, 0x00, 0x03, 0x4c, 0x00, 0x00, 0x6e,
	0xff, 0xe4, 0x3d, 0xff, 0xc9, 0x71, 0xff, 0xcc, 0xb6, 0xff, 0xeb, 0x18, 0x00, 0x04, 0x0f, 0x00,
	0x1c, 0x20, 0x00, 0x02, 0x22, 0x00, 0x06, 0xa2, 0x00, 0x10, 0x93, 0x00, 0x5a, 0xd9, 0x00, 0x65,
	0xba, 0x00, 0x8f, 0x39, 0x00, 0x37, 0xa0, 0x00, 0x29, 0x7e, 0xff, 0xdf, 0x6f, 0x00, 0x16, 0xf7,
	0xff, 0xb6, 0xb7, 0xff, 0xc2, 0x5f, 0xfe, 0xff, 0x78, 0x07, 0x97, 0x5b, 0x00, 0x4c, 0xf1, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x71, 0xeb, 0x85, 0x58, 0x51, 0xec, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20,
	0x00, 0x00, 0x1b, 0x85, 0x1f, 0x00, 0x01, 0xaf, 0x00, 0x01, 0xb0, 0x04, 0x00, 0x00, 0x00, 0x66,
	0x66, 0x19, 0x00, 0x00, 0x00, 0x72, 0xb0
};
/* end binary data. size = 423 bytes */

/* begin binary data: */
char speaker_data_right[] = {/* 423 */
	0x00, 0x01, 0x71, 0x00, 0x01, 0x32, 0x00, 0x00, 0xc9, 0x00, 0x00, 0x47, 0x00, 0x00, 0x88, 0x00,
	0x00, 0x7a, 0x00, 0x00, 0x39, 0xff, 0xff, 0x2a, 0xff, 0xfe, 0xad, 0xff, 0xfe, 0x81, 0xff, 0xfe,
	0xc3, 0xff, 0xff, 0x42, 0xff, 0xfe, 0x46, 0xff, 0xfd, 0xfa, 0xff, 0xfc, 0x99, 0xff, 0xfd, 0x2a,
	0xff, 0xfc, 0x8b, 0xff, 0xfe, 0x10, 0xff, 0xfc, 0x67, 0xff, 0xfc, 0x96, 0xff, 0xfa, 0xdf, 0xff,
	0xfc, 0x4c, 0xff, 0xfb, 0x98, 0xff, 0xfd, 0x51, 0xff, 0xfc, 0x0e, 0xff, 0xfb, 0xce, 0xff, 0xfb,
	0x1b, 0xff, 0xfb, 0x9a, 0xff, 0xfb, 0xfa, 0xff, 0xfd, 0xf3, 0xff, 0xfd, 0x8c, 0xff, 0xfd, 0x15,
	0xff, 0xfc, 0x60, 0xff, 0xfc, 0xfc, 0xff, 0xff, 0x71, 0x00, 0x00, 0x53, 0x00, 0x00, 0xbb, 0xff,
	0xff, 0xe4, 0xff, 0xfe, 0xee, 0xff, 0xff, 0x92, 0x00, 0x02, 0x21, 0x00, 0x03, 0x74, 0x00, 0x02,
	0x13, 0x00, 0x00, 0xc1, 0xff, 0xff, 0x6c, 0xff, 0xff, 0xa6, 0x00, 0x02, 0x01, 0x00, 0x03, 0xf8,
	0x00, 0x01, 0x1e, 0xff, 0xff, 0x95, 0xff, 0xfc, 0x23, 0xff, 0xfc, 0x88, 0xff, 0xff, 0x2f, 0x00,
	0x01, 0x24, 0xff, 0xfd, 0x7b, 0xff, 0xf9, 0xf2, 0xff, 0xf6, 0x8c, 0xff, 0xf8, 0x19, 0xff, 0xfb,
	0x5d, 0xff, 0xfd, 0x2f, 0xff, 0xf9, 0x2d, 0xff, 0xf5, 0x02, 0xff, 0xf1, 0xee, 0xff, 0xf5, 0x08,
	0xff, 0xf9, 0x9c, 0xff, 0xfd, 0x69, 0xff, 0xf8, 0x0a, 0xff, 0xf2, 0x75, 0xff, 0xef, 0xf2, 0xff,
	0xf4, 0x6b, 0xff, 0xfc, 0x57, 0xff, 0xff, 0xe0, 0xff, 0xf9, 0x9b, 0xff, 0xf2, 0x31, 0xff, 0xf1,
	0x3a, 0xff, 0xf7, 0x19, 0x00, 0x02, 0x69, 0x00, 0x06, 0x0f, 0xff, 0xff, 0x98, 0xff, 0xf6, 0x35,
	0xff, 0xf8, 0x2f, 0x00, 0x01, 0x05, 0x00, 0x12, 0x26, 0x00, 0x16, 0x48, 0x00, 0x0e, 0xc0, 0xff,
	0xff, 0xbe, 0x00, 0x04, 0x32, 0x00, 0x0d, 0x57, 0x00, 0x1e, 0x87, 0x00, 0x1d, 0x5c, 0x00, 0x0b,
	0x96, 0xff, 0xf1, 0x9f, 0xff, 0xef, 0x4a, 0xff, 0xf7, 0x7f, 0x00, 0x03, 0x44, 0x00, 0x00, 0x62,
	0xff, 0xe4, 0x2e, 0xff, 0xc9, 0x67, 0xff, 0xcc, 0xae, 0xff, 0xeb, 0x07, 0x00, 0x03, 0xfe, 0x00,
	0x1c, 0x0c, 0x00, 0x02, 0x10, 0x00, 0x06, 0x9e, 0x00, 0x10, 0xb2, 0x00, 0x5b, 0x2c, 0x00, 0x66,
	0x53, 0x00, 0x90, 0x24, 0x00, 0x38, 0xd6, 0x00, 0x2a, 0xf5, 0xff, 0xe1, 0x10, 0x00, 0x18, 0x98,
	0xff, 0xb8, 0x32, 0xff, 0xc3, 0x80, 0xfe, 0xff, 0xe5, 0x07, 0x96, 0x81, 0x00, 0x4a, 0x49, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x71, 0xeb, 0x85, 0x58, 0x51, 0xec, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20,
	0x00, 0x00, 0x1c, 0x7a, 0xe1, 0x00, 0x01, 0xaf, 0x00, 0x01, 0xb0, 0x04, 0x00, 0x00, 0x00, 0x66,
	0x66, 0x19, 0x00, 0x00, 0x00, 0x72, 0xb0
};
/* end binary data. size = 423 bytes */


/* begin binary data: */
char config_data[] = {/* 165 */
0x09, 0xf3, 0x33, 0x01, 0x3e, 0x66, 0x00, 0x54, 0xcd, 0x00, 0x00, 0x14, 0x00, 0x00, 0x02,
0x1a, 0xe6, 0x40, 0x1b, 0x40, 0xd4, 0x1c, 0x59, 0xda, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x4b, 0x00, 0x01, 0x4b,
0x00, 0x00, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01,
0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x80, 0x00, 0x01, 0x40, 0x00, 0x00, 0x03, 0x47,
0x01, 0x47, 0xae, 0x00, 0x19, 0x9a, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x80, 0x00,
0x00, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0f, 0xff, 0x07, 0xc2, 0x8f,
0x00, 0x03, 0xe8, 0x08, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x01,
0x00, 0x00, 0x01, 0x01, 0x47, 0xae, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x19, 0x99, 0x9a,
0x00, 0x80, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x30, 0x00, 0x00, 0x02, 0x00, 0x00, 0x30,
0xec, 0x00, 0x00, 0x00, 0x03, 0xd7, 0x01, 0x00, 0x00, 0x08, 0x00, 0x00, 0x01, 0x00, 0x00
};
/* end binary data. size = 165 bytes */



/* Updated EQ curves, however they use the same value for table and hand */
/* begin binary data: */
char eq_data_hand[] = {/* 180 */
	0x00, 0x00, 0x01, 0xc1, 0x77, 0x0c, 0x7e, 0x7a, 0x48, 0x3f, 0x44, 0x7c, 0x81, 0x85, 0xb8, 0x3f,
	0x44, 0x7c, 0x00, 0x00, 0x01, 0xc0, 0xd5, 0x0c, 0x7f, 0x1f, 0xcc, 0x3f, 0x95, 0x78, 0x80, 0xe0,
	0x34, 0x3f, 0x95, 0x78, 0x00, 0x00, 0x01, 0xc0, 0x52, 0x00, 0x7f, 0x9f, 0x30, 0x3f, 0xd3, 0x4c,
	0x80, 0x59, 0x68, 0x3f, 0xd3, 0x4c, 0x00, 0x00, 0x01, 0xc3, 0xae, 0x8c, 0x7c, 0x35, 0x88, 0x3d,
	0x1a, 0xf0, 0x83, 0xc0, 0xec, 0x3f, 0x2c, 0xf8, 0x00, 0x00, 0x01, 0xf5, 0x04, 0xf4, 0x00, 0x00,
	0x00, 0x10, 0xba, 0x64, 0xe2, 0xd2, 0x70, 0x57, 0x6e, 0x38, 0x00, 0x00, 0x01, 0xca, 0xd0, 0xcc,
	0x74, 0x2e, 0x8c, 0x32, 0x66, 0x78, 0x8c, 0x93, 0x78, 0x43, 0x8a, 0xbc, 0x00, 0x00, 0x01, 0xc3,
	0xf4, 0xb0, 0x72, 0x9a, 0x14, 0x3b, 0x3a, 0x6c, 0x8d, 0x65, 0xec, 0x40, 0xd0, 0xe4, 0x00, 0x00,
	0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00,
	0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
	0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x40, 0x00, 0x00
};
/* end binary data. size = 664 bytes */

/* begin binary data: */
char eq_data_table[] = {/* 180 */
	0x00, 0x00, 0x01, 0xc1, 0x77, 0x0c, 0x7e, 0x7a, 0x48, 0x3f, 0x44, 0x7c, 0x81, 0x85, 0xb8, 0x3f,
	0x44, 0x7c, 0x00, 0x00, 0x01, 0xc0, 0xd5, 0x0c, 0x7f, 0x1f, 0xcc, 0x3f, 0x95, 0x78, 0x80, 0xe0,
	0x34, 0x3f, 0x95, 0x78, 0x00, 0x00, 0x01, 0xc0, 0x52, 0x00, 0x7f, 0x9f, 0x30, 0x3f, 0xd3, 0x4c,
	0x80, 0x59, 0x68, 0x3f, 0xd3, 0x4c, 0x00, 0x00, 0x01, 0xc3, 0xae, 0x8c, 0x7c, 0x35, 0x88, 0x3d,
	0x1a, 0xf0, 0x83, 0xc0, 0xec, 0x3f, 0x2c, 0xf8, 0x00, 0x00, 0x01, 0xf5, 0x04, 0xf4, 0x00, 0x00,
	0x00, 0x10, 0xba, 0x64, 0xe2, 0xd2, 0x70, 0x57, 0x6e, 0x38, 0x00, 0x00, 0x01, 0xca, 0xd0, 0xcc,
	0x74, 0x2e, 0x8c, 0x33, 0x33, 0xf0, 0x8c, 0x51, 0x2c, 0x42, 0x7a, 0xf8, 0x00, 0x00, 0x01, 0xc3,
	0xf4, 0xb0, 0x72, 0x9a, 0x14, 0x3b, 0x3a, 0x6c, 0x8d, 0x65, 0xec, 0x40, 0xd0, 0xe4, 0x00, 0x00,
	0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00,
	0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
	0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x40, 0x00, 0x00
};
/* end binary data. size = 180 bytes */

#if 0
/* begin binary data: */
char preset_data_default[] = {/* 87 */
	0x00, 0x00, 0x01, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x40, 0x00,
	0x00, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x47, 0xae, 0x00, 0x2b, 0xb1, 0x00, 0x00, 0x9d, 0x00, 0x0d,
	0x1b, 0x01, 0x00, 0x00, 0x07, 0x00, 0x00, 0x0c, 0x80, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00,
	0x00, 0xc0, 0x00, 0x00, 0x59, 0x9a, 0x00, 0x0c, 0xcd, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x48, 0x00, 0x01, 0x48, 0x08, 0x00, 0x00, 0x07, 0xc2,
	0x8f, 0x00, 0x0c, 0xcd, 0x00, 0x00, 0x03
};
/* end binary data. size = 87 bytes */
#else
/* begin binary data: */
char preset_data_default[] = {/* 87 */
	0x00, 0x00, 0x01, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x40, 0x00,
	0x00, 0x00, 0x00, 0x01, 0x2c, 0x01, 0x47, 0xae, 0x00, 0x2b, 0xb1, 0x00, 0x00, 0x9d, 0x00, 0x0d,
	0x1b, 0x01, 0x00, 0x00, 0x01, 0x80, 0x00, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00,
	0x00, 0xc0, 0x00, 0x00, 0x59, 0x9a, 0x00, 0x0c, 0xcd, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x48, 0x00, 0x01, 0x48, 0x08, 0x00, 0x00, 0x07, 0xc2,
	0x8f, 0x00, 0x0c, 0xcd, 0x00, 0x00, 0x03
};
/* end binary data. size = 87 bytes */
#endif


/* begin binary data: */
char preset_data0[] = {/* 87 */
0x00, 0x00, 0x07, 0x00, 0x01, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x40
, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2C, 0x01, 0x47, 0xAE, 0x00, 0x2B, 0xB1, 0x00, 0x00, 0x9D
, 0x00, 0x0D, 0x1B, 0x01, 0x00, 0x00, 0x07, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x08, 0x00, 0x00
, 0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x40, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x48, 0x00, 0x01, 0x48
, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x00, 0x03
};
/* end binary data. size = 87 bytes */

/* begin binary data: */
char preset_data1[] = {/* 87 */
0x00, 0x00, 0x07, 0x00, 0x01, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x40
, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2C, 0x01, 0x47, 0xAE, 0x00, 0x2B, 0xB1, 0x00, 0x00, 0x9D
, 0x00, 0x0D, 0x1B, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00
, 0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x40, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x48, 0x00, 0x01, 0x48
, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x00, 0x03
};
/* end binary data. size = 87 bytes */

char preset_data2[] = {/* 87 */
0x00, 0x00, 0x07, 0x00, 0x01, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x40
, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2C, 0x01, 0x47, 0xAE, 0x00, 0x2B, 0xB1, 0x00, 0x00, 0x9D
, 0x00, 0x0D, 0x1B, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x05, 0x00, 0x00, 0x08, 0x00, 0x00
, 0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x40, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x48, 0x00, 0x01, 0x48
, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x00, 0x03
};
/* end binary data. size = 87 bytes */

/* begin binary data: */
char preset_data3[] = {/* 87 */
0x00, 0x00, 0x07, 0x00, 0x01, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x40
, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2C, 0x01, 0x47, 0xAE, 0x00, 0x2B, 0xB1, 0x00, 0x00, 0x9D
, 0x00, 0x0D, 0x1B, 0x01, 0x00, 0x00, 0x01, 0x80, 0x00, 0x04, 0x00, 0x00, 0x08, 0x00, 0x00
, 0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x40, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x48, 0x00, 0x01, 0x48
, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x00, 0x03
};
/* end binary data. size = 87 bytes */

/* begin binary data: */
char preset_data4[] = {/* 87 */
0x00, 0x00, 0x07, 0x00, 0x01, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x40
, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2C, 0x01, 0x47, 0xAE, 0x00, 0x2B, 0xB1, 0x00, 0x00, 0x9D
, 0x00, 0x0D, 0x1B, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x08, 0x00, 0x00
, 0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x40, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x48, 0x00, 0x01, 0x48
, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0C, 0xCD, 0x00, 0x00, 0x03
};
/* end binary data. size = 87 bytes */

void convertBytes2Data(int num_bytes, const unsigned char bytes[], int data[])
{
        int i; /* index for data */
        int k; /* index for bytes */
        int d;
        int num_data = num_bytes/3;

        for (i = 0, k = 0; i < num_data; ++i, k += 3) {
                d = (bytes[k] << 16) | (bytes[k+1] << 8) | (bytes[k+2]);
                if (bytes[k] & 0x80) {/* sign bit was set*/
                        d = - ((1<<24)-d);
                }
                data[i] = d;
        }
}

int ProcessPatchFile(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte, int length, const unsigned char* bytes)
{
	unsigned int size;
	int index = 0;
	unsigned char buffer[MAX_I2C_LENGTH];
	int error;
        int value = 0;
        unsigned int status;
	error = Tfa9887_ReadRegister(tfa9887, TFA9887_STATUS, &status);
	if (error == Tfa9887_Error_Ok) {
		if ( (status & 0x0043) != 0x0043) {
			/* one of Vddd, PLL and clocks not ok */
			error = -1;
		}
	}
	//pr_info("tfa status %u\n",status);
	error = DspReadMem(tfa9887, tfa9887_byte, 0x2210, 1, &value);
	//pr_info("tfa Version  %x\n",value);
	while (index < length) {
		/* extract little endian length */
	 	size = bytes[index] + bytes[index+1] * 256;
		index += 2;
		if ( (index + size) > length) {
			/* too big, outside the buffer, error in the input data */
			return -1;
		}
		memcpy(buffer, bytes + index, size);
		error = regmap_raw_write(tfa9887_byte->regmap, buffer[0], &buffer[1] , (size -1));
		//pr_info("%d %d\n",buffer[0],size -1);
		if (error != Tfa9887_Error_Ok) {
			pr_info("ProcessPatchFile error\n");
			break;
		}
	 	index += size;
	}
	return error;
}

int DspReadMem(struct tfa9887_priv *tfa9887,  struct tfa9887_priv *tfa9887_byte, unsigned short start_offset, int num_words, int *pValues)
{
	unsigned int cf_ctrl; /* the value to sent to the CF_CONTROLS register */
	unsigned char bytes[MAX_I2C_LENGTH];
	int burst_size; /* number of words per burst size */
	int bytes_per_word=3;
	int num_bytes;
	int* p;
	int error;
	/* first set DMEM and AIF, leaving other bits intact */
	error = Tfa9887_ReadRegister(tfa9887, TFA9887_CF_CONTROLS, &cf_ctrl);
	if (error != Tfa9887_Error_Ok) {
		return error;
	}
	cf_ctrl &= ~0x000E; /* clear AIF & DMEM */
	cf_ctrl |= (Tfa9887_DMEM_XMEM<<1); /* set DMEM, leave AIF cleared for autoincrement */
	error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_CONTROLS, cf_ctrl);
	if (error != Tfa9887_Error_Ok) {
		return error;
	}
	error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_MAD, start_offset);
	if (error != Tfa9887_Error_Ok) {
		return error;
	}
	num_bytes = num_words*bytes_per_word;
	p=pValues;
	for (; num_bytes > 0; ) {
		burst_size = ROUND_DOWN(MAX_I2C_LENGTH, bytes_per_word);
		if (num_bytes < burst_size) {
	 		burst_size = num_bytes;
		}

		error = regmap_raw_read(tfa9887_byte->regmap, TFA9887_CF_MEM, bytes,burst_size);
		if (error != Tfa9887_Error_Ok) {
			return error;
		}
		convertBytes2Data(burst_size, bytes, p);
		num_bytes -= burst_size;
		p += burst_size/bytes_per_word;
	}
	return Tfa9887_Error_Ok;
}

int DspSetParam(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte, unsigned char module_id, unsigned char param_id, int num_bytes, const unsigned char *data)
{

	int error;
	unsigned int cf_ctrl = 0x0002; /* the value to be sent to the CF_CONTROLS register: cf_req=00000000, cf_int=0, cf_aif=0, cf_dmem=XMEM=01, cf_rst_dsp=0 */
	unsigned int cf_mad = 0x0001; /* memory address to be accessed (0 : Status, 1 : ID, 2 : parameters) */
	unsigned int cf_status; /* the contents of the CF_STATUS register */
	unsigned char mem[3];
	int rpcStatus = STATUS_OK;
	int tries = 0;

	error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_CONTROLS, cf_ctrl);
	if (error == Tfa9887_Error_Ok) {
		error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_MAD, cf_mad);
	}
	if (error == Tfa9887_Error_Ok) {
		unsigned char id[3];
		id[0] = 0;
		id[1] = module_id+128;
		id[2] = param_id;
		error = regmap_raw_write(tfa9887_byte->regmap, TFA9887_CF_MEM,&id, 3);
	}

	error = regmap_raw_write(tfa9887_byte->regmap, TFA9887_CF_MEM, data, num_bytes);

	if (error == Tfa9887_Error_Ok) {
		cf_ctrl |= (1<<8) | (1<<4); /* set the cf_req1 and cf_int bit */
		error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_CONTROLS, cf_ctrl);

		do {
			error = Tfa9887_ReadRegister(tfa9887, TFA9887_CF_STATUS, &cf_status);
	 		tries++;
	 		usleep_range(100, 200);
		} while ((error == Tfa9887_Error_Ok) && ((cf_status & 0x0100) == 0) && (tries < 100)); /* don't wait forever, DSP is pretty quick to respond (< 1ms) */

		if (tries >= 100 && !powerDown) {
	 		/* something wrong with communication with DSP */
			pr_info("Setparam failed\n");
			error = -1;
		}
	}
	cf_ctrl = 0x0002;
	cf_mad = 0x0000;
	if (error == Tfa9887_Error_Ok) {
		error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_CONTROLS,cf_ctrl);
    }

    if (error == Tfa9887_Error_Ok) {
            error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_MAD, cf_mad);
    }
    if (error == Tfa9887_Error_Ok) {
		error = regmap_raw_read(tfa9887_byte->regmap, TFA9887_CF_MEM,&mem,3);
		rpcStatus = (int)((mem[0] << 16) | (mem[1] << 8) | mem[2]);
    }
    if (error == Tfa9887_Error_Ok) {
		if (rpcStatus != STATUS_OK) {
			error = rpcStatus+100;
			//pr_info("RPC rpcStatus =%d\n",error);
		}
    }
	return error;
}

int DspGetParam(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte,
			unsigned char module_id, unsigned char param_id, int num_bytes, unsigned char *data)
{
        int error;
        unsigned int cf_ctrl = 0x0002;        /* the value to be sent to the CF_CONTROLS register: cf_req=00000000, cf_int=0, cf_aif=0, cf_dmem=XMEM=01, cf_rst_dsp=0 */
        unsigned int cf_mad = 0x0001; /* memory address to be accessed (0 : Status, 1 : ID, 2 : parameters) */
        unsigned int cf_status;       /* the contents of the CF_STATUS register */
		unsigned char mem[3];
		unsigned char id[3];
		int tries = 0;
        /* 1) write the id and data to the DSP XMEM */
                error =
                    Tfa9887_WriteRegister(tfa9887, TFA9887_CF_CONTROLS,
                                            cf_ctrl);
                error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_MAD, cf_mad);
                id[0] = 0;
                id[1] = module_id + 128;
                id[2] = param_id;
                /* only try MEM once, if error, need to resend mad as well */
                error = regmap_raw_write(tfa9887_byte->regmap, TFA9887_CF_MEM, id, 3);
        /* 2) wake up the DSP and let it process the data */
        if (error == 0) {
                cf_ctrl |= (1 << 8) | (1 << 4); /* set the cf_req1 and cf_int bit */
                error =
                    Tfa9887_WriteRegister(tfa9887, TFA9887_CF_CONTROLS,
                                            cf_ctrl);
        }
        /* 3) wait for the ack */
        if (error == Tfa9887_Error_Ok) {
                do {
                        error =
                            Tfa9887_ReadRegister(tfa9887, TFA9887_CF_STATUS,
                                                   &cf_status);
			msleep(1);
                        tries++;
                } while (( error == 0) && ((cf_status & 0x0100) == 0)
			&& (tries < 100));     /* don't wait forever, DSP is pretty quick to respond (< 1ms) */
                if (tries >= 100) {
                        /* something wrong with communication with DSP */
			pr_info("GetParam failed\n");
                        return -1;
                }
        }
        /* 4) check the RPC return value */
        cf_ctrl = 0x0002;
        cf_mad = 0x0000;
        if (error == Tfa9887_Error_Ok) {
                error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_CONTROLS,cf_ctrl);
        }
        if (error == Tfa9887_Error_Ok) {
                error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_MAD, cf_mad);
        }
        if (error == Tfa9887_Error_Ok) {
                    regmap_raw_read(tfa9887_byte->regmap, TFA9887_CF_MEM,&mem,3);
                error = (mem[0] << 16) | (mem[1] << 8) | mem[2];

        }
        if (error != Tfa9887_Error_Ok) {
                pr_info("RPC error\n");

        }

        /* 5) read the resulting data */
        if (error == 0) {
                cf_mad = 0x0002;        /* memory address to be accessed (0 : Status, 1 : ID, 2 : parameters) */
                error = Tfa9887_WriteRegister(tfa9887, TFA9887_CF_MAD, cf_mad);
        }
        if (error == 0) {
                        error =
                            regmap_raw_read(tfa9887_byte->regmap, TFA9887_CF_MEM, data, num_bytes);
                }
        return error;
}

int Tfa9887_WriteRegister(struct tfa9887_priv *tfa9887, unsigned int subaddress, unsigned int value)
{
	 int error = regmap_write(tfa9887->regmap,subaddress,value);
	 return error;
}

int Tfa9887_ReadRegister(struct tfa9887_priv *tfa9887, unsigned int subaddress, unsigned int* pValue)
{
	 int error = regmap_read(tfa9887->regmap,subaddress,pValue);
	 return error;
}

void calibrate (struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte, char *calibdata)
{

	int error;
	int calibrateDone;
	unsigned int status, value;
	unsigned char bytes[3];
	int data[2];
	int tries = 0;

	if (!recalibration) {
		SetMute(tfa9887, Tfa9887_Mute_Digital);
		pr_info("Inside calib\n");
	        while ((calibrateDone == 0) && (tries < 100)) {
			error = DspReadMem(tfa9887, tfa9887_byte, 231, 1, &calibrateDone);
			msleep(10);
			tries++;
	        }

		if (calibrateDone)
		{
			DspGetParam(tfa9887, tfa9887_byte, MODULE_SPEAKERBOOST, PARAM_GET_RE0, 3, bytes);
			convertBytes2Data(3, bytes, &data[0]);
		}
		tfa9887->speaker_data[420] = 0;
		tfa9887->speaker_data[421] = 0;
		tfa9887->speaker_data[422] = 0;
		error = loadSettings(tfa9887, tfa9887_byte);
	}
	calibrateDone = 0;
	tries = 0;
	/*SetConfigured*/
	error = Tfa9887_ReadRegister(tfa9887, TFA9887_SYSTEM_CONTROL, &value);

	if (error == Tfa9887_Error_Ok) {

                value |= TFA9887_SYSCTRL_CONFIGURED;
                error = Tfa9887_WriteRegister(tfa9887, TFA9887_SYSTEM_CONTROL, value);
	}
	calibrateDone = 0;
	tries = 0;


	error = DspReadMem(tfa9887, tfa9887_byte, 231, 1, &calibrateDone);
	while ((calibrateDone == 0) && (tries < 100)) {
		error = DspReadMem(tfa9887, tfa9887_byte, 231, 1, &calibrateDone);
		msleep(10);
		tries++;
	}
	if(tries >= 100)
		pr_info("Calibrate failed1\n");

	calibrateDone = 0;
	tries = 0;

	do {
		error = Tfa9887_ReadRegister(tfa9887, TFA9887_STATUS, &status);
		msleep(10);
		tries++;
	} while ( ((status & TFA9887_STATUS_MTPB) == TFA9887_STATUS_MTPB) && (tries < 100));
	if (tries >= 100)
		pr_info("Calibrate failed2\n");

	calibrateDone = 0;
	tries = 0;
	while ((calibrateDone == 0) && (tries < 100)) {
                error = DspReadMem(tfa9887, tfa9887_byte, 231, 1, &calibrateDone);
		msleep(10);
                tries++;
	}
	if (tries >= 100)
		pr_info("Calibrate failed3\n");

	DspGetParam(tfa9887, tfa9887_byte, MODULE_SPEAKERBOOST, PARAM_GET_RE0, 3, bytes);
	convertBytes2Data(3, bytes, &data[0]);
	DspReadMem(tfa9887, tfa9887_byte, 232, 1, &data[1]);
	pr_info("%d %d\n",data[0], data[1]);
	memcpy(calibdata, (char *)data, 8);
}

void resetMtpEx(struct tfa9887_priv *tfa9887)
{
	int err;
	unsigned int mtp, status;
	int tries = 0;
	err = Tfa9887_ReadRegister(tfa9887, TFA9887_MTP, &mtp);

	pr_info("%d****************mtp",mtp);
	/* all settings loaded, signal the DSP to start calibration, only needed once after cold boot */
	/* reset MTPEX bit if needed */
	err = Tfa9887_WriteRegister(tfa9887, 0x0B, 0x5A); /* unlock key2 */
	err = Tfa9887_WriteRegister(tfa9887, TFA9887_MTP, 1); /* MTPOTC=1, MTPEX=0 */

	err = Tfa9887_WriteRegister(tfa9887, 0x62, 1<<11); /* CIMTP=1 */

        do {
                err = Tfa9887_ReadRegister(tfa9887, TFA9887_STATUS, &status);
		msleep(10);
		tries++;
        } while ( ((status & TFA9887_STATUS_MTPB) == TFA9887_STATUS_MTPB) && (tries < 100));

}

int checkMTPEX(struct tfa9887_priv *tfa9887)
{
	unsigned int mtp;
	int err;

	err = Tfa9887_ReadRegister(tfa9887, TFA9887_MTP, &mtp);
	if ( mtp & (1<<1))	/* check MTP bit1 (MTPEX) */
		return 1;					/* MTPEX is 1, calibration is done */
	else
		return 0;					/* MTPEX is 0, calibration is not done yet */
}

int Tfa9887_Init(int sRate)
{
	int error = 0;
	srate = sRate;
	if (tfa9887R) {
		mutex_lock(&tfa9887R->lock);
		if (tfa9887R->deviceInit) {
			coldStartup(tfa9887R, tfa9887R_byte, srate);
			//Tfa9887_WriteRegister(tfa9887R, 0x0B, 0x5A); /* unlock key2 */
			//Tfa9887_WriteRegister(tfa9887R, TFA9887_MTP, 0); /* MTPOTC=1, MTPEX=0 */
			setOtc(tfa9887R,1);

			if((checkMTPEX(tfa9887R) == 0)) {
				calibration = 1;
				calibrate(tfa9887R, tfa9887R_byte, &calibdata[0]);
			}
			else {
				error = Init(tfa9887R,tfa9887R_byte, sRate);

			}
		}
		mutex_unlock(&tfa9887R->lock);
	}

	if (tfa9887L) {
		mutex_lock(&tfa9887L->lock);
		if (tfa9887L->deviceInit) {
			coldStartup(tfa9887L, tfa9887L_byte, srate);
			//Tfa9887_WriteRegister(tfa9887L, 0x0B, 0x5A); /* unlock key2 */
			//Tfa9887_WriteRegister(tfa9887L, TFA9887_MTP, 0); /* MTPOTC=1, MTPEX=0 */
			setOtc(tfa9887L,1);

			if((checkMTPEX(tfa9887L) == 0)) {
				calibration = 1;
				calibrate(tfa9887L, tfa9887L_byte, &calibdata[8]);
			}
			else {
				error = Init(tfa9887L,tfa9887L_byte, sRate);

			}
		}
		mutex_unlock(&tfa9887L->lock);
	}
        if (error != 0)
		pr_info("Failed to Init tfa\n");
	return error;
}

void setOtc(struct tfa9887_priv *tfa9887, unsigned short otcOn)
{

	int err;
	unsigned int mtp;
	unsigned int status;
	int mtpChanged = 0;
	int tries = 0;

	err = Tfa9887_ReadRegister(tfa9887, TFA9887_MTP, &mtp);
	/* set reset MTPEX bit if needed */
	if ( (mtp & TFA9887_MTP_MTPOTC) != otcOn) {
	/* need to change the OTC bit, set MTPEX=0 in any case */
		err = Tfa9887_WriteRegister(tfa9887, 0x0B, 0x5A); /* unlock key2 */

		err = Tfa9887_WriteRegister(tfa9887, TFA9887_MTP, otcOn); /* MTPOTC=otcOn, MTPEX=0 */

		err = Tfa9887_WriteRegister(tfa9887, 0x62, 1<<11); /* CIMTP=1 */

		mtpChanged =1;

	}
	//Sleep(13*16); /* need to wait until all parameters are copied into MTP */
	do {
		err = Tfa9887_ReadRegister(tfa9887, TFA9887_STATUS, &status);
		msleep(10);
		tries++;
	} while ( ((status & TFA9887_STATUS_MTPB) == TFA9887_STATUS_MTPB) && (tries < 100));

	if (mtpChanged) {
		/* ensure the DSP restarts after this to read out the new value */
		err = Tfa9887_WriteRegister(tfa9887, 0x70, 0x1); /* DSP reset */
	}

}

int Tfa9887_SetEq(void)
{
	int error = 0;

	if (tfa9887R) {
		mutex_lock(&tfa9887R->lock);
		if (tfa9887R->deviceInit)
			error = SetEq(tfa9887R, tfa9887R_byte);
		mutex_unlock(&tfa9887R->lock);
	}

	if (tfa9887L) {
		mutex_lock(&tfa9887L->lock);
		if (tfa9887L->deviceInit)
			error = SetEq(tfa9887L, tfa9887L_byte);
		mutex_unlock(&tfa9887L->lock);
	}
	return error;
}

int Tfa9887_SetVolume(unsigned int index)
{
	int error = 0;
	vol_index = index;

	if (tfa9887R) {
		mutex_lock(&tfa9887R->lock);
		if (tfa9887R->deviceInit) {
			if (index == MAX_DB_INDEX)
				SetMute(tfa9887R, Tfa9887_Mute_Amplifier);
			else
				SetMute(tfa9887R, Tfa9887_Mute_Off);
			error = SetPreset(tfa9887R, tfa9887R_byte);
		}
		mutex_unlock(&tfa9887R->lock);
	}

	if (tfa9887L) {
		mutex_lock(&tfa9887L->lock);
		if (tfa9887L->deviceInit) {
			if (index == MAX_DB_INDEX)
				SetMute(tfa9887L, Tfa9887_Mute_Amplifier);
			else
				SetMute(tfa9887L, Tfa9887_Mute_Off);
			error = SetPreset(tfa9887L, tfa9887L_byte);
		}
		mutex_unlock(&tfa9887L->lock);
	}
	return error;
}

int coldStartup(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte, int sRate)
{
	int error,volume_value;
	unsigned int value;
	int tries = 0;
        error = Tfa9887_WriteRegister(tfa9887, 0x09, 0x0002);
        if (Tfa9887_Error_Ok == error) {
                error = Tfa9887_ReadRegister(tfa9887, 0x09, &value);
        }
        if (Tfa9887_Error_Ok == error) {
                /* DSP must be in control of the amplifier to avoid plops */
                value |= TFA9887_SYSCTRL_SEL_ENBL_AMP;
                error = Tfa9887_WriteRegister(tfa9887, 0x09, value);
        }

        /* some other registers must be set for optimal amplifier behaviour */
        if (Tfa9887_Error_Ok == error) {
                error = Tfa9887_WriteRegister(tfa9887, 0x40, 0x5A6B);
        }
        if (Tfa9887_Error_Ok == error) {
                error = Tfa9887_WriteRegister(tfa9887, 0x05, 0x13AB);
        }
        if (Tfa9887_Error_Ok == error) {
                error = Tfa9887_WriteRegister(tfa9887, 0x06, 0x001F);
        }
        if (Tfa9887_Error_Ok == error) {
                error = Tfa9887_WriteRegister(tfa9887,
                TFA9887_SPKR_CALIBRATION, 0x3C4E); /*  adjusted to mandatory defaults */
        }
        if (Tfa9887_Error_Ok == error) {
                error = Tfa9887_WriteRegister(tfa9887, 0x09, 0x025D);
        }
        if (Tfa9887_Error_Ok == error) {
                error = Tfa9887_WriteRegister(tfa9887, 0x0A, 0x3EC3);
        }
        if (Tfa9887_Error_Ok == error) {
                error = Tfa9887_WriteRegister(tfa9887, 0x41, 0x0308);
        }
        if (Tfa9887_Error_Ok == error) {
                error = Tfa9887_WriteRegister(tfa9887, 0x48, 0x0180);
        }
        if (Tfa9887_Error_Ok == error) {
                error = Tfa9887_WriteRegister(tfa9887, 0x49, 0x0E82);
        }
        if (Tfa9887_Error_Ok == error) {
                error = Tfa9887_WriteRegister(tfa9887, 0x52, 0x0000);
        }
        if (Tfa9887_Error_Ok == error) {
                error = Tfa9887_WriteRegister(tfa9887, 0x40, 0x0000);
        }
        //Set Sampling Frequency
        error = Tfa9887_ReadRegister(tfa9887, TFA9887_I2S_CONTROL, &value);
        if (error == Tfa9887_Error_Ok) {
                // clear the 4 bits first
                value &= (~(0xF<<TFA9887_I2SCTRL_RATE_SHIFT));
                switch (sRate) {
                case 48000:
                        value |= TFA9887_I2SCTRL_RATE_48000;
                        break;
                case 44100:
                        value |= TFA9887_I2SCTRL_RATE_44100;
                        break;
                case 32000:
                        value |= TFA9887_I2SCTRL_RATE_32000;
                        break;
                case 24000:
                        value |= TFA9887_I2SCTRL_RATE_24000;
                        break;
                case 22050:
                        value |= TFA9887_I2SCTRL_RATE_22050;
                        break;
                case 16000:
                        value |= TFA9887_I2SCTRL_RATE_16000;
                        break;
                case 12000:
                        value |= TFA9887_I2SCTRL_RATE_12000;
                        break;
                case 11025:
                        value |= TFA9887_I2SCTRL_RATE_11025;
                        break;
                case 8000:
                        value |= TFA9887_I2SCTRL_RATE_08000;
                        break;
                default:
			pr_info("unsupported samplerate\n");
                        error = -1;
			return error;
                }
                error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_CONTROL, value);
        }
	volume_value = volume_step[PRESET_DEFAULT];
	error = Tfa9887_ReadRegister(tfa9887, TFA9887_AUDIO_CONTROL, &value);
	if(error == Tfa9887_Error_Ok) {
		value = (value&0x00FF) | (unsigned int)(volume_value<<8);
		error = Tfa9887_WriteRegister(tfa9887, TFA9887_AUDIO_CONTROL, value);
	}
        //PowerUp
	error = Tfa9887_ReadRegister(tfa9887, TFA9887_SYSTEM_CONTROL, &value);
        if(error == Tfa9887_Error_Ok) {
                value &= ~(TFA9887_SYSCTRL_POWERDOWN);
                error = Tfa9887_WriteRegister(tfa9887, TFA9887_SYSTEM_CONTROL, value);
        }

		//Waiting for IC to startup
		error = Tfa9887_ReadRegister(tfa9887, TFA9887_STATUS, &value);
		do {
			error = Tfa9887_ReadRegister(tfa9887, TFA9887_STATUS, &value);
			msleep(1);
			tries++;
		} while ((error == Tfa9887_Error_Ok) && ((value & TFA9887_STATUS_PLLS) == 0) && (tries < 100));

        //Firmware
        error = ProcessPatchFile(tfa9887, tfa9887_byte, 10, coldpatch_data);
		error = Tfa9887_ReadRegister(tfa9887, TFA9887_STATUS, &value);
		if(value & TFA9887_STATUS_ACS)
			//pr_info("TFA COLD BOOTED\n");
        error = ProcessPatchFile(tfa9887, tfa9887_byte, sizeof(n1d2_data), n1d2_data);

	return error;
}

int Init(struct tfa9887_priv *tfa9887,struct tfa9887_priv *tfa9887_byte, int sRate)
{
	int error;
	unsigned int value;

        error = loadSettings(tfa9887, tfa9887_byte);
        if(error != Tfa9887_Error_Ok) {
                pr_info("Loading Settings Failed\n");
        }

        error = stereoRouting(tfa9887);

        if(error != Tfa9887_Error_Ok) {
                pr_info("Stereo routing Failed\n");
        }

         //SetConfigured
        error = Tfa9887_ReadRegister(tfa9887, TFA9887_SYSTEM_CONTROL, &value);
        if(error == Tfa9887_Error_Ok)
        {
                value |= TFA9887_SYSCTRL_CONFIGURED;
                error = Tfa9887_WriteRegister(tfa9887, TFA9887_SYSTEM_CONTROL, value);
        }
	if (!calibration) {
		SetMute(tfa9887, Tfa9887_Mute_Amplifier);
		//PowerDown
		if(error == Tfa9887_Error_Ok)
		{
			error = Tfa9887_ReadRegister(tfa9887, TFA9887_SYSTEM_CONTROL, &value);
			value |= TFA9887_SYSCTRL_POWERDOWN;
			error = Tfa9887_WriteRegister(tfa9887, TFA9887_SYSTEM_CONTROL, value);
		}
	}

        return error;
}

int SetEq(struct tfa9887_priv *tfa9887,struct tfa9887_priv *tfa9887_byte)
{
	int error = 0;
	if (eq_mode == IN_HAND_MODE) {
		//pr_info("Setting hand mode\n");
		error = DspSetParam(tfa9887,tfa9887_byte, MODULE_BIQUADFILTERBANK,0, 180, eq_data_hand);
	} else if (eq_mode == ON_DESK_MODE) {
		//pr_info("setting deskmode\n");
		error = DspSetParam(tfa9887,tfa9887_byte, MODULE_BIQUADFILTERBANK,0, 180, eq_data_table);
	}
	return error;
}

int SetPreset(struct tfa9887_priv *tfa9887,struct tfa9887_priv *tfa9887_byte)
{
	int error = 0;
	unsigned int value = 0;
	unsigned int volume_value = 0;

	if (!preset_mode) {
		error = DspSetParam(tfa9887,tfa9887_byte, MODULE_SPEAKERBOOST, PARAM_SET_PRESET, 87, preset_data_default);
		preset_mode = 1;
	}

	volume_value = volume_curve[vol_index];
	error = Tfa9887_ReadRegister(tfa9887, TFA9887_AUDIO_CONTROL, &value);
    if(error == Tfa9887_Error_Ok) {
            value = (value&0x00FF) | (unsigned int)(volume_value<<8);
            error = Tfa9887_WriteRegister(tfa9887, TFA9887_AUDIO_CONTROL, value);
    }
	return error;
}

int loadSettings(struct tfa9887_priv *tfa9887,struct tfa9887_priv *tfa9887_byte)
{
	int error;
        //Load settings
        error = DspSetParam(tfa9887,tfa9887_byte,MODULE_SPEAKERBOOST, PARAM_SET_LSMODEL, 423, tfa9887->speaker_data);
        error = DspSetParam(tfa9887,tfa9887_byte, MODULE_SPEAKERBOOST, PARAM_SET_CONFIG, 165, config_data);
        preset_mode = 0;
		SetPreset(tfa9887,tfa9887_byte);
		SetEq(tfa9887,tfa9887_byte);
	return error;
}

int stereoRouting(struct tfa9887_priv *tfa9887)
{
        int error;
        unsigned int value;
        if(tfa9887 == tfa9887L) {
                //select channel
                error = Tfa9887_ReadRegister(tfa9887, TFA9887_I2S_CONTROL, &value);
                // clear the 2 bits first
                value &= ~(0x3<<TFA9887_I2SCTRL_CHANSEL_SHIFT);

                value |=(1<<TFA9887_I2SCTRL_CHANSEL_SHIFT);
                error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_CONTROL, value);

                //select ouput left for gain
                error = Tfa9887_ReadRegister(tfa9887, TFA9887_I2S_SEL, &value);
                value &= ~(0x7<<TFA9887_I2SSEL_I2SOUT_LEFT_SHIFT);
                value |=(1<<TFA9887_I2SSEL_I2SOUT_LEFT_SHIFT);
                error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_SEL, value);
                //Select stereo gain
                error = Tfa9887_ReadRegister(tfa9887, TFA9887_I2S_CONTROL, &value);
                value &= ~(0x1<<TFA9887_I2SCTRL_DATAI2_SHIFT);
                value |=(1<<TFA9887_I2SCTRL_DATAI2_SHIFT);
                error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_CONTROL, value);

                //select output right for current sense
                error = Tfa9887_ReadRegister(tfa9887, TFA9887_I2S_SEL, &value);
                value &= ~(0x7<<TFA9887_I2SSEL_I2SOUT_RIGHT_SHIFT);
                value |=(0<<TFA9887_I2SSEL_I2SOUT_RIGHT_SHIFT);
                error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_SEL, value);
                error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_SEL, value);
                //pr_info("Tfa inside left\n");

         }
         else if (tfa9887 == tfa9887R) {
                // clear the 2 bits first
                error = Tfa9887_ReadRegister(tfa9887, TFA9887_I2S_CONTROL, &value);
                value &= ~(0x3<<TFA9887_I2SCTRL_CHANSEL_SHIFT);

                value |=(2<<TFA9887_I2SCTRL_CHANSEL_SHIFT);
                error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_CONTROL, value);

                error = Tfa9887_ReadRegister(tfa9887, TFA9887_I2S_SEL, &value);
                value &= ~(0x7<<TFA9887_I2SSEL_I2SOUT_RIGHT_SHIFT);
                value |=(1<<TFA9887_I2SSEL_I2SOUT_RIGHT_SHIFT);
                error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_SEL, value);

                error = Tfa9887_ReadRegister(tfa9887, TFA9887_I2S_CONTROL, &value);
                value &= ~(0x1<<TFA9887_I2SCTRL_DATAI2_SHIFT);
                value |=(0<<TFA9887_I2SCTRL_DATAI2_SHIFT);
                error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_CONTROL, value);

                error = Tfa9887_ReadRegister(tfa9887, TFA9887_I2S_SEL, &value);
                value &= ~(0x7<<TFA9887_I2SSEL_I2SOUT_LEFT_SHIFT);
                value |=(0<<TFA9887_I2SSEL_I2SOUT_LEFT_SHIFT);
                error = Tfa9887_WriteRegister(tfa9887, TFA9887_I2S_SEL, value);
                //pr_info("tfa inside right\n");

        }
        else
        {
		error = -1;
	}
	return error;
}

int Tfa9887_Powerdown(int powerdown)
{
	int error = 0;

	powerDown = powerdown;

	if (tfa9887R) {
		mutex_lock(&tfa9887R->lock);
		if (tfa9887R->deviceInit)
			error = Powerdown(tfa9887R, tfa9887R_byte, powerdown);
		mutex_unlock(&tfa9887R->lock);
	}

	if (tfa9887L) {
		mutex_lock(&tfa9887L->lock);
		if (tfa9887L->deviceInit)
			error = Powerdown(tfa9887L, tfa9887L_byte, powerdown);
		mutex_unlock(&tfa9887L->lock);
	}
	return error;
}

EXPORT_SYMBOL(Tfa9887_Powerdown);

int Powerdown(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte, int powerdown)
{
	int error;
	unsigned int audioctrl_value = 0;
	unsigned int sysctrl_value = 0;

	/* read the SystemControl register, modify the bit and write again */
	error = Tfa9887_ReadRegister(tfa9887, TFA9887_SYSTEM_CONTROL, &sysctrl_value);
	if (error != Tfa9887_Error_Ok)
		return error;

	switch(powerdown) {
		case 1:
			sysctrl_value &= ~TFA9887_SYSCTRL_ENBL_AMP;
			sysctrl_value |= TFA9887_SYSCTRL_SEL_ENBL_AMP;
			error = Tfa9887_WriteRegister(tfa9887, TFA9887_SYSTEM_CONTROL,
										sysctrl_value);
			msleep(50);
			sysctrl_value |= TFA9887_SYSCTRL_POWERDOWN;
			error = Tfa9887_WriteRegister(tfa9887, TFA9887_SYSTEM_CONTROL,
											sysctrl_value);
			msleep(10);
			break;
		case 0:
			sysctrl_value |= TFA9887_SYSCTRL_ENBL_AMP;
			sysctrl_value |= TFA9887_SYSCTRL_SEL_ENBL_AMP;
			sysctrl_value &= ~(TFA9887_SYSCTRL_POWERDOWN);
			error = Tfa9887_WriteRegister(tfa9887, TFA9887_SYSTEM_CONTROL,
											sysctrl_value);
			error = Tfa9887_ReadRegister(tfa9887, TFA9887_AUDIO_CONTROL,
											&audioctrl_value);
			if (error != Tfa9887_Error_Ok)
				return error;
			audioctrl_value |= TFA9887_AUDIOCTRL_MUTE;
			Tfa9887_WriteRegister(tfa9887, TFA9887_AUDIO_CONTROL,
									audioctrl_value);
			preset_mode = 0;
			SetPreset(tfa9887,tfa9887_byte);
			SetEq(tfa9887,tfa9887_byte);
			audioctrl_value &= ~(TFA9887_AUDIOCTRL_MUTE);
			Tfa9887_WriteRegister(tfa9887, TFA9887_AUDIO_CONTROL,
									audioctrl_value);
			break;
		default:
			error = -1;
			break;
	}
	return error;
}

int SetMute(struct tfa9887_priv *tfa9887, Tfa9887_Mute_t mute)
{
        int error;
        unsigned int audioctrl_value;
        unsigned int sysctrl_value;
        error =
            Tfa9887_ReadRegister(tfa9887, TFA9887_AUDIO_CONTROL,
                                   &audioctrl_value);
        if (error != Tfa9887_Error_Ok)
                return error;
        error =
            Tfa9887_ReadRegister(tfa9887, TFA9887_SYSTEM_CONTROL,
                                   &sysctrl_value);
        if (error != Tfa9887_Error_Ok)
                return error;
        switch (mute) {
        case Tfa9887_Mute_Off:
                /* previous state can be digital or amplifier mute,
                 * clear the cf_mute and set the enbl_amplifier bits
                 */
                audioctrl_value &= ~(TFA9887_AUDIOCTRL_MUTE);
                sysctrl_value |= TFA9887_SYSCTRL_ENBL_AMP;
                break;
        case Tfa9887_Mute_Digital:
                /* expect the amplifier to run */
                /* set the cf_mute bit */
                audioctrl_value |= TFA9887_AUDIOCTRL_MUTE;
                /* set the enbl_amplifier bit */
                sysctrl_value |= TFA9887_SYSCTRL_ENBL_AMP;
                break;
        case Tfa9887_Mute_Amplifier:
                /* clear the cf_mute bit */
                audioctrl_value &= ~TFA9887_AUDIOCTRL_MUTE;
                /* clear the enbl_amplifier bit */
                sysctrl_value &= ~TFA9887_SYSCTRL_ENBL_AMP;
                break;
        default:
                error = -1;
        }
        if (error != Tfa9887_Error_Ok)
                return error;
        error =
            Tfa9887_WriteRegister(tfa9887, TFA9887_AUDIO_CONTROL,
                                    audioctrl_value);
        if (error != Tfa9887_Error_Ok)
                return error;
        error =
            Tfa9887_WriteRegister(tfa9887, TFA9887_SYSTEM_CONTROL,
                                    sysctrl_value);
        return error;
}
bool tfa9887_readable_register(struct device *dev, unsigned int reg)
{
	 return true;
}

bool tfa9887_volatile_register(struct device *dev, unsigned int reg)
{
	 return true;
}

static const struct regmap_config tfa9887_regmap = {
	.reg_bits = 8,
	.val_bits = 16,
	.volatile_reg = tfa9887_volatile_register,
	.readable_reg = tfa9887_readable_register,
	.cache_type = REGCACHE_NONE,
};

static const struct regmap_config tfa9887_regmap_byte = {
        .reg_bits = 8,
        .val_bits = 8,
        .volatile_reg = tfa9887_volatile_register,
        .readable_reg = tfa9887_readable_register,
        .cache_type = REGCACHE_NONE,
};
static ssize_t tfa9887_cal_show(struct kobject *kobj,
		struct kobj_attribute *attr, char *buf)
{
	//printk("!tfa9887_cal_show\n");
	if (calibration) {
		memcpy(buf, calibdata, 16);
		return 16;
		//pr_info("copying data\n");
	}
	else
	return -1;
}

static ssize_t tfa9887_cal_store(struct kobject *kobj,
	struct kobj_attribute *attr, const char *buf, size_t count)
{
	ssize_t ret = count;
	//printk("+tfa9887_cal_store: %p, %d\n", buf, count);

	if (!buf || !count) {
		ret = -EINVAL;
		goto fail;
	}
	if (count == 6) {
		if (calibration) {
			recalibration = 1;
			tegra_asoc_enable_clocks();
			memcpy(&speaker_data_right[420],buf,3);
			recalibrate(tfa9887R, tfa9887R_byte);
			memcpy(&speaker_data_left[420],buf+3,3);
			recalibrate(tfa9887L, tfa9887L_byte);
			recalibration = 0;
			calibration = 0;
			tegra_asoc_disable_clocks();
		}
	}
fail:
	//printk("-tfa9887_cal_store: %d\n", count);
	return ret;
}

void recalibrate(struct tfa9887_priv *tfa9887, struct tfa9887_priv *tfa9887_byte) {

	unsigned int value;
	if (tfa9887) {
		mutex_lock(&tfa9887->lock);
		if (tfa9887->deviceInit) {
			resetMtpEx(tfa9887);
			SetMute(tfa9887, Tfa9887_Mute_Amplifier);
			coldStartup(tfa9887, tfa9887_byte, srate);
			Init(tfa9887,tfa9887_byte, srate);
			calibrate(tfa9887, tfa9887_byte, &calibdata[0]);
			Tfa9887_ReadRegister(tfa9887, TFA9887_SYSTEM_CONTROL, &value);
			value |= TFA9887_SYSCTRL_POWERDOWN;
			Tfa9887_WriteRegister(tfa9887, TFA9887_SYSTEM_CONTROL, value);
		}
		mutex_unlock(&tfa9887->lock);
	}
}

static ssize_t tfa9887_config_show(struct kobject *kobj,
		struct kobj_attribute *attr, char *buf)
{
	//printk("!tfa9887_config_show\n");

	if (buf) {
		if (eq_mode == 1)
			*buf = '1';
		else if (eq_mode == 2)
			*buf = '2';
		else
			return -EINVAL;
	}
	printk("%c\n",*buf);
	return 1;
}

static ssize_t tfa9887_config_store(struct kobject *kobj,
	struct kobj_attribute *attr, const char *buf, size_t count)
{
	ssize_t ret = count;

	//printk("+tfa9887_config_store: %p, %d\n", buf, count);

	if (!buf || !count) {
		ret = -EINVAL;
		goto fail;
	}
	if (*buf == '2') {
		pr_info("IN HAND MODE\n");
		eq_mode = 2;
	}
	else if (*buf == '1'){
		pr_info("IN DESK MODE\n");
		eq_mode = 1;
	}
	Tfa9887_SetEq();
fail:
	//printk("-tfa9887_config_store: %d\n", count);
	return ret;
}

static ssize_t tfa9887_vol_show(struct kobject *kobj,
		struct kobj_attribute *attr, char *buf)
{
	printk("!tfa9887_vol_show\n");
	return 0;
}

static ssize_t tfa9887_vol_store(struct kobject *kobj,
	struct kobj_attribute *attr, const char *buf, size_t count)
{
	ssize_t ret = count;
	unsigned int index;


	if (!buf || !count) {
		ret = -EINVAL;
		goto fail;
	}

	index = MAX_DB_INDEX - *buf;
	Tfa9887_SetVolume(index);
fail:
	return ret;
}

static __devinit int tfa9887R_i2c_probe(struct i2c_client *i2c,
				      const struct i2c_device_id *id)
{
	unsigned int val;
	int ret;

	pr_info("tfa9887R_i2c_probe\n");
	tfa9887R = devm_kzalloc(&i2c->dev,  sizeof(struct tfa9887_priv),
			      GFP_KERNEL);
	tfa9887R_byte = devm_kzalloc(&i2c->dev,  sizeof(struct tfa9887_priv),
                              GFP_KERNEL);

	if (tfa9887R == NULL)
		return -ENOMEM;
	tfa9887R->regmap = regmap_init_i2c(i2c, &tfa9887_regmap);
	tfa9887R_byte->regmap = regmap_init_i2c(i2c, &tfa9887_regmap_byte);
	if (IS_ERR(tfa9887R->regmap)) {
		ret = PTR_ERR(tfa9887R->regmap);
		dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
			ret);
		return ret;
	}

	i2c_set_clientdata(i2c, tfa9887R);
	i2c_set_clientdata(i2c, tfa9887R_byte);
	mutex_init(&tfa9887R->lock);
	tfa9887R->irq = i2c->irq;
	tfa9887R_byte->irq = i2c->irq;
	tfa9887R->speaker_data = speaker_data_right;
	ret = regmap_read(tfa9887R->regmap, TFA9887_REVISIONNUMBER, &val);
	if (ret != 0) {
		dev_err(&i2c->dev, "Failed to read chip revision: %d\n", ret);
		goto err;
	}
	dev_info(&i2c->dev, "TFA9887 revision %d\n",val);
	tfa9887_kobj = kobject_create_and_add("tfa9887", kernel_kobj);

	ret = sysfs_create_file(tfa9887_kobj, &tfa9887_config);
	printk("tfa9887_add_sysfs ret=%d\n", ret);
	if (ret != 0) {
                dev_err(&i2c->dev, "Failed to add sysfs: %d\n", ret);
		goto err;
	}
	ret = sysfs_create_file(tfa9887_kobj, &tfa9887_cal);
	printk("tfa9887_add_sysfs ret=%d\n", ret);
	if (ret != 0) {
                dev_err(&i2c->dev, "Failed to add sysfs: %d\n", ret);
		goto err;
	}
	ret = sysfs_create_file(tfa9887_kobj, &tfa9887_vol);
	printk("tfa9887_add_sysfs ret=%d\n", ret);
	if (ret != 0) {
                dev_err(&i2c->dev, "Failed to add sysfs: %d\n", ret);
		goto err;
	}
	if (tfa9887R) {
		mutex_lock(&tfa9887R->lock);
		tfa9887R->deviceInit = true;
		mutex_unlock(&tfa9887R->lock);
	}
	eq_mode = IN_HAND_MODE;
	preset_mode = PRESET_DEFAULT;
	vol_index = PRESET_DEFAULT;
	return 0;
err:
	regmap_exit(tfa9887R->regmap);
	return ret;
}

static __devexit int tfa9887R_i2c_remove(struct i2c_client *client)
{
	struct tfa9887_priv *tfa9887R = i2c_get_clientdata(client);
	regmap_exit(tfa9887R->regmap);
	sysfs_remove_file(tfa9887_kobj, &tfa9887_config);
	sysfs_remove_file(tfa9887_kobj, &tfa9887_cal);
	sysfs_remove_file(tfa9887_kobj, &tfa9887_vol);
	kobject_del(tfa9887_kobj);
	return 0;
}

static void tfa9887R_i2c_shutdown(struct i2c_client *i2c)
{
	if (tfa9887R) {
		mutex_lock(&tfa9887R->lock);
		if (i2c->irq)
			disable_irq(i2c->irq);
		tfa9887R->deviceInit = false;
		mutex_unlock(&tfa9887R->lock);
        }
}

static const struct of_device_id tfa9887R_of_match[] = {
	{ .compatible = "nxp,tfa9887R", },
	{},
};
MODULE_DEVICE_TABLE(of, tfa9887R_of_match);

static const struct i2c_device_id tfa9887R_i2c_id[] = {
	{ "tfa9887R", 0 },
	{ }
};
MODULE_DEVICE_TABLE(i2c, tfa9887R_i2c_id);

static struct i2c_driver tfa9887R_i2c_driver = {
	 .driver = {
	 .name = "tfa9887R",
	 .owner = THIS_MODULE,
	 .of_match_table = tfa9887R_of_match,
	 },
	 .probe =    tfa9887R_i2c_probe,
	 .remove =   __devexit_p(tfa9887R_i2c_remove),
	 .id_table = tfa9887R_i2c_id,
	 .shutdown = tfa9887R_i2c_shutdown,
};

static __devinit int tfa9887L_i2c_probe(struct i2c_client *i2c,
				      const struct i2c_device_id *id)
{
	unsigned int val;
	int ret;

	pr_info("tfa9887L_i2c_probe\n");
	tfa9887L = devm_kzalloc(&i2c->dev,  sizeof(struct tfa9887_priv),
			      GFP_KERNEL);
	tfa9887L_byte = devm_kzalloc(&i2c->dev,  sizeof(struct tfa9887_priv),
                              GFP_KERNEL);

	if (tfa9887L == NULL)
		return -ENOMEM;
	tfa9887L->regmap = regmap_init_i2c(i2c, &tfa9887_regmap);
	tfa9887L_byte->regmap = regmap_init_i2c(i2c, &tfa9887_regmap_byte);
	if (IS_ERR(tfa9887L->regmap)) {
		ret = PTR_ERR(tfa9887L->regmap);
		dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
			ret);
		return ret;
	}

	i2c_set_clientdata(i2c, tfa9887L);
	mutex_init(&tfa9887L->lock);
	tfa9887L->irq = i2c->irq;
	tfa9887L->speaker_data = speaker_data_left;
	ret = regmap_read(tfa9887L->regmap, TFA9887_REVISIONNUMBER, &val);
	if (ret != 0) {
		dev_err(&i2c->dev, "Failed to read chip revision: %d\n", ret);
		goto err;
	}
	dev_info(&i2c->dev, "TFA9887 revision %d\n",val);
	if (tfa9887L) {
		mutex_lock(&tfa9887L->lock);
		tfa9887L->deviceInit = true;
		mutex_unlock(&tfa9887L->lock);
	}
	return 0;
err:
	regmap_exit(tfa9887L->regmap);
	return ret;
}

static __devexit int tfa9887L_i2c_remove(struct i2c_client *client)
{
	struct tfa9887_priv *tfa9887L = i2c_get_clientdata(client);
	regmap_exit(tfa9887L->regmap);
	return 0;
}

static void tfa9887L_i2c_shutdown(struct i2c_client *i2c)
{
	if (tfa9887L) {
		mutex_lock(&tfa9887L->lock);
		if (i2c->irq)
			disable_irq(i2c->irq);
		tfa9887L->deviceInit = false;
		mutex_unlock(&tfa9887L->lock);
	}
}

static const struct of_device_id tfa9887L_of_match[] = {
	{ .compatible = "nxp,tfa9887L", },
	{},
};
MODULE_DEVICE_TABLE(of, tfa9887L_of_match);

static const struct i2c_device_id tfa9887L_i2c_id[] = {
	{ "tfa9887L", 0 },
	{ }
};
MODULE_DEVICE_TABLE(i2c, tfa9887L_i2c_id);

static struct i2c_driver tfa9887L_i2c_driver = {
	 .driver = {
	 .name = "tfa9887L",
	 .owner = THIS_MODULE,
	 .of_match_table = tfa9887L_of_match,
	 },
	 .probe =    tfa9887L_i2c_probe,
	 .remove =   __devexit_p(tfa9887L_i2c_remove),
	 .id_table = tfa9887L_i2c_id,
	 .shutdown = tfa9887L_i2c_shutdown,
};

static int __init tfa9887_modinit(void)
{
	 int ret = 0;
	 ret = i2c_add_driver(&tfa9887R_i2c_driver);
	 if (ret != 0) {
	 printk(KERN_ERR "Failed to register tfa9887 I2C driver: %d\n",
	    ret);
	 }
	 ret = i2c_add_driver(&tfa9887L_i2c_driver);
	 if (ret != 0) {
	 printk(KERN_ERR "Failed to register tfa9887 I2C driver: %d\n",
	    ret);
	 }
	 return ret;
}
module_init(tfa9887_modinit);

static void __exit tfa9887_exit(void)
{
	 i2c_del_driver(&tfa9887R_i2c_driver);
	 i2c_del_driver(&tfa9887L_i2c_driver);
}
module_exit(tfa9887_exit);