/* * 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 #include #include #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 power_saving) { 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 power_saving) { 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_null_2, //int (*OEM_sys_get_backlight_min_brightness) (int index, 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, int power_saving); OEM_sys_set_backlight_brightness, //int (*OEM_sys_set_backlight_brightness) (int index, int value, int power_saving); OEM_sys_get_null_2, //int (*OEM_sys_set_backlight_dimming) (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_image_enhance_info) (int *value); OEM_sys_set_null_1, //int (*OEM_sys_set_display_frame_rate) (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_null_1, //int (*OEM_sys_get_battery_capacity_raw) (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_battery_polling_required) (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; }