summaryrefslogtreecommitdiff
path: root/package/kernel/lantiq/ltq-hcd/src/ifxhcd.c
blob: be0a91d262270932b2b5cf1ea6ed3d62d5ced802 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
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
/*****************************************************************************
 **   FILE NAME       : ifxhcd.c
 **   PROJECT         : IFX USB sub-system V3
 **   MODULES         : IFX USB sub-system Host and Device driver
 **   SRC VERSION     : 3.2
 **   DATE            : 1/Jan/2011
 **   AUTHOR          : Chen, Howard
 **   DESCRIPTION     : This file contains the structures, constants, and
 **                     interfaces for the Host Contoller Driver (HCD).
 **
 **                     The Host Controller Driver (HCD) is responsible for
 **                     translating requests from the USB Driver into the
 **                     appropriate actions on the IFXUSB controller.
 **                     It isolates the USBD from the specifics of the
 **                     controller by providing an API to the USBD.
 **   FUNCTIONS       :
 **   COMPILER        : gcc
 **   REFERENCE       : Synopsys DWC-OTG Driver 2.7
 **   COPYRIGHT       :  Copyright (c) 2010
 **                      LANTIQ DEUTSCHLAND GMBH,
 **                      Am Campeon 3, 85579 Neubiberg, Germany
 **
 **    This program is free software; you can redistribute it and/or modify
 **    it under the terms of the GNU General Public License as published by
 **    the Free Software Foundation; either version 2 of the License, or
 **    (at your option) any later version.
 **
 **  Version Control Section  **
 **   $Author$
 **   $Date$
 **   $Revisions$
 **   $Log$       Revision history
 *****************************************************************************/

/*
 * This file contains code fragments from Synopsys HS OTG Linux Software Driver.
 * For this code the following notice is applicable:
 *
 * ==========================================================================
 *
 * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
 * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
 * otherwise expressly agreed to in writing between Synopsys and you.
 *
 * The Software IS NOT an item of Licensed Software or Licensed Product under
 * any End User Software License Agreement or Agreement for Licensed Product
 * with Synopsys or any supplement thereto. You are permitted to use and
 * redistribute this Software in source and binary forms, with or without
 * modification, provided that redistributions of source code must retain this
 * notice. You may not view, use, disclose, copy or distribute this file or
 * any information contained herein except pursuant to this license grant from
 * Synopsys. If you do not agree with this notice, including the disclaimer
 * below, then you are not authorized to use the Software.
 *
 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 * ========================================================================== */

/*!
  \file ifxhcd.c
  \ingroup IFXUSB_DRIVER_V3
  \brief This file contains the implementation of the HCD. In Linux,
   the HCD implements the hc_driver API.
*/

#include <linux/version.h>
#include "ifxusb_version.h"

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>

#include <linux/device.h>

#include <linux/errno.h>
#include <linux/list.h>
#include <linux/interrupt.h>
#include <linux/string.h>

#include <linux/dma-mapping.h>


#include "ifxusb_plat.h"
#include "ifxusb_regs.h"
#include "ifxusb_cif.h"
#include "ifxhcd.h"

#include <asm/irq.h>

#ifdef __DEBUG__
	static void dump_urb_info(struct urb *_urb, char* _fn_name);
#if 0
	static void dump_channel_info(ifxhcd_hcd_t *_ifxhcd,
	                              ifxhcd_epqh_t *_epqh);
#endif
#endif

static void ifxhcd_complete_urb_sub(ifxhcd_urbd_t *_urbd)
{
	ifxhcd_hcd_t *ifxhcd;
	struct urb *urb=NULL;

	if (!list_empty(&_urbd->ql))
	{
		list_del_init(&_urbd->ql);
		_urbd->epqh->urbd_count--;
	}
	else
		IFX_ERROR("%s: urb(%p) not connect to any epqh\n",
		          __func__,_urbd);

	ifxhcd=_urbd->epqh->ifxhcd;
	urb   =_urbd->urb;
	if(!urb)
		IFX_ERROR("%s: invalid urb\n",__func__);
	else if(urb->hcpriv)
	{
		if(urb->hcpriv != _urbd)
			IFX_ERROR("%s: invalid"
			          " urb(%p)->hcpriv(%p) != _urbd(%p)\n",
			          __func__,
			          urb,
			          urb->hcpriv,
			          _urbd);
		#if   defined(__UNALIGNED_BUF_ADJ__)
			if(_urbd->is_in &&
//			   _urbd->using_aligned_buf &&
			   _urbd->aligned_buf)
				memcpy(_urbd->xfer_buff,
				       _urbd->aligned_buf,
				       _urbd->xfer_len);
			if(_urbd->aligned_buf)
				ifxusb_free_buf_h(_urbd->aligned_buf);
		#endif
		urb->hcpriv = NULL;
		#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
			urb->status=_urbd->status;
			usb_hcd_giveback_urb(ifxhcd_to_syshcd(ifxhcd), urb);
		#else
			usb_hcd_giveback_urb(ifxhcd_to_syshcd(ifxhcd), urb,
			                     _urbd->status);
		#endif
	}
	kfree(_urbd);
}

#ifdef __STRICT_ORDER__
	static void ifxhcd_complete_urb_func(unsigned long data)
	{
		unsigned long             flags;
		ifxhcd_urbd_t *urbd;
		ifxhcd_epqh_t *epqh;
		struct list_head *item;

		int count=10;

		epqh=((ifxhcd_epqh_t *)data);

		while (!list_empty(&epqh->release_list) && count)
		{
			item = epqh->release_list.next;
			urbd = list_entry(item, ifxhcd_urbd_t, ql);
			if (!urbd)
				IFX_ERROR("%s: invalid urbd\n",__func__);
			else if (!urbd->epqh)
				IFX_ERROR("%s: invalid epqd\n",__func__);
			else
			{
				ifxhcd_epqh_t *epqh2;
				epqh2=urbd->epqh;
				local_irq_save(flags);
				LOCK_URBD_LIST(epqh2);
				ifxhcd_complete_urb_sub(urbd);
				UNLOCK_URBD_LIST(epqh2);
				local_irq_restore (flags);
			}
			count--;
		}
		if(!list_empty(&epqh->release_list))
			tasklet_schedule(&epqh->complete_urb_sub);
	}

	/*!
	 \brief Sets the final status of an URB and returns it to the device
	  driver. Any required cleanup of the URB is performed.
	 */
	void ifxhcd_complete_urb(ifxhcd_hcd_t *_ifxhcd,
	                         ifxhcd_urbd_t *_urbd,
	                         int _status)
	{
		unsigned long             flags;

		if(!_urbd)
		{
			IFX_ERROR("%s: invalid urbd\n",__func__);
			return;
		}
		if (!_urbd->epqh)
		{
			IFX_ERROR("%s: invalid epqh\n",__func__);
			return;
		}

		local_irq_save(flags);
		LOCK_URBD_LIST(_urbd->epqh);
		#ifdef __DEBUG__
			if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB))
			{
				IFX_PRINT("%s: ehqh %p _urbd %p, urb %p,"
				          " device %d, ep %d %s/%s, status=%d\n",
					  __func__,_urbd->epqh,
					  _urbd,_urbd->urb,
					  (_urbd->urb)?usb_pipedevice(_urbd->urb->pipe):-1,
					  (_urbd->urb)?usb_pipeendpoint(_urbd->urb->pipe):-1,
					  (_urbd->urb)?(usb_pipein(_urbd->urb->pipe) ? "IN" : "OUT"):"--",
					  (_urbd->is_in) ? "IN" : "OUT",
					   _status);
				if ((_urbd->urb)&& _urbd->epqh->ep_type == IFXUSB_EP_TYPE_ISOC)
				{
					int i;
					for (i = 0; i < _urbd->urb->number_of_packets; i++)
						IFX_PRINT("  ISO Desc %d status: %d\n", i, _urbd->urb->iso_frame_desc[i].status);
				}
			}
		#endif
		_urbd->status = _status;

		if(_urbd->phase!=URBD_FINISHING)
		{
			if(_urbd->phase!=URBD_DEQUEUEING && _urbd->phase!=URBD_COMPLETING)
				printk(KERN_INFO "Warning: %s() Strange URBD PHASE %d\n",__func__,_urbd->phase);
			if(_urbd->urb)
			{
				if(   _urbd->status == 0
				   && _urbd->phase==URBD_COMPLETING
				   && in_irq())
				{
					list_move_tail(&_urbd->ql,&_urbd->epqh->release_list);
					if(!_urbd->epqh->complete_urb_sub.func)
					{
						_urbd->epqh->complete_urb_sub.next = NULL;
						_urbd->epqh->complete_urb_sub.state = 0;
						atomic_set( &_urbd->epqh->complete_urb_sub.count, 0);
						_urbd->epqh->complete_urb_sub.func = ifxhcd_complete_urb_func;
						_urbd->epqh->complete_urb_sub.data = (unsigned long)_urbd->epqh;
					}
					tasklet_schedule(&_urbd->epqh->complete_urb_sub);
				}
				else
				{
					_urbd->phase=URBD_FINISHING;
					ifxhcd_complete_urb_sub(_urbd);
				}
				UNLOCK_URBD_LIST(_urbd->epqh);
			}
			else
			{
				UNLOCK_URBD_LIST(_urbd->epqh);
				kfree(_urbd);
			}
		}
		else
		{
			printk(KERN_INFO "Warning: %s() Double Completing \n",__func__);
			UNLOCK_URBD_LIST(_urbd->epqh);
		}
		
		local_irq_restore (flags);
	}
#else
	static void ifxhcd_complete_urb_func(unsigned long data)
	{
		unsigned long             flags;
		ifxhcd_urbd_t *urbd;

		urbd=((ifxhcd_urbd_t *)data);

	//	local_irq_save(flags);
		if (!urbd)
			IFX_ERROR("%s: invalid urbd\n",__func__);
		else if (!urbd->epqh)
			IFX_ERROR("%s: invalid epqd\n",__func__);
		else
		{
			local_irq_save(flags);
			LOCK_URBD_LIST(urbd->epqh);
			ifxhcd_complete_urb_sub(urbd);
			UNLOCK_URBD_LIST(urbd->epqh);
			local_irq_restore (flags);
		}
	//	local_irq_restore (flags);
	}


	/*!
	 \brief Sets the final status of an URB and returns it to the device driver. Any
	  required cleanup of the URB is performed.
	 */
	void ifxhcd_complete_urb(ifxhcd_hcd_t *_ifxhcd, ifxhcd_urbd_t *_urbd,  int _status)
	{
		unsigned long             flags;

		if(!_urbd)
		{
			IFX_ERROR("%s: invalid urbd\n",__func__);
			return;
		}
		if (!_urbd->epqh)
		{
			IFX_ERROR("%s: invalid epqh\n",__func__);
			return;
		}

		local_irq_save(flags);
		LOCK_URBD_LIST(_urbd->epqh);
		#ifdef __DEBUG__
			if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB))
			{
				IFX_PRINT("%s: ehqh %p _urbd %p, urb %p, device %d, ep %d %s/%s, status=%d\n",
					  __func__,_urbd->epqh, _urbd,_urbd->urb,
					  (_urbd->urb)?usb_pipedevice(_urbd->urb->pipe):-1,
					  (_urbd->urb)?usb_pipeendpoint(_urbd->urb->pipe):-1,
					  (_urbd->urb)?(usb_pipein(_urbd->urb->pipe) ? "IN" : "OUT"):"--",
					  (_urbd->is_in) ? "IN" : "OUT",
					   _status);
				if ((_urbd->urb)&& _urbd->epqh->ep_type == IFXUSB_EP_TYPE_ISOC)
				{
					int i;
					for (i = 0; i < _urbd->urb->number_of_packets; i++)
						IFX_PRINT("  ISO Desc %d status: %d\n", i, _urbd->urb->iso_frame_desc[i].status);
				}
			}
		#endif
		_urbd->status = _status;

		if(_urbd->phase!=URBD_FINISHING)
		{
			if(_urbd->phase!=URBD_DEQUEUEING && _urbd->phase!=URBD_COMPLETING)
				printk(KERN_INFO "Warning: %s() Strange URBD PHASE %d\n",__func__,_urbd->phase);
			if(_urbd->urb)
			{
				if(   _urbd->status == 0
				   && _urbd->phase==URBD_COMPLETING
				   && in_irq())
				{
					if(_urbd->complete_urb_sub.func)
						printk(KERN_INFO "Warning: %s() URBD Tasklet is on already\n",__func__);
					_urbd->phase=URBD_FINISHING;
					_urbd->complete_urb_sub.next = NULL;
					_urbd->complete_urb_sub.state = 0;
					atomic_set( &_urbd->complete_urb_sub.count, 0);
					_urbd->complete_urb_sub.func = ifxhcd_complete_urb_func;
					_urbd->complete_urb_sub.data = (unsigned long)_urbd;
					tasklet_schedule(&_urbd->complete_urb_sub);
				}
				else
				{
					_urbd->phase=URBD_FINISHING;
					ifxhcd_complete_urb_sub(_urbd);
				}
			}
			else
				kfree(_urbd);
		}
		else
			printk(KERN_INFO "Warning: %s() Double Completing \n",__func__);
		UNLOCK_URBD_LIST(_urbd->epqh);
		local_irq_restore (flags);
	}
#endif

/*!
 \brief Processes all the URBs in a single EPQHs. Completes them with
        status and frees the URBD.
 */
static
void kill_all_urbs_in_epqh(ifxhcd_hcd_t *_ifxhcd, ifxhcd_epqh_t *_epqh, int _status)
{
	struct list_head *item;
	struct list_head *next;
	ifxhcd_urbd_t    *urbd;

	if(!_epqh)
		return;

	IFX_DEBUGPL(DBG_HCDV, "%s %p\n",__func__,_epqh);
	LOCK_URBD_LIST(_epqh);
	list_for_each(item, &_epqh->urbd_list)
	{
		urbd = list_entry(item, ifxhcd_urbd_t, ql);
		if(   urbd->phase==URBD_IDLE
		   || urbd->phase==URBD_ACTIVE
//		   || urbd->phase==URBD_STARTING
		  )
			urbd->phase=URBD_DEQUEUEING;
	}
	list_for_each_safe(item, next, &_epqh->urbd_list)
	{
		urbd = list_entry(item, ifxhcd_urbd_t, ql);
		if(urbd->phase==URBD_DEQUEUEING)
		{
			urbd->urb->status = _status;
			urbd->phase = URBD_FINISHING;
			ifxhcd_complete_urb_sub(urbd);
		}
		else if(   urbd->phase==URBD_STARTED
		        || urbd->phase==URBD_STARTING
//		        || urbd->phase==URBD_ACTIVE
		       )
		{
			if(ifxhcd_hc_halt(&_ifxhcd->core_if, _epqh->hc, HC_XFER_URB_DEQUEUE))
			{
				urbd->urb->status = _status;
				urbd->phase=URBD_FINISHING;
				ifxhcd_complete_urb_sub(urbd);
			}
		}
		else
			IFX_ERROR("%s: invalid urb phase:%d \n",__func__,urbd->phase);
	}
	UNLOCK_URBD_LIST(_epqh);
	IFX_DEBUGPL(DBG_HCDV, "%s %p finish\n",__func__,_epqh);
}


/*!
 \brief Free all EPS in one Processes all the URBs in a single list of EPQHs. Completes them with
        -ETIMEDOUT and frees the URBD.
 */
static
void epqh_list_free_1(ifxhcd_hcd_t *_ifxhcd, struct list_head *_epqh_list)
{
	ifxhcd_epqh_t    *epqh;
	struct list_head *item;
	if (!_ifxhcd)
		return;
	if (!_epqh_list)
		return;

	IFX_DEBUGPL(DBG_HCDV, "%s %p\n",__func__,_epqh_list);

	item = _epqh_list->next;
	while(item != _epqh_list && item != item->next)
	{
		epqh = list_entry(item, ifxhcd_epqh_t, ql);
		epqh->phase=EPQH_DISABLING;
		item = item->next;
		kill_all_urbs_in_epqh(_ifxhcd, epqh, -ETIMEDOUT);
		#ifdef __STRICT_ORDER__
		if(list_empty(&epqh->urbd_list) && list_empty(&epqh->release_list))
		#else
		if(list_empty(&epqh->urbd_list))
		#endif
			ifxhcd_epqh_free(epqh);
	}
	IFX_DEBUGPL(DBG_HCDV, "%s %p finish\n",__func__,_epqh_list);
	/* Ensure there are no URBDs or URBs left. */
}

static
void epqh_list_free_2(ifxhcd_hcd_t *_ifxhcd, struct list_head *_epqh_list)
{
	ifxhcd_epqh_t    *epqh;
	struct list_head *item;
	struct list_head *next;
	if (!_ifxhcd)
		return;
	if (!_epqh_list)
		return;

	IFX_DEBUGPL(DBG_HCDV, "%s %p\n",__func__,_epqh_list);
	list_for_each_safe(item, next, _epqh_list)
	{
		epqh = list_entry(item, ifxhcd_epqh_t, ql);
		if(item == item->next)
		{
			ifxhcd_epqh_free(epqh);
		}
		else
		{
			uint32_t count=0x80000;
			#ifdef __STRICT_ORDER__
			for(;(!list_empty(&epqh->urbd_list) || !list_empty(&epqh->release_list))&& count> 0; count--) udelay(1);
			#else
			for(;!list_empty(&epqh->urbd_list) && count> 0; count--) udelay(1);
			#endif
			if(!count)
				IFX_ERROR("%s: unable to clear urbd in epqh \n",__func__);
			ifxhcd_epqh_free(epqh);
		}
	}
	IFX_DEBUGPL(DBG_HCDV, "%s %p finish\n",__func__,_epqh_list);
	/* Ensure there are no URBDs or URBs left. */
}

static
void epqh_list_free_all_sub(unsigned long data)
{
	ifxhcd_hcd_t *ifxhcd;

	ifxhcd=(ifxhcd_hcd_t *)data;
	epqh_list_free_1(ifxhcd, &ifxhcd->epqh_list_np  );
	epqh_list_free_1(ifxhcd, &ifxhcd->epqh_list_intr);
	#ifdef __EN_ISOC__
		epqh_list_free_1(ifxhcd, &ifxhcd->epqh_list_isoc);
	#endif

	epqh_list_free_2(ifxhcd, &ifxhcd->epqh_list_np  );
	epqh_list_free_2(ifxhcd, &ifxhcd->epqh_list_intr);
	#ifdef __EN_ISOC__
		epqh_list_free_2(ifxhcd, &ifxhcd->epqh_list_isoc);
	#endif
}

static
void epqh_list_free_all(ifxhcd_hcd_t *_ifxhcd)
{
	_ifxhcd->tasklet_free_epqh_list.next = NULL;
	_ifxhcd->tasklet_free_epqh_list.state = 0;
	atomic_set( &_ifxhcd->tasklet_free_epqh_list.count, 0);
	_ifxhcd->tasklet_free_epqh_list.func=epqh_list_free_all_sub;
	_ifxhcd->tasklet_free_epqh_list.data = (unsigned long)_ifxhcd;
	tasklet_schedule(&_ifxhcd->tasklet_free_epqh_list);
}


/*!
   \brief This function is called to handle the disconnection of host port.
 */
int32_t ifxhcd_disconnect(ifxhcd_hcd_t *_ifxhcd)
{
	IFX_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, _ifxhcd);

	_ifxhcd->disconnecting=1;
	/* Set status flags for the hub driver. */
	_ifxhcd->flags.b.port_connect_status_change = 1;
	_ifxhcd->flags.b.port_connect_status = 0;

	/*
	 * Shutdown any transfers in process by clearing the Tx FIFO Empty
	 * interrupt mask and status bits and disabling subsequent host
	 * channel interrupts.
	 */
	 {
		gint_data_t intr = { .d32 = 0 };
		intr.b.nptxfempty = 1;
		intr.b.ptxfempty  = 1;
		intr.b.hcintr     = 1;
		ifxusb_mreg (&_ifxhcd->core_if.core_global_regs->gintmsk, intr.d32, 0);
		ifxusb_mreg (&_ifxhcd->core_if.core_global_regs->gintsts, intr.d32, 0);
	}

	/* Respond with an error status to all URBs in the schedule. */
	epqh_list_free_all(_ifxhcd);

	/* Clean up any host channels that were in use. */
	{
		int               num_channels;
		ifxhcd_hc_t      *channel;
		ifxusb_hc_regs_t *hc_regs;
		hcchar_data_t     hcchar;
		int	              i;

		num_channels = _ifxhcd->core_if.params.host_channels;

		for (i = 0; i < num_channels; i++)
		{
			channel = &_ifxhcd->ifxhc[i];
			hc_regs = _ifxhcd->core_if.hc_regs[i];
			hcchar.d32 = ifxusb_rreg(&hc_regs->hcchar);
			if (hcchar.b.chen)
				printk(KERN_INFO "Warning: %s() HC still enabled\n",__func__);
			ifxhcd_hc_cleanup(&_ifxhcd->core_if, channel);
		}
	}
	IFX_DEBUGPL(DBG_HCDV, "%s(%p) finish\n", __func__, _ifxhcd);
	return 1;
}


/*!
   \brief Frees secondary storage associated with the ifxhcd_hcd structure contained
          in the struct usb_hcd field.
 */
static void ifxhcd_freeextra(struct usb_hcd *_syshcd)
{
	ifxhcd_hcd_t 	*ifxhcd = syshcd_to_ifxhcd(_syshcd);

	IFX_DEBUGPL(DBG_HCD, "IFXUSB HCD FREE\n");

	/* Free memory for EPQH/URBD lists */
	epqh_list_free_all(ifxhcd);

	/* Free memory for the host channels. */
	ifxusb_free_buf_h(ifxhcd->status_buf);
	return;
}

/*!
   \brief Initializes the HCD. This function allocates memory for and initializes the
  static parts of the usb_hcd and ifxhcd_hcd structures. It also registers the
  USB bus with the core and calls the hc_driver->start() function. It returns
  a negative error on failure.
 */
int ifxhcd_init(ifxhcd_hcd_t *_ifxhcd)
{
	int retval = 0;
	struct usb_hcd *syshcd = NULL;

	IFX_DEBUGPL(DBG_HCD, "IFX USB HCD INIT\n");

	INIT_EPQH_LIST_ALL(_ifxhcd);
	INIT_EPQH_LIST(_ifxhcd);

	init_timer(&_ifxhcd->autoprobe_timer);
	init_timer(&_ifxhcd->host_probe_timer);
	_ifxhcd->probe_sec = 5;
	_ifxhcd->autoprobe_sec = 30;

	_ifxhcd->hc_driver.description      = _ifxhcd->core_if.core_name;
	_ifxhcd->hc_driver.product_desc     = "IFX USB Controller";
	//_ifxhcd->hc_driver.hcd_priv_size    = sizeof(ifxhcd_hcd_t);
	_ifxhcd->hc_driver.hcd_priv_size    = sizeof(unsigned long);
	_ifxhcd->hc_driver.irq              = ifxhcd_irq;
	_ifxhcd->hc_driver.flags            = HCD_MEMORY | HCD_USB2;
	_ifxhcd->hc_driver.start            = ifxhcd_start;
	_ifxhcd->hc_driver.stop             = ifxhcd_stop;
	//_ifxhcd->hc_driver.reset          =
	//_ifxhcd->hc_driver.suspend        =
	//_ifxhcd->hc_driver.resume         =
	_ifxhcd->hc_driver.urb_enqueue      = ifxhcd_urb_enqueue;
	_ifxhcd->hc_driver.urb_dequeue      = ifxhcd_urb_dequeue;
	_ifxhcd->hc_driver.endpoint_disable = ifxhcd_endpoint_disable;
	_ifxhcd->hc_driver.get_frame_number = ifxhcd_get_frame_number;
	_ifxhcd->hc_driver.hub_status_data  = ifxhcd_hub_status_data;
	_ifxhcd->hc_driver.hub_control      = ifxhcd_hub_control;
	//_ifxhcd->hc_driver.hub_suspend    =
	//_ifxhcd->hc_driver.hub_resume     =
	_ifxhcd->pkt_remaining_reload_hs=PKT_REMAINING_RELOAD_HS;
	_ifxhcd->pkt_remaining_reload_fs=PKT_REMAINING_RELOAD_FS;
	_ifxhcd->pkt_remaining_reload_ls=PKT_REMAINING_RELOAD_LS;
	_ifxhcd->pkt_count_limit_bo         =8;
	_ifxhcd->pkt_count_limit_bi         =8;

	/* Allocate memory for and initialize the base HCD and  */
	//syshcd = usb_create_hcd(&_ifxhcd->hc_driver, _ifxhcd->dev, _ifxhcd->dev->bus_id);
	syshcd = usb_create_hcd(&_ifxhcd->hc_driver, _ifxhcd->dev, _ifxhcd->core_if.core_name);

	if (syshcd == NULL)
	{
		retval = -ENOMEM;
		goto error1;
	}

	syshcd->rsrc_start = (unsigned long)_ifxhcd->core_if.core_global_regs;
	syshcd->regs       = (void *)_ifxhcd->core_if.core_global_regs;
	syshcd->self.otg_port = 0;

	//*((unsigned long *)(&(syshcd->hcd_priv)))=(unsigned long)_ifxhcd;
	//*((unsigned long *)(&(syshcd->hcd_priv[0])))=(unsigned long)_ifxhcd;
	syshcd->hcd_priv[0]=(unsigned long)_ifxhcd;
	_ifxhcd->syshcd=syshcd;
	INIT_LIST_HEAD(&_ifxhcd->epqh_list_all   );
	INIT_LIST_HEAD(&_ifxhcd->epqh_list_np    );
	INIT_LIST_HEAD(&_ifxhcd->epqh_list_intr  );
	#ifdef __EN_ISOC__
		INIT_LIST_HEAD(&_ifxhcd->epqh_list_isoc);
	#endif

	/*
	 * Create a host channel descriptor for each host channel implemented
	 * in the controller. Initialize the channel descriptor array.
	 */
	{
		int          num_channels = _ifxhcd->core_if.params.host_channels;
		int i;
		for (i = 0; i < num_channels; i++)
		{
			_ifxhcd->ifxhc[i].hc_num = i;
			IFX_DEBUGPL(DBG_HCDV, "HCD Added channel #%d\n", i);
		}
	}

	/* Set device flags indicating whether the HCD supports DMA. */
	if(_ifxhcd->dev->dma_mask)
		*(_ifxhcd->dev->dma_mask) = ~0;
	_ifxhcd->dev->coherent_dma_mask = ~0;

	/*
	 * Finish generic HCD initialization and start the HCD. This function
	 * allocates the DMA buffer pool, registers the USB bus, requests the
	 * IRQ line, and calls ifxusb_hcd_start method.
	 */
	retval = usb_add_hcd(syshcd, _ifxhcd->core_if.irq, 0
			                                   |IRQF_DISABLED
			                                   |IRQF_SHARED
							   );
	if (retval < 0)
		goto error2;

	/*
	 * Allocate space for storing data on status transactions. Normally no
	 * data is sent, but this space acts as a bit bucket. This must be
	 * done after usb_add_hcd since that function allocates the DMA buffer
	 * pool.
	 */
	_ifxhcd->status_buf = ifxusb_alloc_buf_h(IFXHCD_STATUS_BUF_SIZE, 1);

	if (_ifxhcd->status_buf)
	{
		IFX_DEBUGPL(DBG_HCD, "IFX USB HCD Initialized, bus=%s, usbbus=%d\n", _ifxhcd->core_if.core_name, syshcd->self.busnum);
		return 0;
	}
	IFX_ERROR("%s: status_buf allocation failed\n", __func__);

	/* Error conditions */
	usb_remove_hcd(syshcd);
error2:
	ifxhcd_freeextra(syshcd);
	usb_put_hcd(syshcd);
error1:
	return retval;
}

/*!
   \brief Removes the HCD.
  Frees memory and resources associated with the HCD and deregisters the bus.
 */
void ifxhcd_remove(ifxhcd_hcd_t *_ifxhcd)
{
	struct usb_hcd *syshcd = ifxhcd_to_syshcd(_ifxhcd);

	IFX_DEBUGPL(DBG_HCD, "IFX USB HCD REMOVE\n");

	/* Turn off all interrupts */
	ifxusb_wreg (&_ifxhcd->core_if.core_global_regs->gintmsk, 0);
	ifxusb_mreg (&_ifxhcd->core_if.core_global_regs->gahbcfg, 1, 0);

	usb_remove_hcd(syshcd);
	ifxhcd_freeextra(syshcd);
	usb_put_hcd(syshcd);

	return;
}


/* =========================================================================
 *  Linux HC Driver Functions
 * ========================================================================= */

/*!
   \brief Initializes the IFXUSB controller and its root hub and prepares it for host
 mode operation. Activates the root port. Returns 0 on success and a negative
 error code on failure.
 Called by USB stack.
 */
int ifxhcd_start(struct usb_hcd *_syshcd)
{
	ifxhcd_hcd_t *ifxhcd = syshcd_to_ifxhcd (_syshcd);
	ifxusb_core_if_t *core_if = &ifxhcd->core_if;
	struct usb_bus *bus;

	IFX_DEBUGPL(DBG_HCD, "IFX USB HCD START\n");

	bus = hcd_to_bus(_syshcd);

	/* Initialize the bus state.  */
	_syshcd->state = HC_STATE_RUNNING;

	/* Initialize and connect root hub if one is not already attached */
	if (bus->root_hub)
	{
		IFX_DEBUGPL(DBG_HCD, "IFX USB HCD Has Root Hub\n");
		/* Inform the HUB driver to resume. */
		usb_hcd_resume_root_hub(_syshcd);
	}

	ifxhcd->flags.d32 = 0;

	/* Put all channels in the free channel list and clean up channel states.*/
	{
		int num_channels = ifxhcd->core_if.params.host_channels;
		int i;
		for (i = 0; i < num_channels; i++)
		{
			ifxhcd_hc_t      *channel;
			channel = &ifxhcd->ifxhc[i];
			ifxhcd_hc_cleanup(&ifxhcd->core_if, channel);
		}
	}
	/* Initialize the USB core for host mode operation. */

	ifxusb_host_enable_interrupts(core_if);
	ifxusb_enable_global_interrupts_h(core_if);
	ifxusb_phy_power_on_h (core_if);

	ifxusb_vbus_init(core_if);

	/* Turn on the vbus power. */
	{
		hprt0_data_t hprt0;
		hprt0.d32 = ifxusb_read_hprt0(core_if);

		IFX_PRINT("Init: Power Port (%d)\n", hprt0.b.prtpwr);
		if (hprt0.b.prtpwr == 0 )
		{
			hprt0.b.prtpwr = 1;
			ifxusb_wreg(core_if->hprt0, hprt0.d32);
			ifxusb_vbus_on(core_if);
		}
	}
	return 0;
}

/*!
   \brief Halts the IFXUSB  host mode operations in a clean manner. USB transfers are
 stopped.
 */
	#if defined(__IS_AR10__)
void		ifxusb_oc_int_free(int port);
	#else
void		ifxusb_oc_int_free(void);
	#endif
 
void ifxhcd_stop(struct usb_hcd *_syshcd)
{
	ifxhcd_hcd_t *ifxhcd = syshcd_to_ifxhcd(_syshcd);
	hprt0_data_t  hprt0 = { .d32=0 };

	IFX_DEBUGPL(DBG_HCD, "IFX USB HCD STOP\n");

	/* Turn off all interrupts. */
	ifxusb_disable_global_interrupts_h(&ifxhcd->core_if );
	ifxusb_host_disable_interrupts(&ifxhcd->core_if );

	/*
	 * The root hub should be disconnected before this function is called.
	 * The disconnect will clear the URBD lists (via ..._hcd_urb_dequeue)
	 * and the EPQH lists (via ..._hcd_endpoint_disable).
	 */

	/* Turn off the vbus power */
	IFX_PRINT("PortPower off\n");

	ifxusb_vbus_off(&ifxhcd->core_if );
	
	
	#if defined(__IS_AR10__)
		ifxusb_oc_int_free(ifxhcd->core_if.core_no);
	#else
		ifxusb_oc_int_free();
	#endif
	

	ifxusb_vbus_free(&ifxhcd->core_if );
	hprt0.b.prtpwr = 0;
	ifxusb_wreg(ifxhcd->core_if.hprt0, hprt0.d32);
	return;
}

/*!
   \brief Returns the current frame number
 */
int ifxhcd_get_frame_number(struct usb_hcd *_syshcd)
{
	ifxhcd_hcd_t 	*ifxhcd = syshcd_to_ifxhcd(_syshcd);
	hfnum_data_t hfnum;

	hfnum.d32 = ifxusb_rreg(&ifxhcd->core_if.host_global_regs->hfnum);

	return hfnum.b.frnum;
}

/*!
   \brief Starts processing a USB transfer request specified by a USB Request Block
  (URB). mem_flags indicates the type of memory allocation to use while
  processing this URB.
 */
int ifxhcd_urb_enqueue( struct usb_hcd           *_syshcd,
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
                        struct usb_host_endpoint *_sysep,
#endif
                        struct urb               *_urb,
                        gfp_t                     _mem_flags)
{
	ifxhcd_hcd_t *ifxhcd = syshcd_to_ifxhcd (_syshcd);
	ifxhcd_epqh_t *epqh = NULL;

	#ifdef __DEBUG__
		if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB))
			dump_urb_info(_urb, "ifxusb_hcd_urb_enqueue");
	#endif //__DEBUG__

	if (!ifxhcd->flags.b.port_connect_status)  /* No longer connected. */
		return -ENODEV;

	#if !defined(__EN_ISOC__)
		if(usb_pipetype(_urb->pipe) == PIPE_ISOCHRONOUS)
		{
			IFX_ERROR("ISOC transfer not supported!!!\n");
			return -ENODEV;
		}
	#endif

	if(_urb->hcpriv)
	{
		IFX_WARN("%s() Previous urb->hcpriv exist %p\n",__func__,_urb->hcpriv);
	#if 1
		return -ENOSPC;
	#endif
	}

	epqh=ifxhcd_urbd_create (ifxhcd,_urb);
	if (!epqh)
	{
		IFX_ERROR("IFXUSB HCD URB Enqueue failed creating URBD\n");
		return -ENOSPC;
	}
	if(epqh->phase==EPQH_DISABLING )
	{
		IFX_ERROR("Enqueue to a DISABLING EP!!!\n");
		return -ENODEV;
	}

	#ifdef __DYN_SOF_INTR__
		ifxhcd->dyn_sof_count = DYN_SOF_COUNT_DEF;
	#endif
	//enable_sof(ifxhcd);
	{
		gint_data_t gintsts;
		gintsts.d32=0;
		gintsts.b.sofintr = 1;
		ifxusb_mreg(&ifxhcd->core_if.core_global_regs->gintmsk, 0,gintsts.d32);
	}

	if(epqh->phase==EPQH_IDLE || epqh->phase==EPQH_STDBY )
	{
		epqh->phase=EPQH_READY;
		#ifdef __EPQD_DESTROY_TIMEOUT__
			del_timer(&epqh->destroy_timer);
		#endif
	}
	select_eps(ifxhcd);
	return 0;
}

/*!
   \brief Aborts/cancels a USB transfer request. Always returns 0 to indicate
  success.
 */
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
int ifxhcd_urb_dequeue(struct usb_hcd *_syshcd, struct urb *_urb)
#else
int ifxhcd_urb_dequeue(struct usb_hcd *_syshcd, struct urb *_urb, int status)
#endif
{
	ifxhcd_hcd_t  *ifxhcd;
	struct usb_host_endpoint *sysep;
	ifxhcd_urbd_t *urbd;
	ifxhcd_epqh_t *epqh;

	IFX_DEBUGPL(DBG_HCD, "IFXUSB HCD URB Dequeue\n");
	#if !defined(__EN_ISOC__)
		if(usb_pipetype(_urb->pipe) == PIPE_ISOCHRONOUS)
			return 0;
	#endif

	ifxhcd = syshcd_to_ifxhcd(_syshcd);

	urbd = (ifxhcd_urbd_t *) _urb->hcpriv;
	if(!urbd)
	{
		#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
			_urb->status=-ETIMEDOUT;
			usb_hcd_giveback_urb(_syshcd, _urb);
		#else
//			usb_hcd_giveback_urb(_syshcd, _urb,-ETIMEDOUT);
			usb_hcd_giveback_urb(_syshcd, _urb,status);
		#endif
		return 0;
	}

	sysep = ifxhcd_urb_to_endpoint(_urb);
	if(sysep)
	{
		LOCK_EPQH_LIST_ALL(ifxhcd);
		epqh = sysep_to_epqh(ifxhcd,sysep);
		UNLOCK_EPQH_LIST_ALL(ifxhcd);
		if(epqh!=urbd->epqh)
			IFX_ERROR("%s inconsistant epqh %p %p\n",__func__,epqh,urbd->epqh);
	}
	else
		epqh = (ifxhcd_epqh_t *) urbd->epqh;
	if(!ifxhcd->flags.b.port_connect_status || !epqh)
	{
		urbd->phase=URBD_DEQUEUEING;
		ifxhcd_complete_urb(ifxhcd, urbd, -ENODEV);
	}
	else
	{
		LOCK_URBD_LIST(epqh);
		if(   urbd->phase==URBD_IDLE
		   || urbd->phase==URBD_ACTIVE
//		   || urbd->phase==URBD_STARTING
		   )
		{
			urbd->phase=URBD_DEQUEUEING;
			#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
				ifxhcd_complete_urb(ifxhcd, urbd, -ETIMEDOUT);
			#else
				ifxhcd_complete_urb(ifxhcd, urbd, status);
			#endif
		}
		else if(   urbd->phase==URBD_STARTED
		        || urbd->phase==URBD_STARTING
//		        || urbd->phase==URBD_ACTIVE
		       )
		{
			if(ifxhcd_hc_halt(&ifxhcd->core_if, epqh->hc, HC_XFER_URB_DEQUEUE))
			{
				urbd->phase=URBD_DEQUEUEING;
				#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
					ifxhcd_complete_urb(ifxhcd, urbd, -ETIMEDOUT);
				#else
					ifxhcd_complete_urb(ifxhcd, urbd, status);
				#endif
				ifxhcd_epqh_idle(epqh);
			}
		}
		UNLOCK_URBD_LIST(epqh);
	}
	return 0;
}


/*!
   \brief Frees resources in the IFXUSB controller related to a given endpoint. Also
  clears state in the HCD related to the endpoint. Any URBs for the endpoint
  must already be dequeued.
 */
void ifxhcd_endpoint_disable( struct usb_hcd *_syshcd,
                              struct usb_host_endpoint *_sysep)
{
	ifxhcd_hcd_t  *ifxhcd;
	ifxhcd_epqh_t *epqh;

	IFX_DEBUGPL(DBG_HCD, "IFXUSB HCD EP DISABLE: _bEndpointAddress=0x%02x, "
	    "endpoint=%d\n", _sysep->desc.bEndpointAddress,
		    ifxhcd_ep_addr_to_endpoint(_sysep->desc.bEndpointAddress));

	ifxhcd = syshcd_to_ifxhcd(_syshcd);

	LOCK_EPQH_LIST_ALL(ifxhcd);
	epqh = sysep_to_epqh(ifxhcd,_sysep);
	UNLOCK_EPQH_LIST_ALL(ifxhcd);

	if (!epqh)
	{
		return;
	}
	else
	{
		if (epqh->sysep!=_sysep)
		{
			IFX_ERROR("%s inconsistant sysep %p %p %p\n",__func__,epqh,epqh->sysep,_sysep);
			return;
		}

		epqh->phase=EPQH_DISABLING;
		kill_all_urbs_in_epqh(ifxhcd, epqh, -ETIMEDOUT);
		{
			uint32_t count=0x80000;
			for(;!list_empty(&epqh->urbd_list) && count> 0; count--) udelay(1);
			if(!count)
				IFX_ERROR("%s: unable to clear urbd in epqh \n",__func__);
		}
		ifxhcd_epqh_free(epqh);
	}
	IFX_DEBUGPL(DBG_HCD, "IFXUSB HCD EP DISABLE: done\n");
}


/*!
  \brief Handles host mode interrupts for the IFXUSB controller. Returns IRQ_NONE if
 there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
 interrupt.

 This function is called by the USB core when an interrupt occurs
 */
irqreturn_t ifxhcd_irq(struct usb_hcd *_syshcd)
{
	ifxhcd_hcd_t *ifxhcd = syshcd_to_ifxhcd (_syshcd);
	int32_t retval=0;

	//mask_and_ack_ifx_irq (ifxhcd->core_if.irq);
	retval = ifxhcd_handle_intr(ifxhcd);
	return IRQ_RETVAL(retval);
}



/*!
 \brief Creates Status Change bitmap for the root hub and root port. The bitmap is
  returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
  is the status change indicator for the single root port. Returns 1 if either
  change indicator is 1, otherwise returns 0.
 */
int ifxhcd_hub_status_data(struct usb_hcd *_syshcd, char *_buf)
{
	ifxhcd_hcd_t *ifxhcd = syshcd_to_ifxhcd (_syshcd);

	_buf[0] = 0;
	_buf[0] |= (ifxhcd->flags.b.port_connect_status_change ||
	            ifxhcd->flags.b.port_reset_change ||
	            ifxhcd->flags.b.port_enable_change ||
	            ifxhcd->flags.b.port_suspend_change ||
	            ifxhcd->flags.b.port_over_current_change) << 1;

	#ifdef __DEBUG__
		if (_buf[0])
		{
			IFX_DEBUGPL(DBG_HCD, "IFXUSB HCD HUB STATUS DATA:"
				    " Root port status changed\n");
			IFX_DEBUGPL(DBG_HCDV, "  port_connect_status_change: %d\n",
				    ifxhcd->flags.b.port_connect_status_change);
			IFX_DEBUGPL(DBG_HCDV, "  port_reset_change: %d\n",
				    ifxhcd->flags.b.port_reset_change);
			IFX_DEBUGPL(DBG_HCDV, "  port_enable_change: %d\n",
				    ifxhcd->flags.b.port_enable_change);
			IFX_DEBUGPL(DBG_HCDV, "  port_suspend_change: %d\n",
				    ifxhcd->flags.b.port_suspend_change);
			IFX_DEBUGPL(DBG_HCDV, "  port_over_current_change: %d\n",
				    ifxhcd->flags.b.port_over_current_change);
			{
				hprt0_data_t hprt0;
				hprt0.d32 = ifxusb_rreg(ifxhcd->core_if.hprt0);
				IFX_DEBUGPL(DBG_HCDV, "  port reg :%08X\n",hprt0.d32);
				IFX_DEBUGPL(DBG_HCDV, "  port reg :connect: %d/%d\n",hprt0.b.prtconnsts,hprt0.b.prtconndet);
				IFX_DEBUGPL(DBG_HCDV, "  port reg :enable: %d/%d\n",hprt0.b.prtena,hprt0.b.prtenchng);
				IFX_DEBUGPL(DBG_HCDV, "  port reg :OC: %d/%d\n",hprt0.b.prtovrcurract,hprt0.b.prtovrcurrchng);
				IFX_DEBUGPL(DBG_HCDV, "  port reg :rsume/suspend/reset: %d/%d/%d\n",hprt0.b.prtres,hprt0.b.prtsusp,hprt0.b.prtrst);
				IFX_DEBUGPL(DBG_HCDV, "  port reg :port power: %d/\n",hprt0.b.prtpwr);
				IFX_DEBUGPL(DBG_HCDV, "  port reg :speed: %d/\n",hprt0.b.prtspd);
			}
		}
	#endif //__DEBUG__
	return (_buf[0] != 0);
}

#ifdef __WITH_HS_ELECT_TST__
	extern void do_setup(ifxusb_core_if_t *_core_if) ;
	extern void do_in_ack(ifxusb_core_if_t *_core_if);
#endif //__WITH_HS_ELECT_TST__

/*!
 \brief Handles hub class-specific requests.
 */
int ifxhcd_hub_control( struct usb_hcd *_syshcd,
                        u16             _typeReq,
                        u16             _wValue,
                        u16             _wIndex,
                        char           *_buf,
                        u16             _wLength)
{
	int retval = 0;
	ifxhcd_hcd_t              *ifxhcd  = syshcd_to_ifxhcd (_syshcd);
	ifxusb_core_if_t          *core_if = &ifxhcd->core_if;
	struct usb_hub_descriptor *desc;
	hprt0_data_t               hprt0 = {.d32 = 0};

	uint32_t port_status;

	switch (_typeReq)
	{
		case ClearHubFeature:
			IFX_DEBUGPL (DBG_HCD, "IFXUSB HCD HUB CONTROL - "
			         "ClearHubFeature 0x%x\n", _wValue);
			switch (_wValue)
			{
				case C_HUB_LOCAL_POWER:
				case C_HUB_OVER_CURRENT:
					/* Nothing required here */
					break;
				default:
					retval = -EINVAL;
					IFX_ERROR ("IFXUSB HCD - "
						   "ClearHubFeature request %xh unknown\n", _wValue);
			}
			break;
		case ClearPortFeature:
			if (!_wIndex || _wIndex > 1)
				goto error;

			switch (_wValue)
			{
				case USB_PORT_FEAT_ENABLE:
					IFX_DEBUGPL (DBG_ANY, "IFXUSB HCD HUB CONTROL - "
						     "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
					hprt0.d32 = ifxusb_read_hprt0 (core_if);
					hprt0.b.prtena = 1;
					ifxusb_wreg(core_if->hprt0, hprt0.d32);
					break;
				case USB_PORT_FEAT_SUSPEND:
					IFX_DEBUGPL (DBG_HCD, "IFXUSB HCD HUB CONTROL - "
						     "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
					hprt0.d32 = ifxusb_read_hprt0 (core_if);
					hprt0.b.prtres = 1;
					ifxusb_wreg(core_if->hprt0, hprt0.d32);
					/* Clear Resume bit */
					mdelay (100);
					hprt0.b.prtres = 0;
					ifxusb_wreg(core_if->hprt0, hprt0.d32);
					break;
				case USB_PORT_FEAT_POWER:
					IFX_DEBUGPL (DBG_HCD, "IFXUSB HCD HUB CONTROL - "
						     "ClearPortFeature USB_PORT_FEAT_POWER\n");
					#ifdef __IS_DUAL__
						ifxusb_vbus_off(core_if);
					#else
						ifxusb_vbus_off(core_if);
					#endif
					hprt0.d32 = ifxusb_read_hprt0 (core_if);
					hprt0.b.prtpwr = 0;
					ifxusb_wreg(core_if->hprt0, hprt0.d32);
					break;
				case USB_PORT_FEAT_INDICATOR:
					IFX_DEBUGPL (DBG_HCD, "IFXUSB HCD HUB CONTROL - "
						     "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
					/* Port inidicator not supported */
					break;
				case USB_PORT_FEAT_C_CONNECTION:
					/* Clears drivers internal connect status change
					 * flag */
					IFX_DEBUGPL (DBG_HCD, "IFXUSB HCD HUB CONTROL - "
						     "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
					ifxhcd->flags.b.port_connect_status_change = 0;
					break;
				case USB_PORT_FEAT_C_RESET:
					/* Clears the driver's internal Port Reset Change
					 * flag */
					IFX_DEBUGPL (DBG_HCD, "IFXUSB HCD HUB CONTROL - "
						     "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
					ifxhcd->flags.b.port_reset_change = 0;
					break;
				case USB_PORT_FEAT_C_ENABLE:
					/* Clears the driver's internal Port
					 * Enable/Disable Change flag */
					IFX_DEBUGPL (DBG_HCD, "IFXUSB HCD HUB CONTROL - "
						     "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
					ifxhcd->flags.b.port_enable_change = 0;
					break;
				case USB_PORT_FEAT_C_SUSPEND:
					/* Clears the driver's internal Port Suspend
					 * Change flag, which is set when resume signaling on
					 * the host port is complete */
					IFX_DEBUGPL (DBG_HCD, "IFXUSB HCD HUB CONTROL - "
						     "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
					ifxhcd->flags.b.port_suspend_change = 0;
					break;
				case USB_PORT_FEAT_C_OVER_CURRENT:
					IFX_DEBUGPL (DBG_HCD, "IFXUSB HCD HUB CONTROL - "
						     "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
					ifxhcd->flags.b.port_over_current_change = 0;
					break;
				default:
					retval = -EINVAL;
					IFX_ERROR ("IFXUSB HCD - "
					         "ClearPortFeature request %xh "
					         "unknown or unsupported\n", _wValue);
			}
			break;
		case GetHubDescriptor:
			IFX_DEBUGPL (DBG_HCD, "IFXUSB HCD HUB CONTROL - "
			         "GetHubDescriptor\n");
			desc = (struct usb_hub_descriptor *)_buf;
			desc->bDescLength = 9;
			desc->bDescriptorType = 0x29;
			desc->bNbrPorts = 1;
			desc->wHubCharacteristics = 0x08;
			desc->bPwrOn2PwrGood = 1;
			desc->bHubContrCurrent = 0;

			desc->u.hs.DeviceRemovable[0] = 0;
		        desc->u.hs.DeviceRemovable[1] = 1;
			/*desc->bitmap[0] = 0;
			desc->bitmap[1] = 0xff;*/
			break;
		case GetHubStatus:
			IFX_DEBUGPL (DBG_HCD, "IFXUSB HCD HUB CONTROL - "
			         "GetHubStatus\n");
			memset (_buf, 0, 4);
			break;
		case GetPortStatus:
			IFX_DEBUGPL (DBG_HCD, "IFXUSB HCD HUB CONTROL - "
			         "GetPortStatus\n");
			if (!_wIndex || _wIndex > 1)
				goto error;
			port_status = 0;
			if (ifxhcd->flags.b.port_connect_status_change)
				port_status |= (1 << USB_PORT_FEAT_C_CONNECTION);
			if (ifxhcd->flags.b.port_enable_change)
				port_status |= (1 << USB_PORT_FEAT_C_ENABLE);
			if (ifxhcd->flags.b.port_suspend_change)
				port_status |= (1 << USB_PORT_FEAT_C_SUSPEND);
			if (ifxhcd->flags.b.port_reset_change)
				port_status |= (1 << USB_PORT_FEAT_C_RESET);
			if (ifxhcd->flags.b.port_over_current_change)
			{
				IFX_ERROR("Device Not Supported\n");
				port_status |= (1 << USB_PORT_FEAT_C_OVER_CURRENT);
			}
			if (!ifxhcd->flags.b.port_connect_status)
			{
				/*
				 * The port is disconnected, which means the core is
				 * either in device mode or it soon will be. Just
				 * return 0's for the remainder of the port status
				 * since the port register can't be read if the core
				 * is in device mode.
				 */
				*((u32 *) _buf) = cpu_to_le32(port_status);
				break;
			}

			hprt0.d32 = ifxusb_rreg(core_if->hprt0);
			IFX_DEBUGPL(DBG_HCDV, "  HPRT0: 0x%08x\n", hprt0.d32);
			if (hprt0.b.prtconnsts)
				port_status |= (1 << USB_PORT_FEAT_CONNECTION);
			if (hprt0.b.prtena)
			{
				ifxhcd->disconnecting=0;
				port_status |= (1 << USB_PORT_FEAT_ENABLE);
			}
			if (hprt0.b.prtsusp)
				port_status |= (1 << USB_PORT_FEAT_SUSPEND);
			if (hprt0.b.prtovrcurract)
				port_status |= (1 << USB_PORT_FEAT_OVER_CURRENT);
			if (hprt0.b.prtrst)
				port_status |= (1 << USB_PORT_FEAT_RESET);
			if (hprt0.b.prtpwr)
				port_status |= (1 << USB_PORT_FEAT_POWER);
			if (hprt0.b.prtspd == IFXUSB_HPRT0_PRTSPD_HIGH_SPEED)
				port_status |= USB_PORT_STAT_HIGH_SPEED;
			else if (hprt0.b.prtspd == IFXUSB_HPRT0_PRTSPD_LOW_SPEED)
				port_status |= USB_PORT_STAT_LOW_SPEED;
			if (hprt0.b.prttstctl)
				port_status |= (1 << USB_PORT_FEAT_TEST);
			/* USB_PORT_FEAT_INDICATOR unsupported always 0 */
			*((u32 *) _buf) = cpu_to_le32(port_status);
			break;
		case SetHubFeature:
			IFX_DEBUGPL (DBG_HCD, "IFXUSB HCD HUB CONTROL - "
			         "SetHubFeature\n");
			/* No HUB features supported */
			break;
		case SetPortFeature:
			if (_wValue != USB_PORT_FEAT_TEST && (!_wIndex || _wIndex > 1))
				goto error;
			/*
			 * The port is disconnected, which means the core is
			 * either in device mode or it soon will be. Just
			 * return without doing anything since the port
			 * register can't be written if the core is in device
			 * mode.
			 */
			if (!ifxhcd->flags.b.port_connect_status)
				break;
			switch (_wValue)
			{
				case USB_PORT_FEAT_SUSPEND:
					IFX_DEBUGPL (DBG_HCD, "IFXUSB HCD HUB CONTROL - "
						     "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
					hprt0.d32 = ifxusb_read_hprt0 (core_if);
					hprt0.b.prtsusp = 1;
					ifxusb_wreg(core_if->hprt0, hprt0.d32);
					//IFX_PRINT( "SUSPEND: HPRT0=%0x\n", hprt0.d32);
					/* Suspend the Phy Clock */
					{
						pcgcctl_data_t pcgcctl = {.d32=0};
						pcgcctl.b.stoppclk = 1;
						ifxusb_wreg(core_if->pcgcctl, pcgcctl.d32);
					}
					break;
				case USB_PORT_FEAT_POWER:
					IFX_DEBUGPL (DBG_HCD, "IFXUSB HCD HUB CONTROL - "
					     "SetPortFeature - USB_PORT_FEAT_POWER\n");
					ifxusb_vbus_on (core_if);
					hprt0.d32 = ifxusb_read_hprt0 (core_if);
					hprt0.b.prtpwr = 1;
					ifxusb_wreg(core_if->hprt0, hprt0.d32);
					break;
				case USB_PORT_FEAT_RESET:
					IFX_DEBUGPL (DBG_HCD, "IFXUSB HCD HUB CONTROL - "
						     "SetPortFeature - USB_PORT_FEAT_RESET\n");
					hprt0.d32 = ifxusb_read_hprt0 (core_if);
					hprt0.b.prtrst = 1;
					ifxusb_wreg(core_if->hprt0, hprt0.d32);
					/* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
					MDELAY (60);
					hprt0.b.prtrst = 0;
					ifxusb_wreg(core_if->hprt0, hprt0.d32);
					break;
			#ifdef __WITH_HS_ELECT_TST__
				case USB_PORT_FEAT_TEST:
					{
						uint32_t t;
						gint_data_t gintmsk;
						t = (_wIndex >> 8); /* MSB wIndex USB */
						IFX_DEBUGPL (DBG_HCD, "IFXUSB HCD HUB CONTROL - "
							     "SetPortFeature - USB_PORT_FEAT_TEST %d\n", t);
						warn("USB_PORT_FEAT_TEST %d\n", t);
						if (t < 6)
						{
							hprt0.d32 = ifxusb_read_hprt0 (core_if);
							hprt0.b.prttstctl = t;
							ifxusb_wreg(core_if->hprt0, hprt0.d32);
						}
						else if (t == 6)  /* HS_HOST_PORT_SUSPEND_RESUME */
						{
							/* Save current interrupt mask */
							gintmsk.d32 = ifxusb_rreg(&core_if->core_global_regs->gintmsk);

							/* Disable all interrupts while we muck with
							 * the hardware directly
							 */
							ifxusb_wreg(&core_if->core_global_regs->gintmsk, 0);

							/* 15 second delay per the test spec */
							mdelay(15000);

							/* Drive suspend on the root port */
							hprt0.d32 = ifxusb_read_hprt0 (core_if);
							hprt0.b.prtsusp = 1;
							hprt0.b.prtres = 0;
							ifxusb_wreg(core_if->hprt0, hprt0.d32);

							/* 15 second delay per the test spec */
							mdelay(15000);

							/* Drive resume on the root port */
							hprt0.d32 = ifxusb_read_hprt0 (core_if);
							hprt0.b.prtsusp = 0;
							hprt0.b.prtres = 1;
							ifxusb_wreg(core_if->hprt0, hprt0.d32);
							mdelay(100);

							/* Clear the resume bit */
							hprt0.b.prtres = 0;
							ifxusb_wreg(core_if->hprt0, hprt0.d32);

							/* Restore interrupts */
							ifxusb_wreg(&core_if->core_global_regs->gintmsk, gintmsk.d32);
						}
						else if (t == 7)  /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
						{
							/* Save current interrupt mask */
							gintmsk.d32 = ifxusb_rreg(&core_if->core_global_regs->gintmsk);

							/* Disable all interrupts while we muck with
							 * the hardware directly
							 */
							ifxusb_wreg(&core_if->core_global_regs->gintmsk, 0);

							/* 15 second delay per the test spec */
							mdelay(15000);

							/* Send the Setup packet */
							do_setup(core_if);

							/* 15 second delay so nothing else happens for awhile */
							mdelay(15000);

							/* Restore interrupts */
							ifxusb_wreg(&core_if->core_global_regs->gintmsk, gintmsk.d32);
						}

						else if (t == 8)  /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
						{
							/* Save current interrupt mask */
							gintmsk.d32 = ifxusb_rreg(&core_if->core_global_regs->gintmsk);

							/* Disable all interrupts while we muck with
							 * the hardware directly
							 */
							ifxusb_wreg(&core_if->core_global_regs->gintmsk, 0);

							/* Send the Setup packet */
							do_setup(core_if);

							/* 15 second delay so nothing else happens for awhile */
							mdelay(15000);

							/* Send the In and Ack packets */
							do_in_ack(core_if);

							/* 15 second delay so nothing else happens for awhile */
							mdelay(15000);

							/* Restore interrupts */
							ifxusb_wreg(&core_if->core_global_regs->gintmsk, gintmsk.d32);
						}
					}
					break;
			#endif //__WITH_HS_ELECT_TST__
				case USB_PORT_FEAT_INDICATOR:
					IFX_DEBUGPL (DBG_HCD, "IFXUSB HCD HUB CONTROL - "
						     "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
					/* Not supported */
					break;
				default:
					retval = -EINVAL;
					IFX_ERROR ("IFXUSB HCD - "
						   "SetPortFeature request %xh "
						   "unknown or unsupported\n", _wValue);
			}
			break;
		default:
		error:
			retval = -EINVAL;
			IFX_WARN ("IFXUSB HCD - "
			          "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
			          _typeReq, _wIndex, _wValue);
	}
	return retval;
}




/*!
   \brief This function trigger a data transfer for a host channel and
  starts the transfer.

  For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
  register along with a packet count of 1 and the channel is enabled. This
  causes a single PING transaction to occur. Other fields in HCTSIZ are
  simply set to 0 since no data transfer occurs in this case.

  For a PING transfer in DMA mode, the HCTSIZ register is initialized with
  all the information required to perform the subsequent data transfer. In
  addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
  controller performs the entire PING protocol, then starts the data
  transfer.
  \param _core_if        Pointer of core_if structure
  \param _ifxhc Information needed to initialize the host channel. The xfer_len
  value may be reduced to accommodate the max widths of the XferSize and
  PktCnt fields in the HCTSIZn register. The multi_count value may be changed
  to reflect the final xfer_len value.
 */
void ifxhcd_hc_start(ifxhcd_hcd_t *_ifxhcd, ifxhcd_hc_t *_ifxhc)
{
	ifxusb_core_if_t *core_if = &_ifxhcd->core_if;
	uint32_t max_hc_xfer_size = core_if->params.max_transfer_size;
	uint16_t max_hc_pkt_count = core_if->params.max_packet_count;
	ifxusb_hc_regs_t *hc_regs = core_if->hc_regs[_ifxhc->hc_num];
	hfnum_data_t hfnum;

	hprt0_data_t hprt0;

	if(_ifxhc->epqh->urbd->phase==URBD_DEQUEUEING)
		return;

	hprt0.d32 = ifxusb_read_hprt0(core_if);

	if(_ifxhcd->pkt_remaining==0)
		return;

#if 0
	if(_ifxhc->phase!=HC_WAITING)
		printk(KERN_INFO "%s() line %d: _ifxhc->phase!=HC_WAITING :%d\n",__func__,__LINE__,_ifxhc->phase);
	if(_ifxhc->epqh->urbd->phase==URBD_IDLE      ) printk(KERN_INFO "%s() line %d: _ifxhc->epqh->urbd->phase==URBD_IDLE\n",__func__,__LINE__);
//	if(_ifxhc->epqh->urbd->phase==URBD_ACTIVE    ) printk(KERN_INFO "%s() line %d: _ifxhc->epqh->urbd->phase==URBD_ACTIVE\n",__func__,__LINE__);
	if(_ifxhc->epqh->urbd->phase==URBD_STARTING  ) printk(KERN_INFO "%s() line %d: _ifxhc->epqh->urbd->phase==URBD_STARTING\n",__func__,__LINE__);
	if(_ifxhc->epqh->urbd->phase==URBD_STARTED   ) printk(KERN_INFO "%s() line %d: _ifxhc->epqh->urbd->phase==URBD_STARTED\n",__func__,__LINE__);
	if(_ifxhc->epqh->urbd->phase==URBD_COMPLETING) printk(KERN_INFO "%s() line %d: _ifxhc->epqh->urbd->phase==URBD_COMPLETING\n",__func__,__LINE__);
	if(_ifxhc->epqh->urbd->phase==URBD_DEQUEUEING) printk(KERN_INFO "%s() line %d: _ifxhc->epqh->urbd->phase==URBD_DEQUEUEING\n",__func__,__LINE__);
	if(_ifxhc->epqh->urbd->phase==URBD_FINISHING ) printk(KERN_INFO "%s() line %d: _ifxhc->epqh->urbd->phase==URBD_FINISHING\n",__func__,__LINE__);
#endif

	if      (hprt0.b.prtspd == IFXUSB_HPRT0_PRTSPD_HIGH_SPEED)
	{
		if (_ifxhc->split)
		{
			if(max_hc_pkt_count > _ifxhcd->pkt_remaining)
				max_hc_pkt_count = _ifxhcd->pkt_remaining;
		}
		else if(_ifxhc->ep_type == IFXUSB_EP_TYPE_BULK)
		{
			if( _ifxhc->is_in && _ifxhcd->pkt_count_limit_bi && max_hc_pkt_count > _ifxhcd->pkt_count_limit_bi)
				max_hc_pkt_count = _ifxhcd->pkt_count_limit_bi;
			if(!_ifxhc->is_in && _ifxhcd->pkt_count_limit_bo && max_hc_pkt_count > _ifxhcd->pkt_count_limit_bo)
				max_hc_pkt_count = _ifxhcd->pkt_count_limit_bo;
			if(max_hc_pkt_count*8 > _ifxhcd->pkt_remaining)
				max_hc_pkt_count = _ifxhcd->pkt_remaining/8;
		}
		else
		{
			if(max_hc_pkt_count > _ifxhcd->pkt_remaining)
				max_hc_pkt_count = _ifxhcd->pkt_remaining;
		}
	}
	else if (hprt0.b.prtspd == IFXUSB_HPRT0_PRTSPD_LOW_SPEED)
	{
		if(max_hc_pkt_count > _ifxhcd->pkt_remaining)
			max_hc_pkt_count = _ifxhcd->pkt_remaining;
	}
	else
	{
		if(max_hc_pkt_count > _ifxhcd->pkt_remaining)
			max_hc_pkt_count = _ifxhcd->pkt_remaining;
	}

	if(max_hc_pkt_count==0)
		return;

	if(max_hc_pkt_count * _ifxhc->mps <  max_hc_xfer_size)
		max_hc_xfer_size = max_hc_pkt_count * _ifxhc->mps;

	_ifxhc->epqh->urbd->phase=URBD_STARTING;

	if(_ifxhc->is_in || _ifxhc->speed != IFXUSB_EP_SPEED_HIGH || _ifxhc->xfer_len==0)
		_ifxhc->epqh->do_ping=0;
	if(_ifxhc->ep_type == IFXUSB_EP_TYPE_INTR || _ifxhc->ep_type == IFXUSB_EP_TYPE_ISOC)
		_ifxhc->epqh->do_ping=0;
	if(_ifxhc->ep_type == IFXUSB_EP_TYPE_CTRL && _ifxhc->control_phase != IFXHCD_CONTROL_DATA  )
		_ifxhc->epqh->do_ping=0;

	if (_ifxhc->split > 0)
	{
		_ifxhc->start_pkt_count = 1;
		if(!_ifxhc->is_in && _ifxhc->split>1) // OUT CSPLIT
			_ifxhc->xfer_len = 0;
		if (_ifxhc->xfer_len > _ifxhc->mps)
			_ifxhc->xfer_len = _ifxhc->mps;
		if (_ifxhc->xfer_len > 188)
			_ifxhc->xfer_len = 188;
	}
	else if(_ifxhc->is_in)
	{
		_ifxhc->short_rw = 0;
		if (_ifxhc->xfer_len > 0)
		{
			if (_ifxhc->xfer_len > max_hc_xfer_size)
				_ifxhc->xfer_len = max_hc_xfer_size - _ifxhc->mps + 1;
			_ifxhc->start_pkt_count = (_ifxhc->xfer_len + _ifxhc->mps - 1) / _ifxhc->mps;
			if (_ifxhc->start_pkt_count > max_hc_pkt_count)
				_ifxhc->start_pkt_count = max_hc_pkt_count;
		}
		else /* Need 1 packet for transfer length of 0. */
			_ifxhc->start_pkt_count = 1;
		_ifxhc->xfer_len = _ifxhc->start_pkt_count * _ifxhc->mps;
	}
	else //non-split out
	{
		if (_ifxhc->xfer_len == 0)
		{
			if(_ifxhc->short_rw==0)
				printk(KERN_INFO "Info: %s() line %d: ZLP write without short_rw set! xfer_count:%d/%d \n",__func__,__LINE__,
					_ifxhc->xfer_count,
					_ifxhc->epqh->urbd->xfer_len);
			_ifxhc->start_pkt_count = 1;
		}
		else
		{
			if (_ifxhc->xfer_len > max_hc_xfer_size)
			{
				_ifxhc->start_pkt_count = (max_hc_xfer_size / _ifxhc->mps);
				_ifxhc->xfer_len = _ifxhc->start_pkt_count * _ifxhc->mps;
			}
			else
			{
				_ifxhc->start_pkt_count = (_ifxhc->xfer_len+_ifxhc->mps-1)  / _ifxhc->mps;
//				if(_ifxhc->start_pkt_count * _ifxhc->mps == _ifxhc->xfer_len )
//					_ifxhc->start_pkt_count += _ifxhc->short_rw;
			}
		}
	}

	if      (hprt0.b.prtspd == IFXUSB_HPRT0_PRTSPD_HIGH_SPEED)
	{
		if (_ifxhc->split)
		{
			if( _ifxhcd->pkt_remaining > _ifxhc->start_pkt_count)
				_ifxhcd->pkt_remaining -= _ifxhc->start_pkt_count;
			else
				_ifxhcd->pkt_remaining  = 0;
		}
		else if(_ifxhc->ep_type == IFXUSB_EP_TYPE_BULK)
		{
			if( _ifxhcd->pkt_remaining*8 > _ifxhc->start_pkt_count)
				_ifxhcd->pkt_remaining -= (_ifxhc->start_pkt_count*8);
			else
				_ifxhcd->pkt_remaining  = 0;
		}
		else
		{
			if( _ifxhcd->pkt_remaining > _ifxhc->start_pkt_count)
				_ifxhcd->pkt_remaining -= _ifxhc->start_pkt_count;
			else
				_ifxhcd->pkt_remaining  = 0;
		}
	}
	else if (hprt0.b.prtspd == IFXUSB_HPRT0_PRTSPD_LOW_SPEED)
	{
		if( _ifxhcd->pkt_remaining > _ifxhc->start_pkt_count)
			_ifxhcd->pkt_remaining -= _ifxhc->start_pkt_count;
		else
			_ifxhcd->pkt_remaining  = 0;
	}
	else
	{
		if( _ifxhcd->pkt_remaining > _ifxhc->start_pkt_count)
			_ifxhcd->pkt_remaining -= _ifxhc->start_pkt_count;
		else
			_ifxhcd->pkt_remaining  = 0;
	}

	#ifdef __EN_ISOC__
		if (_ifxhc->ep_type == IFXUSB_EP_TYPE_ISOC)
		{
			/* Set up the initial PID for the transfer. */
			#if 1
				_ifxhc->data_pid_start = IFXUSB_HC_PID_DATA0;
			#else
				if (_ifxhc->speed == IFXUSB_EP_SPEED_HIGH)
				{
					if (_ifxhc->is_in)
					{
						if      (_ifxhc->multi_count == 1)
							_ifxhc->data_pid_start = IFXUSB_HC_PID_DATA0;
						else if (_ifxhc->multi_count == 2)
							_ifxhc->data_pid_start = IFXUSB_HC_PID_DATA1;
						else
							_ifxhc->data_pid_start = IFXUSB_HC_PID_DATA2;
					}
					else
					{
						if (_ifxhc->multi_count == 1)
							_ifxhc->data_pid_start = IFXUSB_HC_PID_DATA0;
						else
							_ifxhc->data_pid_start = IFXUSB_HC_PID_MDATA;
					}
				}
				else
					_ifxhc->data_pid_start = IFXUSB_HC_PID_DATA0;
			#endif
		}
	#endif

	IFX_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, _ifxhc->hc_num);
	{
		hctsiz_data_t hctsiz= { .d32=0 };

		hctsiz.b.dopng = _ifxhc->epqh->do_ping;
		_ifxhc->epqh->do_ping=0;

		if(_ifxhc->is_in || _ifxhc->speed != IFXUSB_EP_SPEED_HIGH || _ifxhc->xfer_len==0)
			hctsiz.b.dopng = 0;
		if(_ifxhc->ep_type == IFXUSB_EP_TYPE_INTR || _ifxhc->ep_type == IFXUSB_EP_TYPE_ISOC)
			hctsiz.b.dopng = 0;
		if(_ifxhc->ep_type == IFXUSB_EP_TYPE_CTRL && _ifxhc->control_phase != IFXHCD_CONTROL_DATA  )
			hctsiz.b.dopng = 0;

		hctsiz.b.xfersize = _ifxhc->xfer_len;
		hctsiz.b.pktcnt   = _ifxhc->start_pkt_count;
		hctsiz.b.pid      = _ifxhc->data_pid_start;
		ifxusb_wreg(&hc_regs->hctsiz, hctsiz.d32);

		IFX_DEBUGPL(DBG_HCDV, "  Xfer Size: %d\n", hctsiz.b.xfersize);
		IFX_DEBUGPL(DBG_HCDV, "  Num Pkts: %d\n" , hctsiz.b.pktcnt);
		IFX_DEBUGPL(DBG_HCDV, "  Start PID: %d\n", hctsiz.b.pid);
	}
	IFX_DEBUGPL(DBG_HCDV, "  DMA: 0x%08x\n", (uint32_t)(CPHYSADDR( ((uint32_t)(_ifxhc->xfer_buff))+ _ifxhc->xfer_count )));
	ifxusb_wreg(&hc_regs->hcdma, (uint32_t)(CPHYSADDR( ((uint32_t)(_ifxhc->xfer_buff))+ _ifxhc->xfer_count )));

	/* Start the split */
	if (_ifxhc->split>0)
	{
		hcsplt_data_t hcsplt;
		hcsplt.d32 = ifxusb_rreg (&hc_regs->hcsplt);
		hcsplt.b.spltena = 1;
		if (_ifxhc->split>1)
			hcsplt.b.compsplt = 1;
		else
			hcsplt.b.compsplt = 0;

		#if defined(__EN_ISOC__) && defined(__EN_ISOC_SPLIT__)
			if (_ifxhc->ep_type == IFXUSB_EP_TYPE_ISOC)
				hcsplt.b.xactpos = _ifxhc->isoc_xact_pos;
			else
		#endif
		hcsplt.b.xactpos = IFXUSB_HCSPLIT_XACTPOS_ALL;// if not ISO
		ifxusb_wreg(&hc_regs->hcsplt, hcsplt.d32);
		IFX_DEBUGPL(DBG_HCDV, "  SPLIT: XACT_POS:0x%08x\n", hcsplt.d32);
	}

	{
		hcchar_data_t hcchar;
		hcchar.d32 = ifxusb_rreg(&hc_regs->hcchar);
//		hcchar.b.multicnt = _ifxhc->multi_count;
		hcchar.b.multicnt = 1;

		if (_ifxhc->ep_type == IFXUSB_EP_TYPE_INTR || _ifxhc->ep_type == IFXUSB_EP_TYPE_ISOC)
		{
			hfnum.d32 = ifxusb_rreg(&core_if->host_global_regs->hfnum);
			/* 1 if _next_ frame is odd, 0 if it's even */
			hcchar.b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
		}

		#ifdef __DEBUG__
			_ifxhc->start_hcchar_val = hcchar.d32;
			if (hcchar.b.chdis)
				IFX_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
					 __func__, _ifxhc->hc_num, hcchar.d32);
		#endif

		/* Set host channel enable after all other setup is complete. */
		hcchar.b.chen  = 1;
		hcchar.b.chdis = 0;
		hcchar.b.epdir =  _ifxhc->is_in;
		_ifxhc->hcchar=hcchar.d32;
	}

	IFX_DEBUGPL(DBG_HCDV, "  HCCHART: 0x%08x\n", _ifxhc->hcchar);

	_ifxhc->phase=HC_STARTING;
}

/*!
   \brief Attempts to halt a host channel. This function should only be called
  to abort a transfer in DMA mode. Under normal circumstances in DMA mode, the
  controller halts the channel when the transfer is complete or a condition
  occurs that requires application intervention.

  In DMA mode, always sets the Channel Enable and Channel Disable bits of the
  HCCHARn register. The controller ensures there is space in the request
  queue before submitting the halt request.

  Some time may elapse before the core flushes any posted requests for this
  host channel and halts. The Channel Halted interrupt handler completes the
  deactivation of the host channel.
 */
int ifxhcd_hc_halt(ifxusb_core_if_t *_core_if,
                    ifxhcd_hc_t *_ifxhc,
                    ifxhcd_halt_status_e _halt_status)
{
	hcchar_data_t   hcchar;
	ifxusb_hc_regs_t           *hc_regs;
	hc_regs          = _core_if->hc_regs[_ifxhc->hc_num];

	WARN_ON(_halt_status == HC_XFER_NO_HALT_STATUS);

	{
		hprt0_data_t hprt0;
		hprt0.d32 = ifxusb_rreg(_core_if->hprt0);
		if(hprt0.b.prtena == 0)
			return -1;
	}

	if (_halt_status == HC_XFER_URB_DEQUEUE ||
	    _halt_status == HC_XFER_AHB_ERR)
	{
		/*
		 * Disable all channel interrupts except Ch Halted. The URBD
		 * and EPQH state associated with this transfer has been cleared
		 * (in the case of URB_DEQUEUE), so the channel needs to be
		 * shut down carefully to prevent crashes.
		 */
		hcint_data_t hcintmsk;
		hcintmsk.d32 = 0;
		hcintmsk.b.chhltd = 1;
		ifxusb_wreg(&hc_regs->hcintmsk, hcintmsk.d32);

		/*
		 * Make sure no other interrupts besides halt are currently
		 * pending. Handling another interrupt could cause a crash due
		 * to the URBD and EPQH state.
		 */
		ifxusb_wreg(&hc_regs->hcint, ~hcintmsk.d32);

		/*
		 * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
		 * even if the channel was already halted for some other
		 * reason.
		 */
		_ifxhc->halt_status = _halt_status;
	}

	hcchar.d32 = ifxusb_rreg(&hc_regs->hcchar);
	if (hcchar.b.chen == 0)
	{
		/*
		 * The channel is either already halted or it hasn't
		 * started yet. In DMA mode, the transfer may halt if
		 * it finishes normally or a condition occurs that
		 * requires driver intervention. Don't want to halt
		 * the channel again. In either Slave or DMA mode,
		 * it's possible that the transfer has been assigned
		 * to a channel, but not started yet when an URB is
		 * dequeued. Don't want to halt a channel that hasn't
		 * started yet.
		 */
		_ifxhc->phase=HC_IDLE;
		return -1;
	}

	if (_ifxhc->phase==HC_STOPPING)
	{
		/*
		 * A halt has already been issued for this channel. This might
		 * happen when a transfer is aborted by a higher level in
		 * the stack.
		 */
		#ifdef __DEBUG__
			IFX_PRINT("*** %s: Channel %d, double halt a channel***\n",
				  __func__, _ifxhc->hc_num);
		#endif
		return 0;
	}
	hcchar.d32 = ifxusb_rreg(&hc_regs->hcchar);
	hcchar.b.chen = 1;
	hcchar.b.chdis = 1;

	ifxusb_wreg(&hc_regs->hcchar, hcchar.d32);

	_ifxhc->halt_status = _halt_status;
	_ifxhc->phase=HC_STOPPING;

	IFX_DEBUGPL(DBG_HCDV, "%s: Channel %d\n" , __func__, _ifxhc->hc_num);
	IFX_DEBUGPL(DBG_HCDV, "  hcchar: 0x%08x\n"   , hcchar.d32);
	IFX_DEBUGPL(DBG_HCDV, "  halt_status: %d\n"  , _ifxhc->halt_status);

	return 0;
}

/*!
   \brief Clears a host channel.
 */
void ifxhcd_hc_cleanup(ifxusb_core_if_t *_core_if, ifxhcd_hc_t *_ifxhc)
{
	ifxusb_hc_regs_t *hc_regs;

	_ifxhc->phase=HC_IDLE;
	_ifxhc->epqh=0;

	/*
	 * Clear channel interrupt enables and any unhandled channel interrupt
	 * conditions.
	 */
	hc_regs = _core_if->hc_regs[_ifxhc->hc_num];
	ifxusb_wreg(&hc_regs->hcintmsk, 0);
	ifxusb_wreg(&hc_regs->hcint, 0xFFFFFFFF);

	#ifdef __DEBUG__
		{
			hcchar_data_t hcchar;
			hcchar.d32 = ifxusb_rreg(&hc_regs->hcchar);
			if (hcchar.b.chdis)
				IFX_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n", __func__, _ifxhc->hc_num, hcchar.d32);
		}
	#endif
}





#ifdef __DEBUG__
	static void dump_urb_info(struct urb *_urb, char* _fn_name)
	{
		IFX_PRINT("%s, urb %p\n"          , _fn_name, _urb);
		IFX_PRINT("  Device address: %d\n", usb_pipedevice(_urb->pipe));
		IFX_PRINT("  Endpoint: %d, %s\n"  , usb_pipeendpoint(_urb->pipe),
		                                    (usb_pipein(_urb->pipe) ? "IN" : "OUT"));
		IFX_PRINT("  Endpoint type: %s\n",
		    ({	char *pipetype;
		    	switch (usb_pipetype(_urb->pipe)) {
		    		case PIPE_CONTROL:     pipetype = "CONTROL"; break;
		    		case PIPE_BULK:        pipetype = "BULK"; break;
		    		case PIPE_INTERRUPT:   pipetype = "INTERRUPT"; break;
		    		case PIPE_ISOCHRONOUS: pipetype = "ISOCHRONOUS"; break;
		    		default:               pipetype = "UNKNOWN"; break;
		    	};
		    	pipetype;
		    }));
		IFX_PRINT("  Speed: %s\n",
		    ({	char *speed;
		    	switch (_urb->dev->speed) {
		    		case USB_SPEED_HIGH: speed = "HIGH"; break;
		    		case USB_SPEED_FULL: speed = "FULL"; break;
		    		case USB_SPEED_LOW:  speed = "LOW"; break;
		    		default:             speed = "UNKNOWN"; break;
		    	};
		    	speed;
		    }));
		IFX_PRINT("  Max packet size: %d\n",
			  usb_maxpacket(_urb->dev, _urb->pipe, usb_pipeout(_urb->pipe)));
		IFX_PRINT("  Data buffer length: %d\n", _urb->transfer_buffer_length);
		IFX_PRINT("  Transfer buffer: %p, Transfer DMA: %p\n",
			  _urb->transfer_buffer, (void *)_urb->transfer_dma);
		IFX_PRINT("  Setup buffer: %p, Setup DMA: %p\n",
			  _urb->setup_packet, (void *)_urb->setup_dma);
		IFX_PRINT("  Interval: %d\n", _urb->interval);
		if (usb_pipetype(_urb->pipe) == PIPE_ISOCHRONOUS)
		{
			int i;
			for (i = 0; i < _urb->number_of_packets;  i++)
			{
				IFX_PRINT("  ISO Desc %d:\n", i);
				IFX_PRINT("    offset: %d, length %d\n",
				    _urb->iso_frame_desc[i].offset,
				    _urb->iso_frame_desc[i].length);
			}
		}
	}

#if 0
	static void dump_channel_info(ifxhcd_hcd_t *_ifxhcd, ifxhcd_epqh_t *_epqh)
	{
		if (_epqh->hc != NULL)
		{
			ifxhcd_hc_t      *hc = _epqh->hc;
			struct list_head *item;
			ifxhcd_epqh_t      *epqh_item;

			ifxusb_hc_regs_t *hc_regs;

			hcchar_data_t  hcchar;
			hcsplt_data_t  hcsplt;
			hctsiz_data_t  hctsiz;
			uint32_t       hcdma;

			hc_regs = _ifxhcd->core_if.hc_regs[hc->hc_num];
			hcchar.d32 = ifxusb_rreg(&hc_regs->hcchar);
			hcsplt.d32 = ifxusb_rreg(&hc_regs->hcsplt);
			hctsiz.d32 = ifxusb_rreg(&hc_regs->hctsiz);
			hcdma      = ifxusb_rreg(&hc_regs->hcdma);

			IFX_PRINT("  Assigned to channel %d:\n"       , hc->hc_num);
			IFX_PRINT("    hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
			IFX_PRINT("    hctsiz 0x%08x, hcdma 0x%08x\n" , hctsiz.d32, hcdma);
			IFX_PRINT("    dev_addr: %d, ep_num: %d, is_in: %d\n",
			   hc->dev_addr, hc->ep_num, hc->is_in);
			IFX_PRINT("    ep_type: %d\n"        , hc->ep_type);
			IFX_PRINT("    max_packet_size: %d\n", hc->mps);
			IFX_PRINT("    data_pid_start: %d\n" , hc->data_pid_start);
			IFX_PRINT("    halt_status: %d\n"    , hc->halt_status);
			IFX_PRINT("    xfer_buff: %p\n"      , hc->xfer_buff);
			IFX_PRINT("    xfer_len: %d\n"       , hc->xfer_len);
			IFX_PRINT("    epqh: %p\n"           , hc->epqh);
			IFX_PRINT("  NP :\n");
			list_for_each(item, &_ifxhcd->epqh_list_np)
			{
				epqh_item = list_entry(item, ifxhcd_epqh_t, ql);
				IFX_PRINT("    %p\n", epqh_item);
			}
			IFX_PRINT("  INTR :\n");
			list_for_each(item, &_ifxhcd->epqh_list_intr)
			{
				epqh_item = list_entry(item, ifxhcd_epqh_t, ql);
				IFX_PRINT("    %p\n", epqh_item);
			}
			#ifdef __EN_ISOC__
				IFX_PRINT("  ISOC:\n");
				list_for_each(item, &_ifxhcd->epqh_list_isoc)
				{
					epqh_item = list_entry(item, ifxhcd_epqh_t, ql);
					IFX_PRINT("    %p\n", epqh_item);
				}
			#endif
		}
	}
#endif
#endif //__DEBUG__


/*!
   \brief This function writes a packet into the Tx FIFO associated with the Host
  Channel. For a channel associated with a non-periodic EP, the non-periodic
  Tx FIFO is written. For a channel associated with a periodic EP, the
  periodic Tx FIFO is written. This function should only be called in Slave
  mode.

  Upon return the xfer_buff and xfer_count fields in _hc are incremented by
  then number of bytes written to the Tx FIFO.
 */

#ifdef __ENABLE_DUMP__
	void ifxhcd_dump_state(ifxhcd_hcd_t *_ifxhcd)
	{
		int num_channels;
		int i;
		num_channels = _ifxhcd->core_if.params.host_channels;
		IFX_PRINT("\n");
		IFX_PRINT("************************************************************\n");
		IFX_PRINT("HCD State:\n");
		IFX_PRINT("  Num channels: %d\n", num_channels);
		for (i = 0; i < num_channels; i++) {
			ifxhcd_hc_t *hc = &_ifxhcd->ifxhc[i];
			IFX_PRINT("  Channel %d:\n", hc->hc_num);
			IFX_PRINT("    dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
				  hc->dev_addr, hc->ep_num, hc->is_in);
			IFX_PRINT("    speed: %d\n"          , hc->speed);
			IFX_PRINT("    ep_type: %d\n"        , hc->ep_type);
			IFX_PRINT("    mps: %d\n", hc->mps);
			IFX_PRINT("    data_pid_start: %d\n" , hc->data_pid_start);
			IFX_PRINT("    xfer_buff: %p\n"      , hc->xfer_buff);
			IFX_PRINT("    xfer_len: %d\n"       , hc->xfer_len);
			IFX_PRINT("    xfer_count: %d\n"     , hc->xfer_count);
			IFX_PRINT("    halt_status: %d\n"    , hc->halt_status);
			IFX_PRINT("    split: %d\n"          , hc->split);
			IFX_PRINT("    hub_addr: %d\n"       , hc->hub_addr);
			IFX_PRINT("    port_addr: %d\n"      , hc->port_addr);
			#if defined(__EN_ISOC__) && defined(__EN_ISOC_SPLIT__)
				IFX_PRINT("    isoc_xact_pos: %d\n"       , hc->isoc_xact_pos);
			#endif

			IFX_PRINT("    epqh: %p\n"           , hc->epqh);
			IFX_PRINT("    short_rw: %d\n"       , hc->short_rw);
			IFX_PRINT("    control_phase: %d\n"  , hc->control_phase);
			if(hc->epqh)
			{
				IFX_PRINT("    do_ping: %d\n"        , hc->epqh->do_ping);
			}
			IFX_PRINT("    start_pkt_count: %d\n"       , hc->start_pkt_count);
		}
		IFX_PRINT("************************************************************\n");
		IFX_PRINT("\n");
	}
#endif //__ENABLE_DUMP__