return 0;
}
+static inline int exec_func(int (*func)(char *res_name), char *res_name)
+{
+ if (!func)
+ return -ENOTSUP;
+ return func(res_name);
+}
+
+static inline int exec_func_with_str(int (*func)(char *res_name, char *str),
+ char *res_name, char *str)
+{
+ if (!func)
+ return -ENOTSUP;
+ return func(res_name, str);
+}
+
+static inline int exec_func_with_int(int (*func)(char *res_name, int val),
+ char *res_name, int val)
+{
+ if (!func)
+ return -ENOTSUP;
+ return func(res_name, val);
+}
+
/* Get and set the current governor. */
EXPORT int hal_power_dvfs_get_curr_governor(unsigned int res_type,
char *res_name, char *governor)
if (!dvfs)
return -EPERM;
- if (!dvfs->get_curr_governor)
- return -ENOTSUP;
-
- return dvfs->get_curr_governor(res_name, governor);
+ return exec_func_with_str(dvfs->get_curr_governor, res_name, governor);
}
EXPORT int hal_power_dvfs_set_curr_governor(unsigned int res_type, char *res_name, char *governor)
if (!dvfs)
return -EPERM;
- if (!dvfs->set_curr_governor)
- return -ENOTSUP;
-
- return dvfs->set_curr_governor(res_name, governor);
+ 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)
if (!dvfs)
return -EPERM;
- if (!dvfs->get_avail_governor)
+ if (dvfs->get_avail_governor)
return -ENOTSUP;
return dvfs->get_avail_governor(res_name, avail_governor);
if (!dvfs)
return -EPERM;
- if (!dvfs->get_curr_freq)
- return -ENOTSUP;
-
- return dvfs->get_curr_freq(res_name);
+ return exec_func(dvfs->get_curr_freq, res_name);
}
/* Get and set the minimum frequency. */
if (!dvfs)
return -EPERM;
- if (!dvfs->get_min_freq)
- return -ENOTSUP;
-
- return dvfs->get_min_freq(res_name);
+ return exec_func(dvfs->get_min_freq, res_name);
}
EXPORT int hal_power_dvfs_set_min_freq(unsigned int res_type, char *res_name, int freq)
if (!dvfs)
return -EPERM;
- if (!dvfs->set_min_freq)
- return -ENOTSUP;
-
- return dvfs->set_min_freq(res_name, freq);
+ return exec_func_with_int(dvfs->set_min_freq, res_name, freq);
}
/* Get and set the maximum frequency. */
if (!dvfs)
return -EPERM;
- if (!dvfs->get_max_freq)
- return -ENOTSUP;
-
- return dvfs->get_max_freq(res_name);
+ return exec_func(dvfs->get_max_freq, res_name);
}
EXPORT int hal_power_dvfs_set_max_freq(unsigned int res_type, char *res_name, int freq)
if (!dvfs)
return -EPERM;
- if (!dvfs->set_max_freq)
- return -ENOTSUP;
-
- return dvfs->set_max_freq(res_name, freq);
+ return exec_func_with_int(dvfs->set_max_freq, res_name, freq);
}
/* Get the minimum/maximum frequency which can be set to resource. */
if (!dvfs)
return -EPERM;
- if (!dvfs->get_available_min_freq)
- return -ENOTSUP;
-
- return dvfs->get_available_min_freq(res_name);
+ return exec_func(dvfs->get_available_min_freq, res_name);
}
EXPORT int hal_power_dvfs_get_available_max_freq(unsigned int res_type, char *res_name)
if (!dvfs)
return -EPERM;
- if (!dvfs->get_available_max_freq)
- return -ENOTSUP;
-
- return dvfs->get_available_max_freq(res_name);
+ return exec_func(dvfs->get_available_max_freq, res_name);
}
/* Get and set the up_threshold to support boosting. */
if (!dvfs)
return -EPERM;
- if (!dvfs->get_up_threshold)
- return -ENOTSUP;
-
- return dvfs->get_up_threshold(res_name);
+ return exec_func(dvfs->get_up_threshold, res_name);
}
EXPORT int hal_power_dvfs_set_up_threshold(unsigned int res_type, char *res_name, int up_threshold)
if (!dvfs)
return -EPERM;
- if (!dvfs->set_up_threshold)
- return -ENOTSUP;
-
- return dvfs->set_up_threshold(res_name, up_threshold);
+ return exec_func_with_int(dvfs->set_up_threshold, res_name, up_threshold);
}
/* Get the load_table of each resource to estimate the system load. */
if (!hotplug)
return -EPERM;
- if (!hotplug->get_online_min_num)
- return -ENOTSUP;
-
- return hotplug->get_online_min_num(res_name);
+ return exec_func(hotplug->get_online_min_num, res_name);
}
EXPORT int hal_power_hotplug_set_online_min_num(unsigned int res_type,
if (!hotplug)
return -EPERM;
- if (!hotplug->set_online_min_num)
- return -ENOTSUP;
-
- return hotplug->set_online_min_num(res_name, min_num);
+ return exec_func_with_int(hotplug->set_online_min_num, res_name, min_num);
}
/* Get and set the maximum number of online CPUs */
if (!hotplug)
return -EPERM;
- if (!hotplug->get_online_max_num)
- return -ENOTSUP;
-
- return hotplug->get_online_max_num(res_name);
+ return exec_func(hotplug->get_online_max_num, res_name);
}
EXPORT int hal_power_hotplug_set_online_max_num(unsigned int res_type,
if (!hotplug)
return -EPERM;
- if (!hotplug->set_online_max_num)
- return -ENOTSUP;
-
- return hotplug->set_online_max_num(res_name, max_num);
+ return exec_func_with_int(hotplug->set_online_max_num, res_name, max_num);
}
/**
if (!tmu)
return -EPERM;
- if (!tmu->get_temp)
- return -ENOTSUP;
-
/*
* In the case of the HAL TMU ops, res_thermal_name is used
* as the first argument instead of res_name.
*/
- return tmu->get_temp(res_thermal_name);
+ return exec_func(tmu->get_temp, res_thermal_name);
}
/* Get the policy of thermal management unit. */
if (!tmu)
return -EPERM;
- if (!tmu->get_policy)
- return -ENOTSUP;
-
/*
* In the case of the HAL TMU ops, res_thermal_name is used
* as the first argument instead of res_name.
*/
- return tmu->get_policy(res_thermal_name, policy);
+ return exec_func_with_str(tmu->get_policy, res_thermal_name, policy);
}
/* Get and set the state of thermal cooling-device */
if (!tmu)
return -EPERM;
- if (!tmu->set_cooling_device_state)
- return -ENOTSUP;
-
/*
* In the case of the HAL TMU ops, cooling_device_name is used
* as the first argument instead of res_name.
*/
- return tmu->set_cooling_device_state(cooling_device_name, state);
+ return exec_func_with_int(tmu->set_cooling_device_state, cooling_device_name, state);
}
EXPORT int hal_power_thermal_get_cooling_device_state(unsigned int device_type,
if (!tmu)
return -EPERM;
- if (!tmu->get_cooling_device_state)
- return -ENOTSUP;
-
/*
* In the case of the HAL TMU ops, cooling_device_name is used
* as the first argument instead of res_name.
*/
- return tmu->get_cooling_device_state(cooling_device_name);
+ return exec_func(tmu->get_cooling_device_state, cooling_device_name);
}
EXPORT int hal_power_thermal_get_cooling_device_max_state(unsigned int device_type,
if (!tmu)
return -EPERM;
- if (!tmu->get_cooling_device_max_state)
- return -ENOTSUP;
-
/*
* In the case of the HAL TMU ops, cooling_device_name is used
* as the first argument instead of res_name.
*/
- return tmu->get_cooling_device_max_state(cooling_device_name);
+ return exec_func(tmu->get_cooling_device_max_state, cooling_device_name);
}
EXPORT int hal_power_battery_set_charging_status(unsigned int device_type,
if (!charging)
return -EPERM;
- if (!charging->set_charging_status)
- return -ENOTSUP;
-
- return charging->set_charging_status(res_name, state);
+ return exec_func_with_int(charging->set_charging_status, res_name, state);
}
EXPORT int hal_power_battery_get_charging_status(unsigned int device_type,
if (!charging)
return -EPERM;
- if (!charging->get_charging_status)
- return -ENOTSUP;
-
- return charging->get_charging_status(res_name);
+ return exec_func(charging->get_charging_status, res_name);
}
EXPORT int hal_power_battery_set_charging_current(unsigned int device_type,
if (!charging)
return -EPERM;
- if (!charging->set_charging_current)
- return -ENOTSUP;
-
- return charging->set_charging_current(res_name, charing_current_uA);
+ return exec_func_with_int(charging->set_charging_current, res_name, charing_current_uA);
}
EXPORT int hal_power_battery_get_charging_current(unsigned int device_type,
if (!charging)
return -EPERM;
- if (!charging->get_charging_current)
- return -ENOTSUP;
-
- return charging->get_charging_current(res_name);
+ return exec_func(charging->get_charging_current, res_name);
}
/**
return -EPERM;
}
- if (!memory->get_fault_around_bytes)
- return -ENOTSUP;
-
- return memory->get_fault_around_bytes(res_name);
+ return exec_func(memory->get_fault_around_bytes, res_name);
}
EXPORT int hal_power_memory_set_fault_around_bytes(unsigned int res_type,
return -EPERM;
}
- if (!memory->set_fault_around_bytes)
- return -ENOTSUP;
-
- return memory->set_fault_around_bytes(res_name, fault_around_bytes);
+ return exec_func_with_int(memory->set_fault_around_bytes, res_name, fault_around_bytes);
}
/**