aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/lantiq/files/drivers/usb/ifxhcd/ifxusb_ctl.c
blob: ade8e13cb27654c4167761aca8d89842860c73b2 (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
/*****************************************************************************
 **   FILE NAME       : ifxusb_ctl.c
 **   PROJECT         : IFX USB sub-system V3
 **   MODULES         : IFX USB sub-system Host and Device driver
 **   SRC VERSION     : 1.0
 **   DATE            : 1/Jan/2009
 **   AUTHOR          : Chen, Howard
 **   DESCRIPTION     : Implementing the procfs and sysfs for IFX USB driver
 *****************************************************************************/

/*! \file ifxusb_ctl.c
  \ingroup IFXUSB_DRIVER_V3
    \brief Implementing the procfs and sysfs for IFX USB driver
*/

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


#include <linux/proc_fs.h>
#include <asm/byteorder.h>
#include <asm/unaligned.h>
#include <asm/uaccess.h>

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

#ifdef __IS_DEVICE__
	#include "ifxpcd.h"
#endif

#ifdef __IS_HOST__
	#include "ifxhcd.h"
#endif

#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/gfp.h>


#ifdef __IS_HOST__
	extern char ifxusb_driver_name[];

	#ifdef __IS_DUAL__
		extern ifxhcd_hcd_t ifxusb_hcd_1;
		extern ifxhcd_hcd_t ifxusb_hcd_2;
		extern char ifxusb_hcd_name_1[];
		extern char ifxusb_hcd_name_2[];
	#else
		extern ifxhcd_hcd_t ifxusb_hcd;
		extern char ifxusb_hcd_name[];
	#endif

#endif

#ifdef __IS_DEVICE__
	extern char ifxusb_driver_name[];

	extern ifxpcd_pcd_t ifxusb_pcd;
	extern char ifxusb_pcd_name[];
#endif


//Attributes for sysfs (for 2.6 only)

extern struct device_attribute dev_attr_dbglevel;

#ifdef __IS_DUAL__
	extern struct device_attribute dev_attr_dump_params_1;
	extern struct device_attribute dev_attr_dump_params_2;
#else
	extern struct device_attribute dev_attr_dump_params;
#endif

#ifdef __IS_DUAL__
	extern struct device_attribute dev_attr_mode_1;
	extern struct device_attribute dev_attr_mode_2;
#else
	extern struct device_attribute dev_attr_mode;
#endif

#ifdef __IS_HOST__
	#ifdef __IS_DUAL__
		extern struct device_attribute dev_attr_buspower_1;
		extern struct device_attribute dev_attr_buspower_2;
		extern struct device_attribute dev_attr_bussuspend_1;
		extern struct device_attribute dev_attr_bussuspend_2;
		extern struct device_attribute dev_attr_busconnected_1;
		extern struct device_attribute dev_attr_busconnected_2;
		extern struct device_attribute dev_attr_connectspeed_1;
		extern struct device_attribute dev_attr_connectspeed_1;
	#else
		extern struct device_attribute dev_attr_buspower;
		extern struct device_attribute dev_attr_bussuspend;
		extern struct device_attribute dev_attr_busconnected;
		extern struct device_attribute dev_attr_connectspeed;
	#endif
#endif //__IS_HOST__

#ifdef __IS_DEVICE__
	extern struct device_attribute dev_attr_devspeed;
	extern struct device_attribute dev_attr_enumspeed;
#endif //__IS_DEVICE__

#ifdef __ENABLE_DUMP__
	#ifdef __IS_DUAL__
		extern struct device_attribute dev_attr_dump_reg_1;
		extern struct device_attribute dev_attr_dump_reg_2;
		extern struct device_attribute dev_attr_dump_spram_1;
		extern struct device_attribute dev_attr_dump_spram_2;
		#ifdef __IS_HOST__
			extern struct device_attribute dev_attr_dump_host_state_1;
			extern struct device_attribute dev_attr_dump_host_state_2;
		#else
		#endif
	#else
		extern struct device_attribute dev_attr_dump_reg;
		extern struct device_attribute dev_attr_dump_spram;
		#ifdef __IS_HOST__
			extern struct device_attribute dev_attr_dump_host_state;
		#else
		#endif
	#endif
#endif //__ENABLE_DUMP__


/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////

static ssize_t procfs_dbglevel_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
{
	#ifdef __IS_HOST__
		return sprintf( buf, "%08X\n",h_dbg_lvl );
	#else
		return sprintf( buf, "%08X\n",d_dbg_lvl );
	#endif
}

static ssize_t procfs_dbglevel_store(struct file *file, const char *buffer, unsigned long count, void *data)
{
	char buf[10];
	int i = 0;
	uint32_t value;
	if (copy_from_user(buf, &buffer[i], sizeof("0xFFFFFFFF\n")+1))
		return -EFAULT;
	value = simple_strtoul(buf, NULL, 16);
	#ifdef __IS_HOST__
		h_dbg_lvl =value;
	#else
		d_dbg_lvl =value;
	#endif
		//turn on and off power
	return count;
}

#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
	static ssize_t sysfs_dbglevel_show( struct device *_dev, struct device_attribute *attr,char *buf)
#else
	static ssize_t sysfs_dbglevel_show( struct device *_dev,                               char *buf)
#endif
{
	#ifdef __IS_HOST__
		return sprintf( buf, "%08X\n",h_dbg_lvl );
	#else
		return sprintf( buf, "%08X\n",d_dbg_lvl );
	#endif
}

#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
	static ssize_t sysfs_dbglevel_store( struct device *_dev, struct device_attribute *attr,const char *buffer, size_t count )
#else
    static ssize_t sysfs_dbglevel_store( struct device *_dev,                               const char *buffer, size_t count )
#endif
{
	char buf[10];
	int i = 0;
	uint32_t value;
	if (copy_from_user(buf, &buffer[i], sizeof("0xFFFFFFFF\n")+1))
		return -EFAULT;
	value = simple_strtoul(buf, NULL, 16);
	#ifdef __IS_HOST__
		h_dbg_lvl =value;
	#else
		d_dbg_lvl =value;
	#endif
		//turn on and off power
	return count;
}

DEVICE_ATTR(dbglevel, S_IRUGO|S_IWUSR, sysfs_dbglevel_show, sysfs_dbglevel_store);


/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////

static void ifxusb_dump_params(ifxusb_core_if_t *_core_if);

#ifdef __IS_DUAL__
	static void dump_params_1(void)
	{
		ifxusb_dump_params(&ifxusb_hcd_1.core_if);
	}
	static void dump_params_2(void)
	{
		ifxusb_dump_params(&ifxusb_hcd_2.core_if);
	}

	static ssize_t procfs_dump_params_show_1(char *buf, char **start, off_t offset, int count, int *eof, void *data)
	{
		dump_params_1();
		return 0;
	}
	static ssize_t procfs_dump_params_show_2(char *buf, char **start, off_t offset, int count, int *eof, void *data)
	{
		dump_params_2();
		return 0;
	}

	#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
		static ssize_t sysfs_dump_params_show_1( struct device *_dev, struct device_attribute *attr,char *buf)
	#else
		static ssize_t sysfs_dump_params_show_1( struct device *_dev,char *buf)
	#endif
	{
		dump_params_1();
		return 0;
	}
	DEVICE_ATTR(dump_params_1, S_IRUGO|S_IWUSR, sysfs_dump_params_show_1, NULL);

	#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
		static ssize_t sysfs_dump_params_show_2( struct device *_dev, struct device_attribute *attr,char *buf)
	#else
		static ssize_t sysfs_dump_params_show_2( struct device *_dev,char *buf)
	#endif
	{
		dump_params_2();
		return 0;
	}

	DEVICE_ATTR(dump_params_2, S_IRUGO|S_IWUSR, sysfs_dump_params_show_2, NULL);
#else
	static void dump_params(void)
	{
		#ifdef __IS_HOST__
			ifxusb_dump_params(&ifxusb_hcd.core_if);
		#else
			ifxusb_dump_params(&ifxusb_pcd.core_if);
		#endif
	}

	static ssize_t procfs_dump_params_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
	{
		dump_params();
		return 0;
	}

	#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
		static ssize_t sysfs_dump_params_show( struct device *_dev, struct device_attribute *attr,char *buf)
	#else
		static ssize_t sysfs_dump_params_show( struct device *_dev,char *buf)
	#endif
	{
		dump_params();
		return 0;
	}
	DEVICE_ATTR(dump_params, S_IRUGO|S_IWUSR, sysfs_dump_params_show, NULL);
#endif

/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////

#ifdef __IS_DUAL__
	static ssize_t mode_show_1(char *buf)
	{
		if((ifxusb_rreg(&ifxusb_hcd_1.core_if.core_global_regs->gintsts ) & 0x1) == 1)
			return sprintf( buf, "HOST\n" );
		else
			return sprintf( buf, "DEVICE(INCORRECT!)\n" );
	}

	static ssize_t mode_show_2(char *buf)
	{
		if((ifxusb_rreg(&ifxusb_hcd_2.core_if.core_global_regs->gintsts ) & 0x1) == 1)
			return sprintf( buf, "HOST\n" );
		else
			return sprintf( buf, "DEVICE(INCORRECT!)\n" );
	}

	static ssize_t procfs_mode_show_1(char *buf, char **start, off_t offset, int count, int *eof, void *data)
	{
		return mode_show_1(buf);
	}
	static ssize_t procfs_mode_show_2(char *buf, char **start, off_t offset, int count, int *eof, void *data)
	{
		return mode_show_2(buf);
	}

	#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
		static ssize_t sysfs_mode_show_1( struct device *_dev, struct device_attribute *attr,char *buf)
	#else
		static ssize_t sysfs_mode_show_1( struct device *_dev,char *buf)
	#endif
	{
		return mode_show_1(buf);
	}

	DEVICE_ATTR(mode_1, S_IRUGO|S_IWUSR, sysfs_mode_show_1, 0);

	#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
		static ssize_t sysfs_mode_show_2( struct device *_dev, struct device_attribute *attr,char *buf)
	#else
		static ssize_t sysfs_mode_show_2( struct device *_dev,char *buf)
	#endif
	{
		return mode_show_2(buf);
	}
	DEVICE_ATTR(mode_2, S_IRUGO|S_IWUSR, sysfs_mode_show_2, NULL);
#else
	static ssize_t mode_show(char *buf)
	{
		#ifdef __IS_HOST__
			if((ifxusb_rreg(&ifxusb_hcd.core_if.core_global_regs->gintsts ) & 0x1) == 1)
				return sprintf( buf, "HOST\n" );
			else
				return sprintf( buf, "DEVICE(INCORRECT!)\n" );
		#else
			if((ifxusb_rreg(&ifxusb_pcd.core_if.core_global_regs->gintsts ) & 0x1) != 1)
				return sprintf( buf, "DEVICE\n" );
			else
				return sprintf( buf, "HOST(INCORRECT!)\n" );
		#endif
	}
	static ssize_t procfs_mode_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
	{
		return mode_show(buf);
	}
	#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
		static ssize_t sysfs_mode_show( struct device *_dev, struct device_attribute *attr,char *buf)
	#else
		static ssize_t sysfs_mode_show( struct device *_dev,                               char *buf)
	#endif
	{
		return mode_show(buf);
	}
	DEVICE_ATTR(mode, S_IRUGO|S_IWUSR, sysfs_mode_show, NULL);
#endif

/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////

#ifdef __IS_HOST__
	#ifdef __IS_DUAL__
		static ssize_t buspower_show_1(char *buf)
		{
			if(ifxusb_vbus (&ifxusb_hcd_1.core_if)==1) return sprintf( buf, "1\n" );
			if(ifxusb_vbus (&ifxusb_hcd_1.core_if)==0) return sprintf( buf, "0\n" );
			return sprintf( buf, "UNKNOWN\n" );
		}
		static void buspower_store_1(uint32_t value)
		{
			if     (value==1)  ifxusb_vbus_on (&ifxusb_hcd_1.core_if);
			else if(value==0)  ifxusb_vbus_off(&ifxusb_hcd_1.core_if);
		}
		static ssize_t buspower_show_2(char *buf)
		{
			if(ifxusb_vbus (&ifxusb_hcd_2.core_if)==1) return sprintf( buf, "1\n" );
			if(ifxusb_vbus (&ifxusb_hcd_2.core_if)==0) return sprintf( buf, "0\n" );
			return sprintf( buf, "UNKNOWN\n" );
		}
		static void buspower_store_2(uint32_t value)
		{
			if     (value==1)  ifxusb_vbus_on (&ifxusb_hcd_2.core_if);
			else if(value==0)  ifxusb_vbus_off(&ifxusb_hcd_2.core_if);
		}
		static ssize_t procfs_buspower_show_1(char *buf, char **start, off_t offset, int count, int *eof, void *data)
		{
			return buspower_show_1(buf);
		}
		static ssize_t procfs_buspower_store_1(struct file *file, const char *buffer, unsigned long count, void *data)
		{
			char buf[10];
			int i = 0;
			uint32_t value;
			if (copy_from_user(buf, &buffer[i], sizeof("0xFFFFFFFF\n")+1))
				return -EFAULT;
			value = simple_strtoul(buf, NULL, 16);
			buspower_store_1(value);
			return count;
		}
		static ssize_t procfs_buspower_show_2(char *buf, char **start, off_t offset, int count, int *eof, void *data)
		{
			return buspower_show_2(buf);
		}
		static ssize_t procfs_buspower_store_2(struct file *file, const char *buffer, unsigned long count, void *data)
		{
			char buf[10];
			int i = 0;
			uint32_t value;
			if (copy_from_user(buf, &buffer[i], sizeof("0xFFFFFFFF\n")+1))
				return -EFAULT;
			value = simple_strtoul(buf, NULL, 16);
			buspower_store_2(value);
			return count;
		}

		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_buspower_show_1( struct device *_dev, struct device_attribute *attr,char *buf)
		#else
			static ssize_t sysfs_buspower_show_1( struct device *_dev,char *buf)
		#endif
		{
			return buspower_show_1(buf);
		}
		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_buspower_store_1( struct device *_dev, struct device_attribute *attr,const char *buffer, size_t count )
		#else
		    static ssize_t sysfs_buspower_store_1( struct device *_dev,                               const char *buffer, size_t count )
		#endif
		{
			char buf[10];
			int i = 0;
			uint32_t value;
			if (copy_from_user(buf, &buffer[i], sizeof("0xFFFFFFFF\n")+1))
				return -EFAULT;
			value = simple_strtoul(buf, NULL, 16);
			buspower_store_1(value);
			return count;
		}
		DEVICE_ATTR(buspower_1, S_IRUGO|S_IWUSR, sysfs_buspower_show_1, sysfs_buspower_store_1);

		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_buspower_show_2( struct device *_dev, struct device_attribute *attr,char *buf)
		#else
			static ssize_t sysfs_buspower_show_2( struct device *_dev,char *buf)
		#endif
		{
			return buspower_show_2(buf);
		}
		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_buspower_store_2( struct device *_dev, struct device_attribute *attr,const char *buffer, size_t count )
		#else
		    static ssize_t sysfs_buspower_store_2( struct device *_dev,                               const char *buffer, size_t count )
		#endif
		{
			char buf[10];
			int i = 0;
			uint32_t value;
			if (copy_from_user(buf, &buffer[i], sizeof("0xFFFFFFFF\n")+1))
				return -EFAULT;
			value = simple_strtoul(buf, NULL, 16);
			buspower_store_2(value);
			return count;
		}
		DEVICE_ATTR(buspower_2, S_IRUGO|S_IWUSR, sysfs_buspower_show_2, sysfs_buspower_store_2);
	#else
		static ssize_t buspower_show(char *buf)
		{
			if(ifxusb_vbus (&ifxusb_hcd.core_if)==1) return sprintf( buf, "1\n" );
			if(ifxusb_vbus (&ifxusb_hcd.core_if)==0) return sprintf( buf, "0\n" );
			return sprintf( buf, "UNKNOWN\n" );
		}
		static void buspower_store(uint32_t value)
		{
			if     (value==1)  ifxusb_vbus_on (&ifxusb_hcd.core_if);
			else if(value==0)  ifxusb_vbus_off(&ifxusb_hcd.core_if);
		}
		static ssize_t procfs_buspower_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
		{
			return buspower_show(buf);
		}
		static ssize_t procfs_buspower_store(struct file *file, const char *buffer, unsigned long count, void *data)
		{
			char buf[10];
			int i = 0;
			uint32_t value;
			if (copy_from_user(buf, &buffer[i], sizeof("0xFFFFFFFF\n")+1))
				return -EFAULT;
			value = simple_strtoul(buf, NULL, 16);
			buspower_store(value);
			return count;
		}
		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_buspower_show( struct device *_dev, struct device_attribute *attr,char *buf)
		#else
			static ssize_t sysfs_buspower_show( struct device *_dev,                               char *buf)
		#endif
		{
			return buspower_show(buf);
		}
		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_buspower_store( struct device *_dev, struct device_attribute *attr,const char *buffer, size_t count )
		#else
		    static ssize_t sysfs_buspower_store( struct device *_dev,                               const char *buffer, size_t count )
		#endif
		{
			char buf[10];
			int i = 0;
			uint32_t value;
			if (copy_from_user(buf, &buffer[i], sizeof("0xFFFFFFFF\n")+1))
				return -EFAULT;
			value = simple_strtoul(buf, NULL, 16);
			buspower_store(value);
			return count;
		}
		DEVICE_ATTR(buspower, S_IRUGO|S_IWUSR, sysfs_buspower_show, sysfs_buspower_store);
	#endif

/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////


	#ifdef __IS_DUAL__
		static ssize_t bussuspend_show_1(char *buf)
		{
			hprt0_data_t val;
			val.d32 = ifxusb_rreg(ifxusb_hcd_1.core_if.hprt0);
			return sprintf (buf, "Bus Suspend = 0x%x\n", val.b.prtsusp);
		}
		static ssize_t bussuspend_show_2(char *buf)
		{
			hprt0_data_t val;
			val.d32 = ifxusb_rreg(ifxusb_hcd_2.core_if.hprt0);
			return sprintf (buf, "Bus Suspend = 0x%x\n", val.b.prtsusp);
		}

		static ssize_t procfs_bussuspend_show_1(char *buf, char **start, off_t offset, int count, int *eof, void *data)
		{
			return bussuspend_show_1(buf);
		}
		static ssize_t procfs_bussuspend_show_2(char *buf, char **start, off_t offset, int count, int *eof, void *data)
		{
			return bussuspend_show_2(buf);
		}
		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_bussuspend_show_1( struct device *_dev, struct device_attribute *attr,char *buf)
		#else
			static ssize_t sysfs_bussuspend_show_1( struct device *_dev,char *buf)
		#endif
		{
			return bussuspend_show_1(buf);
		}
		DEVICE_ATTR(bussuspend_1, S_IRUGO|S_IWUSR, sysfs_bussuspend_show_1, 0);
		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_bussuspend_show_2( struct device *_dev, struct device_attribute *attr,char *buf)
		#else
			static ssize_t sysfs_bussuspend_show_2( struct device *_dev,char *buf)
		#endif
		{
			return bussuspend_show_2(buf);
		}
		DEVICE_ATTR(bussuspend_2, S_IRUGO|S_IWUSR, sysfs_bussuspend_show_2, 0);
	#else
		static ssize_t bussuspend_show(char *buf)
		{
			hprt0_data_t val;
			val.d32 = ifxusb_rreg(ifxusb_hcd.core_if.hprt0);
			return sprintf (buf, "Bus Suspend = 0x%x\n", val.b.prtsusp);
		}
		static ssize_t procfs_bussuspend_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
		{
			return bussuspend_show(buf);
		}

		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_bussuspend_show( struct device *_dev, struct device_attribute *attr,char *buf)
		#else
			static ssize_t sysfs_bussuspend_show( struct device *_dev,                               char *buf)
		#endif
		{
			return bussuspend_show(buf);
		}
		DEVICE_ATTR(bussuspend, S_IRUGO|S_IWUSR, sysfs_bussuspend_show, 0);
	#endif

/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////

	#ifdef __IS_DUAL__
		static ssize_t busconnected_show_1(char *buf)
		{
			hprt0_data_t val;
			val.d32 = ifxusb_rreg(ifxusb_hcd_1.core_if.hprt0);
			return sprintf (buf, "Bus Connected = 0x%x\n", val.b.prtconnsts);
		}
		static ssize_t busconnected_show_2(char *buf)
		{
			hprt0_data_t val;
			val.d32 = ifxusb_rreg(ifxusb_hcd_2.core_if.hprt0);
			return sprintf (buf, "Bus Connected = 0x%x\n", val.b.prtconnsts);
		}

		static ssize_t procfs_busconnected_show_1(char *buf, char **start, off_t offset, int count, int *eof, void *data)
		{
			return busconnected_show_1(buf);
		}
		static ssize_t procfs_busconnected_show_2(char *buf, char **start, off_t offset, int count, int *eof, void *data)
		{
			return busconnected_show_2(buf);
		}
		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_busconnected_show_1( struct device *_dev, struct device_attribute *attr,char *buf)
		#else
			static ssize_t sysfs_busconnected_show_1( struct device *_dev,char *buf)
		#endif
		{
			return busconnected_show_1(buf);
		}
		DEVICE_ATTR(busconnected_1, S_IRUGO|S_IWUSR, sysfs_busconnected_show_1, 0);
		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_busconnected_show_2( struct device *_dev, struct device_attribute *attr,char *buf)
		#else
			static ssize_t sysfs_busconnected_show_2( struct device *_dev,char *buf)
		#endif
		{
			return busconnected_show_2(buf);
		}
		DEVICE_ATTR(busconnected_2, S_IRUGO|S_IWUSR, sysfs_busconnected_show_2, 0);
	#else
		static ssize_t busconnected_show(char *buf)
		{
			hprt0_data_t val;
			val.d32 = ifxusb_rreg(ifxusb_hcd.core_if.hprt0);
			return sprintf (buf, "Bus Connected = 0x%x\n", val.b.prtconnsts);
		}
		static ssize_t procfs_busconnected_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
		{
			return busconnected_show(buf);
		}

		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_busconnected_show( struct device *_dev, struct device_attribute *attr,char *buf)
		#else
			static ssize_t sysfs_busconnected_show( struct device *_dev,                               char *buf)
		#endif
		{
			return busconnected_show(buf);
		}
		DEVICE_ATTR(busconnected, S_IRUGO|S_IWUSR, sysfs_busconnected_show, 0);
	#endif

/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////

	#ifdef __IS_DUAL__
		static ssize_t connectspeed_show_1(char *buf)
		{
			hprt0_data_t val;
			val.d32 = ifxusb_rreg(ifxusb_hcd_1.core_if.hprt0);
			if( val.b.prtspd ==0) return sprintf (buf, "Bus Speed = High (%d)\n", val.b.prtspd);
			if( val.b.prtspd ==1) return sprintf (buf, "Bus Speed = Full (%d)\n", val.b.prtspd);
			if( val.b.prtspd ==2) return sprintf (buf, "Bus Speed = Low  (%d)\n", val.b.prtspd);
			                      return sprintf (buf, "Bus Speed = Unknown (%d)\n", val.b.prtspd);
		}
		static ssize_t connectspeed_show_2(char *buf)
		{
			hprt0_data_t val;
			val.d32 = ifxusb_rreg(ifxusb_hcd_2.core_if.hprt0);
			if( val.b.prtspd ==0) return sprintf (buf, "Bus Speed = High (%d)\n", val.b.prtspd);
			if( val.b.prtspd ==1) return sprintf (buf, "Bus Speed = Full (%d)\n", val.b.prtspd);
			if( val.b.prtspd ==2) return sprintf (buf, "Bus Speed = Low  (%d)\n", val.b.prtspd);
			                      return sprintf (buf, "Bus Speed = Unknown (%d)\n", val.b.prtspd);
		}

		static ssize_t procfs_connectspeed_show_1(char *buf, char **start, off_t offset, int count, int *eof, void *data)
		{
			return connectspeed_show_1(buf);
		}
		static ssize_t procfs_connectspeed_show_2(char *buf, char **start, off_t offset, int count, int *eof, void *data)
		{
			return connectspeed_show_2(buf);
		}
		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_connectspeed_show_1( struct device *_dev, struct device_attribute *attr,char *buf)
		#else
			static ssize_t sysfs_connectspeed_show_1( struct device *_dev,char *buf)
		#endif
		{
			return connectspeed_show_1(buf);
		}
		DEVICE_ATTR(connectspeed_1, S_IRUGO|S_IWUSR, sysfs_connectspeed_show_1, 0);
		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_connectspeed_show_2( struct device *_dev, struct device_attribute *attr,char *buf)
		#else
			static ssize_t sysfs_connectspeed_show_2( struct device *_dev,char *buf)
		#endif
		{
			return connectspeed_show_2(buf);
		}
		DEVICE_ATTR(connectspeed_2, S_IRUGO|S_IWUSR, sysfs_connectspeed_show_2, 0);
	#else
		static ssize_t connectspeed_show(char *buf)
		{
			hprt0_data_t val;
			val.d32 = ifxusb_rreg(ifxusb_hcd.core_if.hprt0);
			if( val.b.prtspd ==0) return sprintf (buf, "Bus Speed = High (%d)\n", val.b.prtspd);
			if( val.b.prtspd ==1) return sprintf (buf, "Bus Speed = Full (%d)\n", val.b.prtspd);
			if( val.b.prtspd ==2) return sprintf (buf, "Bus Speed = Low  (%d)\n", val.b.prtspd);
			                      return sprintf (buf, "Bus Speed = Unknown (%d)\n", val.b.prtspd);
		}

		static ssize_t procfs_connectspeed_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
		{
			return connectspeed_show(buf);
		}

		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_connectspeed_show( struct device *_dev, struct device_attribute *attr,char *buf)
		#else
			static ssize_t sysfs_connectspeed_show( struct device *_dev,                               char *buf)
		#endif
		{
			return connectspeed_show(buf);
		}
		DEVICE_ATTR(connectspeed, S_IRUGO|S_IWUSR, sysfs_connectspeed_show, 0);
	#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
#endif


#ifdef __IS_DEVICE__
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
	static ssize_t devspeed_show(char *buf)
	{
		dcfg_data_t val;
		val.d32 = ifxusb_rreg(&ifxusb_pcd.core_if.dev_global_regs->dcfg);
		if( val.b.devspd ==0) return sprintf (buf, "Dev Speed = High (%d)\n", val.b.devspd);
		if( val.b.devspd ==1) return sprintf (buf, "Dev Speed = Full (%d)\n", val.b.devspd);
		if( val.b.devspd ==3) return sprintf (buf, "Dev Speed = Full (%d)\n", val.b.devspd);
		                      return sprintf (buf, "Dev Speed = Unknown (%d)\n", val.b.devspd);
	}

	static ssize_t procfs_devspeed_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
	{
		return devspeed_show(buf);
	}

	#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
		static ssize_t sysfs_devspeed_show( struct device *_dev, struct device_attribute *attr,char *buf)
	#else
		static ssize_t sysfs_devspeed_show( struct device *_dev,                               char *buf)
	#endif
	{
		return devspeed_show(buf);
	}
	DEVICE_ATTR(devspeed, S_IRUGO|S_IWUSR, sysfs_devspeed_show, 0);

	static ssize_t enumspeed_show(char *buf)
	{
		dsts_data_t val;
		val.d32 = ifxusb_rreg(&ifxusb_pcd.core_if.dev_global_regs->dsts);
		if( val.b.enumspd ==0) return sprintf (buf, "Enum Speed = High (%d)\n", val.b.enumspd);
		if( val.b.enumspd ==1) return sprintf (buf, "Enum Speed = Full (%d)\n", val.b.enumspd);
		if( val.b.enumspd ==2) return sprintf (buf, "Enum Speed = Low  (%d)\n", val.b.enumspd);
		return sprintf (buf, "Enum Speed = invalid(%d)\n", val.b.enumspd);
	}

	static ssize_t procfs_enumspeed_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
	{
		return enumspeed_show(buf);
	}

	#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
		static ssize_t sysfs_enumspeed_show( struct device *_dev, struct device_attribute *attr,char *buf)
	#else
		static ssize_t sysfs_enumspeed_show( struct device *_dev,                               char *buf)
	#endif
	{
		return enumspeed_show(buf);
	}
	DEVICE_ATTR(enumspeed, S_IRUGO|S_IWUSR, sysfs_enumspeed_show, 0);
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
#endif


//////////////////////////////////////////////////////////////////////////////////
#ifdef __ENABLE_DUMP__

	#ifdef __IS_DUAL__
		static void dump_reg_1(void)
		{
			ifxusb_dump_registers(&ifxusb_hcd_1.core_if);
		}
		static void dump_reg_2(void)
		{
			ifxusb_dump_registers(&ifxusb_hcd_2.core_if);
		}

		static ssize_t procfs_dump_reg_show_1(char *buf, char **start, off_t offset, int count, int *eof, void *data)
		{
			dump_reg_1();
			return 0;
		}
		static ssize_t procfs_dump_reg_show_2(char *buf, char **start, off_t offset, int count, int *eof, void *data)
		{
			dump_reg_2();
			return 0;
		}
		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_dump_reg_show_1( struct device *_dev, struct device_attribute *attr,char *buf)
		#else
			static ssize_t sysfs_dump_reg_show_1( struct device *_dev,char *buf)
		#endif
		{
			dump_reg_1();
			return 0;
		}
		DEVICE_ATTR(dump_reg_1, S_IRUGO|S_IWUSR, sysfs_dump_reg_show_1, 0);
		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_dump_reg_show_2( struct device *_dev, struct device_attribute *attr,char *buf)
		#else
			static ssize_t sysfs_dump_reg_show_2( struct device *_dev,char *buf)
		#endif
		{
			dump_reg_2();
			return 0;
		}
		DEVICE_ATTR(dump_reg_2, S_IRUGO|S_IWUSR, sysfs_dump_reg_show_2, 0);
	#else
		static void dump_reg(void)
		{
			#ifdef __IS_HOST__
				ifxusb_dump_registers(&ifxusb_hcd.core_if);
			#endif
			#ifdef __IS_DEVICE__
				ifxusb_dump_registers(&ifxusb_pcd.core_if);
			#endif
		}
		static ssize_t procfs_dump_reg_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
		{
			dump_reg();
			return 0;
		}
		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_dump_reg_show( struct device *_dev, struct device_attribute *attr,char *buf)
		#else
			static ssize_t sysfs_dump_reg_show( struct device *_dev,char *buf)
		#endif
		{
			dump_reg();
			return 0;
		}
		DEVICE_ATTR(dump_reg, S_IRUGO|S_IWUSR, sysfs_dump_reg_show, 0);
	#endif


/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////

	#ifdef __IS_DUAL__
		static void dump_spram_1(void)
		{
			ifxusb_dump_spram(&ifxusb_hcd_1.core_if);
		}
		static void dump_spram_2(void)
		{
			ifxusb_dump_spram(&ifxusb_hcd_2.core_if);
		}

		static ssize_t procfs_dump_spram_show_1(char *buf, char **start, off_t offset, int count, int *eof, void *data)
		{
			dump_spram_1();
			return 0;
		}
		static ssize_t procfs_dump_spram_show_2(char *buf, char **start, off_t offset, int count, int *eof, void *data)
		{
			dump_spram_2();
			return 0;
		}
		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_dump_spram_show_1( struct device *_dev, struct device_attribute *attr,char *buf)
		#else
			static ssize_t sysfs_dump_spram_show_1( struct device *_dev,char *buf)
		#endif
		{
			dump_spram_1();
			return 0;
		}
		DEVICE_ATTR(dump_spram_1, S_IRUGO|S_IWUSR, sysfs_dump_spram_show_1, 0);

		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_dump_spram_show_2( struct device *_dev, struct device_attribute *attr,char *buf)
		#else
			static ssize_t sysfs_dump_spram_show_2( struct device *_dev,char *buf)
		#endif
		{
			dump_spram_2();
			return 0;
		}
		DEVICE_ATTR(dump_spram_2, S_IRUGO|S_IWUSR, sysfs_dump_spram_show_2, 0);
	#else
		static void dump_spram(void)
		{
			#ifdef __IS_HOST__
				ifxusb_dump_spram(&ifxusb_hcd.core_if);
			#endif
			#ifdef __IS_DEVICE__
				ifxusb_dump_spram(&ifxusb_pcd.core_if);
			#endif
		}
		static ssize_t procfs_dump_spram_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
		{
			dump_spram();
			return 0;
		}
		#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
			static ssize_t sysfs_dump_spram_show( struct device *_dev, struct device_attribute *attr,char *buf)
		#else
			static ssize_t sysfs_dump_spram_show( struct device *_dev,char *buf)
		#endif
		{
			dump_spram();
			return 0;
		}
		DEVICE_ATTR(dump_spram, S_IRUGO|S_IWUSR, sysfs_dump_spram_show, 0);
	#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////

	#ifdef __IS_HOST__
		#ifdef __IS_DUAL__
			static ssize_t procfs_dump_host_state_show_1(char *buf, char **start, off_t offset, int count, int *eof, void *data)
			{
				ifxhcd_dump_state(&ifxusb_hcd_1);
				return 0;
			}
			static ssize_t procfs_dump_host_state_show_2(char *buf, char **start, off_t offset, int count, int *eof, void *data)
			{
				ifxhcd_dump_state(&ifxusb_hcd_2);
				return 0;
			}
			#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
				static ssize_t sysfs_dump_host_state_show_1( struct device *_dev, struct device_attribute *attr,char *buf)
			#else
				static ssize_t sysfs_dump_host_state_show_1( struct device *_dev,char *buf)
			#endif
			{
				ifxhcd_dump_state(&ifxusb_hcd_1);
				return 0;
			}
			DEVICE_ATTR(dump_host_state_1, S_IRUGO|S_IWUSR, sysfs_dump_host_state_show_1, 0);
			#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
				static ssize_t sysfs_dump_host_state_show_2( struct device *_dev, struct device_attribute *attr,char *buf)
			#else
				static ssize_t sysfs_dump_host_state_show_2( struct device *_dev,char *buf)
			#endif
			{
				ifxhcd_dump_state(&ifxusb_hcd_2);
				return 0;
			}
			DEVICE_ATTR(dump_host_state_2, S_IRUGO|S_IWUSR, sysfs_dump_host_state_show_2, 0);
		#else
			static ssize_t procfs_dump_host_state_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
			{
				ifxhcd_dump_state(&ifxusb_hcd);
				return 0;
			}
			#if   LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
				static ssize_t sysfs_dump_host_state_show( struct device *_dev, struct device_attribute *attr,char *buf)
			#else
				static ssize_t sysfs_dump_host_state_show( struct device *_dev,char *buf)
			#endif
			{
				ifxhcd_dump_state(&ifxusb_hcd);
				return 0;
			}
			DEVICE_ATTR(dump_host_state, S_IRUGO|S_IWUSR, sysfs_dump_host_state_show, 0);
		#endif

/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////

	#endif //IS_HOST_

#endif //__ENABLE_DUMP__

//////////////////////////////////////////////////////////////////////////////////

static int  ifx_proc_addproc(char *funcname, read_proc_t *hookfuncr, write_proc_t *hookfuncw);
static void ifx_proc_delproc(char *funcname);

//////////////////////////////////////////////////////////////////////////////////

/*!
  \brief This function create the sysfs and procfs entries
  \param[in] _dev Pointer of device structure, if applied
 */
void ifxusb_attr_create (void *_dev)
{
	int error;

	struct device *dev = (struct device *) _dev;

	IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
	error = ifx_proc_addproc("dbglevel", procfs_dbglevel_show, procfs_dbglevel_store);
	error = device_create_file(dev, &dev_attr_dbglevel);

	#ifdef __IS_DUAL__
		error = ifx_proc_addproc("dump_params_1", procfs_dump_params_show_1, NULL);
		error = ifx_proc_addproc("dump_params_2", procfs_dump_params_show_2, NULL);
		error = device_create_file(dev, &dev_attr_dump_params_1);
		error = device_create_file(dev, &dev_attr_dump_params_2);
	#else
		error = ifx_proc_addproc("dump_params", procfs_dump_params_show, NULL);
		error = device_create_file(dev, &dev_attr_dump_params);
	#endif

	#ifdef __IS_DUAL__
		error = ifx_proc_addproc("mode_1", procfs_mode_show_1, NULL);
		error = ifx_proc_addproc("mode_2", procfs_mode_show_2, NULL);
		error = device_create_file(dev, &dev_attr_mode_1);
		error = device_create_file(dev, &dev_attr_mode_2);
	#else
		error = ifx_proc_addproc("mode", procfs_mode_show, NULL);
		error = device_create_file(dev, &dev_attr_mode);
	#endif

	#ifdef __IS_HOST__
		#ifdef __IS_DUAL__
			error = ifx_proc_addproc("buspower_1", procfs_buspower_show_1, procfs_buspower_store_1);
			error = ifx_proc_addproc("buspower_2", procfs_buspower_show_2, procfs_buspower_store_2);
			error = device_create_file(dev, &dev_attr_buspower_1);
			error = device_create_file(dev, &dev_attr_buspower_2);
		#else
			error = ifx_proc_addproc("buspower", procfs_buspower_show, procfs_buspower_store);
			error = device_create_file(dev, &dev_attr_buspower);
		#endif

		#ifdef __IS_DUAL__
			error = ifx_proc_addproc("bussuspend_1", procfs_bussuspend_show_1, NULL);
			error = ifx_proc_addproc("bussuspend_2", procfs_bussuspend_show_2, NULL);
			error = device_create_file(dev, &dev_attr_bussuspend_1);
			error = device_create_file(dev, &dev_attr_bussuspend_2);
		#else
			error = ifx_proc_addproc("bussuspend", procfs_bussuspend_show, NULL);
			error = device_create_file(dev, &dev_attr_bussuspend);
		#endif

		#ifdef __IS_DUAL__
			error = ifx_proc_addproc("busconnected_1", procfs_busconnected_show_1, NULL);
			error = ifx_proc_addproc("busconnected_2", procfs_busconnected_show_2, NULL);
			error = device_create_file(dev, &dev_attr_busconnected_1);
			error = device_create_file(dev, &dev_attr_busconnected_2);
		#else
			error = ifx_proc_addproc("busconnected", procfs_busconnected_show, NULL);
			error = device_create_file(dev, &dev_attr_busconnected);
		#endif

		#ifdef __IS_DUAL__
			error = ifx_proc_addproc("connectspeed_1", procfs_connectspeed_show_1, NULL);
			error = ifx_proc_addproc("connectspeed_2", procfs_connectspeed_show_2, NULL);
			error = device_create_file(dev, &dev_attr_connectspeed_1);
			error = device_create_file(dev, &dev_attr_connectspeed_2);
		#else
			error = ifx_proc_addproc("connectspeed", procfs_connectspeed_show, NULL);
			error = device_create_file(dev, &dev_attr_connectspeed);
		#endif
	#endif

	#ifdef __IS_DEVICE__
		error = ifx_proc_addproc("devspeed", procfs_devspeed_show, NULL);
		error = device_create_file(dev, &dev_attr_devspeed);
		error = ifx_proc_addproc("enumspeed", procfs_enumspeed_show, NULL);
		error = device_create_file(dev, &dev_attr_enumspeed);
	#endif

	//////////////////////////////////////////////////////
	#ifdef __ENABLE_DUMP__
		#ifdef __IS_DUAL__
			error = ifx_proc_addproc("dump_reg_1", procfs_dump_reg_show_1, NULL);
			error = ifx_proc_addproc("dump_reg_2", procfs_dump_reg_show_2, NULL);
			error = device_create_file(dev, &dev_attr_dump_reg_1);
			error = device_create_file(dev, &dev_attr_dump_reg_2);
		#else
			error = ifx_proc_addproc("dump_reg", procfs_dump_reg_show, NULL);
			error = device_create_file(dev, &dev_attr_dump_reg);
		#endif

		#ifdef __IS_DUAL__
			error = ifx_proc_addproc("dump_spram_1", procfs_dump_spram_show_1, NULL);
			error = ifx_proc_addproc("dump_spram_2", procfs_dump_spram_show_2, NULL);
			error = device_create_file(dev, &dev_attr_dump_spram_1);
			error = device_create_file(dev, &dev_attr_dump_spram_2);
		#else
			error = ifx_proc_addproc("dump_spram", procfs_dump_spram_show, NULL);
			error = device_create_file(dev, &dev_attr_dump_spram);
		#endif

		#ifdef __IS_HOST__
			#ifdef __IS_DUAL__
				error = ifx_proc_addproc("dump_host_state_1", procfs_dump_host_state_show_1, NULL);
				error = ifx_proc_addproc("dump_host_state_2", procfs_dump_host_state_show_2, NULL);
				error = device_create_file(dev, &dev_attr_dump_host_state_1);
				error = device_create_file(dev, &dev_attr_dump_host_state_2);
			#else
				error = ifx_proc_addproc("dump_host_state", procfs_dump_host_state_show, NULL);
				error = device_create_file(dev, &dev_attr_dump_host_state);
			#endif
		#endif
	#endif //__ENABLE_DUMP__
	//////////////////////////////////////////////////////
}


/*!
  \brief This function remove the sysfs and procfs entries
  \param[in] _dev Pointer of device structure, if applied
 */
void ifxusb_attr_remove (void *_dev)
{
	struct device *dev = (struct device *) _dev;

	IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
	ifx_proc_delproc("dbglevel");
	device_remove_file(dev, &dev_attr_dbglevel);

	#ifdef __IS_DUAL__
		ifx_proc_delproc("dump_params_1");
		ifx_proc_delproc("dump_params_2");
		device_remove_file(dev, &dev_attr_dump_params_1);
		device_remove_file(dev, &dev_attr_dump_params_2);
	#else
		ifx_proc_delproc("dump_params");
		device_remove_file(dev, &dev_attr_dump_params);
	#endif

	#ifdef __IS_DUAL__
		ifx_proc_delproc("mode_1");
		ifx_proc_delproc("mode_2");
		device_remove_file(dev, &dev_attr_mode_1);
		device_remove_file(dev, &dev_attr_mode_2);
	#else
		ifx_proc_delproc("mode");
		device_remove_file(dev, &dev_attr_mode);
	#endif

	#ifdef __IS_HOST__
		#ifdef __IS_DUAL__
			ifx_proc_delproc("buspower_1");
			ifx_proc_delproc("buspower_2");
			device_remove_file(dev, &dev_attr_buspower_1);
			device_remove_file(dev, &dev_attr_buspower_2);
		#else
			ifx_proc_delproc("buspower");
			device_remove_file(dev, &dev_attr_buspower);
		#endif

		#ifdef __IS_DUAL__
			ifx_proc_delproc("bussuspend_1");
			ifx_proc_delproc("bussuspend_2");
			device_remove_file(dev, &dev_attr_bussuspend_1);
			device_remove_file(dev, &dev_attr_bussuspend_2);
		#else
			ifx_proc_delproc("bussuspend");
			device_remove_file(dev, &dev_attr_bussuspend);
		#endif

		#ifdef __IS_DUAL__
			ifx_proc_delproc("busconnected_1");
			ifx_proc_delproc("busconnected_2");
			device_remove_file(dev, &dev_attr_busconnected_1);
			device_remove_file(dev, &dev_attr_busconnected_2);
		#else
			ifx_proc_delproc("busconnected");
			device_remove_file(dev, &dev_attr_busconnected);
		#endif

		#ifdef __IS_DUAL__
			ifx_proc_delproc("connectspeed_1");
			ifx_proc_delproc("connectspeed_2");
			device_remove_file(dev, &dev_attr_connectspeed_1);
			device_remove_file(dev, &dev_attr_connectspeed_2);
		#else
			ifx_proc_delproc("connectspeed");
			device_remove_file(dev, &dev_attr_connectspeed);
		#endif
	#endif

	#ifdef __IS_DEVICE__
		ifx_proc_delproc("devspeed");
		device_remove_file(dev, &dev_attr_devspeed);
		ifx_proc_delproc("enumspeed");
		device_remove_file(dev, &dev_attr_enumspeed);
	#endif

	#ifdef __ENABLE_DUMP__
		#ifdef __IS_DUAL__
			ifx_proc_delproc("dump_reg_1");
			ifx_proc_delproc("dump_reg_2");
			device_remove_file(dev, &dev_attr_dump_reg_1);
			device_remove_file(dev, &dev_attr_dump_reg_2);
		#else
			ifx_proc_delproc("dump_reg");
			device_remove_file(dev, &dev_attr_dump_reg);
		#endif

		#ifdef __IS_DUAL__
			ifx_proc_delproc("dump_spram_1");
			ifx_proc_delproc("dump_spram_2");
			device_remove_file(dev, &dev_attr_dump_spram_1);
			device_remove_file(dev, &dev_attr_dump_spram_2);
		#else
			ifx_proc_delproc("dump_spram");
			device_remove_file(dev, &dev_attr_dump_spram);
		#endif

		#ifdef __IS_HOST__
			#ifdef __IS_DUAL__
				ifx_proc_delproc("dump_host_state_1");
				ifx_proc_delproc("dump_host_state_2");
				device_remove_file(dev, &dev_attr_dump_host_state_1);
				device_remove_file(dev, &dev_attr_dump_host_state_2);
			#else
				ifx_proc_delproc("dump_host_state");
				device_remove_file(dev, &dev_attr_dump_host_state);
			#endif
		#endif
	#endif //__ENABLE_DUMP__
	/* AVM/WK fix: del IFXUSB root dir*/
	ifx_proc_delproc(NULL);
}

static struct proc_dir_entry * proc_ifx_root = NULL;

/* initialize the proc file system and make a dir named /proc/[name] */
static void ifx_proc_init(void)
{
	IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
	proc_ifx_root = proc_mkdir(ifxusb_driver_name, (void *)0);
	if (!proc_ifx_root){
		IFX_PRINT("%s proc initialization failed! \n", ifxusb_driver_name);
		return;
	}
}

/* proc file system add function for debugging. */
static int ifx_proc_addproc(char *funcname, read_proc_t *hookfuncr, write_proc_t *hookfuncw)
{
	struct proc_dir_entry *pe;
	IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
	if (!proc_ifx_root)
		ifx_proc_init();

	if (hookfuncw == NULL)
	{
		pe = create_proc_read_entry(funcname, S_IRUGO, proc_ifx_root, hookfuncr, NULL);
		if (!pe)
		{
			IFX_PRINT("ERROR in creating read proc entry (%s)! \n", funcname);
			return -1;
		}
	}
	else
	{
		pe = create_proc_entry(funcname, S_IRUGO | S_IWUGO, proc_ifx_root);
		if (pe)
		{
			pe->read_proc = hookfuncr;
			pe->write_proc = hookfuncw;
		}
		else
		{
			IFX_PRINT("ERROR in creating proc entry (%s)! \n", funcname);
			return -1;
		}
	}
	return 0;
}


/* proc file system del function for removing module. */
static void ifx_proc_delproc(char *funcname)
{
/* AVM/WK Fix*/
	if (funcname != NULL) {
		remove_proc_entry(funcname, proc_ifx_root);
	} else {
		remove_proc_entry(ifxusb_driver_name, NULL);
		proc_ifx_root = NULL;
	}
}

static void ifxusb_dump_params(ifxusb_core_if_t *_core_if)
{
	ifxusb_params_t *params=&_core_if->params;

	#ifdef __IS_HOST__
		IFX_PRINT("IFXUSB Dump Parameters ( Host Mode) \n");
	#endif //__IS_HOST__
	#ifdef __IS_DEVICE__
		IFX_PRINT("IFXUSB Dump Parameters ( Device Mode) \n");
	#endif //__IS_DEVICE__

	#ifdef __DESC_DMA__
		IFX_PRINT("DMA: Hermes DMA\n");
	#else
		IFX_PRINT("DMA: Non-Desc DMA\n");
	#endif
	IFX_PRINT("     Burst size: %d\n",params->dma_burst_size);

	if     (params->speed==1)
		IFX_PRINT("Full Speed only\n");
	else if(params->speed==0)
		IFX_PRINT("Full/Hign Speed\n");
	else
		IFX_PRINT("Unkonwn setting (%d) for Speed\n",params->speed);

	IFX_PRINT("Total Data FIFO size: %d(0x%06X) DWord, %d(0x%06X) Bytes\n",
		params->data_fifo_size,params->data_fifo_size,
		params->data_fifo_size*4, params->data_fifo_size*4
	);

	#ifdef __IS_DEVICE__
		IFX_PRINT("Rx FIFO size: %d(0x%06X) DWord, %d(0x%06X) Bytes\n",
			params->rx_fifo_size,params->rx_fifo_size,
			params->rx_fifo_size*4, params->rx_fifo_size*4
		);
		{
			int i;
			for(i=0;i<MAX_EPS_CHANNELS;i++)
			{
				IFX_PRINT("Tx FIFO #%d size: %d(0x%06X) DWord, %d(0x%06X) Bytes\n",i,
					params->tx_fifo_size[i],params->tx_fifo_size[i],
					params->tx_fifo_size[i]*4, params->tx_fifo_size[i]*4
				);
			}
		}
		#ifdef __DED_FIFO__
			IFX_PRINT("Treshold : %s Rx:%d Tx:%d \n",
				(params->thr_ctl)?"On":"Off",params->tx_thr_length,params->rx_thr_length);
		#endif
	#else //__IS_HOST__
		IFX_PRINT("Host Channels: %d\n",params->host_channels);

		IFX_PRINT("Rx FIFO size: %d(0x%06X) DWord, %d(0x%06X) Bytes\n",
			params->data_fifo_size,params->data_fifo_size,
			params->data_fifo_size*4, params->data_fifo_size*4
		);

		IFX_PRINT("NP Tx FIFO size: %d(0x%06X) DWord, %d(0x%06X) Bytes\n",
			params->nperio_tx_fifo_size,params->nperio_tx_fifo_size,
			params->nperio_tx_fifo_size*4, params->nperio_tx_fifo_size*4
		);

		IFX_PRINT(" P Tx FIFO size: %d(0x%06X) DWord, %d(0x%06X) Bytes\n",
			params->perio_tx_fifo_size,params->perio_tx_fifo_size,
			params->perio_tx_fifo_size*4, params->perio_tx_fifo_size*4
		);
	#endif //__IS_HOST__

	IFX_PRINT("Max Transfer size: %d(0x%06X) Bytes\n",
		params->max_transfer_size,params->max_transfer_size
	);
	IFX_PRINT("Max Packet Count: %d(0x%06X)\n",
		params->max_packet_count,params->max_packet_count
	);

	IFX_PRINT("PHY UTMI Width: %d\n",params->phy_utmi_width);

	IFX_PRINT("Turn Around Time: HS:%d FS:%d\n",params->turn_around_time_hs,params->turn_around_time_fs);
	IFX_PRINT("Timeout Calibration: HS:%d FS:%d\n",params->timeout_cal_hs,params->timeout_cal_fs);


	IFX_PRINT("==================================================\n");
	IFX_PRINT("End of Parameters Dump\n");
	IFX_PRINT("==================================================\n");
}