4 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #ifndef __HW_USB_GADGET_H__
20 #define __HW_USB_GADGET_H__
24 #include <hw/common.h>
26 /* The id of this device */
27 #define USB_GADGET_DEVICE_ID "usb_gadget"
29 /*The version of this device */
30 #define USB_GADGET_DEVICE_VERSION MAKE_VERSION(0,1)
32 /*The default USB configuration */
33 #define DEFAULT_VID 0x04e8
34 #define DEFAULT_PID 0x6860
35 #define DEFAULT_BCD_DEVICE 0x0100
37 #define DEFAULT_LANG 0x409 /* US_en */
38 #define DEFAULT_MANUFACTURER "Samsung"
39 #define DEFAULT_PRODUCT "TIZEN"
40 #define DEFAULT_SERIAL "01234TEST"
42 #define DEFAULT_BMATTRIBUTES ((1 << 7) | (1 << 6))
43 #define DEFAULT_MAX_POWER 500
46 USB_FUNCTION_IDX_MTP = 0,
47 USB_FUNCTION_IDX_ACM = 1,
48 USB_FUNCTION_IDX_SDB = 2,
49 USB_FUNCTION_IDX_RNDIS = 3,
50 USB_FUNCTION_IDX_DIAG = 4,
51 USB_FUNCTION_IDX_CONN_GADGET = 5,
52 USB_FUNCTION_IDX_DM = 6,
53 USB_FUNCTION_IDX_RMNET = 7,
54 USB_FUNCTION_IDX_MAX = USB_FUNCTION_IDX_RMNET + 1
58 USB_FUNCTION_NONE = 0,
59 USB_FUNCTION_MTP = 1 << USB_FUNCTION_IDX_MTP,
60 USB_FUNCTION_ACM = 1 << USB_FUNCTION_IDX_ACM,
61 USB_FUNCTION_SDB = 1 << USB_FUNCTION_IDX_SDB,
62 USB_FUNCTION_RNDIS = 1 << USB_FUNCTION_IDX_RNDIS,
63 USB_FUNCTION_DIAG = 1 << USB_FUNCTION_IDX_DIAG,
64 USB_FUNCTION_CONN_GADGET = 1 << USB_FUNCTION_IDX_CONN_GADGET,
65 USB_FUNCTION_DM = 1 << USB_FUNCTION_IDX_DM,
66 USB_FUNCTION_RMNET = 1 << USB_FUNCTION_IDX_RMNET
71 * legacy enable(usb plug) : enable gadget -> handler(1) -> service start
72 * legacy disable(usb unplug) : service stop -> handler(0) -> disable gadget
74 * configfs init(booting) : service.socket start
75 * configfs enable(usb plug)* : enable gadget -> handler(1)
76 * configfs disable(usb unplug) : handler(0) -> disable gadget -> service.service stop
77 * configfs deinit : service.socket stop
79 * Since functionfs of configfs works by socket activation,
80 * it will be started automatically when data is enqueued to the usb socket.
81 * So when enabling configfs gadget, it doesn't start the service for functionfs.
91 void (*handler)(int enable);
94 struct usb_configuration_attributes {
99 struct usb_configuration_strings {
104 struct usb_configuration {
105 struct usb_configuration_attributes attrs;
106 struct usb_configuration_strings strs;
107 struct usb_function **funcs;
110 struct usb_gadget_attrs {
111 uint8_t bDeviceClass;
112 uint8_t bDeviceSubClass;
113 uint8_t bDeviceProtocol;
119 struct usb_gadget_strings {
127 struct usb_gadget_attrs attrs;
128 struct usb_gadget_strings strs;
129 struct usb_function **funcs;
130 struct usb_configuration **configs;
133 struct usb_gadget_id {
134 unsigned int function_mask;
137 struct usb_gadget_translator {
138 struct hw_common common;
140 int (*id_to_gadget)(struct usb_gadget_id *gadget_id, struct usb_gadget **gadget);
141 void (*cleanup_gadget)(struct usb_gadget *gadget);
144 int simple_translator_open(struct hw_info *info, const char *id, struct hw_common **common);
145 int simple_translator_close(struct hw_common *common);
147 struct usb_function *find_usb_function_by_name(const char *name);
148 struct usb_function *find_usb_function_by_name_instance(const char *name, const char *instance);