Add USB config HAL implementation for slp-gadget 15/88615/3
authortaeyoung <ty317.kim@samsung.com>
Tue, 20 Sep 2016 04:16:48 +0000 (13:16 +0900)
committerTaeyoung Kim <ty317.kim@samsung.com>
Fri, 23 Sep 2016 08:57:00 +0000 (01:57 -0700)
This implementation of USB config HAL allows to apply
abstract gadget description received from USB gadget HAL
to USB gadget subsystem in Kernel via slp-gadget sysfs
interface.

Change-Id: I20821cf04b6a07d79b74dae257c175b70ce854ea
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
CMakeLists.txt
hw/usb_client/CMakeLists.txt [new file with mode: 0644]
hw/usb_client/usb_client.c [new file with mode: 0644]

index fe66040..8d65243 100644 (file)
@@ -36,3 +36,4 @@ ADD_SUBDIRECTORY(hw/battery)
 ADD_SUBDIRECTORY(hw/display)
 ADD_SUBDIRECTORY(hw/external_connection)
 ADD_SUBDIRECTORY(hw/usb_gadget)
+ADD_SUBDIRECTORY(hw/usb_client)
diff --git a/hw/usb_client/CMakeLists.txt b/hw/usb_client/CMakeLists.txt
new file mode 100644 (file)
index 0000000..f7b32c1
--- /dev/null
@@ -0,0 +1,19 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(usb_client C)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(usb_client_pkgs REQUIRED hwcommon dlog glib-2.0)
+
+FOREACH(flag ${usb_client_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_client.c ../shared.c)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${usb_client_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_client/usb_client.c b/hw/usb_client/usb_client.c
new file mode 100644 (file)
index 0000000..9a90967
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * device-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.
+ */
+
+#include <hw/usb_client.h>
+
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+
+#define zalloc(amount) calloc(1, amount)
+
+static int legacy_get_current_gadget(struct usb_client *usb,
+                                    struct usb_gadget **_gadget)
+{
+       return -ENOTSUP;
+}
+
+static bool legacy_is_function_supported(struct usb_client *usb,
+                                        struct usb_function *func)
+{
+       return false;
+}
+
+static bool legacy_is_gadget_supported(struct usb_client *usb,
+                                      struct usb_gadget *gadget)
+{
+       return false;
+}
+
+static int legacy_reconfigure_gadget(struct usb_client *usb,
+                                    struct usb_gadget *gadget)
+{
+       return 0;
+}
+
+static int legacy_enable(struct usb_client *usb)
+{
+       return 0;
+}
+
+static int legacy_disable(struct usb_client *usb)
+{
+       return 0;
+}
+
+static void legacy_free_gadget(struct usb_gadget *gadget)
+{
+}
+
+static int legacy_gadget_open(struct hw_info *info,
+               const char *id, struct hw_common **common)
+{
+       struct usb_client *legacy;
+
+       if (!info || !common)
+               return -EINVAL;
+
+       legacy = zalloc(sizeof(*legacy));
+       if (!legacy)
+               return -ENOMEM;
+
+       legacy->common.info = info;
+       legacy->get_current_gadget = legacy_get_current_gadget;
+       legacy->reconfigure_gadget = legacy_reconfigure_gadget;
+       legacy->is_gadget_supported = legacy_is_gadget_supported;
+       legacy->is_function_supported = legacy_is_function_supported;
+       legacy->enable = legacy_enable;
+       legacy->disable = legacy_disable;
+       legacy->free_gadget = legacy_free_gadget;
+
+       *common = &legacy->common;
+       return 0;
+}
+
+static int legacy_gadget_close(struct hw_common *common)
+{
+       struct usb_client *legacy;
+
+       if (!common)
+               return -EINVAL;
+
+       legacy = container_of(common, struct usb_client,
+                                        common);
+
+       free(legacy);
+       return 0;
+}
+
+HARDWARE_MODULE_STRUCTURE = {
+       .magic = HARDWARE_INFO_TAG,
+       .hal_version = HARDWARE_INFO_VERSION,
+       .device_version = USB_CLIENT_HARDWARE_DEVICE_VERSION,
+       .id = USB_CLIENT_HARDWARE_DEVICE_ID,
+       .name = "legacy-gadget",
+       .open = legacy_gadget_open,
+       .close = legacy_gadget_close,
+};