summaryrefslogtreecommitdiff
path: root/bsp/allwinner/libraries/sunxi-hal/hal/source/usb/include/usb_gen_dev_mod.c
blob: 1da8ab24743047ed285b8e13db8a61450ef8dcf0 (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
/*
*******************************************************************************
*                                              usb host module
*
*                             Copyright(C), 2006-2008, SoftWinners Co., Ltd.
*                                                  All Rights Reserved
*
* File Name :
*
* Author : GLHuang(HoLiGun)
*
* Version : 1.0
*
* Date : 2008.07.07
*
* Description :
*           usb的通用设备模型,临时版本,
* History :
*
********************************************************************************************************************
*/
#include "usb_os_platform.h"
#include "usb_host_common.h"

#include "usb_list.h"

//to_usb_interface
//从sub_devf转换到interface
struct usb_interface *usb_mod_to_usb_interface(struct usb_host_virt_sub_dev *sub_dev)
{
    if (!sub_dev)
    {
        hal_log_err("PANIC : usb_dev_mod :: from virt_sub_dev to usb_interface input == NULL\n");
        return NULL;
    }

    return sub_dev->sub_dev_interface;
}

//从intf转换到virt_sub_dev
struct usb_host_virt_sub_dev *usb_mod_interface_to_virt_sub_dev(struct usb_interface *intf)
{
    if (!intf)
    {
        hal_log_err("PANIC : usb_dev_mod :: from usb_interface to virt_sub_dev input == NULL\n");
        return NULL;
    }

    return intf->virt_sub_dev;
}

//从intf转换到func_drv
struct usb_host_func_drv *usb_mod_interface_to_func_drv(struct usb_interface *intf)
{
    if (!intf)
    {
        hal_log_err("PANIC : usb_dev_mod :: from usb_interface to virt_sub_dev input == NULL\n");
        return NULL;
    }

    if (intf->virt_sub_dev)
    {
        return intf->virt_sub_dev->func_drv;
    }
    else
    {
        hal_log_err("PANIC : usb_dev_mod :: from usb_interface to func_drv :  intf->virt_sub_dev == NULL\n");
        return NULL;
    }
}

//interface_to_usbdev
//从intf转换到virt_dev
struct usb_host_virt_dev *usb_mod_interface_to_usbdev(struct usb_interface *intf)
{
    struct usb_host_virt_sub_dev *virt_sub_dev = NULL;

    //struct usb_host_virt_dev * virt_dev = NULL;
    if (!intf)
    {
        hal_log_err("PANIC : usb_mod_interface_to_usbdev () inft == NULL\n");
        return NULL;
    }

    virt_sub_dev = usb_mod_interface_to_virt_sub_dev(intf);

    if (!virt_sub_dev)
    {
        hal_log_err("PANIC : usb_mod_interface_to_usbdev()  virt_sub_dev == NULL\n");
        return NULL;
    }

    return virt_sub_dev->father_dev;
}

//=========================================================
//usb_get_intfdata
void *usb_mod_usb_get_intf_priv_data(struct usb_interface *intf)
{
    if (!intf)
    {
        hal_log_err("PANIC : usb_mod_usb_get_intf_priv_data () inft == NULL\n");
        return NULL;
    }

    if (intf->virt_sub_dev && intf->virt_sub_dev->drv_pirv_data)
    {
        return  intf->virt_sub_dev->drv_pirv_data;
    }
    else
    {
        hal_log_err("PANIC : usb_mod_usb_get_intf_priv_data () intf->virt_sub_dev->drv_pirv_data == NULL\n");
        return NULL;
    }
}

//usb_set_intfdata
void  usb_mod_usb_set_intf_priv_data(struct usb_interface *intf, void *data)
{
    if (!intf)
    {
        hal_log_err("PANIC : usb_mod_usb_set_intf_priv_data () inft == NULL\n");
        return ;
    }

    //  if(intf->virt_sub_dev && intf->virt_sub_dev->drv_pirv_data){
    if (intf->virt_sub_dev)
    {
        intf->virt_sub_dev->drv_pirv_data = data;
    }
    else
    {
        hal_log_err("PANIC : usb_mod_usb_set_intf_priv_data () intf->virt_sub_dev->drv_pirv_data == NULL\n");
    }
}