From 33404cf65e730398c4bb97e32d26452a6e895d0a Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Fri, 13 Feb 2015 13:59:06 +0900 Subject: [PATCH] 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