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
|
From 9875df1e872eb2b0f9d2d72c9a761a5f03400d9f Mon Sep 17 00:00:00 2001
From: Biwen Li <biwen.li@nxp.com>
Date: Fri, 19 Apr 2019 13:23:01 +0800
Subject: [PATCH] flexspi: support layerscape
This is an integrated patch of flexspi for layerscape
Signed-off-by: Ashish Kumar <Ashish.Kumar@nxp.com>
Signed-off-by: Biwen Li <biwen.li@nxp.com>
Signed-off-by: Rajat Srivastava <rajat.srivastava@nxp.com>
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Signed-off-by: Yogesh Gaur <yogeshnarayan.gaur@nxp.com>
---
.../devicetree/bindings/mtd/nxp-flexspi.txt | 41 +
drivers/mtd/spi-nor/Kconfig | 10 +
drivers/mtd/spi-nor/Makefile | 1 +
drivers/mtd/spi-nor/nxp-flexspi.c | 1404 +++++++++++++++++
drivers/mtd/spi-nor/spi-nor.c | 13 +-
include/linux/mtd/cfi.h | 1 +
include/linux/mtd/spi-nor.h | 3 +-
7 files changed, 1470 insertions(+), 3 deletions(-)
create mode 100644 Documentation/devicetree/bindings/mtd/nxp-flexspi.txt
create mode 100644 drivers/mtd/spi-nor/nxp-flexspi.c
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/nxp-flexspi.txt
@@ -0,0 +1,41 @@
+* NXP Flex Serial Peripheral Interface(FlexSPI)
+
+Required properties:
+ - compatible : Should be "nxp,lx2160a-fspi"
+ - reg : the first contains the register location and length,
+ the second contains the memory mapping address and length
+ - reg-names: Should contain the reg names "FSPI" and "FSPI-memory"
+ - interrupts : Should contain the interrupt for the device
+ - clocks : The clocks needed by the FlexSPI controller
+ - clock-names : Should contain the name of the clocks: "fspi_en" and "fspi"
+
+Optional properties:
+ - nxp,fspi-has-second-chip: The controller has two buses, bus A and bus B.
+ Each bus can be connected with two NOR flashes.
+ Most of the time, each bus only has one NOR flash
+ connected, this is the default case.
+ But if there are two NOR flashes connected to the
+ bus, you should enable this property.
+ (Please check the board's schematic.)
+Example:
+fspi0: flexspi@20c0000 {
+ compatible = "nxp,lx2160a-fspi";
+ reg = <0x0 0x20c0000 0x0 0x10000>, <0x0 0x20000000 0x0 0x10000000>;
+ reg-names = "FSPI", "FSPI-memory";
+ interrupts = <0 25 0x4>; /* Level high type */
+ clocks = <&clockgen 4 3>, <&clockgen 4 3>;
+ clock-names = "fspi_en", "fspi";
+
+ status = "okay";
+ nxp,fspi-has-second-chip;
+ flash0: mt35xu512aba@0 {
+ reg = <0>;
+ ....
+ };
+
+ flash1: mt35xu512aba@1 {
+ reg = <1>;
+ ....
+ };
+
+};
--- a/drivers/mtd/spi-nor/Kconfig
+++ b/drivers/mtd/spi-nor/Kconfig
@@ -97,6 +97,16 @@ config SPI_NXP_SPIFI
Flash. Enable this option if you have a device with a SPIFI
controller and want to access the Flash as a mtd device.
+config SPI_NXP_FLEXSPI
+ tristate "NXP Flex SPI controller"
+ help
+ This enables support for the Flex SPI controller in master mode.
+ Up to four slave devices can be connected on two buses with two
+ chipselects each.
+ This controller does not support generic SPI messages and only
+ supports the high-level SPI memory interface using SPI-NOR
+ framework.
+
config SPI_INTEL_SPI
tristate
--- a/drivers/mtd/spi-nor/Makefile
+++ b/drivers/mtd/spi-nor/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_SPI_FSL_QUADSPI) += fsl-qua
obj-$(CONFIG_SPI_HISI_SFC) += hisi-sfc.o
obj-$(CONFIG_MTD_MT81xx_NOR) += mtk-quadspi.o
obj-$(CONFIG_SPI_NXP_SPIFI) += nxp-spifi.o
+obj-$(CONFIG_SPI_NXP_FLEXSPI) += nxp-flexspi.o
obj-$(CONFIG_SPI_INTEL_SPI) += intel-spi.o
obj-$(CONFIG_SPI_INTEL_SPI_PCI) += intel-spi-pci.o
obj-$(CONFIG_SPI_INTEL_SPI_PLATFORM) += intel-spi-platform.o
--- /dev/null
+++ b/drivers/mtd/spi-nor/nxp-flexspi.c
@@ -0,0 +1,1404 @@
+/*
+ * NXP FSPI(FlexSPI controller) driver.
+ *
+ * Copyright 2018 NXP
+ * Author: Yogesh Gaur <yogeshnarayan.gaur@nxp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/errno.h>
+#include <linux/platform_device.h>
+#include <linux/sched.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/timer.h>
+#include <linux/jiffies.h>
+#include <linux/completion.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+#include <linux/mtd/spi-nor.h>
+#include <linux/mutex.h>
+#include <linux/pm_qos.h>
+#include <linux/pci.h>
+
+/* The registers */
+#define FSPI_MCR0 0x00
+#define FSPI_MCR0_AHB_TIMEOUT_SHIFT 24
+#define FSPI_MCR0_AHB_TIMEOUT_MASK (0xFF << FSPI_MCR0_AHB_TIMEOUT_SHIFT)
+#define FSPI_MCR0_IP_TIMEOUT_SHIFT 16
+#define FSPI_MCR0_IP_TIMEOUT_MASK (0xFF << FSPI_MCR0_IP_TIMEOUT_SHIFT)
+#define FSPI_MCR0_LEARN_EN_SHIFT 15
+#define FSPI_MCR0_LEARN_EN_MASK (1 << FSPI_MCR0_LEARN_EN_SHIFT)
+#define FSPI_MCR0_SCRFRUN_EN_SHIFT 14
+#define FSPI_MCR0_SCRFRUN_EN_MASK (1 << FSPI_MCR0_SCRFRUN_EN_SHIFT)
+#define FSPI_MCR0_OCTCOMB_EN_SHIFT 13
+#define FSPI_MCR0_OCTCOMB_EN_MASK (1 << FSPI_MCR0_OCTCOMB_EN_SHIFT)
+#define FSPI_MCR0_DOZE_EN_SHIFT 12
+#define FSPI_MCR0_DOZE_EN_MASK (1 << FSPI_MCR0_DOZE_EN_SHIFT)
+#define FSPI_MCR0_HSEN_SHIFT 11
+#define FSPI_MCR0_HSEN_MASK (1 << FSPI_MCR0_HSEN_SHIFT)
+#define FSPI_MCR0_SERCLKDIV_SHIFT 8
+#define FSPI_MCR0_SERCLKDIV_MASK (7 << FSPI_MCR0_SERCLKDIV_SHIFT)
+#define FSPI_MCR0_ATDF_EN_SHIFT 7
+#define FSPI_MCR0_ATDF_EN_MASK (1 << FSPI_MCR0_ATDF_EN_SHIFT)
+#define FSPI_MCR0_ARDF_EN_SHIFT 6
+#define FSPI_MCR0_ARDF_EN_MASK (1 << FSPI_MCR0_ARDF_EN_SHIFT)
+#define FSPI_MCR0_RXCLKSRC_SHIFT 4
+#define FSPI_MCR0_RXCLKSRC_MASK (3 << FSPI_MCR0_RXCLKSRC_SHIFT)
+#define FSPI_MCR0_END_CFG_SHIFT 2
+#define FSPI_MCR0_END_CFG_MASK (3 << FSPI_MCR0_END_CFG_SHIFT)
+#define FSPI_MCR0_MDIS_SHIFT 1
+#define FSPI_MCR0_MDIS_MASK (1 << FSPI_MCR0_MDIS_SHIFT)
+#define FSPI_MCR0_SWRST_SHIFT 0
+#define FSPI_MCR0_SWRST_MASK (1 << FSPI_MCR0_SWRST_SHIFT)
+
+#define FSPI_MCR1 0x04
+#define FSPI_MCR1_SEQ_TIMEOUT_SHIFT 16
+#define FSPI_MCR1_SEQ_TIMEOUT_MASK \
+ (0xFFFF << FSPI_MCR1_SEQ_TIMEOUT_SHIFT)
+#define FSPI_MCR1_AHB_TIMEOUT_SHIFT 0
+#define FSPI_MCR1_AHB_TIMEOUT_MASK \
+ (0xFFFF << FSPI_MCR1_AHB_TIMEOUT_SHIFT)
+
+#define FSPI_MCR2 0x08
+#define FSPI_MCR2_IDLE_WAIT_SHIFT 24
+#define FSPI_MCR2_IDLE_WAIT_MASK (0xFF << FSPI_MCR2_IDLE_WAIT_SHIFT)
+#define FSPI_MCR2_SAMEFLASH_SHIFT 15
+#define FSPI_MCR2_SAMEFLASH_MASK (1 << FSPI_MCR2_SAMEFLASH_SHIFT)
+#define FSPI_MCR2_CLRLRPHS_SHIFT 14
+#define FSPI_MCR2_CLRLRPHS_MASK (1 << FSPI_MCR2_CLRLRPHS_SHIFT)
+#define FSPI_MCR2_ABRDATSZ_SHIFT 8
+#define FSPI_MCR2_ABRDATSZ_MASK (1 << FSPI_MCR2_ABRDATSZ_SHIFT)
+#define FSPI_MCR2_ABRLEARN_SHIFT 7
+#define FSPI_MCR2_ABRLEARN_MASK (1 << FSPI_MCR2_ABRLEARN_SHIFT)
+#define FSPI_MCR2_ABR_READ_SHIFT 6
+#define FSPI_MCR2_ABR_READ_MASK (1 << FSPI_MCR2_ABR_READ_SHIFT)
+#define FSPI_MCR2_ABRWRITE_SHIFT 5
+#define FSPI_MCR2_ABRWRITE_MASK (1 << FSPI_MCR2_ABRWRITE_SHIFT)
+#define FSPI_MCR2_ABRDUMMY_SHIFT 4
+#define FSPI_MCR2_ABRDUMMY_MASK (1 << FSPI_MCR2_ABRDUMMY_SHIFT)
+#define FSPI_MCR2_ABR_MODE_SHIFT 3
+#define FSPI_MCR2_ABR_MODE_MASK (1 << FSPI_MCR2_ABR_MODE_SHIFT)
+#define FSPI_MCR2_ABRCADDR_SHIFT 2
+#define FSPI_MCR2_ABRCADDR_MASK (1 << FSPI_MCR2_ABRCADDR_SHIFT)
+#define FSPI_MCR2_ABRRADDR_SHIFT 1
+#define FSPI_MCR2_ABRRADDR_MASK (1 << FSPI_MCR2_ABRRADDR_SHIFT)
+#define FSPI_MCR2_ABR_CMD_SHIFT 0
+#define FSPI_MCR2_ABR_CMD_MASK (1 << FSPI_MCR2_ABR_CMD_SHIFT)
+
+#define FSPI_AHBCR 0x0c
+#define FSPI_AHBCR_RDADDROPT_SHIFT 6
+#define FSPI_AHBCR_RDADDROPT_MASK (1 << FSPI_AHBCR_RDADDROPT_SHIFT)
+#define FSPI_AHBCR_PREF_EN_SHIFT 5
+#define FSPI_AHBCR_PREF_EN_MASK (1 << FSPI_AHBCR_PREF_EN_SHIFT)
+#define FSPI_AHBCR_BUFF_EN_SHIFT 4
+#define FSPI_AHBCR_BUFF_EN_MASK (1 << FSPI_AHBCR_BUFF_EN_SHIFT)
+#define FSPI_AHBCR_CACH_EN_SHIFT 3
+#define FSPI_AHBCR_CACH_EN_MASK (1 << FSPI_AHBCR_CACH_EN_SHIFT)
+#define FSPI_AHBCR_CLRTXBUF_SHIFT 2
+#define FSPI_AHBCR_CLRTXBUF_MASK (1 << FSPI_AHBCR_CLRTXBUF_SHIFT)
+#define FSPI_AHBCR_CLRRXBUF_SHIFT 1
+#define FSPI_AHBCR_CLRRXBUF_MASK (1 << FSPI_AHBCR_CLRRXBUF_SHIFT)
+#define FSPI_AHBCR_PAR_EN_SHIFT 0
+#define FSPI_AHBCR_PAR_EN_MASK (1 << FSPI_AHBCR_PAR_EN_SHIFT)
+
+#define FSPI_INTEN 0x10
+#define FSPI_INTEN_SCLKSBWR_SHIFT 9
+#define FSPI_INTEN_SCLKSBWR_MASK (1 << FSPI_INTEN_SCLKSBWR_SHIFT)
+#define FSPI_INTEN_SCLKSBRD_SHIFT 8
+#define FSPI_INTEN_SCLKSBRD_MASK (1 << FSPI_INTEN_SCLKSBRD_SHIFT)
+#define FSPI_INTEN_DATALRNFL_SHIFT 7
+#define FSPI_INTEN_DATALRNFL_MASK (1 << FSPI_INTEN_DATALRNFL_SHIFT)
+#define FSPI_INTEN_IPTXWE_SHIFT 6
+#define FSPI_INTEN_IPTXWE_MASK (1 << FSPI_INTEN_IPTXWE_SHIFT)
+#define FSPI_INTEN_IPRXWA_SHIFT 5
+#define FSPI_INTEN_IPRXWA_MASK (1 << FSPI_INTEN_IPRXWA_SHIFT)
+#define FSPI_INTEN_AHBCMDERR_SHIFT 4
+#define FSPI_INTEN_AHBCMDERR_MASK (1 << FSPI_INTEN_AHBCMDERR_SHIFT)
+#define FSPI_INTEN_IPCMDERR_SHIFT 3
+#define FSPI_INTEN_IPCMDERR_MASK (1 << FSPI_INTEN_IPCMDERR_SHIFT)
+#define FSPI_INTEN_AHBCMDGE_SHIFT 2
+#define FSPI_INTEN_AHBCMDGE_MASK (1 << FSPI_INTEN_AHBCMDGE_SHIFT)
+#define FSPI_INTEN_IPCMDGE_SHIFT 1
+#define FSPI_INTEN_IPCMDGE_MASK (1 << FSPI_INTEN_IPCMDGE_SHIFT)
+#define FSPI_INTEN_IPCMDDONE_SHIFT 0
+#define FSPI_INTEN_IPCMDDONE_MASK (1 << FSPI_INTEN_IPCMDDONE_SHIFT)
+
+#define FSPI_INTR 0x14
+#define FSPI_INTR_SCLKSBWR_SHIFT 9
+#define FSPI_INTR_SCLKSBWR_MASK (1 << FSPI_INTR_SCLKSBWR_SHIFT)
+#define FSPI_INTR_SCLKSBRD_SHIFT 8
+#define FSPI_INTR_SCLKSBRD_MASK (1 << FSPI_INTR_SCLKSBRD_SHIFT)
+#define FSPI_INTR_DATALRNFL_SHIFT 7
+#define FSPI_INTR_DATALRNFL_MASK (1 << FSPI_INTR_DATALRNFL_SHIFT)
+#define FSPI_INTR_IPTXWE_SHIFT 6
+#define FSPI_INTR_IPTXWE_MASK (1 << FSPI_INTR_IPTXWE_SHIFT)
+#define FSPI_INTR_IPRXWA_SHIFT 5
+#define FSPI_INTR_IPRXWA_MASK (1 << FSPI_INTR_IPRXWA_SHIFT)
+#define FSPI_INTR_AHBCMDERR_SHIFT 4
+#define FSPI_INTR_AHBCMDERR_MASK (1 << FSPI_INTR_AHBCMDERR_SHIFT)
+#define FSPI_INTR_IPCMDERR_SHIFT 3
+#define FSPI_INTR_IPCMDERR_MASK (1 << FSPI_INTR_IPCMDERR_SHIFT)
+#define FSPI_INTR_AHBCMDGE_SHIFT 2
+#define FSPI_INTR_AHBCMDGE_MASK (1 << FSPI_INTR_AHBCMDGE_SHIFT)
+#define FSPI_INTR_IPCMDGE_SHIFT 1
+#define FSPI_INTR_IPCMDGE_MASK (1 << FSPI_INTR_IPCMDGE_SHIFT)
+#define FSPI_INTR_IPCMDDONE_SHIFT 0
+#define FSPI_INTR_IPCMDDONE_MASK (1 << FSPI_INTR_IPCMDDONE_SHIFT)
+
+#define FSPI_LUTKEY 0x18
+#define FSPI_LUTKEY_VALUE 0x5AF05AF0
+
+#define FSPI_LCKCR 0x1C
+#define FSPI_LCKER_LOCK 0x1
+#define FSPI_LCKER_UNLOCK 0x2
+
+#define FSPI_BUFXCR_INVALID_MSTRID 0xe
+#define FSPI_AHBRX_BUF0CR0 0x20
+#define FSPI_AHBRX_BUF1CR0 0x24
+#define FSPI_AHBRX_BUF2CR0 0x28
+#define FSPI_AHBRX_BUF3CR0 0x2C
+#define FSPI_AHBRX_BUF4CR0 0x30
+#define FSPI_AHBRX_BUF5CR0 0x34
+#define FSPI_AHBRX_BUF6CR0 0x38
+#define FSPI_AHBRX_BUF7CR0 0x3C
+#define FSPI_AHBRXBUF0CR7_PREF_SHIFT 31
+#define FSPI_AHBRXBUF0CR7_PREF_MASK (1 << FSPI_AHBRXBUF0CR7_PREF_SHIFT)
+
+#define FSPI_AHBRX_BUF0CR1 0x40
+#define FSPI_AHBRX_BUF1CR1 0x44
+#define FSPI_AHBRX_BUF2CR1 0x48
+#define FSPI_AHBRX_BUF3CR1 0x4C
+#define FSPI_AHBRX_BUF4CR1 0x50
+#define FSPI_AHBRX_BUF5CR1 0x54
+#define FSPI_AHBRX_BUF6CR1 0x58
+#define FSPI_AHBRX_BUF7CR1 0x5C
+#define FSPI_BUFXCR1_MSID_SHIFT 0
+#define FSPI_BUFXCR1_MSID_MASK (0xF << FSPI_BUFXCR1_MSID_SHIFT)
+#define FSPI_BUFXCR1_PRIO_SHIFT 8
+#define FSPI_BUFXCR1_PRIO_MASK (0x7 << FSPI_BUFXCR1_PRIO_SHIFT)
+
+#define FSPI_FLSHA1CR0 0x60
+#define FSPI_FLSHA2CR0 0x64
+#define FSPI_FLSHB1CR0 0x68
+#define FSPI_FLSHB2CR0 0x6C
+#define FSPI_FLSHXCR0_SZ_SHIFT 10
+#define FSPI_FLSHXCR0_SZ_MASK (0x3FFFFF << FSPI_FLSHXCR0_SZ_SHIFT)
+
+#define FSPI_FLSHA1CR1 0x70
+#define FSPI_FLSHA2CR1 0x74
+#define FSPI_FLSHB1CR1 0x78
+#define FSPI_FLSHB2CR1 0x7C
+#define FSPI_FLSHXCR1_CSINTR_SHIFT 16
+#define FSPI_FLSHXCR1_CSINTR_MASK \
+ (0xFFFF << FSPI_FLSHXCR1_CSINTR_SHIFT)
+#define FSPI_FLSHXCR1_CAS_SHIFT 11
+#define FSPI_FLSHXCR1_CAS_MASK (0xF << FSPI_FLSHXCR1_CAS_SHIFT)
+#define FSPI_FLSHXCR1_WA_SHIFT 10
+#define FSPI_FLSHXCR1_WA_MASK (1 << FSPI_FLSHXCR1_WA_SHIFT)
+#define FSPI_FLSHXCR1_TCSH_SHIFT 5
+#define FSPI_FLSHXCR1_TCSH_MASK (0x1F << FSPI_FLSHXCR1_TCSH_SHIFT)
+#define FSPI_FLSHXCR1_TCSS_SHIFT 0
+#define FSPI_FLSHXCR1_TCSS_MASK (0x1F << FSPI_FLSHXCR1_TCSS_SHIFT)
+
+#define FSPI_FLSHA1CR2 0x80
+#define FSPI_FLSHA2CR2 0x84
+#define FSPI_FLSHB1CR2 0x88
+#define FSPI_FLSHB2CR2 0x8C
+#define FSPI_FLSHXCR2_CLRINSP_SHIFT 24
+#define FSPI_FLSHXCR2_CLRINSP_MASK (1 << FSPI_FLSHXCR2_CLRINSP_SHIFT)
+#define FSPI_FLSHXCR2_AWRWAIT_SHIFT 16
+#define FSPI_FLSHXCR2_AWRWAIT_MASK (0xFF << FSPI_FLSHXCR2_AWRWAIT_SHIFT)
+#define FSPI_FLSHXCR2_AWRSEQN_SHIFT 13
+#define FSPI_FLSHXCR2_AWRSEQN_MASK (0x7 << FSPI_FLSHXCR2_AWRSEQN_SHIFT)
+#define FSPI_FLSHXCR2_AWRSEQI_SHIFT 8
+#define FSPI_FLSHXCR2_AWRSEQI_MASK (0xF << FSPI_FLSHXCR2_AWRSEQI_SHIFT)
+#define FSPI_FLSHXCR2_ARDSEQN_SHIFT 5
+#define FSPI_FLSHXCR2_ARDSEQN_MASK (0x7 << FSPI_FLSHXCR2_ARDSEQN_SHIFT)
+#define FSPI_FLSHXCR2_ARDSEQI_SHIFT 0
+#define FSPI_FLSHXCR2_ARDSEQI_MASK (0xF << FSPI_FLSHXCR2_ARDSEQI_SHIFT)
+
+#define FSPI_IPCR0 0xA0
+
+#define FSPI_IPCR1 0xA4
+#define FSPI_IPCR1_IPAREN_SHIFT 31
+#define FSPI_IPCR1_IPAREN_MASK (1 << FSPI_IPCR1_IPAREN_SHIFT)
+#define FSPI_IPCR1_SEQNUM_SHIFT 24
+#define FSPI_IPCR1_SEQNUM_MASK (0xF << FSPI_IPCR1_SEQNUM_SHIFT)
+#define FSPI_IPCR1_SEQID_SHIFT 16
+#define FSPI_IPCR1_SEQID_MASK (0xF << FSPI_IPCR1_SEQID_SHIFT)
+#define FSPI_IPCR1_IDATSZ_SHIFT 0
+#define FSPI_IPCR1_IDATSZ_MASK (0xFFFF << FSPI_IPCR1_IDATSZ_SHIFT)
+
+#define FSPI_IPCMD 0xB0
+#define FSPI_IPCMD_TRG_SHIFT 0
+#define FSPI_IPCMD_TRG_MASK (1 << FSPI_IPCMD_TRG_SHIFT)
+
+#define FSPI_DLPR 0xB4
+
+#define FSPI_IPRXFCR 0xB8
+#define FSPI_IPRXFCR_CLR_SHIFT 0
+#define FSPI_IPRXFCR_CLR_MASK (1 << FSPI_IPRXFCR_CLR_SHIFT)
+#define FSPI_IPRXFCR_DMA_EN_SHIFT 1
+#define FSPI_IPRXFCR_DMA_EN_MASK (1 << FSPI_IPRXFCR_DMA_EN_SHIFT)
+#define FSPI_IPRXFCR_WMRK_SHIFT 2
+#define FSPI_IPRXFCR_WMRK_MASK (0x1F << FSPI_IPRXFCR_WMRK_SHIFT)
+
+#define FSPI_IPTXFCR 0xBC
+#define FSPI_IPTXFCR_CLR_SHIFT 0
+#define FSPI_IPTXFCR_CLR_MASK (1 << FSPI_IPTXFCR_CLR_SHIFT)
+#define FSPI_IPTXFCR_DMA_EN_SHIFT 1
+#define FSPI_IPTXFCR_DMA_EN_MASK (1 << FSPI_IPTXFCR_DMA_EN_SHIFT)
+#define FSPI_IPTXFCR_WMRK_SHIFT 2
+#define FSPI_IPTXFCR_WMRK_MASK (0x1F << FSPI_IPTXFCR_WMRK_SHIFT)
+
+#define FSPI_DLLACR 0xC0
+#define FSPI_DLLACR_OVRDEN_SHIFT 8
+#define FSPI_DLLACR_OVRDEN_MASK (1 << FSPI_DLLACR_OVRDEN_SHIFT)
+
+#define FSPI_DLLBCR 0xC4
+#define FSPI_DLLBCR_OVRDEN_SHIFT 8
+#define FSPI_DLLBCR_OVRDEN_MASK (1 << FSPI_DLLBCR_OVRDEN_SHIFT)
+
+#define FSPI_STS0 0xE0
+#define FSPI_STS0_DLPHA_SHIFT 9
+#define FSPI_STS0_DLPHA_MASK (0x1F << FSPI_STS0_DLPHA_SHIFT)
+#define FSPI_STS0_DLPHB_SHIFT 4
+#define FSPI_STS0_DLPHB_MASK (0x1F << FSPI_STS0_DLPHB_SHIFT)
+#define FSPI_STS0_CMD_SRC_SHIFT 2
+#define FSPI_STS0_CMD_SRC_MASK (3 << FSPI_STS0_CMD_SRC_SHIFT)
+#define FSPI_STS0_ARB_IDLE_SHIFT 1
+#define FSPI_STS0_ARB_IDLE_MASK (1 << FSPI_STS0_ARB_IDLE_SHIFT)
+#define FSPI_STS0_SEQ_IDLE_SHIFT 0
+#define FSPI_STS0_SEQ_IDLE_MASK (1 << FSPI_STS0_SEQ_IDLE_SHIFT)
+
+#define FSPI_STS1 0xE4
+#define FSPI_STS1_IP_ERRCD_SHIFT 24
+#define FSPI_STS1_IP_ERRCD_MASK (0xF << FSPI_STS1_IP_ERRCD_SHIFT)
+#define FSPI_STS1_IP_ERRID_SHIFT 16
+#define FSPI_STS1_IP_ERRID_MASK (0xF << FSPI_STS1_IP_ERRID_SHIFT)
+#define FSPI_STS1_AHB_ERRCD_SHIFT 8
+#define FSPI_STS1_AHB_ERRCD_MASK (0xF << FSPI_STS1_AHB_ERRCD_SHIFT)
+#define FSPI_STS1_AHB_ERRID_SHIFT 0
+#define FSPI_STS1_AHB_ERRID_MASK (0xF << FSPI_STS1_AHB_ERRID_SHIFT)
+
+#define FSPI_AHBSPNST 0xEC
+#define FSPI_AHBSPNST_DATLFT_SHIFT 16
+#define FSPI_AHBSPNST_DATLFT_MASK \
+ (0xFFFF << FSPI_AHBSPNST_DATLFT_SHIFT)
+#define FSPI_AHBSPNST_BUFID_SHIFT 1
+#define FSPI_AHBSPNST_BUFID_MASK (7 << FSPI_AHBSPNST_BUFID_SHIFT)
+#define FSPI_AHBSPNST_ACTIVE_SHIFT 0
+#define FSPI_AHBSPNST_ACTIVE_MASK (1 << FSPI_AHBSPNST_ACTIVE_SHIFT)
+
+#define FSPI_IPRXFSTS 0xF0
+#define FSPI_IPRXFSTS_RDCNTR_SHIFT 16
+#define FSPI_IPRXFSTS_RDCNTR_MASK \
+ (0xFFFF << FSPI_IPRXFSTS_RDCNTR_SHIFT)
+#define FSPI_IPRXFSTS_FILL_SHIFT 0
+#define FSPI_IPRXFSTS_FILL_MASK (0xFF << FSPI_IPRXFSTS_FILL_SHIFT)
+
+#define FSPI_IPTXFSTS 0xF4
+#define FSPI_IPTXFSTS_WRCNTR_SHIFT 16
+#define FSPI_IPTXFSTS_WRCNTR_MASK \
+ (0xFFFF << FSPI_IPTXFSTS_WRCNTR_SHIFT)
+#define FSPI_IPTXFSTS_FILL_SHIFT 0
+#define FSPI_IPTXFSTS_FILL_MASK (0xFF << FSPI_IPTXFSTS_FILL_SHIFT)
+
+#define FSPI_RFDR 0x100
+#define FSPI_TFDR 0x180
+
+#define FSPI_LUT_BASE 0x200
+
+/* register map end */
+
+/*
+ * The definition of the LUT register shows below:
+ *
+ * ---------------------------------------------------
+ * | INSTR1 | PAD1 | OPRND1 | INSTR0 | PAD0 | OPRND0 |
+ * ---------------------------------------------------
+ */
+#define OPRND0_SHIFT 0
+#define PAD0_SHIFT 8
+#define INSTR0_SHIFT 10
+#define OPRND1_SHIFT 16
+
+/* Instruction set for the LUT register. */
+
+#define LUT_STOP 0x00
+#define LUT_CMD 0x01
+#define LUT_ADDR 0x02
+#define LUT_CADDR_SDR 0x03
+#define LUT_MODE 0x04
+#define LUT_MODE2 0x05
+#define LUT_MODE4 0x06
+#define LUT_MODE8 0x07
+#define LUT_NXP_WRITE 0x08
+#define LUT_NXP_READ 0x09
+#define LUT_LEARN_SDR 0x0A
+#define LUT_DATSZ_SDR 0x0B
+#define LUT_DUMMY 0x0C
+#define LUT_DUMMY_RWDS_SDR 0x0D
+#define LUT_JMP_ON_CS 0x1F
+#define LUT_CMD_DDR 0x21
+#define LUT_ADDR_DDR 0x22
+#define LUT_CADDR_DDR 0x23
+#define LUT_MODE_DDR 0x24
+#define LUT_MODE2_DDR 0x25
+#define LUT_MODE4_DDR 0x26
+#define LUT_MODE8_DDR 0x27
+#define LUT_WRITE_DDR 0x28
+#define LUT_READ_DDR 0x29
+#define LUT_LEARN_DDR 0x2A
+#define LUT_DATSZ_DDR 0x2B
+#define LUT_DUMMY_DDR 0x2C
+#define LUT_DUMMY_RWDS_DDR 0x2D
+
+
+/*
+ * The PAD definitions for LUT register.
+ *
+ * The pad stands for the lines number of IO[0:3].
+ * For example, the Quad read need four IO lines, so you should
+ * set LUT_PAD4 which means we use four IO lines.
+ */
+#define LUT_PAD1 0
+#define LUT_PAD2 1
+#define LUT_PAD4 2
+#define LUT_PAD8 3
+
+/* Oprands for the LUT register. */
+#define ADDR24BIT 0x18
+#define ADDR32BIT 0x20
+
+/* Macros for constructing the LUT register. */
+#define LUT0(ins, pad, opr) \
+ (((opr) << OPRND0_SHIFT) | ((LUT_##pad) << PAD0_SHIFT) | \
+ ((LUT_##ins) << INSTR0_SHIFT))
+
+#define LUT1(ins, pad, opr) (LUT0(ins, pad, opr) << OPRND1_SHIFT)
+
+/* other macros for LUT register. */
+#define FSPI_LUT(x) (FSPI_LUT_BASE + (x) * 4)
+#define FSPI_LUT_NUM 128
+
+/* SEQID -- we can have 32 seqids at most. */
+#define SEQID_READ 0
+#define SEQID_WREN 1
+#define SEQID_WRDI 2
+#define SEQID_RDSR 3
+#define SEQID_SE 4
+#define SEQID_CHIP_ERASE 5
+#define SEQID_PP 6
+#define SEQID_RDID 7
+#define SEQID_WRSR 8
+#define SEQID_RDCR 9
+#define SEQID_EN4B 10
+#define SEQID_BRWR 11
+#define SEQID_RD_EVCR 12
+#define SEQID_WD_EVCR 13
+#define SEQID_RDFSR 14
+
+#define FSPI_MIN_IOMAP SZ_4M
+
+#define FSPI_RX_MAX_IPBUF_SIZE 0x200 /* 64 * 64bits */
+#define FSPI_TX_MAX_IPBUF_SIZE 0x400 /* 128 * 64bits */
+#define FSPI_RX_MAX_AHBBUF_SIZE 0x800 /* 256 * 64bits */
+#define FSPI_TX_MAX_AHBBUF_SIZE 0x40 /* 8 * 64bits */
+
+#define TX_IPBUF_SIZE FSPI_TX_MAX_IPBUF_SIZE
+#define RX_IPBUF_SIZE FSPI_RX_MAX_IPBUF_SIZE
+#define RX_AHBBUF_SIZE FSPI_RX_MAX_AHBBUF_SIZE
+#define TX_AHBBUF_SIZE FSPI_TX_MAX_AHBBUF_SIZE
+
+#define FSPI_SINGLE_MODE 1
+#define FSPI_OCTAL_MODE 8
+
+#define FSPINOR_OP_READ_1_1_8_4B 0x7c
+
+enum nxp_fspi_devtype {
+ NXP_FSPI_LX2160A,
+};
+
+struct nxp_fspi_devtype_data {
+ enum nxp_fspi_devtype devtype;
+ int rxfifo;
+ int txfifo;
+ int ahb_buf_size;
+ int driver_data;
+};
+
+static struct nxp_fspi_devtype_data lx2160a_data = {
+ .devtype = NXP_FSPI_LX2160A,
+ .rxfifo = RX_IPBUF_SIZE,
+ .txfifo = TX_IPBUF_SIZE,
+ .ahb_buf_size = RX_AHBBUF_SIZE,
+ .driver_data = 0,
+};
+
+#define NXP_FSPI_MAX_CHIP 4
+struct nxp_fspi {
+ struct mtd_info mtd[NXP_FSPI_MAX_CHIP];
+ struct spi_nor nor[NXP_FSPI_MAX_CHIP];
+ void __iomem *iobase;
+ void __iomem *ahb_addr;
+ u32 memmap_phy;
+ u32 memmap_offs;
+ u32 memmap_len;
+ struct clk *clk, *clk_en;
+ struct device *dev;
+ struct completion c;
+ struct nxp_fspi_devtype_data *devtype_data;
+ u32 nor_size;
+ u32 nor_num;
+ u32 clk_rate;
+ u32 spi_rx_bus_width;
+ u32 spi_tx_bus_width;
+ unsigned int chip_base_addr; /* We may support two chips. */
+ bool has_second_chip;
+ struct mutex lock;
+ struct pm_qos_request pm_qos_req;
+};
+
+static inline void nxp_fspi_unlock_lut(struct nxp_fspi *fspi)
+{
+ writel(FSPI_LUTKEY_VALUE, fspi->iobase + FSPI_LUTKEY);
+ writel(FSPI_LCKER_UNLOCK, fspi->iobase + FSPI_LCKCR);
+}
+
+static inline void nxp_fspi_lock_lut(struct nxp_fspi *fspi)
+{
+ writel(FSPI_LUTKEY_VALUE, fspi->iobase + FSPI_LUTKEY);
+ writel(FSPI_LCKER_LOCK, fspi->iobase + FSPI_LCKCR);
+}
+
+static irqreturn_t nxp_fspi_irq_handler(int irq, void *dev_id)
+{
+ struct nxp_fspi *fspi = dev_id;
+ u32 reg;
+
+ reg = readl(fspi->iobase + FSPI_INTR);
+ writel(FSPI_INTR_IPCMDDONE_MASK, fspi->iobase + FSPI_INTR);
+ if (reg & FSPI_INTR_IPCMDDONE_MASK)
+ complete(&fspi->c);
+
+ return IRQ_HANDLED;
+}
+
+static void nxp_fspi_init_lut(struct nxp_fspi *fspi)
+{
+ void __iomem *base = fspi->iobase;
+ struct spi_nor *nor = &fspi->nor[0];
+ u8 addrlen = (nor->addr_width == 3) ? ADDR24BIT : ADDR32BIT;
+ u32 lut_base;
+ u8 op, dm;
+ int i;
+
+ nxp_fspi_unlock_lut(fspi);
+
+ /* Clear all the LUT table */
+ for (i = 0; i < FSPI_LUT_NUM; i++)
+ writel(0, base + FSPI_LUT_BASE + i * 4);
+
+ /* Read */
+ lut_base = SEQID_READ * 4;
+ op = nor->read_opcode;
+ dm = nor->read_dummy;
+
+ if (fspi->spi_rx_bus_width == FSPI_OCTAL_MODE) {
+ dm = 8;
+ op = FSPINOR_OP_READ_1_1_8_4B;
+ writel(LUT0(CMD, PAD1, op) | LUT1(ADDR, PAD1, addrlen),
+ base + FSPI_LUT(lut_base));
+ writel(LUT0(DUMMY, PAD8, dm) | LUT1(NXP_READ, PAD8, 0),
+ base + FSPI_LUT(lut_base + 1));
+ } else {
+ if ((op == SPINOR_OP_READ_FAST_4B) ||
+ (op == SPINOR_OP_READ_FAST) ||
+ (op == SPINOR_OP_READ) ||
+ (op == SPINOR_OP_READ_4B)) {
+ dm = 8;
+ writel(LUT0(CMD, PAD1, op) | LUT1(ADDR, PAD1, addrlen),
+ base + FSPI_LUT(lut_base));
+ writel(LUT0(DUMMY, PAD1, dm) | LUT1(NXP_READ, PAD1, 0),
+ base + FSPI_LUT(lut_base + 1));
+ } else if (nor->read_proto == SNOR_PROTO_1_4_4) {
+ dev_dbg(nor->dev, "Unsupported opcode : 0x%.2x\n", op);
+ /* TODO Add support for other Read ops. */
+ } else {
+ dev_dbg(nor->dev, "Unsupported opcode : 0x%.2x\n", op);
+ }
+ }
+
+ /* Write enable */
+ lut_base = SEQID_WREN * 4;
+ writel(LUT0(CMD, PAD1, SPINOR_OP_WREN), base + FSPI_LUT(lut_base));
+
+ /* Page Program */
+ lut_base = SEQID_PP * 4;
+ writel(LUT0(CMD, PAD1, nor->program_opcode) | LUT1(ADDR, PAD1, addrlen),
+ base + FSPI_LUT(lut_base));
+ writel(LUT0(NXP_WRITE, PAD1, 0), base + FSPI_LUT(lut_base + 1));
+
+ /* Read Status */
+ lut_base = SEQID_RDSR * 4;
+ writel(LUT0(CMD, PAD1, SPINOR_OP_RDSR) | LUT1(NXP_READ, PAD1, 0x1),
+ base + FSPI_LUT(lut_base));
+
+ /* Erase a sector */
+ lut_base = SEQID_SE * 4;
+ writel(LUT0(CMD, PAD1, nor->erase_opcode) | LUT1(ADDR, PAD1, addrlen),
+ base + FSPI_LUT(lut_base));
+
+ /* Erase the whole chip */
+ lut_base = SEQID_CHIP_ERASE * 4;
+ writel(LUT0(CMD, PAD1, SPINOR_OP_CHIP_ERASE),
+ base + FSPI_LUT(lut_base));
+
+ /* READ ID */
+ lut_base = SEQID_RDID * 4;
+ writel(LUT0(CMD, PAD1, SPINOR_OP_RDID) | LUT1(NXP_READ, PAD1, 0x8),
+ base + FSPI_LUT(lut_base));
+
+ /* Write Register */
+ lut_base = SEQID_WRSR * 4;
+ writel(LUT0(CMD, PAD1, SPINOR_OP_WRSR) | LUT1(NXP_WRITE, PAD1, 0x2),
+ base + FSPI_LUT(lut_base));
+
+ /* Read Configuration Register */
+ lut_base = SEQID_RDCR * 4;
+ writel(LUT0(CMD, PAD1, SPINOR_OP_RDCR) | LUT1(NXP_READ, PAD1, 0x1),
+ base + FSPI_LUT(lut_base));
+
+ /* Write disable */
+ lut_base = SEQID_WRDI * 4;
+ writel(LUT0(CMD, PAD1, SPINOR_OP_WRDI), base + FSPI_LUT(lut_base));
+
+ /* Enter 4 Byte Mode (Micron) */
+ lut_base = SEQID_EN4B * 4;
+ writel(LUT0(CMD, PAD1, SPINOR_OP_EN4B), base + FSPI_LUT(lut_base));
+
+ /* Enter 4 Byte Mode (Spansion) */
+ lut_base = SEQID_BRWR * 4;
+ writel(LUT0(CMD, PAD1, SPINOR_OP_BRWR), base + FSPI_LUT(lut_base));
+
+ /* Read EVCR register */
+ lut_base = SEQID_RD_EVCR * 4;
+ writel(LUT0(CMD, PAD1, SPINOR_OP_RD_EVCR),
+ base + FSPI_LUT(lut_base));
+
+ /* Write EVCR register */
+ lut_base = SEQID_WD_EVCR * 4;
+ writel(LUT0(CMD, PAD1, SPINOR_OP_WD_EVCR),
+ base + FSPI_LUT(lut_base));
+
+ /* Read Flag Status */
+ lut_base = SEQID_RDFSR * 4;
+ writel(LUT0(CMD, PAD1, SPINOR_OP_RDFSR) | LUT1(NXP_READ, PAD1, 0x1),
+ base + FSPI_LUT(lut_base));
+
+ nxp_fspi_lock_lut(fspi);
+}
+
+/* Get the SEQID for the command */
+static int nxp_fspi_get_seqid(struct nxp_fspi *fspi, u8 cmd)
+{
+
+ switch (cmd) {
+ case SPINOR_OP_READ_1_1_4_4B:
+ case SPINOR_OP_READ_1_1_4:
+ case SPINOR_OP_READ:
+ case SPINOR_OP_READ_4B:
+ case SPINOR_OP_READ_FAST:
+ case SPINOR_OP_READ_FAST_4B:
+ return SEQID_READ;
+ case SPINOR_OP_WREN:
+ return SEQID_WREN;
+ case SPINOR_OP_WRDI:
+ return SEQID_WRDI;
+ case SPINOR_OP_RDSR:
+ return SEQID_RDSR;
+ case SPINOR_OP_RDFSR:
+ return SEQID_RDFSR;
+ case SPINOR_OP_BE_4K:
+ case SPINOR_OP_SE:
+ case SPINOR_OP_SE_4B:
+ case SPINOR_OP_BE_4K_4B:
+ return SEQID_SE;
+ case SPINOR_OP_CHIP_ERASE:
+ return SEQID_CHIP_ERASE;
+ case SPINOR_OP_PP:
+ case SPINOR_OP_PP_4B:
+ return SEQID_PP;
+ case SPINOR_OP_RDID:
+ return SEQID_RDID;
+ case SPINOR_OP_WRSR:
+ return SEQID_WRSR;
+ case SPINOR_OP_RDCR:
+ return SEQID_RDCR;
+ case SPINOR_OP_EN4B:
+ return SEQID_EN4B;
+ case SPINOR_OP_BRWR:
+ return SEQID_BRWR;
+ case SPINOR_OP_RD_EVCR:
+ return SEQID_RD_EVCR;
+ case SPINOR_OP_WD_EVCR:
+ return SEQID_WD_EVCR;
+ default:
+ dev_err(fspi->dev, "Unsupported cmd 0x%.2x\n", cmd);
+ break;
+ }
+ return -EINVAL;
+}
+
+static int
+nxp_fspi_runcmd(struct nxp_fspi *fspi, u8 cmd, unsigned int addr, int len)
+{
+ void __iomem *base = fspi->iobase;
+ int seqid;
+ int seqnum = 0;
+ u32 reg;
+ int err;
+ int iprxfcr = 0;
+
+ iprxfcr = readl(fspi->iobase + FSPI_IPRXFCR);
+ /* invalid RXFIFO first */
+ iprxfcr &= ~FSPI_IPRXFCR_DMA_EN_MASK;
+ iprxfcr = iprxfcr | FSPI_IPRXFCR_CLR_MASK;
+ writel(iprxfcr, fspi->iobase + FSPI_IPRXFCR);
+
+ init_completion(&fspi->c);
+ dev_dbg(fspi->dev, "to 0x%.8x:0x%.8x, len:%d, cmd:%.2x\n",
+ fspi->chip_base_addr, addr, len, cmd);
+
+ /* write address */
+ writel(fspi->chip_base_addr + addr, base + FSPI_IPCR0);
+
+ seqid = nxp_fspi_get_seqid(fspi, cmd);
+
+ writel((seqnum << FSPI_IPCR1_SEQNUM_SHIFT) |
+ (seqid << FSPI_IPCR1_SEQID_SHIFT) | len,
+ base + FSPI_IPCR1);
+
+ /* wait till controller is idle */
+ do {
+ reg = readl(base + FSPI_STS0);
+ if ((reg & FSPI_STS0_ARB_IDLE_MASK) &&
+ (reg & FSPI_STS0_SEQ_IDLE_MASK))
+ break;
+ udelay(1);
+ dev_dbg(fspi->dev, "The controller is busy, 0x%x\n", reg);
+ } while (1);
+
+ /* trigger the LUT now */
+ writel(1, base + FSPI_IPCMD);
+
+ /* Wait for the interrupt. */
+ if (!wait_for_completion_timeout(&fspi->c, msecs_to_jiffies(1000))) {
+ dev_err(fspi->dev,
+ "cmd 0x%.2x timeout, addr@%.8x, Status0:0x%.8x, Status1:0x%.8x\n",
+ cmd, addr, readl(base + FSPI_STS0),
+ readl(base + FSPI_STS1));
+ err = -ETIMEDOUT;
+ } else {
+ err = 0;
+ dev_dbg(fspi->dev, "FSPI Intr done,INTR:<0x%.8x>\n",
+ readl(base + FSPI_INTR));
+ }
+
+ return err;
+}
+
+/* Read out the data from the FSPI_RBDR buffer registers. */
+static void nxp_fspi_read_data(struct nxp_fspi *fspi, int len, u8 *rxbuf)
+{
+ int i = 0, j = 0, tmp_size = 0;
+ int size;
+ u32 tmp = 0;
+
+ while (len > 0) {
+
+ size = len / 8;
+
+ for (i = 0; i < size; ++i) {
+ /* Wait for RXFIFO available*/
+ while (!(readl(fspi->iobase + FSPI_INTR)
+ & FSPI_INTR_IPRXWA_MASK))
+ ;
+
+ j = 0;
+ tmp_size = 8;
+ while (tmp_size > 0) {
+ tmp = 0;
+ tmp = readl(fspi->iobase + FSPI_RFDR + j * 4);
+ memcpy(rxbuf, &tmp, 4);
+ tmp_size -= 4;
+ j++;
+ rxbuf += 4;
+ }
+
+ /* move the FIFO pointer */
+ writel(FSPI_INTR_IPRXWA_MASK,
+ fspi->iobase + FSPI_INTR);
+ len -= 8;
+ }
+
+ size = len % 8;
+
+ j = 0;
+ if (size) {
+ /* Wait for RXFIFO available*/
+ while (!(readl(fspi->iobase + FSPI_INTR)
+ & FSPI_INTR_IPRXWA_MASK))
+ ;
+
+ while (len > 0) {
+ tmp = 0;
+ size = (len < 4) ? len : 4;
+ tmp = readl(fspi->iobase + FSPI_RFDR + j * 4);
+ memcpy(rxbuf, &tmp, size);
+ len -= size;
+ j++;
+ rxbuf += size;
+ }
+ }
+
+ /* invalid the RXFIFO */
+ writel(FSPI_IPRXFCR_CLR_MASK,
+ fspi->iobase + FSPI_IPRXFCR);
+
+ writel(FSPI_INTR_IPRXWA_MASK,
+ fspi->iobase + FSPI_INTR);
+ }
+}
+
+static inline void nxp_fspi_invalid(struct nxp_fspi *fspi)
+{
+ u32 reg;
+
+ reg = readl(fspi->iobase + FSPI_MCR0);
+ writel(reg | FSPI_MCR0_SWRST_MASK, fspi->iobase + FSPI_MCR0);
+
+ /*
+ * The minimum delay : 1 AHB + 2 SFCK clocks.
+ * Delay 1 us is enough.
+ */
+ while (readl(fspi->iobase + FSPI_MCR0) & FSPI_MCR0_SWRST_MASK)
+ ;
+}
+
+static ssize_t nxp_fspi_nor_write(struct nxp_fspi *fspi,
+ struct spi_nor *nor, u8 opcode,
+ unsigned int to, u32 *txbuf,
+ unsigned int count)
+{
+ int ret, i, j;
+ int size, tmp_size;
+ u32 data = 0;
+
+ dev_dbg(fspi->dev, "nor write to 0x%.8x:0x%.8x, len : %d\n",
+ fspi->chip_base_addr, to, count);
+
+ /* clear the TX FIFO. */
+ writel(FSPI_IPTXFCR_CLR_MASK, fspi->iobase + FSPI_IPTXFCR);
+
+ size = count / 8;
+ for (i = 0; i < size; i++) {
+ /* Wait for TXFIFO empty*/
+ while (!(readl(fspi->iobase + FSPI_INTR)
+ & FSPI_INTR_IPTXWE_MASK))
+ ;
+ j = 0;
+ tmp_size = 8;
+ while (tmp_size > 0) {
+ data = 0;
+ memcpy(&data, txbuf, 4);
+ writel(data, fspi->iobase + FSPI_TFDR + j * 4);
+ tmp_size -= 4;
+ j++;
+ txbuf += 1;
+ }
+
+ writel(FSPI_INTR_IPTXWE_MASK, fspi->iobase + FSPI_INTR);
+ }
+
+ size = count % 8;
+ if (size) {
+ /* Wait for TXFIFO empty*/
+ while (!(readl(fspi->iobase + FSPI_INTR)
+ & FSPI_INTR_IPTXWE_MASK))
+ ;
+
+ j = 0;
+ tmp_size = 0;
+ while (size > 0) {
+ data = 0;
+ tmp_size = (size < 4) ? size : 4;
+ memcpy(&data, txbuf, tmp_size);
+ writel(data, fspi->iobase + FSPI_TFDR + j * 4);
+ size -= tmp_size;
+ j++;
+ txbuf += 1;
+ }
+
+ writel(FSPI_INTR_IPTXWE_MASK, fspi->iobase + FSPI_INTR);
+ }
+
+ /* Trigger it */
+ ret = nxp_fspi_runcmd(fspi, opcode, to, count);
+
+ if (ret == 0)
+ return count;
+
+ return ret;
+}
+
+static void nxp_fspi_set_map_addr(struct nxp_fspi *fspi)
+{
+ int nor_size = fspi->nor_size >> 10;
+ void __iomem *base = fspi->iobase;
+
+ /*
+ * Supporting same flash device as slaves on different chip-select.
+ * As SAMEDEVICEEN bit set, by default, in mcr2 reg then need not to
+ * configure FLSHA2CRx/FLSHB1CRx/FLSHB2CRx register as setting for
+ * these would be ignored.
+ * Need to Reset SAMEDEVICEEN bit in mcr2 reg, when require to add
+ * support for different flashes.
+ */
+ writel(nor_size, base + FSPI_FLSHA1CR0);
+ writel(0, base + FSPI_FLSHA2CR0);
+ writel(0, base + FSPI_FLSHB1CR0);
+ writel(0, base + FSPI_FLSHB2CR0);
+}
+
+static void nxp_fspi_init_ahb_read(struct nxp_fspi *fspi)
+{
+ void __iomem *base = fspi->iobase;
+ struct spi_nor *nor = &fspi->nor[0];
+ int i = 0;
+ int seqid;
+
+ /* AHB configuration for access buffer 0~7. */
+ for (i = 0; i < 7; i++)
+ writel(0, base + FSPI_AHBRX_BUF0CR0 + 4 * i);
+
+ /*
+ * Set ADATSZ with the maximum AHB buffer size to improve the read
+ * performance.
+ */
+ writel((fspi->devtype_data->ahb_buf_size / 8 |
+ FSPI_AHBRXBUF0CR7_PREF_MASK), base + FSPI_AHBRX_BUF7CR0);
+
+ /* prefetch and no start address alignment limitation */
+ writel(FSPI_AHBCR_PREF_EN_MASK | FSPI_AHBCR_RDADDROPT_MASK,
+ base + FSPI_AHBCR);
+
+
+ /* Set the default lut sequence for AHB Read. */
+ seqid = nxp_fspi_get_seqid(fspi, nor->read_opcode);
+ writel(seqid, base + FSPI_FLSHA1CR2);
+}
+
+/* This function was used to prepare and enable FSPI clock */
+static int nxp_fspi_clk_prep_enable(struct nxp_fspi *fspi)
+{
+ int ret;
+
+ ret = clk_prepare_enable(fspi->clk_en);
+ if (ret)
+ return ret;
+
+ ret = clk_prepare_enable(fspi->clk);
+ if (ret) {
+ clk_disable_unprepare(fspi->clk_en);
+ return ret;
+ }
+
+ return 0;
+}
+
+/* This function was used to disable and unprepare FSPI clock */
+static void nxp_fspi_clk_disable_unprep(struct nxp_fspi *fspi)
+{
+ clk_disable_unprepare(fspi->clk);
+ clk_disable_unprepare(fspi->clk_en);
+}
+
+/* We use this function to do some basic init for spi_nor_scan(). */
+static int nxp_fspi_nor_setup(struct nxp_fspi *fspi)
+{
+ void __iomem *base = fspi->iobase;
+ u32 reg;
+
+ /* Reset the module */
+ writel(FSPI_MCR0_SWRST_MASK, base + FSPI_MCR0);
+ do {
+ udelay(1);
+ } while (0x1 & readl(base + FSPI_MCR0));
+
+ /* Disable the module */
+ writel(FSPI_MCR0_MDIS_MASK, base + FSPI_MCR0);
+
+ /* Reset the DLL register to default value */
+ writel(FSPI_DLLACR_OVRDEN_MASK, base + FSPI_DLLACR);
+ writel(FSPI_DLLBCR_OVRDEN_MASK, base + FSPI_DLLBCR);
+
+ /* enable module */
+ writel(FSPI_MCR0_AHB_TIMEOUT_MASK | FSPI_MCR0_IP_TIMEOUT_MASK,
+ base + FSPI_MCR0);
+
+ /* Read the register value */
+ reg = readl(base + FSPI_MCR0);
+
+ /* Init the LUT table. */
+ nxp_fspi_init_lut(fspi);
+
+ /* enable the interrupt */
+ writel(FSPI_INTEN_IPCMDDONE_MASK, fspi->iobase + FSPI_INTEN);
+ return 0;
+}
+
+static int nxp_fspi_nor_setup_last(struct nxp_fspi *fspi)
+{
+ unsigned long rate = fspi->clk_rate;
+ int ret;
+
+ /* disable and unprepare clock to avoid glitch pass to controller */
+ nxp_fspi_clk_disable_unprep(fspi);
+
+ ret = clk_set_rate(fspi->clk, rate);
+ if (ret)
+ return ret;
+
+ ret = nxp_fspi_clk_prep_enable(fspi);
+ if (ret)
+ return ret;
+
+ /* Init the LUT table again. */
+ nxp_fspi_init_lut(fspi);
+
+ /* Init for AHB read */
+ nxp_fspi_init_ahb_read(fspi);
+
+ return 0;
+}
+
+static void nxp_fspi_set_base_addr(struct nxp_fspi *fspi,
+ struct spi_nor *nor)
+{
+ fspi->chip_base_addr = fspi->nor_size * (nor - fspi->nor);
+}
+
+static int nxp_fspi_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf,
+ int len)
+{
+ int ret;
+ struct nxp_fspi *fspi = nor->priv;
+
+ ret = nxp_fspi_runcmd(fspi, opcode, 0, len);
+ if (ret)
+ return ret;
+
+ nxp_fspi_read_data(fspi, len, buf);
+ return 0;
+}
+
+static int nxp_fspi_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf,
+ int len)
+{
+ struct nxp_fspi *fspi = nor->priv;
+ int ret;
+
+ if (!buf) {
+ ret = nxp_fspi_runcmd(fspi, opcode, 0, 1);
+ if (ret)
+ return ret;
+
+ if (opcode == SPINOR_OP_CHIP_ERASE)
+ nxp_fspi_invalid(fspi);
+
+ } else if (len > 0) {
+ ret = nxp_fspi_nor_write(fspi, nor, opcode, 0,
+ (u32 *)buf, len);
+ } else {
+ dev_err(fspi->dev, "invalid cmd %d\n", opcode);
+ ret = -EINVAL;
+ }
+
+ return ret;
+}
+
+static ssize_t nxp_fspi_write(struct spi_nor *nor, loff_t to,
+ size_t len, const u_char *buf)
+{
+ struct nxp_fspi *fspi = nor->priv;
+ ssize_t tx_size = 0, act_wrt = 0, ret = 0;
+
+ while (len > 0) {
+ tx_size = (len > TX_IPBUF_SIZE) ? TX_IPBUF_SIZE : len;
+
+ act_wrt = nxp_fspi_nor_write(fspi, nor, nor->program_opcode, to,
+ (u32 *)buf, tx_size);
+ len -= tx_size;
+ to += tx_size;
+ ret += act_wrt;
+ }
+
+ /* invalid the data in the AHB buffer. */
+ nxp_fspi_invalid(fspi);
+ return ret;
+}
+
+static ssize_t nxp_fspi_read(struct spi_nor *nor, loff_t from,
+ size_t len, u_char *buf)
+{
+ struct nxp_fspi *fspi = nor->priv;
+
+ /* if necessary, ioremap buffer before AHB read, */
+ if (!fspi->ahb_addr) {
+ fspi->memmap_offs = fspi->chip_base_addr + from;
+ fspi->memmap_len = len > FSPI_MIN_IOMAP ?
+ len : FSPI_MIN_IOMAP;
+
+ fspi->ahb_addr = ioremap_nocache(
+ fspi->memmap_phy + fspi->memmap_offs,
+ fspi->memmap_len);
+ if (!fspi->ahb_addr) {
+ dev_err(fspi->dev, "ioremap failed\n");
+ return -ENOMEM;
+ }
+ /* ioremap if the data requested is out of range */
+ } else if (fspi->chip_base_addr + from < fspi->memmap_offs
+ || fspi->chip_base_addr + from + len >
+ fspi->memmap_offs + fspi->memmap_len) {
+ iounmap(fspi->ahb_addr);
+
+ fspi->memmap_offs = fspi->chip_base_addr + from;
+ fspi->memmap_len = len > FSPI_MIN_IOMAP ?
+ len : FSPI_MIN_IOMAP;
+ fspi->ahb_addr = ioremap_nocache(
+ fspi->memmap_phy + fspi->memmap_offs,
+ fspi->memmap_len);
+ if (!fspi->ahb_addr) {
+ dev_err(fspi->dev, "ioremap failed\n");
+ return -ENOMEM;
+ }
+ }
+
+ dev_dbg(fspi->dev, "cmd [%x],read from %p, len:%zd\n",
+ nor->read_opcode, fspi->ahb_addr + fspi->chip_base_addr
+ + from - fspi->memmap_offs, len);
+
+ /* Read out the data directly from the AHB buffer.*/
+ memcpy_toio(buf, fspi->ahb_addr + fspi->chip_base_addr
+ + from - fspi->memmap_offs, len);
+
+ return len;
+}
+
+static int nxp_fspi_erase(struct spi_nor *nor, loff_t offs)
+{
+ struct nxp_fspi *fspi = nor->priv;
+ int ret;
+
+ dev_dbg(nor->dev, "%dKiB at 0x%08x:0x%08x\n",
+ nor->mtd.erasesize / 1024, fspi->chip_base_addr, (u32)offs);
+
+ ret = nxp_fspi_runcmd(fspi, nor->erase_opcode, offs, 0);
+ if (ret)
+ return ret;
+
+ nxp_fspi_invalid(fspi);
+ return 0;
+}
+
+static int nxp_fspi_prep(struct spi_nor *nor, enum spi_nor_ops ops)
+{
+ struct nxp_fspi *fspi = nor->priv;
+ int ret;
+
+ mutex_lock(&fspi->lock);
+
+ ret = nxp_fspi_clk_prep_enable(fspi);
+ if (ret)
+ goto err_mutex;
+
+ nxp_fspi_set_base_addr(fspi, nor);
+ return 0;
+
+err_mutex:
+ mutex_unlock(&fspi->lock);
+ return ret;
+}
+
+static void nxp_fspi_unprep(struct spi_nor *nor, enum spi_nor_ops ops)
+{
+ struct nxp_fspi *fspi = nor->priv;
+
+ nxp_fspi_clk_disable_unprep(fspi);
+ mutex_unlock(&fspi->lock);
+}
+
+static const struct of_device_id nxp_fspi_dt_ids[] = {
+ { .compatible = "nxp,lx2160a-fspi", .data = (void *)&lx2160a_data, },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, nxp_fspi_dt_ids);
+
+static int nxp_fspi_probe(struct platform_device *pdev)
+{
+ struct spi_nor_hwcaps hwcaps = {
+ .mask = SPINOR_OP_READ_FAST_4B |
+ SPINOR_OP_READ_4B |
+ SNOR_HWCAPS_PP
+ };
+ struct device_node *np = pdev->dev.of_node;
+ struct device *dev = &pdev->dev;
+ struct nxp_fspi *fspi;
+ struct resource *res;
+ struct spi_nor *nor;
+ struct mtd_info *mtd;
+ int ret, i = 0;
+ int find_node = 0;
+
+ const struct of_device_id *of_id =
+ of_match_device(nxp_fspi_dt_ids, &pdev->dev);
+
+ fspi = devm_kzalloc(dev, sizeof(*fspi), GFP_KERNEL);
+ if (!fspi)
+ return -ENOMEM;
+
+ fspi->nor_num = of_get_child_count(dev->of_node);
+ if (!fspi->nor_num || fspi->nor_num > 4)
+ return -ENODEV;
+
+ fspi->dev = dev;
+ fspi->devtype_data = (struct nxp_fspi_devtype_data *)of_id->data;
+ platform_set_drvdata(pdev, fspi);
+
+ /* find the resources */
+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "FSPI");
+ if (!res) {
+ dev_err(dev, "FSPI get resource IORESOURCE_MEM failed\n");
+ return -ENODEV;
+ }
+
+ fspi->iobase = devm_ioremap_resource(dev, res);
+ if (IS_ERR(fspi->iobase))
+ return PTR_ERR(fspi->iobase);
+
+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+ "FSPI-memory");
+ if (!res) {
+ dev_err(dev,
+ "FSPI-memory get resource IORESOURCE_MEM failed\n");
+ return -ENODEV;
+ }
+
+ if (!devm_request_mem_region(dev, res->start, resource_size(res),
+ res->name)) {
+ dev_err(dev, "can't request region for resource %pR\n", res);
+ return -EBUSY;
+ }
+
+ fspi->memmap_phy = res->start;
+
+ /* find the clocks */
+ fspi->clk_en = devm_clk_get(dev, "fspi_en");
+ if (IS_ERR(fspi->clk_en))
+ return PTR_ERR(fspi->clk_en);
+
+ fspi->clk = devm_clk_get(dev, "fspi");
+ if (IS_ERR(fspi->clk))
+ return PTR_ERR(fspi->clk);
+
+ ret = nxp_fspi_clk_prep_enable(fspi);
+ if (ret) {
+ dev_err(dev, "can not enable the clock\n");
+ goto clk_failed;
+ }
+
+ /* find the irq */
+ ret = platform_get_irq(pdev, 0);
+ if (ret < 0) {
+ dev_err(dev, "failed to get the irq: %d\n", ret);
+ goto irq_failed;
+ }
+
+ ret = devm_request_irq(dev, ret,
+ nxp_fspi_irq_handler, 0, pdev->name, fspi);
+ if (ret) {
+ dev_err(dev, "failed to request irq: %d\n", ret);
+ goto irq_failed;
+ }
+
+ ret = nxp_fspi_nor_setup(fspi);
+ if (ret)
+ goto irq_failed;
+
+ if (of_get_property(np, "nxp,fspi-has-second-chip", NULL))
+ fspi->has_second_chip = true;
+
+ mutex_init(&fspi->lock);
+
+ find_node = 0;
+ /* iterate the subnodes. */
+ for_each_available_child_of_node(dev->of_node, np) {
+ /* skip the holes */
+ if (!fspi->has_second_chip)
+ i *= 2;
+
+ nor = &fspi->nor[i];
+ mtd = &nor->mtd;
+
+ nor->dev = dev;
+ spi_nor_set_flash_node(nor, np);
+ nor->priv = fspi;
+
+ /* fill the hooks */
+ nor->read_reg = nxp_fspi_read_reg;
+ nor->write_reg = nxp_fspi_write_reg;
+ nor->read = nxp_fspi_read;
+ nor->write = nxp_fspi_write;
+ nor->erase = nxp_fspi_erase;
+
+ nor->prepare = nxp_fspi_prep;
+ nor->unprepare = nxp_fspi_unprep;
+
+ ret = of_property_read_u32(np, "spi-max-frequency",
+ &fspi->clk_rate);
+ if (ret < 0)
+ goto next_node;
+
+ /* set the chip address for READID */
+ nxp_fspi_set_base_addr(fspi, nor);
+
+ ret = of_property_read_u32(np, "spi-rx-bus-width",
+ &fspi->spi_rx_bus_width);
+ if (ret < 0)
+ fspi->spi_rx_bus_width = FSPI_SINGLE_MODE;
+
+ ret = of_property_read_u32(np, "spi-tx-bus-width",
+ &fspi->spi_tx_bus_width);
+ if (ret < 0)
+ fspi->spi_tx_bus_width = FSPI_SINGLE_MODE;
+
+ ret = spi_nor_scan(nor, NULL, &hwcaps);
+ if (ret)
+ goto next_node;
+
+ ret = mtd_device_register(mtd, NULL, 0);
+ if (ret)
+ goto next_node;
+
+ /* Set the correct NOR size now. */
+ if (fspi->nor_size == 0) {
+ fspi->nor_size = mtd->size;
+
+ /* Map the SPI NOR to accessiable address */
+ nxp_fspi_set_map_addr(fspi);
+ }
+
+ /*
+ * The write is working in the unit of the TX FIFO,
+ * not in the unit of the SPI NOR's page size.
+ *
+ * So shrink the spi_nor->page_size if it is larger then the
+ * TX FIFO.
+ */
+ if (nor->page_size > fspi->devtype_data->txfifo)
+ nor->page_size = fspi->devtype_data->txfifo;
+
+ find_node++;
+next_node:
+ i++;
+ }
+
+ if (find_node == 0)
+ goto mutex_failed;
+
+ /* finish the rest init. */
+ ret = nxp_fspi_nor_setup_last(fspi);
+ if (ret)
+ goto last_init_failed;
+
+ nxp_fspi_clk_disable_unprep(fspi);
+ return 0;
+
+last_init_failed:
+ for (i = 0; i < fspi->nor_num; i++) {
+ /* skip the holes */
+ if (!fspi->has_second_chip)
+ i *= 2;
+ mtd_device_unregister(&fspi->mtd[i]);
+ }
+mutex_failed:
+ mutex_destroy(&fspi->lock);
+irq_failed:
+ nxp_fspi_clk_disable_unprep(fspi);
+clk_failed:
+ dev_err(dev, "NXP FSPI probe failed\n");
+ return ret;
+}
+
+static int nxp_fspi_remove(struct platform_device *pdev)
+{
+ struct nxp_fspi *fspi = platform_get_drvdata(pdev);
+ int i;
+
+ for (i = 0; i < fspi->nor_num; i++) {
+ /* skip the holes */
+ if (!fspi->has_second_chip)
+ i *= 2;
+ mtd_device_unregister(&fspi->nor[i].mtd);
+ }
+
+ /* disable the hardware */
+ writel(FSPI_MCR0_MDIS_MASK, fspi->iobase + FSPI_MCR0);
+
+ mutex_destroy(&fspi->lock);
+
+ if (fspi->ahb_addr)
+ iounmap(fspi->ahb_addr);
+
+ return 0;
+}
+
+static int nxp_fspi_suspend(struct platform_device *pdev, pm_message_t state)
+{
+ return 0;
+}
+
+static int nxp_fspi_resume(struct platform_device *pdev)
+{
+ return 0;
+}
+
+static struct platform_driver nxp_fspi_driver = {
+ .driver = {
+ .name = "nxp-fspi",
+ .bus = &platform_bus_type,
+ .of_match_table = nxp_fspi_dt_ids,
+ },
+ .probe = nxp_fspi_probe,
+ .remove = nxp_fspi_remove,
+ .suspend = nxp_fspi_suspend,
+ .resume = nxp_fspi_resume,
+};
+module_platform_driver(nxp_fspi_driver);
+
+MODULE_DESCRIPTION("NXP FSPI Controller Driver");
+MODULE_AUTHOR("NXP Semiconductor");
+MODULE_LICENSE("GPL v2");
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -269,6 +269,7 @@ static inline int set_4byte(struct spi_n
u8 cmd;
switch (JEDEC_MFR(info)) {
+ case SNOR_MFR_ST:
case SNOR_MFR_MICRON:
/* Some Micron need WREN command; all will accept it */
need_wren = true;
@@ -1039,7 +1040,7 @@ static const struct flash_info spi_nor_i
{ "mx66l1g45g", INFO(0xc2201b, 0, 64 * 1024, 2048, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
{ "mx66l1g55g", INFO(0xc2261b, 0, 64 * 1024, 2048, SPI_NOR_QUAD_READ) },
- /* Micron */
+ /* Micron <--> ST Micro */
{ "n25q016a", INFO(0x20bb15, 0, 64 * 1024, 32, SECT_4K | SPI_NOR_QUAD_READ) },
{ "n25q032", INFO(0x20ba16, 0, 64 * 1024, 64, SPI_NOR_QUAD_READ) },
{ "n25q032a", INFO(0x20bb16, 0, 64 * 1024, 64, SPI_NOR_QUAD_READ) },
@@ -1054,6 +1055,12 @@ static const struct flash_info spi_nor_i
{ "n25q00", INFO(0x20ba21, 0, 64 * 1024, 2048, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ | NO_CHIP_ERASE) },
{ "n25q00a", INFO(0x20bb21, 0, 64 * 1024, 2048, SECT_4K | USE_FSR | SPI_NOR_QUAD_READ | NO_CHIP_ERASE) },
+ /* Micron */
+ {
+ "mt35xu512aba", INFO(0x2c5b1a, 0, 128 * 1024, 512,
+ SECT_4K | USE_FSR | SPI_NOR_4B_OPCODES)
+ },
+
/* PMC */
{ "pm25lv512", INFO(0, 0, 32 * 1024, 2, SECT_4K_PMC) },
{ "pm25lv010", INFO(0, 0, 32 * 1024, 4, SECT_4K_PMC) },
@@ -2435,6 +2442,7 @@ static int spi_nor_init_params(struct sp
params->quad_enable = macronix_quad_enable;
break;
+ case SNOR_MFR_ST:
case SNOR_MFR_MICRON:
break;
@@ -2753,7 +2761,8 @@ int spi_nor_scan(struct spi_nor *nor, co
mtd->_read = spi_nor_read;
/* NOR protection support for STmicro/Micron chips and similar */
- if (JEDEC_MFR(info) == SNOR_MFR_MICRON ||
+ if (JEDEC_MFR(info) == SNOR_MFR_ST ||
+ JEDEC_MFR(info) == SNOR_MFR_MICRON ||
JEDEC_MFR(info) == SNOR_MFR_WINBOND ||
info->flags & SPI_NOR_HAS_LOCK) {
nor->flash_lock = stm_lock;
--- a/include/linux/mtd/cfi.h
+++ b/include/linux/mtd/cfi.h
@@ -377,6 +377,7 @@ struct cfi_fixup {
#define CFI_MFR_SHARP 0x00B0
#define CFI_MFR_SST 0x00BF
#define CFI_MFR_ST 0x0020 /* STMicroelectronics */
+#define CFI_MFR_MICRON 0x002C /* Micron */
#define CFI_MFR_TOSHIBA 0x0098
#define CFI_MFR_WINBOND 0x00DA
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -23,7 +23,8 @@
#define SNOR_MFR_ATMEL CFI_MFR_ATMEL
#define SNOR_MFR_GIGADEVICE 0xc8
#define SNOR_MFR_INTEL CFI_MFR_INTEL
-#define SNOR_MFR_MICRON CFI_MFR_ST /* ST Micro <--> Micron */
+#define SNOR_MFR_ST CFI_MFR_ST /* ST Micro */
+#define SNOR_MFR_MICRON CFI_MFR_MICRON /* Micron */
#define SNOR_MFR_MACRONIX CFI_MFR_MACRONIX
#define SNOR_MFR_SPANSION CFI_MFR_AMD
#define SNOR_MFR_SST CFI_MFR_SST
|