summaryrefslogtreecommitdiff
path: root/device-manager-plugin-pinetrail.c
blob: 9f53df34a420925a921d75fd9c3d3754c0fe3d37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343

/*
 * Overview: device mananger(devman) plugin for pinetrail platform
 *
 * Copyright (c) 2000 - 2011 Intel Co., Ltd. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <devman/devman.h>
#include <devman/devman_plugin_intf.h>
#include <string.h>

#include "devlog.h"
#include "device_engine.h"

#include "device-manager-plugin-pinetrail.h"

#define BATTERY_PRESENT_PATH   		"/sys/class/power_supply/BAT1/present"
#define BATTERY_CHARGE_STATUS_PATH  "/sys/class/power_supply/BAT1/status"
#define BATTERY_CHARGE_FULL_PATH    "/sys/class/power_supply/BAT1/charge_full"
#define BATTERY_CHARGE_NOW_PATH     "/sys/class/power_supply/BAT1/charge_now"

#define BACKLIGHTNESS_MAX_PATH      "/sys/class/backlight/intel_backlight/max_brightness"
#define BACKLIGHTNESS_PATH          "/sys/class/backlight/intel_backlight/brightness"

#define WAKEUP_COUNT_PATH           "/sys/power/wakeup_count"
#define POWER_STATE_PATH            "/sys/power/state"


#define DEVIDE(_x, _y, _z)\
    if(_y)	\
{	\
    int _tmpy = _y;	\
    _z = 0;	\
    while(_x >= _tmpy)	\
    {			\
        ++_z;	\
        _tmpy += _y;	\
    }	\
}

int OEM_sys_get_backlight_max_brightness(int index, int *value)
{
    int ret = -1;

    ret = sys_get_int(BACKLIGHTNESS_MAX_PATH, value);
    DBG("path[%s]value[%d]", BACKLIGHTNESS_MAX_PATH, *value);
    return ret;
}

int OEM_sys_get_backlight_brightness(int index, int *value)
{
    int ret = -1;

    ret = sys_get_int(BACKLIGHTNESS_PATH, value);
    DBG("path[%s]value[%d]", BACKLIGHTNESS_PATH, *value);

    return ret;
}

int OEM_sys_set_backlight_brightness(int index, int value)
{
    int ret = -1;

    ret = sys_set_int(BACKLIGHTNESS_PATH, value);
    DBG("path[%s]value[%d]", BACKLIGHTNESS_PATH, value);

    return ret;
}

int OEM_sys_get_power_wakeup_count(int *value)
{
    int ret = -1;

    ret = sys_get_int(WAKEUP_COUNT_PATH, value);
    /*
     * Fix me: with the below format output, we always run into
     * SEGFAULT if *value != 0, it may from overflow/out of binds
     * type issue.
     */
    //DBG("path[%s], value[%d], line[%d]", WAKEUP_COUNT_PATH, *value, __LINE__);

    return ret;
}

int OEM_sys_set_power_wakeup_count(int value)
{
    int ret = -1;

    ret = sys_set_int(WAKEUP_COUNT_PATH, value);
    DBG("path[%s]value[%d]", WAKEUP_COUNT_PATH, value);

    return ret;
}

int OEM_sys_set_power_state(int value)
{
    int ret = -1;

    if(POWER_STATE_SUSPEND == value)
        ret = sys_set_str(POWER_STATE_PATH, "mem");
    DBG("path[%s], value[%d]", POWER_STATE_PATH, value);

    return ret;
}

int OEM_sys_get_battery_present(int *value)
{
    int ret = -1;

    ret = sys_get_int(BATTERY_PRESENT_PATH, value);
    DBG("path[%s], value[%d]", BATTERY_PRESENT_PATH, *value);

    return ret;
}


int OEM_sys_get_battery_capacity(int *value)
{
    int ret = -1;
    static int charge_full = 0;
    static int unit = 0;
    int charge_now;
    int capacity = 0;

    if(charge_full == 0)
    {
        ret = sys_get_int(BATTERY_CHARGE_FULL_PATH, &charge_full);
        if(ret != 0)
        {
            ERR("get battery charge full error!");
            charge_full = 0;
            return -1;
        }
        DEVIDE(charge_full, 100, unit);
    }

    ret = sys_get_int(BATTERY_CHARGE_NOW_PATH, &charge_now);
    if(ret != 0)
    {
        ERR("get battery charge now error!");
        return -1;
    }

    DEVIDE(charge_now, unit, capacity);
    *value = capacity;
    DBG("battery capacity value[%d]", *value);

    return 0;
}


int OEM_sys_get_battery_charge_full(int *value)
{
    int capacity = 0;

    if(OEM_sys_get_battery_capacity(&capacity) < 0){
        DBG("OEM_sys_get_battery_capacity failed");
        return -1;
    }else{
        if(capacity == 100){
            *value = 1;
        }else{
            *value = 0;
        }
    }

    DBG("func[%s]value[%d]", __func__, *value);

    return 0;
}

int OEM_sys_get_battery_charge_now(int *value)
{
    char* buf = NULL;
    int ret = -1;
    int len = strlen("Charging\n");

    buf = sys_get_str(BATTERY_CHARGE_STATUS_PATH);

    if(buf){
        if(0 == strncmp(buf, "Charging\n", len )){
            *value = 1;
        }else{
            *value = 0;
        }
        DBG("path[%s]value[%d]", BATTERY_CHARGE_STATUS_PATH, *value);

        free(buf);
        ret = 0;
    }

    return ret;
}

int OEM_sys_get_null_1(int *value)
{
    int ret = -1;
    ERR("this interface is not implemented");

    return ret;
}

int OEM_sys_set_null_1(int value)
{
    int ret = -1;
    ERR("this interface is not implemented");

    return ret;
}


int OEM_sys_get_null_2(int index, int *value)
{
    int ret = -1;
    ERR("this interface is not implemented");

    return ret;

}

int OEM_sys_set_null_2(int index, int value)
{
    int ret = -1;
    ERR("this interface is not implemented");

    return ret;

}


int OEM_sys_get_null_3(char *node)
{
    int ret = -1;
    ERR("this interface is not implemented");

    return ret;

}


/*  devman_plugin_interface_sampledevice is the structure of the type
 *  OEM_sys_devman_plugin_interface in which OEM API’s which are implemented are
 *  defined */

static const OEM_sys_devman_plugin_interface  devman_plugin_interface_pinetrail = {
    OEM_sys_get_null_1, //int        (*OEM_sys_get_display_count) (int *value);

    OEM_sys_get_backlight_max_brightness, //int        (*OEM_sys_get_backlight_max_brightness) (int index, int *value);
    OEM_sys_get_backlight_brightness, //int        (*OEM_sys_get_backlight_brightness) (int index, int *value);
    OEM_sys_set_backlight_brightness, //int        (*OEM_sys_set_backlight_brightness) (int index, int value);

    OEM_sys_get_null_2, //int        (*OEM_sys_get_backlight_acl_control) (int index, int *value);
    OEM_sys_set_null_2, //int        (*OEM_sys_set_backlight_acl_control) (int index, int value);

    OEM_sys_get_null_2, //int        (*OEM_sys_get_lcd_power) (int index, int *value);
    OEM_sys_set_null_2, //int        (*OEM_sys_set_lcd_power) (int index, int value);

    OEM_sys_get_null_1, //int        (*OEM_sys_get_image_enhance_mode) (int *value);
    OEM_sys_set_null_1, //int        (*OEM_sys_set_image_enhance_mode) (int value);
    OEM_sys_get_null_1, //int        (*OEM_sys_get_image_enhance_scenario) (int *value);
    OEM_sys_set_null_1, //int        (*OEM_sys_set_image_enhance_scenario) (int value);
    OEM_sys_get_null_1, //int        (*OEM_sys_get_image_enhance_tone) (int *value);
    OEM_sys_set_null_1, //int        (*OEM_sys_set_image_enhance_tone) (int value);
    OEM_sys_get_null_1, //int        (*OEM_sys_get_image_enhance_outdoor) (int *value);
    OEM_sys_set_null_1, //int        (*OEM_sys_set_image_enhance_outdoor) (int value);

    OEM_sys_get_null_1, //int        (*OEM_sys_get_image_enhance_tune) (int *value);
    OEM_sys_set_null_1, //int        (*OEM_sys_set_image_enhance_tune) (int value);

    OEM_sys_get_null_1, //int        (*OEM_sys_get_uart_path) (int *value);
    OEM_sys_set_null_1, //int        (*OEM_sys_set_uart_path) (int value);

    OEM_sys_get_null_1, //int        (*OEM_sys_get_usb_path) (int *value);
    OEM_sys_set_null_1, //int        (*OEM_sys_set_usb_path) (int value);

    OEM_sys_get_null_1, //int        (*OEM_sys_get_haptic_vibetones_level_max) (int *value);
    OEM_sys_get_null_1, //int        (*OEM_sys_get_haptic_vibetones_level) (int *value);
    OEM_sys_set_null_1, //int        (*OEM_sys_set_haptic_vibetones_level) (int value);
    OEM_sys_set_null_1, //int        (*OEM_sys_set_haptic_vibetones_enable) (int value);
    OEM_sys_set_null_1, //int        (*OEM_sys_set_haptic_vibetones_oneshot) (int value);

    OEM_sys_get_battery_capacity, //int     (*OEM_sys_get_battery_capacity) (int *value);
    OEM_sys_get_battery_charge_full, //int        (*OEM_sys_get_battery_charge_full) (int *value);
    OEM_sys_get_battery_charge_now, //int        (*OEM_sys_get_battery_charge_now) (int *value);
    OEM_sys_get_battery_present, //int      (*OEM_sys_get_battery_present) (int *value);
    OEM_sys_get_null_1, //int        (*OEM_sys_get_battery_health) (int *value);

    OEM_sys_get_null_1, //int        (*OEM_sys_get_jack_charger_online) (int *value);
    OEM_sys_get_null_1, //int        (*OEM_sys_get_jack_earjack_online) (int *value);
    OEM_sys_get_null_1, //int        (*OEM_sys_get_jack_earkey_online) (int *value);
    OEM_sys_get_null_1, //int        (*OEM_sys_get_jack_hdmi_online) (int *value);
    OEM_sys_get_null_1, //int        (*OEM_sys_get_jack_usb_online) (int *value);
    OEM_sys_get_null_1, //int        (*OEM_sys_get_jack_cradle_online) (int *value);
    OEM_sys_get_null_1, //int        (*OEM_sys_get_jack_tvout_online) (int *value);
    OEM_sys_get_null_1, //int        (*OEM_sys_get_jack_keyboard_online) (int *value);

    OEM_sys_get_null_1, //int        (*OEM_sys_get_leds_torch_max_brightness) (int *value);
    OEM_sys_get_null_1, //int        (*OEM_sys_get_leds_torch_brightness) (int *value);
    OEM_sys_set_null_1, //int        (*OEM_sys_set_leds_torch_brightness) (int value);

    OEM_sys_set_power_state, //int        (*OEM_sys_set_power_state) (int value);

    OEM_sys_get_power_wakeup_count, //int        (*OEM_sys_get_power_wakeup_count) (int *value);
    OEM_sys_set_power_wakeup_count, //int        (*OEM_sys_set_power_wakeup_count) (int value);

    OEM_sys_get_null_3, //int        (*OEM_sys_get_memnotify_node) (char *node);
    OEM_sys_get_null_1, //int        (*OEM_sys_get_memnotify_victim_task) (int *value);
    OEM_sys_set_null_1, //int        (*OEM_sys_set_memnotify_threshold_lv1) (int value);
    OEM_sys_set_null_1, //int        (*OEM_sys_set_memnotify_threshold_lv2) (int value);

    OEM_sys_get_null_3, //int        (*OEM_sys_get_process_monitor_node) (char *node);
    OEM_sys_set_null_1, //int        (*OEM_sys_set_process_monitor_mp_pnp) (int value);
    OEM_sys_set_null_1, //int        (*OEM_sys_set_process_monitor_mp_vip) (int value);

    OEM_sys_get_null_1, //int        (*OEM_sys_get_cpufreq_cpuinfo_max_freq) (int *value);
    OEM_sys_get_null_1, //int        (*OEM_sys_get_cpufreq_cpuinfo_min_freq) (int *value);
    OEM_sys_get_null_1, //int        (*OEM_sys_get_cpufreq_scaling_max_freq) (int *value);
    OEM_sys_set_null_1, //int        (*OEM_sys_set_cpufreq_scaling_max_freq) (int value);
    OEM_sys_get_null_1, //int        (*OEM_sys_get_cpufreq_scaling_min_freq) (int *value);
    OEM_sys_set_null_1, //int        (*OEM_sys_set_cpufreq_scaling_min_freq) (int value);
};

/*  The following code returns  the address  of the structure
 *  devman_plugin_interface_sampledevice  as defined above*/

const OEM_sys_devman_plugin_interface *OEM_sys_get_devman_plugin_interface()
{

    return &devman_plugin_interface_pinetrail;
}