Root/target/linux/lantiq/files/drivers/usb/ifxhcd/ifxusb_ctl.c

1/*****************************************************************************
2 ** FILE NAME : ifxusb_ctl.c
3 ** PROJECT : IFX USB sub-system V3
4 ** MODULES : IFX USB sub-system Host and Device driver
5 ** SRC VERSION : 1.0
6 ** DATE : 1/Jan/2009
7 ** AUTHOR : Chen, Howard
8 ** DESCRIPTION : Implementing the procfs and sysfs for IFX USB driver
9 *****************************************************************************/
10
11/*! \file ifxusb_ctl.c
12  \ingroup IFXUSB_DRIVER_V3
13    \brief Implementing the procfs and sysfs for IFX USB driver
14*/
15
16#include <linux/version.h>
17#include "ifxusb_version.h"
18
19
20#include <linux/proc_fs.h>
21#include <asm/byteorder.h>
22#include <asm/unaligned.h>
23#include <asm/uaccess.h>
24
25#include "ifxusb_plat.h"
26#include "ifxusb_regs.h"
27#include "ifxusb_cif.h"
28
29#ifdef __IS_DEVICE__
30    #include "ifxpcd.h"
31#endif
32
33#ifdef __IS_HOST__
34    #include "ifxhcd.h"
35#endif
36
37#include <linux/device.h>
38#include <linux/platform_device.h>
39#include <linux/gfp.h>
40
41
42#ifdef __IS_HOST__
43    extern char ifxusb_driver_name[];
44
45    #ifdef __IS_DUAL__
46        extern ifxhcd_hcd_t ifxusb_hcd_1;
47        extern ifxhcd_hcd_t ifxusb_hcd_2;
48        extern char ifxusb_hcd_name_1[];
49        extern char ifxusb_hcd_name_2[];
50    #else
51        extern ifxhcd_hcd_t ifxusb_hcd;
52        extern char ifxusb_hcd_name[];
53    #endif
54
55#endif
56
57#ifdef __IS_DEVICE__
58    extern char ifxusb_driver_name[];
59
60    extern ifxpcd_pcd_t ifxusb_pcd;
61    extern char ifxusb_pcd_name[];
62#endif
63
64
65//Attributes for sysfs (for 2.6 only)
66
67extern struct device_attribute dev_attr_dbglevel;
68
69#ifdef __IS_DUAL__
70    extern struct device_attribute dev_attr_dump_params_1;
71    extern struct device_attribute dev_attr_dump_params_2;
72#else
73    extern struct device_attribute dev_attr_dump_params;
74#endif
75
76#ifdef __IS_DUAL__
77    extern struct device_attribute dev_attr_mode_1;
78    extern struct device_attribute dev_attr_mode_2;
79#else
80    extern struct device_attribute dev_attr_mode;
81#endif
82
83#ifdef __IS_HOST__
84    #ifdef __IS_DUAL__
85        extern struct device_attribute dev_attr_buspower_1;
86        extern struct device_attribute dev_attr_buspower_2;
87        extern struct device_attribute dev_attr_bussuspend_1;
88        extern struct device_attribute dev_attr_bussuspend_2;
89        extern struct device_attribute dev_attr_busconnected_1;
90        extern struct device_attribute dev_attr_busconnected_2;
91        extern struct device_attribute dev_attr_connectspeed_1;
92        extern struct device_attribute dev_attr_connectspeed_1;
93    #else
94        extern struct device_attribute dev_attr_buspower;
95        extern struct device_attribute dev_attr_bussuspend;
96        extern struct device_attribute dev_attr_busconnected;
97        extern struct device_attribute dev_attr_connectspeed;
98    #endif
99#endif //__IS_HOST__
100
101#ifdef __IS_DEVICE__
102    extern struct device_attribute dev_attr_devspeed;
103    extern struct device_attribute dev_attr_enumspeed;
104#endif //__IS_DEVICE__
105
106#ifdef __ENABLE_DUMP__
107    #ifdef __IS_DUAL__
108        extern struct device_attribute dev_attr_dump_reg_1;
109        extern struct device_attribute dev_attr_dump_reg_2;
110        extern struct device_attribute dev_attr_dump_spram_1;
111        extern struct device_attribute dev_attr_dump_spram_2;
112        #ifdef __IS_HOST__
113            extern struct device_attribute dev_attr_dump_host_state_1;
114            extern struct device_attribute dev_attr_dump_host_state_2;
115        #else
116        #endif
117    #else
118        extern struct device_attribute dev_attr_dump_reg;
119        extern struct device_attribute dev_attr_dump_spram;
120        #ifdef __IS_HOST__
121            extern struct device_attribute dev_attr_dump_host_state;
122        #else
123        #endif
124    #endif
125#endif //__ENABLE_DUMP__
126
127
128/////////////////////////////////////////////////////////////////////////////////////////////////////
129/////////////////////////////////////////////////////////////////////////////////////////////////////
130/////////////////////////////////////////////////////////////////////////////////////////////////////
131
132static ssize_t procfs_dbglevel_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
133{
134    #ifdef __IS_HOST__
135        return sprintf( buf, "%08X\n",h_dbg_lvl );
136    #else
137        return sprintf( buf, "%08X\n",d_dbg_lvl );
138    #endif
139}
140
141static ssize_t procfs_dbglevel_store(struct file *file, const char *buffer, unsigned long count, void *data)
142{
143    char buf[10];
144    int i = 0;
145    uint32_t value;
146    if (copy_from_user(buf, &buffer[i], sizeof("0xFFFFFFFF\n")+1))
147        return -EFAULT;
148    value = simple_strtoul(buf, NULL, 16);
149    #ifdef __IS_HOST__
150        h_dbg_lvl =value;
151    #else
152        d_dbg_lvl =value;
153    #endif
154        //turn on and off power
155    return count;
156}
157
158#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
159    static ssize_t sysfs_dbglevel_show( struct device *_dev, struct device_attribute *attr,char *buf)
160#else
161    static ssize_t sysfs_dbglevel_show( struct device *_dev, char *buf)
162#endif
163{
164    #ifdef __IS_HOST__
165        return sprintf( buf, "%08X\n",h_dbg_lvl );
166    #else
167        return sprintf( buf, "%08X\n",d_dbg_lvl );
168    #endif
169}
170
171#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
172    static ssize_t sysfs_dbglevel_store( struct device *_dev, struct device_attribute *attr,const char *buffer, size_t count )
173#else
174    static ssize_t sysfs_dbglevel_store( struct device *_dev, const char *buffer, size_t count )
175#endif
176{
177    char buf[10];
178    int i = 0;
179    uint32_t value;
180    if (copy_from_user(buf, &buffer[i], sizeof("0xFFFFFFFF\n")+1))
181        return -EFAULT;
182    value = simple_strtoul(buf, NULL, 16);
183    #ifdef __IS_HOST__
184        h_dbg_lvl =value;
185    #else
186        d_dbg_lvl =value;
187    #endif
188        //turn on and off power
189    return count;
190}
191
192DEVICE_ATTR(dbglevel, S_IRUGO|S_IWUSR, sysfs_dbglevel_show, sysfs_dbglevel_store);
193
194
195/////////////////////////////////////////////////////////////////////////////////////////////////////
196/////////////////////////////////////////////////////////////////////////////////////////////////////
197/////////////////////////////////////////////////////////////////////////////////////////////////////
198
199static void ifxusb_dump_params(ifxusb_core_if_t *_core_if);
200
201#ifdef __IS_DUAL__
202    static void dump_params_1(void)
203    {
204        ifxusb_dump_params(&ifxusb_hcd_1.core_if);
205    }
206    static void dump_params_2(void)
207    {
208        ifxusb_dump_params(&ifxusb_hcd_2.core_if);
209    }
210
211    static ssize_t procfs_dump_params_show_1(char *buf, char **start, off_t offset, int count, int *eof, void *data)
212    {
213        dump_params_1();
214        return 0;
215    }
216    static ssize_t procfs_dump_params_show_2(char *buf, char **start, off_t offset, int count, int *eof, void *data)
217    {
218        dump_params_2();
219        return 0;
220    }
221
222    #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
223        static ssize_t sysfs_dump_params_show_1( struct device *_dev, struct device_attribute *attr,char *buf)
224    #else
225        static ssize_t sysfs_dump_params_show_1( struct device *_dev,char *buf)
226    #endif
227    {
228        dump_params_1();
229        return 0;
230    }
231    DEVICE_ATTR(dump_params_1, S_IRUGO|S_IWUSR, sysfs_dump_params_show_1, NULL);
232
233    #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
234        static ssize_t sysfs_dump_params_show_2( struct device *_dev, struct device_attribute *attr,char *buf)
235    #else
236        static ssize_t sysfs_dump_params_show_2( struct device *_dev,char *buf)
237    #endif
238    {
239        dump_params_2();
240        return 0;
241    }
242
243    DEVICE_ATTR(dump_params_2, S_IRUGO|S_IWUSR, sysfs_dump_params_show_2, NULL);
244#else
245    static void dump_params(void)
246    {
247        #ifdef __IS_HOST__
248            ifxusb_dump_params(&ifxusb_hcd.core_if);
249        #else
250            ifxusb_dump_params(&ifxusb_pcd.core_if);
251        #endif
252    }
253
254    static ssize_t procfs_dump_params_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
255    {
256        dump_params();
257        return 0;
258    }
259
260    #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
261        static ssize_t sysfs_dump_params_show( struct device *_dev, struct device_attribute *attr,char *buf)
262    #else
263        static ssize_t sysfs_dump_params_show( struct device *_dev,char *buf)
264    #endif
265    {
266        dump_params();
267        return 0;
268    }
269    DEVICE_ATTR(dump_params, S_IRUGO|S_IWUSR, sysfs_dump_params_show, NULL);
270#endif
271
272/////////////////////////////////////////////////////////////////////////////////////////////////////
273/////////////////////////////////////////////////////////////////////////////////////////////////////
274/////////////////////////////////////////////////////////////////////////////////////////////////////
275
276#ifdef __IS_DUAL__
277    static ssize_t mode_show_1(char *buf)
278    {
279        if((ifxusb_rreg(&ifxusb_hcd_1.core_if.core_global_regs->gintsts ) & 0x1) == 1)
280            return sprintf( buf, "HOST\n" );
281        else
282            return sprintf( buf, "DEVICE(INCORRECT!)\n" );
283    }
284
285    static ssize_t mode_show_2(char *buf)
286    {
287        if((ifxusb_rreg(&ifxusb_hcd_2.core_if.core_global_regs->gintsts ) & 0x1) == 1)
288            return sprintf( buf, "HOST\n" );
289        else
290            return sprintf( buf, "DEVICE(INCORRECT!)\n" );
291    }
292
293    static ssize_t procfs_mode_show_1(char *buf, char **start, off_t offset, int count, int *eof, void *data)
294    {
295        return mode_show_1(buf);
296    }
297    static ssize_t procfs_mode_show_2(char *buf, char **start, off_t offset, int count, int *eof, void *data)
298    {
299        return mode_show_2(buf);
300    }
301
302    #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
303        static ssize_t sysfs_mode_show_1( struct device *_dev, struct device_attribute *attr,char *buf)
304    #else
305        static ssize_t sysfs_mode_show_1( struct device *_dev,char *buf)
306    #endif
307    {
308        return mode_show_1(buf);
309    }
310
311    DEVICE_ATTR(mode_1, S_IRUGO|S_IWUSR, sysfs_mode_show_1, 0);
312
313    #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
314        static ssize_t sysfs_mode_show_2( struct device *_dev, struct device_attribute *attr,char *buf)
315    #else
316        static ssize_t sysfs_mode_show_2( struct device *_dev,char *buf)
317    #endif
318    {
319        return mode_show_2(buf);
320    }
321    DEVICE_ATTR(mode_2, S_IRUGO|S_IWUSR, sysfs_mode_show_2, NULL);
322#else
323    static ssize_t mode_show(char *buf)
324    {
325        #ifdef __IS_HOST__
326            if((ifxusb_rreg(&ifxusb_hcd.core_if.core_global_regs->gintsts ) & 0x1) == 1)
327                return sprintf( buf, "HOST\n" );
328            else
329                return sprintf( buf, "DEVICE(INCORRECT!)\n" );
330        #else
331            if((ifxusb_rreg(&ifxusb_pcd.core_if.core_global_regs->gintsts ) & 0x1) != 1)
332                return sprintf( buf, "DEVICE\n" );
333            else
334                return sprintf( buf, "HOST(INCORRECT!)\n" );
335        #endif
336    }
337    static ssize_t procfs_mode_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
338    {
339        return mode_show(buf);
340    }
341    #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
342        static ssize_t sysfs_mode_show( struct device *_dev, struct device_attribute *attr,char *buf)
343    #else
344        static ssize_t sysfs_mode_show( struct device *_dev, char *buf)
345    #endif
346    {
347        return mode_show(buf);
348    }
349    DEVICE_ATTR(mode, S_IRUGO|S_IWUSR, sysfs_mode_show, NULL);
350#endif
351
352/////////////////////////////////////////////////////////////////////////////////////////////////////
353/////////////////////////////////////////////////////////////////////////////////////////////////////
354/////////////////////////////////////////////////////////////////////////////////////////////////////
355
356#ifdef __IS_HOST__
357    #ifdef __IS_DUAL__
358        static ssize_t buspower_show_1(char *buf)
359        {
360            if(ifxusb_vbus (&ifxusb_hcd_1.core_if)==1) return sprintf( buf, "1\n" );
361            if(ifxusb_vbus (&ifxusb_hcd_1.core_if)==0) return sprintf( buf, "0\n" );
362            return sprintf( buf, "UNKNOWN\n" );
363        }
364        static void buspower_store_1(uint32_t value)
365        {
366            if (value==1) ifxusb_vbus_on (&ifxusb_hcd_1.core_if);
367            else if(value==0) ifxusb_vbus_off(&ifxusb_hcd_1.core_if);
368        }
369        static ssize_t buspower_show_2(char *buf)
370        {
371            if(ifxusb_vbus (&ifxusb_hcd_2.core_if)==1) return sprintf( buf, "1\n" );
372            if(ifxusb_vbus (&ifxusb_hcd_2.core_if)==0) return sprintf( buf, "0\n" );
373            return sprintf( buf, "UNKNOWN\n" );
374        }
375        static void buspower_store_2(uint32_t value)
376        {
377            if (value==1) ifxusb_vbus_on (&ifxusb_hcd_2.core_if);
378            else if(value==0) ifxusb_vbus_off(&ifxusb_hcd_2.core_if);
379        }
380        static ssize_t procfs_buspower_show_1(char *buf, char **start, off_t offset, int count, int *eof, void *data)
381        {
382            return buspower_show_1(buf);
383        }
384        static ssize_t procfs_buspower_store_1(struct file *file, const char *buffer, unsigned long count, void *data)
385        {
386            char buf[10];
387            int i = 0;
388            uint32_t value;
389            if (copy_from_user(buf, &buffer[i], sizeof("0xFFFFFFFF\n")+1))
390                return -EFAULT;
391            value = simple_strtoul(buf, NULL, 16);
392            buspower_store_1(value);
393            return count;
394        }
395        static ssize_t procfs_buspower_show_2(char *buf, char **start, off_t offset, int count, int *eof, void *data)
396        {
397            return buspower_show_2(buf);
398        }
399        static ssize_t procfs_buspower_store_2(struct file *file, const char *buffer, unsigned long count, void *data)
400        {
401            char buf[10];
402            int i = 0;
403            uint32_t value;
404            if (copy_from_user(buf, &buffer[i], sizeof("0xFFFFFFFF\n")+1))
405                return -EFAULT;
406            value = simple_strtoul(buf, NULL, 16);
407            buspower_store_2(value);
408            return count;
409        }
410
411        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
412            static ssize_t sysfs_buspower_show_1( struct device *_dev, struct device_attribute *attr,char *buf)
413        #else
414            static ssize_t sysfs_buspower_show_1( struct device *_dev,char *buf)
415        #endif
416        {
417            return buspower_show_1(buf);
418        }
419        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
420            static ssize_t sysfs_buspower_store_1( struct device *_dev, struct device_attribute *attr,const char *buffer, size_t count )
421        #else
422            static ssize_t sysfs_buspower_store_1( struct device *_dev, const char *buffer, size_t count )
423        #endif
424        {
425            char buf[10];
426            int i = 0;
427            uint32_t value;
428            if (copy_from_user(buf, &buffer[i], sizeof("0xFFFFFFFF\n")+1))
429                return -EFAULT;
430            value = simple_strtoul(buf, NULL, 16);
431            buspower_store_1(value);
432            return count;
433        }
434        DEVICE_ATTR(buspower_1, S_IRUGO|S_IWUSR, sysfs_buspower_show_1, sysfs_buspower_store_1);
435
436        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
437            static ssize_t sysfs_buspower_show_2( struct device *_dev, struct device_attribute *attr,char *buf)
438        #else
439            static ssize_t sysfs_buspower_show_2( struct device *_dev,char *buf)
440        #endif
441        {
442            return buspower_show_2(buf);
443        }
444        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
445            static ssize_t sysfs_buspower_store_2( struct device *_dev, struct device_attribute *attr,const char *buffer, size_t count )
446        #else
447            static ssize_t sysfs_buspower_store_2( struct device *_dev, const char *buffer, size_t count )
448        #endif
449        {
450            char buf[10];
451            int i = 0;
452            uint32_t value;
453            if (copy_from_user(buf, &buffer[i], sizeof("0xFFFFFFFF\n")+1))
454                return -EFAULT;
455            value = simple_strtoul(buf, NULL, 16);
456            buspower_store_2(value);
457            return count;
458        }
459        DEVICE_ATTR(buspower_2, S_IRUGO|S_IWUSR, sysfs_buspower_show_2, sysfs_buspower_store_2);
460    #else
461        static ssize_t buspower_show(char *buf)
462        {
463            if(ifxusb_vbus (&ifxusb_hcd.core_if)==1) return sprintf( buf, "1\n" );
464            if(ifxusb_vbus (&ifxusb_hcd.core_if)==0) return sprintf( buf, "0\n" );
465            return sprintf( buf, "UNKNOWN\n" );
466        }
467        static void buspower_store(uint32_t value)
468        {
469            if (value==1) ifxusb_vbus_on (&ifxusb_hcd.core_if);
470            else if(value==0) ifxusb_vbus_off(&ifxusb_hcd.core_if);
471        }
472        static ssize_t procfs_buspower_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
473        {
474            return buspower_show(buf);
475        }
476        static ssize_t procfs_buspower_store(struct file *file, const char *buffer, unsigned long count, void *data)
477        {
478            char buf[10];
479            int i = 0;
480            uint32_t value;
481            if (copy_from_user(buf, &buffer[i], sizeof("0xFFFFFFFF\n")+1))
482                return -EFAULT;
483            value = simple_strtoul(buf, NULL, 16);
484            buspower_store(value);
485            return count;
486        }
487        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
488            static ssize_t sysfs_buspower_show( struct device *_dev, struct device_attribute *attr,char *buf)
489        #else
490            static ssize_t sysfs_buspower_show( struct device *_dev, char *buf)
491        #endif
492        {
493            return buspower_show(buf);
494        }
495        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
496            static ssize_t sysfs_buspower_store( struct device *_dev, struct device_attribute *attr,const char *buffer, size_t count )
497        #else
498            static ssize_t sysfs_buspower_store( struct device *_dev, const char *buffer, size_t count )
499        #endif
500        {
501            char buf[10];
502            int i = 0;
503            uint32_t value;
504            if (copy_from_user(buf, &buffer[i], sizeof("0xFFFFFFFF\n")+1))
505                return -EFAULT;
506            value = simple_strtoul(buf, NULL, 16);
507            buspower_store(value);
508            return count;
509        }
510        DEVICE_ATTR(buspower, S_IRUGO|S_IWUSR, sysfs_buspower_show, sysfs_buspower_store);
511    #endif
512
513/////////////////////////////////////////////////////////////////////////////////////////////////////
514/////////////////////////////////////////////////////////////////////////////////////////////////////
515/////////////////////////////////////////////////////////////////////////////////////////////////////
516
517
518    #ifdef __IS_DUAL__
519        static ssize_t bussuspend_show_1(char *buf)
520        {
521            hprt0_data_t val;
522            val.d32 = ifxusb_rreg(ifxusb_hcd_1.core_if.hprt0);
523            return sprintf (buf, "Bus Suspend = 0x%x\n", val.b.prtsusp);
524        }
525        static ssize_t bussuspend_show_2(char *buf)
526        {
527            hprt0_data_t val;
528            val.d32 = ifxusb_rreg(ifxusb_hcd_2.core_if.hprt0);
529            return sprintf (buf, "Bus Suspend = 0x%x\n", val.b.prtsusp);
530        }
531
532        static ssize_t procfs_bussuspend_show_1(char *buf, char **start, off_t offset, int count, int *eof, void *data)
533        {
534            return bussuspend_show_1(buf);
535        }
536        static ssize_t procfs_bussuspend_show_2(char *buf, char **start, off_t offset, int count, int *eof, void *data)
537        {
538            return bussuspend_show_2(buf);
539        }
540        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
541            static ssize_t sysfs_bussuspend_show_1( struct device *_dev, struct device_attribute *attr,char *buf)
542        #else
543            static ssize_t sysfs_bussuspend_show_1( struct device *_dev,char *buf)
544        #endif
545        {
546            return bussuspend_show_1(buf);
547        }
548        DEVICE_ATTR(bussuspend_1, S_IRUGO|S_IWUSR, sysfs_bussuspend_show_1, 0);
549        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
550            static ssize_t sysfs_bussuspend_show_2( struct device *_dev, struct device_attribute *attr,char *buf)
551        #else
552            static ssize_t sysfs_bussuspend_show_2( struct device *_dev,char *buf)
553        #endif
554        {
555            return bussuspend_show_2(buf);
556        }
557        DEVICE_ATTR(bussuspend_2, S_IRUGO|S_IWUSR, sysfs_bussuspend_show_2, 0);
558    #else
559        static ssize_t bussuspend_show(char *buf)
560        {
561            hprt0_data_t val;
562            val.d32 = ifxusb_rreg(ifxusb_hcd.core_if.hprt0);
563            return sprintf (buf, "Bus Suspend = 0x%x\n", val.b.prtsusp);
564        }
565        static ssize_t procfs_bussuspend_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
566        {
567            return bussuspend_show(buf);
568        }
569
570        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
571            static ssize_t sysfs_bussuspend_show( struct device *_dev, struct device_attribute *attr,char *buf)
572        #else
573            static ssize_t sysfs_bussuspend_show( struct device *_dev, char *buf)
574        #endif
575        {
576            return bussuspend_show(buf);
577        }
578        DEVICE_ATTR(bussuspend, S_IRUGO|S_IWUSR, sysfs_bussuspend_show, 0);
579    #endif
580
581/////////////////////////////////////////////////////////////////////////////////////////////////////
582/////////////////////////////////////////////////////////////////////////////////////////////////////
583/////////////////////////////////////////////////////////////////////////////////////////////////////
584
585    #ifdef __IS_DUAL__
586        static ssize_t busconnected_show_1(char *buf)
587        {
588            hprt0_data_t val;
589            val.d32 = ifxusb_rreg(ifxusb_hcd_1.core_if.hprt0);
590            return sprintf (buf, "Bus Connected = 0x%x\n", val.b.prtconnsts);
591        }
592        static ssize_t busconnected_show_2(char *buf)
593        {
594            hprt0_data_t val;
595            val.d32 = ifxusb_rreg(ifxusb_hcd_2.core_if.hprt0);
596            return sprintf (buf, "Bus Connected = 0x%x\n", val.b.prtconnsts);
597        }
598
599        static ssize_t procfs_busconnected_show_1(char *buf, char **start, off_t offset, int count, int *eof, void *data)
600        {
601            return busconnected_show_1(buf);
602        }
603        static ssize_t procfs_busconnected_show_2(char *buf, char **start, off_t offset, int count, int *eof, void *data)
604        {
605            return busconnected_show_2(buf);
606        }
607        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
608            static ssize_t sysfs_busconnected_show_1( struct device *_dev, struct device_attribute *attr,char *buf)
609        #else
610            static ssize_t sysfs_busconnected_show_1( struct device *_dev,char *buf)
611        #endif
612        {
613            return busconnected_show_1(buf);
614        }
615        DEVICE_ATTR(busconnected_1, S_IRUGO|S_IWUSR, sysfs_busconnected_show_1, 0);
616        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
617            static ssize_t sysfs_busconnected_show_2( struct device *_dev, struct device_attribute *attr,char *buf)
618        #else
619            static ssize_t sysfs_busconnected_show_2( struct device *_dev,char *buf)
620        #endif
621        {
622            return busconnected_show_2(buf);
623        }
624        DEVICE_ATTR(busconnected_2, S_IRUGO|S_IWUSR, sysfs_busconnected_show_2, 0);
625    #else
626        static ssize_t busconnected_show(char *buf)
627        {
628            hprt0_data_t val;
629            val.d32 = ifxusb_rreg(ifxusb_hcd.core_if.hprt0);
630            return sprintf (buf, "Bus Connected = 0x%x\n", val.b.prtconnsts);
631        }
632        static ssize_t procfs_busconnected_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
633        {
634            return busconnected_show(buf);
635        }
636
637        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
638            static ssize_t sysfs_busconnected_show( struct device *_dev, struct device_attribute *attr,char *buf)
639        #else
640            static ssize_t sysfs_busconnected_show( struct device *_dev, char *buf)
641        #endif
642        {
643            return busconnected_show(buf);
644        }
645        DEVICE_ATTR(busconnected, S_IRUGO|S_IWUSR, sysfs_busconnected_show, 0);
646    #endif
647
648/////////////////////////////////////////////////////////////////////////////////////////////////////
649/////////////////////////////////////////////////////////////////////////////////////////////////////
650/////////////////////////////////////////////////////////////////////////////////////////////////////
651
652    #ifdef __IS_DUAL__
653        static ssize_t connectspeed_show_1(char *buf)
654        {
655            hprt0_data_t val;
656            val.d32 = ifxusb_rreg(ifxusb_hcd_1.core_if.hprt0);
657            if( val.b.prtspd ==0) return sprintf (buf, "Bus Speed = High (%d)\n", val.b.prtspd);
658            if( val.b.prtspd ==1) return sprintf (buf, "Bus Speed = Full (%d)\n", val.b.prtspd);
659            if( val.b.prtspd ==2) return sprintf (buf, "Bus Speed = Low (%d)\n", val.b.prtspd);
660                                  return sprintf (buf, "Bus Speed = Unknown (%d)\n", val.b.prtspd);
661        }
662        static ssize_t connectspeed_show_2(char *buf)
663        {
664            hprt0_data_t val;
665            val.d32 = ifxusb_rreg(ifxusb_hcd_2.core_if.hprt0);
666            if( val.b.prtspd ==0) return sprintf (buf, "Bus Speed = High (%d)\n", val.b.prtspd);
667            if( val.b.prtspd ==1) return sprintf (buf, "Bus Speed = Full (%d)\n", val.b.prtspd);
668            if( val.b.prtspd ==2) return sprintf (buf, "Bus Speed = Low (%d)\n", val.b.prtspd);
669                                  return sprintf (buf, "Bus Speed = Unknown (%d)\n", val.b.prtspd);
670        }
671
672        static ssize_t procfs_connectspeed_show_1(char *buf, char **start, off_t offset, int count, int *eof, void *data)
673        {
674            return connectspeed_show_1(buf);
675        }
676        static ssize_t procfs_connectspeed_show_2(char *buf, char **start, off_t offset, int count, int *eof, void *data)
677        {
678            return connectspeed_show_2(buf);
679        }
680        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
681            static ssize_t sysfs_connectspeed_show_1( struct device *_dev, struct device_attribute *attr,char *buf)
682        #else
683            static ssize_t sysfs_connectspeed_show_1( struct device *_dev,char *buf)
684        #endif
685        {
686            return connectspeed_show_1(buf);
687        }
688        DEVICE_ATTR(connectspeed_1, S_IRUGO|S_IWUSR, sysfs_connectspeed_show_1, 0);
689        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
690            static ssize_t sysfs_connectspeed_show_2( struct device *_dev, struct device_attribute *attr,char *buf)
691        #else
692            static ssize_t sysfs_connectspeed_show_2( struct device *_dev,char *buf)
693        #endif
694        {
695            return connectspeed_show_2(buf);
696        }
697        DEVICE_ATTR(connectspeed_2, S_IRUGO|S_IWUSR, sysfs_connectspeed_show_2, 0);
698    #else
699        static ssize_t connectspeed_show(char *buf)
700        {
701            hprt0_data_t val;
702            val.d32 = ifxusb_rreg(ifxusb_hcd.core_if.hprt0);
703            if( val.b.prtspd ==0) return sprintf (buf, "Bus Speed = High (%d)\n", val.b.prtspd);
704            if( val.b.prtspd ==1) return sprintf (buf, "Bus Speed = Full (%d)\n", val.b.prtspd);
705            if( val.b.prtspd ==2) return sprintf (buf, "Bus Speed = Low (%d)\n", val.b.prtspd);
706                                  return sprintf (buf, "Bus Speed = Unknown (%d)\n", val.b.prtspd);
707        }
708
709        static ssize_t procfs_connectspeed_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
710        {
711            return connectspeed_show(buf);
712        }
713
714        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
715            static ssize_t sysfs_connectspeed_show( struct device *_dev, struct device_attribute *attr,char *buf)
716        #else
717            static ssize_t sysfs_connectspeed_show( struct device *_dev, char *buf)
718        #endif
719        {
720            return connectspeed_show(buf);
721        }
722        DEVICE_ATTR(connectspeed, S_IRUGO|S_IWUSR, sysfs_connectspeed_show, 0);
723    #endif
724/////////////////////////////////////////////////////////////////////////////////////////////////////
725/////////////////////////////////////////////////////////////////////////////////////////////////////
726/////////////////////////////////////////////////////////////////////////////////////////////////////
727#endif
728
729
730#ifdef __IS_DEVICE__
731/////////////////////////////////////////////////////////////////////////////////////////////////////
732/////////////////////////////////////////////////////////////////////////////////////////////////////
733/////////////////////////////////////////////////////////////////////////////////////////////////////
734    static ssize_t devspeed_show(char *buf)
735    {
736        dcfg_data_t val;
737        val.d32 = ifxusb_rreg(&ifxusb_pcd.core_if.dev_global_regs->dcfg);
738        if( val.b.devspd ==0) return sprintf (buf, "Dev Speed = High (%d)\n", val.b.devspd);
739        if( val.b.devspd ==1) return sprintf (buf, "Dev Speed = Full (%d)\n", val.b.devspd);
740        if( val.b.devspd ==3) return sprintf (buf, "Dev Speed = Full (%d)\n", val.b.devspd);
741                              return sprintf (buf, "Dev Speed = Unknown (%d)\n", val.b.devspd);
742    }
743
744    static ssize_t procfs_devspeed_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
745    {
746        return devspeed_show(buf);
747    }
748
749    #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
750        static ssize_t sysfs_devspeed_show( struct device *_dev, struct device_attribute *attr,char *buf)
751    #else
752        static ssize_t sysfs_devspeed_show( struct device *_dev, char *buf)
753    #endif
754    {
755        return devspeed_show(buf);
756    }
757    DEVICE_ATTR(devspeed, S_IRUGO|S_IWUSR, sysfs_devspeed_show, 0);
758
759    static ssize_t enumspeed_show(char *buf)
760    {
761        dsts_data_t val;
762        val.d32 = ifxusb_rreg(&ifxusb_pcd.core_if.dev_global_regs->dsts);
763        if( val.b.enumspd ==0) return sprintf (buf, "Enum Speed = High (%d)\n", val.b.enumspd);
764        if( val.b.enumspd ==1) return sprintf (buf, "Enum Speed = Full (%d)\n", val.b.enumspd);
765        if( val.b.enumspd ==2) return sprintf (buf, "Enum Speed = Low (%d)\n", val.b.enumspd);
766        return sprintf (buf, "Enum Speed = invalid(%d)\n", val.b.enumspd);
767    }
768
769    static ssize_t procfs_enumspeed_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
770    {
771        return enumspeed_show(buf);
772    }
773
774    #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
775        static ssize_t sysfs_enumspeed_show( struct device *_dev, struct device_attribute *attr,char *buf)
776    #else
777        static ssize_t sysfs_enumspeed_show( struct device *_dev, char *buf)
778    #endif
779    {
780        return enumspeed_show(buf);
781    }
782    DEVICE_ATTR(enumspeed, S_IRUGO|S_IWUSR, sysfs_enumspeed_show, 0);
783/////////////////////////////////////////////////////////////////////////////////////////////////////
784/////////////////////////////////////////////////////////////////////////////////////////////////////
785/////////////////////////////////////////////////////////////////////////////////////////////////////
786#endif
787
788
789//////////////////////////////////////////////////////////////////////////////////
790#ifdef __ENABLE_DUMP__
791
792    #ifdef __IS_DUAL__
793        static void dump_reg_1(void)
794        {
795            ifxusb_dump_registers(&ifxusb_hcd_1.core_if);
796        }
797        static void dump_reg_2(void)
798        {
799            ifxusb_dump_registers(&ifxusb_hcd_2.core_if);
800        }
801
802        static ssize_t procfs_dump_reg_show_1(char *buf, char **start, off_t offset, int count, int *eof, void *data)
803        {
804            dump_reg_1();
805            return 0;
806        }
807        static ssize_t procfs_dump_reg_show_2(char *buf, char **start, off_t offset, int count, int *eof, void *data)
808        {
809            dump_reg_2();
810            return 0;
811        }
812        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
813            static ssize_t sysfs_dump_reg_show_1( struct device *_dev, struct device_attribute *attr,char *buf)
814        #else
815            static ssize_t sysfs_dump_reg_show_1( struct device *_dev,char *buf)
816        #endif
817        {
818            dump_reg_1();
819            return 0;
820        }
821        DEVICE_ATTR(dump_reg_1, S_IRUGO|S_IWUSR, sysfs_dump_reg_show_1, 0);
822        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
823            static ssize_t sysfs_dump_reg_show_2( struct device *_dev, struct device_attribute *attr,char *buf)
824        #else
825            static ssize_t sysfs_dump_reg_show_2( struct device *_dev,char *buf)
826        #endif
827        {
828            dump_reg_2();
829            return 0;
830        }
831        DEVICE_ATTR(dump_reg_2, S_IRUGO|S_IWUSR, sysfs_dump_reg_show_2, 0);
832    #else
833        static void dump_reg(void)
834        {
835            #ifdef __IS_HOST__
836                ifxusb_dump_registers(&ifxusb_hcd.core_if);
837            #endif
838            #ifdef __IS_DEVICE__
839                ifxusb_dump_registers(&ifxusb_pcd.core_if);
840            #endif
841        }
842        static ssize_t procfs_dump_reg_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
843        {
844            dump_reg();
845            return 0;
846        }
847        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
848            static ssize_t sysfs_dump_reg_show( struct device *_dev, struct device_attribute *attr,char *buf)
849        #else
850            static ssize_t sysfs_dump_reg_show( struct device *_dev,char *buf)
851        #endif
852        {
853            dump_reg();
854            return 0;
855        }
856        DEVICE_ATTR(dump_reg, S_IRUGO|S_IWUSR, sysfs_dump_reg_show, 0);
857    #endif
858
859
860/////////////////////////////////////////////////////////////////////////////////////////////////////
861/////////////////////////////////////////////////////////////////////////////////////////////////////
862/////////////////////////////////////////////////////////////////////////////////////////////////////
863
864    #ifdef __IS_DUAL__
865        static void dump_spram_1(void)
866        {
867            ifxusb_dump_spram(&ifxusb_hcd_1.core_if);
868        }
869        static void dump_spram_2(void)
870        {
871            ifxusb_dump_spram(&ifxusb_hcd_2.core_if);
872        }
873
874        static ssize_t procfs_dump_spram_show_1(char *buf, char **start, off_t offset, int count, int *eof, void *data)
875        {
876            dump_spram_1();
877            return 0;
878        }
879        static ssize_t procfs_dump_spram_show_2(char *buf, char **start, off_t offset, int count, int *eof, void *data)
880        {
881            dump_spram_2();
882            return 0;
883        }
884        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
885            static ssize_t sysfs_dump_spram_show_1( struct device *_dev, struct device_attribute *attr,char *buf)
886        #else
887            static ssize_t sysfs_dump_spram_show_1( struct device *_dev,char *buf)
888        #endif
889        {
890            dump_spram_1();
891            return 0;
892        }
893        DEVICE_ATTR(dump_spram_1, S_IRUGO|S_IWUSR, sysfs_dump_spram_show_1, 0);
894
895        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
896            static ssize_t sysfs_dump_spram_show_2( struct device *_dev, struct device_attribute *attr,char *buf)
897        #else
898            static ssize_t sysfs_dump_spram_show_2( struct device *_dev,char *buf)
899        #endif
900        {
901            dump_spram_2();
902            return 0;
903        }
904        DEVICE_ATTR(dump_spram_2, S_IRUGO|S_IWUSR, sysfs_dump_spram_show_2, 0);
905    #else
906        static void dump_spram(void)
907        {
908            #ifdef __IS_HOST__
909                ifxusb_dump_spram(&ifxusb_hcd.core_if);
910            #endif
911            #ifdef __IS_DEVICE__
912                ifxusb_dump_spram(&ifxusb_pcd.core_if);
913            #endif
914        }
915        static ssize_t procfs_dump_spram_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
916        {
917            dump_spram();
918            return 0;
919        }
920        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
921            static ssize_t sysfs_dump_spram_show( struct device *_dev, struct device_attribute *attr,char *buf)
922        #else
923            static ssize_t sysfs_dump_spram_show( struct device *_dev,char *buf)
924        #endif
925        {
926            dump_spram();
927            return 0;
928        }
929        DEVICE_ATTR(dump_spram, S_IRUGO|S_IWUSR, sysfs_dump_spram_show, 0);
930    #endif
931/////////////////////////////////////////////////////////////////////////////////////////////////////
932/////////////////////////////////////////////////////////////////////////////////////////////////////
933/////////////////////////////////////////////////////////////////////////////////////////////////////
934
935    #ifdef __IS_HOST__
936        #ifdef __IS_DUAL__
937            static ssize_t procfs_dump_host_state_show_1(char *buf, char **start, off_t offset, int count, int *eof, void *data)
938            {
939                ifxhcd_dump_state(&ifxusb_hcd_1);
940                return 0;
941            }
942            static ssize_t procfs_dump_host_state_show_2(char *buf, char **start, off_t offset, int count, int *eof, void *data)
943            {
944                ifxhcd_dump_state(&ifxusb_hcd_2);
945                return 0;
946            }
947            #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
948                static ssize_t sysfs_dump_host_state_show_1( struct device *_dev, struct device_attribute *attr,char *buf)
949            #else
950                static ssize_t sysfs_dump_host_state_show_1( struct device *_dev,char *buf)
951            #endif
952            {
953                ifxhcd_dump_state(&ifxusb_hcd_1);
954                return 0;
955            }
956            DEVICE_ATTR(dump_host_state_1, S_IRUGO|S_IWUSR, sysfs_dump_host_state_show_1, 0);
957            #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
958                static ssize_t sysfs_dump_host_state_show_2( struct device *_dev, struct device_attribute *attr,char *buf)
959            #else
960                static ssize_t sysfs_dump_host_state_show_2( struct device *_dev,char *buf)
961            #endif
962            {
963                ifxhcd_dump_state(&ifxusb_hcd_2);
964                return 0;
965            }
966            DEVICE_ATTR(dump_host_state_2, S_IRUGO|S_IWUSR, sysfs_dump_host_state_show_2, 0);
967        #else
968            static ssize_t procfs_dump_host_state_show(char *buf, char **start, off_t offset, int count, int *eof, void *data)
969            {
970                ifxhcd_dump_state(&ifxusb_hcd);
971                return 0;
972            }
973            #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
974                static ssize_t sysfs_dump_host_state_show( struct device *_dev, struct device_attribute *attr,char *buf)
975            #else
976                static ssize_t sysfs_dump_host_state_show( struct device *_dev,char *buf)
977            #endif
978            {
979                ifxhcd_dump_state(&ifxusb_hcd);
980                return 0;
981            }
982            DEVICE_ATTR(dump_host_state, S_IRUGO|S_IWUSR, sysfs_dump_host_state_show, 0);
983        #endif
984
985/////////////////////////////////////////////////////////////////////////////////////////////////////
986/////////////////////////////////////////////////////////////////////////////////////////////////////
987/////////////////////////////////////////////////////////////////////////////////////////////////////
988
989    #endif //IS_HOST_
990
991#endif //__ENABLE_DUMP__
992
993//////////////////////////////////////////////////////////////////////////////////
994
995static int ifx_proc_addproc(char *funcname, read_proc_t *hookfuncr, write_proc_t *hookfuncw);
996static void ifx_proc_delproc(char *funcname);
997
998//////////////////////////////////////////////////////////////////////////////////
999
1000/*!
1001  \brief This function create the sysfs and procfs entries
1002  \param[in] _dev Pointer of device structure, if applied
1003 */
1004void ifxusb_attr_create (void *_dev)
1005{
1006    int error;
1007
1008    struct device *dev = (struct device *) _dev;
1009
1010    IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
1011    error = ifx_proc_addproc("dbglevel", procfs_dbglevel_show, procfs_dbglevel_store);
1012    error = device_create_file(dev, &dev_attr_dbglevel);
1013
1014    #ifdef __IS_DUAL__
1015        error = ifx_proc_addproc("dump_params_1", procfs_dump_params_show_1, NULL);
1016        error = ifx_proc_addproc("dump_params_2", procfs_dump_params_show_2, NULL);
1017        error = device_create_file(dev, &dev_attr_dump_params_1);
1018        error = device_create_file(dev, &dev_attr_dump_params_2);
1019    #else
1020        error = ifx_proc_addproc("dump_params", procfs_dump_params_show, NULL);
1021        error = device_create_file(dev, &dev_attr_dump_params);
1022    #endif
1023
1024    #ifdef __IS_DUAL__
1025        error = ifx_proc_addproc("mode_1", procfs_mode_show_1, NULL);
1026        error = ifx_proc_addproc("mode_2", procfs_mode_show_2, NULL);
1027        error = device_create_file(dev, &dev_attr_mode_1);
1028        error = device_create_file(dev, &dev_attr_mode_2);
1029    #else
1030        error = ifx_proc_addproc("mode", procfs_mode_show, NULL);
1031        error = device_create_file(dev, &dev_attr_mode);
1032    #endif
1033
1034    #ifdef __IS_HOST__
1035        #ifdef __IS_DUAL__
1036            error = ifx_proc_addproc("buspower_1", procfs_buspower_show_1, procfs_buspower_store_1);
1037            error = ifx_proc_addproc("buspower_2", procfs_buspower_show_2, procfs_buspower_store_2);
1038            error = device_create_file(dev, &dev_attr_buspower_1);
1039            error = device_create_file(dev, &dev_attr_buspower_2);
1040        #else
1041            error = ifx_proc_addproc("buspower", procfs_buspower_show, procfs_buspower_store);
1042            error = device_create_file(dev, &dev_attr_buspower);
1043        #endif
1044
1045        #ifdef __IS_DUAL__
1046            error = ifx_proc_addproc("bussuspend_1", procfs_bussuspend_show_1, NULL);
1047            error = ifx_proc_addproc("bussuspend_2", procfs_bussuspend_show_2, NULL);
1048            error = device_create_file(dev, &dev_attr_bussuspend_1);
1049            error = device_create_file(dev, &dev_attr_bussuspend_2);
1050        #else
1051            error = ifx_proc_addproc("bussuspend", procfs_bussuspend_show, NULL);
1052            error = device_create_file(dev, &dev_attr_bussuspend);
1053        #endif
1054
1055        #ifdef __IS_DUAL__
1056            error = ifx_proc_addproc("busconnected_1", procfs_busconnected_show_1, NULL);
1057            error = ifx_proc_addproc("busconnected_2", procfs_busconnected_show_2, NULL);
1058            error = device_create_file(dev, &dev_attr_busconnected_1);
1059            error = device_create_file(dev, &dev_attr_busconnected_2);
1060        #else
1061            error = ifx_proc_addproc("busconnected", procfs_busconnected_show, NULL);
1062            error = device_create_file(dev, &dev_attr_busconnected);
1063        #endif
1064
1065        #ifdef __IS_DUAL__
1066            error = ifx_proc_addproc("connectspeed_1", procfs_connectspeed_show_1, NULL);
1067            error = ifx_proc_addproc("connectspeed_2", procfs_connectspeed_show_2, NULL);
1068            error = device_create_file(dev, &dev_attr_connectspeed_1);
1069            error = device_create_file(dev, &dev_attr_connectspeed_2);
1070        #else
1071            error = ifx_proc_addproc("connectspeed", procfs_connectspeed_show, NULL);
1072            error = device_create_file(dev, &dev_attr_connectspeed);
1073        #endif
1074    #endif
1075
1076    #ifdef __IS_DEVICE__
1077        error = ifx_proc_addproc("devspeed", procfs_devspeed_show, NULL);
1078        error = device_create_file(dev, &dev_attr_devspeed);
1079        error = ifx_proc_addproc("enumspeed", procfs_enumspeed_show, NULL);
1080        error = device_create_file(dev, &dev_attr_enumspeed);
1081    #endif
1082
1083    //////////////////////////////////////////////////////
1084    #ifdef __ENABLE_DUMP__
1085        #ifdef __IS_DUAL__
1086            error = ifx_proc_addproc("dump_reg_1", procfs_dump_reg_show_1, NULL);
1087            error = ifx_proc_addproc("dump_reg_2", procfs_dump_reg_show_2, NULL);
1088            error = device_create_file(dev, &dev_attr_dump_reg_1);
1089            error = device_create_file(dev, &dev_attr_dump_reg_2);
1090        #else
1091            error = ifx_proc_addproc("dump_reg", procfs_dump_reg_show, NULL);
1092            error = device_create_file(dev, &dev_attr_dump_reg);
1093        #endif
1094
1095        #ifdef __IS_DUAL__
1096            error = ifx_proc_addproc("dump_spram_1", procfs_dump_spram_show_1, NULL);
1097            error = ifx_proc_addproc("dump_spram_2", procfs_dump_spram_show_2, NULL);
1098            error = device_create_file(dev, &dev_attr_dump_spram_1);
1099            error = device_create_file(dev, &dev_attr_dump_spram_2);
1100        #else
1101            error = ifx_proc_addproc("dump_spram", procfs_dump_spram_show, NULL);
1102            error = device_create_file(dev, &dev_attr_dump_spram);
1103        #endif
1104
1105        #ifdef __IS_HOST__
1106            #ifdef __IS_DUAL__
1107                error = ifx_proc_addproc("dump_host_state_1", procfs_dump_host_state_show_1, NULL);
1108                error = ifx_proc_addproc("dump_host_state_2", procfs_dump_host_state_show_2, NULL);
1109                error = device_create_file(dev, &dev_attr_dump_host_state_1);
1110                error = device_create_file(dev, &dev_attr_dump_host_state_2);
1111            #else
1112                error = ifx_proc_addproc("dump_host_state", procfs_dump_host_state_show, NULL);
1113                error = device_create_file(dev, &dev_attr_dump_host_state);
1114            #endif
1115        #endif
1116    #endif //__ENABLE_DUMP__
1117    //////////////////////////////////////////////////////
1118}
1119
1120
1121/*!
1122  \brief This function remove the sysfs and procfs entries
1123  \param[in] _dev Pointer of device structure, if applied
1124 */
1125void ifxusb_attr_remove (void *_dev)
1126{
1127    struct device *dev = (struct device *) _dev;
1128
1129    IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
1130    ifx_proc_delproc("dbglevel");
1131    device_remove_file(dev, &dev_attr_dbglevel);
1132
1133    #ifdef __IS_DUAL__
1134        ifx_proc_delproc("dump_params_1");
1135        ifx_proc_delproc("dump_params_2");
1136        device_remove_file(dev, &dev_attr_dump_params_1);
1137        device_remove_file(dev, &dev_attr_dump_params_2);
1138    #else
1139        ifx_proc_delproc("dump_params");
1140        device_remove_file(dev, &dev_attr_dump_params);
1141    #endif
1142
1143    #ifdef __IS_DUAL__
1144        ifx_proc_delproc("mode_1");
1145        ifx_proc_delproc("mode_2");
1146        device_remove_file(dev, &dev_attr_mode_1);
1147        device_remove_file(dev, &dev_attr_mode_2);
1148    #else
1149        ifx_proc_delproc("mode");
1150        device_remove_file(dev, &dev_attr_mode);
1151    #endif
1152
1153    #ifdef __IS_HOST__
1154        #ifdef __IS_DUAL__
1155            ifx_proc_delproc("buspower_1");
1156            ifx_proc_delproc("buspower_2");
1157            device_remove_file(dev, &dev_attr_buspower_1);
1158            device_remove_file(dev, &dev_attr_buspower_2);
1159        #else
1160            ifx_proc_delproc("buspower");
1161            device_remove_file(dev, &dev_attr_buspower);
1162        #endif
1163
1164        #ifdef __IS_DUAL__
1165            ifx_proc_delproc("bussuspend_1");
1166            ifx_proc_delproc("bussuspend_2");
1167            device_remove_file(dev, &dev_attr_bussuspend_1);
1168            device_remove_file(dev, &dev_attr_bussuspend_2);
1169        #else
1170            ifx_proc_delproc("bussuspend");
1171            device_remove_file(dev, &dev_attr_bussuspend);
1172        #endif
1173
1174        #ifdef __IS_DUAL__
1175            ifx_proc_delproc("busconnected_1");
1176            ifx_proc_delproc("busconnected_2");
1177            device_remove_file(dev, &dev_attr_busconnected_1);
1178            device_remove_file(dev, &dev_attr_busconnected_2);
1179        #else
1180            ifx_proc_delproc("busconnected");
1181            device_remove_file(dev, &dev_attr_busconnected);
1182        #endif
1183
1184        #ifdef __IS_DUAL__
1185            ifx_proc_delproc("connectspeed_1");
1186            ifx_proc_delproc("connectspeed_2");
1187            device_remove_file(dev, &dev_attr_connectspeed_1);
1188            device_remove_file(dev, &dev_attr_connectspeed_2);
1189        #else
1190            ifx_proc_delproc("connectspeed");
1191            device_remove_file(dev, &dev_attr_connectspeed);
1192        #endif
1193    #endif
1194
1195    #ifdef __IS_DEVICE__
1196        ifx_proc_delproc("devspeed");
1197        device_remove_file(dev, &dev_attr_devspeed);
1198        ifx_proc_delproc("enumspeed");
1199        device_remove_file(dev, &dev_attr_enumspeed);
1200    #endif
1201
1202    #ifdef __ENABLE_DUMP__
1203        #ifdef __IS_DUAL__
1204            ifx_proc_delproc("dump_reg_1");
1205            ifx_proc_delproc("dump_reg_2");
1206            device_remove_file(dev, &dev_attr_dump_reg_1);
1207            device_remove_file(dev, &dev_attr_dump_reg_2);
1208        #else
1209            ifx_proc_delproc("dump_reg");
1210            device_remove_file(dev, &dev_attr_dump_reg);
1211        #endif
1212
1213        #ifdef __IS_DUAL__
1214            ifx_proc_delproc("dump_spram_1");
1215            ifx_proc_delproc("dump_spram_2");
1216            device_remove_file(dev, &dev_attr_dump_spram_1);
1217            device_remove_file(dev, &dev_attr_dump_spram_2);
1218        #else
1219            ifx_proc_delproc("dump_spram");
1220            device_remove_file(dev, &dev_attr_dump_spram);
1221        #endif
1222
1223        #ifdef __IS_HOST__
1224            #ifdef __IS_DUAL__
1225                ifx_proc_delproc("dump_host_state_1");
1226                ifx_proc_delproc("dump_host_state_2");
1227                device_remove_file(dev, &dev_attr_dump_host_state_1);
1228                device_remove_file(dev, &dev_attr_dump_host_state_2);
1229            #else
1230                ifx_proc_delproc("dump_host_state");
1231                device_remove_file(dev, &dev_attr_dump_host_state);
1232            #endif
1233        #endif
1234    #endif //__ENABLE_DUMP__
1235    /* AVM/WK fix: del IFXUSB root dir*/
1236    ifx_proc_delproc(NULL);
1237}
1238
1239static struct proc_dir_entry * proc_ifx_root = NULL;
1240
1241/* initialize the proc file system and make a dir named /proc/[name] */
1242static void ifx_proc_init(void)
1243{
1244    IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
1245    proc_ifx_root = proc_mkdir(ifxusb_driver_name, (void *)0);
1246    if (!proc_ifx_root){
1247        IFX_PRINT("%s proc initialization failed! \n", ifxusb_driver_name);
1248        return;
1249    }
1250}
1251
1252/* proc file system add function for debugging. */
1253static int ifx_proc_addproc(char *funcname, read_proc_t *hookfuncr, write_proc_t *hookfuncw)
1254{
1255    struct proc_dir_entry *pe;
1256    IFX_DEBUGPL(DBG_ENTRY, "%s() %d\n", __func__, __LINE__ );
1257    if (!proc_ifx_root)
1258        ifx_proc_init();
1259
1260    if (hookfuncw == NULL)
1261    {
1262        pe = create_proc_read_entry(funcname, S_IRUGO, proc_ifx_root, hookfuncr, NULL);
1263        if (!pe)
1264        {
1265            IFX_PRINT("ERROR in creating read proc entry (%s)! \n", funcname);
1266            return -1;
1267        }
1268    }
1269    else
1270    {
1271        pe = create_proc_entry(funcname, S_IRUGO | S_IWUGO, proc_ifx_root);
1272        if (pe)
1273        {
1274            pe->read_proc = hookfuncr;
1275            pe->write_proc = hookfuncw;
1276        }
1277        else
1278        {
1279            IFX_PRINT("ERROR in creating proc entry (%s)! \n", funcname);
1280            return -1;
1281        }
1282    }
1283    return 0;
1284}
1285
1286
1287/* proc file system del function for removing module. */
1288static void ifx_proc_delproc(char *funcname)
1289{
1290/* AVM/WK Fix*/
1291    if (funcname != NULL) {
1292        remove_proc_entry(funcname, proc_ifx_root);
1293    } else {
1294        remove_proc_entry(ifxusb_driver_name, NULL);
1295        proc_ifx_root = NULL;
1296    }
1297}
1298
1299static void ifxusb_dump_params(ifxusb_core_if_t *_core_if)
1300{
1301    ifxusb_params_t *params=&_core_if->params;
1302
1303    #ifdef __IS_HOST__
1304        IFX_PRINT("IFXUSB Dump Parameters ( Host Mode) \n");
1305    #endif //__IS_HOST__
1306    #ifdef __IS_DEVICE__
1307        IFX_PRINT("IFXUSB Dump Parameters ( Device Mode) \n");
1308    #endif //__IS_DEVICE__
1309
1310    #ifdef __DESC_DMA__
1311        IFX_PRINT("DMA: Hermes DMA\n");
1312    #else
1313        IFX_PRINT("DMA: Non-Desc DMA\n");
1314    #endif
1315    IFX_PRINT(" Burst size: %d\n",params->dma_burst_size);
1316
1317    if (params->speed==1)
1318        IFX_PRINT("Full Speed only\n");
1319    else if(params->speed==0)
1320        IFX_PRINT("Full/Hign Speed\n");
1321    else
1322        IFX_PRINT("Unkonwn setting (%d) for Speed\n",params->speed);
1323
1324    IFX_PRINT("Total Data FIFO size: %d(0x%06X) DWord, %d(0x%06X) Bytes\n",
1325        params->data_fifo_size,params->data_fifo_size,
1326        params->data_fifo_size*4, params->data_fifo_size*4
1327    );
1328
1329    #ifdef __IS_DEVICE__
1330        IFX_PRINT("Rx FIFO size: %d(0x%06X) DWord, %d(0x%06X) Bytes\n",
1331            params->rx_fifo_size,params->rx_fifo_size,
1332            params->rx_fifo_size*4, params->rx_fifo_size*4
1333        );
1334        {
1335            int i;
1336            for(i=0;i<MAX_EPS_CHANNELS;i++)
1337            {
1338                IFX_PRINT("Tx FIFO #%d size: %d(0x%06X) DWord, %d(0x%06X) Bytes\n",i,
1339                    params->tx_fifo_size[i],params->tx_fifo_size[i],
1340                    params->tx_fifo_size[i]*4, params->tx_fifo_size[i]*4
1341                );
1342            }
1343        }
1344        #ifdef __DED_FIFO__
1345            IFX_PRINT("Treshold : %s Rx:%d Tx:%d \n",
1346                (params->thr_ctl)?"On":"Off",params->tx_thr_length,params->rx_thr_length);
1347        #endif
1348    #else //__IS_HOST__
1349        IFX_PRINT("Host Channels: %d\n",params->host_channels);
1350
1351        IFX_PRINT("Rx FIFO size: %d(0x%06X) DWord, %d(0x%06X) Bytes\n",
1352            params->data_fifo_size,params->data_fifo_size,
1353            params->data_fifo_size*4, params->data_fifo_size*4
1354        );
1355
1356        IFX_PRINT("NP Tx FIFO size: %d(0x%06X) DWord, %d(0x%06X) Bytes\n",
1357            params->nperio_tx_fifo_size,params->nperio_tx_fifo_size,
1358            params->nperio_tx_fifo_size*4, params->nperio_tx_fifo_size*4
1359        );
1360
1361        IFX_PRINT(" P Tx FIFO size: %d(0x%06X) DWord, %d(0x%06X) Bytes\n",
1362            params->perio_tx_fifo_size,params->perio_tx_fifo_size,
1363            params->perio_tx_fifo_size*4, params->perio_tx_fifo_size*4
1364        );
1365    #endif //__IS_HOST__
1366
1367    IFX_PRINT("Max Transfer size: %d(0x%06X) Bytes\n",
1368        params->max_transfer_size,params->max_transfer_size
1369    );
1370    IFX_PRINT("Max Packet Count: %d(0x%06X)\n",
1371        params->max_packet_count,params->max_packet_count
1372    );
1373
1374    IFX_PRINT("PHY UTMI Width: %d\n",params->phy_utmi_width);
1375
1376    IFX_PRINT("Turn Around Time: HS:%d FS:%d\n",params->turn_around_time_hs,params->turn_around_time_fs);
1377    IFX_PRINT("Timeout Calibration: HS:%d FS:%d\n",params->timeout_cal_hs,params->timeout_cal_fs);
1378
1379
1380    IFX_PRINT("==================================================\n");
1381    IFX_PRINT("End of Parameters Dump\n");
1382    IFX_PRINT("==================================================\n");
1383}
1384
1385
1386

Archive Download this file



interactive