1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
|
/*
* Exynos Specific Extensions for Synopsys DW Multimedia Card Interface driver
*
* Copyright (C) 2012, Samsung Electronics Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/clk.h>
#include <linux/mmc/host.h>
#include <linux/mmc/dw_mmc.h>
#include <linux/mmc/mmc.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/slab.h>
#include <linux/pinctrl/pinctrl.h>
#include <linux/pinctrl/pinconf.h>
#include <linux/smc.h>
#include <linux/sec_sysfs.h>
#include "dw_mmc.h"
#include "dw_mmc-pltfm.h"
#include "dw_mmc-exynos.h"
#include "dw_mmc-exynos-smu.h"
#include "dw_mmc-exynos-fmp.h"
extern int cal_pll_mmc_set_ssc(unsigned int mfr, unsigned int mrr, unsigned int ssc_on);
extern int cal_pll_mmc_check(void);
static void dw_mci_exynos_register_dump(struct dw_mci *host)
{
dev_err(host->dev, ": EMMCP_BASE: 0x%08x\n",
host->sfr_dump->fmp_emmcp_base = mci_readl(host, EMMCP_BASE));
dev_err(host->dev, ": MPSECURITY: 0x%08x\n",
host->sfr_dump->mpsecurity = mci_readl(host, MPSECURITY));
dev_err(host->dev, ": MPSTAT: 0x%08x\n",
host->sfr_dump->mpstat = mci_readl(host, MPSTAT));
dev_err(host->dev, ": MPSBEGIN: 0x%08x\n",
host->sfr_dump->mpsbegin = mci_readl(host, MPSBEGIN0));
dev_err(host->dev, ": MPSEND: 0x%08x\n",
host->sfr_dump->mpsend = mci_readl(host, MPSEND0));
dev_err(host->dev, ": MPSCTRL: 0x%08x\n",
host->sfr_dump->mpsctrl = mci_readl(host, MPSCTRL0));
dev_err(host->dev, ": HS400_DQS_EN: 0x%08x\n",
host->sfr_dump->hs400_rdqs_en = mci_readl(host, HS400_DQS_EN));
dev_err(host->dev, ": HS400_ASYNC_FIFO_CTRL: 0x%08x\n",
host->sfr_dump->hs400_acync_fifo_ctrl =
mci_readl(host, HS400_ASYNC_FIFO_CTRL));
dev_err(host->dev, ": HS400_DLINE_CTRL: 0x%08x\n",
host->sfr_dump->hs400_dline_ctrl =
mci_readl(host, HS400_DLINE_CTRL));
}
void dw_mci_reg_dump(struct dw_mci *host)
{
u32 reg;
dev_err(host->dev, ": ============== REGISTER DUMP ==============\n");
dev_err(host->dev, ": CTRL: 0x%08x\n",
host->sfr_dump->contrl = mci_readl(host, CTRL));
dev_err(host->dev, ": PWREN: 0x%08x\n",
host->sfr_dump->pwren = mci_readl(host, PWREN));
dev_err(host->dev, ": CLKDIV: 0x%08x\n",
host->sfr_dump->clkdiv = mci_readl(host, CLKDIV));
dev_err(host->dev, ": CLKSRC: 0x%08x\n",
host->sfr_dump->clksrc = mci_readl(host, CLKSRC));
dev_err(host->dev, ": CLKENA: 0x%08x\n",
host->sfr_dump->clkena = mci_readl(host, CLKENA));
dev_err(host->dev, ": TMOUT: 0x%08x\n",
host->sfr_dump->tmout = mci_readl(host, TMOUT));
dev_err(host->dev, ": CTYPE: 0x%08x\n",
host->sfr_dump->ctype = mci_readl(host, CTYPE));
dev_err(host->dev, ": BLKSIZ: 0x%08x\n",
host->sfr_dump->blksiz = mci_readl(host, BLKSIZ));
dev_err(host->dev, ": BYTCNT: 0x%08x\n",
host->sfr_dump->bytcnt = mci_readl(host, BYTCNT));
dev_err(host->dev, ": INTMSK: 0x%08x\n",
host->sfr_dump->intmask = mci_readl(host, INTMASK));
dev_err(host->dev, ": CMDARG: 0x%08x\n",
host->sfr_dump->cmdarg = mci_readl(host, CMDARG));
dev_err(host->dev, ": CMD: 0x%08x\n",
host->sfr_dump->cmd = mci_readl(host, CMD));
dev_err(host->dev, ": RESP0: 0x%08x\n", mci_readl(host, RESP0));
dev_err(host->dev, ": RESP1: 0x%08x\n", mci_readl(host, RESP1));
dev_err(host->dev, ": RESP2: 0x%08x\n", mci_readl(host, RESP2));
dev_err(host->dev, ": RESP3: 0x%08x\n", mci_readl(host, RESP3));
dev_err(host->dev, ": MINTSTS: 0x%08x\n",
host->sfr_dump->mintsts = mci_readl(host, MINTSTS));
dev_err(host->dev, ": RINTSTS: 0x%08x\n",
host->sfr_dump->rintsts = mci_readl(host, RINTSTS));
dev_err(host->dev, ": STATUS: 0x%08x\n",
host->sfr_dump->status = mci_readl(host, STATUS));
dev_err(host->dev, ": FIFOTH: 0x%08x\n",
host->sfr_dump->fifoth = mci_readl(host, FIFOTH));
dev_err(host->dev, ": CDETECT: 0x%08x\n", mci_readl(host, CDETECT));
dev_err(host->dev, ": WRTPRT: 0x%08x\n", mci_readl(host, WRTPRT));
dev_err(host->dev, ": GPIO: 0x%08x\n", mci_readl(host, GPIO));
dev_err(host->dev, ": TCBCNT: 0x%08x\n",
host->sfr_dump->tcbcnt = mci_readl(host, TCBCNT));
dev_err(host->dev, ": TBBCNT: 0x%08x\n",
host->sfr_dump->tbbcnt = mci_readl(host, TBBCNT));
dev_err(host->dev, ": DEBNCE: 0x%08x\n", mci_readl(host, DEBNCE));
dev_err(host->dev, ": USRID: 0x%08x\n", mci_readl(host, USRID));
dev_err(host->dev, ": VERID: 0x%08x\n", mci_readl(host, VERID));
dev_err(host->dev, ": HCON: 0x%08x\n", mci_readl(host, HCON));
dev_err(host->dev, ": UHS_REG: 0x%08x\n",
host->sfr_dump->uhs_reg = mci_readl(host, UHS_REG));
dev_err(host->dev, ": BMOD: 0x%08x\n",
host->sfr_dump->bmod = mci_readl(host, BMOD));
dev_err(host->dev, ": PLDMND: 0x%08x\n", mci_readl(host, PLDMND));
dev_err(host->dev, ": DBADDRL: 0x%08x\n",
host->sfr_dump->dbaddrl = mci_readl(host, DBADDRL));
dev_err(host->dev, ": DBADDRU: 0x%08x\n",
host->sfr_dump->dbaddru = mci_readl(host, DBADDRU));
dev_err(host->dev, ": DSCADDRL: 0x%08x\n",
host->sfr_dump->dscaddrl = mci_readl(host, DSCADDRL));
dev_err(host->dev, ": DSCADDRU: 0x%08x\n",
host->sfr_dump->dscaddru = mci_readl(host, DSCADDRU));
dev_err(host->dev, ": BUFADDR: 0x%08x\n",
host->sfr_dump->bufaddr = mci_readl(host, BUFADDR));
dev_err(host->dev, ": BUFADDRU: 0x%08x\n",
host->sfr_dump->bufaddru = mci_readl(host, BUFADDRU));
dev_err(host->dev, ": DBADDR: 0x%08x\n",
host->sfr_dump->dbaddr = mci_readl(host, DBADDR));
dev_err(host->dev, ": DSCADDR: 0x%08x\n",
host->sfr_dump->dscaddr = mci_readl(host, DSCADDR));
dev_err(host->dev, ": BUFADDR: 0x%08x\n",
host->sfr_dump->bufaddr = mci_readl(host, BUFADDR));
dev_err(host->dev, ": CLKSEL: 0x%08x\n",
host->sfr_dump->clksel = mci_readl(host, CLKSEL));
dev_err(host->dev, ": IDSTS: 0x%08x\n", mci_readl(host, IDSTS));
dev_err(host->dev, ": IDSTS64: 0x%08x\n",
host->sfr_dump->idsts64 = mci_readl(host, IDSTS64));
dev_err(host->dev, ": IDINTEN: 0x%08x\n", mci_readl(host, IDINTEN));
dev_err(host->dev, ": IDINTEN64: 0x%08x\n",
host->sfr_dump->idinten64 = mci_readl(host, IDINTEN64));
dev_err(host->dev, ": RESP_TAT: 0x%08x\n", mci_readl(host, RESP_TAT));
dev_err(host->dev, ": FORCE_CLK_STOP: 0x%08x\n",
host->sfr_dump->force_clk_stop = mci_readl(host, FORCE_CLK_STOP));
dev_err(host->dev, ": CDTHRCTL: 0x%08x\n", mci_readl(host, CDTHRCTL));
dw_mci_exynos_register_dump(host);
dev_err(host->dev, ": ============== STATUS DUMP ================\n");
dev_err(host->dev, ": cmd_status: 0x%08x\n",
host->sfr_dump->cmd_status = host->cmd_status);
dev_err(host->dev, ": data_status: 0x%08x\n",
host->sfr_dump->force_clk_stop = host->data_status);
dev_err(host->dev, ": pending_events: 0x%08lx\n",
host->sfr_dump->pending_events = host->pending_events);
dev_err(host->dev, ": completed_events:0x%08lx\n",
host->sfr_dump->completed_events = host->completed_events);
dev_err(host->dev, ": state: %d\n",
host->sfr_dump->host_state = host->state);
dev_err(host->dev, ": gate-clk: %s\n",
atomic_read(&host->ciu_clk_cnt) ?
"enable" : "disable");
dev_err(host->dev, ": ciu_en_win: %d\n",
atomic_read(&host->ciu_en_win));
reg = mci_readl(host, CMD);
dev_err(host->dev, ": ================= CMD REG =================\n");
if((reg >> 9) & 0x1) {
dev_err(host->dev, ": read/write : %s\n",
(reg & (0x1 << 10)) ? "write" : "read");
dev_err(host->dev, ": data expected : %d\n", (reg >> 9) & 0x1);
}
dev_err(host->dev, ": cmd index : %d\n",
host->sfr_dump->cmd_index =((reg >> 0) & 0x3f));
reg = mci_readl(host, STATUS);
dev_err(host->dev, ": ================ STATUS REG ===============\n");
dev_err(host->dev, ": fifocount : %d\n",
host->sfr_dump->fifo_count = ((reg >> 17) & 0x1fff));
dev_err(host->dev, ": response index : %d\n", (reg >> 11) & 0x3f);
dev_err(host->dev, ": data state mc busy: %d\n", (reg >> 10) & 0x1);
dev_err(host->dev, ": data busy : %d\n",
host->sfr_dump->data_busy = ((reg >> 9) & 0x1));
dev_err(host->dev, ": data 3 state : %d\n",
host->sfr_dump->data_3_state = ((reg >> 8) & 0x1));
dev_err(host->dev, ": command fsm state : %d\n", (reg >> 4) & 0xf);
dev_err(host->dev, ": fifo full : %d\n", (reg >> 3) & 0x1);
dev_err(host->dev, ": fifo empty : %d\n", (reg >> 2) & 0x1);
dev_err(host->dev, ": fifo tx watermark : %d\n",
host->sfr_dump->fifo_tx_watermark = ((reg >> 1) & 0x1));
dev_err(host->dev, ": fifo rx watermark : %d\n",
host->sfr_dump->fifo_rx_watermark = ((reg >> 0) & 0x1));
dev_err(host->dev, ": ===========================================\n");
}
/* Variations in Exynos specific dw-mshc controller */
enum dw_mci_exynos_type {
DW_MCI_TYPE_EXYNOS,
};
static struct dw_mci_exynos_compatible {
char *compatible;
enum dw_mci_exynos_type ctrl_type;
} exynos_compat[] = {
{
.compatible = "samsung,exynos-dw-mshc",
.ctrl_type = DW_MCI_TYPE_EXYNOS,
},
};
static inline u8 dw_mci_exynos_get_ciu_div(struct dw_mci *host)
{
return SDMMC_CLKSEL_GET_DIV(mci_readl(host, CLKSEL)) + 1;
}
static int dw_mci_exynos_priv_init(struct dw_mci *host)
{
struct dw_mci_exynos_priv_data *priv = host->priv;
priv->saved_strobe_ctrl = mci_readl(host, HS400_DLINE_CTRL);
priv->saved_dqs_en = mci_readl(host, HS400_DQS_EN);
priv->saved_dqs_en |= AXI_NON_BLOCKING_WR;
mci_writel(host, HS400_DQS_EN, priv->saved_dqs_en);
if (!priv->dqs_delay)
priv->dqs_delay =
DQS_CTRL_GET_RD_DELAY(priv->saved_strobe_ctrl);
#if defined(CONFIG_MMC_DW_64BIT_DESC)
if (priv->voltage_int_extra != 0) {
u32 reg = 0;
reg = mci_readl(host, AXI_BURST_LEN);
reg &= ~(0x7 << 24);
reg |= (priv->voltage_int_extra << 24);
mci_writel(host, AXI_BURST_LEN, reg);
}
#endif
return 0;
}
static void dw_mci_ssclk_control(struct dw_mci *host, int enable)
{
if (host->pdata->quirks & DW_MCI_QUIRK_USE_SSC) {
u32 err;
if (enable && cal_pll_mmc_check() == false) {
if (host->pdata->ssc_rate > 8) {
dev_info(host->dev, "unvalid SSC rate value.\n");
} else {
err = cal_pll_mmc_set_ssc(12 ,host->pdata->ssc_rate, 1);
if (err)
dev_info(host->dev, "SSC set fail.\n");
else
dev_info(host->dev, "SSC set enable.\n");
}
} else if (!enable && cal_pll_mmc_check() == true) {
err = cal_pll_mmc_set_ssc(0 , 0, 0);
if (err)
dev_info(host->dev, "SSC set fail.\n");
else
dev_info(host->dev, "SSC set disable.\n");
}
}
}
static void dw_mci_exynos_set_clksel_timing(struct dw_mci *host, u32 timing)
{
u32 clksel;
clksel = mci_readl(host, CLKSEL);
clksel = (clksel & ~SDMMC_CLKSEL_TIMING_MASK) | timing;
if (!((host->pdata->io_mode == MMC_TIMING_MMC_HS400) ||
(host->pdata->io_mode == MMC_TIMING_MMC_HS400_ES)))
clksel &= ~(BIT(30) | BIT(19));
mci_writel(host, CLKSEL, clksel);
}
#ifdef CONFIG_PM_SLEEP
static int dw_mci_exynos_suspend(struct device *dev)
{
struct dw_mci *host = dev_get_drvdata(dev);
return dw_mci_suspend(host);
}
static int dw_mci_exynos_resume(struct device *dev)
{
struct dw_mci *host = dev_get_drvdata(dev);
return dw_mci_resume(host);
}
/**
* dw_mci_exynos_resume_noirq - Exynos-specific resume code
*
* On exynos5420 there is a silicon errata that will sometimes leave the
* WAKEUP_INT bit in the CLKSEL register asserted. This bit is 1 to indicate
* that it fired and we can clear it by writing a 1 back. Clear it to prevent
* interrupts from going off constantly.
*
* We run this code on all exynos variants because it doesn't hurt.
*/
static int dw_mci_exynos_resume_noirq(struct device *dev)
{
struct dw_mci *host = dev_get_drvdata(dev);
u32 clksel;
clksel = mci_readl(host, CLKSEL);
if (clksel & SDMMC_CLKSEL_WAKEUP_INT)
mci_writel(host, CLKSEL, clksel);
return 0;
}
#else
#define dw_mci_exynos_suspend NULL
#define dw_mci_exynos_resume NULL
#define dw_mci_exynos_resume_noirq NULL
#endif /* CONFIG_PM_SLEEP */
static void dw_mci_card_int_hwacg_ctrl(struct dw_mci *host, u32 flag)
{
u32 reg;
reg = mci_readl(host, FORCE_CLK_STOP);
if (flag == HWACG_Q_ACTIVE_EN) {
reg |= MMC_HWACG_CONTROL;
host->qactive_check = HWACG_Q_ACTIVE_EN;
} else {
reg &= ~(MMC_HWACG_CONTROL);
host->qactive_check = HWACG_Q_ACTIVE_DIS;
}
mci_writel(host, FORCE_CLK_STOP, reg);
}
static void dw_mci_exynos_config_hs400(struct dw_mci *host, u32 timing)
{
struct dw_mci_exynos_priv_data *priv = host->priv;
u32 dqs, strobe;
/*
* Not supported to configure register
* related to HS400
*/
dqs = priv->saved_dqs_en;
strobe = priv->saved_strobe_ctrl;
if (timing == MMC_TIMING_MMC_HS400 ||
timing == MMC_TIMING_MMC_HS400_ES) {
dqs &= ~(DWMCI_TXDT_CRC_TIMER_SET(0xFF, 0xFF));
dqs |= (DWMCI_TXDT_CRC_TIMER_SET(priv->hs400_tx_t_fastlimit,
priv->hs400_tx_t_initval) | DWMCI_RDDQS_EN |
DWMCI_AXI_NON_BLOCKING_WRITE);
if (host->pdata->quirks & DW_MCI_QUIRK_ENABLE_ULP) {
if (priv->delay_line || priv->tx_delay_line)
strobe = DWMCI_WD_DQS_DELAY_CTRL(priv->tx_delay_line) |
DWMCI_FIFO_CLK_DELAY_CTRL(0x2) |
DWMCI_RD_DQS_DELAY_CTRL(priv->delay_line);
else
strobe = DWMCI_FIFO_CLK_DELAY_CTRL(0x2) |
DWMCI_RD_DQS_DELAY_CTRL(90);
} else {
if (priv->delay_line)
strobe = DWMCI_FIFO_CLK_DELAY_CTRL(0x2) |
DWMCI_RD_DQS_DELAY_CTRL(priv->delay_line);
else
strobe = DWMCI_FIFO_CLK_DELAY_CTRL(0x2) |
DWMCI_RD_DQS_DELAY_CTRL(90);
}
dqs |= (DATA_STROBE_EN | DWMCI_AXI_NON_BLOCKING_WRITE);
if (timing == MMC_TIMING_MMC_HS400_ES)
dqs |= DWMCI_RESP_RCLK_MODE;
} else {
dqs &= ~DATA_STROBE_EN;
}
mci_writel(host, HS400_DQS_EN, dqs);
mci_writel(host, HS400_DLINE_CTRL, strobe);
}
static void dw_mci_exynos_adjust_clock(struct dw_mci *host, unsigned int wanted)
{
struct dw_mci_exynos_priv_data *priv = host->priv;
unsigned long actual;
u8 div;
int ret;
u32 clock;
/*
* Don't care if wanted clock is zero or
* ciu clock is unavailable
*/
if (!wanted || IS_ERR(host->ciu_clk))
return;
/* Guaranteed minimum frequency for cclkin */
if (wanted < EXYNOS_CCLKIN_MIN)
wanted = EXYNOS_CCLKIN_MIN;
div = dw_mci_exynos_get_ciu_div(host);
if (wanted == priv->cur_speed) {
clock = clk_get_rate(host->ciu_clk);
if (clock == priv->cur_speed * div)
return;
}
ret = clk_set_rate(host->ciu_clk, wanted * div);
if (ret)
dev_warn(host->dev,
"failed to set clk-rate %u error: %d\n",
wanted * div, ret);
actual = clk_get_rate(host->ciu_clk);
host->bus_hz = actual / div;
priv->cur_speed = wanted;
host->current_speed = 0;
}
#define KHZ (1000)
static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios)
{
struct dw_mci_exynos_priv_data *priv = host->priv;
unsigned int wanted = ios->clock;
u32 *clk_tbl = priv->ref_clk;
u32 timing = ios->timing, clksel;
u32 cclkin;
cclkin = clk_tbl[timing];
host->pdata->io_mode = timing;
if (host->bus_hz != cclkin)
wanted = cclkin;
switch (timing) {
case MMC_TIMING_MMC_HS400:
case MMC_TIMING_MMC_HS400_ES:
if (host->pdata->quirks & DW_MCI_QUIRK_ENABLE_ULP) {
clksel = SDMMC_CLKSEL_UP_SAMPLE(
priv->hs400_ulp_timing,
priv->tuned_sample);
clksel |= (BIT(30) | BIT(19)); /* ultra low powermode on */
} else {
clksel = SDMMC_CLKSEL_UP_SAMPLE(
priv->hs400_timing,
priv->tuned_sample);
clksel &= ~(BIT(30) | BIT(19)); /* ultra low powermode on */
wanted <<= 1;
}
if (host->pdata->is_fine_tuned)
clksel |= BIT(6);
break;
case MMC_TIMING_MMC_DDR52:
case MMC_TIMING_UHS_DDR50:
clksel = priv->ddr_timing;
/* Should be double rate for DDR mode */
if (ios->bus_width == MMC_BUS_WIDTH_8)
wanted <<= 1;
break;
case MMC_TIMING_MMC_HS200:
clksel = SDMMC_CLKSEL_UP_SAMPLE(priv->hs200_timing, priv->tuned_sample);
break;
case MMC_TIMING_UHS_SDR104:
if (priv->sdr104_timing)
clksel = SDMMC_CLKSEL_UP_SAMPLE(priv->sdr104_timing, priv->tuned_sample);
else {
dev_info(host->dev, "Setting of SDR104 timing in not been!!\n");
clksel = SDMMC_CLKSEL_UP_SAMPLE(priv->sdr_timing,
priv->tuned_sample);
}
dw_mci_ssclk_control(host, 1);
break;
case MMC_TIMING_UHS_SDR50:
if (priv->sdr50_timing)
clksel = SDMMC_CLKSEL_UP_SAMPLE(priv->sdr50_timing, priv->tuned_sample);
else {
dev_info(host->dev, "Setting of SDR50 timing is not been!!\n");
clksel = SDMMC_CLKSEL_UP_SAMPLE(priv->sdr_timing,
priv->tuned_sample);
}
dw_mci_ssclk_control(host, 1);
break;
default:
clksel = priv->sdr_timing;
}
if ((ios->clock > 0) && (ios->clock <= 400 * KHZ))
sample_path_sel_dis(host, AXI_BURST_LEN);
host->cclk_in = wanted;
/* Set clock timing for the requested speed mode*/
dw_mci_exynos_set_clksel_timing(host, clksel);
/* Configure setting for HS400 */
dw_mci_exynos_config_hs400(host, timing);
/* Configure clock rate */
dw_mci_exynos_adjust_clock(host, wanted);
}
#ifndef MHZ
#define MHZ (1000 * 1000)
#endif
static int dw_mci_exynos_parse_dt(struct dw_mci *host)
{
struct dw_mci_exynos_priv_data *priv;
struct device_node *np = host->dev->of_node;
u32 timing[4];
u32 div = 0, voltage_int_extra = 0;
int idx;
u32 ref_clk_size;
u32 *ref_clk;
u32 *ciu_clkin_values = NULL;
int idx_ref;
int ret = 0;
int id = 0, i;
priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL);
if (!priv) {
dev_err(host->dev, "mem alloc failed for private data\n");
return -ENOMEM;
}
for (idx = 0; idx < ARRAY_SIZE(exynos_compat); idx++) {
if (of_device_is_compatible(np, exynos_compat[idx].compatible))
priv->ctrl_type = exynos_compat[idx].ctrl_type;
}
if (of_property_read_u32(np, "num-ref-clks", &ref_clk_size)) {
dev_err(host->dev, "Getting a number of referece clock failed\n");
ret = -ENODEV;
goto err_ref_clk;
}
ref_clk = devm_kzalloc(host->dev, ref_clk_size * sizeof(*ref_clk),
GFP_KERNEL);
if (!ref_clk) {
dev_err(host->dev, "Mem alloc failed for reference clock table\n");
ret = -ENOMEM;
goto err_ref_clk;
}
ciu_clkin_values = devm_kzalloc(host->dev,
ref_clk_size * sizeof(*ciu_clkin_values), GFP_KERNEL);
if (!ciu_clkin_values) {
dev_err(host->dev, "Mem alloc failed for temporary clock values\n");
ret = -ENOMEM;
goto err_ref_clk;
}
if (of_property_read_u32_array(np, "ciu_clkin", ciu_clkin_values, ref_clk_size)) {
dev_err(host->dev, "Getting ciu_clkin values faild\n");
ret = -ENOMEM;
goto err_ref_clk;
}
for (idx_ref = 0; idx_ref < ref_clk_size; idx_ref++, ref_clk++, ciu_clkin_values++) {
if (*ciu_clkin_values > MHZ)
*(ref_clk) = (*ciu_clkin_values);
else
*(ref_clk) = (*ciu_clkin_values) * MHZ;
}
ref_clk -= ref_clk_size;
ciu_clkin_values -= ref_clk_size;
priv->ref_clk = ref_clk;
if (of_get_property(np, "card-detect", NULL))
priv->cd_gpio = of_get_named_gpio(np, "card-detect", 0);
else
priv->cd_gpio = -1;
if (of_get_property(np, "sec-sd-slot-type", NULL))
of_property_read_u32(np,
"sec-sd-slot-type", &priv->sec_sd_slot_type);
else {
if (priv->cd_gpio != -1) /* treat default SD slot if cd_gpio is defined */
priv->sec_sd_slot_type = SEC_HOTPLUG_SD_SLOT;
else
priv->sec_sd_slot_type = -1;
}
/* Swapping clock drive strength */
of_property_read_u32(np, "clk-drive-number", &priv->clk_drive_number);
priv->pinctrl = devm_pinctrl_get(host->dev);
if (IS_ERR(priv->pinctrl)) {
priv->pinctrl = NULL;
} else {
priv->clk_drive_base = pinctrl_lookup_state(priv->pinctrl, "default");
priv->clk_drive_str[0] = pinctrl_lookup_state(priv->pinctrl, "fast-slew-rate-1x");
priv->clk_drive_str[1] = pinctrl_lookup_state(priv->pinctrl, "fast-slew-rate-2x");
priv->clk_drive_str[2] = pinctrl_lookup_state(priv->pinctrl, "fast-slew-rate-3x");
priv->clk_drive_str[3] = pinctrl_lookup_state(priv->pinctrl, "fast-slew-rate-4x");
priv->clk_drive_str[4] = pinctrl_lookup_state(priv->pinctrl, "fast-slew-rate-5x");
priv->clk_drive_str[5] = pinctrl_lookup_state(priv->pinctrl, "fast-slew-rate-6x");
for (i = 0; i < 6; i++) {
if (IS_ERR(priv->clk_drive_str[i]))
priv->clk_drive_str[i] = NULL;
}
}
of_property_read_u32(np, "samsung,dw-mshc-ciu-div", &div);
priv->ciu_div = div;
if (of_property_read_u32(np, "samsung,voltage-int-extra", &voltage_int_extra))
priv->voltage_int_extra = voltage_int_extra;
ret = of_property_read_u32_array(np,
"samsung,dw-mshc-sdr-timing", timing, 4);
if (ret)
return ret;
priv->sdr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], timing[2], timing[3]);
ret = of_property_read_u32_array(np,
"samsung,dw-mshc-ddr-timing", timing, 4);
if (ret)
return ret;
priv->ddr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], timing[2], timing[3]);
of_property_read_u32(np, "ignore-phase", &priv->ignore_phase);
if (of_find_property(np, "bypass-for-allpass", NULL))
priv->ctrl_flag |= DW_MMC_EXYNOS_BYPASS_FOR_ALL_PASS;
if (of_find_property(np, "use-enable-shift", NULL))
priv->ctrl_flag |= DW_MMC_EXYNOS_ENABLE_SHIFT;
id = of_alias_get_id(host->dev->of_node, "mshc");
switch (id) {
/* dwmmc0 : eMMC */
case 0:
ret = of_property_read_u32_array(np,
"samsung,dw-mshc-hs200-timing", timing, 4);
if (ret)
goto err_ref_clk;
priv->hs200_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], timing[2], timing[3]);
ret = of_property_read_u32_array(np,
"samsung,dw-mshc-hs400-timing", timing, 4);
if (ret)
goto err_ref_clk;
priv->hs400_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], timing[2], timing[3]);
ret = of_property_read_u32_array(np,
"samsung,dw-mshc-hs400-ulp-timing", timing, 4);
if (!ret)
priv->hs400_ulp_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], timing[2], timing[3]);
else
ret = 0;
/* Rx Delay Line */
of_property_read_u32(np,
"samsung,dw-mshc-hs400-delay-line", &priv->delay_line);
/* Tx Delay Line */
of_property_read_u32(np,
"samsung,dw-mshc-hs400-tx-delay-line", &priv->tx_delay_line);
/* The fast RXCRC packet arrival time */
of_property_read_u32(np,
"samsung,dw-mshc-txdt-crc-timer-fastlimit", &priv->hs400_tx_t_fastlimit);
/* Initial value of the timeout down counter for RXCRC packet */
of_property_read_u32(np,
"samsung,dw-mshc-txdt-crc-timer-initval", &priv->hs400_tx_t_initval);
break;
/* dwmmc1 : SDIO */
case 1:
/* dwmmc2 : SD Card */
case 2:
ret = of_property_read_u32_array(np,
"samsung,dw-mshc-sdr50-timing", timing, 4); /* SDR50 100Mhz */
if (!ret)
priv->sdr50_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], timing[2], timing[3]);
else {
priv->sdr50_timing = priv->sdr_timing;
ret = 0;
}
ret = of_property_read_u32_array(np,
"samsung,dw-mshc-sdr104-timing", timing, 4); /* SDR104 200mhz */
if (!ret)
priv->sdr104_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], timing[2], timing[3]);
else {
priv->sdr104_timing = priv->sdr_timing;
ret = 0;
}
break;
default:
ret = -ENODEV;
}
host->priv = priv;
err_ref_clk:
return ret;
}
static inline u8 dw_mci_exynos_get_clksmpl(struct dw_mci *host)
{
return SDMMC_CLKSEL_CCLK_SAMPLE(mci_readl(host, CLKSEL));
}
static inline void dw_mci_exynos_set_clksmpl(struct dw_mci *host, u8 sample)
{
u32 clksel;
clksel = mci_readl(host, CLKSEL);
clksel = (clksel & ~0x7) | SDMMC_CLKSEL_CCLK_SAMPLE(sample);
mci_writel(host, CLKSEL, clksel);
}
static inline u8 dw_mci_exynos_move_next_clksmpl(struct dw_mci *host)
{
u32 clksel;
u8 sample;
clksel = mci_readl(host, CLKSEL);
sample = (clksel + 1) & 0x7;
clksel = (clksel & ~0x7) | sample;
mci_writel(host, CLKSEL, clksel);
return sample;
}
static void dw_mci_set_quirk_endbit(struct dw_mci *host, s8 mid)
{
u32 clksel, phase;
u32 shift;
clksel = mci_readl(host, CLKSEL);
phase = (((clksel >> 24) & 0x7) + 1) << 1;
shift = 360 / phase;
if (host->verid < DW_MMC_260A && (shift * mid) % 360 >= 225)
host->quirks |= DW_MCI_QUIRK_NO_DETECT_EBIT;
else
host->quirks &= ~DW_MCI_QUIRK_NO_DETECT_EBIT;
}
static void dw_mci_exynos_set_enable_shift(struct dw_mci *host, u32 sample, bool fine_tune)
{
u32 i, j, en_shift, en_shift_phase[3][4] = {{0, 0, 1, 0},
{1, 2, 3, 3},
{2, 4, 5, 5}};
en_shift = mci_readl(host, HS400_ENABLE_SHIFT)
& ~(DWMCI_ENABLE_SHIFT_MASK);
for (i = 0; i < 3; i++) {
for (j = 1; j < 4; j++) {
if (sample == en_shift_phase[i][j]) {
en_shift |= DWMCI_ENABLE_SHIFT(en_shift_phase[i][0]);
break;
}
}
}
if ((en_shift < 2) && fine_tune)
en_shift += 1;
mci_writel(host, HS400_ENABLE_SHIFT, en_shift);
}
static u8 dw_mci_tuning_sampling(struct dw_mci *host)
{
struct dw_mci_exynos_priv_data *priv = host->priv;
u32 clksel, i;
u8 sample;
clksel = mci_readl(host, CLKSEL);
sample = (clksel + 1) & 0x7;
clksel = SDMMC_CLKSEL_UP_SAMPLE(clksel, sample);
if (priv->ignore_phase) {
for (i = 0; i < 8; i++) {
if (priv->ignore_phase & (0x1 << sample))
sample = (sample + 1) & 0x7;
else
break;
}
}
clksel = (clksel & 0xfffffff8) | sample;
mci_writel(host, CLKSEL, clksel);
if (phase6_en & (0x1 << sample) || phase7_en & (0x1 << sample))
sample_path_sel_en(host, AXI_BURST_LEN);
else
sample_path_sel_dis(host, AXI_BURST_LEN);
if (priv->ctrl_flag & DW_MMC_EXYNOS_ENABLE_SHIFT)
dw_mci_exynos_set_enable_shift(host, sample, false);
return sample;
}
/* initialize the clock sample to given value */
static void dw_mci_exynos_set_sample(struct dw_mci *host, u32 sample, bool tuning)
{
struct dw_mci_exynos_priv_data *priv = host->priv;
u32 clksel;
clksel = mci_readl(host, CLKSEL);
clksel = (clksel & ~0x7) | SDMMC_CLKSEL_CCLK_SAMPLE(sample);
mci_writel(host, CLKSEL, clksel);
if (sample == 6 || sample == 7)
sample_path_sel_en(host, AXI_BURST_LEN);
else
sample_path_sel_dis(host, AXI_BURST_LEN);
if (priv->ctrl_flag & DW_MMC_EXYNOS_ENABLE_SHIFT)
dw_mci_exynos_set_enable_shift(host, sample, false);
if (!tuning)
dw_mci_set_quirk_endbit(host, clksel);
}
static void dw_mci_set_fine_tuning_bit(struct dw_mci *host,
bool is_fine_tuning)
{
struct dw_mci_exynos_priv_data *priv = host->priv;
u32 clksel, sample;
clksel = mci_readl(host, CLKSEL);
clksel = (clksel & ~BIT(6));
sample = (clksel & 0x7);
if (is_fine_tuning) {
host->pdata->is_fine_tuned = true;
clksel |= BIT(6);
} else
host->pdata->is_fine_tuned = false;
mci_writel(host, CLKSEL, clksel);
if (priv->ctrl_flag & DW_MMC_EXYNOS_ENABLE_SHIFT) {
if (((sample % 2) == 1) && is_fine_tuning && sample != 0x7)
dw_mci_exynos_set_enable_shift(host, sample, true);
else
dw_mci_exynos_set_enable_shift(host, sample, false);
}
}
/* read current clock sample offset */
static u32 dw_mci_exynos_get_sample(struct dw_mci *host)
{
u32 clksel = mci_readl(host, CLKSEL);
return SDMMC_CLKSEL_CCLK_SAMPLE(clksel);
}
static int __find_median_of_16bits(u32 orig_bits, u16 mask, u8 startbit)
{
u32 i, testbits;
testbits = orig_bits;
for (i = startbit; i < (16 + startbit); i++, testbits >>= 1)
if ((testbits & mask) == mask)
return SDMMC_CLKSEL_CCLK_FINE_SAMPLE(i);
return -1;
}
#define NUM_OF_MASK 7
static int find_median_of_16bits(struct dw_mci *host, unsigned int map, bool force)
{
struct dw_mci_exynos_priv_data *priv = host->priv;
u32 orig_bits;
u8 i, divratio;
int sel = -1;
u16 mask[NUM_OF_MASK] = {0x1fff, 0x7ff, 0x1ff, 0x7f, 0x1f, 0xf, 0x7};
/* Tuning during the center value is set to 3/2 */
int optimum[NUM_OF_MASK] = {9, 7, 6, 5, 3, 2, 1};
/* replicate the map so "arithimetic shift right" shifts in
* the same bits "again". e.g. portable "Rotate Right" bit operation.
*/
if (map == 0xFFFF && force == false)
return sel;
divratio = (mci_readl(host, CLKSEL) >> 24) & 0x7;
dev_info(host->dev, "divratio: %d map: 0x %08x\n", divratio, map);
orig_bits = map | (map << 16);
if (divratio == 1) {
if (!(priv->ctrl_flag & DW_MMC_EXYNOS_ENABLE_SHIFT))
orig_bits = orig_bits & (orig_bits >> 8);
}
for (i = 0; i < NUM_OF_MASK; i++) {
sel = __find_median_of_16bits(orig_bits, mask[i], optimum[i]);
if (-1 != sel)
break;
}
return sel;
}
static void exynos_dwmci_tuning_drv_st(struct dw_mci *host)
{
struct dw_mci_exynos_priv_data *priv = host->priv;
dev_info(host->dev, "Clock GPIO Drive Strength Value: x%d\n",
priv->clk_drive_tuning);
if (priv->pinctrl && priv->clk_drive_str[priv->clk_drive_tuning - 1])
pinctrl_select_state(priv->pinctrl, priv->clk_drive_str[priv->clk_drive_tuning - 1]);
}
/*
* Test all 8 possible "Clock in" Sample timings.
* Create a bitmap of which CLock sample values work and find the "median"
* value. Apply it and remember that we found the best value.
*/
static int dw_mci_exynos_execute_tuning(struct dw_mci_slot *slot, u32 opcode,
struct dw_mci_tuning_data *tuning_data)
{
struct dw_mci *host = slot->host;
struct dw_mci_exynos_priv_data *priv = host->priv;
struct mmc_host *mmc = slot->mmc;
unsigned int tuning_loop = MAX_TUNING_LOOP;
unsigned int drv_str_retries;
bool tuned = 0;
int ret = 0;
u8 *tuning_blk; /* data read from device */
unsigned int sample_good = 0; /* bit map of clock sample (0-7) */
u32 test_sample = -1;
u32 orig_sample;
int best_sample = 0, best_sample_ori = 0;
u8 pass_index;
bool is_fine_tuning = false;
unsigned int abnormal_result = 0xFFFF;
unsigned int temp_ignore_phase = priv->ignore_phase;
int ffs_ignore_phase = 0;
u8 all_pass_count = 0;
bool bypass = false;
while (temp_ignore_phase) {
ffs_ignore_phase = ffs(temp_ignore_phase) - 1;
abnormal_result &= ~(0x3 << (2 * ffs_ignore_phase));
temp_ignore_phase &= ~(0x1 << ffs_ignore_phase);
}
/* Short circuit: don't tune again if we already did. */
if (host->pdata->tuned) {
host->drv_data->misc_control(host, CTRL_RESTORE_CLKSEL, NULL);
mci_writel(host, CDTHRCTL, host->cd_rd_thr << 16 | 1);
dev_info(host->dev, "EN_SHIFT 0x %08x CLKSEL 0x %08x\n",
mci_readl(host, HS400_ENABLE_SHIFT),
mci_readl(host, CLKSEL));
return 0;
}
tuning_blk = kmalloc(2 * tuning_data->blksz, GFP_KERNEL);
if (!tuning_blk)
return -ENOMEM;
test_sample = orig_sample = dw_mci_exynos_get_sample(host);
host->cd_rd_thr = 512;
mci_writel(host, CDTHRCTL, host->cd_rd_thr << 16 | 1);
/*
* eMMC 4.5 spec section 6.6.7.1 says the device is guaranteed to
* complete 40 iteration of CMD21 in 150ms. So this shouldn't take
* longer than about 30ms or so....at least assuming most values
* work and don't time out.
*/
if (host->pdata->io_mode == MMC_TIMING_MMC_HS400)
host->quirks |= DW_MCI_QUIRK_NO_DETECT_EBIT;
dev_info(host->dev, "Tuning Abnormal_result 0x%08x.\n", abnormal_result);
priv->clk_drive_tuning = priv->clk_drive_number;
drv_str_retries = priv->clk_drive_number;
do {
struct mmc_request mrq;
struct mmc_command cmd;
struct mmc_command stop;
struct mmc_data data;
struct scatterlist sg;
if (!tuning_loop)
break;
memset(&cmd, 0, sizeof(cmd));
cmd.opcode = opcode;
cmd.arg = 0;
cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
cmd.error = 0;
cmd.busy_timeout = 10; /* 2x * (150ms/40 + setup overhead) */
memset(&stop, 0, sizeof(stop));
stop.opcode = MMC_STOP_TRANSMISSION;
stop.arg = 0;
stop.flags = MMC_RSP_R1B | MMC_CMD_AC;
stop.error = 0;
memset(&data, 0, sizeof(data));
data.blksz = tuning_data->blksz;
data.blocks = 1;
data.flags = MMC_DATA_READ;
data.sg = &sg;
data.sg_len = 1;
data.error = 0;
memset(tuning_blk, ~0U, tuning_data->blksz);
sg_init_one(&sg, tuning_blk, tuning_data->blksz);
memset(&mrq, 0, sizeof(mrq));
mrq.cmd = &cmd;
mrq.stop = &stop;
mrq.data = &data;
host->mrq = &mrq;
/*
* DDR200 tuning Sequence with fine tuning setup
*
* 0. phase 0 (0 degree) + no fine tuning setup
* - pass_index = 0
* 1. phase 0 + fine tuning setup
* - pass_index = 1
* 2. phase 1 (90 degree) + no fine tuning setup
* - pass_index = 2
* ..
* 15. phase 7 + fine tuning setup
* - pass_index = 15
*
*/
dw_mci_set_fine_tuning_bit(host, is_fine_tuning);
dw_mci_set_timeout(host, dw_mci_calc_timeout(host));
mmc_wait_for_req(mmc, &mrq);
pass_index = (u8)test_sample * 2;
if (is_fine_tuning)
pass_index++;
if (!cmd.error && !data.error) {
/*
* Verify the "tuning block" arrived (to host) intact.
* If yes, remember this sample value works.
*/
if (host->use_dma == 1) {
sample_good |= (1 << pass_index);
} else {
if (!memcmp(tuning_data->blk_pattern, tuning_blk, tuning_data->blksz))
sample_good |= (1 << pass_index);
}
} else {
dev_info(&mmc->class_dev,
"Tuning error: cmd.error:%d, data.error:%d CLKSEL = 0x%08x, EN_SHIFT = 0x%08x\n",
cmd.error, data.error,
mci_readl(host, CLKSEL),
mci_readl(host, HS400_ENABLE_SHIFT));
}
if (is_fine_tuning)
test_sample = dw_mci_tuning_sampling(host);
is_fine_tuning = !is_fine_tuning;
if (orig_sample == test_sample && !is_fine_tuning) {
/*
* Get at middle clock sample values.
*/
if (sample_good == abnormal_result)
all_pass_count++;
if (priv->ctrl_flag & DW_MMC_EXYNOS_BYPASS_FOR_ALL_PASS)
bypass = (all_pass_count > priv->clk_drive_number) ? true : false;
if (bypass) {
dev_info(host->dev, "Bypassed for all pass at %d times\n", priv->clk_drive_number);
sample_good = abnormal_result & 0xFFFF;
tuned = true;
}
best_sample = find_median_of_16bits(host, sample_good, bypass);
if (best_sample >= 0) {
dev_info(host->dev, "sample_good: 0x%02x best_sample: 0x%02x\n",
sample_good, best_sample);
if (sample_good != abnormal_result || bypass) {
tuned = true;
break;
}
} else
dev_info(host->dev,
"Failed to find median value in sample good (0x%02x)\n", sample_good);
if (drv_str_retries) {
drv_str_retries--;
if (priv->clk_drive_str[0]) {
exynos_dwmci_tuning_drv_st(host);
if (priv->clk_drive_tuning > 0)
priv->clk_drive_tuning--;
}
sample_good = 0;
} else
break;
}
tuning_loop--;
} while (!tuned);
/*
* To set sample value with mid, the value should be divided by 2,
* because mid represents index in pass map extended.(8 -> 16 bits)
* And that mid is odd number, means the selected case includes
* using fine tuning.
*/
best_sample_ori = best_sample;
best_sample /= 2;
if (host->pdata->io_mode == MMC_TIMING_MMC_HS400)
host->quirks &= ~DW_MCI_QUIRK_NO_DETECT_EBIT;
if (tuned) {
host->pdata->clk_smpl = priv->tuned_sample = best_sample;
if (host->pdata->only_once_tune)
host->pdata->tuned = true;
if (best_sample_ori % 2)
best_sample += 1;
dw_mci_exynos_set_sample(host, best_sample, false);
dw_mci_set_fine_tuning_bit(host, false);
} else {
/* Failed. Just restore and return error */
dev_err(host->dev, "tuning err\n");
mci_writel(host, CDTHRCTL, 0 << 16 | 0);
dw_mci_exynos_set_sample(host, orig_sample, false);
ret = -EIO;
}
/* Rollback Clock drive strength */
if (priv->pinctrl && priv->clk_drive_base)
pinctrl_select_state(priv->pinctrl, priv->clk_drive_base);
dev_info(host->dev, "CLKSEL = 0x%08x, EN_SHIFT = 0x%08x\n",
mci_readl(host, CLKSEL),
mci_readl(host, HS400_ENABLE_SHIFT));
kfree(tuning_blk);
return ret;
}
static struct device *sd_detection_cmd_dev;
static ssize_t sd_detection_cmd_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct dw_mci *host = dev_get_drvdata(dev);
struct dw_mci_exynos_priv_data *priv = host->priv;
if (host->cur_slot && host->cur_slot->mmc && host->cur_slot->mmc->card) {
if (priv->sec_sd_slot_type > 0 && !gpio_is_valid(priv->cd_gpio))
goto gpio_error;
dev_info(host->dev, "SD card inserted.\n");
return sprintf(buf, "Insert\n");
} else {
if (priv->sec_sd_slot_type > 0 && !gpio_is_valid(priv->cd_gpio))
goto gpio_error;
if (gpio_get_value(priv->cd_gpio)
&& priv->sec_sd_slot_type == SEC_HYBRID_SD_SLOT) {
dev_info(host->dev, "SD slot tray Removed.\n");
return sprintf(buf, "Notray\n");
}
dev_info(host->dev, "SD card removed.\n");
return sprintf(buf, "Remove\n");
}
gpio_error:
dev_info(host->dev, "%s : External SD detect pin Error\n", __func__);
return sprintf(buf, "Error\n");
}
static ssize_t sd_detection_cnt_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct dw_mci *host = dev_get_drvdata(dev);
dev_info(host->dev, "%s : CD count is = %u\n", __func__, host->card_detect_cnt);
return sprintf(buf, "%u", host->card_detect_cnt);
}
static ssize_t sd_detection_maxmode_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct dw_mci *host = dev_get_drvdata(dev);
const char *uhs_bus_speed_mode = "";
struct device_node *np = host->dev->of_node;
if (of_find_property(np, "sd-uhs-sdr104", NULL))
uhs_bus_speed_mode = "SDR104";
else if (of_find_property(np, "sd-uhs-ddr50", NULL))
uhs_bus_speed_mode = "DDR50";
else if (of_find_property(np, "sd-uhs-sdr50", NULL))
uhs_bus_speed_mode = "SDR50";
else if (of_find_property(np, "sd-uhs-sdr25", NULL))
uhs_bus_speed_mode = "SDR25";
else if (of_find_property(np, "sd-uhs-sdr12", NULL))
uhs_bus_speed_mode = "SDR12";
else
uhs_bus_speed_mode = "HS";
dev_info(host->dev, "%s : Max supported Host Speed Mode = %s\n", __func__, uhs_bus_speed_mode);
return sprintf(buf, "%s\n", uhs_bus_speed_mode);
}
static ssize_t sd_detection_curmode_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct dw_mci *host = dev_get_drvdata(dev);
const char *uhs_bus_speed_mode = "";
static const char *const uhs_speeds[] = {
[UHS_SDR12_BUS_SPEED] = "SDR12",
[UHS_SDR25_BUS_SPEED] = "SDR25",
[UHS_SDR50_BUS_SPEED] = "SDR50",
[UHS_SDR104_BUS_SPEED] = "SDR104",
[UHS_DDR50_BUS_SPEED] = "DDR50",
};
if (host->cur_slot && host->cur_slot->mmc && host->cur_slot->mmc->card) {
if (mmc_card_uhs(host->cur_slot->mmc->card))
uhs_bus_speed_mode = uhs_speeds[host->cur_slot->mmc->card->sd_bus_speed];
else
uhs_bus_speed_mode = "HS";
} else
uhs_bus_speed_mode = "No Card";
dev_info(host->dev, "%s : Current SD Card Speed = %s\n", __func__, uhs_bus_speed_mode);
return sprintf(buf, "%s\n", uhs_bus_speed_mode);
}
static ssize_t sdcard_summary_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct dw_mci *host = dev_get_drvdata(dev);
struct mmc_card *card;
const char *uhs_bus_speed_mode = "";
static const char *const uhs_speeds[] = {
[UHS_SDR12_BUS_SPEED] = "SDR12",
[UHS_SDR25_BUS_SPEED] = "SDR25",
[UHS_SDR50_BUS_SPEED] = "SDR50",
[UHS_SDR104_BUS_SPEED] = "SDR104",
[UHS_DDR50_BUS_SPEED] = "DDR50",
};
static const char *const unit[] = {"KB", "MB", "GB", "TB"};
unsigned int size, serial;
int digit = 1;
char ret_size[6];
if (host->cur_slot && host->cur_slot->mmc && host->cur_slot->mmc->card) {
card = host->cur_slot->mmc->card;
/* MANID */
/* SERIAL */
serial = card->cid.serial & (0x0000FFFF);
/*SIZE*/
if (card->csd.read_blkbits == 9) /* 1 Sector = 512 Bytes */
size = (card->csd.capacity) >> 1;
else if (card->csd.read_blkbits == 11) /* 1 Sector = 2048 Bytes */
size = (card->csd.capacity) << 1;
else /* 1 Sector = 1024 Bytes */
size = card->csd.capacity;
if (size >= 380000000 && size <= 410000000) { /* QUIRK 400GB SD Card */
sprintf(ret_size, "400GB");
} else if(size >= 190000000 && size <= 210000000) { /* QUIRK 200GB SD Card */
sprintf(ret_size, "200GB");
} else {
while ((size >> 1) > 0) {
size = size >> 1;
digit++;
}
sprintf(ret_size, "%d%s", 1 << (digit%10), unit[digit/10]);
}
/* SPEEDMODE */
if (mmc_card_uhs(card))
uhs_bus_speed_mode = uhs_speeds[card->sd_bus_speed];
else if (mmc_card_hs(card))
uhs_bus_speed_mode = "HS";
else
uhs_bus_speed_mode = "DS";
/* SUMMARY */
dev_info(host->dev, "MANID : 0x%02X, SERIAL : %04X, SIZE : %s, SPEEDMODE : %s\n",
card->cid.manfid, serial, ret_size, uhs_bus_speed_mode);
return sprintf(buf, "\"MANID\":\"0x%02X\",\"SERIAL\":\"%04X\""\
",\"SIZE\":\"%s\",\"SPEEDMODE\":\"%s\",\"NOTI\":\"%d\"\n",
card->cid.manfid, serial, ret_size, uhs_bus_speed_mode,
card->err_log[0].noti_cnt);
} else {
/* SUMMARY : No SD Card Case */
dev_info(host->dev, "%s : No SD Card\n", __func__);
return sprintf(buf, "\"MANID\":\"NoCard\",\"SERIAL\":\"NoCard\""\
",\"SIZE\":\"NoCard\",\"SPEEDMODE\":\"NoCard\",\"NOTI\":\"NoCard\"\n");
}
}
static struct device *sd_info_cmd_dev;
static ssize_t sd_count_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct dw_mci *host = dev_get_drvdata(dev);
struct mmc_card *cur_card = NULL;
struct mmc_card_error_log *err_log;
u64 total_cnt = 0;
int len = 0;
int i = 0;
if (host->cur_slot && host->cur_slot->mmc && host->cur_slot->mmc->card)
cur_card = host->cur_slot->mmc->card;
else {
len = snprintf(buf, PAGE_SIZE, "no card\n");
goto out;
}
err_log = cur_card->err_log;
for (i = 0; i < 6; i++) {
if (total_cnt < MAX_CNT_U64)
total_cnt += err_log[i].count;
}
len = snprintf(buf, PAGE_SIZE, "%lld\n", total_cnt);
out:
return len;
}
static struct device *sd_data_cmd_dev;
static ssize_t sd_data_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct dw_mci *host = dev_get_drvdata(dev);
struct mmc_card *cur_card = NULL;
struct mmc_card_error_log *err_log;
u64 total_c_cnt = 0;
u64 total_t_cnt = 0;
int len = 0;
int i = 0;
if (host->cur_slot && host->cur_slot->mmc && host->cur_slot->mmc->card)
cur_card = host->cur_slot->mmc->card;
else {
len = snprintf(buf, PAGE_SIZE,
"\"GE\":\"0\",\"CC\":\"0\",\"ECC\":\"0\",\"WP\":\"0\"\
,\"OOR\":\"0\",\"CRC\":\"0\",\"TMO\":\"0\"\n");
goto out;
}
err_log = cur_card->err_log;
for (i = 0; i < 6; i++) {
if (err_log[i].err_type == -EILSEQ && total_c_cnt < MAX_CNT_U64)
total_c_cnt += err_log[i].count;
if (err_log[i].err_type == -ETIMEDOUT && total_t_cnt < MAX_CNT_U64)
total_t_cnt += err_log[i].count;
}
len = snprintf(buf, PAGE_SIZE,
"\"GE\":\"%d\",\"CC\":\"%d\",\"ECC\":\"%d\",\"WP\":\"%d\"\
,\"OOR\":\"%d\",\"CRC\":\"%lld\",\"TMO\":\"%lld\"\n",
err_log[0].ge_cnt, err_log[0].cc_cnt, err_log[0].ecc_cnt, err_log[0].wp_cnt,
err_log[0].oor_cnt, total_c_cnt, total_t_cnt);
out:
return len;
}
static ssize_t sd_cid_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct dw_mci *host = dev_get_drvdata(dev);
struct mmc_card *cur_card = NULL;
int len = 0;
if (host->cur_slot && host->cur_slot->mmc && host->cur_slot->mmc->card)
cur_card = host->cur_slot->mmc->card;
else {
len = snprintf(buf, PAGE_SIZE, "No Card\n");
goto out;
}
len = snprintf(buf, PAGE_SIZE,
"%08x%08x%08x%08x\n",
cur_card->raw_cid[0], cur_card->raw_cid[1],
cur_card->raw_cid[2], cur_card->raw_cid[3]);
out:
return len;
}
static DEVICE_ATTR(status, 0444, sd_detection_cmd_show, NULL);
static DEVICE_ATTR(cd_cnt, 0444, sd_detection_cnt_show, NULL);
static DEVICE_ATTR(max_mode, 0444, sd_detection_maxmode_show, NULL);
static DEVICE_ATTR(current_mode, 0444, sd_detection_curmode_show, NULL);
static DEVICE_ATTR(sdcard_summary, 0444, sdcard_summary_show, NULL);
static DEVICE_ATTR(sd_count, 0444, sd_count_show, NULL);
static DEVICE_ATTR(sd_data, 0444, sd_data_show, NULL);
static DEVICE_ATTR(data, 0444, sd_cid_show, NULL);
/* Callback function for SD Card IO Error */
static int sdcard_uevent(struct mmc_card *card)
{
pr_info("%s: Send Notification about SD Card IO Error\n", mmc_hostname(card->host));
return kobject_uevent(&sd_detection_cmd_dev->kobj, KOBJ_CHANGE);
}
static int dw_mci_sdcard_uevent(struct device *dev, struct kobj_uevent_env *env)
{
struct dw_mci *host = dev_get_drvdata(dev);
struct mmc_card *card;
int retval;
bool card_exist;
add_uevent_var(env, "DEVNAME=%s", dev->kobj.name);
if (host->cur_slot && host->cur_slot->mmc && host->cur_slot->mmc->card) {
card_exist = true;
card = host->cur_slot->mmc->card;
} else
card_exist = false;
retval = add_uevent_var(env, "IOERROR=%s", card_exist ? (
((card->err_log[0].ge_cnt && !(card->err_log[0].ge_cnt % 1000)) ||
(card->err_log[0].ecc_cnt && !(card->err_log[0].ecc_cnt % 1000)) ||
(card->err_log[0].wp_cnt && !(card->err_log[0].wp_cnt % 100)) ||
(card->err_log[0].oor_cnt && !(card->err_log[0].oor_cnt % 100)))
? "YES" : "NO") : "NoCard");
return retval;
}
static struct device_type sdcard_type = {
.uevent = dw_mci_sdcard_uevent,
};
static int dw_mci_exynos_request_ext_irq(struct dw_mci *host,
irq_handler_t func)
{
struct dw_mci_exynos_priv_data *priv = host->priv;
int ext_cd_irq = 0;
if (gpio_is_valid(priv->cd_gpio) &&
!gpio_request(priv->cd_gpio, "DWMCI_EXT_CD")) {
ext_cd_irq = gpio_to_irq(priv->cd_gpio);
if (ext_cd_irq &&
devm_request_irq(host->dev, ext_cd_irq, func,
IRQF_TRIGGER_RISING |
IRQF_TRIGGER_FALLING |
IRQF_ONESHOT,
"tflash_det", host) == 0) {
dev_warn(host->dev, "success to request irq for card detect.\n");
enable_irq_wake(ext_cd_irq);
} else
dev_warn(host->dev, "cannot request irq for card detect.\n");
}
return 0;
}
static int dw_mci_exynos_check_cd(struct dw_mci *host)
{
int ret = -1;
struct dw_mci_exynos_priv_data *priv = host->priv;
if (gpio_is_valid(priv->cd_gpio)) {
if(host->pdata->use_gpio_invert)
ret = gpio_get_value(priv->cd_gpio) ? 1 : 0;
else
ret = gpio_get_value(priv->cd_gpio) ? 0 : 1;
}
return ret;
}
static void dw_mci_exynos_add_sysfs(struct dw_mci *host)
{
struct dw_mci_exynos_priv_data *priv = host->priv;
if ((priv->sec_sd_slot_type) >= 0) {
if (!sd_detection_cmd_dev) {
sd_detection_cmd_dev = sec_device_create(host, "sdcard");
if (IS_ERR(sd_detection_cmd_dev))
pr_err("Fail to create sysfs dev\n");
sd_detection_cmd_dev->type = &sdcard_type;
host->slot[0]->mmc->sdcard_uevent = sdcard_uevent;
if (device_create_file(sd_detection_cmd_dev,
&dev_attr_status) < 0)
pr_err("Fail to create status sysfs file\n");
if (device_create_file(sd_detection_cmd_dev,
&dev_attr_cd_cnt) < 0)
pr_err("Fail to create cd_cnt sysfs file\n");
if (device_create_file(sd_detection_cmd_dev,
&dev_attr_max_mode) < 0)
pr_err("Fail to create max_mode sysfs file\n");
if (device_create_file(sd_detection_cmd_dev,
&dev_attr_current_mode) < 0)
pr_err("Fail to create current_mode sysfs file\n");
if (device_create_file(sd_detection_cmd_dev,
&dev_attr_sdcard_summary) < 0)
pr_err("Fail to create sdcard_summary sysfs file\n");
}
if (!sd_info_cmd_dev) {
sd_info_cmd_dev = sec_device_create(host, "sdinfo");
if (IS_ERR(sd_info_cmd_dev))
pr_err("Fail to create sysfs dev\n");
if (device_create_file(sd_info_cmd_dev,
&dev_attr_sd_count) < 0)
pr_err("Fail to create status sysfs file\n");
if (device_create_file(sd_info_cmd_dev,
&dev_attr_data) < 0)
pr_err("Fail to create status sysfs file\n");
}
if (!sd_data_cmd_dev) {
sd_data_cmd_dev = sec_device_create(host, "sddata");
if (IS_ERR(sd_data_cmd_dev))
pr_err("Fail to create sysfs dev\n");
if (device_create_file(sd_data_cmd_dev,
&dev_attr_sd_data) < 0)
pr_err("Fail to create status sysfs file\n");
}
}
}
#if 0
static s8 dw_mci_exynos_get_best_clksmpl(u8 candiates)
{
const u8 iter = 8;
u8 __c;
s8 i, loc = -1;
for (i = 0; i < iter; i++) {
__c = ror8(candiates, i);
if ((__c & 0xc7) == 0xc7) {
loc = i;
goto out;
}
}
for (i = 0; i < iter; i++) {
__c = ror8(candiates, i);
if ((__c & 0x83) == 0x83) {
loc = i;
goto out;
}
}
out:
return loc;
}
static int dw_mci_exynos_execute_tuning(struct dw_mci_slot *slot, u32 opcode)
{
struct dw_mci *host = slot->host;
struct dw_mci_exynos_priv_data *priv = host->priv;
struct mmc_host *mmc = slot->mmc;
u8 start_smpl, smpl, candiates = 0;
s8 found = -1;
int ret = 0;
start_smpl = dw_mci_exynos_get_clksmpl(host);
do {
mci_writel(host, TMOUT, ~0);
smpl = dw_mci_exynos_move_next_clksmpl(host);
if (!mmc_send_tuning(mmc, opcode, NULL))
candiates |= (1 << smpl);
} while (start_smpl != smpl);
found = dw_mci_exynos_get_best_clksmpl(candiates);
if (found >= 0) {
dw_mci_exynos_set_clksmpl(host, found);
priv->tuned_sample = found;
} else {
ret = -EIO;
}
return ret;
}
#endif
#if 0
static int dw_mci_exynos_prepare_hs400_tuning(struct dw_mci *host,
struct mmc_ios *ios)
{
struct dw_mci_exynos_priv_data *priv = host->priv;
dw_mci_exynos_set_clksel_timing(host, priv->hs400_timing);
dw_mci_exynos_adjust_clock(host, (ios->clock) << 1);
return 0;
}
#endif
/* Common capabilities of Exynos4/Exynos5 SoC */
static unsigned long exynos_dwmmc_caps[4] = {
MMC_CAP_1_8V_DDR | MMC_CAP_8_BIT_DATA | MMC_CAP_CMD23,
MMC_CAP_CMD23,
MMC_CAP_CMD23,
MMC_CAP_CMD23,
};
static int dw_mci_exynos_misc_control(struct dw_mci *host,
enum dw_mci_misc_control control, void *priv)
{
int ret = 0;
switch (control) {
case CTRL_RESTORE_CLKSEL:
dw_mci_exynos_set_sample(host, host->pdata->clk_smpl, false);
dw_mci_set_fine_tuning_bit(host, host->pdata->is_fine_tuned);
break;
case CTRL_REQUEST_EXT_IRQ:
ret = dw_mci_exynos_request_ext_irq(host, (irq_handler_t)priv);
break;
case CTRL_CHECK_CD:
ret = dw_mci_exynos_check_cd(host);
break;
case CTRL_ADD_SYSFS:
dw_mci_exynos_add_sysfs(host);
break;
default:
dev_err(host->dev, "dw_mmc exynos: wrong case\n");
ret = -ENODEV;
}
return ret;
}
static int dw_mci_exynos_crypto_engine_cfg(struct dw_mci *host,
void *desc,
struct mmc_data *data,
struct page *page,
int sector_offset,
bool cmdq_enabled)
{
return exynos_mmc_fmp_cfg(host, desc, data, page, sector_offset, cmdq_enabled);
}
static int dw_mci_exynos_crypto_engine_clear(struct dw_mci *host, void *desc,
bool cmdq_enabled)
{
return exynos_mmc_fmp_clear(host, desc, cmdq_enabled);
}
static int dw_mci_exynos_access_control_get_dev(struct dw_mci *host)
{
return exynos_mmc_smu_get_dev(host);
}
static int dw_mci_exynos_access_control_sec_cfg(struct dw_mci *host)
{
return exynos_mmc_smu_sec_cfg(host);
}
static int dw_mci_exynos_access_control_init(struct dw_mci *host)
{
return exynos_mmc_smu_init(host);
}
static int dw_mci_exynos_access_control_abort(struct dw_mci *host)
{
return exynos_mmc_smu_abort(host);
}
static int dw_mci_exynos_access_control_resume(struct dw_mci *host)
{
return exynos_mmc_smu_resume(host);
}
static const struct dw_mci_drv_data exynos_drv_data = {
.caps = exynos_dwmmc_caps,
.init = dw_mci_exynos_priv_init,
.set_ios = dw_mci_exynos_set_ios,
.parse_dt = dw_mci_exynos_parse_dt,
.execute_tuning = dw_mci_exynos_execute_tuning,
.hwacg_control = dw_mci_card_int_hwacg_ctrl,
#if 0
.prepare_hs400_tuning = dw_mci_exynos_prepare_hs400_tuning,
#endif
.misc_control = dw_mci_exynos_misc_control,
.crypto_engine_cfg = dw_mci_exynos_crypto_engine_cfg,
.crypto_engine_clear = dw_mci_exynos_crypto_engine_clear,
.access_control_get_dev = dw_mci_exynos_access_control_get_dev,
.access_control_sec_cfg = dw_mci_exynos_access_control_sec_cfg,
.access_control_init = dw_mci_exynos_access_control_init,
.access_control_abort = dw_mci_exynos_access_control_abort,
.access_control_resume = dw_mci_exynos_access_control_resume,
.ssclk_control = dw_mci_ssclk_control,
};
static const struct of_device_id dw_mci_exynos_match[] = {
{ .compatible = "samsung,exynos-dw-mshc",
.data = &exynos_drv_data, },
{},
};
MODULE_DEVICE_TABLE(of, dw_mci_exynos_match);
static int dw_mci_exynos_probe(struct platform_device *pdev)
{
const struct dw_mci_drv_data *drv_data;
const struct of_device_id *match;
match = of_match_node(dw_mci_exynos_match, pdev->dev.of_node);
drv_data = match->data;
return dw_mci_pltfm_register(pdev, drv_data);
}
static const struct dev_pm_ops dw_mci_exynos_pmops = {
SET_SYSTEM_SLEEP_PM_OPS(dw_mci_exynos_suspend, dw_mci_exynos_resume)
.resume_noirq = dw_mci_exynos_resume_noirq,
.thaw_noirq = dw_mci_exynos_resume_noirq,
.restore_noirq = dw_mci_exynos_resume_noirq,
};
static struct platform_driver dw_mci_exynos_pltfm_driver = {
.probe = dw_mci_exynos_probe,
.remove = dw_mci_pltfm_remove,
.driver = {
.name = "dwmmc_exynos",
.of_match_table = dw_mci_exynos_match,
.pm = &dw_mci_exynos_pmops,
.suppress_bind_attrs = true,
},
};
module_platform_driver(dw_mci_exynos_pltfm_driver);
MODULE_DESCRIPTION("Samsung Specific DW-MSHC Driver Extension");
MODULE_AUTHOR("Thomas Abraham <thomas.ab@samsung.com");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("platform:dwmmc_exynos");
|