return 0;
}
-static struct pass_resource_dvfs_ops *get_dvfs(hal_backend_power_funcs *funcs,
- int res_type)
+static int get_dvfs(hal_backend_power_funcs *funcs, int res_type, char *res_name,
+ struct pass_resource_dvfs_ops **dvfs)
{
- struct pass_resource_dvfs_ops *dvfs = NULL;
+ if (!funcs)
+ return -ENOTSUP;
+ else if (!res_name)
+ return -EINVAL;
switch (res_type) {
case PASS_RESOURCE_CPU_ID:
if (funcs && funcs->cpu)
- dvfs = &(funcs->cpu->dvfs);
+ *dvfs = &(funcs->cpu->dvfs);
break;
case PASS_RESOURCE_BUS_ID:
if (funcs && funcs->bus)
- dvfs = &(funcs->bus->dvfs);
+ *dvfs = &(funcs->bus->dvfs);
break;
case PASS_RESOURCE_GPU_ID:
if (funcs && funcs->gpu)
- dvfs = &(funcs->gpu->dvfs);
+ *dvfs = &(funcs->gpu->dvfs);
break;
+ default:
+ return -EPERM;
}
- return dvfs;
+ return 0;
}
-static struct pass_resource_tmu_ops *get_tmu(hal_backend_power_funcs *funcs,
- int res_type)
+static int get_tmu(hal_backend_power_funcs *funcs, int res_type, char *res_name,
+ struct pass_resource_tmu_ops **tmu)
{
- struct pass_resource_tmu_ops *tmu = NULL;
+ if (!funcs)
+ return -ENOTSUP;
+ else if (!res_name)
+ return -EINVAL;
switch (res_type) {
case PASS_RESOURCE_CPU_ID:
if (funcs && funcs->cpu)
- tmu = &(funcs->cpu->tmu);
+ *tmu = &(funcs->cpu->tmu);
break;
case PASS_RESOURCE_BUS_ID:
if (funcs && funcs->bus)
- tmu = &(funcs->bus->tmu);
+ *tmu = &(funcs->bus->tmu);
break;
case PASS_RESOURCE_GPU_ID:
if (funcs && funcs->gpu)
- tmu = &(funcs->gpu->tmu);
+ *tmu = &(funcs->gpu->tmu);
break;
case PASS_RESOURCE_BATTERY_ID:
if (funcs && funcs->battery)
- tmu = &(funcs->battery->tmu);
+ *tmu = &(funcs->battery->tmu);
break;
case PASS_RESOURCE_NONSTANDARD_ID:
if (funcs && funcs->nonstandard)
- tmu = &(funcs->nonstandard->tmu);
+ *tmu = &(funcs->nonstandard->tmu);
break;
+ default:
+ return -EPERM;
}
- return tmu;
+ return 0;
}
-static struct pass_resource_hotplug_ops *get_hotplug(hal_backend_power_funcs *funcs,
- int res_type)
+static int get_hotplug(hal_backend_power_funcs *funcs, int res_type, char *res_name,
+ struct pass_resource_hotplug_ops **hotplug)
{
- struct pass_resource_hotplug_ops *hotplug = NULL;
+ if (!funcs)
+ return -ENOTSUP;
+ else if (!res_name)
+ return -EINVAL;
switch (res_type) {
case PASS_RESOURCE_CPU_ID:
if (funcs && funcs->cpu)
- hotplug = &(funcs->cpu->hotplug);
+ *hotplug = &(funcs->cpu->hotplug);
break;
+ default:
+ return -EPERM;
}
- return hotplug;
+ return 0;
}
-static struct pass_resource_battery_ops *get_charging(hal_backend_power_funcs *funcs,
- int res_type)
+static int get_charging(hal_backend_power_funcs *funcs, int res_type, char *res_name,
+ struct pass_resource_battery_ops **charging)
{
- struct pass_resource_battery_ops *charging = NULL;
+ if (!funcs)
+ return -ENOTSUP;
+ else if (!res_name)
+ return -EINVAL;
switch (res_type) {
case PASS_RESOURCE_BATTERY_ID:
if (funcs && funcs->battery)
- charging = &(funcs->battery->battery);
+ *charging = &(funcs->battery->battery);
break;
case PASS_RESOURCE_NONSTANDARD_ID:
if (funcs && funcs->nonstandard)
- charging = &(funcs->nonstandard->battery);
+ *charging = &(funcs->nonstandard->battery);
break;
+ default:
+ return -EPERM;
}
- return charging;
+ return 0;
}
EXPORT int hal_power_get_backend(unsigned int res_type)
return 0;
}
-static int is_valid_param(char *res_name)
-{
- if (!g_power_funcs)
- return -ENOTSUP;
- else if (!res_name)
- return -EINVAL;
- return 0;
-}
-
static int is_valid_param_with_str(char *res_name, char *str)
{
if (!g_power_funcs)
struct pass_resource_dvfs_ops *dvfs;
int ret;
- ret = is_valid_param_with_str(res_name, governor);
- if (ret < 0)
- return ret;
+ if (!governor)
+ return -EINVAL;
- dvfs = get_dvfs(g_power_funcs, res_type);
- if (!dvfs)
- return -EPERM;
+ ret = get_dvfs(g_power_funcs, res_type, res_name, &dvfs);
+ if (ret < 0 || !dvfs)
+ return ret;
return exec_func_with_str(dvfs->get_curr_governor, res_name, governor);
}
struct pass_resource_dvfs_ops *dvfs;
int ret;
- ret = is_valid_param_with_str(res_name, governor);
- if (ret < 0)
- return ret;
+ if (!governor)
+ return -EINVAL;
- dvfs = get_dvfs(g_power_funcs, res_type);
- if (!dvfs)
- return -EPERM;
+ ret = get_dvfs(g_power_funcs, res_type, res_name, &dvfs);
+ if (ret < 0 || !dvfs)
+ return ret;
return exec_func_with_str(dvfs->set_curr_governor, res_name, governor);
}
EXPORT int hal_power_dvfs_get_avail_governor(unsigned int res_type, char *res_name, char **avail_governor)
{
struct pass_resource_dvfs_ops *dvfs;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name)
- return -EINVAL;
-
- dvfs = get_dvfs(g_power_funcs, res_type);
- if (!dvfs)
- return -EPERM;
+ ret = get_dvfs(g_power_funcs, res_type, res_name, &dvfs);
+ if (ret < 0 || !dvfs)
+ return ret;
if (!dvfs->get_avail_governor)
return -ENOTSUP;
struct pass_resource_dvfs_ops *dvfs;
int ret;
- ret = is_valid_param(res_name);
- if (ret < 0)
+ ret = get_dvfs(g_power_funcs, res_type, res_name, &dvfs);
+ if (ret < 0 || !dvfs)
return ret;
- dvfs = get_dvfs(g_power_funcs, res_type);
- if (!dvfs)
- return -EPERM;
-
return exec_func(dvfs->get_curr_freq, res_name);
}
struct pass_resource_dvfs_ops *dvfs;
int ret;
- ret = is_valid_param(res_name);
- if (ret < 0)
+ ret = get_dvfs(g_power_funcs, res_type, res_name, &dvfs);
+ if (ret < 0 || !dvfs)
return ret;
- dvfs = get_dvfs(g_power_funcs, res_type);
- if (!dvfs)
- return -EPERM;
-
return exec_func(dvfs->get_min_freq, res_name);
}
struct pass_resource_dvfs_ops *dvfs;
int ret;
- ret = is_valid_param_with_int(res_name, freq);
- if (ret < 0)
- return ret;
+ if (freq < 0)
+ return -EINVAL;
- dvfs = get_dvfs(g_power_funcs, res_type);
- if (!dvfs)
- return -EPERM;
+ ret = get_dvfs(g_power_funcs, res_type, res_name, &dvfs);
+ if (ret < 0 || !dvfs)
+ return ret;
return exec_func_with_int(dvfs->set_min_freq, res_name, freq);
}
struct pass_resource_dvfs_ops *dvfs;
int ret;
- ret = is_valid_param(res_name);
- if (ret < 0)
+ ret = get_dvfs(g_power_funcs, res_type, res_name, &dvfs);
+ if (ret < 0 || !dvfs)
return ret;
- dvfs = get_dvfs(g_power_funcs, res_type);
- if (!dvfs)
- return -EPERM;
-
return exec_func(dvfs->get_max_freq, res_name);
}
struct pass_resource_dvfs_ops *dvfs;
int ret;
- ret = is_valid_param_with_int(res_name, freq);
- if (ret < 0)
- return ret;
+ if (freq < 0)
+ return -EINVAL;
- dvfs = get_dvfs(g_power_funcs, res_type);
- if (!dvfs)
- return -EPERM;
+ ret = get_dvfs(g_power_funcs, res_type, res_name, &dvfs);
+ if (ret < 0 || !dvfs)
+ return ret;
return exec_func_with_int(dvfs->set_max_freq, res_name, freq);
}
struct pass_resource_dvfs_ops *dvfs;
int ret;
- ret = is_valid_param(res_name);
- if (ret < 0)
+ ret = get_dvfs(g_power_funcs, res_type, res_name, &dvfs);
+ if (ret < 0 || !dvfs)
return ret;
- dvfs = get_dvfs(g_power_funcs, res_type);
- if (!dvfs)
- return -EPERM;
-
return exec_func(dvfs->get_available_min_freq, res_name);
}
struct pass_resource_dvfs_ops *dvfs;
int ret;
- ret = is_valid_param(res_name);
- if (ret < 0)
+ ret = get_dvfs(g_power_funcs, res_type, res_name, &dvfs);
+ if (ret < 0 || !dvfs)
return ret;
- dvfs = get_dvfs(g_power_funcs, res_type);
- if (!dvfs)
- return -EPERM;
-
return exec_func(dvfs->get_available_max_freq, res_name);
}
struct pass_resource_dvfs_ops *dvfs;
int ret;
- ret = is_valid_param(res_name);
- if (ret < 0)
+ ret = get_dvfs(g_power_funcs, res_type, res_name, &dvfs);
+ if (ret < 0 || !dvfs)
return ret;
- dvfs = get_dvfs(g_power_funcs, res_type);
- if (!dvfs)
- return -EPERM;
-
return exec_func(dvfs->get_up_threshold, res_name);
}
struct pass_resource_dvfs_ops *dvfs;
int ret;
- ret = is_valid_param_with_int(res_name, up_threshold);
- if (ret < 0)
- return ret;
+ if (up_threshold < 0)
+ return -EINVAL;
- dvfs = get_dvfs(g_power_funcs, res_type);
- if (!dvfs)
- return -EPERM;
+ ret = get_dvfs(g_power_funcs, res_type, res_name, &dvfs);
+ if (ret < 0 || !dvfs)
+ return ret;
return exec_func_with_int(dvfs->set_up_threshold, res_name, up_threshold);
}
struct pass_resource_dvfs_ops *dvfs;
int ret;
- ret = is_valid_param(res_name);
- if (ret < 0)
+ ret = get_dvfs(g_power_funcs, res_type, res_name, &dvfs);
+ if (ret < 0 || !dvfs)
return ret;
- dvfs = get_dvfs(g_power_funcs, res_type);
- if (!dvfs)
- return -EPERM;
-
if (!dvfs->get_load_table)
return -ENOTSUP;
struct pass_resource_hotplug_ops *hotplug;
int ret;
- ret = is_valid_param_with_int(res_name, cpu);
- if (ret < 0)
- return ret;
-
- hotplug = get_hotplug(g_power_funcs, res_type);
- if (!hotplug)
- return -EPERM;
+ if (cpu < 0)
+ return -EINVAL;
- if (!hotplug->get_online_state)
- return -ENOTSUP;
+ ret = get_hotplug(g_power_funcs, res_type, res_name, &hotplug);
+ if (ret < 0 || !hotplug)
+ return ret;
- return hotplug->get_online_state(res_name, cpu);
+ return exec_func_with_int(hotplug->get_online_state, res_name, cpu);
}
EXPORT int hal_power_hotplug_set_online_state(unsigned int res_type, char *res_name, int cpu, int on)
struct pass_resource_hotplug_ops *hotplug;
int ret;
- ret = is_valid_param_with_int(res_name, cpu);
- if (ret < 0)
- return ret;
-
- if (on < 0)
+ if (cpu < 0 || on < 0)
return -EINVAL;
- hotplug = get_hotplug(g_power_funcs, res_type);
- if (!hotplug)
- return -EPERM;
+ ret = get_hotplug(g_power_funcs, res_type, res_name, &hotplug);
+ if (ret < 0 || !hotplug)
+ return ret;
if (!hotplug->set_online_state)
return -ENOTSUP;
struct pass_resource_hotplug_ops *hotplug;
int ret;
- ret = is_valid_param(res_name);
- if (ret < 0)
+ ret = get_hotplug(g_power_funcs, res_type, res_name, &hotplug);
+ if (ret < 0 || !hotplug)
return ret;
- hotplug = get_hotplug(g_power_funcs, res_type);
- if (!hotplug)
- return -EPERM;
-
return exec_func(hotplug->get_online_min_num, res_name);
}
struct pass_resource_hotplug_ops *hotplug;
int ret;
- ret = is_valid_param_with_int(res_name, min_num);
- if (ret < 0)
- return ret;
+ if (min_num < 0)
+ return -EINVAL;
- hotplug = get_hotplug(g_power_funcs, res_type);
- if (!hotplug)
- return -EPERM;
+ ret = get_hotplug(g_power_funcs, res_type, res_name, &hotplug);
+ if (ret < 0 || !hotplug)
+ return ret;
return exec_func_with_int(hotplug->set_online_min_num, res_name, min_num);
}
struct pass_resource_hotplug_ops *hotplug;
int ret;
- ret = is_valid_param(res_name);
- if (ret < 0)
+ ret = get_hotplug(g_power_funcs, res_type, res_name, &hotplug);
+ if (ret < 0 || !hotplug)
return ret;
- hotplug = get_hotplug(g_power_funcs, res_type);
- if (!hotplug)
- return -EPERM;
-
return exec_func(hotplug->get_online_max_num, res_name);
}
struct pass_resource_hotplug_ops *hotplug;
int ret;
- ret = is_valid_param_with_int(res_name, max_num);
- if (ret < 0)
- return ret;
+ if (max_num < 0)
+ return -EINVAL;
- hotplug = get_hotplug(g_power_funcs, res_type);
- if (!hotplug)
- return -EPERM;
+ ret = get_hotplug(g_power_funcs, res_type, res_name, &hotplug);
+ if (ret < 0 || !hotplug)
+ return ret;
return exec_func_with_int(hotplug->set_online_max_num, res_name, max_num);
}
struct pass_resource_tmu_ops *tmu;
int ret;
- ret = is_valid_param(res_thermal_name);
- if (ret < 0)
+ ret = get_tmu(g_power_funcs, res_type, res_thermal_name, &tmu);
+ if (ret < 0 || !tmu)
return ret;
- tmu = get_tmu(g_power_funcs, res_type);
- if (!tmu)
- return -EPERM;
-
/*
* In the case of the HAL TMU ops, res_thermal_name is used
* as the first argument instead of res_name.
struct pass_resource_tmu_ops *tmu;
int ret;
- ret = is_valid_param_with_str(res_thermal_name, policy);
- if (ret < 0)
- return ret;
+ if (!policy)
+ return -EINVAL;
- tmu = get_tmu(g_power_funcs, res_type);
- if (!tmu)
- return -EPERM;
+ ret = get_tmu(g_power_funcs, res_type, res_thermal_name, &tmu);
+ if (ret < 0 || !tmu)
+ return ret;
/*
* In the case of the HAL TMU ops, res_thermal_name is used
struct pass_resource_tmu_ops *tmu;
int ret;
- ret = is_valid_param_with_int(cooling_device_name, state);
- if (ret < 0)
- return ret;
+ if (state < 0)
+ return -EINVAL;
- tmu = get_tmu(g_power_funcs, device_type);
- if (!tmu)
- return -EPERM;
+ ret = get_tmu(g_power_funcs, device_type, cooling_device_name, &tmu);
+ if (ret < 0 || !tmu)
+ return ret;
/*
* In the case of the HAL TMU ops, cooling_device_name is used
struct pass_resource_tmu_ops *tmu;
int ret;
- ret = is_valid_param(cooling_device_name);
- if (ret < 0)
+ ret= get_tmu(g_power_funcs, device_type, cooling_device_name, &tmu);
+ if (ret < 0 || !tmu)
return ret;
- tmu = get_tmu(g_power_funcs, device_type);
- if (!tmu)
- return -EPERM;
-
/*
* In the case of the HAL TMU ops, cooling_device_name is used
* as the first argument instead of res_name.
struct pass_resource_tmu_ops *tmu;
int ret;
- ret = is_valid_param(cooling_device_name);
- if (ret < 0)
+ ret = get_tmu(g_power_funcs, device_type, cooling_device_name, &tmu);
+ if (ret < 0 || !tmu)
return ret;
- tmu = get_tmu(g_power_funcs, device_type);
- if (!tmu)
- return -EPERM;
-
/*
* In the case of the HAL TMU ops, cooling_device_name is used
* as the first argument instead of res_name.
struct pass_resource_battery_ops *charging;
int ret;
- ret = is_valid_param_with_int(res_name, state);
- if (ret < 0)
- return ret;
+ if (state < 0)
+ return -EINVAL;
- charging = get_charging(g_power_funcs, device_type);
- if (!charging)
- return -EPERM;
+ ret = get_charging(g_power_funcs, device_type, res_name, &charging);
+ if (ret < 0 || !charging)
+ return ret;
return exec_func_with_int(charging->set_charging_status, res_name, state);
}
struct pass_resource_battery_ops *charging;
int ret;
- ret = is_valid_param(res_name);
- if (ret < 0)
+ ret = get_charging(g_power_funcs, device_type, res_name, &charging);
+ if (ret < 0 || !charging)
return ret;
- charging = get_charging(g_power_funcs, device_type);
- if (!charging)
- return -EPERM;
-
return exec_func(charging->get_charging_status, res_name);
}
struct pass_resource_battery_ops *charging;
int ret;
- ret = is_valid_param_with_int(res_name, charing_current_uA);
- if (ret < 0)
- return ret;
+ if (charing_current_uA < 0)
+ return -EINVAL;
- charging = get_charging(g_power_funcs, device_type);
- if (!charging)
- return -EPERM;
+ ret = get_charging(g_power_funcs, device_type, res_name, &charging);
+ if (ret < 0 || !charging)
+ return ret;
return exec_func_with_int(charging->set_charging_current, res_name, charing_current_uA);
}
struct pass_resource_battery_ops *charging;
int ret;
- ret = is_valid_param(res_name);
- if (ret < 0)
+ ret = get_charging(g_power_funcs, device_type, res_name, &charging);
+ if (ret < 0 || !charging)
return ret;
- charging = get_charging(g_power_funcs, device_type);
- if (!charging)
- return -EPERM;
-
return exec_func(charging->get_charging_current, res_name);
}
struct pass_resource_memory *memory;
int ret;
- ret = is_valid_param(res_name);
- if (ret < 0)
- return ret;
+ if (!res_name)
+ return -EINVAL;
switch (res_type) {
case PASS_RESOURCE_MEMORY_ID: