From 4539efcd6b86ba885c7993bda14d745411269b0e Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 5 Aug 2022 04:47:39 +0900 Subject: power-emulator: Add battery hal information Change-Id: If31c5d2254adcd4800e72ea404e5ec00b410fdd6 Signed-off-by: Chanwoo Choi --- scripts/pass.json | 4 ++++ src/hal-backend-power.c | 34 ++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/scripts/pass.json b/scripts/pass.json index 6178d54..557f286 100644 --- a/scripts/pass.json +++ b/scripts/pass.json @@ -21,6 +21,10 @@ "device_type" : "disk", "device_name" : "vda", "device_config_path" : "/hal/etc/pass/pass-dummy.json" + }, { + "device_type" : "battery", + "device_name" : "battery", + "device_config_path" : "/hal/etc/pass/pass-dummy.json" } ] } diff --git a/src/hal-backend-power.c b/src/hal-backend-power.c index 2a9bd7f..ce7606f 100644 --- a/src/hal-backend-power.c +++ b/src/hal-backend-power.c @@ -470,6 +470,7 @@ static int power_init(void **data) struct pass_resource_bus *bus = NULL; struct pass_resource_gpu *gpu = NULL; struct pass_resource_memory *memory = NULL; + struct pass_resource_battery *battery = NULL; int ret; /* Allocate memory */ @@ -501,6 +502,12 @@ static int power_init(void **data) goto err_gpu; } + battery = calloc(1, sizeof(struct pass_resource_battery)); + if (!battery) { + ret = -ENOMEM; + goto err_memory; + } + /* Initialize each h/w resource */ cpu->dvfs = cpufreq_dvfs_ops; cpu->hotplug = cpu_hotplus_ops; @@ -512,6 +519,8 @@ static int power_init(void **data) gpu->dvfs = gpu_dvfs_ops; gpu->tmu = tmu_ops; + battery->tmu = tmu_ops; + memory->get_fault_around_bytes = memory_get_fault_around_bytes; memory->set_fault_around_bytes = memory_set_fault_around_bytes; @@ -520,20 +529,20 @@ static int power_init(void **data) power_funcs->bus = bus; power_funcs->gpu = gpu; power_funcs->memory = memory; + power_funcs->battery = battery; *data = (void *)power_funcs; return 0; +err_memory: + free(memory); err_gpu: - if (gpu) - free(gpu); + free(gpu); err_bus: - if (bus) - free(bus); + free(bus); err_cpu: - if (cpu) - free(cpu); + free(cpu); err_funcs: free(power_funcs); @@ -549,14 +558,11 @@ static int power_exit(void *data) funcs = (hal_backend_power_funcs *)data; - if (funcs->cpu) - free(funcs->cpu); - if (funcs->bus) - free(funcs->bus); - if (funcs->gpu) - free(funcs->gpu); - if (funcs->memory) - free(funcs->memory); + free(funcs->cpu); + free(funcs->bus); + free(funcs->gpu); + free(funcs->memory); + free(funcs->battery); free(funcs); -- cgit v1.2.3