summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2015-04-03 13:19:48 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2015-04-05 19:10:20 -0700
commit79790de287e5bbe23c93f817bd14f47a67f1b72e (patch)
tree8e02acb1bb4cddb70a00d0e131fbaebc7ca59fb5
parent5dcaa424929f04b8f8ee8ecdd4e691c25f1b6c6d (diff)
downloaddeviced-79790de287e5bbe23c93f817bd14f47a67f1b72e.tar.gz
deviced-79790de287e5bbe23c93f817bd14f47a67f1b72e.tar.bz2
deviced-79790de287e5bbe23c93f817bd14f47a67f1b72e.zip
extcon: Support dock devices
Dock module will be activated by extcon event. If there is no event for dock, it doesn't work. Change-Id: I13992b2b1d8736ee84e84623aea1bae651f23ccc Signed-off-by: Jiyoung Yun <jy910.yun@samsung.com>
-rwxr-xr-xCMakeLists.txt1
-rw-r--r--src/battery/power-supply.c2
-rw-r--r--src/core/device-change-handler.c110
-rw-r--r--src/core/device-handler.h2
-rw-r--r--src/extcon/cradle.c124
5 files changed, 126 insertions, 113 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cc7de44c..e7ceb8d2 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -33,6 +33,7 @@ SET(SRCS
src/core/log.c
src/core/main.c
src/core/sig-handler.c
+ src/extcon/cradle.c
src/extcon/earjack.c
src/extcon/extcon.c
src/gpio/gpio.c
diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c
index 8a33925d..f63b7da9 100644
--- a/src/battery/power-supply.c
+++ b/src/battery/power-supply.c
@@ -376,8 +376,6 @@ static void check_power_supply(int state)
pm_lock_internal(INTERNAL_LOCK_TA, LCD_OFF, STAY_CUR_STATE, 0);
out:
_I("ta device %d(capacity %d)", state, battery.capacity);
-
- sync_cradle_status();
}
static void update_present(enum battery_noti_status status)
diff --git a/src/core/device-change-handler.c b/src/core/device-change-handler.c
index 0d9bb049..726531ea 100644
--- a/src/core/device-change-handler.c
+++ b/src/core/device-change-handler.c
@@ -85,9 +85,6 @@ enum snd_jack_types {
#define HDMI_AUDIO_NAME "ch_hdmi_audio"
#define HDMI_AUDIO_LEN 13
-#define CRADLE_NAME "cradle"
-#define CRADLE_NAME_LEN 6
-
#define KEYBOARD_NAME "keyboard"
#define KEYBOARD_NAME_LEN 8
@@ -100,9 +97,6 @@ enum snd_jack_types {
#define HDCP_HDMI_VALUE(HDCP, HDMI) ((HDCP << 1) | HDMI)
-#define METHOD_GET_CRADLE "GetCradle"
-#define SIGNAL_CRADLE_STATE "ChangedCradle"
-
struct ticker_data {
char *name;
int type;
@@ -142,7 +136,7 @@ static dd_list *udev_event_list;
static int display_changed(void *data)
{
enum state_t state;
- int ret, cradle = 0;
+ int ret;
if (!data)
return 0;
@@ -151,11 +145,6 @@ static int display_changed(void *data)
if (state != S_NORMAL)
return 0;
- ret = vconf_get_int(VCONFKEY_SYSMAN_CRADLE_STATUS, &cradle);
- if (ret >= 0 && cradle == DOCK_SOUND) {
- pm_lock_internal(getpid(), LCD_DIM, STAY_CUR_STATE, 0);
- _I("sound dock is connected! dim lock is on.");
- }
if (hdmi_status) {
pm_lock_internal(getpid(), LCD_DIM, STAY_CUR_STATE, 0);
_I("hdmi is connected! dim lock is on.");
@@ -163,84 +152,6 @@ static int display_changed(void *data)
return 0;
}
-static void cradle_send_broadcast(int status)
-{
- static int old = 0;
- char *arr[1];
- char str_status[32];
-
- if (old == status)
- return;
-
- _I("broadcast cradle status %d", status);
- old = status;
- snprintf(str_status, sizeof(str_status), "%d", status);
- arr[0] = str_status;
-
- broadcast_edbus_signal(DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI,
- SIGNAL_CRADLE_STATE, "i", arr);
-}
-
-static int cradle_cb(void *data)
-{
- static int old = 0;
- int val = 0;
- int ret = 0;
-
- if (data == NULL)
- return old;
-
- val = *(int *)data;
-
- if (old == val)
- return old;
-
- old = val;
- cradle_send_broadcast(old);
- return old;
-}
-
-static void cradle_chgdet_cb(void *data)
-{
- int val;
- int ret = 0;
-
- pm_change_internal(getpid(), LCD_NORMAL);
-
- if (data)
- val = *(int *)data;
- else {
- ret = device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_CRADLE_ONLINE, &val);
- if (ret != 0) {
- _E("failed to get status");
- return;
- }
- }
-
- _I("jack - cradle changed %d", val);
- cradle_cb((void *)&val);
- if (vconf_set_int(VCONFKEY_SYSMAN_CRADLE_STATUS, val) != 0) {
- _E("failed to set vconf status");
- return;
- }
-
- if (val == DOCK_SOUND)
- pm_lock_internal(getpid(), LCD_DIM, STAY_CUR_STATE, 0);
- else if (val == DOCK_NONE)
- pm_unlock_internal(getpid(), LCD_DIM, PM_SLEEP_MARGIN);
-}
-
-void sync_cradle_status(void)
-{
- int val;
- int status;
- if ((device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_CRADLE_ONLINE, &val) != 0) ||
- vconf_get_int(VCONFKEY_SYSMAN_CRADLE_STATUS, &status) != 0)
- return;
- if ((val != 0 && status == 0) || (val == 0 && status != 0))
- cradle_chgdet_cb(NULL);
-}
-
static void tvout_chgdet_cb(void *data)
{
_I("jack - tvout changed");
@@ -485,8 +396,6 @@ static int changed_device(const char *name, const char *value)
}
else if (strncmp(name, HDMI_AUDIO_NAME, HDMI_AUDIO_LEN) == 0)
hdmi_audio_chgdet_cb((void *)state);
- else if (strncmp(name, CRADLE_NAME, CRADLE_NAME_LEN) == 0)
- cradle_chgdet_cb((void *)state);
else if (strncmp(name, KEYBOARD_NAME, KEYBOARD_NAME_LEN) == 0)
keyboard_chgdet_cb((void *)state);
out:
@@ -508,7 +417,6 @@ static int booting_done(void *data)
_I("booting done");
/* set initial state for devices */
- cradle_chgdet_cb(NULL);
keyboard_chgdet_cb(NULL);
hdmi_chgdet_cb(NULL);
return done;
@@ -771,21 +679,6 @@ int uevent_udev_get_path(const char *subsystem, dd_list **list)
return 0;
}
-static DBusMessage *dbus_cradle_handler(E_DBus_Object *obj, DBusMessage *msg)
-{
- DBusMessageIter iter;
- DBusMessage *reply;
- int ret;
-
- ret = cradle_cb(NULL);
- _I("cradle %d", ret);
-
- reply = dbus_message_new_method_return(msg);
- dbus_message_iter_init_append(reply, &iter);
- dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
- return reply;
-}
-
static DBusMessage *dbus_hdcp_hdmi_handler(E_DBus_Object *obj, DBusMessage *msg)
{
DBusMessageIter iter;
@@ -937,7 +830,6 @@ static const struct edbus_method edbus_methods[] = {
{ METHOD_GET_HDCP, NULL, "i", dbus_hdcp_handler },
{ METHOD_GET_HDMI_AUDIO, NULL, "i", dbus_hdmi_audio_handler },
{ METHOD_GET_HDMI, NULL, "i", dbus_hdcp_hdmi_handler },
- { METHOD_GET_CRADLE, NULL, "i", dbus_cradle_handler },
};
static int device_change_poweroff(void *data)
diff --git a/src/core/device-handler.h b/src/core/device-handler.h
index bf41f942..64db56da 100644
--- a/src/core/device-handler.h
+++ b/src/core/device-handler.h
@@ -27,7 +27,5 @@ enum dock_type {
DOCK_SOUND = 7,
};
-void sync_cradle_status(void);
-
void internal_pm_change_state(unsigned int s_bits);
#endif /* __DEVICE_HANDLER_H__ */
diff --git a/src/extcon/cradle.c b/src/extcon/cradle.c
new file mode 100644
index 00000000..6b4d6b2b
--- /dev/null
+++ b/src/extcon/cradle.c
@@ -0,0 +1,124 @@
+/*
+ * 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 <vconf.h>
+
+#include "core/log.h"
+#include "core/device-notifier.h"
+#include "core/edbus-handler.h"
+#include "core/device-handler.h"
+#include "display/core.h"
+#include "extcon/extcon.h"
+
+#define METHOD_GET_CRADLE "GetCradle"
+#define SIGNAL_CRADLE_STATE "ChangedCradle"
+
+static struct extcon_ops cradle_extcon_ops;
+
+static void cradle_send_broadcast(int status)
+{
+ static int old;
+ char *arr[1];
+ char str_status[32];
+
+ if (old == status)
+ return;
+
+ _I("broadcast cradle status %d", status);
+ old = status;
+ snprintf(str_status, sizeof(str_status), "%d", status);
+ arr[0] = str_status;
+
+ broadcast_edbus_signal(DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI,
+ SIGNAL_CRADLE_STATE, "i", arr);
+}
+
+static int cradle_update(int status)
+{
+ _I("jack - cradle changed %d", status);
+ pm_change_internal(getpid(), LCD_NORMAL);
+ cradle_send_broadcast(status);
+ if (vconf_set_int(VCONFKEY_SYSMAN_CRADLE_STATUS, status) != 0) {
+ _E("failed to set vconf status");
+ return -EIO;
+ }
+
+ if (status == DOCK_SOUND)
+ pm_lock_internal(getpid(), LCD_DIM, STAY_CUR_STATE, 0);
+ else if (status == DOCK_NONE)
+ pm_unlock_internal(getpid(), LCD_DIM, PM_SLEEP_MARGIN);
+
+ return 0;
+}
+
+static int display_changed(void *data)
+{
+ enum state_t state;
+ int cradle;
+
+ if (!data)
+ return 0;
+
+ state = *(int *)data;
+ if (state != S_NORMAL)
+ return 0;
+
+ cradle = cradle_extcon_ops.status;
+ if (cradle == DOCK_SOUND) {
+ pm_lock_internal(getpid(), LCD_DIM, STAY_CUR_STATE, 0);
+ _I("sound dock is connected! dim lock is on.");
+ }
+
+ return 0;
+}
+
+static DBusMessage *dbus_cradle_handler(E_DBus_Object *obj, DBusMessage *msg)
+{
+ return make_reply_message(msg, cradle_extcon_ops.status);
+}
+
+static const struct edbus_method edbus_methods[] = {
+ { METHOD_GET_CRADLE, NULL, "i", dbus_cradle_handler },
+};
+
+static void cradle_init(void *data)
+{
+ int ret;
+
+ register_notifier(DEVICE_NOTIFIER_LCD, display_changed);
+
+ ret = register_edbus_method(DEVICED_PATH_SYSNOTI,
+ edbus_methods, ARRAY_SIZE(edbus_methods));
+ if (ret < 0)
+ _E("fail to init edbus method(%d)", ret);
+}
+
+static void cradle_exit(void *data)
+{
+ unregister_notifier(DEVICE_NOTIFIER_LCD, display_changed);
+}
+
+static struct extcon_ops cradle_extcon_ops = {
+ .name = EXTCON_CABLE_DOCK,
+ .init = cradle_init,
+ .update = cradle_update,
+};
+
+EXTCON_OPS_REGISTER(&cradle_extcon_ops);