tizen 2.3 release
[framework/system/deviced.git] / src / touch / touchscreen.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19 #include "core/devices.h"
20 #include "core/common.h"
21 #include "core/log.h"
22
23 #define TOUCH_ON        1
24 #define TOUCH_OFF       0
25
26 static char *touchscreen_node;
27
28 /*
29  * touchscreen_init - Initialize Touchscreen module
30  */
31 static void touchscreen_init(void *data)
32 {
33         if (touchscreen_node)
34                 return;
35
36         touchscreen_node = getenv("PM_TOUCHSCREEN");
37         _D("touchscreen node : %s", touchscreen_node);
38 }
39
40 static int touchscreen_start(enum device_flags flags)
41 {
42         int ret;
43
44         touchscreen_init((void *)NORMAL_MODE);
45         if (!touchscreen_node)
46                 return -ENOENT;
47
48         if (flags & TOUCH_SCREEN_OFF_MODE)
49                 return 0;
50
51         ret = sys_set_int(touchscreen_node, TOUCH_ON);
52         if (ret < 0)
53                 _E("Failed to on touch screen!");
54
55         return ret;
56 }
57
58 static int touchscreen_stop(enum device_flags flags)
59 {
60         int ret;
61
62         touchscreen_init((void *)NORMAL_MODE);
63         if (!touchscreen_node)
64                 return -ENOENT;
65
66         if (flags & AMBIENT_MODE)
67                 return 0;
68
69         ret = sys_set_int(touchscreen_node, TOUCH_OFF);
70         if (ret < 0)
71                 _E("Failed to off touch screen!");
72
73         return ret;
74 }
75
76 static const struct device_ops touchscreen_device_ops = {
77         .priority = DEVICE_PRIORITY_NORMAL,
78         .name     = "touchscreen",
79         .init     = touchscreen_init,
80         .start    = touchscreen_start,
81         .stop     = touchscreen_stop,
82 };
83
84 DEVICE_OPS_REGISTER(&touchscreen_device_ops)
85