usb: add usb handler 35/34935/8
authortaeyoung <ty317.kim@samsung.com>
Wed, 4 Feb 2015 13:27:18 +0000 (22:27 +0900)
committerJiyoung Yun <jy910.yun@samsung.com>
Fri, 13 Feb 2015 04:56:39 +0000 (20:56 -0800)
- Usb connection status is delivered to the handler by extcon module

Change-Id: Ieec715641fa758693a5614203f865adb9eb17732
Signed-off-by: taeyoung <ty317.kim@samsung.com>
CMakeLists.txt
src/core/device-notifier.h
src/usb/usb.c [new file with mode: 0644]

index 88229eb..9ff2c69 100755 (executable)
@@ -41,6 +41,10 @@ SET(SRCS
        src/time/time-handler.c
 )
 
+SET(SRCS ${SRCS}
+       src/usb/usb.c
+)
+
 IF(TIZEN_BUZZER)
 SET(SRCS ${SRCS}
        src/gpio/buzzer.c)
index 597217a..aba3e13 100644 (file)
@@ -26,6 +26,7 @@ enum device_notifier_type {
        DEVICE_NOTIFIER_LCD,
        DEVICE_NOTIFIER_MMC,
        DEVICE_NOTIFIER_TA,
+       DEVICE_NOTIFIER_USB,
        DEVICE_NOTIFIER_LOWBAT,
        DEVICE_NOTIFIER_TOUCH_HARDKEY,
        DEVICE_NOTIFIER_INPUT_ADD,
diff --git a/src/usb/usb.c b/src/usb/usb.c
new file mode 100644 (file)
index 0000000..3d2830c
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * deviced
+ *
+ * Copyright (c) 2015 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 <stdio.h>
+
+#include "core/log.h"
+#include "core/common.h"
+#include "core/device-notifier.h"
+#include "extcon/extcon.h"
+
+enum usb_state {
+       USB_DISCONNECTED,
+       USB_CONNECTED,
+};
+
+struct extcon_ops extcon_usb_ops;
+
+static int usb_state_changed(void *data)
+{
+       static int state = USB_DISCONNECTED;
+       int input;
+
+       if (!data)
+               return -EINVAL;
+
+       input = *(int *)data;
+
+       _I("USB state is changed from (%d) to (%d)", state, input);
+
+       if (state == input)
+               return 0;
+
+       switch (input) {
+       case USB_CONNECTED:
+               _I("USB cable is connected");
+               break;
+       case USB_DISCONNECTED:
+               _I("USB cable is disconnected");
+               break;
+       default:
+               _E("Invalid USB state(%d)", state);
+               return -EINVAL;
+       }
+
+       state = input;
+
+       return 0;
+}
+
+static void usb_init(void *data)
+{
+       int ret, status;
+
+       register_notifier(DEVICE_NOTIFIER_USB, usb_state_changed);
+
+       ret = usb_state_changed(&(extcon_usb_ops.status));
+       if (ret < 0)
+               _E("Failed to update usb status(%d)", ret);
+}
+
+static void usb_exit(void *data)
+{
+       unregister_notifier(DEVICE_NOTIFIER_USB, usb_state_changed);
+}
+
+struct extcon_ops extcon_usb_ops = {
+       .name   = "USB",
+       .noti   = DEVICE_NOTIFIER_USB,
+       .init   = usb_init,
+       .exit   = usb_exit,
+};
+
+EXTCON_OPS_REGISTER(&extcon_usb_ops)