aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/lantiq/files/drivers/usb/ifxhcd/ifxusb_driver.c
blob: 23349059f44396b22b47dab4aa2ce64aeb33240c (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
/*****************************************************************************
 **   FILE NAME       : ifxusb_driver.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     : The provides the initialization and cleanup entry
 **                     points for the IFX USB driver. This module can be
 **                     dynamically loaded with insmod command or built-in
 **                     with kernel. When loaded or executed the ifxusb_driver_init
 **                     function is called. When the module is removed (using rmmod),
 **                     the ifxusb_driver_cleanup function is called.
 *****************************************************************************/

/*!
 \file ifxusb_driver.c
 \brief This file contains the loading/unloading interface to the Linux driver.
*/

#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/platform_device.h>

#include <linux/errno.h>
#include <linux/types.h>
#include <linux/stat.h>  /* permission constants */
#include <linux/gpio.h>
#include <lantiq_soc.h>

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
	#include <linux/irq.h>
#endif

#include <asm/io.h>

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
	#include <asm/irq.h>
#endif

#include "ifxusb_plat.h"

#include "ifxusb_cif.h"

#ifdef __IS_HOST__
	#include "ifxhcd.h"

	#define    USB_DRIVER_DESC		"IFX USB HCD driver"
	const char ifxusb_driver_name[]    = "ifxusb_hcd";

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

	#if defined(__DO_OC_INT__)
		static unsigned int  oc_int_installed=0;
		static ifxhcd_hcd_t *oc_int_id=NULL;
	#endif
#endif

#ifdef __IS_DEVICE__
	#include "ifxpcd.h"

	#define    USB_DRIVER_DESC		"IFX USB PCD driver"
	const char ifxusb_driver_name[] = "ifxusb_pcd";

	ifxpcd_pcd_t ifxusb_pcd;
	const char ifxusb_pcd_name[]    = "ifxusb_pcd";
#endif

/* Global Debug Level Mask. */
#ifdef __IS_HOST__
	uint32_t h_dbg_lvl = 0x00;
#endif

#ifdef __IS_DEVICE__
	uint32_t d_dbg_lvl = 0x00;
#endif

ifxusb_params_t ifxusb_module_params;

static void parse_parms(void);


#include <lantiq_irq.h>
#define IFX_USB0_IR                     (INT_NUM_IM1_IRL0 + 22)
#define IFX_USB1_IR                     (INT_NUM_IM2_IRL0 + 19)

/*!
   \brief This function is called when a driver is unregistered. This happens when
  the rmmod command is executed. The device may or may not be electrically
  present. If it is present, the driver stops device processing. Any resources
  used on behalf of this device are freed.
*/
static int ifxusb_driver_remove(struct platform_device *_dev)
{
	IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
	#ifdef __IS_HOST__
		#if defined(__DO_OC_INT__)
			#if defined(__DO_OC_INT_ENABLE__)
				ifxusb_oc_int_off();
			#endif

			if(oc_int_installed && oc_int_id)
				free_irq((unsigned int)IFXUSB_OC_IRQ, oc_int_id );
			oc_int_installed=0;
			oc_int_id=NULL;
		#endif

		#if defined(__IS_DUAL__)
			ifxhcd_remove(&ifxusb_hcd_1);
			ifxusb_core_if_remove(&ifxusb_hcd_1.core_if );
			ifxhcd_remove(&ifxusb_hcd_2);
			ifxusb_core_if_remove(&ifxusb_hcd_2.core_if );
		#else
			ifxhcd_remove(&ifxusb_hcd);
			ifxusb_core_if_remove(&ifxusb_hcd.core_if );
		#endif
	#endif

	#ifdef __IS_DEVICE__
		ifxpcd_remove();
		ifxusb_core_if_remove(&ifxusb_pcd.core_if );
	#endif

	/* Remove the device attributes */

	ifxusb_attr_remove(&_dev->dev);

	return 0;
}


/* Function to setup the structures to control one usb core running as host*/
#ifdef __IS_HOST__
/*!
   \brief inlined by ifxusb_driver_probe(), handling host mode probing. Run at each host core.
*/
	static inline int ifxusb_driver_probe_h(ifxhcd_hcd_t *_hcd,
	                                        int           _irq,
	                                        uint32_t      _iobase,
	                                        uint32_t      _fifomem,
	                                        uint32_t      _fifodbg
	                                        )
	{
		int retval = 0;

		IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );

#ifdef __DEV_NEW__
		ifxusb_power_off  (&_hcd->core_if);
		ifxusb_phy_power_off  (&_hcd->core_if); // Test
		mdelay(500);
#endif //__DEV_NEW__
		ifxusb_power_on  (&_hcd->core_if);
		mdelay(50);
		ifxusb_phy_power_on  (&_hcd->core_if); // Test
		mdelay(50);
		ifxusb_hard_reset(&_hcd->core_if);
		retval =ifxusb_core_if_init(&_hcd->core_if,
		                             _irq,
		                             _iobase,
		                             _fifomem,
		                             _fifodbg);
		if(retval)
			return retval;

		ifxusb_host_core_init(&_hcd->core_if,&ifxusb_module_params);

		ifxusb_disable_global_interrupts( &_hcd->core_if);

		/* The driver is now initialized and need to be registered into Linux USB sub-system */

		retval = ifxhcd_init(_hcd); // hook the hcd into usb ss

		if (retval != 0)
		{
			IFX_ERROR("_hcd_init failed\n");
			return retval;
		}

		//ifxusb_enable_global_interrupts( _hcd->core_if ); // this should be done at hcd_start , including hcd_interrupt
		return 0;
	}
#endif //__IS_HOST__

#ifdef __IS_DEVICE__
/*!
  \brief inlined by ifxusb_driver_probe(), handling device mode probing.
*/
	static inline int ifxusb_driver_probe_d(ifxpcd_pcd_t *_pcd,
	                                        int           _irq,
	                                        uint32_t      _iobase,
	                                        uint32_t      _fifomem,
	                                        uint32_t      _fifodbg
	                                        )
	{
		int retval = 0;

		IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
#ifdef __DEV_NEW__
		ifxusb_power_off  (&_pcd->core_if);
		ifxusb_phy_power_off (&_pcd->core_if); // Test
		mdelay(500);
#endif // __DEV_NEW__
		ifxusb_power_on  (&_pcd->core_if);
		mdelay(50);
		ifxusb_phy_power_on  (&_pcd->core_if); // Test
		mdelay(50);
		ifxusb_hard_reset(&_pcd->core_if);
		retval =ifxusb_core_if_init(&_pcd->core_if,
		                             _irq,
		                             _iobase,
		                             _fifomem,
		                             _fifodbg);
		if(retval)
			return retval;

		IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
		ifxusb_dev_core_init(&_pcd->core_if,&ifxusb_module_params);

		IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
		ifxusb_disable_global_interrupts( &_pcd->core_if);

		/* The driver is now initialized and need to be registered into
		   Linux USB Gadget sub-system
		 */
		retval = ifxpcd_init();
		IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );

		if (retval != 0)
		{
			IFX_ERROR("_pcd_init failed\n");
			return retval;
		}
		//ifxusb_enable_global_interrupts( _pcd->core_if );  // this should be done at gadget bind or start
		return 0;
	}
#endif //__IS_DEVICE__



/*!
   \brief This function is called by module management in 2.6 kernel or by ifxusb_driver_init with 2.4 kernel
  It is to probe and setup IFXUSB core(s).
*/
static int ifxusb_driver_probe(struct platform_device *_dev)
{
	int retval = 0;
	int *pins = _dev->dev.platform_data;
	if (ltq_is_vr9()) {
		gpio_request(6, "id1");
		gpio_request(9, "id2");
		gpio_direction_input(6);
		gpio_direction_input(9);
	}
	if (pins) {
		if (pins[0]) {
			gpio_request(pins[0], "vbus1");
			gpio_direction_output(pins[0], 1);
		}
		if (pins[1] && ltq_is_vr9()) {
			gpio_request(pins[1], "vbus2");
			gpio_direction_output(pins[1], 1);
		}
	}
	// Parsing and store the parameters
	IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
	parse_parms();

	#ifdef __IS_HOST__
		#if   defined(__IS_DUAL__)
			memset(&ifxusb_hcd_1, 0, sizeof(ifxhcd_hcd_t));
			memset(&ifxusb_hcd_2, 0, sizeof(ifxhcd_hcd_t));

			ifxusb_hcd_1.core_if.core_no=0;
			ifxusb_hcd_2.core_if.core_no=1;
			ifxusb_hcd_1.core_if.core_name=(char *)ifxusb_hcd_name_1;
			ifxusb_hcd_2.core_if.core_name=(char *)ifxusb_hcd_name_2;

			ifxusb_hcd_1.dev=&_dev->dev;
			ifxusb_hcd_2.dev=&_dev->dev;

			retval = ifxusb_driver_probe_h(&ifxusb_hcd_1,
			                               IFX_USB0_IR,
			                               IFXUSB1_IOMEM_BASE,
			                               IFXUSB1_FIFOMEM_BASE,
			                               IFXUSB1_FIFODBG_BASE
			                               );
			if(retval)
				goto ifxusb_driver_probe_fail;

			retval = ifxusb_driver_probe_h(&ifxusb_hcd_2,
			                               IFX_USB1_IR,
			                               IFXUSB2_IOMEM_BASE,
			                               IFXUSB2_FIFOMEM_BASE,
			                               IFXUSB2_FIFODBG_BASE
			                              );
			if(retval)
				goto ifxusb_driver_probe_fail;

		#elif defined(__IS_FIRST__)
			memset(&ifxusb_hcd, 0, sizeof(ifxhcd_hcd_t));

			ifxusb_hcd.core_if.core_no=0;
			ifxusb_hcd.core_if.core_name=(char *)ifxusb_hcd_name;

			ifxusb_hcd.dev=&_dev->dev;

			retval = ifxusb_driver_probe_h(&ifxusb_hcd,
			                               IFX_USB0_IR,
			                               IFXUSB1_IOMEM_BASE,
			                               IFXUSB1_FIFOMEM_BASE,
			                               IFXUSB1_FIFODBG_BASE
			                              );
			if(retval)
				goto ifxusb_driver_probe_fail;

		#elif defined(__IS_SECOND__)
			memset(&ifxusb_hcd, 0, sizeof(ifxhcd_hcd_t));

			ifxusb_hcd.core_if.core_no=1;
			ifxusb_hcd.core_if.core_name=(char *)ifxusb_hcd_name;

			ifxusb_hcd.dev=&_dev->dev;

			retval = ifxusb_driver_probe_h(&ifxusb_hcd,
			                               IFX_USB1_IR,
			                               IFXUSB2_IOMEM_BASE,
			                               IFXUSB2_FIFOMEM_BASE,
			                               IFXUSB2_FIFODBG_BASE
			                              );
			if(retval)
				goto ifxusb_driver_probe_fail;

		#else
			memset(&ifxusb_hcd, 0, sizeof(ifxhcd_hcd_t));

			ifxusb_hcd.core_if.core_no=0;
			ifxusb_hcd.core_if.core_name=(char *)ifxusb_hcd_name;

			ifxusb_hcd.dev=&_dev->dev;

			retval = ifxusb_driver_probe_h(&ifxusb_hcd,
			                               IFXUSB_IRQ,
			                               IFXUSB_IOMEM_BASE,
			                               IFXUSB_FIFOMEM_BASE,
			                               IFXUSB_FIFODBG_BASE
			                              );
			if(retval)
				goto ifxusb_driver_probe_fail;
		#endif

		#if defined(__DO_OC_INT__)
			IFXUSB_DEBUGPL( DBG_CIL, "registering (overcurrent) handler for irq%d\n", IFXUSB_OC_IRQ);
			#if   defined(__IS_DUAL__)
				request_irq((unsigned int)IFXUSB_OC_IRQ, &ifx_hcd_oc_irq,
//				  SA_INTERRUPT|SA_SHIRQ, "ifxusb_oc", (void *)&ifxusb_hcd_1);
				  IRQF_DISABLED | IRQF_SHARED, "ifxusb_oc", (void *)&ifxusb_hcd_1);
				oc_int_id=&ifxusb_hcd_1;
			#else
				request_irq((unsigned int)IFXUSB_OC_IRQ, &ifx_hcd_oc_irq,
//				  SA_INTERRUPT|SA_SHIRQ, "ifxusb_oc", (void *)&ifxusb_hcd);
				  IRQF_DISABLED | IRQF_SHARED, "ifxusb_oc", (void *)&ifxusb_hcd);
				oc_int_id=&ifxusb_hcd;
			#endif
			oc_int_installed=1;

			#if defined(__DO_OC_INT_ENABLE__)
				ifxusb_oc_int_on();
			#endif
		#endif

	#endif

	#ifdef __IS_DEVICE__
		memset(&ifxusb_pcd, 0, sizeof(ifxpcd_pcd_t));
		ifxusb_pcd.core_if.core_name=(char *)&ifxusb_pcd_name[0];

		ifxusb_pcd.dev=&_dev->dev;

		#if   defined(__IS_FIRST__)
			ifxusb_pcd.core_if.core_no=0;
			retval = ifxusb_driver_probe_d(&ifxusb_pcd,
			                               IFXUSB1_IRQ,
			                               IFXUSB1_IOMEM_BASE,
			                               IFXUSB1_FIFOMEM_BASE,
			                               IFXUSB1_FIFODBG_BASE
			                              );
		#elif defined(__IS_SECOND__)
			ifxusb_pcd.core_if.core_no=1;
			retval = ifxusb_driver_probe_d(&ifxusb_pcd,
			                               IFXUSB2_IRQ,
			                               IFXUSB2_IOMEM_BASE,
			                               IFXUSB2_FIFOMEM_BASE,
			                               IFXUSB2_FIFODBG_BASE
			                              );
		#else
			ifxusb_pcd.core_if.core_no=0;
			retval = ifxusb_driver_probe_d(&ifxusb_pcd,
			                               IFXUSB_IRQ,
			                               IFXUSB_IOMEM_BASE,
			                               IFXUSB_FIFOMEM_BASE,
			                               IFXUSB_FIFODBG_BASE
			                              );
		#endif
		if(retval)
			goto ifxusb_driver_probe_fail;
	#endif

	ifxusb_attr_create(&_dev->dev);

	return 0;

ifxusb_driver_probe_fail:
	ifxusb_driver_remove(_dev);
	return retval;
}



/*!
   \brief This function is called when the ifxusb_driver is installed with the insmod command.
*/


static struct platform_driver ifxusb_driver = {
	.driver = {
		.name		= ifxusb_driver_name,
		.owner = THIS_MODULE,
	},
	.probe		= ifxusb_driver_probe,
	.remove		= ifxusb_driver_remove,
};

int __init ifxusb_driver_init(void)
{
	int retval = 0;

	IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
	IFX_PRINT("%s: version %s\n", ifxusb_driver_name, IFXUSB_VERSION);

	retval = platform_driver_register(&ifxusb_driver);

	if (retval < 0) {
		IFX_ERROR("%s retval=%d\n", __func__, retval);
		return retval;
	}
	return retval;
}

#if 0 // 2.4
	int __init ifxusb_driver_init(void)
	{
		int retval = 0;
		IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
		IFX_PRINT("%s: version %s\n", ifxusb_driver_name, IFXUSB_VERSION);
		retval = ifxusb_driver_probe();

		if (retval < 0) {
			IFX_ERROR("%s retval=%d\n", __func__, retval);
			return retval;
		}

		return retval;
	}
#endif

module_init(ifxusb_driver_init);


/*!
   \brief This function is called when the driver is removed from the kernel
  with the rmmod command. The driver unregisters itself with its bus
  driver.
*/

void __exit ifxusb_driver_cleanup(void)
{
	IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );

	platform_driver_unregister(&ifxusb_driver);

	IFX_PRINT("%s module removed\n", ifxusb_driver_name);
}
#if 0
	void __exit ifxusb_driver_cleanup(void)
	{
		IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
		ifxusb_driver_remove();
		IFX_PRINT("%s module removed\n", ifxusb_driver_name);
	}
#endif
module_exit(ifxusb_driver_cleanup);



MODULE_DESCRIPTION(USB_DRIVER_DESC);
MODULE_AUTHOR("Infineon");
MODULE_LICENSE("GPL");



// Parameters set when loaded
//static long  dbg_lvl =0xFFFFFFFF;
static long  dbg_lvl =0;
static short dma_burst_size =-1;
static short speed =-1;
static long  data_fifo_size =-1;
#ifdef __IS_DEVICE__
	static long   rx_fifo_size =-1;
	#ifdef __DED_FIFO__
		static long  tx_fifo_size_00 =-1;
		static long  tx_fifo_size_01 =-1;
		static long  tx_fifo_size_02 =-1;
		static long  tx_fifo_size_03 =-1;
		static long  tx_fifo_size_04 =-1;
		static long  tx_fifo_size_05 =-1;
		static long  tx_fifo_size_06 =-1;
		static long  tx_fifo_size_07 =-1;
		static long  tx_fifo_size_08 =-1;
		static long  tx_fifo_size_09 =-1;
		static long  tx_fifo_size_10 =-1;
		static long  tx_fifo_size_11 =-1;
		static long  tx_fifo_size_12 =-1;
		static long  tx_fifo_size_13 =-1;
		static long  tx_fifo_size_14 =-1;
		static long  tx_fifo_size_15 =-1;
		static short thr_ctl=-1;
		static long  tx_thr_length =-1;
		static long  rx_thr_length =-1;
	#else
		static long   nperio_tx_fifo_size =-1;
		static long   perio_tx_fifo_size_01 =-1;
		static long   perio_tx_fifo_size_02 =-1;
		static long   perio_tx_fifo_size_03 =-1;
		static long   perio_tx_fifo_size_04 =-1;
		static long   perio_tx_fifo_size_05 =-1;
		static long   perio_tx_fifo_size_06 =-1;
		static long   perio_tx_fifo_size_07 =-1;
		static long   perio_tx_fifo_size_08 =-1;
		static long   perio_tx_fifo_size_09 =-1;
		static long   perio_tx_fifo_size_10 =-1;
		static long   perio_tx_fifo_size_11 =-1;
		static long   perio_tx_fifo_size_12 =-1;
		static long   perio_tx_fifo_size_13 =-1;
		static long   perio_tx_fifo_size_14 =-1;
		static long   perio_tx_fifo_size_15 =-1;
	#endif
	static short   dev_endpoints =-1;
#endif

#ifdef __IS_HOST__
	static long   rx_fifo_size =-1;
	static long   nperio_tx_fifo_size =-1;
	static long   perio_tx_fifo_size =-1;
	static short  host_channels =-1;
#endif

static long   max_transfer_size =-1;
static long   max_packet_count =-1;
static long   phy_utmi_width =-1;
static long   turn_around_time_hs =-1;
static long   turn_around_time_fs =-1;
static long   timeout_cal_hs =-1;
static long   timeout_cal_fs =-1;

/*!
   \brief Parsing the parameters taken when module load
*/
static void parse_parms(void)
{

	IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
	#ifdef __IS_HOST__
		h_dbg_lvl=dbg_lvl;
	#endif
	#ifdef __IS_DEVICE__
		d_dbg_lvl=dbg_lvl;
	#endif

	switch(dma_burst_size)
	{
		case 0:
		case 1:
		case 4:
		case 8:
		case 16:
			ifxusb_module_params.dma_burst_size=dma_burst_size;
			break;
		default:
			ifxusb_module_params.dma_burst_size=default_param_dma_burst_size;
	}

	if(speed==0 || speed==1)
		ifxusb_module_params.speed=speed;
	else
		ifxusb_module_params.speed=default_param_speed;

	if(max_transfer_size>=2048 && max_transfer_size<=65535)
		ifxusb_module_params.max_transfer_size=max_transfer_size;
	else
		ifxusb_module_params.max_transfer_size=default_param_max_transfer_size;

	if(max_packet_count>=15 && max_packet_count<=511)
		ifxusb_module_params.max_packet_count=max_packet_count;
	else
		ifxusb_module_params.max_packet_count=default_param_max_packet_count;

	switch(phy_utmi_width)
	{
		case 8:
		case 16:
			ifxusb_module_params.phy_utmi_width=phy_utmi_width;
			break;
		default:
			ifxusb_module_params.phy_utmi_width=default_param_phy_utmi_width;
	}

	if(turn_around_time_hs>=0 && turn_around_time_hs<=7)
		ifxusb_module_params.turn_around_time_hs=turn_around_time_hs;
	else
		ifxusb_module_params.turn_around_time_hs=default_param_turn_around_time_hs;

	if(turn_around_time_fs>=0 && turn_around_time_fs<=7)
		ifxusb_module_params.turn_around_time_fs=turn_around_time_fs;
	else
		ifxusb_module_params.turn_around_time_fs=default_param_turn_around_time_fs;

	if(timeout_cal_hs>=0 && timeout_cal_hs<=7)
		ifxusb_module_params.timeout_cal_hs=timeout_cal_hs;
	else
		ifxusb_module_params.timeout_cal_hs=default_param_timeout_cal_hs;

	if(timeout_cal_fs>=0 && timeout_cal_fs<=7)
		ifxusb_module_params.timeout_cal_fs=timeout_cal_fs;
	else
		ifxusb_module_params.timeout_cal_fs=default_param_timeout_cal_fs;

	if(data_fifo_size>=32 && data_fifo_size<=32768)
		ifxusb_module_params.data_fifo_size=data_fifo_size;
	else
		ifxusb_module_params.data_fifo_size=default_param_data_fifo_size;

	#ifdef __IS_HOST__
		if(host_channels>=1 && host_channels<=16)
			ifxusb_module_params.host_channels=host_channels;
		else
			ifxusb_module_params.host_channels=default_param_host_channels;

		if(rx_fifo_size>=16 && rx_fifo_size<=32768)
			ifxusb_module_params.rx_fifo_size=rx_fifo_size;
		else
			ifxusb_module_params.rx_fifo_size=default_param_rx_fifo_size;

		if(nperio_tx_fifo_size>=16 && nperio_tx_fifo_size<=32768)
			ifxusb_module_params.nperio_tx_fifo_size=nperio_tx_fifo_size;
		else
			ifxusb_module_params.nperio_tx_fifo_size=default_param_nperio_tx_fifo_size;

		if(perio_tx_fifo_size>=16 && perio_tx_fifo_size<=32768)
			ifxusb_module_params.perio_tx_fifo_size=perio_tx_fifo_size;
		else
			ifxusb_module_params.perio_tx_fifo_size=default_param_perio_tx_fifo_size;
	#endif //__IS_HOST__

	#ifdef __IS_DEVICE__
		if(rx_fifo_size>=16 && rx_fifo_size<=32768)
			ifxusb_module_params.rx_fifo_size=rx_fifo_size;
		else
			ifxusb_module_params.rx_fifo_size=default_param_rx_fifo_size;
		#ifdef __DED_FIFO__
			if(tx_fifo_size_00>=16 && tx_fifo_size_00<=32768)
				ifxusb_module_params.tx_fifo_size[ 0]=tx_fifo_size_00;
			else
				ifxusb_module_params.tx_fifo_size[ 0]=default_param_tx_fifo_size_00;
			if(tx_fifo_size_01>=0 && tx_fifo_size_01<=32768)
				ifxusb_module_params.tx_fifo_size[ 1]=tx_fifo_size_01;
			else
				ifxusb_module_params.tx_fifo_size[ 1]=default_param_tx_fifo_size_01;
			if(tx_fifo_size_02>=0 && tx_fifo_size_02<=32768)
				ifxusb_module_params.tx_fifo_size[ 2]=tx_fifo_size_02;
			else
				ifxusb_module_params.tx_fifo_size[ 2]=default_param_tx_fifo_size_02;
			if(tx_fifo_size_03>=0 && tx_fifo_size_03<=32768)
				ifxusb_module_params.tx_fifo_size[ 3]=tx_fifo_size_03;
			else
				ifxusb_module_params.tx_fifo_size[ 3]=default_param_tx_fifo_size_03;
			if(tx_fifo_size_04>=0 && tx_fifo_size_04<=32768)
				ifxusb_module_params.tx_fifo_size[ 4]=tx_fifo_size_04;
			else
				ifxusb_module_params.tx_fifo_size[ 4]=default_param_tx_fifo_size_04;
			if(tx_fifo_size_05>=0 && tx_fifo_size_05<=32768)
				ifxusb_module_params.tx_fifo_size[ 5]=tx_fifo_size_05;
			else
				ifxusb_module_params.tx_fifo_size[ 5]=default_param_tx_fifo_size_05;
			if(tx_fifo_size_06>=0 && tx_fifo_size_06<=32768)
				ifxusb_module_params.tx_fifo_size[ 6]=tx_fifo_size_06;
			else
				ifxusb_module_params.tx_fifo_size[ 6]=default_param_tx_fifo_size_06;
			if(tx_fifo_size_07>=0 && tx_fifo_size_07<=32768)
				ifxusb_module_params.tx_fifo_size[ 7]=tx_fifo_size_07;
			else
				ifxusb_module_params.tx_fifo_size[ 7]=default_param_tx_fifo_size_07;
			if(tx_fifo_size_08>=0 && tx_fifo_size_08<=32768)
				ifxusb_module_params.tx_fifo_size[ 8]=tx_fifo_size_08;
			else
				ifxusb_module_params.tx_fifo_size[ 8]=default_param_tx_fifo_size_08;
			if(tx_fifo_size_09>=0 && tx_fifo_size_09<=32768)
				ifxusb_module_params.tx_fifo_size[ 9]=tx_fifo_size_09;
			else
				ifxusb_module_params.tx_fifo_size[ 9]=default_param_tx_fifo_size_09;
			if(tx_fifo_size_10>=0 && tx_fifo_size_10<=32768)
				ifxusb_module_params.tx_fifo_size[10]=tx_fifo_size_10;
			else
				ifxusb_module_params.tx_fifo_size[10]=default_param_tx_fifo_size_10;
			if(tx_fifo_size_11>=0 && tx_fifo_size_11<=32768)
				ifxusb_module_params.tx_fifo_size[11]=tx_fifo_size_11;
			else
				ifxusb_module_params.tx_fifo_size[11]=default_param_tx_fifo_size_11;
			if(tx_fifo_size_12>=0 && tx_fifo_size_12<=32768)
				ifxusb_module_params.tx_fifo_size[12]=tx_fifo_size_12;
			else
				ifxusb_module_params.tx_fifo_size[12]=default_param_tx_fifo_size_12;
			if(tx_fifo_size_13>=0 && tx_fifo_size_13<=32768)
				ifxusb_module_params.tx_fifo_size[13]=tx_fifo_size_13;
			else
				ifxusb_module_params.tx_fifo_size[13]=default_param_tx_fifo_size_13;
			if(tx_fifo_size_14>=0 && tx_fifo_size_14<=32768)
				ifxusb_module_params.tx_fifo_size[14]=tx_fifo_size_14;
			else
				ifxusb_module_params.tx_fifo_size[14]=default_param_tx_fifo_size_14;
			if(tx_fifo_size_15>=0 && tx_fifo_size_15<=32768)
				ifxusb_module_params.tx_fifo_size[15]=tx_fifo_size_15;
			else
				ifxusb_module_params.tx_fifo_size[15]=default_param_tx_fifo_size_15;
			if(thr_ctl==0 || thr_ctl==1)
				ifxusb_module_params.thr_ctl=thr_ctl;
			else
				ifxusb_module_params.thr_ctl=default_param_thr_ctl;
			if(tx_thr_length>=16 && tx_thr_length<=511)
				ifxusb_module_params.tx_thr_length=tx_thr_length;
			else
				ifxusb_module_params.tx_thr_length=default_param_tx_thr_length;
			if(rx_thr_length>=16 && rx_thr_length<=511)
				ifxusb_module_params.rx_thr_length=rx_thr_length;
			else
				ifxusb_module_params.rx_thr_length=default_param_rx_thr_length;
		#else  //__DED_FIFO__
			if(nperio_tx_fifo_size>=16 && nperio_tx_fifo_size<=32768)
				ifxusb_module_params.tx_fifo_size[ 0]=nperio_tx_fifo_size;
			else
				ifxusb_module_params.tx_fifo_size[ 0]=default_param_nperio_tx_fifo_size;
			if(perio_tx_fifo_size_01>=0 && perio_tx_fifo_size_01<=32768)
				ifxusb_module_params.tx_fifo_size[ 1]=perio_tx_fifo_size_01;
			else
				ifxusb_module_params.tx_fifo_size[ 1]=default_param_perio_tx_fifo_size_01;
			if(perio_tx_fifo_size_02>=0 && perio_tx_fifo_size_02<=32768)
				ifxusb_module_params.tx_fifo_size[ 2]=perio_tx_fifo_size_02;
			else
				ifxusb_module_params.tx_fifo_size[ 2]=default_param_perio_tx_fifo_size_02;
			if(perio_tx_fifo_size_03>=0 && perio_tx_fifo_size_03<=32768)
				ifxusb_module_params.tx_fifo_size[ 3]=perio_tx_fifo_size_03;
			else
				ifxusb_module_params.tx_fifo_size[ 3]=default_param_perio_tx_fifo_size_03;
			if(perio_tx_fifo_size_04>=0 && perio_tx_fifo_size_04<=32768)
				ifxusb_module_params.tx_fifo_size[ 4]=perio_tx_fifo_size_04;
			else
				ifxusb_module_params.tx_fifo_size[ 4]=default_param_perio_tx_fifo_size_04;
			if(perio_tx_fifo_size_05>=0 && perio_tx_fifo_size_05<=32768)
				ifxusb_module_params.tx_fifo_size[ 5]=perio_tx_fifo_size_05;
			else
				ifxusb_module_params.tx_fifo_size[ 5]=default_param_perio_tx_fifo_size_05;
			if(perio_tx_fifo_size_06>=0 && perio_tx_fifo_size_06<=32768)
				ifxusb_module_params.tx_fifo_size[ 6]=perio_tx_fifo_size_06;
			else
				ifxusb_module_params.tx_fifo_size[ 6]=default_param_perio_tx_fifo_size_06;
			if(perio_tx_fifo_size_07>=0 && perio_tx_fifo_size_07<=32768)
				ifxusb_module_params.tx_fifo_size[ 7]=perio_tx_fifo_size_07;
			else
				ifxusb_module_params.tx_fifo_size[ 7]=default_param_perio_tx_fifo_size_07;
			if(perio_tx_fifo_size_08>=0 && perio_tx_fifo_size_08<=32768)
				ifxusb_module_params.tx_fifo_size[ 8]=perio_tx_fifo_size_08;
			else
				ifxusb_module_params.tx_fifo_size[ 8]=default_param_perio_tx_fifo_size_08;
			if(perio_tx_fifo_size_09>=0 && perio_tx_fifo_size_09<=32768)
				ifxusb_module_params.tx_fifo_size[ 9]=perio_tx_fifo_size_09;
			else
				ifxusb_module_params.tx_fifo_size[ 9]=default_param_perio_tx_fifo_size_09;
			if(perio_tx_fifo_size_10>=0 && perio_tx_fifo_size_10<=32768)
				ifxusb_module_params.tx_fifo_size[10]=perio_tx_fifo_size_10;
			else
				ifxusb_module_params.tx_fifo_size[10]=default_param_perio_tx_fifo_size_10;
			if(perio_tx_fifo_size_11>=0 && perio_tx_fifo_size_11<=32768)
				ifxusb_module_params.tx_fifo_size[11]=perio_tx_fifo_size_11;
			else
				ifxusb_module_params.tx_fifo_size[11]=default_param_perio_tx_fifo_size_11;
			if(perio_tx_fifo_size_12>=0 && perio_tx_fifo_size_12<=32768)
				ifxusb_module_params.tx_fifo_size[12]=perio_tx_fifo_size_12;
			else
				ifxusb_module_params.tx_fifo_size[12]=default_param_perio_tx_fifo_size_12;
			if(perio_tx_fifo_size_13>=0 && perio_tx_fifo_size_13<=32768)
				ifxusb_module_params.tx_fifo_size[13]=perio_tx_fifo_size_13;
			else
				ifxusb_module_params.tx_fifo_size[13]=default_param_perio_tx_fifo_size_13;
			if(perio_tx_fifo_size_14>=0 && perio_tx_fifo_size_14<=32768)
				ifxusb_module_params.tx_fifo_size[14]=perio_tx_fifo_size_14;
			else
				ifxusb_module_params.tx_fifo_size[14]=default_param_perio_tx_fifo_size_14;
			if(perio_tx_fifo_size_15>=0 && perio_tx_fifo_size_15<=32768)
				ifxusb_module_params.tx_fifo_size[15]=perio_tx_fifo_size_15;
			else
				ifxusb_module_params.tx_fifo_size[15]=default_param_perio_tx_fifo_size_15;
		#endif //__DED_FIFO__
	#endif //__IS_DEVICE__
}







module_param(dbg_lvl, long, 0444);
MODULE_PARM_DESC(dbg_lvl, "Debug level.");

module_param(dma_burst_size, short, 0444);
MODULE_PARM_DESC(dma_burst_size, "DMA Burst Size 0, 1, 4, 8, 16");

module_param(speed, short, 0444);
MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");

module_param(data_fifo_size, long, 0444);
MODULE_PARM_DESC(data_fifo_size, "Total number of words in the data FIFO memory 32-32768");

#ifdef __IS_DEVICE__
	module_param(rx_fifo_size, long, 0444);
	MODULE_PARM_DESC(rx_fifo_size, "Number of words in the Rx FIFO 16-32768");

	#ifdef __DED_FIFO__
		module_param(tx_fifo_size_00, long, 0444);
		MODULE_PARM_DESC(tx_fifo_size_00, "Number of words in the Tx FIFO #00 16-32768");
		module_param(tx_fifo_size_01, long, 0444);
		MODULE_PARM_DESC(tx_fifo_size_01, "Number of words in the Tx FIFO #01  0-32768");
		module_param(tx_fifo_size_02, long, 0444);
		MODULE_PARM_DESC(tx_fifo_size_02, "Number of words in the Tx FIFO #02  0-32768");
		module_param(tx_fifo_size_03, long, 0444);
		MODULE_PARM_DESC(tx_fifo_size_03, "Number of words in the Tx FIFO #03  0-32768");
		module_param(tx_fifo_size_04, long, 0444);
		MODULE_PARM_DESC(tx_fifo_size_04, "Number of words in the Tx FIFO #04  0-32768");
		module_param(tx_fifo_size_05, long, 0444);
		MODULE_PARM_DESC(tx_fifo_size_05, "Number of words in the Tx FIFO #05  0-32768");
		module_param(tx_fifo_size_06, long, 0444);
		MODULE_PARM_DESC(tx_fifo_size_06, "Number of words in the Tx FIFO #06  0-32768");
		module_param(tx_fifo_size_07, long, 0444);
		MODULE_PARM_DESC(tx_fifo_size_07, "Number of words in the Tx FIFO #07  0-32768");
		module_param(tx_fifo_size_08, long, 0444);
		MODULE_PARM_DESC(tx_fifo_size_08, "Number of words in the Tx FIFO #08  0-32768");
		module_param(tx_fifo_size_09, long, 0444);
		MODULE_PARM_DESC(tx_fifo_size_09, "Number of words in the Tx FIFO #09  0-32768");
		module_param(tx_fifo_size_10, long, 0444);
		MODULE_PARM_DESC(tx_fifo_size_10, "Number of words in the Tx FIFO #10  0-32768");
		module_param(tx_fifo_size_11, long, 0444);
		MODULE_PARM_DESC(tx_fifo_size_11, "Number of words in the Tx FIFO #11  0-32768");
		module_param(tx_fifo_size_12, long, 0444);
		MODULE_PARM_DESC(tx_fifo_size_12, "Number of words in the Tx FIFO #12  0-32768");
		module_param(tx_fifo_size_13, long, 0444);
		MODULE_PARM_DESC(tx_fifo_size_13, "Number of words in the Tx FIFO #13  0-32768");
		module_param(tx_fifo_size_14, long, 0444);
		MODULE_PARM_DESC(tx_fifo_size_14, "Number of words in the Tx FIFO #14  0-32768");
		module_param(tx_fifo_size_15, long, 0444);
		MODULE_PARM_DESC(tx_fifo_size_15, "Number of words in the Tx FIFO #15  0-32768");

		module_param(thr_ctl, short, 0444);
		MODULE_PARM_DESC(thr_ctl, "0=Without 1=With Theshold Ctrl");

		module_param(tx_thr_length, long, 0444);
		MODULE_PARM_DESC(tx_thr_length, "TX Threshold length");

		module_param(rx_thr_length, long, 0444);
		MODULE_PARM_DESC(rx_thr_length, "RX Threshold length");

	#else
		module_param(nperio_tx_fifo_size, long, 0444);
		MODULE_PARM_DESC(nperio_tx_fifo_size, "Number of words in the non-periodic Tx FIFO 16-32768");

		module_param(perio_tx_fifo_size_01, long, 0444);
		MODULE_PARM_DESC(perio_tx_fifo_size_01, "Number of words in the periodic Tx FIFO #01  0-32768");
		module_param(perio_tx_fifo_size_02, long, 0444);
		MODULE_PARM_DESC(perio_tx_fifo_size_02, "Number of words in the periodic Tx FIFO #02  0-32768");
		module_param(perio_tx_fifo_size_03, long, 0444);
		MODULE_PARM_DESC(perio_tx_fifo_size_03, "Number of words in the periodic Tx FIFO #03  0-32768");
		module_param(perio_tx_fifo_size_04, long, 0444);
		MODULE_PARM_DESC(perio_tx_fifo_size_04, "Number of words in the periodic Tx FIFO #04  0-32768");
		module_param(perio_tx_fifo_size_05, long, 0444);
		MODULE_PARM_DESC(perio_tx_fifo_size_05, "Number of words in the periodic Tx FIFO #05  0-32768");
		module_param(perio_tx_fifo_size_06, long, 0444);
		MODULE_PARM_DESC(perio_tx_fifo_size_06, "Number of words in the periodic Tx FIFO #06  0-32768");
		module_param(perio_tx_fifo_size_07, long, 0444);
		MODULE_PARM_DESC(perio_tx_fifo_size_07, "Number of words in the periodic Tx FIFO #07  0-32768");
		module_param(perio_tx_fifo_size_08, long, 0444);
		MODULE_PARM_DESC(perio_tx_fifo_size_08, "Number of words in the periodic Tx FIFO #08  0-32768");
		module_param(perio_tx_fifo_size_09, long, 0444);
		MODULE_PARM_DESC(perio_tx_fifo_size_09, "Number of words in the periodic Tx FIFO #09  0-32768");
		module_param(perio_tx_fifo_size_10, long, 0444);
		MODULE_PARM_DESC(perio_tx_fifo_size_10, "Number of words in the periodic Tx FIFO #10  0-32768");
		module_param(perio_tx_fifo_size_11, long, 0444);
		MODULE_PARM_DESC(perio_tx_fifo_size_11, "Number of words in the periodic Tx FIFO #11  0-32768");
		module_param(perio_tx_fifo_size_12, long, 0444);
		MODULE_PARM_DESC(perio_tx_fifo_size_12, "Number of words in the periodic Tx FIFO #12  0-32768");
		module_param(perio_tx_fifo_size_13, long, 0444);
		MODULE_PARM_DESC(perio_tx_fifo_size_13, "Number of words in the periodic Tx FIFO #13  0-32768");
		module_param(perio_tx_fifo_size_14, long, 0444);
		MODULE_PARM_DESC(perio_tx_fifo_size_14, "Number of words in the periodic Tx FIFO #14  0-32768");
		module_param(perio_tx_fifo_size_15, long, 0444);
		MODULE_PARM_DESC(perio_tx_fifo_size_15, "Number of words in the periodic Tx FIFO #15  0-32768");
	#endif//__DED_FIFO__
	module_param(dev_endpoints, short, 0444);
	MODULE_PARM_DESC(dev_endpoints, "The number of endpoints in addition to EP0 available for device mode 1-15");
#endif

#ifdef __IS_HOST__
	module_param(rx_fifo_size, long, 0444);
	MODULE_PARM_DESC(rx_fifo_size, "Number of words in the Rx FIFO 16-32768");

	module_param(nperio_tx_fifo_size, long, 0444);
	MODULE_PARM_DESC(nperio_tx_fifo_size, "Number of words in the non-periodic Tx FIFO 16-32768");

	module_param(perio_tx_fifo_size, long, 0444);
	MODULE_PARM_DESC(perio_tx_fifo_size, "Number of words in the host periodic Tx FIFO 16-32768");

	module_param(host_channels, short, 0444);
	MODULE_PARM_DESC(host_channels, "The number of host channel registers to use 1-16");
#endif

module_param(max_transfer_size, long, 0444);
MODULE_PARM_DESC(max_transfer_size, "The maximum transfer size supported in bytes 2047-65535");

module_param(max_packet_count, long, 0444);
MODULE_PARM_DESC(max_packet_count, "The maximum number of packets in a transfer 15-511");

module_param(phy_utmi_width, long, 0444);
MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");

module_param(turn_around_time_hs, long, 0444);
MODULE_PARM_DESC(turn_around_time_hs, "Turn-Around time for HS");

module_param(turn_around_time_fs, long, 0444);
MODULE_PARM_DESC(turn_around_time_fs, "Turn-Around time for FS");

module_param(timeout_cal_hs, long, 0444);
MODULE_PARM_DESC(timeout_cal_hs, "Timeout Cal for HS");

module_param(timeout_cal_fs, long, 0444);
MODULE_PARM_DESC(timeout_cal_fs, "Timeout Cal for FS");