In order to control the battery charging status and charging current,
add new properties as following:
[Newly added properties for battery h/w resource]
- 'battery,charging_status' property in 'level_list' section
- 'battery,charging_current_limit' property in 'level_list' section
[Example of charging properties]
In case of scripts/pass-battery.json,
"support" : true,
"init_level" : 0,
"level_list" :
[
{
"level" : 0,
"battery,charging_status" : 0, // POWER_SUPPLY_STATUS_UNKNOWN
"battery_charging_currnt_uA" :
2048000
}, {
"level" : 1,
"battery,charging_status" : 0, // POWER_SUPPLY_STATUS_UNKNOWN
"battery_charging_currnt_uA" :
1024000
}, {
"level" : 2,
"battery,charging_status" : 3, // POWER_SUPPLY_STATUS_NOT_CHARGING
"battery_charging_currnt_uA" :
1024000
}
],
Change-Id: I5a762d3127c2b156be377846a8ab19c4e582b247
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
res->config_data.res_cooling_name);
}
+/**
+ * @brief Set the battery charging state
+ * @param [in] res Instance of h/w resource
+ * @param [in] state State of cooling device
+ * @return @c positive integer on success, otherwise error value
+ * @retval -22 Invalid argument (-EINVAL)
+ * @retval -1 Operation not permitted (-EPERM)
+ * @retval -19 Operation not supported (-ENOTSUP)
+ */
+int pass_hal_set_battery_charging_status(struct pass_resource *res, int charging_status)
+{
+ if (!res)
+ return -EINVAL;
+
+ return hal_power_battery_set_charging_status(res->config_data.res_type,
+ res->config_data.res_name,
+ charging_status);
+}
+
+/**
+ * @brief Get the battery charging state
+ * @param [in] res Instance of h/w resource
+ * @return @c positive integer on success, otherwise error value
+ * @retval -22 Invalid argument (-EINVAL)
+ * @retval -1 Operation not permitted (-EPERM)
+ * @retval -19 Operation not supported (-ENOTSUP)
+ */
+int pass_hal_get_battery_charging_status(struct pass_resource *res)
+{
+ if (!res)
+ return -EINVAL;
+
+ return hal_power_battery_get_charging_status(res->config_data.res_type,
+ res->config_data.res_name);
+}
+
+/**
+ * @brief Set the battery charging current (unit: uA)
+ * @param [in] res Instance of h/w resource
+ * @param [in] state State of cooling device
+ * @return @c positive integer on success, otherwise error value
+ * @retval -22 Invalid argument (-EINVAL)
+ * @retval -1 Operation not permitted (-EPERM)
+ * @retval -19 Operation not supported (-ENOTSUP)
+ */
+int pass_hal_set_battery_charging_current(struct pass_resource *res,
+ int charging_current_uA)
+{
+ if (!res)
+ return -EINVAL;
+
+ return hal_power_battery_set_charging_current(res->config_data.res_type,
+ res->config_data.res_name,
+ charging_current_uA);
+}
+
+/**
+ * @brief Get the battery charging current (unit: uA)
+ * @param [in] res Instance of h/w resource
+ * @return @c positive integer on success, otherwise error value
+ * @retval -22 Invalid argument (-EINVAL)
+ * @retval -1 Operation not permitted (-EPERM)
+ * @retval -19 Operation not supported (-ENOTSUP)
+ */
+int pass_hal_get_battery_charging_current(struct pass_resource *res)
+{
+ if (!res)
+ return -EINVAL;
+
+ return hal_power_battery_get_charging_current(res->config_data.res_type,
+ res->config_data.res_name);
+}
+
/**
* @brief Set the fault_around_bytes for memory h/w resource
* @param [in] res Instance of h/w resource
return 0;
}
+/**
+ * @brief Restore the saved state of charging for battery h/w resource
+ * before PASS (Power Aware System Service) daemon starting
+ * @param [in] res Instance of h/w resource
+ * @return @c 0 on success, otherwise error value
+ */
+static int pass_hal_save_battery_initdata(struct pass_resource *res)
+{
+ struct pass_resource_init_data *initdata = &res->init_data;
+
+ initdata->battery.charging_status
+ = pass_hal_get_battery_charging_status(res);
+ initdata->battery.charging_current_uA
+ = pass_hal_get_battery_charging_current(res);
+
+ return 0;
+}
+
/**
* @brief Restore the saved state of DVFS(Dynamic Voltage and Frequency
* Scaling) resource when PASS (Power Aware System Service) daemon
return 0;
}
+/**
+ * @brief Restore the saved state of charging for battery h/w resource
+ * before PASS (Power Aware System Service) daemon starting
+ * @param [in] res Instance of h/w resource
+ * @return @c 0 on success, otherwise error value
+ */
+static int pass_hal_restore_battery_initdata(struct pass_resource *res)
+{
+ struct pass_resource_init_data *initdata = &res->init_data;
+ int charging_status = initdata->battery.charging_status;
+ int charging_current_uA = initdata->battery.charging_current_uA;
+ int ret;
+
+ if (charging_status >= 0) {
+ ret = pass_hal_set_battery_charging_status(res, charging_status);
+ if (ret < 0)
+ return ret;
+ }
+
+ if (charging_current_uA >= 0) {
+ ret = pass_hal_set_battery_charging_current(res, charging_current_uA);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
/**
* @brief Save the initial state of h/w resource before PASS
* (Power Aware System Service) daemon starting
/* fall through */
case PASS_RESOURCE_BATTERY_ID:
case PASS_RESOURCE_NONSTANDARD_ID:
+ ret = pass_hal_save_battery_initdata(res);
+ if (ret < 0) {
+ _E("Failed to save battery initdata for '%s' resource",
+ res->config_data.res_name);
+ return ret;
+ }
+
ret = pass_hal_save_thermal_initdata(res);
if (ret < 0) {
_E("Failed to save thermal initdata for '%s' resource",
/* fall through */
case PASS_RESOURCE_BATTERY_ID:
case PASS_RESOURCE_NONSTANDARD_ID:
+ ret = pass_hal_restore_battery_initdata(res);
+ if (ret < 0) {
+ _E("Failed to restore battery initdata for '%s' resource",
+ res->config_data.res_name);
+ return ret;
+ }
+
ret = pass_hal_restore_thermal_initdata(res);
if (ret < 0) {
_E("Failed to restore thermal initdata for '%s' resource",
int pass_hal_set_cooling_device_state(struct pass_resource *res, int state);
int pass_hal_get_cooling_device_max_state(struct pass_resource *res);
+/* Get and set the battery charging state. */
+int pass_hal_set_battery_charging_status(struct pass_resource *res,int charging_status);
+int pass_hal_get_battery_charging_status(struct pass_resource *res);
+
+/* Get and set the battery charging current. */
+int pass_hal_set_battery_charging_current(struct pass_resource *res, int charging_current_uA);
+int pass_hal_get_battery_charging_current(struct pass_resource *res);
+
/***
* Functions for CPU H/W resources
*/
level->fault_around_bytes = INIT_VALUE;
level->cooling_device_state = INIT_VALUE;
+ level->charging_status = INIT_VALUE;
+ level->charging_current_uA = INIT_VALUE;
}
static int parse_level(struct pass_resource *res, json_object *obj,
double governor_timeout_sec;
int fault_around_bytes;
int cooling_device_state;
+ int charging_status;
+ int charging_current_uA;
/* Get property values */
level = get_int_from_object(obj, "level");
fault_around_bytes = get_int_from_object(obj, "memory,fault_around_bytes");
cooling_device_state = get_int_from_object(obj, "thermal,cooling_device_state");
+ charging_status = get_int_from_object(obj, "battery,charging_status");
+ charging_current_uA = get_int_from_object(obj, "battery,charging_current_uA");
/* Check the mandatory property values are valid or not */
if (level < 0) {
if (cooling_device_state >= 0)
target_level->cooling_device_state = cooling_device_state;
+ /*
+ * Properties for the following h/w resources:
+ * - PASS_RESOURCE_BATTERY_ID
+ * - PASS_RESOURCE_NONSTANDARD_ID
+ */
+ if (charging_status >= 0)
+ target_level->charging_status = charging_status;
+ if (charging_current_uA >= 0)
+ target_level->charging_current_uA = charging_current_uA;
+
return 0;
}
res->config_data.res_name);
}
+ if (level->charging_status >= 0) {
+ _D("charging_status is %10d of '%s' resource\n",
+ level->charging_status,
+ res->config_data.res_name);
+ }
+
+ if (level->charging_current_uA >= 0) {
+ _D("charging_current_uA is %10d of '%s' resource\n",
+ level->charging_current_uA,
+ res->config_data.res_name);
+ }
}
static void rescon_adjust_level(struct pass_level *a, struct pass_level *b)
/* Adjust cooling_device_state */
a->cooling_device_state = MAX(a->cooling_device_state,
b->cooling_device_state);
+
+ /* Adjust charging_status and charging_current_uA */
+ a->charging_status = MAX(a->charging_status, b->charging_status);
+ a->charging_current_uA = MIN(a->charging_current_uA,
+ b->charging_current_uA);
}
static int rescon_update(struct pass_resource *res)
int limit_max_cpu = -1;
int fault_around_bytes = -1;
int cooling_device_state = -1;
+ int charging_status = -1;
+ int charging_current_uA = -1;
int ret, i;
int failed = 0;
adjusted_level.limit_max_cpu = MAX_INT;
adjusted_level.fault_around_bytes = MIN_INT;
adjusted_level.cooling_device_state = MIN_INT;
+ adjusted_level.charging_status = MIN_INT;
+ adjusted_level.charging_current_uA = MAX_INT;
/* Adjust with pass_level */
if (res->rescon.curr_level >= 0)
case PASS_RESOURCE_BATTERY_ID:
case PASS_RESOURCE_NONSTANDARD_ID:
cooling_device_state = adjusted_level.cooling_device_state;
+ charging_status = adjusted_level.charging_status;
+ charging_current_uA = adjusted_level.charging_current_uA;
break;
case PASS_RESOURCE_MEMORY_ID:
fault_around_bytes = adjusted_level.fault_around_bytes;
}
}
+ /* Set charging_status for battery h/w */
+ if (charging_status >= 0) {
+ ret = pass_hal_set_battery_charging_status(res, charging_status);
+ if (ret < 0) {
+ _W("failed to set the charging_status(%d) of %s",
+ charging_status,
+ res->config_data.res_name);
+ failed = 1;
+ }
+ }
+
+ /* Set charging_current_uA for battery h/w */
+ if (charging_current_uA >= 0) {
+ ret = pass_hal_set_battery_charging_current(res, charging_current_uA);
+ if (ret < 0) {
+ _W("failed to set the charging_current_uA(%d) of %s",
+ charging_current_uA,
+ res->config_data.res_name);
+ failed = 1;
+ }
+ }
+
if (!failed)
rescon_print_level(res, &adjusted_level);
else
*/
int cooling_device_state;
+ /**
+ * The current state of battery charging device
+ * and this property is used for the following resources:
+ * - PASS_RESOURCE_BATTERY_ID
+ * - PASS_RESOURCE_NONSTANDARD_ID
+ */
+ int charging_status;
+ int charging_current_uA;
+
/* Properties for the timer */
/**
int cooling_device_state;
} tmu;
+ /** Initial state of battery charging configuration */
+ struct {
+ /** Charging state */
+ int charging_status;
+ int charging_current_uA;
+ } battery;
+
/** Initial state of memory configuration */
struct {
/** the number of bytes to be mapped around the fault */