1 /*
2 *******************************************************************************
3 *                                              usb host module
4 *
5 *                             Copyright(C), 2006-2008, SoftWinners Co., Ltd.
6 *                                                  All Rights Reserved
7 *
8 * File Name :
9 *
10 * Author : GLHuang(HoLiGun)
11 *
12 * Version : 1.0
13 *
14 * Date : 2008.07.07
15 *
16 * Description :
17 *           usb的通用设备模型,临时版本,
18 * History :
19 *
20 ********************************************************************************************************************
21 */
22 #include "usb_os_platform.h"
23 #include "usb_host_common.h"
24 
25 #include "usb_list.h"
26 
27 //to_usb_interface
28 //从sub_devf转换到interface
usb_mod_to_usb_interface(struct usb_host_virt_sub_dev * sub_dev)29 struct usb_interface *usb_mod_to_usb_interface(struct usb_host_virt_sub_dev *sub_dev)
30 {
31     if (!sub_dev)
32     {
33         hal_log_err("PANIC : usb_dev_mod :: from virt_sub_dev to usb_interface input == NULL\n");
34         return NULL;
35     }
36 
37     return sub_dev->sub_dev_interface;
38 }
39 
40 //从intf转换到virt_sub_dev
usb_mod_interface_to_virt_sub_dev(struct usb_interface * intf)41 struct usb_host_virt_sub_dev *usb_mod_interface_to_virt_sub_dev(struct usb_interface *intf)
42 {
43     if (!intf)
44     {
45         hal_log_err("PANIC : usb_dev_mod :: from usb_interface to virt_sub_dev input == NULL\n");
46         return NULL;
47     }
48 
49     return intf->virt_sub_dev;
50 }
51 
52 //从intf转换到func_drv
usb_mod_interface_to_func_drv(struct usb_interface * intf)53 struct usb_host_func_drv *usb_mod_interface_to_func_drv(struct usb_interface *intf)
54 {
55     if (!intf)
56     {
57         hal_log_err("PANIC : usb_dev_mod :: from usb_interface to virt_sub_dev input == NULL\n");
58         return NULL;
59     }
60 
61     if (intf->virt_sub_dev)
62     {
63         return intf->virt_sub_dev->func_drv;
64     }
65     else
66     {
67         hal_log_err("PANIC : usb_dev_mod :: from usb_interface to func_drv :  intf->virt_sub_dev == NULL\n");
68         return NULL;
69     }
70 }
71 
72 //interface_to_usbdev
73 //从intf转换到virt_dev
usb_mod_interface_to_usbdev(struct usb_interface * intf)74 struct usb_host_virt_dev *usb_mod_interface_to_usbdev(struct usb_interface *intf)
75 {
76     struct usb_host_virt_sub_dev *virt_sub_dev = NULL;
77 
78     //struct usb_host_virt_dev * virt_dev = NULL;
79     if (!intf)
80     {
81         hal_log_err("PANIC : usb_mod_interface_to_usbdev () inft == NULL\n");
82         return NULL;
83     }
84 
85     virt_sub_dev = usb_mod_interface_to_virt_sub_dev(intf);
86 
87     if (!virt_sub_dev)
88     {
89         hal_log_err("PANIC : usb_mod_interface_to_usbdev()  virt_sub_dev == NULL\n");
90         return NULL;
91     }
92 
93     return virt_sub_dev->father_dev;
94 }
95 
96 //=========================================================
97 //usb_get_intfdata
usb_mod_usb_get_intf_priv_data(struct usb_interface * intf)98 void *usb_mod_usb_get_intf_priv_data(struct usb_interface *intf)
99 {
100     if (!intf)
101     {
102         hal_log_err("PANIC : usb_mod_usb_get_intf_priv_data () inft == NULL\n");
103         return NULL;
104     }
105 
106     if (intf->virt_sub_dev && intf->virt_sub_dev->drv_pirv_data)
107     {
108         return  intf->virt_sub_dev->drv_pirv_data;
109     }
110     else
111     {
112         hal_log_err("PANIC : usb_mod_usb_get_intf_priv_data () intf->virt_sub_dev->drv_pirv_data == NULL\n");
113         return NULL;
114     }
115 }
116 
117 //usb_set_intfdata
usb_mod_usb_set_intf_priv_data(struct usb_interface * intf,void * data)118 void  usb_mod_usb_set_intf_priv_data(struct usb_interface *intf, void *data)
119 {
120     if (!intf)
121     {
122         hal_log_err("PANIC : usb_mod_usb_set_intf_priv_data () inft == NULL\n");
123         return ;
124     }
125 
126     //  if(intf->virt_sub_dev && intf->virt_sub_dev->drv_pirv_data){
127     if (intf->virt_sub_dev)
128     {
129         intf->virt_sub_dev->drv_pirv_data = data;
130     }
131     else
132     {
133         hal_log_err("PANIC : usb_mod_usb_set_intf_priv_data () intf->virt_sub_dev->drv_pirv_data == NULL\n");
134     }
135 }
136 
137 
138