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
|
/*
SiI8348 Linux Driver
Copyright (C) 2013 Silicon Image, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation version 2.
This program is distributed AS-IS WITHOUT ANY WARRANTY of any
kind, whether express or implied; INCLUDING without the implied warranty
of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE or NON-INFRINGEMENT. See
the GNU General Public License for more details at http://www.gnu.org/licenses/gpl-2.0.html.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/hrtimer.h>
#include <linux/fs.h>
#include <linux/semaphore.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/cdev.h>
#include <linux/stringify.h>
#include <linux/uaccess.h>
#include "sii_hal.h"
#include "si_fw_macros.h"
#include "si_mhl_defs.h"
#include "si_infoframe.h"
#include "si_edid.h"
#include "si_mhl2_edid_3d_api.h"
#include "si_mhl_tx_hw_drv_api.h"
#ifdef MEDIA_DATA_TUNNEL_SUPPORT
#include "si_mdt_inputdev.h"
#endif
#ifdef RCP_INPUTDEV_SUPPORT
#include "mhl_rcp_inputdev.h"
#endif
#include "mhl_linux_tx.h"
#include "mhl_supp.h"
#include "platform.h"
#include <linux/kthread.h>
#include <mach/irqs.h>
#include "mach/eint.h"
#include <mach/mt_gpio.h>
#include <cust_gpio_usage.h>
#include <cust_eint.h>
#include "hdmi_drv.h"
#include "smartbook.h"
#define MHL_DRIVER_MINOR_MAX 1
static wait_queue_head_t mhl_irq_wq;
static struct task_struct *mhl_irq_task = NULL;
static atomic_t mhl_irq_event = ATOMIC_INIT(0);
/************************** MHL TX User Layer To HAL****************************************/
#ifdef CONFIG_MTK_SMARTBOOK_SUPPORT
extern int smartbook_kthread(void *data);
extern wait_queue_head_t smartbook_wq;
static struct task_struct *smartbook_task = NULL;
#endif
void Notify_AP_MHL_TX_Event(unsigned int event, unsigned int event_param, void *param);
/************************** ****************************************************/
struct mhl_dev_context *si_dev_context;
static char *white_space = "' ', '\t'";
static dev_t dev_num;
static struct class *mhl_class;
static void mhl_tx_destroy_timer_support(struct mhl_dev_context *dev_context);
/* Define SysFs attribute names */
#define SYS_ATTR_NAME_CONN connection_state
#define SYS_ATTR_NAME_RCP rcp_keycode
#define SYS_ATTR_NAME_RCPK rcp_ack
#define SYS_ATTR_NAME_RAP rap
#define SYS_ATTR_NAME_RAP_STATUS rap_status
#define SYS_ATTR_NAME_DEVCAP devcap
#define SYS_ATTR_NAME_UCP ucp_keycode
#define SYS_ATTR_NAME_UCPK ucp_ack
#define SYS_ATTR_NAME_SPAD spad
#define SYS_ATTR_NAME_DEBUG debug
#define SYS_ATTR_NAME_TRACE_LEVEL trace_level
/*
* show_connection_state() - Handle read request to the connection_state
* attribute file.
*/
ssize_t show_connection_state(struct device *dev, struct device_attribute *attr, char *buf)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
if (dev_context->mhl_flags & MHL_STATE_FLAG_CONNECTED) {
return scnprintf(buf, PAGE_SIZE, "connected");
} else {
return scnprintf(buf, PAGE_SIZE, "not connected");
}
}
#ifndef RCP_INPUTDEV_SUPPORT
/*
* show_rcp() - Handle read request to the rcp_keycode attribute file.
*/
ssize_t show_rcp(struct device *dev, struct device_attribute *attr, char *buf)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
int status = 0;
if (down_interruptible(&dev_context->isr_lock))
return -ERESTARTSYS;
if (dev_context->mhl_flags &
(MHL_STATE_FLAG_RCP_SENT | MHL_STATE_FLAG_RCP_RECEIVED)) {
status = scnprintf(buf, PAGE_SIZE, "0x%02x %s",
dev_context->rcp_key_code,
dev_context->mhl_flags & MHL_STATE_FLAG_RCP_SENT? "sent" : "received");
}
up(&dev_context->isr_lock);
return status;
}
/*
* send_rcp() - Handle write request to the rcp_keycode attribute file.
*/
ssize_t send_rcp(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
unsigned long key_code;
int status = -EINVAL;
MHL_TX_DBG_INFO(dev_context, "send_rcp received string: ""%s""\n", buf);
if (down_interruptible(&dev_context->isr_lock))
return -ERESTARTSYS;
if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
status = -ENODEV;
goto err_exit;
}
if (!(dev_context->mhl_flags & MHL_STATE_FLAG_CONNECTED))
goto err_exit;
if (strict_strtoul(buf, 0, &key_code)) {
MHL_TX_DBG_ERR(dev_context, "Unable to convert key code string\n");
goto err_exit;
}
if (key_code >= 0xFE) {
MHL_TX_DBG_ERR(dev_context, "key code (0x%lx) is too large to be valid\n", key_code);
goto err_exit;
}
dev_context->mhl_flags &= ~(MHL_STATE_FLAG_RCP_RECEIVED |
MHL_STATE_FLAG_RCP_ACK |
MHL_STATE_FLAG_RCP_NAK);
dev_context->mhl_flags |= MHL_STATE_FLAG_RCP_SENT;
dev_context->rcp_send_status = 0;
dev_context->rcp_key_code = (u8)key_code;
if (!si_mhl_tx_rcp_send(dev_context, (u8)key_code))
goto err_exit;
status = count;
err_exit:
up(&dev_context->isr_lock);
return status;
}
/*
* send_rcp_ack() - Handle write request to the rcp_ack attribute file.
*
* This file is used to send either an ACK or NAK for a received
* Remote Control Protocol (RCP) key code.
*
* The format of the string in buf must be:
* "keycode=<keyvalue> errorcode=<errorvalue>
* where: <keyvalue> is replaced with value of the RCP to be ACK'd or NAK'd
* <errorvalue> 0 if the RCP key code is to be ACK'd
* non-zero error code if the RCP key code is to be NAK'd
*/
ssize_t send_rcp_ack(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
unsigned long key_code = 0x100; /* initialize with invalid values */
unsigned long err_code = 0x100;
char *pStr;
int status = -EINVAL;
MHL_TX_DBG_INFO(dev_context, "received string: %s\n", buf);
/* Parse the input string and extract the RCP key code and error code */
pStr = strstr(buf, "keycode=");
if (pStr != NULL) {
key_code = simple_strtoul(pStr + 8, NULL, 0);
if (key_code > 0xFF) {
MHL_TX_DBG_ERR(dev_context, "Unable to convert keycode string\n");
goto err_exit_2;
}
} else {
MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find ""keycode"" value\n");
goto err_exit_2;
}
pStr = strstr(buf, "errorcode=");
if (pStr != NULL) {
if(strict_strtoul(pStr + 10, 0, &err_code)) {
MHL_TX_DBG_ERR(dev_context, "Unable to convert errorcode string\n");
goto err_exit_2;
}
} else {
MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find ""errorcode"" value\n");
goto err_exit_2;
}
if ((key_code > 0xFF) || (err_code > 0xFF)) {
MHL_TX_DBG_ERR(dev_context, "Invalid key code or error code "\
"specified, key code: 0x%02lx error code: 0x%02lx\n",
key_code, err_code);
goto err_exit_2;
}
if (down_interruptible(&dev_context->isr_lock))
return -ERESTARTSYS;
if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
status = -ENODEV;
goto err_exit_1;
}
if (dev_context->mhl_flags & MHL_STATE_FLAG_CONNECTED) {
if((key_code != dev_context->rcp_key_code)
|| !(dev_context->mhl_flags & MHL_STATE_FLAG_RCP_RECEIVED)) {
MHL_TX_DBG_ERR(dev_context, "Attempting to ACK a key code "\
"that was not received! try:0x%02x(%d)\n"
,dev_context->rcp_key_code
,dev_context->rcp_key_code);
goto err_exit_1;
}
if (err_code == 0) {
if (!si_mhl_tx_rcpk_send(dev_context, (u8)key_code)) {
status = -ENOMEM;
goto err_exit_1;
}
} else {
if (!si_mhl_tx_rcpe_send(dev_context, (u8)err_code))
goto err_exit_1;
}
status = count;
}
err_exit_1:
up(&dev_context->isr_lock);
err_exit_2:
return status;
}
/*
* show_rcp_ack() - Handle read request to the rcp_ack attribute file.
*
* Reads from this file return a string detailing the last RCP
* ACK or NAK received by the driver.
*
* The format of the string returned in buf is:
* "keycode=<keyvalue> errorcode=<errorvalue>
* where: <keyvalue> is replaced with value of the RCP key code for which
* an ACK or NAK has been received.
* <errorvalue> 0 if the last RCP key code was ACK'd or
* non-zero error code if the RCP key code was NAK'd
*/
ssize_t show_rcp_ack(struct device *dev, struct device_attribute *attr, char *buf)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
int status = -EINVAL;
MHL_TX_DBG_INFO(dev_context, "called\n");
if (down_interruptible(&dev_context->isr_lock))
return -ERESTARTSYS;
if (dev_context->mhl_flags & (MHL_STATE_FLAG_RCP_ACK | MHL_STATE_FLAG_RCP_NAK)) {
status = scnprintf(buf, PAGE_SIZE, "keycode=0x%02x errorcode=0x%02x",
dev_context->rcp_key_code, dev_context->rcp_err_code);
}
up(&dev_context->isr_lock);
return status;
}
#endif /* #ifndef RCP_INPUTDEV_SUPPORT */
/*
* show_ucp() - Handle read request to the ucp_keycode attribute file.
*/
ssize_t show_ucp(struct device *dev, struct device_attribute *attr, char *buf)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
int status = 0;
MHL_TX_DBG_INFO(dev_context, "called keycode:0x%02x\n",dev_context->ucp_key_code);
if (down_interruptible(&dev_context->isr_lock))
return -ERESTARTSYS;
if (dev_context->mhl_flags &
(MHL_STATE_FLAG_UCP_SENT | MHL_STATE_FLAG_UCP_RECEIVED)) {
status = scnprintf(buf, PAGE_SIZE, "0x%02x %s",
dev_context->ucp_key_code,
dev_context->mhl_flags & MHL_STATE_FLAG_UCP_SENT? "sent" : "received");
}
up(&dev_context->isr_lock);
return status;
}
/*
* send_ucp() - Handle write request to the ucp_keycode attribute file.
*/
ssize_t send_ucp(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
unsigned long key_code;
int status = -EINVAL;
MHL_TX_DBG_INFO(dev_context, "received string: ""%s""\n", buf);
if (down_interruptible(&dev_context->isr_lock))
return -ERESTARTSYS;
if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
status = -ENODEV;
goto err_exit;
}
if (!(dev_context->mhl_flags & MHL_STATE_FLAG_CONNECTED))
goto err_exit;
if (strict_strtoul(buf, 0, &key_code)) {
MHL_TX_DBG_ERR(dev_context, "Unable to convert key code string\n");
goto err_exit;
}
if (key_code > 0xFF) {
MHL_TX_DBG_ERR(dev_context, "ucp key code (0x%lx) is too large to be valid\n", key_code);
goto err_exit;
}
dev_context->mhl_flags &= ~(MHL_STATE_FLAG_UCP_RECEIVED |
MHL_STATE_FLAG_UCP_ACK |
MHL_STATE_FLAG_UCP_NAK);
dev_context->mhl_flags |= MHL_STATE_FLAG_UCP_SENT;
dev_context->ucp_key_code = (u8)key_code;
if (!si_mhl_tx_ucp_send(dev_context, (u8)key_code))
goto err_exit;
status = count;
err_exit:
up(&dev_context->isr_lock);
return status;
}
/*
* send_ucp_ack() - Handle write request to the ucp_ack attribute file.
*
* This file is used to send either an ACK or NAK for a received
* UTF-8 Control Protocol (UCP) key code.
*
* The format of the string in buf must be:
* "keycode=<keyvalue> errorcode=<errorvalue>
* where: <keyvalue> is replaced with value of the UCP to be ACK'd or NAK'd
* <errorvalue> 0 if the UCP key code is to be ACK'd
* non-zero error code if the UCP key code is to be NAK'd
*/
ssize_t send_ucp_ack(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
unsigned long key_code = 0x100; /* initialize with invalid values */
unsigned long err_code = 0x100;
char *pStr;
int status = -EINVAL;
MHL_TX_DBG_INFO(dev_context, "received string: %s\n", buf);
/* Parse the input string and extract the UCP key code and error code */
pStr = strstr(buf, "keycode=");
if (pStr != NULL) {
key_code = simple_strtoul(pStr + 8, NULL, 0);
if (key_code > 0xFF) {
MHL_TX_DBG_ERR(dev_context, "Unable to convert keycode string\n");
goto err_exit_2;
}
} else {
MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find ""keycode"" value\n");
goto err_exit_2;
}
pStr = strstr(buf, "errorcode=");
if (pStr != NULL) {
if(strict_strtoul(pStr + 10, 0, &err_code)) {
MHL_TX_DBG_ERR(dev_context, "Unable to convert errorcode string\n");
goto err_exit_2;
}
} else {
MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find ""errorcode"" value\n");
goto err_exit_2;
}
if ((key_code > 0xFF) || (err_code > 0xFF)) {
MHL_TX_DBG_ERR(dev_context, "Invalid key code or error code "\
"specified, key code: 0x%02lx error code: 0x%02lx\n",
key_code, err_code);
goto err_exit_2;
}
if (down_interruptible(&dev_context->isr_lock))
return -ERESTARTSYS;
if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
status = -ENODEV;
goto err_exit_1;
}
if (dev_context->mhl_flags & MHL_STATE_FLAG_CONNECTED) {
if((key_code != dev_context->ucp_key_code)
|| !(dev_context->mhl_flags & MHL_STATE_FLAG_UCP_RECEIVED)) {
MHL_TX_DBG_ERR(dev_context, "Attempting to ACK a key code that was not received!\n");
goto err_exit_1;
}
if (err_code == 0) {
if (!si_mhl_tx_ucpk_send(dev_context, (u8)key_code)) {
status = -ENOMEM;
goto err_exit_1;
}
} else {
if (!si_mhl_tx_ucpe_send(dev_context, (u8)err_code)) {
status = -ENOMEM;
goto err_exit_1;
}
}
status = count;
}
err_exit_1:
up(&dev_context->isr_lock);
err_exit_2:
return status;
}
/*
* show_ucp_ack() - Handle read request to the ucp_ack attribute file.
*
* Reads from this file return a string detailing the last UCP
* ACK or NAK received by the driver.
*
* The format of the string returned in buf is:
* "keycode=<keyvalue> errorcode=<errorvalue>
* where: <keyvalue> is replaced with value of the UCP key code for which
* an ACK or NAK has been received.
* <errorvalue> 0 if the last UCP key code was ACK'd or
* non-zero error code if the UCP key code was NAK'd
*/
ssize_t show_ucp_ack(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
int status = -EINVAL;
MHL_TX_DBG_INFO(dev_context, "called\n");
if (down_interruptible(&dev_context->isr_lock))
return -ERESTARTSYS;
if (dev_context->mhl_flags & (MHL_STATE_FLAG_UCP_ACK | MHL_STATE_FLAG_UCP_NAK)) {
status = scnprintf(buf, PAGE_SIZE, "keycode=0x%02x errorcode=0x%02x",
dev_context->ucp_key_code, dev_context->ucp_err_code);
}
up(&dev_context->isr_lock);
return status;
}
/*
* show_rap() - Handle read request to the rap attribute file.
*
* Reads from this file return a string value indicating the last
* Request Action Protocol (RAP) request received.
*
* The return value is the number characters written to buf, or EAGAIN
* if the driver is busy and cannot service the read request immediately.
* If EAGAIN is returned the caller should wait a little and retry the
* read.
*/
ssize_t show_rap(struct device *dev, struct device_attribute *attr, char *buf)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
int status = -EINVAL;
MHL_TX_DBG_INFO(dev_context, "called last sub-command:0x%02x\n",dev_context->rap_sub_command);
if (down_interruptible(&dev_context->isr_lock)){
MHL_TX_DBG_ERR(dev_context,"-ERESTARTSYS\n");
return -ERESTARTSYS;
}
if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
MHL_TX_DBG_ERR(dev_context,"-ENODEV\n");
status = -ENODEV;
goto err_exit;
}
*buf = '\0';
if (MHL_RAP_POLL == dev_context->rap_sub_command)
status = scnprintf(buf, PAGE_SIZE, "poll");
else if (MHL_RAP_CONTENT_ON == dev_context->rap_sub_command)
status = scnprintf(buf, PAGE_SIZE, "content_on");
else if (MHL_RAP_CONTENT_OFF == dev_context->rap_sub_command)
status = scnprintf(buf, PAGE_SIZE, "content_off");
MHL_TX_DBG_INFO(dev_context,"buf:%c%s%c\n",'"',buf,'"');
err_exit:
up(&dev_context->isr_lock);
return status;
}
/*
* send_rap() - Handle write request to the rap attribute file.
*
* Writes to this file cause a RAP message with the specified action code
* to be sent to the downstream device.
*/
ssize_t send_rap(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
int status;
/* Assume success */
status = count;
MHL_TX_DBG_INFO(dev_context, "received string: %s\n", buf);
if (down_interruptible(&dev_context->isr_lock))
return -ERESTARTSYS;
if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
status = -ENODEV;
goto err_exit;
}
if (strnicmp("poll", buf, count - 1) == 0) {
if (!si_mhl_tx_rap_send(dev_context, MHL_RAP_POLL))
status = -EPERM;
} else if (strnicmp("content_on", buf, count - 1) == 0) {
if (!si_mhl_tx_rap_send(dev_context, MHL_RAP_CONTENT_ON))
status = -EPERM;
} else if (strnicmp("content_off", buf, count - 1) == 0) {
if (!si_mhl_tx_rap_send(dev_context, MHL_RAP_CONTENT_OFF))
status = -EPERM;
} else {
MHL_TX_DBG_ERR(dev_context, "Invalid parameter %s received\n", buf);
status = -EINVAL;
}
err_exit:
up(&dev_context->isr_lock);
return status;
}
//( begin rap_status interface
/*
* show_rap_status() - Handle read request to the rap_status attribute file.
*
* Reads from this file return the last setting from the customer application
*/
ssize_t show_rap_status(struct device *dev, struct device_attribute *attr, char *buf)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
int status = -EINVAL;
MHL_TX_DBG_INFO(dev_context, "called last sub-command:0x%02x\n",dev_context->rap_sub_command);
if (down_interruptible(&dev_context->isr_lock)){
MHL_TX_DBG_ERR(dev_context,"-ERESTARTSYS\n");
return -ERESTARTSYS;
}
if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
MHL_TX_DBG_ERR(dev_context,"-ENODEV\n");
status = -ENODEV;
goto err_exit;
}
*buf = '\0';
if (dev_context->mhl_flags & MHL_STATE_APPLICATION_RAP_BUSY){
status = scnprintf(buf, PAGE_SIZE, "busy");
}else{
status = scnprintf(buf, PAGE_SIZE, "ready");
}
MHL_TX_DBG_INFO(dev_context,"buf:%c%s%c\n",'"',buf,'"');
err_exit:
up(&dev_context->isr_lock);
return status;
}
/*
* set_rap_status() - Handle write request to the rap attribute file.
*
* Writes to this file cause a RAP message with the specified action code
* to be sent to the downstream device.
*/
ssize_t set_rap_status(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
int status;
/* Assume success */
status = count;
MHL_TX_DBG_INFO(dev_context, "received string: %s\n", buf);
if (down_interruptible(&dev_context->isr_lock))
return -ERESTARTSYS;
if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
status = -ENODEV;
goto err_exit;
}
if (strnicmp("busy", buf, count - 1) == 0) {
dev_context->mhl_flags |= MHL_STATE_APPLICATION_RAP_BUSY;
} else if (strnicmp("ready", buf, count - 1) == 0) {
dev_context->mhl_flags &= ~MHL_STATE_APPLICATION_RAP_BUSY;
} else {
MHL_TX_DBG_ERR(dev_context, "Invalid parameter %s received\n", buf);
status = -EINVAL;
}
err_exit:
up(&dev_context->isr_lock);
return status;
}
//) end rap_status interface
/*
* select_dev_cap() - Handle write request to the devcap attribute file.
*
* Writes to the devcap file are done to set the offset of a particular
* Device Capabilities register to be returned by a subsequent read
* from this file.
*
* All we need to do is validate the specified offset and if valid
* save it for later use.
*/
ssize_t select_dev_cap(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
unsigned long offset;
int status = -EINVAL;
MHL_TX_DBG_INFO(dev_context, "received string: ""%s""\n", buf);
if (strict_strtoul(buf, 0, &offset)) {
MHL_TX_DBG_ERR(dev_context, "Unable to convert register offset string\n");
goto err_exit;
}
if (offset > 0x0F) {
MHL_TX_DBG_INFO(dev_context,
"dev cap offset (0x%lx) is too large to be valid\n", offset);
goto err_exit;
}
dev_context->dev_cap_offset = (u8)offset;
status = count;
err_exit:
return status;
}
/*
* show_dev_cap() - Handle read request to the devcap attribute file.
*
* Reads from this file return the hexadecimal string value of the last
* Device Capability register offset written to this file.
*
* The return value is the number characters written to buf, or EAGAIN
* if the driver is busy and cannot service the read request immediately.
* If EAGAIN is returned the caller should wait a little and retry the
* read.
*
* The format of the string returned in buf is:
* "offset:<offset>=<regvalue>
* where: <offset> is the last Device Capability register offset
* written to this file
* <regvalue> the currentl value of the Device Capability register
* specified in offset
*/
ssize_t show_dev_cap(struct device *dev, struct device_attribute *attr, char *buf)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
uint8_t regValue;
int status = -EINVAL;
MHL_TX_DBG_INFO(dev_context, "called\n");
if (down_interruptible(&dev_context->isr_lock))
return -ERESTARTSYS;
if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
status = -ENODEV;
goto err_exit;
}
if (dev_context->mhl_flags & MHL_STATE_FLAG_CONNECTED) {
status = si_mhl_tx_get_peer_dev_cap_entry(dev_context,
dev_context->dev_cap_offset,
®Value);
if (status != 0) {
/*
* Driver is busy and cannot provide the requested DEVCAP
* register value right now so inform caller they need to
* try again later.
*/
status = -EAGAIN;
goto err_exit;
}
status = scnprintf(buf, PAGE_SIZE, "offset:0x%02x=0x%02x",
dev_context->dev_cap_offset, regValue);
}
err_exit:
up(&dev_context->isr_lock);
return status;
}
/*
* send_scratch_pad() - Handle write request to the spad attribute file.
*
* This file is used to either initiate a write to the scratch pad registers
* of an attached device, or to set the offset and byte count for a subsequent
* read from the local scratch pad registers.
*
* The format of the string in buf must be:
* offset=<offset_value> length=<Length_value> \
* data=data_byte_0 ... data_byte_length-1
* where: <offset_value> specifies the starting register offset to begin
* read/writing within the scratch pad register space
* <length_value> number of scratch pad registers to be written/read
* data_byte space separated list of <length_value> data bytes
* to be written. If no data bytes are present then
* the write to this file will only be used to set
* the offset and length for a subsequent read from
* this file.
*/
ssize_t send_scratch_pad(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
unsigned long offset = 0x100; /* initialize with invalid values */
unsigned long length = 0x100;
unsigned long value;
u8 data[MAX_SCRATCH_PAD_TRANSFER_SIZE];
u8 idx;
char *str;
char *endptr;
enum scratch_pad_status scratch_pad_status;
int status = -EINVAL;
MHL_TX_DBG_ERR(dev_context, "received string: ""%s""\n", buf);
/*
* Parse the input string and extract the scratch pad register selection
* parameters
*/
str = strstr(buf, "offset=");
if (str != NULL) {
offset = simple_strtoul(str + 7, NULL, 0);
if (offset > SCRATCH_PAD_SIZE) {
MHL_TX_DBG_ERR(dev_context, "Invalid offset value entered\n");
goto err_exit_2;
}
} else {
MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find ""offset"" value\n");
goto err_exit_2;
}
str = strstr(buf, "length=");
if (str != NULL) {
length = simple_strtoul(str + 7, NULL, 0);
if (length > MAX_SCRATCH_PAD_TRANSFER_SIZE) {
MHL_TX_DBG_ERR(dev_context, "Transfer length too large\n");
goto err_exit_2;
}
} else {
MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find ""length"" value\n");
goto err_exit_2;
}
str = strstr(buf, "data=");
if (str != NULL) {
str += 5;
endptr = str;
for(idx = 0; idx < length; idx++) {
endptr += strspn(endptr, white_space);
str = endptr;
if (*str == 0) {
MHL_TX_DBG_ERR(dev_context, "Too few data values provided\n");
goto err_exit_2;
}
value = simple_strtoul(str, &endptr, 0);
if (value > 0xFF) {
MHL_TX_DBG_ERR(dev_context, "Invalid scratch pad data detected\n");
goto err_exit_2;
}
data[idx] = value;
}
} else {
idx = 0;
}
if ((offset + length) > SCRATCH_PAD_SIZE) {
MHL_TX_DBG_ERR(dev_context, "Invalid offset/length combination entered");
goto err_exit_2;
}
dev_context->spad_offset = offset;
dev_context->spad_xfer_length = length;
if (idx == 0) {
MHL_TX_DBG_INFO(dev_context, "No data specified, storing offset "\
"and length for subsequent scratch pad read\n");
goto err_exit_2;
}
if (down_interruptible(&dev_context->isr_lock))
return -ERESTARTSYS;
if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
status = -ENODEV;
goto err_exit_1;
}
/*
* Make sure there is an MHL connection and that the requested
* data transfer parameters don't exceed the address space of
* the scratch pad. NOTE: The address space reserved for the
* Scratch Pad registers is 64 bytes but sources and sink devices
* are only required to implement the 1st 16 bytes.
*/
if (!(dev_context->mhl_flags & MHL_STATE_FLAG_CONNECTED) ||
(length < ADOPTER_ID_SIZE) ||
(offset > (SCRATCH_PAD_SIZE - ADOPTER_ID_SIZE)) ||
(offset + length > SCRATCH_PAD_SIZE)) {
status = -EINVAL;
goto err_exit_1;
}
dev_context->mhl_flags |= MHL_STATE_FLAG_SPAD_SENT;
dev_context->spad_send_status = 0;
scratch_pad_status = si_mhl_tx_request_write_burst(dev_context, offset, length, data);
switch (scratch_pad_status) {
case SCRATCHPAD_SUCCESS:
/* On success return the number of bytes written to this file */
status = count;
break;
case SCRATCHPAD_BUSY:
status = -EAGAIN;
break;
default:
status = -EFAULT;
break;
}
err_exit_1:
up(&dev_context->isr_lock);
err_exit_2:
return status;
}
/*
* show_scratch_pad() - Handle read request to the spad attribute file.
*
* Reads from this file return one or more scratch pad register values
* in hexadecimal string format. The registers returned are specified
* by the offset and length values previously written to this file.
*
* The return value is the number characters written to buf, or EAGAIN
* if the driver is busy and cannot service the read request immediately.
* If EAGAIN is returned the caller should wait a little and retry the
* read.
*
* The format of the string returned in buf is:
* "offset:<offset> length:<lenvalue> data:<datavalues>
* where: <offset> is the last scratch pad register offset
* written to this file
* <lenvalue> is the last scratch pad register transfer length
* written to this file
* <datavalue> space separated list of <lenvalue> scratch pad
* register values in OxXX format
*/
ssize_t show_scratch_pad(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
u8 data[MAX_SCRATCH_PAD_TRANSFER_SIZE];
u8 idx;
enum scratch_pad_status scratch_pad_status;
int status = -EINVAL;
MHL_TX_DBG_INFO(dev_context, "called\n");
if (down_interruptible(&dev_context->isr_lock))
return -ERESTARTSYS;
if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
status = -ENODEV;
goto err_exit;
}
if (dev_context->mhl_flags & MHL_STATE_FLAG_CONNECTED) {
scratch_pad_status = si_get_scratch_pad_vector(dev_context,
dev_context->spad_offset,
dev_context->spad_xfer_length,
data);
switch (scratch_pad_status) {
case SCRATCHPAD_SUCCESS:
status = scnprintf(buf, PAGE_SIZE, "offset:0x%02x " \
"length:0x%02x data:",
dev_context->spad_offset,
dev_context->spad_xfer_length);
for (idx = 0; idx < dev_context->spad_xfer_length; idx++) {
status += scnprintf(&buf[status], PAGE_SIZE, "0x%02x ", data[idx]);
}
break;
case SCRATCHPAD_BUSY:
status = -EAGAIN;
break;
default:
status = -EFAULT;
break;
}
}
err_exit:
up(&dev_context->isr_lock);
return status;
}
/*
* send_debug() - Handle write request to the debug attribute file.
*
* This file is used to either perform a write to registers of the transmitter
* or to set the address, offset and byte count for a subsequent from the
* register(s) of the transmitter.
*
* The format of the string in buf must be:
* address=<pageaddr> offset=<offset_value> length=<Length_value> \
* data=data_byte_0 ... data_byte_length-1
* where: <pageaddr> specifies the I2C register page of the register(s)
* to be written/read
* <offset_value> specifies the starting register offset within the
* register page to begin writing/reading
* <length_value> number registers to be written/read
* data_byte space separated list of <length_value> data bytes
* to be written. If no data bytes are present then
* the write to this file will only be used to set
* the page address, offset and length for a
* subsequent read from this file.
*/
ssize_t send_debug(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
unsigned long address = 0x100; /* initialize with invalid values */
unsigned long offset = 0x100;
unsigned long length = 0x100;
unsigned long value;
u8 data[MAX_DEBUG_TRANSFER_SIZE];
u8 idx;
char *str;
char *endptr;
int status = -EINVAL;
MHL_TX_DBG_INFO(dev_context, "received string: ""%s""\n", buf);
/*
* Parse the input string and extract the scratch pad register selection
* parameters
*/
str = strstr(buf, "address=");
if (str != NULL) {
address = simple_strtoul(str + 8, NULL, 0);
if (address > 0xFF) {
MHL_TX_DBG_ERR(dev_context, "Invalid page address: 0x%02lx specified\n", address);
goto err_exit_2;
}
} else {
MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find ""address"" parameter\n");
goto err_exit_2;
}
str = strstr(buf, "offset=");
if (str != NULL) {
offset = simple_strtoul(str + 7, NULL, 0);
if (offset > 0xFF) {
MHL_TX_DBG_ERR(dev_context, "Invalid page offset: 0x%02lx specified\n", offset);
goto err_exit_2;
}
} else {
MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find ""offset"" value\n");
goto err_exit_2;
}
str = strstr(buf, "length=");
if (str != NULL) {
length = simple_strtoul(str + 7, NULL, 0);
if (length > MAX_DEBUG_TRANSFER_SIZE) {
MHL_TX_DBG_ERR(dev_context, "Transfer size 0x%02lx is too large\n", length);
goto err_exit_2;
}
} else {
MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find ""length"" value\n");
goto err_exit_2;
}
str = strstr(buf, "data=");
if (str != NULL) {
str += 5;
endptr = str;
for(idx = 0; idx < length; idx++) {
endptr += strspn(endptr, white_space);
str = endptr;
if (*str == 0) {
MHL_TX_DBG_ERR(dev_context, "Too few data values provided\n");
goto err_exit_2;
}
value = simple_strtoul(str, &endptr, 0);
if (value > 0xFF) {
MHL_TX_DBG_ERR(dev_context, "Invalid register data value detected\n");
goto err_exit_2;
}
data[idx] = value;
}
} else {
idx = 0;
}
if ((offset + length) > 0x100) {
MHL_TX_DBG_ERR(dev_context
, "Invalid offset/length combination entered 0x%02x/0x%02x"
, offset, length);
goto err_exit_2;
}
dev_context->debug_i2c_address = address;
dev_context->debug_i2c_offset = offset;
dev_context->debug_i2c_xfer_length = length;
if (idx == 0) {
MHL_TX_DBG_INFO(dev_context, "No data specified, storing address "\
"offset and length for subsequent debug read\n");
goto err_exit_2;
}
if (down_interruptible(&dev_context->isr_lock))
return -ERESTARTSYS;
if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
status = -ENODEV;
goto err_exit_1;
}
status = dev_context->drv_info->mhl_device_dbg_i2c_reg_xfer(
&dev_context->drv_context,
address, offset, length,
DEBUG_I2C_WRITE, data);
if (status == 0)
status = count;
err_exit_1:
up(&dev_context->isr_lock);
err_exit_2:
return status;
}
/*
* show_debug() - Handle read request to the debug attribute file.
*
* Reads from this file return one or more transmitter register values in
* hexadecimal string format. The registers returned are specified by the
* address, offset and length values previously written to this file.
*
* The return value is the number characters written to buf, or an error
* code if the I2C read fails.
*
* The format of the string returned in buf is:
* "address:<pageaddr> offset:<offset> length:<lenvalue> data:<datavalues>
* where: <pageaddr> is the last I2C register page address written
* to this file
* <offset> is the last register offset written to this file
* <lenvalue> is the last register transfer length written
* to this file
* <datavalue> space separated list of <lenvalue> register
* values in OxXX format
*/
ssize_t show_debug(struct device *dev, struct device_attribute *attr, char *buf)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
u8 data[MAX_DEBUG_TRANSFER_SIZE];
u8 idx;
int status = -EINVAL;
MHL_TX_DBG_INFO(dev_context, "called\n");
if (down_interruptible(&dev_context->isr_lock))
return -ERESTARTSYS;
if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
status = -ENODEV;
goto no_dev;
}
status = dev_context->drv_info->mhl_device_dbg_i2c_reg_xfer(
&dev_context->drv_context,
dev_context->debug_i2c_address,
dev_context->debug_i2c_offset,
dev_context->debug_i2c_xfer_length,
DEBUG_I2C_READ, data);
no_dev:
up(&dev_context->isr_lock);
if (status == 0) {
status = scnprintf(buf, PAGE_SIZE, "address:0x%02x offset:0x%02x " \
"length:0x%02x data:",
dev_context->debug_i2c_address,
dev_context->debug_i2c_offset,
dev_context->debug_i2c_xfer_length);
for (idx = 0; idx < dev_context->debug_i2c_xfer_length; idx++) {
status += scnprintf(&buf[status], PAGE_SIZE, "0x%02x ", data[idx]);
}
}
return status;
}
//( begin trace_level API
/*
* show_trace_level() - Handle read request to the trace_level attribute file.
*
* The return value is the number characters written to buf, or EAGAIN
* if the driver is busy and cannot service the read request immediately.
* If EAGAIN is returned the caller should wait a little and retry the
* read.
*/
ssize_t get_trace_level(struct device *dev, struct device_attribute *attr, char *buf)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
int status = -EINVAL;
extern int debug_msgs;
if (down_interruptible(&dev_context->isr_lock)){
MHL_TX_DBG_ERR(dev_context,"-ERESTARTSYS\n");
return -ERESTARTSYS;
}
if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
MHL_TX_DBG_ERR(dev_context,"-ENODEV\n");
status = -ENODEV;
goto err_exit;
}
status = scnprintf(buf, PAGE_SIZE, "level=%d",debug_msgs );
MHL_TX_DBG_INFO(dev_context,"buf:%c%s%c\n",'"',buf,'"');
err_exit:
up(&dev_context->isr_lock);
return status;
}
/*
* set_trace_level() - Handle write request to the trace_level attribute file.
*
* Writes to this file cause a RAP message with the specified action code
* to be sent to the downstream device.
*/
ssize_t set_trace_level(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct mhl_dev_context *dev_context = dev_get_drvdata(dev);
int status;
char *str;
const char *key="level=";
extern int debug_msgs;
/* Assume success */
status = count;
MHL_TX_DBG_INFO(dev_context, "received string: %s\n", buf);
if (down_interruptible(&dev_context->isr_lock))
return -ERESTARTSYS;
if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN) {
status = -ENODEV;
goto err_exit;
}
str = strstr(buf, key);
if (str != NULL) {
debug_msgs = simple_strtol(str + strlen(key), NULL, 0);
} else {
MHL_TX_DBG_ERR(dev_context, "Invalid string format, can't find \"%s\" parameter\n",key);
}
err_exit:
up(&dev_context->isr_lock);
return status;
}
//) end trace_level API
#define MAX_EVENT_STRING_LEN 128
/*
* Handler for event notifications from the MhlTx layer.
*
*/
#define MTK_MHL_NOTIFY_SYS
void mhl_event_notify(struct mhl_dev_context *dev_context, u32 event, u32 event_param, void *data)
{
char event_string[MAX_EVENT_STRING_LEN];
char *envp[] = {event_string, NULL};
char *buf;
u32 length;
u32 count;
int idx;
MHL_TX_DBG_INFO(dev_context, "called, event: 0x%08x "\
"event_param: 0x%08x\n", event, event_param);
/*
* Save the info on the most recent event. This is done to support the
* SII_MHL_GET_MHL_TX_EVENT IOCTL. If at some point in the future the
* driver's IOCTL interface is abandoned in favor of using sysfs attributes
* this can be removed.
*/
dev_context->pending_event = event;
dev_context->pending_event_data = event_param;
switch(event) {
case MHL_TX_EVENT_SMB_DATA:
case MHL_TX_EVENT_HPD_CLEAR:
case MHL_TX_EVENT_HPD_GOT:
case MHL_TX_EVENT_DEV_CAP_UPDATE:
case MHL_TX_EVENT_EDID_UPDATE:
case MHL_TX_EVENT_EDID_DONE:
Notify_AP_MHL_TX_Event(event, event_param, data);
break;
case MHL_TX_EVENT_CONNECTION:
dev_context->mhl_flags |= MHL_STATE_FLAG_CONNECTED;
#ifdef MEDIA_DATA_TUNNEL_SUPPORT
// mdt_init(dev_context);
#endif
#ifdef RCP_INPUTDEV_SUPPORT
//init_rcp_input_dev(dev_context);
#endif
#ifndef MTK_MHL_NOTIFY_SYS
sysfs_notify(&dev_context->mhl_dev->kobj, NULL,
__stringify(SYS_ATTR_NAME_CONN));
strncpy(event_string, "MHLEVENT=connected", MAX_EVENT_STRING_LEN);
kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
#else
#endif
Notify_AP_MHL_TX_Event(event, event_param, data);
break;
case MHL_TX_EVENT_DISCONNECTION:
dev_context->mhl_flags = 0;
dev_context->rcp_key_code = 0;
dev_context->rcp_err_code = 0;
dev_context->rcp_send_status = 0;
dev_context->ucp_key_code = 0;
dev_context->ucp_err_code = 0;
dev_context->spad_send_status = 0;
dev_context->misc_flags.flags.have_complete_devcap = false;//SET the para to default;
#ifdef MEDIA_DATA_TUNNEL_SUPPORT
// mdt_destroy(dev_context);
#endif
#ifdef RCP_INPUTDEV_SUPPORT
//destroy_rcp_input_dev(dev_context);
#endif
#ifndef MTK_MHL_NOTIFY_SYS
sysfs_notify(&dev_context->mhl_dev->kobj, NULL,
__stringify(SYS_ATTR_NAME_CONN));
strncpy(event_string, "MHLEVENT=disconnected", MAX_EVENT_STRING_LEN);
kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
#else
#endif
Notify_AP_MHL_TX_Event(event, event_param, data);
break;
case MHL_TX_EVENT_RCP_RECEIVED:
#ifdef RCP_INPUTDEV_SUPPORT
if (0 == generate_rcp_input_event(dev_context, (uint8_t)event_param))
si_mhl_tx_rcpk_send(dev_context, (uint8_t)event_param);
else
{
si_mhl_tx_rcpe_send(dev_context, MHL_RCPE_STATUS_INEEFECTIVE_KEY_CODE);
si_mhl_tx_rcpk_send(dev_context, (uint8_t)event_param);
}
#else
dev_context->mhl_flags &= ~MHL_STATE_FLAG_RCP_SENT;
dev_context->mhl_flags |= MHL_STATE_FLAG_RCP_RECEIVED;
dev_context->rcp_key_code = event_param;
#ifndef MTK_MHL_NOTIFY_SYS
sysfs_notify(&dev_context->mhl_dev->kobj, NULL, __stringify(SYS_ATTR_NAME_RCP));
snprintf(event_string, MAX_EVENT_STRING_LEN, "MHLEVENT=received_RCP key code=0x%02x", event_param);
kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
#else
#endif
break;
case MHL_TX_EVENT_RCPK_RECEIVED:
if ((dev_context->mhl_flags & MHL_STATE_FLAG_RCP_SENT)
&& (dev_context->rcp_key_code == event_param)) {
dev_context->rcp_err_code = 0;
dev_context->mhl_flags |= MHL_STATE_FLAG_RCP_ACK;
MHL_TX_DBG_INFO(dev_context, "Generating RCPK received event, keycode: 0x%02x\n", event_param);
#ifndef MTK_MHL_NOTIFY_SYS
sysfs_notify(&dev_context->mhl_dev->kobj, NULL, __stringify(SYS_ATTR_NAME_RCPK));
snprintf(event_string, MAX_EVENT_STRING_LEN, "MHLEVENT=received_RCPK key code=0x%02x", event_param);
kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
#else
#endif
} else {
MHL_TX_DBG_ERR(dev_context, "Ignoring unexpected RCPK received event, keycode: 0x%02x\n", event_param);
}
break;
case MHL_TX_EVENT_RCPE_RECEIVED:
if (dev_context->mhl_flags & MHL_STATE_FLAG_RCP_SENT) {
dev_context->rcp_err_code = event_param;
dev_context->mhl_flags |= MHL_STATE_FLAG_RCP_NAK;
MHL_TX_DBG_INFO(dev_context, "Generating RCPE received event, error code: 0x%02x\n", event_param);
#ifndef MTK_MHL_NOTIFY_SYS
sysfs_notify(&dev_context->mhl_dev->kobj, NULL, __stringify(SYS_ATTR_NAME_RCPK));
snprintf(event_string, MAX_EVENT_STRING_LEN, "MHLEVENT=received_RCPE error code=0x%02x", event_param);
kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
#else
#endif
} else {
MHL_TX_DBG_ERR(dev_context, "Ignoring unexpected RCPE received event, error code: 0x%02x\n", event_param);
}
break;
#endif /* #ifdef RCP_INPUTDEV_SUPPORT */
case MHL_TX_EVENT_UCP_RECEIVED:
dev_context->mhl_flags &= ~MHL_STATE_FLAG_UCP_SENT;
dev_context->mhl_flags |= MHL_STATE_FLAG_UCP_RECEIVED;
dev_context->ucp_key_code = event_param;
#ifndef MTK_MHL_NOTIFY_SYS
sysfs_notify(&dev_context->mhl_dev->kobj, NULL, __stringify(SYS_ATTR_NAME_UCP));
snprintf(event_string, MAX_EVENT_STRING_LEN, "MHLEVENT=received_UCP key code=0x%02x", event_param);
kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
#else
#endif
break;
case MHL_TX_EVENT_UCPK_RECEIVED:
if ((dev_context->mhl_flags & MHL_STATE_FLAG_UCP_SENT)
&& (dev_context->ucp_key_code == event_param)) {
dev_context->mhl_flags |= MHL_STATE_FLAG_UCP_ACK;
MHL_TX_DBG_INFO(dev_context, "Generating UCPK received event, keycode: 0x%02x\n", event_param);
#ifndef MTK_MHL_NOTIFY_SYS
sysfs_notify(&dev_context->mhl_dev->kobj, NULL, __stringify(SYS_ATTR_NAME_UCPK));
snprintf(event_string, MAX_EVENT_STRING_LEN, "MHLEVENT=received_UCPK key code=0x%02x", event_param);
kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
#else
#endif
} else {
MHL_TX_DBG_ERR(dev_context, "Ignoring unexpected UCPK received event, keycode: 0x%02x\n", event_param);
}
break;
case MHL_TX_EVENT_UCPE_RECEIVED:
if (dev_context->mhl_flags & MHL_STATE_FLAG_UCP_SENT) {
dev_context->ucp_err_code = event_param;
dev_context->mhl_flags |= MHL_STATE_FLAG_UCP_NAK;
MHL_TX_DBG_INFO(dev_context, "Generating UCPE received event, error code: 0x%02x\n", event_param);
#ifndef MTK_MHL_NOTIFY_SYS
sysfs_notify(&dev_context->mhl_dev->kobj, NULL, __stringify(SYS_ATTR_NAME_UCPK));
snprintf(event_string, MAX_EVENT_STRING_LEN, "MHLEVENT=received_UCPE error code=0x%02x", event_param);
kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
#else
#endif
} else {
MHL_TX_DBG_ERR(dev_context, "Ignoring unexpected UCPE received event, error code: 0x%02x\n", event_param);
}
break;
case MHL_TX_EVENT_SPAD_RECEIVED:
length = event_param;
buf = data;
#ifndef MTK_MHL_NOTIFY_SYS
sysfs_notify(&dev_context->mhl_dev->kobj, NULL, __stringify(SYS_ATTR_NAME_SPAD));
idx = snprintf(event_string, MAX_EVENT_STRING_LEN, "MHLEVENT=SPAD_CHG length=0x%02x data=", length);
count = 0;
while (idx < MAX_EVENT_STRING_LEN) {
if (count >= length)
break;
idx += snprintf(&event_string[idx], MAX_EVENT_STRING_LEN - idx, "0x%02x ", buf[count]);
count++;
}
if (idx < MAX_EVENT_STRING_LEN) {
kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
} else {
MHL_TX_DBG_ERR(dev_context, "Buffer too small to contain scratch pad data!\n");
}
#else
#endif
break;
case MHL_TX_EVENT_POW_BIT_CHG:
MHL_TX_DBG_INFO(dev_context, "Generating VBUS power bit change event, POW bit is %s\n", event_param? "ON" : "OFF");
#ifndef MTK_MHL_NOTIFY_SYS
snprintf(event_string, MAX_EVENT_STRING_LEN, "MHLEVENT=MHL VBUS power %s", event_param? "ON" : "OFF");
kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
#else
#endif
break;
case MHL_TX_EVENT_RAP_RECEIVED:
MHL_TX_DBG_INFO(dev_context, "Generating RAP received event, action code: 0x%02x\n", event_param);
#ifndef MTK_MHL_NOTIFY_SYS
sysfs_notify(&dev_context->mhl_dev->kobj, NULL, __stringify(SYS_ATTR_NAME_RAP));
snprintf(event_string, MAX_EVENT_STRING_LEN, "MHLEVENT=received_RAP action code=0x%02x", event_param);
kobject_uevent_env(&dev_context->mhl_dev->kobj, KOBJ_CHANGE, envp);
#else
#endif
break;
default:
MHL_TX_DBG_ERR(dev_context, "called with unrecognized event code!\n");
}
}
/*
* File operations supported by the MHL driver
*/
static const struct file_operations mhl_fops = {
.owner = THIS_MODULE
};
/*
* Sysfs attribute files supported by this driver.
*/
struct device_attribute driver_attribs[] = {
__ATTR(SYS_ATTR_NAME_CONN ,0444,show_connection_state, NULL),
#ifndef RCP_INPUTDEV_SUPPORT
__ATTR(SYS_ATTR_NAME_RCP ,0444,show_rcp , send_rcp),
__ATTR(SYS_ATTR_NAME_RCPK ,0444,show_rcp_ack , send_rcp_ack),
#endif
__ATTR(SYS_ATTR_NAME_RAP ,0444,show_rap , send_rap),
__ATTR(SYS_ATTR_NAME_RAP_STATUS ,0444,show_rap_status , set_rap_status),
__ATTR(SYS_ATTR_NAME_DEVCAP ,0444,show_dev_cap , select_dev_cap),
__ATTR(SYS_ATTR_NAME_UCP ,0444,show_ucp , send_ucp),
__ATTR(SYS_ATTR_NAME_UCPK ,0444,show_ucp_ack , send_ucp_ack),
__ATTR(SYS_ATTR_NAME_SPAD ,0444,show_scratch_pad , send_scratch_pad),
__ATTR(SYS_ATTR_NAME_DEBUG ,0444,show_debug , send_debug),
__ATTR(SYS_ATTR_NAME_TRACE_LEVEL ,0444,get_trace_level , set_trace_level),
__ATTR_NULL
};
static void mhl8338_irq_handler(void)
{
atomic_set(&mhl_irq_event, 1);
wake_up_interruptible(&mhl_irq_wq);
//mt65xx_eint_unmask(CUST_EINT_HDMI_HPD_NUM);
}
static void mhl_irq_handler(int irq, void *data);
static int irq_cnt = 0;
static int mhl_irq_kthread(void *data)
{
int i=0;
struct sched_param param = { .sched_priority = RTPM_PRIO_SCRN_UPDATE };
sched_setscheduler(current, SCHED_RR, ¶m);
for( ;; ) {
set_current_state(TASK_INTERRUPTIBLE);
wait_event_interruptible(mhl_irq_wq, atomic_read(&mhl_irq_event));
set_current_state(TASK_RUNNING);
irq_cnt++;
//hdmi_update_impl();
atomic_set(&mhl_irq_event, 0);
//for( i=0;i<30; i++)
mhl_irq_handler(0, si_dev_context);
if (kthread_should_stop())
break;
#ifdef CUST_EINT_MHL_NUM
mt_eint_unmask(CUST_EINT_MHL_NUM);
#endif
}
return 0;
}
/*
* Interrupt handler for MHL transmitter interrupts.
*
* @irq: The number of the asserted IRQ line that caused
* this handler to be called.
* @data: Data pointer passed when the interrupt was enabled,
* which in this case is a pointer to an mhl_dev_context struct.
*
* Always returns IRQ_HANDLED.
*/
static void mhl_irq_handler(int irq, void *data)
{
struct mhl_dev_context *dev_context = (struct mhl_dev_context *)data;
if (!down_interruptible(&dev_context->isr_lock)) {
if (dev_context->dev_flags & DEV_FLAG_SHUTDOWN)
goto irq_done;
if (dev_context->dev_flags & DEV_FLAG_COMM_MODE)
goto irq_done;
memset(&dev_context->intr_info, 0, sizeof(*(&dev_context->intr_info)));
dev_context->intr_info.edid_parser_context = dev_context->edid_parser_context;
dev_context->drv_info->mhl_device_isr((struct drv_hw_context *)
(&dev_context->drv_context),
&dev_context->intr_info);
/* Now post process events detected by the interrupt handler */
if(dev_context->intr_info.flags & DRV_INTR_FLAG_DISCONNECT) {
dev_context->misc_flags.flags.rap_content_on = false;
dev_context->misc_flags.flags.mhl_rsen = false;
dev_context->mhl_connection_event = true;
dev_context->mhl_connected = MHL_TX_EVENT_DISCONNECTION;
si_mhl_tx_process_events(dev_context);
} else {
if (dev_context->intr_info.flags & DRV_INTR_FLAG_CONNECT) {
dev_context->misc_flags.flags.rap_content_on = true;
dev_context->rap_sub_command = MHL_RAP_CONTENT_ON;
dev_context->misc_flags.flags.mhl_rsen = true;
dev_context->mhl_connection_event = true;
dev_context->mhl_connected = MHL_TX_EVENT_CONNECTION;
si_mhl_tx_process_events(dev_context);
}
if (dev_context->intr_info.flags & DRV_INTR_FLAG_CBUS_ABORT)
process_cbus_abort(dev_context);
if (dev_context->intr_info.flags & DRV_INTR_FLAG_WRITE_BURST)
si_mhl_tx_process_write_burst_data(dev_context);
if (dev_context->intr_info.flags & DRV_INTR_FLAG_SET_INT)
si_mhl_tx_got_mhl_intr(dev_context,
dev_context->intr_info.int_msg[0],
dev_context->intr_info.int_msg[1]);
if (dev_context->intr_info.flags & DRV_INTR_FLAG_MSC_DONE)
si_mhl_tx_msc_command_done(dev_context,
dev_context->intr_info.msc_done_data);
if (dev_context->intr_info.flags & DRV_INTR_FLAG_HPD_CHANGE)
si_mhl_tx_notify_downstream_hpd_change(dev_context,
dev_context->intr_info.hpd_status);
if (dev_context->intr_info.flags & DRV_INTR_FLAG_WRITE_STAT)
si_mhl_tx_got_mhl_status(dev_context,
dev_context->intr_info.write_stat[0],
dev_context->intr_info.write_stat[1]);
if (dev_context->intr_info.flags & DRV_INTR_FLAG_MSC_RECVD) {
dev_context->msc_msg_arrived = true;
dev_context->msc_msg_sub_command = dev_context->intr_info.msc_msg[0];
dev_context->msc_msg_data = dev_context->intr_info.msc_msg[1];
si_mhl_tx_process_events(dev_context);
}
}
/*
* Check to see if we can send any messages that may have
* been queued up as the result of interrupt processing.
*/
si_mhl_tx_drive_states(dev_context);
// if(sii_mhl_connected != dev_context->mhl_connected)
// pr_err("MHL connected status %d -> %d\n",sii_mhl_connected, dev_context->mhl_connected);
irq_done:
up(&dev_context->isr_lock);
}
}
/* APIs provided by the MHL layer to the lower level driver */
int mhl_tx_init(struct mhl_drv_info const *drv_info, struct i2c_client *client)
{
///struct mhl_dev_context *dev_context;
int ret,dummy;
if (drv_info == NULL || client == NULL) {
pr_err("Null parameter passed to %s\n",__func__);
return -EINVAL;
}
init_waitqueue_head(&mhl_irq_wq);
mhl_irq_task = kthread_create(mhl_irq_kthread, NULL, "mhl_irq_kthread");
wake_up_process(mhl_irq_task);
#ifdef CONFIG_MTK_SMARTBOOK_SUPPORT
init_waitqueue_head(&smartbook_wq);
smartbook_task = kthread_create(smartbook_kthread, NULL, "smartbook_kthread");
wake_up_process(smartbook_task);
#endif
si_dev_context = kzalloc(sizeof(*si_dev_context) + drv_info->drv_context_size, GFP_KERNEL);
if (!si_dev_context) {
dev_err(&client->dev, "failed to allocate driver data\n");
return -ENOMEM;
}
si_dev_context->signature = MHL_DEV_CONTEXT_SIGNATURE;
si_dev_context->drv_info = drv_info;
si_dev_context->client = client;
sema_init(&si_dev_context->isr_lock, 1);
INIT_LIST_HEAD(&si_dev_context->timer_list);
si_dev_context->timer_work_queue = create_workqueue(MHL_DRIVER_NAME);
if (si_dev_context->timer_work_queue == NULL) {
ret = -ENOMEM;
goto free_mem;
}
if (mhl_class == NULL) {
mhl_class = class_create(THIS_MODULE, "mhl");
if(IS_ERR(mhl_class)) {
ret = PTR_ERR(mhl_class);
pr_info("class_create failed %d\n", ret);
goto err_exit;
}
mhl_class->dev_attrs = driver_attribs;
ret = alloc_chrdev_region(&dev_num,
0, MHL_DRIVER_MINOR_MAX,
MHL_DRIVER_NAME);
if (ret) {
pr_info("register_chrdev %s failed, error code: %d\n", MHL_DRIVER_NAME, ret);
goto free_class;
}
cdev_init(&si_dev_context->mhl_cdev, &mhl_fops);
si_dev_context->mhl_cdev.owner = THIS_MODULE;
ret = cdev_add(&si_dev_context->mhl_cdev, MINOR(dev_num), MHL_DRIVER_MINOR_MAX);
if (ret) {
pr_info("cdev_add %s failed %d\n", MHL_DRIVER_NAME, ret);
goto free_chrdev;
}
}
si_dev_context->mhl_dev = device_create(mhl_class, &si_dev_context->client->dev,
dev_num, si_dev_context,
"%s", MHL_DEVICE_NAME);
if (IS_ERR(si_dev_context->mhl_dev)) {
ret = PTR_ERR(si_dev_context->mhl_dev);
pr_info("device_create failed %s %d\n", MHL_DEVICE_NAME, ret);
goto free_cdev;
}
#ifdef CUST_EINT_MHL_NUM
mt_eint_registration(CUST_EINT_MHL_NUM, CUST_EINT_MHL_TYPE, &mhl8338_irq_handler, 0);
mt_eint_mask(CUST_EINT_MHL_NUM);
#else
printk("%s,%d Error: CUST_EINT_MHL_NUM is not defined\n", __func__, __LINE__);
#endif
/* Initialize the MHL transmitter hardware. */
ret = down_interruptible(&si_dev_context->isr_lock);
if (ret) {
dev_err(&client->dev, "failed to acquire ISR semaphore, status: %d\n", ret);
goto free_irq_handler;
}
i2c_set_clientdata(client, si_dev_context);
/* initialize the PCA 950x GPIO expander, if present */
//ret = gpio_expander_init(dev_context);
//if (ret < 0) {
// dev_err(&client->dev,"failed to initialize GPIO expander, status: %d\n",ret);
// goto free_irq_handler;
//}
/* Initialize EDID parser module */
si_dev_context->edid_parser_context = si_edid_create_context(si_dev_context,&si_dev_context->drv_context);
ret = si_mhl_tx_initialize(si_dev_context, true);
up(&si_dev_context->isr_lock);
#ifdef RCP_INPUTDEV_SUPPORT
init_rcp_input_dev(si_dev_context);
#endif
MHL_TX_DBG_INFO(si_dev_context, "MHL transmitter successfully initialized\n");
return ret;
free_irq_handler:
i2c_set_clientdata(client, NULL);
dummy = down_interruptible(&si_dev_context->isr_lock);
if(si_dev_context->edid_parser_context)
si_edid_destroy_context(si_dev_context->edid_parser_context);
free_irq(si_dev_context->client->irq, si_dev_context);
free_device:
device_destroy(mhl_class, dev_num);
free_cdev:
cdev_del(&si_dev_context->mhl_cdev);
free_chrdev:
unregister_chrdev_region(dev_num, MHL_DRIVER_MINOR_MAX);
dev_num = 0;
free_class:
class_destroy(mhl_class);
err_exit:
destroy_workqueue(si_dev_context->timer_work_queue);
free_mem:
kfree(si_dev_context);
return ret;
}
int mhl_tx_remove(struct i2c_client *client)
{
struct mhl_dev_context *dev_context;
int ret = 0;
dev_context = i2c_get_clientdata(client);
if (dev_context != NULL){
MHL_TX_DBG_INFO(dev_context, "%x\n",dev_context);
ret = down_interruptible(&dev_context->isr_lock);
dev_context->dev_flags |= DEV_FLAG_SHUTDOWN;
ret = si_mhl_tx_shutdown(dev_context);
mhl_tx_destroy_timer_support(dev_context);
up(&dev_context->isr_lock);
free_irq(dev_context->client->irq, dev_context);
device_destroy(mhl_class, dev_num);
cdev_del(&dev_context->mhl_cdev);
unregister_chrdev_region(dev_num, MHL_DRIVER_MINOR_MAX);
dev_num = 0;
class_destroy(mhl_class);
mhl_class = NULL;
#ifdef MEDIA_DATA_TUNNEL_SUPPORT
// mdt_destroy(dev_context);
#endif
#ifdef RCP_INPUTDEV_SUPPORT
destroy_rcp_input_dev(dev_context);
#endif
si_edid_destroy_context(dev_context->edid_parser_context);
//mhl_tx_delete_timer(dev_context, dev_context->cbus_abort_timer); //TB added to clean up timer object
kfree(dev_context);
MHL_TX_DBG_INFO(dev_context, "%x\n",dev_context);
}
return ret;
}
static void mhl_tx_destroy_timer_support(struct mhl_dev_context *dev_context)
{
struct timer_obj *mhl_timer;
/*
* Make sure all outstanding timer objects are canceled and the
* memory allocated for them is freed.
*/
while(!list_empty(&dev_context->timer_list)) {
mhl_timer = list_first_entry(&dev_context->timer_list, struct timer_obj, list_link);
hrtimer_cancel(&mhl_timer->hr_timer);
list_del(&mhl_timer->list_link);
kfree(mhl_timer);
}
destroy_workqueue(dev_context->timer_work_queue);
dev_context->timer_work_queue = NULL;
}
static void mhl_tx_timer_work_handler(struct work_struct *work)
{
struct timer_obj *mhl_timer;
mhl_timer = container_of(work, struct timer_obj, work_item);
mhl_timer->flags |= TIMER_OBJ_FLAG_WORK_IP;
if (!down_interruptible(&mhl_timer->dev_context->isr_lock)) {
mhl_timer->timer_callback_handler(mhl_timer->callback_param);
up(&mhl_timer->dev_context->isr_lock);
}
mhl_timer->flags &= ~TIMER_OBJ_FLAG_WORK_IP;
if(mhl_timer->flags & TIMER_OBJ_FLAG_DEL_REQ) {
/*
* Deletion of this timer was requested during the execution of
* the callback handler so go ahead and delete it now.
*/
kfree(mhl_timer);
}
}
static enum hrtimer_restart mhl_tx_timer_handler(struct hrtimer *timer)
{
struct timer_obj *mhl_timer;
mhl_timer = container_of(timer, struct timer_obj, hr_timer);
queue_work(mhl_timer->dev_context->timer_work_queue, &mhl_timer->work_item);
return HRTIMER_NORESTART;
}
static int is_timer_handle_valid(struct mhl_dev_context *dev_context, void *timer_handle)
{
struct timer_obj *timer;
list_for_each_entry(timer, &dev_context->timer_list, list_link) {
if (timer == timer_handle)
break;
}
if(timer != timer_handle) {
MHL_TX_DBG_ERR(dev_context, "Invalid timer handle %p received\n", timer_handle);
return -EINVAL;
}
return 0;
}
int mhl_tx_create_timer(void *context,
void (*callback_handler)(void *callback_param),
void *callback_param,
void **timer_handle)
{
struct mhl_dev_context *dev_context;
struct timer_obj *new_timer;
dev_context = get_mhl_device_context(context);
if (callback_handler == NULL)
return -EINVAL;
if (dev_context->timer_work_queue == NULL)
return -ENOMEM;
new_timer = kmalloc(sizeof(*new_timer), GFP_KERNEL);
if (new_timer == NULL)
return -ENOMEM;
new_timer->timer_callback_handler = callback_handler;
new_timer->callback_param = callback_param;
new_timer->flags = 0;
new_timer->dev_context = dev_context;
INIT_WORK(&new_timer->work_item, mhl_tx_timer_work_handler);
list_add(&new_timer->list_link, &dev_context->timer_list);
hrtimer_init(&new_timer->hr_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
new_timer->hr_timer.function = mhl_tx_timer_handler;
*timer_handle = new_timer;
return 0;
}
int mhl_tx_delete_timer(void *context, void *timer_handle)
{
struct mhl_dev_context *dev_context;
struct timer_obj *timer;
int status;
dev_context = get_mhl_device_context(context);
status = is_timer_handle_valid(dev_context, timer_handle);
if (status == 0) {
timer = timer_handle;
list_del(&timer->list_link);
hrtimer_cancel(&timer->hr_timer);
if(timer->flags & TIMER_OBJ_FLAG_WORK_IP) {
/*
* Request to delete timer object came from within the timer's
* callback handler. If we were to proceed with the timer deletion
* we would deadlock at cancel_work_sync(). So instead just flag
* that the user wants the timer deleted. Later when the timer
* callback completes the timer's work handler will complete the
* process of deleting this timer.
*/
timer->flags |= TIMER_OBJ_FLAG_DEL_REQ;
} else {
cancel_work_sync(&timer->work_item);
kfree(timer);
}
}
return status;
}
int mhl_tx_start_timer(void *context, void *timer_handle, uint32_t time_msec)
{
struct mhl_dev_context *dev_context;
struct timer_obj *timer;
ktime_t timer_period;
int status;
dev_context = get_mhl_device_context(context);
status = is_timer_handle_valid(dev_context, timer_handle);
if (status == 0) {
timer = timer_handle;
timer_period = ktime_set(0, MSEC_TO_NSEC(time_msec));
hrtimer_start(&timer->hr_timer, timer_period, HRTIMER_MODE_REL);
}
return status;
}
int mhl_tx_stop_timer(void *context, void *timer_handle)
{
struct mhl_dev_context *dev_context;
struct timer_obj *timer;
int status;
dev_context = get_mhl_device_context(context);
status = is_timer_handle_valid(dev_context, timer_handle);
if (status == 0) {
timer = timer_handle;
hrtimer_cancel(&timer->hr_timer);
}
return status;
}
|