Add USB gadget HAL implementation 02/88602/2
authortaeyoung <ty317.kim@samsung.com>
Tue, 20 Sep 2016 02:44:30 +0000 (11:44 +0900)
committerTaeyoung Kim <ty317.kim@samsung.com>
Fri, 23 Sep 2016 08:56:23 +0000 (01:56 -0700)
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>
CMakeLists.txt
hw/usb_gadget/CMakeLists.txt [new file with mode: 0644]
hw/usb_gadget/usb_gadget.c [new file with mode: 0644]

index 6114ce3..fe66040 100644 (file)
@@ -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 (file)
index 0000000..2e28b15
--- /dev/null
@@ -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 (file)
index 0000000..a7ddd9f
--- /dev/null
@@ -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