Initialize Tizen 2.3
[framework/system/deviced.git] / src / ta / ta-handler.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
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
20 #include <vconf.h>
21 #include <device-node.h>
22
23 #include "core/log.h"
24 #include "core/data.h"
25 #include "core/devices.h"
26 #include "display/poll.h"
27 #include "core/common.h"
28
29 #define RETRY   3
30
31 enum ta_connect_status{
32         TA_OFFLINE = 0,
33         TA_ONLINE = 1,
34 };
35
36 static int __check_insuspend_charging(void)
37 {
38         int val, ret;
39
40         ret = device_get_property(DEVICE_TYPE_POWER, PROP_POWER_INSUSPEND_CHARGING_SUPPORT, &val);
41         if (ret != 0)
42                 val = 0;
43         if (val == 0)
44                 ret = pm_lock_internal(INTERNAL_LOCK_TA, LCD_OFF, STAY_CUR_STATE, 0);
45         else
46                 ret = 0;
47         return ret;
48 }
49
50 static void ta_init(void *data)
51 {
52         int val, i = 0;
53         int ret;
54
55         if (device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_TA_ONLINE, &val) != 0)
56                 val = -EINVAL;
57
58         if (val == TA_ONLINE) {
59                 vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS,
60                                 VCONFKEY_SYSMAN_CHARGER_CONNECTED);
61                 while (i < RETRY
62                            && __check_insuspend_charging() == -1) {
63                         i++;
64                         sleep(1);
65                 }
66         } else if (val == TA_OFFLINE) {
67                 vconf_set_int(VCONFKEY_SYSMAN_CHARGER_STATUS,
68                                 VCONFKEY_SYSMAN_CHARGER_DISCONNECTED);
69         }
70 }
71
72 static const struct device_ops ta_device_ops = {
73         .priority = DEVICE_PRIORITY_NORMAL,
74         .name     = "ta",
75         .init     = ta_init,
76 };
77
78 DEVICE_OPS_REGISTER(&ta_device_ops)