Commit 7c251a8a authored by peturbg's avatar peturbg
Browse files
parent c0f72d53
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -12,18 +12,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

LOCAL_PATH := $(call my-dir)

LOCAL_PATH:= $(call my-dir)
# HAL module implemenation, not prelinked and stored in
# hw/<COPYPIX_HARDWARE_MODULE_ID>.<ro.board.platform>.so
include $(CLEAR_VARS)

LOCAL_MODULE := power.$(TARGET_BOARD_PLATFORM)
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := power.c
LOCAL_SHARED_LIBRARIES := liblog

LOCAL_MODULE_TAGS := optional
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE_RELATIVE_PATH := hw

ifneq ($(TARGET_TAP_TO_WAKE_NODE),)
  LOCAL_CFLAGS += -DTAP_TO_WAKE_NODE=\"$(TARGET_TAP_TO_WAKE_NODE)\"
endif
LOCAL_SHARED_LIBRARIES := liblog

LOCAL_MODULE := power.$(TARGET_BOARD_PLATFORM)
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_OWNER := mtk

include $(BUILD_SHARED_LIBRARY)
include $(MTK_SHARED_LIBRARY)
 No newline at end of file
+131 −0
Original line number Diff line number Diff line
@@ -15,87 +15,102 @@
 */
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define LOG_TAG "PowerHAL"
#define LOG_TAG "MTKPowerHAL"
#include <utils/Log.h>

#include <hardware/hardware.h>
#include <hardware/power.h>

#define MT_RUSH_BOOST_PATH "/proc/hps/rush_boost_enabled"
#define MT_FPS_UPPER_BOUND_PATH "/d/ged/hal/fps_upper_bound"


#define POWER_HINT_POWER_SAVING 0x00000101
#define POWER_HINT_PERFORMANCE_BOOST 0x00000102
#define POWER_HINT_BALANCE  0x00000103

static void power_init(struct power_module *module)
{
	if(module)
    	ALOGI("power_init");
}

static void power_set_interactive(struct power_module *module, int on)
{
	if(module)
    	ALOGI("power_set_interactive on:%d", on);
}

static void power_fwrite(const char *path, char *s)
static void power_set_feature(struct power_module *module, feature_t feature, int state)
{
    char buf[64];
    int len;
    int fd = open(path, O_WRONLY);

    if (fd < 0) {
        strerror_r(errno, buf, sizeof(buf));
        ALOGE("Error opening %s: %s\n", path, buf);
        return;
    }

    len = write(fd, s, strlen(s));
    if (len < 0) {
        strerror_r(errno, buf, sizeof(buf));
        ALOGE("Error writing to %s: %s\n", path, buf);
    }

    close(fd);
	if(module)
	ALOGI("power_set_feature feature:%d, state:%d", feature, state);
}

static void power_hint(struct power_module *module, power_hint_t hint,
                       void *data) {

    int param = 0;

    if(data)
	param = *((int *)data);

    switch (hint) {
        case POWER_HINT_LOW_POWER:
            if (data) {
                power_fwrite(MT_FPS_UPPER_BOUND_PATH, "30");
                power_fwrite(MT_RUSH_BOOST_PATH, "0");
            } else {
                power_fwrite(MT_FPS_UPPER_BOUND_PATH, "60");
                power_fwrite(MT_RUSH_BOOST_PATH, "1");
            }
            ALOGI("POWER_HINT_LOW_POWER");
            break;
        case POWER_HINT_VSYNC:
        case POWER_HINT_INTERACTION:
        case POWER_HINT_CPU_BOOST:
        case POWER_HINT_LAUNCH:
        case POWER_HINT_SET_PROFILE:
        case POWER_HINT_VIDEO_ENCODE:
        case POWER_HINT_VIDEO_DECODE:
        break;
        case POWER_HINT_SUSTAINED_PERFORMANCE:
            ALOGI("POWER_HINT_SUSTAINED_PERFORMANCE");
			if(module) {
				if(param)
            		ALOGI("POWER_HINT_SUSTAINED_PERFORMANCE, on");
				else
					ALOGI("POWER_HINT_SUSTAINED_PERFORMANCE, off");
			}
            break;
        case POWER_HINT_VR_MODE:
            ALOGI("POWER_HINT_VR_MODE");
			if(module) {
				if(param)
            		ALOGI("POWER_HINT_VR_MODE, on");
				else
					ALOGI("POWER_HINT_VR_MODE, off");
			}
            break;
        default:
             break;
    }
}

static int power_open(const hw_module_t* module, const char* name,
                    hw_device_t** device)
{
	if(module)
    	ALOGI("%s: enter; name=%s", __FUNCTION__, name);
    int retval = 0; /* 0 is ok; -1 is error */

    if (strcmp(name, POWER_HARDWARE_MODULE_ID) == 0) {
        power_module_t *dev = (power_module_t *)calloc(1,
                sizeof(power_module_t));

        if (dev) {
            /* Common hw_device_t fields */
            dev->common.tag = HARDWARE_DEVICE_TAG;
            dev->common.module_api_version = POWER_MODULE_API_VERSION_0_2;
            dev->common.hal_api_version = HARDWARE_HAL_API_VERSION;

            dev->init = power_init;
            dev->powerHint = power_hint;
            dev->setInteractive = power_set_interactive;
            dev->get_number_of_platform_modes = NULL;
            dev->get_platform_low_power_stats = NULL;
            dev->get_voter_list = NULL;

            *device = (hw_device_t*)dev;
        } else
            retval = -ENOMEM;
    } else {
        retval = -EINVAL;
    }

    ALOGD("%s: exit %d", __FUNCTION__, retval);
    return retval;
}

static struct hw_module_methods_t power_module_methods = {
    .open = NULL,
    .open = power_open,
};

struct power_module HAL_MODULE_INFO_SYM = {
@@ -111,5 +126,6 @@ struct power_module HAL_MODULE_INFO_SYM = {

    .init = power_init,
    .setInteractive = power_set_interactive,
    .setFeature = power_set_feature,
    .powerHint = power_hint,
};