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>
27 * The id of this device
29 #define USB_GADGET_DEVICE_ID "usb_gadget"
32 * The version of this device
34 #define USB_GADGET_DEVICE_VERSION MAKE_VERSION(0,1)
37 USB_FUNCTION_IDX_MTP = 0,
38 USB_FUNCTION_IDX_ACM = 1,
39 USB_FUNCTION_IDX_SDB = 2,
40 USB_FUNCTION_IDX_RNDIS = 3,
41 USB_FUNCTION_IDX_DIAG = 4,
42 USB_FUNCTION_IDX_CONN_GADGET = 5,
43 USB_FUNCTION_IDX_DM = 6,
44 USB_FUNCTION_IDX_RMNET = 7,
45 USB_FUNCTION_IDX_MAX = USB_FUNCTION_IDX_RMNET + 1
49 USB_FUNCTION_NONE = 0,
50 USB_FUNCTION_MTP = 1 << USB_FUNCTION_IDX_MTP,
51 USB_FUNCTION_ACM = 1 << USB_FUNCTION_IDX_ACM,
52 USB_FUNCTION_SDB = 1 << USB_FUNCTION_IDX_SDB,
53 USB_FUNCTION_RNDIS = 1 << USB_FUNCTION_IDX_RNDIS,
54 USB_FUNCTION_DIAG = 1 << USB_FUNCTION_IDX_DIAG,
55 USB_FUNCTION_CONN_GADGET = 1 << USB_FUNCTION_IDX_CONN_GADGET,
56 USB_FUNCTION_DM = 1 << USB_FUNCTION_IDX_DM,
57 USB_FUNCTION_RMNET = 1 << USB_FUNCTION_IDX_RMNET
62 * legacy enable(usb plug) : enable gadget -> handler(1) -> service start
63 * legacy disable(usb unplug) : service stop -> handler(0) -> disable gadget
65 * configfs init(booting) : service.socket start
66 * configfs enable(usb plug)* : enable gadget -> handler(1)
67 * configfs disable(usb unplug) : handler(0) -> disable gadget -> service.service stop
68 * configfs deinit : service.socket stop
70 * Since functionfs of configfs works by socket activation,
71 * it will be started automatically when data is enqueued to the usb socket.
72 * So when enabling configfs gadget, it doesn't start the service for functionfs.
82 void (*handler)(int enable);
85 struct usb_configuration_attributes {
90 struct usb_configuration_strings {
95 struct usb_configuration {
96 struct usb_configuration_attributes attrs;
97 struct usb_configuration_strings *strs;
98 const struct usb_function **funcs;
101 struct usb_gadget_attrs {
102 uint8_t bDeviceClass;
103 uint8_t bDeviceSubClass;
104 uint8_t bDeviceProtocol;
110 struct usb_gadget_strings {
118 struct usb_gadget_attrs attrs;
119 struct usb_gadget_strings *strs;
120 const struct usb_function **funcs;
121 struct usb_configuration **configs;
124 struct usb_gadget_id {
125 unsigned int function_mask;
128 struct usb_gadget_translator {
129 struct hw_common common;
131 int (*id_to_gadget)(struct usb_gadget_id *gadget_id, struct usb_gadget **gadget);
132 void (*cleanup_gadget)(struct usb_gadget *gadget);
135 int simple_translator_open(struct hw_info *info, const char *id, struct hw_common **common);
136 int simple_translator_close(struct hw_common *common);
138 const struct usb_function *find_usb_function_by_name(const char *name);
139 const struct usb_function *find_usb_function_by_name_instance(const char *name, const char *instance);