From 54e4cc087ea8ce909f9b0179455b4e6d27ea3a49 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Tue, 10 Feb 2015 16:54:30 +0900 Subject: [PATCH 01/16] usb: add plugin interfaces for usb configuration - USB configuration manner can be changed according to the Kernel or vendors. Thus USB configuration setting codes should be implemented by plugin structure. - This modification contains basic structure for the USB configuration plugin. Change-Id: I4afb1033fb59ba132182ae16ffef9fbb34192f13 Signed-off-by: taeyoung --- src/usb/usb.c | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- src/usb/usb.h | 50 +++++++++++++++++++++ 2 files changed, 183 insertions(+), 5 deletions(-) create mode 100644 src/usb/usb.h diff --git a/src/usb/usb.c b/src/usb/usb.c index 3d2830c..02fd197 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -20,21 +20,133 @@ #include #include "core/log.h" +#include "core/list.h" #include "core/common.h" #include "core/device-notifier.h" #include "extcon/extcon.h" +#include "usb.h" enum usb_state { USB_DISCONNECTED, USB_CONNECTED, }; +static dd_list *config_list; struct extcon_ops extcon_usb_ops; +static const struct usb_config_plugin_ops *config_plugin; + +void add_usb_config(const struct usb_config_ops *ops) +{ + DD_LIST_APPEND(config_list, ops); +} + +void remove_usb_config(const struct usb_config_ops *ops) +{ + DD_LIST_REMOVE(config_list, ops); +} + +static int usb_config_module_load(void) +{ + dd_list *l; + struct usb_config_ops *ops; + + DD_LIST_FOREACH(config_list, l, ops) { + if (ops->is_valid && ops->is_valid()) { + if (ops->load) + config_plugin = ops->load(); + return 0; + } + } + return -ENOENT; +} + +static void usb_config_module_unload(void) +{ + dd_list *l; + struct usb_config_ops *ops; + + config_plugin = NULL; + + DD_LIST_FOREACH(config_list, l, ops) { + if (ops->is_valid && ops->is_valid()) { + if (ops->release) + ops->release(); + } + } +} + +static int usb_config_init(void) +{ + if (!config_plugin) { + _E("There is no usb config plugin"); + return -ENOENT; + } + + if (config_plugin->init == NULL) { + _E("There is no usb config init function"); + return -ENOENT; + } + + /* TODO: + * parameter "DEFAULT" can be changed */ + return config_plugin->init("DEFAULT"); +} + +static void usb_config_deinit(void) +{ + if (!config_plugin) { + _E("There is no usb config plugin"); + return; + } + + if (config_plugin->deinit == NULL) { + _E("There is no usb config deinit function"); + return; + } + + /* TODO: + * parameter "DEFAULT" can be changed */ + config_plugin->deinit("DEFAULT"); +} + +static int usb_config_enable(void) +{ + if (!config_plugin) { + _E("There is no usb config plugin"); + return -ENOENT; + } + + if (config_plugin->enable == NULL) { + _E("There is no usb config enable function"); + return -ENOENT; + } + + /* TODO: + * parameter "DEFAULT" can be changed */ + return config_plugin->enable("DEFAULT"); +} + +static int usb_config_disable(void) +{ + if (!config_plugin) { + _E("There is no usb config plugin"); + return -ENOENT; + } + + if (config_plugin->disable == NULL) { + _E("There is no usb config disable function"); + return -ENOENT; + } + + /* TODO: + * parameter "DEFAULT" can be changed */ + return config_plugin->disable("DEFAULT"); +} static int usb_state_changed(void *data) { static int state = USB_DISCONNECTED; - int input; + int input, ret; if (!data) return -EINVAL; @@ -49,26 +161,40 @@ static int usb_state_changed(void *data) switch (input) { case USB_CONNECTED: _I("USB cable is connected"); + ret = usb_config_enable(); break; case USB_DISCONNECTED: _I("USB cable is disconnected"); + ret = usb_config_disable(); break; default: _E("Invalid USB state(%d)", state); return -EINVAL; } + if (ret < 0) + _E("Failed to operate usb connection(%d)", ret); + else + state = input; - state = input; - - return 0; + return ret; } static void usb_init(void *data) { - int ret, status; + int ret; register_notifier(DEVICE_NOTIFIER_USB, usb_state_changed); + ret = usb_config_module_load(); + if (ret < 0) { + _E("Failed to get config module (%d)", ret); + return; + } + + ret = usb_config_init(); + if (ret < 0) + _E("Failed to initialize usb configuation"); + ret = usb_state_changed(&(extcon_usb_ops.status)); if (ret < 0) _E("Failed to update usb status(%d)", ret); @@ -77,6 +203,8 @@ static void usb_init(void *data) static void usb_exit(void *data) { unregister_notifier(DEVICE_NOTIFIER_USB, usb_state_changed); + usb_config_deinit(); + usb_config_module_unload(); } struct extcon_ops extcon_usb_ops = { diff --git a/src/usb/usb.h b/src/usb/usb.h new file mode 100644 index 0000000..5c3276d --- /dev/null +++ b/src/usb/usb.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef __USB_CLIENT_H__ +#define __USB_CLIENT_H__ + +#define USB_CONFIG_OPS_REGISTER(dev) \ +static void __CONSTRUCTOR__ usb_config_init(void) \ +{ \ + add_usb_config(dev); \ +} \ +static void __DESTRUCTOR__ usb_config_exit(void) \ +{ \ + remove_usb_config(dev); \ +} + +struct usb_config_ops { + bool (*is_valid)(void); + const struct usb_config_plugin_ops *(*load)(void); + void (*release)(void); +}; + +/* TODO + * move it to proper location */ +struct usb_config_plugin_ops { + int (*init)(char *name); + void (*deinit)(char *name); + int (*enable)(char *name); + int (*disable)(char *name); +}; + +void add_usb_config(const struct usb_config_ops *ops); +void remove_usb_config(const struct usb_config_ops *ops); + +#endif /* __USB_CLIENT_H__ */ -- 2.7.4 From 33404cf65e730398c4bb97e32d26452a6e895d0a Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Fri, 13 Feb 2015 13:59:06 +0900 Subject: [PATCH 02/16] extcon: Register extcon uevent inside extcon module If there is no extcon module, deviced does not need to register extcon uevent. So the code is moved into extcon module. Change-Id: Ib36295a1f54c3528bb0c3473201b1f1d36671e9c Signed-off-by: Jiyoung Yun --- src/core/device-change-handler.c | 10 ---------- src/extcon/extcon.c | 38 ++++++++++++++++++++++++++++++++++++-- src/extcon/extcon.h | 1 - 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/core/device-change-handler.c b/src/core/device-change-handler.c index 74e9391..794a9f9 100644 --- a/src/core/device-change-handler.c +++ b/src/core/device-change-handler.c @@ -154,7 +154,6 @@ enum udev_subsystem_type { UDEV_INPUT, UDEV_PLATFORM, UDEV_SWITCH, - UDEV_EXTCON, }; static const struct udev_subsystem { @@ -165,7 +164,6 @@ static const struct udev_subsystem { { UDEV_INPUT, INPUT_SUBSYSTEM, NULL }, { UDEV_PLATFORM, PLATFORM_SUBSYSTEM, NULL }, { UDEV_SWITCH, SWITCH_SUBSYSTEM, NULL }, - { UDEV_EXTCON, EXTCON_SUBSYSTEM, NULL }, }; static dd_list *udev_event_list; @@ -789,14 +787,6 @@ static Eina_Bool uevent_kernel_control_cb(void *data, Ecore_Fd_Handler *fd_handl break; changed_device(env_value, NULL); break; - case UDEV_EXTCON: - env_value = udev_device_get_property_value(dev, "STATE"); - if (!env_value) - break; - ret = extcon_update(env_value); - if (ret < 0) - _E("Failed to update extcon status"); - break; } out: diff --git a/src/extcon/extcon.c b/src/extcon/extcon.c index c4046f0..5f87442 100755 --- a/src/extcon/extcon.c +++ b/src/extcon/extcon.c @@ -25,9 +25,11 @@ #include "core/devices.h" #include "core/config-parser.h" #include "core/device-notifier.h" +#include "core/udev.h" #include "extcon.h" -#define EXTCON_PATH "/sys/class/extcon" +#define EXTCON_PATH "/sys/class/extcon" +#define STATE_NAME "STATE" #define BUF_MAX 256 @@ -89,7 +91,7 @@ int extcon_get_status(const char *name) return dev->status; } -int extcon_update(const char *value) +static int extcon_update(const char *value) { char *s, *p; char name[NAME_MAX]; @@ -178,6 +180,22 @@ static int get_extcon_uevent_state(char *state, unsigned int len) return ret; } +static void uevent_extcon_handler(struct udev_device *dev) +{ + const char *env_value; + int ret; + + env_value = udev_device_get_property_value(dev, STATE_NAME); + if (!env_value) + return; + + ret = extcon_update(env_value); + if (ret < 0) + _E("fail to update extcon status : %d", ret); + + return; +} + static int extcon_probe(void *data) { /** @@ -193,6 +211,11 @@ static int extcon_probe(void *data) return 0; } +static struct uevent_handler uh = { + .subsystem = EXTCON_SUBSYSTEM, + .uevent_func = uevent_extcon_handler, +}; + static void extcon_init(void *data) { int ret; @@ -209,6 +232,11 @@ static void extcon_init(void *data) dev->init(data); } + /* register extcon uevent */ + ret = register_kernel_uevent_control(&uh); + if (ret < 0) + _E("fail to register extcon uevent : %d", ret); + /* load extcon uevent */ ret = get_extcon_uevent_state(state, sizeof(state)); if (ret == 0) { @@ -224,6 +252,12 @@ static void extcon_exit(void *data) { dd_list *l; struct extcon_ops *dev; + int ret; + + /* unreigster extcon uevent */ + ret = unregister_kernel_uevent_control(&uh); + if (ret < 0) + _E("fail to unregister extcon uevent : %d", ret); DD_LIST_FOREACH(extcon_list, l, dev) { _I("[extcon] deinit (%s)", dev->name); diff --git a/src/extcon/extcon.h b/src/extcon/extcon.h index 28fc8a1..989da1a 100755 --- a/src/extcon/extcon.h +++ b/src/extcon/extcon.h @@ -41,7 +41,6 @@ static void __DESTRUCTOR__ extcon_exit(void) \ void add_extcon(struct extcon_ops *dev); void remove_extcon(struct extcon_ops *dev); -int extcon_update(const char *value); int extcon_get_status(const char *name); #endif /* __EXTCON_H__ */ -- 2.7.4 From ded250a3e17978bc77349490dfbc89757cb563c3 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Fri, 13 Feb 2015 14:04:46 +0900 Subject: [PATCH 03/16] extcon: Register GetStatus dbus method GetStatus method returns the current device status. The first string argument should be the same with EXTCON_XXX name. Change-Id: Ifaf2baa26e1189bc6d91e4be6e522df7631ce53f Signed-off-by: Jiyoung Yun --- src/core/edbus-handler.c | 1 - src/extcon/extcon.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ src/extcon/extcon.h | 12 ++++++++++++ src/usb/usb.c | 2 +- 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/core/edbus-handler.c b/src/core/edbus-handler.c index 3c50ba3..6d24931 100644 --- a/src/core/edbus-handler.c +++ b/src/core/edbus-handler.c @@ -61,7 +61,6 @@ static struct edbus_object edbus_objects[] = { { DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, NULL, NULL }, { DEVICED_PATH_USB , DEVICED_INTERFACE_USB , NULL, NULL }, { DEVICED_PATH_USBHOST, DEVICED_INTERFACE_USBHOST, NULL, NULL }, - { DEVICED_PATH_EXTCON , DEVICED_INTERFACE_EXTCON , NULL, NULL }, { DEVICED_PATH_GPIO, DEVICED_INTERFACE_GPIO, NULL, NULL}, { DEVICED_PATH_HDMICEC, DEVICED_INTERFACE_HDMICEC, NULL, NULL}, /* Add new object & interface here*/ diff --git a/src/extcon/extcon.c b/src/extcon/extcon.c index 5f87442..54c4b33 100755 --- a/src/extcon/extcon.c +++ b/src/extcon/extcon.c @@ -25,6 +25,7 @@ #include "core/devices.h" #include "core/config-parser.h" #include "core/device-notifier.h" +#include "core/edbus-handler.h" #include "core/udev.h" #include "extcon.h" @@ -196,6 +197,44 @@ static void uevent_extcon_handler(struct udev_device *dev) return; } +static DBusMessage *dbus_get_extcon_status(E_DBus_Object *obj, + DBusMessage *msg) +{ + DBusError err; + DBusMessageIter iter; + DBusMessage *reply; + struct extcon_ops *dev; + char *str; + int ret; + + dbus_error_init(&err); + + if (!dbus_message_get_args(msg, &err, + DBUS_TYPE_STRING, &str, + DBUS_TYPE_INVALID)) { + _E("fail to get message : %s - %s", err.name, err.message); + dbus_error_free(&err); + ret = -EINVAL; + goto error; + } + + dev = find_extcon(str); + if (!dev) { + _E("fail to matched extcon device : %s", str); + ret = -ENOENT; + goto error; + } + + ret = dev->status; + _D("Extcon device : %s, status : %d", dev->name, dev->status); + +error: + 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 int extcon_probe(void *data) { /** @@ -216,6 +255,10 @@ static struct uevent_handler uh = { .uevent_func = uevent_extcon_handler, }; +static const struct edbus_method edbus_methods[] = { + { "GetStatus", "s", "i", dbus_get_extcon_status }, +}; + static void extcon_init(void *data) { int ret; @@ -246,6 +289,12 @@ static void extcon_init(void *data) } else { _E("Failed to get extcon uevent state node"); } + + ret = register_edbus_interface_and_method(DEVICED_PATH_EXTCON, + DEVICED_INTERFACE_EXTCON, + edbus_methods, ARRAY_SIZE(edbus_methods)); + if (ret < 0) + _E("fail to init edbus interface and method(%d)", ret); } static void extcon_exit(void *data) diff --git a/src/extcon/extcon.h b/src/extcon/extcon.h index 989da1a..4fd8d6d 100755 --- a/src/extcon/extcon.h +++ b/src/extcon/extcon.h @@ -20,6 +20,18 @@ #ifndef __EXTCON_H__ #define __EXTCON_H__ +/** + * Extcon cable name is shared with kernel extcon class. + * So do not change below strings. + */ +#define EXTCON_CABLE_USB "USB" +#define EXTCON_CABLE_USB_HOST "USB-Host" +#define EXTCON_CABLE_TA "TA" +#define EXTCON_CABLE_HDMI "HDMI" +#define EXTCON_CABLE_DOCK "Dock" +#define EXTCON_CABLE_MIC_IN "Microphone" +#define EXTCON_CABLE_HEADPHONE_OUT "Headphone" + struct extcon_ops { const char *name; int status; diff --git a/src/usb/usb.c b/src/usb/usb.c index 02fd197..7595da7 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -208,7 +208,7 @@ static void usb_exit(void *data) } struct extcon_ops extcon_usb_ops = { - .name = "USB", + .name = EXTCON_CABLE_USB, .noti = DEVICE_NOTIFIER_USB, .init = usb_init, .exit = usb_exit, -- 2.7.4 From 0223019c976544d3b04c0938b2156f41837a39cf Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Fri, 13 Feb 2015 18:18:21 +0900 Subject: [PATCH 04/16] extcon: Replace device-notifier with update callback function Device-notifier makes to be tight code among each other modules. And update callback is more useful without any effort to register or unregister device-notifier. Change-Id: I6a9ba2eafb26973bf15f18b2dc74a0e1bd970e43 Signed-off-by: Jiyoung Yun --- src/core/device-notifier.h | 1 - src/extcon/extcon.c | 3 ++- src/extcon/extcon.h | 2 +- src/usb/usb.c | 26 +++++++++----------------- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/core/device-notifier.h b/src/core/device-notifier.h index aba3e13..597217a 100644 --- a/src/core/device-notifier.h +++ b/src/core/device-notifier.h @@ -26,7 +26,6 @@ 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/extcon/extcon.c b/src/extcon/extcon.c index 54c4b33..37635f5 100755 --- a/src/extcon/extcon.c +++ b/src/extcon/extcon.c @@ -57,7 +57,8 @@ static int extcon_changed(struct extcon_ops *dev, int status) _I("Changed %s device : %d -> %d", dev->name, dev->status, status); dev->status = status; - device_notify(dev->noti, &status); + if (dev->update) + dev->update(status); return 0; } diff --git a/src/extcon/extcon.h b/src/extcon/extcon.h index 4fd8d6d..c41857a 100755 --- a/src/extcon/extcon.h +++ b/src/extcon/extcon.h @@ -35,9 +35,9 @@ struct extcon_ops { const char *name; int status; - enum device_notifier_type noti; void (*init)(void *data); void (*exit)(void *data); + int (*update)(int status); }; #define EXTCON_OPS_REGISTER(dev) \ diff --git a/src/usb/usb.c b/src/usb/usb.c index 7595da7..4cfa55d 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -143,22 +143,17 @@ static int usb_config_disable(void) return config_plugin->disable("DEFAULT"); } -static int usb_state_changed(void *data) +static int usb_state_changed(int status) { - static int state = USB_DISCONNECTED; - int input, ret; - - if (!data) - return -EINVAL; - - input = *(int *)data; + static int old = USB_DISCONNECTED; + int ret; - _I("USB state is changed from (%d) to (%d)", state, input); + _I("USB state is changed from (%d) to (%d)", old, status); - if (state == input) + if (old == status) return 0; - switch (input) { + switch (status) { case USB_CONNECTED: _I("USB cable is connected"); ret = usb_config_enable(); @@ -168,13 +163,13 @@ static int usb_state_changed(void *data) ret = usb_config_disable(); break; default: - _E("Invalid USB state(%d)", state); + _E("Invalid USB state(%d)", status); return -EINVAL; } if (ret < 0) _E("Failed to operate usb connection(%d)", ret); else - state = input; + old = status; return ret; } @@ -183,8 +178,6 @@ static void usb_init(void *data) { int ret; - register_notifier(DEVICE_NOTIFIER_USB, usb_state_changed); - ret = usb_config_module_load(); if (ret < 0) { _E("Failed to get config module (%d)", ret); @@ -202,16 +195,15 @@ static void usb_init(void *data) static void usb_exit(void *data) { - unregister_notifier(DEVICE_NOTIFIER_USB, usb_state_changed); usb_config_deinit(); usb_config_module_unload(); } struct extcon_ops extcon_usb_ops = { .name = EXTCON_CABLE_USB, - .noti = DEVICE_NOTIFIER_USB, .init = usb_init, .exit = usb_exit, + .update = usb_state_changed, }; EXTCON_OPS_REGISTER(&extcon_usb_ops) -- 2.7.4 From ec7bef629e2ff6811292fdccb887444b8f13d3ce Mon Sep 17 00:00:00 2001 From: taeyoung Date: Tue, 10 Feb 2015 20:13:38 +0900 Subject: [PATCH 05/16] usb: set default usb config to usb sdb - Default usb config is used from Tizen 1.0 to tizen 2.3. USB nodes at sysfs are used to set usb configuration. - Default usb config is not plugin type since it will be used when other plugin does not exist Change-Id: I0f1f3ed1ff128d6cb62c410529c6227981a1f5de Signed-off-by: taeyoung --- CMakeLists.txt | 3 + packaging/deviced.spec | 2 + src/usb/usb-default.c | 273 +++++++++++++++++++++++++++++++++++++++++++++ src/usb/usb-operation.conf | 3 + src/usb/usb-setting.conf | 14 +++ src/usb/usb.c | 16 +-- 6 files changed, 299 insertions(+), 12 deletions(-) create mode 100644 src/usb/usb-default.c create mode 100644 src/usb/usb-operation.conf create mode 100644 src/usb/usb-setting.conf diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ff2c69..fd65784 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,7 @@ SET(SRCS SET(SRCS ${SRCS} src/usb/usb.c + src/usb/usb-default.c ) IF(TIZEN_BUZZER) @@ -189,6 +190,8 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_I INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/deviced-pre.sh DESTINATION bin) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/scripts/deviced.conf DESTINATION /etc/dbus-1/system.d) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/scripts/movi_format.sh DESTINATION bin) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/usb/usb-setting.conf DESTINATION /etc/deviced) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/usb/usb-operation.conf DESTINATION /etc/deviced) IF(TIZEN_SDCARD) INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/mmc-smack-label DESTINATION bin) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/fsck-msdos/LICENSE DESTINATION share/license RENAME fsck_msdosfs) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index fc0397f..d18c5ad 100755 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -317,6 +317,8 @@ systemctl daemon-reload %{_bindir}/deviced %{_bindir}/devicectl %{_bindir}/movi_format.sh +%{_sysconfdir}/deviced/usb-setting.conf +%{_sysconfdir}/deviced/usb-operation.conf %if %{with sdcard} %{_bindir}/mmc-smack-label %{_bindir}/fsck_msdosfs diff --git a/src/usb/usb-default.c b/src/usb/usb-default.c new file mode 100644 index 0000000..2154641 --- /dev/null +++ b/src/usb/usb-default.c @@ -0,0 +1,273 @@ +/* + * 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 +#include + +#include "core/log.h" +#include "core/common.h" +#include "core/config-parser.h" +#include "core/launch.h" +#include "usb.h" + +#define USB_SETTING "/etc/deviced/usb-setting.conf" +#define USB_OPERATION "/etc/deviced/usb-operation.conf" + +#define SECTION_BASE "BASE" +#define KEY_ROOTPATH "rootpath" +#define KEY_LOAD "load" +#define KEY_DEFAULT "default" +#define KEY_START "start" +#define KEY_STOP "stop" + +#define CONFIG_ENABLE "1" +#define CONFIG_DISABLE "0" + +#define BUF_MAX 128 + +struct oper_data { + char *type; + char *name; +}; + +static char config_rootpath[BUF_MAX]; +static char config_load[BUF_MAX]; +static char config_default[BUF_MAX]; + +static int write_file(char *path, char *val) +{ + FILE *fp; + int ret; + unsigned int len; + + if (!path || !val) + return -EINVAL; + + fp = fopen(path, "w"); + if (!fp) { + ret = -errno; + _E("Failed to open file (%s, errno:%d)", path, ret); + return ret; + } + + len = strlen(val); + ret = fwrite(val, sizeof(char), len, fp); + fclose(fp); + if (ret < len) { + _E("Failed to write (%s, %s)", path, val); + return -ENOMEM; + } + + return 0; +} + +static int load_setting_config(struct parse_result *result, void *user_data) +{ + char *section = user_data; + char path[BUF_MAX]; + int ret; + + if (!result || !section) + return -EINVAL; + + if (result->section == NULL || result->name == NULL) + return -EINVAL; + + if (strncmp(section, result->section, strlen(section))) + return 0; + + snprintf(path, sizeof(path), "%s/%s", config_rootpath, result->name); + ret = write_file(path, result->value); + if (ret < 0) + _E("Failed to write (%s, %s)", path, result->value); + + return ret; +} + +static int load_base_config(struct parse_result *result, void *user_data) +{ + unsigned int len; + + if (!result) + return -EINVAL; + + if (result->section == NULL || result->name == NULL) + return -EINVAL; + + if (strncmp(result->section, SECTION_BASE, sizeof(SECTION_BASE))) + return 0; + + if (!strncmp(result->name, KEY_ROOTPATH, sizeof(KEY_ROOTPATH))) { + snprintf(config_rootpath, sizeof(config_rootpath), + "%s", result->value); + _I("USB config rootpath(%s)", config_rootpath); + } + + else if (!strncmp(result->name, KEY_LOAD, sizeof(KEY_LOAD))) { + snprintf(config_load, sizeof(config_load), + "%s", result->value); + _I("USB config load(%s)", config_load); + } + + else if (!strncmp(result->name, KEY_DEFAULT, sizeof(KEY_DEFAULT))) { + snprintf(config_default, sizeof(config_default), + "%s", result->value); + _I("USB config default(%s)", config_default); + } + + return 0; +} + +static int load_operation_config(struct parse_result *result, void *user_data) +{ + struct oper_data *data = user_data; + int ret; + + if (!data || !result) + return -EINVAL; + + if (strncmp(result->section, data->type, strlen(result->section))) + return 0; + + if (strncmp(result->name, data->name, strlen(result->name))) + return 0; + + ret = launch_app_cmd(result->value); + + _I("Execute(%s: %d)", result->value, ret); + + return ret; +} + +static int usb_execute_operation(char *type, char *name) +{ + int ret; + struct oper_data data; + + if (!name) + return -EINVAL; + + if (!type) + type = config_default; + + data.name = name; + data.type = type; + + ret = config_parse(USB_OPERATION, + load_operation_config, &data); + if (ret < 0) + _E("Failed to load usb operation (%d)", ret); + + return ret; +} + +static int usb_load_configuration(char *enable) +{ + int ret; + static char buf[BUF_MAX]; + static bool node = false; + + if (!node) { + snprintf(buf, sizeof(buf), "%s/%s", + config_rootpath, config_load); + node = true; + } + + ret = write_file(buf, enable); + if (ret < 0) + _E("Failed to write (%s, %s)", buf, enable); + + return ret; +} + +static int usb_update_configuration(char *name) +{ + if (!name) + name = config_default; + + return config_parse(USB_SETTING, + load_setting_config, name); +} + +static int usb_init(char *name) +{ + int ret; + + ret = config_parse(USB_SETTING, + load_base_config, name); + if (ret < 0) { + _E("Failed to get base information(%d)", ret); + return ret; + } + + ret = usb_update_configuration(name); + if (ret < 0) + _E("Failed to update usb configuration(%d)", ret); + + return ret; +} + +static int usb_enable(char *name) +{ + int ret; + + ret = usb_load_configuration(CONFIG_DISABLE); + if (ret < 0) { + _E("Failed to disable usb config"); + return ret; + } + + ret = usb_load_configuration(CONFIG_ENABLE); + if (ret < 0) { + _E("Failed to enable usb config"); + return ret; + } + + return usb_execute_operation(name, KEY_START); +} + +static int usb_disable(char *name) +{ + return usb_execute_operation(name, KEY_STOP); +} + +static const struct usb_config_plugin_ops default_plugin = { + .init = usb_init, + .enable = usb_enable, + .disable = usb_disable, +}; + +static bool usb_valid(void) +{ + /* TODO + * add checking default config valid condition */ + return true; +} + +static const struct usb_config_plugin_ops *usb_load(void) +{ + return &default_plugin; +} + +static const struct usb_config_ops usb_config_default_ops = { + .is_valid = usb_valid, + .load = usb_load, +}; + +USB_CONFIG_OPS_REGISTER(&usb_config_default_ops) diff --git a/src/usb/usb-operation.conf b/src/usb/usb-operation.conf new file mode 100644 index 0000000..8db280d --- /dev/null +++ b/src/usb/usb-operation.conf @@ -0,0 +1,3 @@ +[SDB] +start=/usr/bin/systemctl start sdbd.service +stop=/usr/bin/systemctl stop sdbd.service diff --git a/src/usb/usb-setting.conf b/src/usb/usb-setting.conf new file mode 100644 index 0000000..755937f --- /dev/null +++ b/src/usb/usb-setting.conf @@ -0,0 +1,14 @@ +[BASE] +rootpath=/sys/class/usb_mode/usb0 +load=enable +default=SDB + +[SDB] +idVendor=04e8 +idProduct=6860 +funcs_fconf=sdb +funcs_sconf=sdb +bDeviceClass=239 +bDeviceSubClass=2 +bDeviceProtocol=1 +iProduct=TIZEN diff --git a/src/usb/usb.c b/src/usb/usb.c index 02fd197..bee3b0c 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -87,9 +87,7 @@ static int usb_config_init(void) return -ENOENT; } - /* TODO: - * parameter "DEFAULT" can be changed */ - return config_plugin->init("DEFAULT"); + return config_plugin->init(NULL); } static void usb_config_deinit(void) @@ -104,9 +102,7 @@ static void usb_config_deinit(void) return; } - /* TODO: - * parameter "DEFAULT" can be changed */ - config_plugin->deinit("DEFAULT"); + config_plugin->deinit(NULL); } static int usb_config_enable(void) @@ -121,9 +117,7 @@ static int usb_config_enable(void) return -ENOENT; } - /* TODO: - * parameter "DEFAULT" can be changed */ - return config_plugin->enable("DEFAULT"); + return config_plugin->enable(NULL); } static int usb_config_disable(void) @@ -138,9 +132,7 @@ static int usb_config_disable(void) return -ENOENT; } - /* TODO: - * parameter "DEFAULT" can be changed */ - return config_plugin->disable("DEFAULT"); + return config_plugin->disable(NULL); } static int usb_state_changed(void *data) -- 2.7.4 From ee16b8e1929be48ccb750134ce5426d578674240 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Tue, 24 Feb 2015 19:08:05 +0900 Subject: [PATCH 06/16] deviced: Set vconf as NOTSUP error in no battery model Runtime-info and Capi-system-device api uses battery vconf to get battery status. So if there is no battery in target, deviced set vconf as -ENOTSUP value. Change-Id: I9fe23fb6671493394a02ff5b4c7d8a91437e48fe Signed-off-by: Jiyoung Yun --- src/battery/lowbat-handler.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 8e19789..52baa79 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -520,6 +520,14 @@ static int lowbat_probe(void *data) * deviced does not activate a battery module. */ if (access(POWER_PATH, R_OK) != 0) { + /** + * Set battery vconf as -ENOTSUP + * These vconf key used by runtime-info and capi-system-device. + */ + vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS, -ENOTSUP); + vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, -ENOTSUP); + vconf_set_int(VCONFKEY_SYSMAN_BATTERY_LEVEL_STATUS, -ENOTSUP); + _E("there is no power-supply class"); return -ENODEV; } -- 2.7.4 From af9e4848023c0e119870db80ffa944bb020653f7 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Wed, 25 Feb 2015 20:35:32 +0900 Subject: [PATCH 07/16] deviced: Change wrong dbus configuration Root, console and default user can send to device object path. Change-Id: I22e24d33cf5b3f93731982f805aba6f2fadccd03 Signed-off-by: Jiyoung Yun --- scripts/deviced.conf | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/scripts/deviced.conf b/scripts/deviced.conf index e70c8e8..51ca6a0 100644 --- a/scripts/deviced.conf +++ b/scripts/deviced.conf @@ -1,23 +1,16 @@ - + - - + + + + + - - - - - - - - - - - + -- 2.7.4 From b7bf5c01ffc9347d0c143724fa5112f611e76c63 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Thu, 12 Feb 2015 10:51:13 +0900 Subject: [PATCH 08/16] deviced: Enable camera led module and check whether it is available at runtime Deviced loads led HAL structure at loading time. If it is failed, the device does not support camera led module. Change-Id: Ie45423cdd920ae5192b56a678c4c256b1e5f4a2f Signed-off-by: Jiyoung Yun --- CMakeLists.txt | 3 +- packaging/deviced.spec | 5 +-- src/core/edbus-handler.c | 1 - src/led/ir.c | 4 +- src/led/torch.c | 108 ++++++++++++++++++++++++++++++++++++++++++----- 5 files changed, 102 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd65784..30c795c 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,13 +106,11 @@ SET(SRCS ${SRCS} ) ENDIF(TIZEN_DISPLAY) -IF(TIZEN_CAMERA_LED) SET(SRCS ${SRCS} src/led/ir.c src/led/noti.c src/led/torch.c ) -ENDIF(TIZEN_CAMERA_LED) IF(TIZEN_VIBRATOR) SET(SRCS ${SRCS} @@ -138,6 +136,7 @@ SET(PKG_MODULES tapi libtzplatform-config notification + hwcommon ) IF(X11_SUPPORT) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index d18c5ad..34de28a 100755 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -5,7 +5,6 @@ #These options are DEACTIVATED by default. %bcond_with x %bcond_with buzzer -%bcond_with camera_led %bcond_with extcon %bcond_with hall %bcond_with sdcard @@ -48,6 +47,7 @@ BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(dbus-glib-1) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(notification) +BuildRequires: pkgconfig(hwcommon) %{?systemd_requires} Requires(preun): /usr/bin/systemctl @@ -190,9 +190,6 @@ export CFLAGS+=" -DX11_SUPPORT" %if %{with buzzer} -DTIZEN_BUZZER:BOOL=ON \ %endif -%if %{with camera_led} - -DTIZEN_CAMERA_LED:BOOL=ON \ -%endif %if %{with display} -DTIZEN_DISPLAY:BOOL=ON \ %endif diff --git a/src/core/edbus-handler.c b/src/core/edbus-handler.c index 6d24931..4da6a5c 100644 --- a/src/core/edbus-handler.c +++ b/src/core/edbus-handler.c @@ -53,7 +53,6 @@ static struct edbus_object edbus_objects[] = { { DEVICED_PATH_POWER , DEVICED_INTERFACE_POWER , NULL, NULL }, { DEVICED_PATH_STORAGE, DEVICED_INTERFACE_STORAGE, NULL, NULL }, { DEVICED_PATH_HAPTIC , DEVICED_INTERFACE_HAPTIC , NULL, NULL }, - { DEVICED_PATH_LED , DEVICED_INTERFACE_LED , NULL, NULL }, { DEVICED_PATH_MMC , DEVICED_INTERFACE_MMC , NULL, NULL }, { DEVICED_PATH_PROCESS, DEVICED_INTERFACE_PROCESS, NULL, NULL }, { DEVICED_PATH_KEY , DEVICED_INTERFACE_KEY , NULL, NULL }, diff --git a/src/led/ir.c b/src/led/ir.c index af448ff..e86f889 100644 --- a/src/led/ir.c +++ b/src/led/ir.c @@ -59,7 +59,9 @@ static void ir_init(void *data) int ret; /* init dbus interface */ - ret = register_edbus_method(DEVICED_PATH_LED, edbus_methods, ARRAY_SIZE(edbus_methods)); + ret = register_edbus_interface_and_method(DEVICED_PATH_LED, + DEVICED_INTERFACE_LED, + edbus_methods, ARRAY_SIZE(edbus_methods)); if (ret < 0) _E("fail to init edbus method(%d)", ret); } diff --git a/src/led/torch.c b/src/led/torch.c index f1cf6a3..6f40368 100644 --- a/src/led/torch.c +++ b/src/led/torch.c @@ -22,22 +22,43 @@ #include #include #include +#include #include "core/log.h" #include "core/edbus-handler.h" #include "core/devices.h" #include "torch.h" +#define LED_MAX_BRIGHTNESS 100 +#define GET_BRIGHTNESS(x) (((x) >> 24) & 0xFF) + +static struct led_device *led_dev; +static struct led_state led_state = { + .type = LED_TYPE_MANUAL, + .color = 0x0, + .duty_on = 0, + .duty_off = 0, +}; + static DBusMessage *edbus_get_brightness(E_DBus_Object *obj, DBusMessage *msg) { DBusMessageIter iter; DBusMessage *reply; - int val, ret; + int ret, alpha; - ret = device_get_property(DEVICE_TYPE_LED, PROP_LED_BRIGHTNESS, &val); - if (ret >= 0) - ret = val; + if (!led_dev) { + _E("there is no led device"); + ret = -ENOENT; + goto error; + } + alpha = GET_BRIGHTNESS(led_state.color); + ret = alpha * 100.f / 255; + if (alpha != 0 && alpha != 0xFF) + ret += 1; + _D("color : val(%d), color(%x)", ret, led_state.color); + +error: reply = dbus_message_new_method_return(msg); dbus_message_iter_init_append(reply, &iter); dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret); @@ -48,11 +69,9 @@ static DBusMessage *edbus_get_max_brightness(E_DBus_Object *obj, DBusMessage *ms { DBusMessageIter iter; DBusMessage *reply; - int val, ret; + int ret; - ret = device_get_property(DEVICE_TYPE_LED, PROP_LED_MAX_BRIGHTNESS, &val); - if (ret >= 0) - ret = val; + ret = LED_MAX_BRIGHTNESS; reply = dbus_message_new_method_return(msg); dbus_message_iter_init_append(reply, &iter); @@ -65,6 +84,7 @@ static DBusMessage *edbus_set_brightness(E_DBus_Object *obj, DBusMessage *msg) DBusMessageIter iter; DBusMessage *reply; int val, enable, ret; + struct led_state tmp = {0,}; ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &val, @@ -75,10 +95,21 @@ static DBusMessage *edbus_set_brightness(E_DBus_Object *obj, DBusMessage *msg) goto error; } - ret = device_set_property(DEVICE_TYPE_LED, PROP_LED_BRIGHTNESS, val); + if (!led_dev) { + _E("there is no led device"); + ret = -ENOENT; + goto error; + } + + tmp.color = (((int)(val * 255.f) / LED_MAX_BRIGHTNESS) & 0xFF) << 24; + _D("color : val(%d), color(%x)", val, tmp.color); + + ret = led_dev->set_state(&tmp); if (ret < 0) goto error; + memcpy(&led_state, &tmp, sizeof(led_state)); + /* if enable is ON, noti will be show or hide */ if (enable) { if (val) @@ -101,19 +132,74 @@ static const struct edbus_method edbus_methods[] = { /* Add methods here */ }; +static int led_service_load(void) +{ + struct hw_info *info; + int r; + + r = hw_get_info(LED_HARDWARE_DEVICE_ID, + (const struct hw_info **)&info); + if (r < 0) { + _E("fail to load led shared library : %d", r); + return -ENOENT; + } + + if (!info->open) { + _E("fail to open camera led device : open(NULL)"); + return -EPERM; + } + + r = info->open(info, LED_ID_CAMERA_BACK, + (struct hw_common **)&led_dev); + if (r < 0) { + _E("fail to get camera led device : %d", r); + return -EPERM; + } + + _D("camera led device structure load success"); + return 0; +} + +static int led_service_free(void) +{ + struct hw_info *info; + + info = led_dev->common.info; + + assert(info); + + info->close((struct hw_common *)led_dev); +} + +static int torch_probe(void *data) +{ + /* load led device */ + return led_service_load(); +} + static void torch_init(void *data) { int ret; /* init dbus interface */ - ret = register_edbus_method(DEVICED_PATH_LED, edbus_methods, ARRAY_SIZE(edbus_methods)); + ret = register_edbus_interface_and_method(DEVICED_PATH_LED, + DEVICED_INTERFACE_LED, + edbus_methods, ARRAY_SIZE(edbus_methods)); if (ret < 0) - _E("fail to init edbus method(%d)", ret); + _E("fail to init edbus interface and method(%d)", ret); +} + +static void torch_exit(void *data) +{ + /* free led device */ + led_service_free(); } static const struct device_ops torchled_device_ops = { .name = "torchled", + .probe = torch_probe, .init = torch_init, + .exit = torch_exit, }; DEVICE_OPS_REGISTER(&torchled_device_ops) -- 2.7.4 From 9aa13a9765d5dea73ab36e56e50b74c84d411a4a Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Fri, 27 Feb 2015 18:54:59 +0900 Subject: [PATCH 09/16] deviced: add null point check When deviced is terminated, if there is no led device, it makes a segfault issue by null point access. Change-Id: I8724c9f235b090e04682d514e9de8f030b7591ca Signed-off-by: Jiyoung Yun --- src/led/torch.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/led/torch.c b/src/led/torch.c index 6f40368..f4ad1f7 100644 --- a/src/led/torch.c +++ b/src/led/torch.c @@ -164,11 +164,16 @@ static int led_service_free(void) { struct hw_info *info; + if (!led_dev) + return -ENOENT; + info = led_dev->common.info; assert(info); info->close((struct hw_common *)led_dev); + + return 0; } static int torch_probe(void *data) -- 2.7.4 From b24f524ebe4e77fdccbffffe25aa93422288d054 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Thu, 26 Feb 2015 12:51:46 +0900 Subject: [PATCH 10/16] deviced: Enable vibrator and check whether it is available at runtime Deviced will check if there is an external vibrator plugin. It should be named 'libhaptic-module.so' in lib directory. If not, it checks whether this target supports the input force feedback. If there is no valid module, it will return fail and do not register any function and method related to vibrator. Change-Id: I3bc1da9cb378fac1ecea3cb0480915e0485c229f Signed-off-by: Jiyoung Yun --- CMakeLists.txt | 2 -- packaging/deviced.spec | 4 ---- src/core/edbus-handler.c | 1 - src/haptic/external.c | 2 +- src/haptic/haptic.c | 20 +++++++++++++++----- src/haptic/standard.c | 2 +- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 30c795c..304e348 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,13 +112,11 @@ SET(SRCS ${SRCS} src/led/torch.c ) -IF(TIZEN_VIBRATOR) SET(SRCS ${SRCS} src/haptic/haptic.c src/haptic/external.c src/haptic/standard.c src/haptic/emulator.c) -ENDIF(TIZEN_VIBRATOR) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 34de28a..5cfb87b 100755 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -10,7 +10,6 @@ %bcond_with sdcard %bcond_with sim %bcond_with usb -%bcond_with vibrator Name: deviced Summary: Deviced @@ -208,9 +207,6 @@ export CFLAGS+=" -DX11_SUPPORT" %if %{with usb} -DTIZEN_USB:BOOL=ON \ %endif -%if %{with vibrator} - -DTIZEN_VIBRATOR:BOOL=ON \ -%endif #eol %build diff --git a/src/core/edbus-handler.c b/src/core/edbus-handler.c index 4da6a5c..9353b58 100644 --- a/src/core/edbus-handler.c +++ b/src/core/edbus-handler.c @@ -52,7 +52,6 @@ static struct edbus_object edbus_objects[] = { { DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, NULL, NULL }, { DEVICED_PATH_POWER , DEVICED_INTERFACE_POWER , NULL, NULL }, { DEVICED_PATH_STORAGE, DEVICED_INTERFACE_STORAGE, NULL, NULL }, - { DEVICED_PATH_HAPTIC , DEVICED_INTERFACE_HAPTIC , NULL, NULL }, { DEVICED_PATH_MMC , DEVICED_INTERFACE_MMC , NULL, NULL }, { DEVICED_PATH_PROCESS, DEVICED_INTERFACE_PROCESS, NULL, NULL }, { DEVICED_PATH_KEY , DEVICED_INTERFACE_KEY , NULL, NULL }, diff --git a/src/haptic/external.c b/src/haptic/external.c index 46dfe5d..2482f59 100644 --- a/src/haptic/external.c +++ b/src/haptic/external.c @@ -70,7 +70,7 @@ error: dlopen_handle = NULL; } - _I("Do not support external haptic device"); + _E("Do not support external haptic device"); return false; } diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c index 2884ac9..61ccc91 100644 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -660,13 +660,20 @@ static const struct edbus_method edbus_methods[] = { /* Add methods here */ }; +static int haptic_probe(void *data) +{ + /** + * load haptic module. + * if there is no haptic module, + * deviced does not activate a haptic interface. + */ + return haptic_module_load(); +} + static void haptic_init(void *data) { int r; - /* Load haptic module */ - haptic_module_load(); - /* get haptic data from configuration file */ r = config_parse(HAPTIC_CONF_PATH, haptic_load_config, &haptic_conf); if (r < 0) { @@ -675,9 +682,11 @@ static void haptic_init(void *data) } /* init dbus interface */ - r = register_edbus_method(DEVICED_PATH_HAPTIC, edbus_methods, ARRAY_SIZE(edbus_methods)); + r = register_edbus_interface_and_method(DEVICED_PATH_HAPTIC, + DEVICED_INTERFACE_HAPTIC, + edbus_methods, ARRAY_SIZE(edbus_methods)); if (r < 0) - _E("fail to init edbus method(%d)", r); + _E("fail to init edbus interface and method(%d)", r); /* register notifier for below each event */ register_notifier(DEVICE_NOTIFIER_TOUCH_HARDKEY, haptic_hardkey_changed_cb); @@ -736,6 +745,7 @@ static int haptic_stop(void) static const struct device_ops haptic_device_ops = { .name = "haptic", + .probe = haptic_probe, .init = haptic_init, .exit = haptic_exit, }; diff --git a/src/haptic/standard.c b/src/haptic/standard.c index ed43488..d6c7ad0 100644 --- a/src/haptic/standard.c +++ b/src/haptic/standard.c @@ -499,7 +499,7 @@ static bool is_valid(void) ret = ff_find_device(); if (ret < 0) { - _I("Do not support standard haptic device"); + _E("Do not support standard haptic device"); return false; } -- 2.7.4 From b9daf8e75ac67e0403905b951845f98ebbda31ee Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Thu, 26 Feb 2015 17:03:49 +0900 Subject: [PATCH 11/16] deviced: resolve resource leak issue DD_LIST_FOREACH define is not proper to remove elementary in loop. Instead, DD_LIST_FOREACH_SAFE define redeems the issue. So change the FOREACH define to FOREACH_SAFE. Change-Id: I722ca291115f2a82b06d29764a7bfc4ae8cc7256 Signed-off-by: Jiyoung Yun --- src/core/edbus-handler.c | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/core/edbus-handler.c b/src/core/edbus-handler.c index 9353b58..78038f1 100644 --- a/src/core/edbus-handler.c +++ b/src/core/edbus-handler.c @@ -35,19 +35,17 @@ #define DBUS_REPLY_TIMEOUT (-1) #define RETRY_MAX 5 -struct edbus_object { - const char *path; - const char *interface; - E_DBus_Object *obj; - E_DBus_Interface *iface; -}; - -struct edbus_list{ +struct edbus_list { char *signal_name; E_DBus_Signal_Handler *handler; }; -static struct edbus_object edbus_objects[] = { +static struct edbus_object { + const char *path; + const char *interface; + E_DBus_Object *obj; + E_DBus_Interface *iface; +} edbus_objects[] = { { DEVICED_PATH_CORE , DEVICED_INTERFACE_CORE , NULL, NULL }, { DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, NULL, NULL }, { DEVICED_PATH_POWER , DEVICED_INTERFACE_POWER , NULL, NULL }, @@ -75,8 +73,6 @@ static DBusPendingCall *edbus_request_name; static int register_edbus_interface(struct edbus_object *object) { - int ret; - if (!object) { _E("object is invalid value!"); return -1; @@ -175,10 +171,10 @@ pid_t get_edbus_sender_pid(DBusMessage *msg) static void unregister_edbus_signal_handle(void) { - dd_list *tmp; + dd_list *tmp, *next; struct edbus_list *entry; - DD_LIST_FOREACH(edbus_handler_list, tmp, entry) { + DD_LIST_FOREACH_SAFE(edbus_handler_list, tmp, next, entry) { e_dbus_signal_handler_del(edbus_conn, entry->handler); DD_LIST_REMOVE(edbus_handler_list, entry); free(entry->signal_name); @@ -271,7 +267,7 @@ static DBusHandlerResult message_filter(DBusConnection *connection, int ret; const char *iface, *member, *arg = NULL; struct watch *watch; - dd_list *n; + dd_list *n, *next; if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; @@ -294,7 +290,7 @@ static DBusHandlerResult message_filter(DBusConnection *connection, _D("Argument : %s", arg); - DD_LIST_FOREACH(edbus_watch_list, n, watch) { + DD_LIST_FOREACH_SAFE(edbus_watch_list, n, next, watch) { if (strcmp(arg, watch->name)) continue; if (watch->func) @@ -352,11 +348,11 @@ int register_edbus_watch(DBusMessage *msg, enum watch_id id, int (*func)(char *n return 0; } - watch = malloc(sizeof(struct watch)); - if (!watch) { - _E("Fail to malloc for watch!"); - return -ENOMEM; - } + watch = malloc(sizeof(struct watch)); + if (!watch) { + _E("Fail to malloc for watch!"); + return -ENOMEM; + } watch->id = id; watch->func = func; @@ -398,7 +394,7 @@ int unregister_edbus_watch(DBusMessage *msg, enum watch_id id) char match[256]; const char *sender; struct watch *watch; - dd_list *n; + dd_list *n, *next; bool matched = false; if (!msg) { @@ -412,7 +408,7 @@ int unregister_edbus_watch(DBusMessage *msg, enum watch_id id) return -EINVAL; } - DD_LIST_FOREACH(edbus_watch_list, n, watch) { + DD_LIST_FOREACH_SAFE(edbus_watch_list, n, next, watch) { if (strcmp(sender, watch->name)) continue; @@ -427,8 +423,8 @@ int unregister_edbus_watch(DBusMessage *msg, enum watch_id id) /* remove match */ if (!matched) { - snprintf(match, sizeof(match), NAME_OWNER_MATCH, sender); - dbus_bus_remove_match(conn, match, NULL); + snprintf(match, sizeof(match), NAME_OWNER_MATCH, sender); + dbus_bus_remove_match(conn, match, NULL); if (DD_LIST_LENGTH(edbus_watch_list) == 0) dbus_connection_remove_filter(conn, message_filter, @@ -441,13 +437,13 @@ int unregister_edbus_watch(DBusMessage *msg, enum watch_id id) static void unregister_edbus_watch_all(void) { char match[256]; - dd_list *n; + dd_list *n, *next; struct watch *watch; if (DD_LIST_LENGTH(edbus_watch_list) > 0) dbus_connection_remove_filter(conn, message_filter, NULL); - DD_LIST_FOREACH(edbus_watch_list, n, watch) { + DD_LIST_FOREACH_SAFE(edbus_watch_list, n, next, watch) { snprintf(match, sizeof(match), NAME_OWNER_MATCH, watch->name); dbus_bus_remove_match(conn, match, NULL); DD_LIST_REMOVE(edbus_watch_list, watch); -- 2.7.4 From ec1d4bd71eb275b6184c5d5851d7dd7b06e7eeda Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Fri, 27 Feb 2015 18:56:33 +0900 Subject: [PATCH 12/16] deviced: remove out unsupported device from device list Unsupported device remove out from device list. It does not invoke any function of unsuppoted device include exit() function. Change-Id: Ia09a9a0b3676b0fc8cca8cbf3875c72961d51d1b Signed-off-by: Jiyoung Yun --- src/core/devices.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/devices.c b/src/core/devices.c index 307d3a0..942b7e0 100644 --- a/src/core/devices.c +++ b/src/core/devices.c @@ -64,12 +64,13 @@ int check_default(const struct device_ops *dev) void devices_init(void *data) { - dd_list *elem; + dd_list *elem, *elem_n; const struct device_ops *dev; - DD_LIST_FOREACH(dev_head, elem, dev) { + DD_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { if (dev->probe && dev->probe(data) != 0) { _E("[%s] probe fail", dev->name); + DD_LIST_REMOVE(dev_head, dev); continue; } -- 2.7.4 From 088d78b463cd5c44b2a2fe3dc40efe538e0e271f Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Wed, 25 Feb 2015 21:30:05 +0900 Subject: [PATCH 13/16] deviced: Add inline function to make dbus reply automatically Apply new function in extcon module Change-Id: Ia9a77fd88be8151288e9f51bc1ddd3e9ece74f8b Signed-off-by: Jiyoung Yun --- src/core/edbus-handler.h | 10 ++++++++++ src/extcon/extcon.c | 7 +------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/core/edbus-handler.h b/src/core/edbus-handler.h index cd2d266..6aee7d5 100644 --- a/src/core/edbus-handler.h +++ b/src/core/edbus-handler.h @@ -43,6 +43,16 @@ struct watch { int (*func)(char *name, enum watch_id id); }; +static inline DBusMessage *make_reply_message(DBusMessage *msg, int ret) +{ + DBusMessageIter iter; + DBusMessage *reply; + 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; +} + int register_edbus_interface_and_method(const char *path, const char *interface, const struct edbus_method *edbus_methods, int size); diff --git a/src/extcon/extcon.c b/src/extcon/extcon.c index 37635f5..030dcae 100755 --- a/src/extcon/extcon.c +++ b/src/extcon/extcon.c @@ -202,8 +202,6 @@ static DBusMessage *dbus_get_extcon_status(E_DBus_Object *obj, DBusMessage *msg) { DBusError err; - DBusMessageIter iter; - DBusMessage *reply; struct extcon_ops *dev; char *str; int ret; @@ -230,10 +228,7 @@ static DBusMessage *dbus_get_extcon_status(E_DBus_Object *obj, _D("Extcon device : %s, status : %d", dev->name, dev->status); error: - 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; + return make_reply_message(msg, ret); } static int extcon_probe(void *data) -- 2.7.4 From 0eedb2a0954e4e7153758b925b1564782a2c0ce9 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Fri, 6 Mar 2015 18:04:05 +0900 Subject: [PATCH 14/16] deviced: Apply display HAL structure Deviced will control display power using display HAL. It also supports to control display brightness. Change-Id: Ie15c0abe434610dfe60bbda7949ba6e5f71d174f Signed-off-by: Jiyoung Yun --- CMakeLists.txt | 3 - src/display/auto-brightness.c | 13 ++-- src/display/core.c | 14 ++++ src/display/device-interface.c | 148 +++++++++++++++++++++++++++++++++-------- src/display/device-interface.h | 14 ++-- src/display/display-dbus.c | 46 +++++-------- 6 files changed, 166 insertions(+), 72 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 304e348..d613d2f 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,9 +159,6 @@ ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"") ADD_DEFINITIONS("-DLIBPATH=\"${LIB_INSTALL_DIR}\"") ADD_DEFINITIONS("-DENABLE_KEY_FILTER") -IF(X11_SUPPORT) -ADD_DEFINITIONS("-DENABLE_X_LCD_ONOFF") -ENDIF(X11_SUPPORT) ADD_DEFINITIONS("-DENABLE_DEVICED_DLOG") ADD_DEFINITIONS("-DENABLE_LIBDEVICED_DLOG") ADD_DEFINITIONS("-DENABLE_PM_LOG") diff --git a/src/display/auto-brightness.c b/src/display/auto-brightness.c index 63b245e..6611d06 100644 --- a/src/display/auto-brightness.c +++ b/src/display/auto-brightness.c @@ -118,11 +118,10 @@ static bool update_working_position(void) static int get_siop_brightness(int value) { - int cmd, ret, brt; + int brt; - cmd = DISP_CMD(PROP_DISPLAY_MAX_BRIGHTNESS, DEFAULT_DISPLAY); - ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &brt); - if (ret >= 0 && value > brt) + brt = DEFAULT_DISPLAY_MAX_BRIGHTNESS; + if (value > brt) return brt; return value; @@ -131,10 +130,10 @@ static int get_siop_brightness(int value) static void alc_set_brightness(int setting, int value, int lux) { static int old; - int position, cmd, tmp_value = 0; + int position, tmp_value = 0, ret; - cmd = DISP_CMD(PROP_DISPLAY_BRIGHTNESS, DEFAULT_DISPLAY); - if (device_get_property(DEVICE_TYPE_DISPLAY, cmd, &tmp_value) < 0) { + ret = backlight_ops.get_brightness(&tmp_value); + if (ret < 0) { _E("Fail to get display brightness!"); return; } diff --git a/src/display/core.c b/src/display/core.c index 19557d2..c7cdd94 100644 --- a/src/display/core.c +++ b/src/display/core.c @@ -2319,6 +2319,16 @@ static int display_load_config(struct parse_result *result, void *user_data) * Power manager Main * */ +static int display_probe(void *data) +{ + /** + * load display service + * if there is no display shared library, + * deviced does not provide any method and function of display. + */ + return display_service_load(); +} + static void display_init(void *data) { int ret, i; @@ -2448,6 +2458,9 @@ static void display_exit(void *data) exit_lcd_operation(); free_lock_info_list(); + /* free display service */ + display_service_free(); + _I("Stop power manager"); } @@ -2504,6 +2517,7 @@ static int display_status(void) static const struct device_ops display_device_ops = { .priority = DEVICE_PRIORITY_HIGH, .name = "display", + .probe = display_probe, .init = display_init, .exit = display_exit, .start = display_start, diff --git a/src/display/device-interface.c b/src/display/device-interface.c index 7c9575d..17bd707 100644 --- a/src/display/device-interface.c +++ b/src/display/device-interface.c @@ -1,7 +1,7 @@ /* * deviced * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. + * Copyright (c) 2012 - 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. @@ -27,6 +27,9 @@ #include #include #include +#include +#include +#include #include "core/log.h" #include "core/devices.h" @@ -79,20 +82,30 @@ static bool custom_status = false; static int custom_brightness = 0; static int force_brightness = 0; +static struct display_device *display_dev; + static int _bl_onoff(PMSys *p, int on) { - int cmd; + if (!display_dev || !display_dev->set_state) { + _E("there is no display device"); + return -ENOENT; + } - cmd = DISP_CMD(PROP_DISPLAY_ONOFF, DEFAULT_DISPLAY); - return device_set_property(DEVICE_TYPE_DISPLAY, cmd, on); + return display_dev->set_state(on); } static int _bl_brt(PMSys *p, int brightness, int delay) { int ret = -1; - int cmd; int prev; + if (!display_dev || + !display_dev->get_brightness || + !display_dev->set_brightness) { + _E("there is no display device"); + return -ENOENT; + } + if (delay > 0) usleep(delay); @@ -102,8 +115,7 @@ static int _bl_brt(PMSys *p, int brightness, int delay) brightness = force_brightness; } - cmd = DISP_CMD(PROP_DISPLAY_BRIGHTNESS, DEFAULT_DISPLAY); - ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &prev); + ret = display_dev->get_brightness(&prev); /* Update new brightness to vconf */ if (!ret && (brightness != prev)) { @@ -111,7 +123,7 @@ static int _bl_brt(PMSys *p, int brightness, int delay) } /* Update device brightness */ - ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, brightness); + ret = display_dev->set_brightness(brightness); _I("set brightness %d, %d", brightness, ret); @@ -148,17 +160,19 @@ static int _sys_get_power_lock_support(PMSys *p) static int _sys_get_lcd_power(PMSys *p) { - int value = -1; - int ret = -1; - int cmd; + enum display_state state; + int ret; - cmd = DISP_CMD(PROP_DISPLAY_ONOFF, DEFAULT_DISPLAY); - ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &value); + if (!display_dev || !display_dev->get_state) { + _E("there is no display device"); + return -ENOENT; + } - if (ret < 0 || value < 0) - return -1; + ret = display_dev->get_state(&state); + if (ret < 0) + return ret; - return value; + return state; } static void _init_bldev(PMSys *p, unsigned int flags) @@ -291,15 +305,23 @@ void change_brightness(int start, int end, int step) { int diff, val; int ret = -1; - int cmd; int prev; + if (!display_dev || + !display_dev->get_brightness) { + _E("there is no display device"); + return; + } + if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) return; - cmd = DISP_CMD(PROP_DISPLAY_BRIGHTNESS, DEFAULT_DISPLAY); - ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &prev); + ret = display_dev->get_brightness(&prev); + if (ret < 0) { + _E("fail to get brightness : %d", ret); + return; + } if (prev == end) return; @@ -336,8 +358,8 @@ static int backlight_on(enum device_flags flags) return -1; for (i = 0; i < PM_LCD_RETRY_CNT; i++) { - ret = pmsys->bl_onoff(pmsys, STATUS_ON); - if (get_lcd_power() == PM_LCD_POWER_ON) { + ret = pmsys->bl_onoff(pmsys, DISPLAY_ON); + if (get_lcd_power() == DISPLAY_ON) { #ifdef ENABLE_PM_LOG pm_history_save(PM_LOG_LCD_ON, pm_cur_state); #endif @@ -381,8 +403,8 @@ static int backlight_off(enum device_flags flags) if (x_dpms_enable == false) #endif usleep(30000); - ret = pmsys->bl_onoff(pmsys, STATUS_OFF); - if (get_lcd_power() == PM_LCD_POWER_OFF) { + ret = pmsys->bl_onoff(pmsys, DISPLAY_OFF); + if (get_lcd_power() == DISPLAY_OFF) { #ifdef ENABLE_PM_LOG pm_history_save(PM_LOG_LCD_OFF, pm_cur_state); #endif @@ -430,10 +452,15 @@ static bool get_custom_status(void) static int save_custom_brightness(void) { - int cmd, ret, brightness; + int ret, brightness; + + if (!display_dev || + !display_dev->get_brightness) { + _E("there is no display device"); + return -ENOENT; + } - cmd = DISP_CMD(PROP_DISPLAY_BRIGHTNESS, DEFAULT_DISPLAY); - ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &brightness); + ret = display_dev->get_brightness(&brightness); custom_brightness = brightness; @@ -490,9 +517,9 @@ static int backlight_standby(int force) if (!pmsys || !pmsys->bl_onoff) return -1; - if ((get_lcd_power() == PM_LCD_POWER_ON) || force) { + if ((get_lcd_power() == DISPLAY_ON) || force) { _I("LCD standby"); - ret = pmsys->bl_onoff(pmsys, STATUS_STANDBY); + ret = pmsys->bl_onoff(pmsys, DISPLAY_STANDBY); } return ret; @@ -518,6 +545,26 @@ static int check_wakeup_src(void) return EVENT_DEVICE; } +static int set_brightness(int val) +{ + if (!display_dev || !display_dev->set_brightness) { + _E("there is no display device"); + return -ENOENT; + } + + return display_dev->set_brightness(val); +} + +static int get_brightness(int *val) +{ + if (!display_dev || !display_dev->get_brightness) { + _E("there is no display device"); + return -ENOENT; + } + + return display_dev->get_brightness(val); +} + void _init_ops(void) { backlight_ops.off = backlight_off; @@ -532,6 +579,8 @@ void _init_ops(void) backlight_ops.save_custom_brightness = save_custom_brightness; backlight_ops.custom_update = custom_backlight_update; backlight_ops.set_force_brightness = set_force_brightness; + backlight_ops.set_brightness = set_brightness; + backlight_ops.get_brightness = get_brightness; power_ops.suspend = system_suspend; power_ops.pre_suspend = system_pre_suspend; @@ -542,6 +591,49 @@ void _init_ops(void) power_ops.check_wakeup_src = check_wakeup_src; } +int display_service_load(void) +{ + struct hw_info *info; + int r; + + r = hw_get_info(DISPLAY_HARDWARE_DEVICE_ID, + (const struct hw_info **)&info); + if (r < 0) { + _E("fail to load display shared library : %d", r); + return -ENOENT; + } + + if (!info->open) { + _E("fail to open display device : open(NULL)"); + return -EPERM; + } + + r = info->open(info, NULL, (struct hw_common **)&display_dev); + if (r < 0) { + _E("fail to get display device structure : %d", r); + return -EPERM; + } + + _D("display device structure load success"); + return 0; +} + +int display_service_free(void) +{ + struct hw_info *info; + + if (!display_dev) + return -ENOENT; + + info = display_dev->common.info; + + assert(info); + + info->close((struct hw_common *)display_dev); + + return 0; +} + int init_sysfs(unsigned int flags) { int ret; diff --git a/src/display/device-interface.h b/src/display/device-interface.h index 59191c3..01f44ef 100644 --- a/src/display/device-interface.h +++ b/src/display/device-interface.h @@ -36,14 +36,16 @@ #define PM_DEFAULT_BRIGHTNESS 60 #define PM_LCD_POWER_ON 0 -#define PM_LCD_POWER_OFF 4 +#define PM_LCD_POWER_OFF 3 #define PM_LCD_RETRY_CNT 3 -#define STATUS_STANDBY (STATUS_ON + 1) #define DISP_INDEX_SHIFT 16 #define DISP_CMD(prop, index) ((index << DISP_INDEX_SHIFT) | prop) +#define DEFAULT_DISPLAY_COUNT 1 +#define DEFAULT_DISPLAY_MAX_BRIGHTNESS 100 + /* * Event type enumeration */ @@ -54,8 +56,10 @@ enum { EVENT_END, }; -extern int init_sysfs(unsigned int); -extern int exit_sysfs(void); +int init_sysfs(unsigned int); +int exit_sysfs(void); +int display_service_load(void); +int display_service_free(void); struct _backlight_ops { int (*off)(enum device_flags); @@ -70,6 +74,8 @@ struct _backlight_ops { int (*save_custom_brightness)(void); int (*custom_update)(void); int (*set_force_brightness)(int level); + int (*set_brightness)(int val); + int (*get_brightness)(int *val); }; struct _power_ops { diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 2068e67..fedddda 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -330,12 +330,9 @@ static DBusMessage *edbus_getdisplaycount(E_DBus_Object *obj, DBusMessage *msg) { DBusMessageIter iter; DBusMessage *reply; - int cmd, cnt, ret; + int ret; - cmd = DISP_CMD(PROP_DISPLAY_DISPLAY_COUNT, DEFAULT_DISPLAY); - ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &cnt); - if (ret >= 0) - ret = cnt; + ret = DEFAULT_DISPLAY_COUNT; reply = dbus_message_new_method_return(msg); dbus_message_iter_init_append(reply, &iter); @@ -347,12 +344,9 @@ static DBusMessage *edbus_getmaxbrightness(E_DBus_Object *obj, DBusMessage *msg) { DBusMessageIter iter; DBusMessage *reply; - int cmd, brt, ret; + int ret; - cmd = DISP_CMD(PROP_DISPLAY_MAX_BRIGHTNESS, DEFAULT_DISPLAY); - ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &brt); - if (ret >= 0) - ret = brt; + ret = DEFAULT_DISPLAY_MAX_BRIGHTNESS; reply = dbus_message_new_method_return(msg); dbus_message_iter_init_append(reply, &iter); @@ -364,13 +358,9 @@ static DBusMessage *edbus_setmaxbrightness(E_DBus_Object *obj, DBusMessage *msg) { DBusMessageIter iter; DBusMessage *reply; - int cmd, brt, ret; - - dbus_message_iter_init(msg, &iter); - dbus_message_iter_get_basic(&iter, &brt); + int ret; - cmd = DISP_CMD(PROP_DISPLAY_MAX_BRIGHTNESS, DEFAULT_DISPLAY); - ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, brt); + ret = -ENOTSUP; reply = dbus_message_new_method_return(msg); dbus_message_iter_init_append(reply, &iter); @@ -382,10 +372,9 @@ static DBusMessage *edbus_getbrightness(E_DBus_Object *obj, DBusMessage *msg) { DBusMessageIter iter; DBusMessage *reply; - int cmd, brt, ret; + int brt, ret; - cmd = DISP_CMD(PROP_DISPLAY_BRIGHTNESS, DEFAULT_DISPLAY); - ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &brt); + ret = backlight_ops.get_brightness(&brt); if (ret >= 0) ret = brt; @@ -401,7 +390,7 @@ static DBusMessage *edbus_setbrightness(E_DBus_Object *obj, DBusMessage *msg) { DBusMessageIter iter; DBusMessage *reply; - int cmd, brt, autobrt, ret, caps; + int brt, autobrt, ret, caps; caps = display_get_caps(DISPLAY_ACTOR_API); @@ -431,8 +420,7 @@ static DBusMessage *edbus_setbrightness(E_DBus_Object *obj, DBusMessage *msg) goto error; } - cmd = DISP_CMD(PROP_DISPLAY_BRIGHTNESS, DEFAULT_DISPLAY); - ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, brt); + ret = backlight_ops.set_brightness(brt); if (ret < 0) goto error; if (vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt) != 0) @@ -454,7 +442,7 @@ static DBusMessage *edbus_holdbrightness(E_DBus_Object *obj, DBusMessage *msg) { DBusMessageIter iter; DBusMessage *reply; - int cmd, brt, autobrt, ret, caps; + int brt, autobrt, ret, caps; caps = display_get_caps(DISPLAY_ACTOR_API); @@ -480,8 +468,7 @@ static DBusMessage *edbus_holdbrightness(E_DBus_Object *obj, DBusMessage *msg) vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON); - cmd = DISP_CMD(PROP_DISPLAY_BRIGHTNESS, DEFAULT_DISPLAY); - ret = device_set_property(DEVICE_TYPE_DISPLAY, cmd, brt); + ret = backlight_ops.set_brightness(brt); if (ret < 0) goto error; @@ -507,7 +494,7 @@ static DBusMessage *edbus_releasebrightness(E_DBus_Object *obj, DBusMessage *msg { DBusMessageIter iter; DBusMessage *reply; - int cmd, bat, charger, changed, setting, brt, autobrt, ret = 0; + int bat, charger, changed, setting, brt, autobrt, ret = 0; if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat) != 0) { _E("Failed to get VCONFKEY_SYSMAN_BATTERY_STATUS_LOW value"); @@ -541,8 +528,7 @@ static DBusMessage *edbus_releasebrightness(E_DBus_Object *obj, DBusMessage *msg vconf_set_int(VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, VCONFKEY_PM_CUSTOM_BRIGHTNESS_OFF); - cmd = DISP_CMD(PROP_DISPLAY_BRIGHTNESS, DEFAULT_DISPLAY); - ret = device_get_property(DEVICE_TYPE_DISPLAY, cmd, &brt); + ret = backlight_ops.get_brightness(&brt); if (ret < 0) brt = ret; @@ -551,14 +537,14 @@ static DBusMessage *edbus_releasebrightness(E_DBus_Object *obj, DBusMessage *msg charger == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED && !changed) { _D("batt warning low : brightness is not changed!"); if (brt != 0) { - device_set_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_BRIGHTNESS, 0); + backlight_ops.set_brightness(0); } goto error; } if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_OFF) { if (brt != setting) { - device_set_property(DEVICE_TYPE_DISPLAY, PROP_DISPLAY_BRIGHTNESS, setting); + backlight_ops.set_brightness(setting); if (vconf_set_int(VCONFKEY_PM_CURRENT_BRIGHTNESS, setting) != 0) { _E("Failed to set VCONFKEY_PM_CURRENT_BRIGHTNESS value"); } -- 2.7.4 From 82adf8aab74588db77a8dbc22525ca19b495db6f Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Wed, 11 Mar 2015 15:33:48 +0900 Subject: [PATCH 15/16] deviced: Update usb vconf key whenever usb is connected or not Currently, runtime-info uses VCONFKEY_SYSMAN_USB_STATUS vconf key to judge if usb is connected or not. Deviced will update the vconf key whenever usb is changed. Change-Id: I97ab2e9a7a8228fe33b14297b4c002398fd9532c Signed-off-by: Jiyoung Yun --- src/usb/usb.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/usb/usb.c b/src/usb/usb.c index 6de4bd3..44d5d2d 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -18,6 +18,7 @@ #include +#include #include "core/log.h" #include "core/list.h" @@ -137,7 +138,8 @@ static int usb_config_disable(void) static int usb_state_changed(int status) { - static int old = USB_DISCONNECTED; + static int old = -1; /* to update at the first time */ + int vconf_state; int ret; _I("USB state is changed from (%d) to (%d)", old, status); @@ -149,10 +151,15 @@ static int usb_state_changed(int status) case USB_CONNECTED: _I("USB cable is connected"); ret = usb_config_enable(); + if (ret == 0) + vconf_state = VCONFKEY_SYSMAN_USB_AVAILABLE; + else + vconf_state = VCONFKEY_SYSMAN_USB_CONNECTED; break; case USB_DISCONNECTED: _I("USB cable is disconnected"); ret = usb_config_disable(); + vconf_state = VCONFKEY_SYSMAN_USB_DISCONNECTED; break; default: _E("Invalid USB state(%d)", status); @@ -163,6 +170,7 @@ static int usb_state_changed(int status) else old = status; + vconf_set_int(VCONFKEY_SYSMAN_USB_STATUS, vconf_state); return ret; } @@ -180,7 +188,7 @@ static void usb_init(void *data) if (ret < 0) _E("Failed to initialize usb configuation"); - ret = usb_state_changed(&(extcon_usb_ops.status)); + ret = usb_state_changed(extcon_usb_ops.status); if (ret < 0) _E("Failed to update usb status(%d)", ret); } -- 2.7.4 From 8ef2d179c83065f76601343a849b8276e539481c Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Wed, 25 Mar 2015 20:57:39 +0900 Subject: [PATCH 16/16] extcon: Changed the function name easily identifiable get_extcon_uevent_state is changed to get_extcon_state_node. This function is for getting state node string. And remove the duplicated logic regarding extcon_changed() and extcon_update(). Signed-off-by: Jiyoung Yun Change-Id: Ifdd5f5f3d1a1b710d9ead02bce64d7cb7e388fdc --- src/extcon/extcon.c | 96 ++++++++++++++++++++++++++--------------------------- 1 file changed, 47 insertions(+), 49 deletions(-) diff --git a/src/extcon/extcon.c b/src/extcon/extcon.c index 030dcae..8d5479f 100755 --- a/src/extcon/extcon.c +++ b/src/extcon/extcon.c @@ -46,23 +46,6 @@ void remove_extcon(struct extcon_ops *dev) DD_LIST_REMOVE(extcon_list, dev); } -static int extcon_changed(struct extcon_ops *dev, int status) -{ - if (!dev) - return -EINVAL; - - if (dev->status == status) - return 0; - - _I("Changed %s device : %d -> %d", dev->name, dev->status, status); - - dev->status = status; - if (dev->update) - dev->update(status); - - return 0; -} - static struct extcon_ops *find_extcon(const char *name) { dd_list *l; @@ -93,7 +76,31 @@ int extcon_get_status(const char *name) return dev->status; } -static int extcon_update(const char *value) +static int extcon_update(const char *name, const char *value) +{ + struct extcon_ops *dev; + int status; + + if (!name || !value) + return -EINVAL; + + dev = find_extcon(name); + if (!dev) { + _E("fail to find matched extcon device : name(%s)", name); + return -EINVAL; + } + + status = atoi(value); + _I("Changed %s device : %d -> %d", name, dev->status, status); + + dev->status = status; + if (dev->update) + dev->update(status); + + return 0; +} + +static int extcon_parsing_value(const char *value) { char *s, *p; char name[NAME_MAX]; @@ -109,9 +116,8 @@ static int extcon_update(const char *value) break; memset(name, 0, sizeof(name)); memcpy(name, s, p-s); - dev = find_extcon(name); - if (dev) - extcon_changed(dev, atoi(p+1)); + /* name is env_name and p+1 is env_value */ + extcon_update(name, p+1); s = strchr(p, '\n'); if (!s) break; @@ -121,26 +127,34 @@ static int extcon_update(const char *value) return 0; } -static int extcon_load_uevent(struct parse_result *result, void *user_data) +static void uevent_extcon_handler(struct udev_device *dev) { - struct extcon_ops *dev; - int val; + const char *env_value; + int ret; + env_value = udev_device_get_property_value(dev, STATE_NAME); + if (!env_value) + return; + + ret = extcon_parsing_value(env_value); + if (ret < 0) + _E("fail to parse extcon value : %d", ret); +} + +static int extcon_load_uevent(struct parse_result *result, void *user_data) +{ if (!result) return 0; if (!result->name || !result->value) return 0; - val = atoi(result->value); - dev = find_extcon(result->name); - if (dev) - extcon_changed(dev, val); + extcon_update(result->name, result->value); return 0; } -static int get_extcon_uevent_state(char *state, unsigned int len) +static int get_extcon_state_node(char *state, unsigned int len) { DIR *dir; struct dirent *entry; @@ -182,22 +196,6 @@ static int get_extcon_uevent_state(char *state, unsigned int len) return ret; } -static void uevent_extcon_handler(struct udev_device *dev) -{ - const char *env_value; - int ret; - - env_value = udev_device_get_property_value(dev, STATE_NAME); - if (!env_value) - return; - - ret = extcon_update(env_value); - if (ret < 0) - _E("fail to update extcon status : %d", ret); - - return; -} - static DBusMessage *dbus_get_extcon_status(E_DBus_Object *obj, DBusMessage *msg) { @@ -276,12 +274,12 @@ static void extcon_init(void *data) if (ret < 0) _E("fail to register extcon uevent : %d", ret); - /* load extcon uevent */ - ret = get_extcon_uevent_state(state, sizeof(state)); + /* set initialize extcon device state */ + ret = get_extcon_state_node(state, sizeof(state)); if (ret == 0) { ret = config_parse(state, extcon_load_uevent, NULL); if (ret < 0) - _E("Failed to load %s file : %d", EXTCON_PATH, ret); + _E("Failed to load %s file : %d", state, ret); } else { _E("Failed to get extcon uevent state node"); } @@ -311,7 +309,7 @@ static void extcon_exit(void *data) } } -const struct device_ops extcon_device_ops = { +static const struct device_ops extcon_device_ops = { .name = "extcon", .probe = extcon_probe, .init = extcon_init, -- 2.7.4