1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
|
/*
* Driver core for Samsung SoC onboard UARTs.
*
* Ben Dooks, Copyright (c) 2003-2008 Simtec Electronics
* http://armlinux.simtec.co.uk/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
/* Hote on 2410 error handling
*
* The s3c2410 manual has a love/hate affair with the contents of the
* UERSTAT register in the UART blocks, and keeps marking some of the
* error bits as reserved. Having checked with the s3c2410x01,
* it copes with BREAKs properly, so I am happy to ignore the RESERVED
* feature from the latter versions of the manual.
*
* If it becomes aparrent that latter versions of the 2410 remove these
* bits, then action will have to be taken to differentiate the versions
* and change the policy on BREAK
*
* BJD, 04-Nov-2004
*/
#if defined(CONFIG_SERIAL_SAMSUNG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
#define SUPPORT_SYSRQ
#endif
#include <linux/module.h>
#include <linux/ioport.h>
#include <linux/io.h>
#include <linux/platform_device.h>
#include <linux/init.h>
#include <linux/sysrq.h>
#include <linux/console.h>
#include <linux/tty.h>
#include <linux/tty_flip.h>
#include <linux/serial_core.h>
#include <linux/serial.h>
#include <linux/serial_s3c.h>
#include <linux/notifier.h>
#include <linux/delay.h>
#include <linux/clk.h>
#include <linux/suspend.h>
#include <linux/of.h>
#include <linux/slab.h>
#include <soc/samsung/exynos-pmu.h>
#ifdef CONFIG_SND_SAMSUNG_AUDSS
#include <sound/exynos.h>
#endif
#include <asm/irq.h>
#include "samsung.h"
#include "../../pinctrl/core.h"
#ifdef CONFIG_CPU_IDLE
#include <soc/samsung/exynos-pm.h>
#endif
#ifdef CONFIG_PM_DEVFREQ
#include <linux/pm_qos.h>
#endif
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#if defined(CONFIG_SERIAL_SAMSUNG_DEBUG) && \
defined(CONFIG_DEBUG_LL) && \
!defined(MODULE)
extern void printascii(const char *);
__printf(1, 2)
static void dbg(const char *fmt, ...)
{
va_list va;
char buff[256];
va_start(va, fmt);
vscnprintf(buff, sizeof(buff), fmt, va);
va_end(va);
printascii(buff);
}
#else
#define dbg(fmt, ...) do { if (0) no_printk(fmt, ##__VA_ARGS__); } while (0)
#endif
/* UART name and device definitions */
#define S3C24XX_SERIAL_NAME "ttySAC"
#define S3C24XX_SERIAL_MAJOR 204
#define S3C24XX_SERIAL_MINOR 64
/* This port SHOULD be matched with the parameter
* which is delivered to Kernel from BL via command line as below.
* androidboot.sec_atd.tty=/dev/ttySAC0
*/
#define FACTORY_UART_PORT_LINE 0
#define is_factory_port(port) (FACTORY_UART_PORT_LINE == (port)->line)
/* Baudrate definition*/
#define MAX_BAUD 3000000
#define MIN_BAUD 0
#define BT_UART_TRACE 1
#define LOG_BUFFER_SIZE (0xC8000) /* Allocate 800KB of buffer */
#define PROC_DIR "bluetooth/uart"
#define BLUETOOTH_UART_PORT_LINE 1
#if defined(CONFIG_BCM4361)
#define WIFI_UART_PORT_LINE 15
#endif
/* macros to change one thing to another */
#define tx_enabled(port) ((port)->unused[0])
#define rx_enabled(port) ((port)->unused[1])
/* flag to ignore all characters coming in */
#define RXSTAT_DUMMY_READ (0x10000000)
static LIST_HEAD(drvdata_list);
s3c_wake_peer_t s3c2410_serial_wake_peer[CONFIG_SERIAL_SAMSUNG_UARTS];
EXPORT_SYMBOL_GPL(s3c2410_serial_wake_peer);
#define UART_LOOPBACK_MODE (0x1 << 0)
#define UART_DBG_MODE (0x1 << 1)
static void s3c24xx_serial_rx_fifo_wait(struct s3c24xx_uart_port *ourport);
unsigned char uart_log_buf[256] = {0, };
/* Allocate 800KB of buffer for UART logging */
#define LOG_BUFFER_SIZE (0xC8000)
struct s3c24xx_uart_port *panic_port;
static int exynos_s3c24xx_panic_handler(struct notifier_block *nb,
unsigned long l, void *p)
{
struct uart_port *port = &panic_port->port;
dev_err(panic_port->port.dev, " Register dump\n"
"ULCON 0x%08x "
"UCON 0x%08x "
"UFCON 0x%08x\n"
"UMCON 0x%08x "
"UTRSTAT 0x%08x "
"UERSTAT 0x%08x "
"UMSTAT 0x%08x\n"
"UBRDIV 0x%08x "
"UINTP 0x%08x "
"UINTM 0x%08x\n"
, readl(port->membase + S3C2410_ULCON)
, readl(port->membase + S3C2410_UCON)
, readl(port->membase + S3C2410_UFCON)
, readl(port->membase + S3C2410_UMCON)
, readl(port->membase + S3C2410_UTRSTAT)
, readl(port->membase + S3C2410_UERSTAT)
, readl(port->membase + S3C2410_UMSTAT)
, readl(port->membase + S3C2410_UBRDIV)
, readl(port->membase + S3C64XX_UINTP)
, readl(port->membase + S3C64XX_UINTM)
);
return 0;
}
static struct notifier_block exynos_s3c24xx_panic_block = {
.notifier_call = exynos_s3c24xx_panic_handler,
};
static void uart_sfr_dump(struct s3c24xx_uart_port *ourport)
{
struct uart_port *port = &ourport->port;
dev_err(ourport->port.dev, " Register dump\n"
"ULCON 0x%08x "
"UCON 0x%08x "
"UFCON 0x%08x \n"
"UMCON 0x%08x "
"UTRSTAT 0x%08x "
"UERSTAT 0x%08x "
"UMSTAT 0x%08x \n"
"UBRDIV 0x%08x "
"UINTP 0x%08x "
"UINTM 0x%08x \n"
, readl(port->membase + S3C2410_ULCON)
, readl(port->membase + S3C2410_UCON)
, readl(port->membase + S3C2410_UFCON)
, readl(port->membase + S3C2410_UMCON)
, readl(port->membase + S3C2410_UTRSTAT)
, readl(port->membase + S3C2410_UERSTAT)
, readl(port->membase + S3C2410_UMSTAT)
, readl(port->membase + S3C2410_UBRDIV)
, readl(port->membase + S3C64XX_UINTP)
, readl(port->membase + S3C64XX_UINTM)
);
}
#define PAD_RETENTION_UART_BT_OPTION (0x3188)
#define RTS_PINCTRL (1)
#define DEFAULT_PINCTRL (0)
static void change_uart_gpio(int value, struct s3c24xx_uart_port *ourport)
{
int status = 0;
if (value) {
if (!IS_ERR(ourport->uart_pinctrl_tx_dat)) {
ourport->default_uart_pinctrl->state = NULL;
status = pinctrl_select_state(ourport->default_uart_pinctrl, ourport->uart_pinctrl_tx_dat);
if (status)
dev_err(ourport->port.dev, "Can't set TXD uart pins!!!\n");
else
udelay(10);
}
if (!IS_ERR(ourport->uart_pinctrl_rts)) {
ourport->default_uart_pinctrl->state = NULL;
status = pinctrl_select_state(ourport->default_uart_pinctrl, ourport->uart_pinctrl_rts);
if (status)
dev_err(ourport->port.dev, "Can't set RTS uart pins!!!\n");
}
} else {
if (!IS_ERR(ourport->uart_pinctrl_default)) {
ourport->default_uart_pinctrl->state = NULL;
status = pinctrl_select_state(ourport->default_uart_pinctrl, ourport->uart_pinctrl_default);
if (status)
dev_err(ourport->port.dev, "Can't set default uart pins!!!\n");
}
}
}
static void print_uart_mode(struct uart_port *port,
struct ktermios *termios, unsigned int baud)
{
printk(KERN_ERR "UART port%d configurations\n", port->line);
switch (termios->c_cflag & CSIZE) {
case CS5:
printk(KERN_ERR " - 5bits word length\n");
break;
case CS6:
printk(KERN_ERR " - 6bits word length\n");
break;
case CS7:
printk(KERN_ERR " - 7bits word length\n");
break;
case CS8:
default:
printk(KERN_ERR " - 8bits word length\n");
break;
}
if (termios->c_cflag & CSTOPB)
printk(KERN_ERR " - Use TWO stop bit\n");
else
printk(KERN_ERR " - Use one stop bit\n");
if (termios->c_cflag & CRTSCTS)
printk(KERN_ERR " - Use Autoflow control\n");
printk(KERN_ERR " - Baudrate : %u\n", baud);
}
static ssize_t
uart_dbg_show(struct device *dev, struct device_attribute *attr, char *buf)
{
ssize_t ret = 0;
ret += snprintf(buf + ret, PAGE_SIZE - ret,
"UART Debug Mode Configuration.\n");
ret += snprintf(buf + ret, PAGE_SIZE - ret,
"0 : Change loopback & DBG mode.\n");
ret += snprintf(buf + ret, PAGE_SIZE - ret,
"1 : Change DBG mode.\n");
ret += snprintf(buf + ret, PAGE_SIZE - ret,
"2 : Change Normal mode.\n");
if (ret < PAGE_SIZE - 1) {
ret += snprintf(buf+ret, PAGE_SIZE-ret, "\n");
} else {
buf[PAGE_SIZE-2] = '\n';
buf[PAGE_SIZE-1] = '\0';
ret = PAGE_SIZE-1;
}
return ret;
}
static ssize_t
uart_dbg_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
int input_cmd = 0, ret;
struct s3c24xx_uart_port *ourport;
ret = sscanf(buf, "%d", &input_cmd);
list_for_each_entry(ourport, &drvdata_list, node) {
if (&ourport->pdev->dev != dev)
continue;
switch(input_cmd) {
case 0:
printk(KERN_ERR "Change UART%d to Loopback(DBG) mode\n",
ourport->port.line);
ourport->dbg_mode = UART_DBG_MODE | UART_LOOPBACK_MODE;
break;
case 1:
printk(KERN_ERR "Change UART%d to DBG mode\n",
ourport->port.line);
ourport->dbg_mode = UART_DBG_MODE;
break;
case 2:
printk(KERN_ERR "Change UART%d to normal mode\n",
ourport->port.line);
ourport->dbg_mode = 0;
break;
default:
printk(KERN_ERR "Wrong Command!(0/1/2)\n");
}
}
return count;
}
static DEVICE_ATTR(uart_dbg, 0640, uart_dbg_show, uart_dbg_store);
static ssize_t
uart_error_cnt_show(struct device *dev, struct device_attribute *attr, char *buf)
{
int ret=0;
struct s3c24xx_uart_port *ourport;
sprintf(buf, "000 000 000 000\n");//init buf : overrun parity frame break count
list_for_each_entry(ourport, &drvdata_list, node){
struct uart_port *port = &ourport->port;
if (&ourport->pdev->dev != dev)
continue;
ret = sprintf(buf, "%03x %03x %03x %03x\n", port->icount.overrun, 0, port->icount.frame, port->icount.brk);
}
return ret;
}
static DEVICE_ATTR(error_cnt, 0664, uart_error_cnt_show, NULL);
struct proc_dir_entry *bluetooth_dir, *bt_log_dir;
static void uart_copy_to_local_buf(int dir, struct uart_local_buf *local_buf,
unsigned char *trace_buf, int len)
{
unsigned long long time;
unsigned long rem_nsec;
int i;
int cpu = raw_smp_processor_id();
time = cpu_clock(cpu);
rem_nsec = do_div(time, NSEC_PER_SEC);
if (local_buf->index + (len * 3 + 30) >= local_buf->size)
local_buf->index = 0;
local_buf->index += scnprintf(local_buf->buffer + local_buf->index,
local_buf->size - local_buf->index,
"[%5lu.%06lu] ",
(unsigned long)time, rem_nsec / NSEC_PER_USEC);
if (dir == 2) {
local_buf->index += scnprintf(local_buf->buffer + local_buf->index,
local_buf->size - local_buf->index, "[reg] ");
local_buf->index += scnprintf(local_buf->buffer + local_buf->index,
local_buf->size - local_buf->index,
"%s", trace_buf);
} else {
if (dir == 1)
local_buf->index += snprintf(local_buf->buffer + local_buf->index,
local_buf->size - local_buf->index, "[RX] ");
else
local_buf->index += snprintf(local_buf->buffer + local_buf->index,
local_buf->size - local_buf->index, "[TX] ");
for (i = 0; i < len; i++) {
local_buf->index += snprintf(local_buf->buffer + local_buf->index,
local_buf->size - local_buf->index,
"%02X ", trace_buf[i]);
}
}
local_buf->index += scnprintf(local_buf->buffer + local_buf->index,
local_buf->size - local_buf->index, "\n");
}
static void s3c24xx_serial_resetport(struct uart_port *port,
struct s3c2410_uartcfg *cfg);
static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level,
unsigned int old);
static struct uart_driver s3c24xx_uart_drv;
static inline void uart_clock_enable(struct s3c24xx_uart_port *ourport)
{
if (ourport->check_separated_clk)
clk_prepare_enable(ourport->separated_clk);
clk_prepare_enable(ourport->clk);
}
static inline void uart_clock_disable(struct s3c24xx_uart_port *ourport)
{
clk_disable_unprepare(ourport->clk);
if (ourport->check_separated_clk)
clk_disable_unprepare(ourport->separated_clk);
}
#define MAX_AUD_UART_PIN_STATE 3
#define AUD_UART_PIN_IDLE 0
#define AUD_UART_PIN_LPM 1
#define AUD_UART_PIN_DEFAULT 2
struct pinctrl_state *uart_pin_state[MAX_AUD_UART_PIN_STATE];
struct pinctrl *aud_uart_pinctrl;
static inline struct s3c24xx_uart_port *to_ourport(struct uart_port *port)
{
return container_of(port, struct s3c24xx_uart_port, port);
}
/* translate a port to the device name */
static inline const char *s3c24xx_serial_portname(struct uart_port *port)
{
return to_platform_device(port->dev)->name;
}
static int s3c24xx_serial_txempty_nofifo(struct uart_port *port)
{
return rd_regl(port, S3C2410_UTRSTAT) & S3C2410_UTRSTAT_TXE;
}
/*
* s3c64xx and later SoC's include the interrupt mask and status registers in
* the controller itself, unlike the s3c24xx SoC's which have these registers
* in the interrupt controller. Check if the port type is s3c64xx or higher.
*/
static int s3c24xx_serial_has_interrupt_mask(struct uart_port *port)
{
return to_ourport(port)->info->type == PORT_S3C6400;
}
static void s3c24xx_serial_rx_enable(struct uart_port *port)
{
unsigned long flags;
unsigned int ucon, ufcon;
int count = 10000;
spin_lock_irqsave(&port->lock, flags);
while (--count && !s3c24xx_serial_txempty_nofifo(port))
udelay(100);
ufcon = rd_regl(port, S3C2410_UFCON);
ufcon |= S3C2410_UFCON_RESETRX;
wr_regl(port, S3C2410_UFCON, ufcon);
ucon = rd_regl(port, S3C2410_UCON);
ucon |= S3C2410_UCON_RXIRQMODE;
wr_regl(port, S3C2410_UCON, ucon);
rx_enabled(port) = 1;
spin_unlock_irqrestore(&port->lock, flags);
}
static void s3c24xx_serial_rx_disable(struct uart_port *port)
{
unsigned long flags;
unsigned int ucon;
spin_lock_irqsave(&port->lock, flags);
ucon = rd_regl(port, S3C2410_UCON);
ucon &= ~S3C2410_UCON_RXIRQMODE;
wr_regl(port, S3C2410_UCON, ucon);
rx_enabled(port) = 0;
spin_unlock_irqrestore(&port->lock, flags);
}
static void s3c24xx_serial_stop_tx(struct uart_port *port)
{
struct s3c24xx_uart_port *ourport = to_ourport(port);
if (tx_enabled(port)) {
if (s3c24xx_serial_has_interrupt_mask(port))
__set_bit(S3C64XX_UINTM_TXD,
portaddrl(port, S3C64XX_UINTM));
else
disable_irq_nosync(ourport->tx_irq);
tx_enabled(port) = 0;
if (port->flags & UPF_CONS_FLOW)
s3c24xx_serial_rx_enable(port);
}
}
static void s3c24xx_serial_start_tx(struct uart_port *port)
{
struct s3c24xx_uart_port *ourport = to_ourport(port);
if (!tx_enabled(port)) {
if (port->flags & UPF_CONS_FLOW)
s3c24xx_serial_rx_disable(port);
if (s3c24xx_serial_has_interrupt_mask(port))
__clear_bit(S3C64XX_UINTM_TXD,
portaddrl(port, S3C64XX_UINTM));
else
enable_irq(ourport->tx_irq);
tx_enabled(port) = 1;
}
}
static void s3c24xx_serial_stop_rx(struct uart_port *port)
{
struct s3c24xx_uart_port *ourport = to_ourport(port);
if (rx_enabled(port)) {
dbg("s3c24xx_serial_stop_rx: port=%p\n", port);
if (s3c24xx_serial_has_interrupt_mask(port))
__set_bit(S3C64XX_UINTM_RXD,
portaddrl(port, S3C64XX_UINTM));
else
disable_irq_nosync(ourport->rx_irq);
rx_enabled(port) = 0;
}
}
static inline struct s3c24xx_uart_info *s3c24xx_port_to_info(struct uart_port *port)
{
return to_ourport(port)->info;
}
static inline struct s3c2410_uartcfg *s3c24xx_port_to_cfg(struct uart_port *port)
{
struct s3c24xx_uart_port *ourport;
if (port->dev == NULL)
return NULL;
ourport = container_of(port, struct s3c24xx_uart_port, port);
return ourport->cfg;
}
static int s3c24xx_serial_rx_fifocnt(struct s3c24xx_uart_port *ourport,
unsigned long ufstat)
{
struct s3c24xx_uart_info *info = ourport->info;
if (ufstat & info->rx_fifofull)
return ourport->port.fifosize;
return (ufstat & info->rx_fifomask) >> info->rx_fifoshift;
}
static int s3c24xx_serial_tx_fifocnt(struct s3c24xx_uart_port *ourport,
unsigned long ufstat)
{
struct s3c24xx_uart_info *info = ourport->info;
if (ufstat & info->tx_fifofull)
return ourport->port.fifosize;
return (ufstat & info->tx_fifomask) >> info->tx_fifoshift;
}
/* ? - where has parity gone?? */
#define S3C2410_UERSTAT_PARITY (0x1000)
static irqreturn_t
s3c24xx_serial_rx_chars(int irq, void *dev_id)
{
struct s3c24xx_uart_port *ourport = dev_id;
struct uart_port *port = &ourport->port;
unsigned int ufcon, ch, flag, ufstat, uerstat;
unsigned long flags;
int fifocnt = 0;
int max_count = 64;
unsigned char insert_buf[256] = {0, };
unsigned int insert_cnt = 0;
unsigned char trace_buf[256] = {0, };
int trace_cnt = 0;
spin_lock_irqsave(&port->lock, flags);
__set_bit(S3C64XX_UINTM_RXD, portaddrl(port, S3C64XX_UINTM));
wr_regl(port, S3C64XX_UINTP, S3C64XX_UINTM_RXD_MSK);
while (max_count-- > 0) {
/*
* Receive all characters known to be in FIFO
* before reading FIFO level again
*/
if (fifocnt == 0) {
ufstat = rd_regl(port, S3C2410_UFSTAT);
fifocnt = s3c24xx_serial_rx_fifocnt(ourport, ufstat);
if (fifocnt == 0)
break;
}
fifocnt--;
uerstat = rd_regl(port, S3C2410_UERSTAT);
ch = rd_regb(port, S3C2410_URXH);
if (port->flags & UPF_CONS_FLOW) {
int txe = s3c24xx_serial_txempty_nofifo(port);
if (rx_enabled(port)) {
if (!txe) {
rx_enabled(port) = 0;
continue;
}
} else {
if (txe) {
ufcon = rd_regl(port, S3C2410_UFCON);
ufcon |= S3C2410_UFCON_RESETRX;
wr_regl(port, S3C2410_UFCON, ufcon);
rx_enabled(port) = 1;
spin_unlock_irqrestore(&port->lock,
flags);
goto out;
}
continue;
}
}
/* insert the character into the buffer */
flag = TTY_NORMAL;
port->icount.rx++;
if (unlikely(uerstat & S3C2410_UERSTAT_ANY)) {
dbg("rxerr: port ch=0x%02x, rxs=0x%08x\n",
ch, uerstat);
uart_sfr_dump(ourport);
/* check for break */
if (uerstat & S3C2410_UERSTAT_BREAK) {
dbg("break!\n");
port->icount.brk++;
if (uart_handle_break(port))
goto ignore_char;
}
if (uerstat & S3C2410_UERSTAT_FRAME) {
printk("[UART] Frame Error!\n");
port->icount.frame++;
}
if (uerstat & S3C2410_UERSTAT_OVERRUN) {
printk("[UART] Overrun Error!\n");
port->icount.overrun++;
}
uerstat &= port->read_status_mask;
if (uerstat & S3C2410_UERSTAT_BREAK) {
printk("[UART] Break signal!\n");
flag = TTY_BREAK;
}
else if (uerstat & S3C2410_UERSTAT_PARITY) {
printk("[UART] Parity error!\n");
flag = TTY_PARITY;
}
else if (uerstat & (S3C2410_UERSTAT_FRAME |
S3C2410_UERSTAT_OVERRUN)) {
printk("[UART] Frame&Overrunn Error!\n");
flag = TTY_FRAME;
}
}
if (uart_handle_sysrq_char(port, ch))
goto ignore_char;
insert_buf[insert_cnt++] = ch;
if (ourport->uart_logging)
trace_buf[trace_cnt++] = ch;
ignore_char:
continue;
}
if (ourport->uart_logging && trace_cnt)
uart_copy_to_local_buf(1, &ourport->uart_local_buf, trace_buf, trace_cnt);
__clear_bit(S3C64XX_UINTM_RXD, portaddrl(port, S3C64XX_UINTM));
spin_unlock_irqrestore(&port->lock, flags);
tty_insert_flip_string(&port->state->port, insert_buf, insert_cnt);
tty_flip_buffer_push(&port->state->port);
flush_workqueue(system_unbound_wq);
out:
if (ourport->port.line == BLUETOOTH_UART_PORT_LINE) {
sprintf(uart_log_buf,"[0] UMCON:0x%08x UFSTAT:0x%08x UINTP:0x%08x UCON:0x%08x UMSTAT:0x%08x\n",
rd_regl(port, S3C2410_UMCON), rd_regl(port, S3C2410_UFSTAT), rd_regl(port, S3C2410_UINTP),
rd_regl(port, S3C2410_UCON), rd_regl(port, S3C2410_UMSTAT));
uart_copy_to_local_buf(2, &ourport->uart_local_buf, uart_log_buf, sizeof(uart_log_buf));
}
return IRQ_HANDLED;
}
static irqreturn_t s3c24xx_serial_tx_chars(int irq, void *id)
{
struct s3c24xx_uart_port *ourport = id;
struct uart_port *port = &ourport->port;
struct circ_buf *xmit = &port->state->xmit;
unsigned long flags;
int count = 256;
unsigned char trace_buf[256] = {0, };
int trace_cnt = 0;
if (ourport->port.line == BLUETOOTH_UART_PORT_LINE) {
sprintf(uart_log_buf,"[1] UMCON:0x%08x UFSTAT:0x%08x UINTP:0x%08x UCON:0x%08x UMSTAT:0x%08x\n",
rd_regl(port, S3C2410_UMCON), rd_regl(port, S3C2410_UFSTAT), rd_regl(port, S3C2410_UINTP),
rd_regl(port, S3C2410_UCON), rd_regl(port, S3C2410_UMSTAT));
uart_copy_to_local_buf(2, &ourport->uart_local_buf, uart_log_buf, sizeof(uart_log_buf));
}
spin_lock_irqsave(&port->lock, flags);
if (port->x_char) {
wr_regb(port, S3C2410_UTXH, port->x_char);
if (ourport->uart_logging)
trace_buf[trace_cnt++] = port->x_char;
port->icount.tx++;
port->x_char = 0;
goto out;
}
/* if there isn't anything more to transmit, or the uart is now
* stopped, disable the uart and exit
*/
if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
s3c24xx_serial_stop_tx(port);
goto out;
}
/* try and drain the buffer... */
while (!uart_circ_empty(xmit) && count-- > 0) {
if (rd_regl(port, S3C2410_UFSTAT) & ourport->info->tx_fifofull)
break;
wr_regb(port, S3C2410_UTXH, xmit->buf[xmit->tail]);
if (ourport->uart_logging)
trace_buf[trace_cnt++] = (unsigned char)xmit->buf[xmit->tail];
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
port->icount.tx++;
}
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) {
spin_unlock_irqrestore(&port->lock, flags);
uart_write_wakeup(port);
spin_lock_irqsave(&port->lock, flags);
}
if (uart_circ_empty(xmit))
s3c24xx_serial_stop_tx(port);
out:
wr_regl(port, S3C64XX_UINTP, S3C64XX_UINTM_TXD_MSK);
if (ourport->uart_logging && trace_cnt)
uart_copy_to_local_buf(0, &ourport->uart_local_buf, trace_buf, trace_cnt);
spin_unlock_irqrestore(&port->lock, flags);
return IRQ_HANDLED;
}
#ifdef CONFIG_ARM_EXYNOS_DEVFREQ
static void s3c64xx_serial_qos_func(struct work_struct *work)
{
struct s3c24xx_uart_port *ourport =
container_of(work, struct s3c24xx_uart_port, qos_work.work);
struct uart_port *port = &ourport->port;
if (ourport->mif_qos_val)
pm_qos_update_request_timeout(&ourport->s3c24xx_uart_mif_qos,
ourport->mif_qos_val, ourport->qos_timeout);
if (ourport->cpu_qos_val)
pm_qos_update_request_timeout(&ourport->s3c24xx_uart_cpu_qos,
ourport->cpu_qos_val, ourport->qos_timeout);
if (ourport->uart_irq_affinity)
irq_set_affinity(port->irq, cpumask_of(ourport->uart_irq_affinity));
}
#endif
/* interrupt handler for s3c64xx and later SoC's.*/
static irqreturn_t s3c64xx_serial_handle_irq(int irq, void *id)
{
struct s3c24xx_uart_port *ourport = id;
struct uart_port *port = &ourport->port;
irqreturn_t ret = IRQ_HANDLED;
#ifdef CONFIG_PM_DEVFREQ
if ((ourport->mif_qos_val || ourport->cpu_qos_val)
&& ourport->qos_timeout)
schedule_delayed_work(&ourport->qos_work,
msecs_to_jiffies(100));
#endif
if (rd_regl(port, S3C64XX_UINTP) & S3C64XX_UINTM_RXD_MSK)
ret = s3c24xx_serial_rx_chars(irq, id);
if (rd_regl(port, S3C64XX_UINTP) & S3C64XX_UINTM_TXD_MSK)
ret = s3c24xx_serial_tx_chars(irq, id);
return ret;
}
static unsigned int s3c24xx_serial_tx_empty(struct uart_port *port)
{
struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
unsigned long ufstat = rd_regl(port, S3C2410_UFSTAT);
unsigned long ufcon = rd_regl(port, S3C2410_UFCON);
if (ufcon & S3C2410_UFCON_FIFOMODE) {
if ((ufstat & info->tx_fifomask) != 0 ||
(ufstat & info->tx_fifofull))
return 0;
return 1;
}
return s3c24xx_serial_txempty_nofifo(port);
}
/* no modem control lines */
static unsigned int s3c24xx_serial_get_mctrl(struct uart_port *port)
{
unsigned int umstat = rd_regb(port, S3C2410_UMSTAT);
if (umstat & S3C2410_UMSTAT_CTS)
return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
else
return TIOCM_CAR | TIOCM_DSR;
}
static void s3c24xx_serial_set_mctrl(struct uart_port *port, unsigned int mctrl)
{
unsigned int umcon = rd_regl(port, S3C2410_UMCON);
struct s3c24xx_uart_port *ourport = to_ourport(port);
if (mctrl & TIOCM_RTS)
umcon |= S3C2410_UMCOM_RTS_LOW;
else
umcon &= ~S3C2410_UMCOM_RTS_LOW;
wr_regl(port, S3C2410_UMCON, umcon);
if (ourport->port.line == BLUETOOTH_UART_PORT_LINE) {
sprintf(uart_log_buf,"[2] UMCON:0x%08x UFSTAT:0x%08x UINTP:0x%08x UCON:0x%08x UMSTAT:0x%08x\n",
rd_regl(port, S3C2410_UMCON), rd_regl(port, S3C2410_UFSTAT), rd_regl(port, S3C2410_UINTP),
rd_regl(port, S3C2410_UCON), rd_regl(port, S3C2410_UMSTAT));
uart_copy_to_local_buf(2, &ourport->uart_local_buf, uart_log_buf, sizeof(uart_log_buf));
}
}
static void s3c24xx_serial_break_ctl(struct uart_port *port, int break_state)
{
unsigned long flags;
unsigned int ucon;
spin_lock_irqsave(&port->lock, flags);
ucon = rd_regl(port, S3C2410_UCON);
if (break_state)
ucon |= S3C2410_UCON_SBREAK;
else
ucon &= ~S3C2410_UCON_SBREAK;
wr_regl(port, S3C2410_UCON, ucon);
spin_unlock_irqrestore(&port->lock, flags);
}
static void s3c24xx_serial_shutdown(struct uart_port *port)
{
struct s3c24xx_uart_port *ourport = to_ourport(port);
if (ourport->tx_claimed) {
if (!s3c24xx_serial_has_interrupt_mask(port))
free_irq(ourport->tx_irq, ourport);
tx_enabled(port) = 0;
ourport->tx_claimed = 0;
}
if (ourport->rx_claimed) {
if (!s3c24xx_serial_has_interrupt_mask(port))
free_irq(ourport->rx_irq, ourport);
ourport->rx_claimed = 0;
rx_enabled(port) = 0;
}
/* Clear pending interrupts and mask all interrupts */
if (s3c24xx_serial_has_interrupt_mask(port)) {
free_irq(port->irq, ourport);
wr_regl(port, S3C64XX_UINTP, 0xf);
wr_regl(port, S3C64XX_UINTM, 0xf);
}
}
static int s3c24xx_serial_startup(struct uart_port *port)
{
struct s3c24xx_uart_port *ourport = to_ourport(port);
int ret;
dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
port, (unsigned long long)port->mapbase, port->membase);
ourport->cfg->wake_peer[port->line] =
s3c2410_serial_wake_peer[port->line];
rx_enabled(port) = 1;
ret = request_irq(ourport->rx_irq, s3c24xx_serial_rx_chars, 0,
s3c24xx_serial_portname(port), ourport);
if (ret != 0) {
dev_err(port->dev, "cannot get irq %d\n", ourport->rx_irq);
return ret;
}
ourport->rx_claimed = 1;
dbg("requesting tx irq...\n");
tx_enabled(port) = 1;
ret = request_irq(ourport->tx_irq, s3c24xx_serial_tx_chars, 0,
s3c24xx_serial_portname(port), ourport);
if (ret) {
dev_err(port->dev, "cannot get irq %d\n", ourport->tx_irq);
goto err;
}
ourport->tx_claimed = 1;
dbg("s3c24xx_serial_startup ok\n");
/* the port reset code should have done the correct
* register setup for the port controls */
return ret;
err:
s3c24xx_serial_shutdown(port);
return ret;
}
static int s3c64xx_serial_startup(struct uart_port *port)
{
struct s3c24xx_uart_port *ourport = to_ourport(port);
unsigned long flags;
int ret;
dbg("s3c64xx_serial_startup: port=%p (%08llx,%p)\n",
port, (unsigned long long)port->mapbase, port->membase);
ourport->cfg->wake_peer[port->line] =
s3c2410_serial_wake_peer[port->line];
spin_lock_irqsave(&port->lock, flags);
wr_regl(port, S3C64XX_UINTM, 0xf);
spin_unlock_irqrestore(&port->lock, flags);
if (ourport->use_default_irq == 1)
ret = devm_request_irq(port->dev, port->irq, s3c64xx_serial_handle_irq,
IRQF_SHARED, s3c24xx_serial_portname(port), ourport);
else
ret = request_threaded_irq(port->irq, NULL, s3c64xx_serial_handle_irq,
IRQF_ONESHOT, s3c24xx_serial_portname(port), ourport);
if (ret) {
dev_err(port->dev, "cannot get irq %d\n", port->irq);
return ret;
}
/* For compatibility with s3c24xx Soc's */
rx_enabled(port) = 1;
ourport->rx_claimed = 1;
tx_enabled(port) = 0;
ourport->tx_claimed = 1;
/* Enable Rx Interrupt */
spin_lock_irqsave(&port->lock, flags);
__clear_bit(S3C64XX_UINTM_RXD, portaddrl(port, S3C64XX_UINTM));
spin_unlock_irqrestore(&port->lock, flags);
dbg("s3c64xx_serial_startup ok\n");
return ret;
}
static void aud_uart_gpio_cfg(struct device *dev, int level)
{
#ifdef CONFIG_PINCTRL_SAMSUNG
struct pinctrl_state *pins_default;
int status = 0;
if (level == S3C24XX_UART_PORT_SUSPEND)
pins_default = uart_pin_state[AUD_UART_PIN_IDLE];
else if (level == S3C24XX_UART_PORT_LPM)
pins_default = uart_pin_state[AUD_UART_PIN_LPM];
else
pins_default = uart_pin_state[AUD_UART_PIN_DEFAULT];
if (IS_ERR(pins_default)) {
dev_info(dev, "Uart is still not probed!!!\n");
if (level == S3C24XX_UART_PORT_SUSPEND)
pins_default = pinctrl_lookup_state(aud_uart_pinctrl,
PINCTRL_STATE_IDLE);
else if (level == S3C24XX_UART_PORT_LPM)
pins_default = pinctrl_lookup_state(aud_uart_pinctrl, "lpm");
else
pins_default = pinctrl_lookup_state(aud_uart_pinctrl,
PINCTRL_STATE_DEFAULT);
}
if (!IS_ERR(pins_default)) {
aud_uart_pinctrl->state = NULL;
status = pinctrl_select_state(aud_uart_pinctrl, pins_default);
if (status) {
dev_err(dev, "could not set default pins\n");
goto err_no_pinctrl;
}
} else {
dev_err(dev, "could not get default pinstate\n");
goto err_no_pinctrl;
}
return;
err_no_pinctrl:
#endif
dev_err(dev, "failed to configure gpio for audio\n");
}
void aud_uart_gpio_idle(struct device *dev)
{
/* set aud uart gpio for idle */
aud_uart_gpio_cfg(dev, S3C24XX_UART_PORT_SUSPEND);
}
/* power power management control */
static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level,
unsigned int old)
{
struct s3c24xx_uart_port *ourport = to_ourport(port);
unsigned int umcon;
switch (level) {
case S3C24XX_UART_PORT_SUSPEND:
if (!ourport->in_band_wakeup) {
/* disable auto flow control & set nRTS for High */
umcon = rd_regl(port, S3C2410_UMCON);
umcon &= ~(S3C2410_UMCOM_AFC | S3C2410_UMCOM_RTS_LOW);
wr_regl(port, S3C2410_UMCON, umcon);
if (ourport->port.line == BLUETOOTH_UART_PORT_LINE) {
sprintf(uart_log_buf,"[3] UMCON:0x%08x UFSTAT:0x%08x UINTP:0x%08x UCON:0x%08x UMSTAT:0x%08x\n",
rd_regl(port, S3C2410_UMCON), rd_regl(port, S3C2410_UFSTAT), rd_regl(port, S3C2410_UINTP),
rd_regl(port, S3C2410_UCON), rd_regl(port, S3C2410_UMSTAT));
uart_copy_to_local_buf(2, &ourport->uart_local_buf, uart_log_buf, sizeof(uart_log_buf));
}
}
if (ourport->domain == DOMAIN_AUD)
aud_uart_gpio_cfg(&ourport->pdev->dev, level);
uart_clock_disable(ourport);
break;
case S3C24XX_UART_PORT_RESUME:
uart_clock_enable(ourport);
if (ourport->domain == DOMAIN_AUD)
aud_uart_gpio_cfg(&ourport->pdev->dev, level);
if (ourport->port.line == BLUETOOTH_UART_PORT_LINE) {
sprintf(uart_log_buf,"[4] UMCON:0x%08x UFSTAT:0x%08x UINTP:0x%08x UCON:0x%08x UMSTAT:0x%08x\n",
rd_regl(port, S3C2410_UMCON), rd_regl(port, S3C2410_UFSTAT), rd_regl(port, S3C2410_UINTP),
rd_regl(port, S3C2410_UCON), rd_regl(port, S3C2410_UMSTAT));
uart_copy_to_local_buf(2, &ourport->uart_local_buf, uart_log_buf, sizeof(uart_log_buf));
}
s3c24xx_serial_resetport(port, s3c24xx_port_to_cfg(port));
break;
default:
dev_err(port->dev, "s3c24xx_serial: unknown pm %d\n", level);
}
}
/* baud rate calculation
*
* The UARTs on the S3C2410/S3C2440 can take their clocks from a number
* of different sources, including the peripheral clock ("pclk") and an
* external clock ("uclk"). The S3C2440 also adds the core clock ("fclk")
* with a programmable extra divisor.
*
* The following code goes through the clock sources, and calculates the
* baud clocks (and the resultant actual baud rates) and then tries to
* pick the closest one and select that.
*
*/
#define MAX_CLK_NAME_LENGTH 15
static unsigned int s3c24xx_serial_getclk(struct s3c24xx_uart_port *ourport,
unsigned int req_baud, struct clk **best_clk,
unsigned int *clk_num)
{
struct s3c24xx_uart_info *info = ourport->info;
unsigned long rate;
unsigned int cnt, baud, quot, clk_sel, best_quot = 0;
int calc_deviation, deviation = (1 << 30) - 1;
clk_sel = (ourport->cfg->clk_sel) ? ourport->cfg->clk_sel :
ourport->info->def_clk_sel;
for (cnt = 0; cnt < info->num_clks; cnt++) {
if (!(clk_sel & (1 << cnt)))
continue;
rate = clk_get_rate(ourport->clk);
if (ourport->dbg_mode & UART_DBG_MODE)
printk(" - Clock rate : %ld\n", rate);
if (!rate)
continue;
if (ourport->info->has_divslot) {
unsigned long div = rate / req_baud;
/* The UDIVSLOT register on the newer UARTs allows us to
* get a divisor adjustment of 1/16th on the baud clock.
*
* We don't keep the UDIVSLOT value (the 16ths we
* calculated by not multiplying the baud by 16) as it
* is easy enough to recalculate.
*/
quot = div / 16;
baud = rate / div;
} else {
quot = (rate + (8 * req_baud)) / (16 * req_baud);
baud = rate / (quot * 16);
}
quot--;
calc_deviation = req_baud - baud;
if (calc_deviation < 0)
calc_deviation = -calc_deviation;
if (calc_deviation < deviation) {
*best_clk = ourport->clk;
best_quot = quot;
*clk_num = cnt;
deviation = calc_deviation;
}
}
return best_quot;
}
/* udivslot_table[]
*
* This table takes the fractional value of the baud divisor and gives
* the recommended setting for the UDIVSLOT register.
*/
static u16 udivslot_table[16] = {
[0] = 0x0000,
[1] = 0x0080,
[2] = 0x0808,
[3] = 0x0888,
[4] = 0x2222,
[5] = 0x4924,
[6] = 0x4A52,
[7] = 0x54AA,
[8] = 0x5555,
[9] = 0xD555,
[10] = 0xD5D5,
[11] = 0xDDD5,
[12] = 0xDDDD,
[13] = 0xDFDD,
[14] = 0xDFDF,
[15] = 0xFFDF,
};
static void s3c24xx_serial_set_termios(struct uart_port *port,
struct ktermios *termios,
struct ktermios *old)
{
struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port);
struct s3c24xx_uart_port *ourport = to_ourport(port);
struct clk *clk = ERR_PTR(-EINVAL);
unsigned long flags;
unsigned int baud, quot, clk_sel = 0;
unsigned int ulcon;
unsigned int umcon;
unsigned int udivslot = 0;
/*
* We don't support modem control lines.
*/
termios->c_cflag &= ~(HUPCL | CMSPAR);
termios->c_cflag |= CLOCAL;
/*
* Ask the core to calculate the divisor for us.
*/
baud = uart_get_baud_rate(port, termios, old, MIN_BAUD, MAX_BAUD);
#if defined(CONFIG_BCM4361)
if (ourport->port.line == WIFI_UART_PORT_LINE){
baud = 460800;
printk("set baud as 460800!!\n");
}
#endif
quot = s3c24xx_serial_getclk(ourport, baud, &clk, &clk_sel);
if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST)
quot = port->custom_divisor;
if (IS_ERR(clk))
return;
/* setting clock for baud rate */
if (ourport->baudclk != clk) {
ourport->baudclk = clk;
ourport->baudclk_rate = clk ? clk_get_rate(clk) : 0;
}
if (ourport->info->has_divslot) {
unsigned int div = ourport->baudclk_rate / baud;
if (cfg->has_fracval) {
udivslot = (div & 15);
dbg("fracval = %04x\n", udivslot);
} else {
udivslot = udivslot_table[div & 15];
dbg("udivslot = %04x (div %d)\n", udivslot, div & 15);
}
}
switch (termios->c_cflag & CSIZE) {
case CS5:
dbg("config: 5bits/char\n");
ulcon = S3C2410_LCON_CS5;
break;
case CS6:
dbg("config: 6bits/char\n");
ulcon = S3C2410_LCON_CS6;
break;
case CS7:
dbg("config: 7bits/char\n");
ulcon = S3C2410_LCON_CS7;
break;
case CS8:
default:
dbg("config: 8bits/char\n");
ulcon = S3C2410_LCON_CS8;
break;
}
/* preserve original lcon IR settings */
ulcon |= (cfg->ulcon & S3C2410_LCON_IRM);
if (termios->c_cflag & CSTOPB)
ulcon |= S3C2410_LCON_STOPB;
if (termios->c_cflag & PARENB) {
if (termios->c_cflag & PARODD)
ulcon |= S3C2410_LCON_PODD;
else
ulcon |= S3C2410_LCON_PEVEN;
} else {
ulcon |= S3C2410_LCON_PNONE;
}
spin_lock_irqsave(&port->lock, flags);
dbg("setting ulcon to %08x, brddiv to %d, udivslot %08x\n",
ulcon, quot, udivslot);
wr_regl(port, S3C2410_ULCON, ulcon);
wr_regl(port, S3C2410_UBRDIV, quot);
if (ourport->info->has_divslot)
wr_regl(port, S3C2443_DIVSLOT, udivslot);
umcon = rd_regl(port, S3C2410_UMCON);
if (termios->c_cflag & CRTSCTS) {
umcon |= S3C2410_UMCOM_AFC;
} else {
umcon &= ~S3C2410_UMCOM_AFC;
}
wr_regl(port, S3C2410_UMCON, umcon);
dbg("uart: ulcon = 0x%08x, ucon = 0x%08x, ufcon = 0x%08x\n",
rd_regl(port, S3C2410_ULCON),
rd_regl(port, S3C2410_UCON),
rd_regl(port, S3C2410_UFCON));
if (ourport->dbg_mode & UART_DBG_MODE)
print_uart_mode(port, termios, baud);
/*
* Update the per-port timeout.
*/
uart_update_timeout(port, termios->c_cflag, baud);
/*
* Which character status flags are we interested in?
*/
port->read_status_mask = S3C2410_UERSTAT_OVERRUN;
if (termios->c_iflag & INPCK)
port->read_status_mask |= S3C2410_UERSTAT_FRAME | S3C2410_UERSTAT_PARITY;
/*
* Which character status flags should we ignore?
*/
port->ignore_status_mask = 0;
if (termios->c_iflag & IGNPAR)
port->ignore_status_mask |= S3C2410_UERSTAT_OVERRUN;
if (termios->c_iflag & IGNBRK && termios->c_iflag & IGNPAR)
port->ignore_status_mask |= S3C2410_UERSTAT_FRAME;
/*
* Ignore all characters if CREAD is not set.
*/
if ((termios->c_cflag & CREAD) == 0)
port->ignore_status_mask |= RXSTAT_DUMMY_READ;
spin_unlock_irqrestore(&port->lock, flags);
}
static const char *s3c24xx_serial_type(struct uart_port *port)
{
switch (port->type) {
case PORT_S3C2410:
return "S3C2410";
case PORT_S3C2440:
return "S3C2440";
case PORT_S3C2412:
return "S3C2412";
case PORT_S3C6400:
return "S3C6400/10";
default:
return NULL;
}
}
#define MAP_SIZE (0x100)
static void s3c24xx_serial_release_port(struct uart_port *port)
{
release_mem_region(port->mapbase, MAP_SIZE);
}
static int s3c24xx_serial_request_port(struct uart_port *port)
{
const char *name = s3c24xx_serial_portname(port);
return request_mem_region(port->mapbase, MAP_SIZE, name) ? 0 : -EBUSY;
}
static void s3c24xx_serial_config_port(struct uart_port *port, int flags)
{
struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
if (flags & UART_CONFIG_TYPE &&
s3c24xx_serial_request_port(port) == 0)
port->type = info->type;
}
/*
* verify the new serial_struct (for TIOCSSERIAL).
*/
static int
s3c24xx_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
{
struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
if (ser->type != PORT_UNKNOWN && ser->type != info->type)
return -EINVAL;
return 0;
}
static void s3c24xx_serial_wake_peer(struct uart_port *port)
{
struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port);
if (cfg->wake_peer[port->line])
cfg->wake_peer[port->line](port);
}
#ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE
static struct console s3c24xx_serial_console;
static int __init s3c24xx_serial_console_init(void)
{
struct clk *console_clk;
char pclk_name[16], sclk_name[16];
snprintf(pclk_name, sizeof(pclk_name), "console-pclk%d", CONFIG_S3C_LOWLEVEL_UART_PORT);
snprintf(sclk_name, sizeof(sclk_name), "console-sclk%d", CONFIG_S3C_LOWLEVEL_UART_PORT);
pr_info("Enable clock for console to add reference counter\n");
console_clk = clk_get(NULL, pclk_name);
if (IS_ERR(console_clk)) {
pr_err("Can't get %s!(it's not err)\n", pclk_name);
} else {
clk_prepare_enable(console_clk);
}
console_clk = clk_get(NULL, sclk_name);
if (IS_ERR(console_clk)) {
pr_err("Can't get %s!(it's not err)\n", sclk_name);
} else {
clk_prepare_enable(console_clk);
}
register_console(&s3c24xx_serial_console);
return 0;
}
console_initcall(s3c24xx_serial_console_init);
#define S3C24XX_SERIAL_CONSOLE &s3c24xx_serial_console
#else
#define S3C24XX_SERIAL_CONSOLE NULL
#endif
#if defined(CONFIG_SERIAL_SAMSUNG_CONSOLE) && defined(CONFIG_CONSOLE_POLL)
static int s3c24xx_serial_get_poll_char(struct uart_port *port);
static void s3c24xx_serial_put_poll_char(struct uart_port *port,
unsigned char c);
#endif
static struct uart_ops s3c24xx_serial_ops = {
.pm = s3c24xx_serial_pm,
.tx_empty = s3c24xx_serial_tx_empty,
.get_mctrl = s3c24xx_serial_get_mctrl,
.set_mctrl = s3c24xx_serial_set_mctrl,
.stop_tx = s3c24xx_serial_stop_tx,
.start_tx = s3c24xx_serial_start_tx,
.stop_rx = s3c24xx_serial_stop_rx,
.break_ctl = s3c24xx_serial_break_ctl,
.startup = s3c24xx_serial_startup,
.shutdown = s3c24xx_serial_shutdown,
.set_termios = s3c24xx_serial_set_termios,
.type = s3c24xx_serial_type,
.release_port = s3c24xx_serial_release_port,
.request_port = s3c24xx_serial_request_port,
.config_port = s3c24xx_serial_config_port,
.verify_port = s3c24xx_serial_verify_port,
.wake_peer = s3c24xx_serial_wake_peer,
#if defined(CONFIG_SERIAL_SAMSUNG_CONSOLE) && defined(CONFIG_CONSOLE_POLL)
.poll_get_char = s3c24xx_serial_get_poll_char,
.poll_put_char = s3c24xx_serial_put_poll_char,
#endif
};
static struct uart_driver s3c24xx_uart_drv = {
.owner = THIS_MODULE,
.driver_name = "s3c2410_serial",
.nr = CONFIG_SERIAL_SAMSUNG_UARTS,
.cons = S3C24XX_SERIAL_CONSOLE,
.dev_name = S3C24XX_SERIAL_NAME,
.major = S3C24XX_SERIAL_MAJOR,
.minor = S3C24XX_SERIAL_MINOR,
};
#define __PORT_LOCK_UNLOCKED(i) \
__SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[i].port.lock)
static struct s3c24xx_uart_port s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS] = {
[0] = {
.port = {
.lock = __PORT_LOCK_UNLOCKED(0),
.iotype = UPIO_MEM,
.uartclk = 0,
.fifosize = 16,
.ops = &s3c24xx_serial_ops,
.flags = UPF_BOOT_AUTOCONF,
.line = 0,
}
},
[1] = {
.port = {
.lock = __PORT_LOCK_UNLOCKED(1),
.iotype = UPIO_MEM,
.uartclk = 0,
.fifosize = 16,
.ops = &s3c24xx_serial_ops,
.flags = UPF_BOOT_AUTOCONF,
.line = 1,
}
},
#if CONFIG_SERIAL_SAMSUNG_UARTS > 2
[2] = {
.port = {
.lock = __PORT_LOCK_UNLOCKED(2),
.iotype = UPIO_MEM,
.uartclk = 0,
.fifosize = 16,
.ops = &s3c24xx_serial_ops,
.flags = UPF_BOOT_AUTOCONF,
.line = 2,
}
},
#endif
#if CONFIG_SERIAL_SAMSUNG_UARTS > 3
[3] = {
.port = {
.lock = __PORT_LOCK_UNLOCKED(3),
.iotype = UPIO_MEM,
.uartclk = 0,
.fifosize = 16,
.ops = &s3c24xx_serial_ops,
.flags = UPF_BOOT_AUTOCONF,
.line = 3,
}
},
#endif
#if CONFIG_SERIAL_SAMSUNG_UARTS > 4
[4] = {
.port = {
.lock = __PORT_LOCK_UNLOCKED(4),
.iotype = UPIO_MEM,
.uartclk = 0,
.fifosize = 16,
.ops = &s3c24xx_serial_ops,
.flags = UPF_BOOT_AUTOCONF,
.line = 4,
}
},
#endif
#if CONFIG_SERIAL_SAMSUNG_UARTS > 5
[5] = {
.port = {
.lock = __PORT_LOCK_UNLOCKED(5),
.iotype = UPIO_MEM,
.uartclk = 0,
.fifosize = 16,
.ops = &s3c24xx_serial_ops,
.flags = UPF_BOOT_AUTOCONF,
.line = 5,
}
},
#endif
};
static struct s3c24xx_uart_port *exynos_serial_default_port(int port_index)
{
s3c24xx_serial_ports[port_index].port.lock = __PORT_LOCK_UNLOCKED(port_index);
s3c24xx_serial_ports[port_index].port.iotype = UPIO_MEM;
s3c24xx_serial_ports[port_index].port.uartclk = 0;
s3c24xx_serial_ports[port_index].port.fifosize = 0;
s3c24xx_serial_ports[port_index].port.ops =
&s3c24xx_serial_ops;
s3c24xx_serial_ports[port_index].port.flags = UPF_BOOT_AUTOCONF;
s3c24xx_serial_ports[port_index].port.line = port_index;
return &s3c24xx_serial_ports[port_index];
}
#undef __PORT_LOCK_UNLOCKED
/* s3c24xx_serial_resetport
*
* reset the fifos and other the settings.
*/
static void s3c24xx_serial_resetport(struct uart_port *port,
struct s3c2410_uartcfg *cfg)
{
struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
struct s3c24xx_uart_port *ourport = to_ourport(port);
unsigned long ucon = rd_regl(port, S3C2410_UCON);
unsigned long umcon = rd_regl(port, S3C2410_UMCON);
unsigned int ucon_mask;
ucon_mask = info->clksel_mask;
if (info->type == PORT_S3C2440)
ucon_mask |= S3C2440_UCON0_DIVMASK;
ucon &= ucon_mask;
if (ourport->dbg_mode & UART_LOOPBACK_MODE) {
dev_err(port->dev, "Change Loopback mode!\n");
ucon |= S3C2443_UCON_LOOPBACK;
}
/* Set rts trigger level */
umcon &= ~S5PV210_UMCON_RTSTRIG32;
if (ourport->rts_trig_level && info->rts_trig_shift)
umcon |= ourport->rts_trig_level << info->rts_trig_shift;
wr_regl(port, S3C2410_UMCON, umcon);
/* To prevent unexpected Interrupt before enabling the channel */
wr_regl(port, S3C64XX_UINTM, 0xf);
/* reset both fifos */
wr_regl(port, S3C2410_UFCON, cfg->ufcon | S3C2410_UFCON_RESETBOTH);
wr_regl(port, S3C2410_UFCON, cfg->ufcon);
/* some delay is required after fifo reset */
udelay(1);
wr_regl(port, S3C2410_UCON, ucon | cfg->ucon);
}
/* s3c24xx_serial_init_port
*
* initialise a single serial port from the platform device given
*/
static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
struct platform_device *platdev)
{
struct uart_port *port = &ourport->port;
struct s3c2410_uartcfg *cfg = ourport->cfg;
struct resource *res;
char clkname[MAX_CLK_NAME_LENGTH];
int ret;
dbg("s3c24xx_serial_init_port: port=%p, platdev=%p\n", port, platdev);
if (platdev == NULL)
return -ENODEV;
if (port->mapbase != 0)
return -EINVAL;
/* setup info for port */
port->dev = &platdev->dev;
ourport->pdev = platdev;
/* Startup sequence is different for s3c64xx and higher SoC's */
if (s3c24xx_serial_has_interrupt_mask(port))
s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
port->uartclk = 1;
if (cfg->uart_flags & UPF_CONS_FLOW) {
dbg("s3c24xx_serial_init_port: enabling flow control\n");
port->flags |= UPF_CONS_FLOW;
}
/* sort our the physical and virtual addresses for each UART */
res = platform_get_resource(platdev, IORESOURCE_MEM, 0);
if (res == NULL) {
dev_err(port->dev, "failed to find memory resource for uart\n");
return -EINVAL;
}
dbg("resource %pR)\n", res);
port->membase = devm_ioremap(port->dev, res->start, resource_size(res));
if (!port->membase) {
dev_err(port->dev, "failed to remap controller address\n");
return -EBUSY;
}
port->mapbase = res->start;
ret = platform_get_irq(platdev, 0);
if (ret < 0)
port->irq = 0;
else {
port->irq = ret;
ourport->rx_irq = ret;
ourport->tx_irq = ret + 1;
}
ret = platform_get_irq(platdev, 1);
if (ret > 0)
ourport->tx_irq = ret;
#if defined(CONFIG_PM) && defined(CONFIG_SND_SAMSUNG_AUDSS)
if (ourport->domain == DOMAIN_AUD)
lpass_register_subip(&platdev->dev, "aud-uart");
#endif
if (of_get_property(platdev->dev.of_node,
"samsung,separate-uart-clk", NULL))
ourport->check_separated_clk = 1;
else
ourport->check_separated_clk = 0;
snprintf(clkname, sizeof(clkname), "gate_uart%d", ourport->port.line);
ourport->clk = devm_clk_get(&platdev->dev, clkname);
if (IS_ERR(ourport->clk)) {
pr_err("%s: Controller clock not found\n",
dev_name(&platdev->dev));
ret = PTR_ERR(ourport->clk);
goto err;
}
if (ourport->check_separated_clk) {
snprintf(clkname, sizeof(clkname), "gate_pclk%d", ourport->port.line);
ourport->separated_clk = devm_clk_get(&platdev->dev, clkname);
if (IS_ERR(ourport->separated_clk)) {
pr_err("%s: Controller clock not found\n",
dev_name(&platdev->dev));
return PTR_ERR(ourport->separated_clk);
}
ret = clk_prepare_enable(ourport->separated_clk);
if (ret) {
pr_err("uart: clock failed to prepare+enable: %d\n", ret);
return ret;
}
}
ret = clk_prepare_enable(ourport->clk);
if (ret) {
pr_err("uart: clock failed to prepare+enable: %d\n", ret);
return ret;
}
/* Keep all interrupts masked and cleared */
if (s3c24xx_serial_has_interrupt_mask(port)) {
wr_regl(port, S3C64XX_UINTM, 0xf);
wr_regl(port, S3C64XX_UINTP, 0xf);
wr_regl(port, S3C64XX_UINTSP, 0xf);
}
dbg("port: map=%pa, mem=%p, irq=%d (%d,%d), clock=%u\n",
&port->mapbase, port->membase, port->irq,
ourport->rx_irq, ourport->tx_irq, port->uartclk);
/* reset the fifos (and setup the uart) */
s3c24xx_serial_resetport(port, cfg);
return 0;
err:
port->mapbase = 0;
return ret;
}
#ifdef CONFIG_SAMSUNG_CLOCK
static ssize_t s3c24xx_serial_show_clksrc(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct uart_port *port = s3c24xx_dev_to_port(dev);
struct s3c24xx_uart_port *ourport = to_ourport(port);
if (IS_ERR(ourport->baudclk))
return -EINVAL;
return snprintf(buf, PAGE_SIZE, "* %s\n",
ourport->baudclk->name ?: "(null)");
}
static DEVICE_ATTR(clock_source, S_IRUGO, s3c24xx_serial_show_clksrc, NULL);
#endif
/* Device driver serial port probe */
static const struct of_device_id s3c24xx_uart_dt_match[];
static int probe_index;
static inline struct s3c24xx_serial_drv_data *s3c24xx_get_driver_data(
struct platform_device *pdev)
{
#ifdef CONFIG_OF
if (pdev->dev.of_node) {
const struct of_device_id *match;
match = of_match_node(s3c24xx_uart_dt_match, pdev->dev.of_node);
return (struct s3c24xx_serial_drv_data *)match->data;
}
#endif
return (struct s3c24xx_serial_drv_data *)
platform_get_device_id(pdev)->driver_data;
}
static void s3c24xx_serial_rx_fifo_wait(struct s3c24xx_uart_port *ourport)
{
struct uart_port *port = &ourport->port;
unsigned int fifo_stat;
unsigned long wait_time;
unsigned int fifo_count;
unsigned long flags;
fifo_count = 0;
spin_lock_irqsave(&port->lock, flags);
fifo_stat = rd_regl(port, S3C2410_UFSTAT);
fifo_count = s3c24xx_serial_rx_fifocnt(ourport, fifo_stat);
if (fifo_count) {
__clear_bit(S3C64XX_UINTM_RXD, portaddrl(port, S3C64XX_UINTM));
rx_enabled(port) = 1;
wait_time = jiffies + HZ;
do {
port = &ourport->port;
fifo_stat = rd_regl(port, S3C2410_UFSTAT);
cpu_relax();
} while (s3c24xx_serial_rx_fifocnt(ourport, fifo_stat) && time_before(jiffies, wait_time));
}
spin_unlock_irqrestore(&port->lock, flags);
if (rx_enabled(port))
s3c24xx_serial_stop_rx(port);
}
void s3c24xx_serial_fifo_wait(void)
{
struct s3c24xx_uart_port *ourport;
struct uart_port *port;
unsigned int fifo_stat;
unsigned long wait_time;
list_for_each_entry(ourport, &drvdata_list, node) {
if (ourport->port.line != CONFIG_S3C_LOWLEVEL_UART_PORT)
continue;
wait_time = jiffies + HZ / 4;
do {
port = &ourport->port;
fifo_stat = rd_regl(port, S3C2410_UFSTAT);
cpu_relax();
} while (s3c24xx_serial_tx_fifocnt(ourport, fifo_stat)
&& time_before(jiffies, wait_time));
}
}
EXPORT_SYMBOL_GPL(s3c24xx_serial_fifo_wait);
#ifdef BT_UART_TRACE
static void s3c24xx_print_reg_status(struct s3c24xx_uart_port *ourport)
{
if (ourport->port.line == BLUETOOTH_UART_PORT_LINE) {
struct uart_port *port = &ourport->port;
unsigned int ulcon = rd_regl(port, S3C2410_ULCON);
unsigned int ucon = rd_regl(port, S3C2410_UCON);
unsigned int ufcon = rd_regl(port, S3C2410_UFCON);
unsigned int umcon = rd_regl(port, S3C2410_UMCON);
unsigned int utrstat = rd_regl(port, S3C2410_UTRSTAT);
unsigned int ufstat = rd_regl(port, S3C2410_UFSTAT);
unsigned int umstat = rd_regl(port, S3C2410_UMSTAT);
unsigned int uerstat = rd_regl(port, S3C2410_UERSTAT);
int tx_fifo_full = ufstat & S5PV210_UFSTAT_TXFULL;
int tx_fifo_count = s3c24xx_serial_tx_fifocnt(ourport, ufstat);
int rx_fifo_full = ufstat & S5PV210_UFSTAT_RXFULL;
int rx_fifo_count = s3c24xx_serial_rx_fifocnt(ourport, ufstat);
pr_err("[BT]: ulcon = 0x%08x, ucon = 0x%08x, ufcon = 0x%08x\n, umcon = 0x%08x\n", ulcon, ucon, ufcon, umcon);
pr_err("[BT]: utrstat = 0x%08x, ufstat = 0x%08x, umstat = 0x%08x\n", utrstat, ufstat, umstat);
pr_err("[BT]: uerstat = 0x%08x\n", uerstat);
pr_err("[BT]: tx_fifo_full = %d, tx_fifo_count = %d\n", tx_fifo_full, tx_fifo_count);
pr_err("[BT]: rx_fifo_full = %d, rx_fifo_count = %d\n", rx_fifo_full, rx_fifo_count);
}
}
static ssize_t s3c24xx_serial_bt_log(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
{
int ret;
struct s3c24xx_uart_port *ourport = &s3c24xx_serial_ports[BLUETOOTH_UART_PORT_LINE];
static int copied_bytes = 0;
if (copied_bytes >= LOG_BUFFER_SIZE) {
struct uart_port *port;
port = &ourport->port;
copied_bytes = 0;
if (port && port->state->pm_state == UART_PM_STATE_ON)
s3c24xx_print_reg_status(ourport);
return 0;
}
if (copied_bytes + bytes < LOG_BUFFER_SIZE) {
ret = copy_to_user(userbuf, ourport->uart_local_buf.buffer+copied_bytes, bytes);
if(ret)
{
pr_err("Failed to s3c24xx_serial_bt_log : %d\n", (int)ret);
return ret;
}
copied_bytes += bytes;
return bytes;
} else {
int byte_to_read = LOG_BUFFER_SIZE-copied_bytes;
ret = copy_to_user(userbuf, ourport->uart_local_buf.buffer+copied_bytes, byte_to_read);
if(ret)
{
pr_err("Failed to s3c24xx_serial_bt_log : %d\n", (int)ret);
return ret;
}
copied_bytes += byte_to_read;
return byte_to_read;
}
return 0;
}
static const struct file_operations proc_fops_btlog = {
.owner = THIS_MODULE,
.read = s3c24xx_serial_bt_log,
};
#endif
#ifdef CONFIG_CPU_IDLE
static int s3c24xx_serial_notifier(struct notifier_block *self,
unsigned long cmd, void *v)
{
struct s3c24xx_uart_port *ourport;
struct uart_port *port;
unsigned long flags;
unsigned int umcon;
switch (cmd) {
case LPA_ENTER:
s3c24xx_serial_fifo_wait();
break;
case SICD_ENTER:
case SICD_AUD_ENTER:
list_for_each_entry(ourport, &drvdata_list, node) {
port = &ourport->port;
if (uart_console(port))
continue;
if (is_factory_port(port))
continue;
if (port->state->pm_state == UART_PM_STATE_OFF)
continue;
spin_lock_irqsave(&port->lock, flags);
/* disable auto flow control & set nRTS for High */
umcon = rd_regl(port, S3C2410_UMCON);
umcon &= ~(S3C2410_UMCOM_AFC | S3C2410_UMCOM_RTS_LOW);
wr_regl(port, S3C2410_UMCON, umcon);
spin_unlock_irqrestore(&port->lock, flags);
if (ourport->port.line == BLUETOOTH_UART_PORT_LINE) {
sprintf(uart_log_buf,"[5] UMCON:0x%08x UFSTAT:0x%08x UINTP:0x%08x UCON:0x%08x UMSTAT:0x%08x\n",
rd_regl(port, S3C2410_UMCON), rd_regl(port, S3C2410_UFSTAT), rd_regl(port, S3C2410_UINTP),
rd_regl(port, S3C2410_UCON), rd_regl(port, S3C2410_UMSTAT));
uart_copy_to_local_buf(2, &ourport->uart_local_buf, uart_log_buf, sizeof(uart_log_buf));
}
if (ourport->rts_control)
change_uart_gpio(RTS_PINCTRL, ourport);
}
s3c24xx_serial_fifo_wait();
break;
case SICD_EXIT:
case SICD_AUD_EXIT:
list_for_each_entry(ourport, &drvdata_list, node) {
port = &ourport->port;
if (uart_console(port))
continue;
if (is_factory_port(port))
continue;
if (port->state->pm_state == UART_PM_STATE_OFF)
continue;
spin_lock_irqsave(&port->lock, flags);
/* enable auto flow control */
umcon = rd_regl(port, S3C2410_UMCON);
umcon |= S3C2410_UMCOM_AFC;
wr_regl(port, S3C2410_UMCON, umcon);
spin_unlock_irqrestore(&port->lock, flags);
if (ourport->port.line == BLUETOOTH_UART_PORT_LINE) {
sprintf(uart_log_buf,"[6] UMCON:0x%08x UFSTAT:0x%08x UINTP:0x%08x UCON:0x%08x UMSTAT:0x%08x\n",
rd_regl(port, S3C2410_UMCON), rd_regl(port, S3C2410_UFSTAT), rd_regl(port, S3C2410_UINTP),
rd_regl(port, S3C2410_UCON), rd_regl(port, S3C2410_UMSTAT));
uart_copy_to_local_buf(2, &ourport->uart_local_buf, uart_log_buf, sizeof(uart_log_buf));
}
if (ourport->rts_control)
change_uart_gpio(DEFAULT_PINCTRL, ourport);
}
break;
default:
break;
}
return NOTIFY_DONE;
}
static struct notifier_block s3c24xx_serial_notifier_block = {
.notifier_call = s3c24xx_serial_notifier,
};
#endif
static int s3c24xx_serial_probe(struct platform_device *pdev)
{
struct s3c24xx_uart_port *ourport;
int index = probe_index;
int ret, fifo_size;
int port_index = probe_index;
int rts_trig_level;
dbg("s3c24xx_serial_probe(%p) %d\n", pdev, index);
if (pdev->dev.of_node) {
ret = of_alias_get_id(pdev->dev.of_node, "uart");
if (ret < 0) {
dev_err(&pdev->dev, "UART aliases are not defined(%d).\n",
ret);
} else {
port_index = ret;
}
}
ourport = &s3c24xx_serial_ports[port_index];
if (ourport->port.line != port_index)
ourport = exynos_serial_default_port(port_index);
if (ourport->port.line >= CONFIG_SERIAL_SAMSUNG_UARTS) {
dev_err(&pdev->dev,
"the port %d exceeded CONFIG_SERIAL_SAMSUNG_UARTS(%d)\n"
, ourport->port.line, CONFIG_SERIAL_SAMSUNG_UARTS);
return -EINVAL;
}
ourport->drv_data = s3c24xx_get_driver_data(pdev);
if (!ourport->drv_data) {
dev_err(&pdev->dev, "could not find driver data\n");
return -ENODEV;
}
ourport->baudclk = ERR_PTR(-EINVAL);
ourport->info = ourport->drv_data->info;
ourport->cfg = (dev_get_platdata(&pdev->dev)) ?
dev_get_platdata(&pdev->dev) :
ourport->drv_data->def_cfg;
ourport->port.fifosize = (ourport->info->fifosize) ?
ourport->info->fifosize :
ourport->drv_data->fifosize[port_index];
if (of_get_property(pdev->dev.of_node, "samsung,uart-panic-log", NULL))
ourport->uart_panic_log = 1;
else
ourport->uart_panic_log = 0;
if (ourport->uart_panic_log) {
atomic_notifier_chain_register(&panic_notifier_list, &exynos_s3c24xx_panic_block);
panic_port = ourport;
}
if (of_get_property(pdev->dev.of_node, "samsung,usi-serial-v2", NULL))
ourport->usi_v2 = 1;
else
ourport->usi_v2 = 0;
if (of_get_property(pdev->dev.of_node, "samsung,rts-gpio-control", NULL)) {
ourport->rts_control = 1;
ourport->default_uart_pinctrl = devm_pinctrl_get(&pdev->dev);
if (IS_ERR(ourport->default_uart_pinctrl))
dev_err(&pdev->dev, "Can't get uart pinctrl!!!\n");
else {
ourport->uart_pinctrl_rts = pinctrl_lookup_state(ourport->default_uart_pinctrl,
"rts");
if (IS_ERR(ourport->uart_pinctrl_rts))
dev_err(&pdev->dev, "Can't get RTS pinstate!!!\n");
ourport->uart_pinctrl_tx_dat = pinctrl_lookup_state(ourport->default_uart_pinctrl,
"tx_dat");
ourport->uart_pinctrl_default = pinctrl_lookup_state(ourport->default_uart_pinctrl,
"default");
if (IS_ERR(ourport->uart_pinctrl_default))
dev_err(&pdev->dev, "Can't get Default pinstate!!!\n");
}
}
if (!of_property_read_u32(pdev->dev.of_node, "samsung,rts-trig-level",
&rts_trig_level)) {
ourport->rts_trig_level = rts_trig_level;
}
if (!of_property_read_u32(pdev->dev.of_node, "samsung,fifo-size",
&fifo_size)) {
ourport->port.fifosize = fifo_size;
ourport->info->fifosize = fifo_size;
} else {
dev_err(&pdev->dev,
"Please add FIFO size in device tree!(UART%d)\n", port_index);
return -EINVAL;
}
probe_index++;
dbg("%s: initialising port %p...\n", __func__, ourport);
#ifdef CONFIG_ARM_EXYNOS_DEVFREQ
if (of_property_read_u32(pdev->dev.of_node, "mif_qos_val",
&ourport->mif_qos_val))
ourport->mif_qos_val = 0;
if (of_property_read_u32(pdev->dev.of_node, "cpu_qos_val",
&ourport->cpu_qos_val))
ourport->cpu_qos_val = 0;
if (of_property_read_u32(pdev->dev.of_node, "irq_affinity",
&ourport->uart_irq_affinity))
ourport->uart_irq_affinity = 0;
if (of_property_read_u64(pdev->dev.of_node, "qos_timeout",
(u64 *)&ourport->qos_timeout))
ourport->qos_timeout = 0;
if ((ourport->mif_qos_val || ourport->cpu_qos_val)
&& ourport->qos_timeout) {
INIT_DELAYED_WORK(&ourport->qos_work,
s3c64xx_serial_qos_func);
/* request pm qos */
if (ourport->mif_qos_val)
pm_qos_add_request(&ourport->s3c24xx_uart_mif_qos,
PM_QOS_BUS_THROUGHPUT, 0);
if (ourport->cpu_qos_val)
pm_qos_add_request(&ourport->s3c24xx_uart_cpu_qos,
PM_QOS_CLUSTER1_FREQ_MIN, 0);
}
#endif
if (of_get_property(pdev->dev.of_node, "samsung,in-band-wakeup", NULL))
ourport->in_band_wakeup = 1;
else
ourport->in_band_wakeup = 0;
if (of_get_property(pdev->dev.of_node, "samsung,uart-logging", NULL))
ourport->uart_logging = 1;
else
ourport->uart_logging = 0;
if (of_find_property(pdev->dev.of_node, "samsung,lpass-subip", NULL))
ourport->domain = DOMAIN_AUD;
else
ourport->domain = DOMAIN_TOP;
if (of_find_property(pdev->dev.of_node, "samsung,use-default-irq", NULL))
ourport->use_default_irq =1;
else
ourport->use_default_irq =0;
ret = s3c24xx_serial_init_port(ourport, pdev);
if (ret < 0)
return ret;
if (ourport->uart_logging == 1) {
/* Allocate memory for UART logging */
ourport->uart_local_buf.buffer = kzalloc(LOG_BUFFER_SIZE, GFP_KERNEL);
if (!ourport->uart_local_buf.buffer)
dev_err(&pdev->dev, "could not allocate buffer for UART logging\n");
ourport->uart_local_buf.size = LOG_BUFFER_SIZE;
ourport->uart_local_buf.index = 0;
#ifdef BT_UART_TRACE
if (port_index == BLUETOOTH_UART_PORT_LINE) {
struct proc_dir_entry *ent;
bluetooth_dir = proc_mkdir("bluetooth", NULL);
if (bluetooth_dir == NULL) {
pr_err("Unable to create /proc/bluetooth directory\n");
return -ENOMEM;
}
bt_log_dir = proc_mkdir("uart", bluetooth_dir);
if (bt_log_dir == NULL) {
pr_err("Unable to create /proc/%s directory\n", PROC_DIR);
return -ENOMEM;
}
ent = proc_create("log", 0440, bt_log_dir, &proc_fops_btlog);
if (ent == NULL) {
pr_err("Unable to create /proc/%s/log entry\n", PROC_DIR);
return -ENOMEM;
}
}
#endif
}
/* Registering notifier for audio uart */
if (ourport->domain == DOMAIN_AUD) {
#ifdef CONFIG_SND_SAMSUNG_AUDSS
lpass_set_gpio_cb(&pdev->dev, &aud_uart_gpio_idle);
#endif
#ifdef CONFIG_PINCTRL_SAMSUNG
aud_uart_pinctrl = devm_pinctrl_get(&pdev->dev);
if (IS_ERR(aud_uart_pinctrl)) {
dev_err(&pdev->dev, "could not get AUD pinctrl\n");
} else {
uart_pin_state[AUD_UART_PIN_IDLE] =
pinctrl_lookup_state(aud_uart_pinctrl, PINCTRL_STATE_IDLE);
uart_pin_state[AUD_UART_PIN_LPM] =
pinctrl_lookup_state(aud_uart_pinctrl, "lpm");
uart_pin_state[AUD_UART_PIN_DEFAULT] =
pinctrl_lookup_state(aud_uart_pinctrl, PINCTRL_STATE_DEFAULT);
}
#endif
#ifdef CONFIG_SND_SAMSUNG_AUDSS
/* Audio uart always on */
lpass_get_sync(&pdev->dev);
dev_err(&pdev->dev, "AUD-UART : Audio block power enable.\n");
#endif
}
if (ourport->uart_logging == 1) {
/* Allocate memory for UART logging */
ourport->uart_local_buf.buffer = kzalloc(LOG_BUFFER_SIZE, GFP_KERNEL);
if (!ourport->uart_local_buf.buffer)
dev_err(&pdev->dev, "could not allocate buffer for UART logging\n");
ourport->uart_local_buf.size = LOG_BUFFER_SIZE;
ourport->uart_local_buf.index = 0;
}
dbg("%s: adding port\n", __func__);
uart_add_one_port(&s3c24xx_uart_drv, &ourport->port);
platform_set_drvdata(pdev, &ourport->port);
/*
* Deactivate the clock enabled in s3c24xx_serial_init_port here,
* so that a potential re-enablement through the pm-callback overlaps
* and keeps the clock enabled in this case.
*/
uart_clock_disable(ourport);
#ifdef CONFIG_SAMSUNG_CLOCK
ret = device_create_file(&pdev->dev, &dev_attr_clock_source);
if (ret < 0)
dev_err(&pdev->dev, "failed to add clock source attr.\n");
#endif
list_add_tail(&ourport->node, &drvdata_list);
ret = device_create_file(&pdev->dev, &dev_attr_uart_dbg);
if (ret < 0)
dev_err(&pdev->dev, "failed to create sysfs file.\n");
ret = device_create_file(&pdev->dev, &dev_attr_error_cnt);
if (ret < 0)
dev_err(&pdev->dev, "failed to create sysfs file.\n");
ourport->dbg_mode = 0;
return 0;
}
static int s3c24xx_serial_remove(struct platform_device *dev)
{
struct uart_port *port = s3c24xx_dev_to_port(&dev->dev);
#ifdef CONFIG_PM_DEVFREQ
struct s3c24xx_uart_port *ourport = to_ourport(port);
if (ourport->mif_qos_val && ourport->qos_timeout)
pm_qos_remove_request(&ourport->s3c24xx_uart_mif_qos);
if (ourport->cpu_qos_val && ourport->qos_timeout)
pm_qos_remove_request(&ourport->s3c24xx_uart_cpu_qos);
#endif
if (port) {
device_remove_file(&dev->dev, &dev_attr_error_cnt);
#ifdef CONFIG_SAMSUNG_CLOCK
device_remove_file(&dev->dev, &dev_attr_clock_source);
#endif
if (ourport->uart_logging == 1) {
if (ourport->port.line == BLUETOOTH_UART_PORT_LINE) {
remove_proc_entry("lpm", bt_log_dir);
remove_proc_entry("sleep", bluetooth_dir);
remove_proc_entry("bluetooth", 0);
}
kfree(ourport->uart_local_buf.buffer);
}
uart_remove_one_port(&s3c24xx_uart_drv, port);
}
uart_unregister_driver(&s3c24xx_uart_drv);
return 0;
}
/* UART power management code */
#ifdef CONFIG_PM_SLEEP
static int s3c24xx_serial_suspend(struct device *dev)
{
struct uart_port *port = s3c24xx_dev_to_port(dev);
struct s3c24xx_uart_port *ourport = to_ourport(port);
#ifdef CONFIG_SERIAL_SAMSUNG_HWACG
unsigned int ucon;
#endif
if (port) {
/*
* If rts line must be protected while suspending
* we change the gpio pad as output high
*/
if (ourport->rts_control)
change_uart_gpio(RTS_PINCTRL, ourport);
udelay(300);//dealy for sfr update
s3c24xx_serial_rx_fifo_wait(ourport);
uart_suspend_port(&s3c24xx_uart_drv, port);
#ifdef CONFIG_SERIAL_SAMSUNG_HWACG
uart_clock_enable(ourport);
/* disable Tx, Rx mode bit for suspend in case of HWACG */
ucon = rd_regl(port, S3C2410_UCON);
ucon &= ~(S3C2410_UCON_RXIRQMODE | S3C2410_UCON_TXIRQMODE);
wr_regl(port, S3C2410_UCON, ucon);
uart_clock_disable(ourport);
rx_enabled(port) = 0;
tx_enabled(port) = 0;
#endif
if (ourport->dbg_mode & UART_DBG_MODE)
dev_err(dev, "UART suspend notification for tty framework.\n");
if (ourport->port.line == BLUETOOTH_UART_PORT_LINE) {
struct pinctrl *bt_uart_pinctrl;
bt_uart_pinctrl = devm_pinctrl_get_select(dev, "btsleep");
if (IS_ERR(bt_uart_pinctrl)) {
dev_err(dev, "could not set bt sleep pins\n");
}
}
}
return 0;
}
static int s3c24xx_serial_resume(struct device *dev)
{
struct uart_port *port = s3c24xx_dev_to_port(dev);
struct s3c24xx_uart_port *ourport = to_ourport(port);
if (port) {
if (ourport->port.line == BLUETOOTH_UART_PORT_LINE) {
struct pinctrl *bt_uart_pinctrl;
bt_uart_pinctrl = devm_pinctrl_get_select(dev, "btdefault");
if (IS_ERR(bt_uart_pinctrl)) {
dev_err(dev, "could not set bt default pins\n");
}
}
uart_resume_port(&s3c24xx_uart_drv, port);
if (ourport->port.line == BLUETOOTH_UART_PORT_LINE)
exynos_pmu_update(PAD_RETENTION_UART_BT_OPTION, 0x10000000, 0x10000000);
if (ourport->rts_control)
change_uart_gpio(DEFAULT_PINCTRL, ourport);
if (ourport->dbg_mode & UART_DBG_MODE)
dev_err(dev, "UART resume notification for tty framework.\n");
}
return 0;
}
static int s3c24xx_serial_resume_noirq(struct device *dev)
{
struct uart_port *port = s3c24xx_dev_to_port(dev);
struct s3c24xx_uart_port *ourport = to_ourport(port);
if (port) {
/* restore IRQ mask */
if (s3c24xx_serial_has_interrupt_mask(port)) {
unsigned int uintm = 0xf;
if (tx_enabled(port))
uintm &= ~S3C64XX_UINTM_TXD_MSK;
if (rx_enabled(port))
uintm &= ~S3C64XX_UINTM_RXD_MSK;
uart_clock_enable(ourport);
wr_regl(port, S3C64XX_UINTM, uintm);
uart_clock_disable(ourport);
}
}
return 0;
}
static const struct dev_pm_ops s3c24xx_serial_pm_ops = {
.suspend = s3c24xx_serial_suspend,
.resume = s3c24xx_serial_resume,
.resume_noirq = s3c24xx_serial_resume_noirq,
};
#define SERIAL_SAMSUNG_PM_OPS (&s3c24xx_serial_pm_ops)
#else /* !CONFIG_PM_SLEEP */
#define SERIAL_SAMSUNG_PM_OPS NULL
#endif /* CONFIG_PM_SLEEP */
/* Console code */
#ifdef CONFIG_SERIAL_SAMSUNG_CONSOLE
static struct uart_port *cons_uart;
static int
s3c24xx_serial_console_txrdy(struct uart_port *port, unsigned int ufcon)
{
struct s3c24xx_uart_info *info = s3c24xx_port_to_info(port);
unsigned long ufstat, utrstat;
if (ufcon & S3C2410_UFCON_FIFOMODE) {
/* fifo mode - check amount of data in fifo registers... */
ufstat = rd_regl(port, S3C2410_UFSTAT);
return (ufstat & info->tx_fifofull) ? 0 : 1;
}
/* in non-fifo mode, we go and use the tx buffer empty */
utrstat = rd_regl(port, S3C2410_UTRSTAT);
return (utrstat & S3C2410_UTRSTAT_TXE) ? 1 : 0;
}
static bool
s3c24xx_port_configured(unsigned int ucon)
{
/* consider the serial port configured if the tx/rx mode set */
return (ucon & 0xf) != 0;
}
#ifdef CONFIG_CONSOLE_POLL
/*
* Console polling routines for writing and reading from the uart while
* in an interrupt or debug context.
*/
static int s3c24xx_serial_get_poll_char(struct uart_port *port)
{
struct s3c24xx_uart_port *ourport = to_ourport(port);
unsigned int ufstat;
ufstat = rd_regl(port, S3C2410_UFSTAT);
if (s3c24xx_serial_rx_fifocnt(ourport, ufstat) == 0)
return NO_POLL_CHAR;
return rd_regb(port, S3C2410_URXH);
}
static void s3c24xx_serial_put_poll_char(struct uart_port *port,
unsigned char c)
{
unsigned int ufcon = rd_regl(port, S3C2410_UFCON);
unsigned int ucon = rd_regl(port, S3C2410_UCON);
/* not possible to xmit on unconfigured port */
if (!s3c24xx_port_configured(ucon))
return;
while (!s3c24xx_serial_console_txrdy(port, ufcon))
cpu_relax();
wr_regb(port, S3C2410_UTXH, c);
}
#endif /* CONFIG_CONSOLE_POLL */
static void
s3c24xx_serial_console_putchar(struct uart_port *port, int ch)
{
unsigned int ufcon = rd_regl(port, S3C2410_UFCON);
while (!s3c24xx_serial_console_txrdy(port, ufcon))
cpu_relax();
wr_regb(port, S3C2410_UTXH, ch);
}
static void
s3c24xx_serial_console_write(struct console *co, const char *s,
unsigned int count)
{
unsigned int ucon = rd_regl(cons_uart, S3C2410_UCON);
/* not possible to xmit on unconfigured port */
if (!s3c24xx_port_configured(ucon))
return;
uart_console_write(cons_uart, s, count, s3c24xx_serial_console_putchar);
}
static void __init
s3c24xx_serial_get_options(struct uart_port *port, int *baud,
int *parity, int *bits)
{
struct s3c24xx_uart_port *ourport = to_ourport(port);
unsigned int ulcon;
unsigned int ucon;
unsigned int ubrdiv;
unsigned long rate;
ulcon = rd_regl(port, S3C2410_ULCON);
ucon = rd_regl(port, S3C2410_UCON);
ubrdiv = rd_regl(port, S3C2410_UBRDIV);
dbg("s3c24xx_serial_get_options: port=%p\n"
"registers: ulcon=%08x, ucon=%08x, ubdriv=%08x\n",
port, ulcon, ucon, ubrdiv);
if (s3c24xx_port_configured(ucon)) {
switch (ulcon & S3C2410_LCON_CSMASK) {
case S3C2410_LCON_CS5:
*bits = 5;
break;
case S3C2410_LCON_CS6:
*bits = 6;
break;
case S3C2410_LCON_CS7:
*bits = 7;
break;
case S3C2410_LCON_CS8:
default:
*bits = 8;
break;
}
switch (ulcon & S3C2410_LCON_PMASK) {
case S3C2410_LCON_PEVEN:
*parity = 'e';
break;
case S3C2410_LCON_PODD:
*parity = 'o';
break;
case S3C2410_LCON_PNONE:
default:
*parity = 'n';
}
/* now calculate the baud rate */
rate = clk_get_rate(ourport->clk);
*baud = rate / (16 * (ubrdiv + 1));
dbg("calculated baud %d\n", *baud);
}
}
static int __init
s3c24xx_serial_console_setup(struct console *co, char *options)
{
struct uart_port *port;
int baud = 9600;
int bits = 8;
int parity = 'n';
int flow = 'n';
dbg("s3c24xx_serial_console_setup: co=%p (%d), %s\n",
co, co->index, options);
/* is this a valid port */
if (co->index == -1 || co->index >= CONFIG_SERIAL_SAMSUNG_UARTS)
co->index = 0;
port = &s3c24xx_serial_ports[co->index].port;
/* is the port configured? */
if (port->mapbase == 0x0)
return -ENODEV;
cons_uart = port;
dbg("s3c24xx_serial_console_setup: port=%p (%d)\n", port, co->index);
/*
* Check whether an invalid uart number has been specified, and
* if so, search for the first available port that does have
* console support.
*/
if (options)
uart_parse_options(options, &baud, &parity, &bits, &flow);
else
s3c24xx_serial_get_options(port, &baud, &parity, &bits);
dbg("s3c24xx_serial_console_setup: baud %d\n", baud);
return uart_set_options(port, co, baud, parity, bits, flow);
}
static struct console s3c24xx_serial_console = {
.name = S3C24XX_SERIAL_NAME,
.device = uart_console_device,
.flags = CON_PRINTBUFFER,
.index = -1,
.write = s3c24xx_serial_console_write,
.setup = s3c24xx_serial_console_setup,
.data = &s3c24xx_uart_drv,
};
#define UFCON 0x08
#define FIFO_ENABLED (1<<0)
#define UTXH 0x20
#define URXH 0x24
#define UTRSTAT 0x10
#define UTRSTAT_TXFE (1<<1)
#define UTRSTAT_RXDR (1<<0)
static void
exynos_serial_early_write(struct console *con, const char *s, unsigned n)
{
struct earlycon_device *dev = con->data;
struct uart_port *port = &dev->port;
unsigned char __iomem *early_base = port->membase;
char *ch = (char *)s;
while (n--) {
while (!(readl_relaxed(early_base + UFCON) & FIFO_ENABLED))
;
writeb_relaxed(*ch, early_base + UTXH);
while (!(readl_relaxed(early_base + UTRSTAT) & UTRSTAT_TXFE))
;
ch++;
}
while (!(readl_relaxed(early_base + UFCON) & FIFO_ENABLED))
;
writeb_relaxed('\r', early_base + UTXH);
}
static int __init
exynos_serial_early_console_setup(struct earlycon_device *device, const char *opt)
{
if (!device->port.membase)
return -ENODEV;
device->con->write = exynos_serial_early_write;
return 0;
}
EARLYCON_DECLARE(exynos, exynos_serial_early_console_setup);
#endif /* CONFIG_SERIAL_SAMSUNG_CONSOLE */
#ifdef CONFIG_CPU_S3C2410
static struct s3c24xx_serial_drv_data s3c2410_serial_drv_data = {
.info = &(struct s3c24xx_uart_info) {
.name = "Samsung S3C2410 UART",
.type = PORT_S3C2410,
.fifosize = 16,
.rx_fifomask = S3C2410_UFSTAT_RXMASK,
.rx_fifoshift = S3C2410_UFSTAT_RXSHIFT,
.rx_fifofull = S3C2410_UFSTAT_RXFULL,
.tx_fifofull = S3C2410_UFSTAT_TXFULL,
.tx_fifomask = S3C2410_UFSTAT_TXMASK,
.tx_fifoshift = S3C2410_UFSTAT_TXSHIFT,
.def_clk_sel = S3C2410_UCON_CLKSEL0,
.num_clks = 2,
.clksel_mask = S3C2410_UCON_CLKMASK,
.clksel_shift = S3C2410_UCON_CLKSHIFT,
},
.def_cfg = &(struct s3c2410_uartcfg) {
.ucon = S3C2410_UCON_DEFAULT,
.ufcon = S3C2410_UFCON_DEFAULT,
},
};
#define S3C2410_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c2410_serial_drv_data)
#else
#define S3C2410_SERIAL_DRV_DATA (kernel_ulong_t)NULL
#endif
#ifdef CONFIG_CPU_S3C2412
static struct s3c24xx_serial_drv_data s3c2412_serial_drv_data = {
.info = &(struct s3c24xx_uart_info) {
.name = "Samsung S3C2412 UART",
.type = PORT_S3C2412,
.fifosize = 64,
.has_divslot = 1,
.rx_fifomask = S3C2440_UFSTAT_RXMASK,
.rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
.rx_fifofull = S3C2440_UFSTAT_RXFULL,
.tx_fifofull = S3C2440_UFSTAT_TXFULL,
.tx_fifomask = S3C2440_UFSTAT_TXMASK,
.tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
.def_clk_sel = S3C2410_UCON_CLKSEL2,
.num_clks = 4,
.clksel_mask = S3C2412_UCON_CLKMASK,
.clksel_shift = S3C2412_UCON_CLKSHIFT,
},
.def_cfg = &(struct s3c2410_uartcfg) {
.ucon = S3C2410_UCON_DEFAULT,
.ufcon = S3C2410_UFCON_DEFAULT,
},
};
#define S3C2412_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c2412_serial_drv_data)
#else
#define S3C2412_SERIAL_DRV_DATA (kernel_ulong_t)NULL
#endif
#if defined(CONFIG_CPU_S3C2440) || defined(CONFIG_CPU_S3C2416) || \
defined(CONFIG_CPU_S3C2443) || defined(CONFIG_CPU_S3C2442)
static struct s3c24xx_serial_drv_data s3c2440_serial_drv_data = {
.info = &(struct s3c24xx_uart_info) {
.name = "Samsung S3C2440 UART",
.type = PORT_S3C2440,
.fifosize = 64,
.has_divslot = 1,
.rx_fifomask = S3C2440_UFSTAT_RXMASK,
.rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
.rx_fifofull = S3C2440_UFSTAT_RXFULL,
.tx_fifofull = S3C2440_UFSTAT_TXFULL,
.tx_fifomask = S3C2440_UFSTAT_TXMASK,
.tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
.def_clk_sel = S3C2410_UCON_CLKSEL2,
.num_clks = 4,
.clksel_mask = S3C2412_UCON_CLKMASK,
.clksel_shift = S3C2412_UCON_CLKSHIFT,
},
.def_cfg = &(struct s3c2410_uartcfg) {
.ucon = S3C2410_UCON_DEFAULT,
.ufcon = S3C2410_UFCON_DEFAULT,
},
};
#define S3C2440_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c2440_serial_drv_data)
#else
#define S3C2440_SERIAL_DRV_DATA (kernel_ulong_t)NULL
#endif
#if defined(CONFIG_CPU_S3C6400) || defined(CONFIG_CPU_S3C6410)
static struct s3c24xx_serial_drv_data s3c6400_serial_drv_data = {
.info = &(struct s3c24xx_uart_info) {
.name = "Samsung S3C6400 UART",
.type = PORT_S3C6400,
.fifosize = 64,
.has_divslot = 1,
.rx_fifomask = S3C2440_UFSTAT_RXMASK,
.rx_fifoshift = S3C2440_UFSTAT_RXSHIFT,
.rx_fifofull = S3C2440_UFSTAT_RXFULL,
.tx_fifofull = S3C2440_UFSTAT_TXFULL,
.tx_fifomask = S3C2440_UFSTAT_TXMASK,
.tx_fifoshift = S3C2440_UFSTAT_TXSHIFT,
.def_clk_sel = S3C2410_UCON_CLKSEL2,
.num_clks = 4,
.clksel_mask = S3C6400_UCON_CLKMASK,
.clksel_shift = S3C6400_UCON_CLKSHIFT,
},
.def_cfg = &(struct s3c2410_uartcfg) {
.ucon = S3C2410_UCON_DEFAULT,
.ufcon = S3C2410_UFCON_DEFAULT,
},
};
#define S3C6400_SERIAL_DRV_DATA ((kernel_ulong_t)&s3c6400_serial_drv_data)
#else
#define S3C6400_SERIAL_DRV_DATA (kernel_ulong_t)NULL
#endif
#ifdef CONFIG_CPU_S5PV210
static struct s3c24xx_serial_drv_data s5pv210_serial_drv_data = {
.info = &(struct s3c24xx_uart_info) {
.name = "Samsung S5PV210 UART",
.type = PORT_S3C6400,
.has_divslot = 1,
.rx_fifomask = S5PV210_UFSTAT_RXMASK,
.rx_fifoshift = S5PV210_UFSTAT_RXSHIFT,
.rx_fifofull = S5PV210_UFSTAT_RXFULL,
.tx_fifofull = S5PV210_UFSTAT_TXFULL,
.tx_fifomask = S5PV210_UFSTAT_TXMASK,
.tx_fifoshift = S5PV210_UFSTAT_TXSHIFT,
.def_clk_sel = S3C2410_UCON_CLKSEL0,
.num_clks = 2,
.clksel_mask = S5PV210_UCON_CLKMASK,
.clksel_shift = S5PV210_UCON_CLKSHIFT,
},
.def_cfg = &(struct s3c2410_uartcfg) {
.ucon = S5PV210_UCON_DEFAULT,
.ufcon = S5PV210_UFCON_DEFAULT,
},
.fifosize = { 256, 64, 16, 16 },
};
#define S5PV210_SERIAL_DRV_DATA ((kernel_ulong_t)&s5pv210_serial_drv_data)
#else
#define S5PV210_SERIAL_DRV_DATA (kernel_ulong_t)NULL
#endif
#if defined(CONFIG_ARCH_EXYNOS)
#define EXYNOS_COMMON_SERIAL_DRV_DATA \
.info = &(struct s3c24xx_uart_info) { \
.name = "Samsung Exynos UART", \
.type = PORT_S3C6400, \
.has_divslot = 1, \
.rx_fifomask = S5PV210_UFSTAT_RXMASK, \
.rx_fifoshift = S5PV210_UFSTAT_RXSHIFT, \
.rx_fifofull = S5PV210_UFSTAT_RXFULL, \
.tx_fifofull = S5PV210_UFSTAT_TXFULL, \
.tx_fifomask = S5PV210_UFSTAT_TXMASK, \
.tx_fifoshift = S5PV210_UFSTAT_TXSHIFT, \
.rts_trig_shift = S5PV210_UMCON_RTSTRIG_SHIFT, \
.def_clk_sel = S3C2410_UCON_CLKSEL0, \
.num_clks = 1, \
.clksel_mask = 0, \
.clksel_shift = 0, \
}, \
.def_cfg = &(struct s3c2410_uartcfg) { \
.ucon = S5PV210_UCON_DEFAULT, \
.ufcon = S5PV210_UFCON_DEFAULT, \
.has_fracval = 1, \
} \
static struct s3c24xx_serial_drv_data exynos4210_serial_drv_data = {
EXYNOS_COMMON_SERIAL_DRV_DATA,
.fifosize = { 256, 64, 16, 16 },
};
static struct s3c24xx_serial_drv_data exynos_serial_drv_data = {
EXYNOS_COMMON_SERIAL_DRV_DATA,
.fifosize = { 0, },
};
#define EXYNOS4210_SERIAL_DRV_DATA ((kernel_ulong_t)&exynos4210_serial_drv_data)
#define EXYNOS_SERIAL_DRV_DATA ((kernel_ulong_t)&exynos_serial_drv_data)
#else
#define EXYNOS4210_SERIAL_DRV_DATA (kernel_ulong_t)NULL
#define EXYNOS_SERIAL_DRV_DATA (kernel_ulong_t)NULL
#endif
static const struct platform_device_id s3c24xx_serial_driver_ids[] = {
{
.name = "s3c2410-uart",
.driver_data = S3C2410_SERIAL_DRV_DATA,
}, {
.name = "s3c2412-uart",
.driver_data = S3C2412_SERIAL_DRV_DATA,
}, {
.name = "s3c2440-uart",
.driver_data = S3C2440_SERIAL_DRV_DATA,
}, {
.name = "s3c6400-uart",
.driver_data = S3C6400_SERIAL_DRV_DATA,
}, {
.name = "s5pv210-uart",
.driver_data = S5PV210_SERIAL_DRV_DATA,
}, {
.name = "exynos4210-uart",
.driver_data = EXYNOS4210_SERIAL_DRV_DATA,
}, {
}, {
.name = "exynos-uart",
.driver_data = EXYNOS_SERIAL_DRV_DATA,
},
{ },
};
MODULE_DEVICE_TABLE(platform, s3c24xx_serial_driver_ids);
#ifdef CONFIG_OF
static const struct of_device_id s3c24xx_uart_dt_match[] = {
{ .compatible = "samsung,s3c2410-uart",
.data = (void *)S3C2410_SERIAL_DRV_DATA },
{ .compatible = "samsung,s3c2412-uart",
.data = (void *)S3C2412_SERIAL_DRV_DATA },
{ .compatible = "samsung,s3c2440-uart",
.data = (void *)S3C2440_SERIAL_DRV_DATA },
{ .compatible = "samsung,s3c6400-uart",
.data = (void *)S3C6400_SERIAL_DRV_DATA },
{ .compatible = "samsung,s5pv210-uart",
.data = (void *)S5PV210_SERIAL_DRV_DATA },
{ .compatible = "samsung,exynos4210-uart",
.data = (void *)EXYNOS4210_SERIAL_DRV_DATA },
{ .compatible = "samsung,exynos-uart",
.data = (void *)EXYNOS_SERIAL_DRV_DATA },
{},
};
MODULE_DEVICE_TABLE(of, s3c24xx_uart_dt_match);
#endif
static struct platform_driver samsung_serial_driver = {
.probe = s3c24xx_serial_probe,
.remove = s3c24xx_serial_remove,
.id_table = s3c24xx_serial_driver_ids,
.driver = {
.name = "samsung-uart",
.owner = THIS_MODULE,
.pm = SERIAL_SAMSUNG_PM_OPS,
.of_match_table = of_match_ptr(s3c24xx_uart_dt_match),
},
};
/* module initialisation code */
static int __init s3c24xx_serial_modinit(void)
{
int ret;
ret = uart_register_driver(&s3c24xx_uart_drv);
if (ret < 0) {
pr_err("Failed to register Samsung UART driver\n");
return ret;
}
#ifdef CONFIG_CPU_IDLE
exynos_pm_register_notifier(&s3c24xx_serial_notifier_block);
#endif
return platform_driver_register(&samsung_serial_driver);
}
static void __exit s3c24xx_serial_modexit(void)
{
platform_driver_unregister(&samsung_serial_driver);
uart_unregister_driver(&s3c24xx_uart_drv);
}
module_init(s3c24xx_serial_modinit);
module_exit(s3c24xx_serial_modexit);
MODULE_ALIAS("platform:samsung-uart");
MODULE_DESCRIPTION("Samsung SoC Serial port driver");
MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
MODULE_LICENSE("GPL v2");
|