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__
22 #include <hw/common.h>
30 * The id of this device
32 #define USB_GADGET_DEVICE_ID "usb_gadget"
35 * The version of this device
37 #define USB_GADGET_DEVICE_VERSION MAKE_VERSION(0,1)
40 USB_FUNCTION_IDX_MTP = 0,
41 USB_FUNCTION_IDX_ACM = 1,
42 USB_FUNCTION_IDX_SDB = 2,
43 USB_FUNCTION_IDX_RNDIS = 3,
44 USB_FUNCTION_IDX_DIAG = 4,
45 USB_FUNCTION_IDX_CONN_GADGET = 5,
46 USB_FUNCTION_IDX_DM = 6,
47 USB_FUNCTION_IDX_RMNET = 7,
48 USB_FUNCTION_IDX_MAX = USB_FUNCTION_IDX_RMNET + 1
52 USB_FUNCTION_NONE = 0,
53 USB_FUNCTION_MTP = 1 << USB_FUNCTION_IDX_MTP,
54 USB_FUNCTION_ACM = 1 << USB_FUNCTION_IDX_ACM,
55 USB_FUNCTION_SDB = 1 << USB_FUNCTION_IDX_SDB,
56 USB_FUNCTION_RNDIS = 1 << USB_FUNCTION_IDX_RNDIS,
57 USB_FUNCTION_DIAG = 1 << USB_FUNCTION_IDX_DIAG,
58 USB_FUNCTION_CONN_GADGET = 1 << USB_FUNCTION_IDX_CONN_GADGET,
59 USB_FUNCTION_DM = 1 << USB_FUNCTION_IDX_DM,
60 USB_FUNCTION_RMNET = 1 << USB_FUNCTION_IDX_RMNET
65 * legacy enable(usb plug) : enable gadget -> handler(1) -> ffs_service start -> service start
66 * legacy disable(usb unplug) : service stop -> ffs_service stop -> handler(0) -> disable gadget
68 * configfs init(booting) : ffs_service.socket start
69 * configfs enable(usb plug)* : enable gadget -> handler(1) -> service start
70 * configfs disable(usb unplug) : service stop -> handler(0) -> disable gadget -> ffs_service.service stop
71 * configfs deinit : ffs_service.socket stop
73 * Since ffs_service works by socket activation, it will be started automatically when data is enqueued to the usb socket.
74 * So when enabling configfs gadget, it doesn't start ffs_service.
81 const char *ffs_service; /* only used in configfs */
84 void (*handler)(int enable);
86 int (*clone)(struct usb_function *func, struct usb_function **_clone);
87 void (*free_func)(struct usb_function *func);
90 struct usb_configuration_attributes {
95 struct usb_configuration_strings {
100 struct usb_configuration {
101 struct usb_configuration_attributes attrs;
102 struct usb_configuration_strings *strs;
103 struct usb_function **funcs;
106 struct usb_gadget_attrs {
107 uint8_t bDeviceClass;
108 uint8_t bDeviceSubClass;
109 uint8_t bDeviceProtocol;
115 struct usb_gadget_strings {
123 struct usb_gadget_attrs attrs;
124 struct usb_gadget_strings *strs;
125 struct usb_function **funcs;
126 struct usb_configuration **configs;
129 struct usb_gadget_id {
130 unsigned int function_mask;
133 struct usb_gadget_translator {
134 struct hw_common common;
136 int (*id_to_gadget)(struct usb_gadget_id *gadget_id,
137 struct usb_gadget **gadget);
139 void (*cleanup_gadget)(struct usb_gadget *gadget);
142 int simple_translator_open(struct hw_info *info,
143 const char *id, struct hw_common **common);
144 int simple_translator_close(struct hw_common *common);
146 extern struct usb_function *_available_funcs[];