Update ABI version
[platform/hal/backend/tm1/device-tm1.git] / hw / usb_gadget / usb_gadget.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <errno.h>
18 #include <stdlib.h>
19
20 #include <hal/hal-common-interface.h>
21 #include <hal/device/hal-usb_gadget-interface.h>
22
23 #include </hal/include/device/hal-backend-common-usb_gadget.h>
24 #include </hal/include/device/hal-backend-common.h>
25
26 static int usb_gadget_init(void **data)
27 {
28         hal_backend_usb_gadget_funcs *usb_gadget_funcs;
29
30         if (!data)
31                 return -EINVAL;
32
33         usb_gadget_funcs = calloc(1, sizeof(hal_backend_usb_gadget_funcs));
34         if (!usb_gadget_funcs)
35                 return -ENOMEM;
36
37         // usb_gadget_translator
38         if (simple_translator_open(usb_gadget_funcs)) {
39                 _E("No USB gadget translator");
40                 goto error_translator_open;
41         }
42
43         // usb_client
44         if (hw_legacy_gadget_open(usb_gadget_funcs)) {
45                 _I("No USB client");
46                 goto error_gadget_open;
47         }
48
49         *data = (void *)usb_gadget_funcs;
50
51         return 0;
52
53 error_gadget_open:
54         simple_translator_close(usb_gadget_funcs);
55
56 error_translator_open:
57         free(usb_gadget_funcs);
58
59         return -ENODEV;
60 }
61
62 static int usb_gadget_exit(void *data)
63 {
64         hal_backend_usb_gadget_funcs *usb_gadget_funcs = (hal_backend_usb_gadget_funcs *)data;
65
66         if (usb_gadget_funcs) {
67                 hw_legacy_gadget_close(usb_gadget_funcs);
68                 simple_translator_close(usb_gadget_funcs);
69                 free(usb_gadget_funcs);
70         }
71
72         return 0;
73 }
74
75 hal_backend EXPORT hal_backend_device_usb_gadget_data = {
76         .name = "usb_gadget",
77         .vendor = "SC7730",
78         .abi_version = HAL_ABI_VERSION_TIZEN_7_0,
79         .init = usb_gadget_init,
80         .exit = usb_gadget_exit,
81 };