summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortaeyoung <ty317.kim@samsung.com>2016-09-20 11:44:30 +0900
committerTaeyoung Kim <ty317.kim@samsung.com>2016-09-23 01:56:23 -0700
commita044268e1c01c89751432957dd38d91b01528fb6 (patch)
tree0c1a669afb085f07d1fb08fab802b4aa400b083e
parentc0ff251413ec12bd02e1bd90d87d915fcf701e52 (diff)
downloaddevice-emulator-a044268e1c01c89751432957dd38d91b01528fb6.tar.gz
device-emulator-a044268e1c01c89751432957dd38d91b01528fb6.tar.bz2
device-emulator-a044268e1c01c89751432957dd38d91b01528fb6.zip
Add USB gadget HAL implementation
USB gadget HAL is an abstraction layer which translates set of functions into full USB gadget description specific for this particular device. Change-Id: I7b3faca4e116de28e053d96a6eb6d1e280a36edd Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
-rw-r--r--CMakeLists.txt1
-rw-r--r--hw/usb_gadget/CMakeLists.txt19
-rw-r--r--hw/usb_gadget/usb_gadget.c82
3 files changed, 102 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6114ce3..fe66040 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,3 +35,4 @@ INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT Runtime
ADD_SUBDIRECTORY(hw/battery)
ADD_SUBDIRECTORY(hw/display)
ADD_SUBDIRECTORY(hw/external_connection)
+ADD_SUBDIRECTORY(hw/usb_gadget)
diff --git a/hw/usb_gadget/CMakeLists.txt b/hw/usb_gadget/CMakeLists.txt
new file mode 100644
index 0000000..2e28b15
--- /dev/null
+++ b/hw/usb_gadget/CMakeLists.txt
@@ -0,0 +1,19 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(usb_gadget C)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(usb_gadget_pkgs REQUIRED hwcommon)
+
+FOREACH(flag ${usb_gadget_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+ADD_LIBRARY(${PROJECT_NAME} MODULE usb_gadget.c ../shared.c)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${usb_gadget_pkgs_LDFLAGS})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/hw COMPONENT RuntimeLibraries)
diff --git a/hw/usb_gadget/usb_gadget.c b/hw/usb_gadget/usb_gadget.c
new file mode 100644
index 0000000..a7ddd9f
--- /dev/null
+++ b/hw/usb_gadget/usb_gadget.c
@@ -0,0 +1,82 @@
+/*
+ * libdevice-node
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __HW_USB_GADGET_SIMPLE_TRANSLATOR_H__
+
+#include <hw/usb_gadget.h>
+
+#include <stdlib.h>
+#include <errno.h>
+
+#define zalloc(amount) calloc(1, amount)
+
+static void simple_cleanup_gadget(struct usb_gadget *gadget)
+{
+}
+
+static int simple_id_to_gadget(struct usb_gadget_id *gadget_id,
+ struct usb_gadget **_gadget)
+{
+ return -ENOTSUP;
+}
+
+static int simple_translator_open(struct hw_info *info,
+ const char *id, struct hw_common **common)
+{
+ struct usb_gadget_translator *simple_translator;
+
+ if (!info || !common)
+ return -EINVAL;
+
+ simple_translator = zalloc(sizeof(*simple_translator));
+ if (!simple_translator)
+ return -ENOMEM;
+
+ simple_translator->common.info = info;
+ simple_translator->id_to_gadget = simple_id_to_gadget;
+ simple_translator->cleanup_gadget = simple_cleanup_gadget;
+
+ *common = &simple_translator->common;
+ return 0;
+}
+
+static int simple_translator_close(struct hw_common *common)
+{
+ struct usb_gadget_translator *simple_translator;
+
+ if (!common)
+ return -EINVAL;
+
+ simple_translator = container_of(common, struct usb_gadget_translator,
+ common);
+
+ free(simple_translator);
+ return 0;
+}
+
+HARDWARE_MODULE_STRUCTURE = {
+ .magic = HARDWARE_INFO_TAG,
+ .hal_version = HARDWARE_INFO_VERSION,
+ .device_version = USB_GADGET_DEVICE_VERSION,
+ .id = USB_GADGET_DEVICE_ID,
+ .name = "simple_translator",
+ .open = simple_translator_open,
+ .close = simple_translator_close,
+};
+
+#endif