tizen 2.3 release
[framework/system/deviced.git] / src / touch / touch.c
1 /*
2  * Touch
3  *
4  * Copyright (c) 2013 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 <glib.h>
20 #include <stdio.h>
21 #include <vconf.h>
22
23 #include "touch.h"
24 #include "touch-controller.h"
25
26 #include "core/devices.h"
27 #include "core/common.h"
28
29 void touch_boost_enable(struct touch_control *touch_control,
30                 enum touch_type type, enum touch_boost_state state)
31 {
32         if (!touch_control)
33                 return;
34
35         switch (state) {
36         case TOUCH_BOOST_ON:
37                 touch_control->mask |= (1 << type);
38                 break;
39         case TOUCH_BOOST_OFF:
40                 touch_control->mask &= ~(1 << type);
41                 break;
42         default:
43                 _E("Unknow touch boost state");
44                 return;
45         }
46
47         /*
48          * Touch should update touch_control->cur_state after updating
49          * touch_control->mask variable because Touch need what some module
50          * turn on/off touch boost feature.
51          */
52         if (touch_control->cur_state == state)
53                 return;
54
55         switch (type) {
56         case TOUCH_TYPE_VCONF_SIP:
57                 set_cpufreq_touch_boost_off(state);
58                 break;
59         default:
60                 _E("Unknow touch type");
61                 return;
62         }
63
64         touch_control->cur_state = state;
65
66         _I("Touch Boost is %s", state == TOUCH_BOOST_ON ? "ON" : "OFF");
67 }
68
69 /* Define global variable of struct touch_control */
70 static struct touch_control touch_control;
71
72 static int touch_stop(enum device_flags flags)
73 {
74         /* Restore touch boost state as ON state */
75         set_cpufreq_touch_boost_off(TOUCH_BOOST_ON);
76
77         touch_controller_stop();
78
79         _I("Stop Touch");
80
81         return 0;
82 }
83
84 static int touch_start(enum device_flags flags)
85 {
86         int i;
87
88         /* Touch Boost is default on state */
89         touch_control.cur_state = TOUCH_BOOST_ON;
90
91         for (i = 0; i < TOUCH_TYPE_MAX; i++)
92                 touch_control.mask |= (1 << i);
93
94         touch_controller_start();
95
96         _I("Start Touch");
97
98         return 0;
99 }
100
101 /*
102  * touch_init - Initialize Touch module
103  */
104 static void touch_init(void *data)
105 {
106         touch_controller_init(&touch_control);
107 }
108
109 /*
110  * touch_exit - Exit Touch module
111  */
112 static void touch_exit(void *data)
113 {
114         touch_controller_exit();
115 }
116
117 static const struct device_ops touch_device_ops = {
118         .priority = DEVICE_PRIORITY_NORMAL,
119         .name     = "touch",
120         .init     = touch_init,
121         .exit     = touch_exit,
122         .start    = touch_start,
123         .stop     = touch_stop,
124 };
125
126 DEVICE_OPS_REGISTER(&touch_device_ops)