4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
26 #include <sys/types.h>
30 #include <device-node.h>
34 #include "core/common.h"
35 #include "core/devices.h"
36 #include "core/device-notifier.h"
37 #include "core/edbus-handler.h"
38 #include "hall-handler.h"
40 #define SIGNAL_HALL_STATE "ChangeState"
41 #define HALL_PMQOS_TIME 1000 //ms
42 enum hall_ic_init_type{
43 HALL_IC_NOT_READY = 0,
44 HALL_IC_INITIALIZED = 1,
47 static int hall_ic_status = HALL_IC_OPENED;
48 static int hall_ic_initialized = HALL_IC_NOT_READY;
50 static int hall_ic_get_status(void)
53 int val = HALL_IC_OPENED;
55 if (hall_ic_initialized == HALL_IC_INITIALIZED)
56 return hall_ic_status;
58 ret = device_get_property(DEVICE_TYPE_HALL, PROP_HALL_STATUS, &val);
59 if (ret == 0 && (val == HALL_IC_OPENED || val == HALL_IC_CLOSED))
62 return hall_ic_status;
65 static void hall_ic_chgdet_cb(void)
73 fd = open(HALL_IC_STATUS, O_RDONLY);
75 _E("%s open error: %s", HALL_IC_STATUS, strerror(errno));
81 _E("fail to get hall status %d", r);
87 hall_ic_initialized = HALL_IC_INITIALIZED;
90 if (val != HALL_IC_OPENED && val != HALL_IC_CLOSED)
94 _I("cover is opened(%d)", hall_ic_status);
96 device_notify(DEVICE_NOTIFIER_HALLIC_OPEN, (void *)hall_ic_status);
98 snprintf(str_status, sizeof(str_status), "%d", hall_ic_status);
101 broadcast_edbus_signal(DEVICED_PATH_HALL, DEVICED_INTERFACE_HALL,
102 SIGNAL_HALL_STATE, "i", arr);
104 /* Set touch screen flip mode when cover is closed */
105 ret = device_set_property(DEVICE_TYPE_TOUCH,
106 PROP_TOUCH_SCREEN_FLIP_MODE, (hall_ic_status ? 0 : 1));
108 _E("Failed to set touch screen flip mode!");
110 /* Set touch key flip mode when cover is closed */
111 ret = device_set_property(DEVICE_TYPE_TOUCH,
112 PROP_TOUCH_KEY_FLIP_MODE, (hall_ic_status ? 0 : 1));
114 _E("Failed to set touch key flip mode!");
118 static void hall_edbus_signal_handler(void *data, DBusMessage *msg)
120 _D("hall_edbus_signal_handler occurs!!!");
123 static DBusMessage *edbus_getstatus_cb(E_DBus_Object *obj, DBusMessage *msg)
125 DBusMessageIter iter;
129 val = hall_ic_get_status();
130 _D("get hall status %d", val);
131 reply = dbus_message_new_method_return(msg);
132 dbus_message_iter_init_append(reply, &iter);
133 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &val);
137 static const struct edbus_method edbus_methods[] = {
138 { "getstatus", NULL, "i", edbus_getstatus_cb },
139 /* Add methods here */
142 static void hall_ic_init(void *data)
146 /* init dbus interface */
147 ret = register_edbus_method(DEVICED_PATH_HALL, edbus_methods, ARRAY_SIZE(edbus_methods));
149 _E("fail to init edbus method(%d)", ret);
151 register_edbus_signal_handler(DEVICED_PATH_HALL, DEVICED_INTERFACE_HALL,
153 hall_edbus_signal_handler);
154 val = hall_ic_get_status();
155 _D("get hall status %d", val);
158 static int hall_ic_execute(void *data)
160 device_notify(DEVICE_NOTIFIER_PMQOS_HALL, (void*)HALL_PMQOS_TIME);
165 static const struct device_ops hall_device_ops = {
166 .priority = DEVICE_PRIORITY_NORMAL,
167 .name = HALL_IC_NAME,
168 .init = hall_ic_init,
169 .status = hall_ic_get_status,
170 .execute = hall_ic_execute,
173 DEVICE_OPS_REGISTER(&hall_device_ops)