halapi: power: Add new battery HAL API to control charging status 49/262549/3 accepted/tizen/unified/20210816.122904 submit/tizen/20210813.100724
authorChanwoo Choi <cw00.choi@samsung.com>
Fri, 13 Aug 2021 04:03:04 +0000 (13:03 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Fri, 13 Aug 2021 08:26:43 +0000 (17:26 +0900)
When over-temperature is meaused for h/w resource, must need to change
the state in order to down the temperature for preventing the dangerous
situation. So that add new battery HAL API for controlling the battery
status via power_supply subsystem in Linux kernel.

[Detailed new thermal HAL API]
/* Get and set the batterh charging state */
int hal_power_battery_set_charging_state(unsigned int device_type, char *res_name, int state);
int hal_power_battery_get_charging_state(unsigned int device_type, char *res_name);

/* Get and set the battery charging current (unit: uA) */
int hal_power_battery_set_charging_current(unsigned int device_type, char *res_name, int charing_current_uA);
int hal_power_battery_get_charging_current(unsigned int device_type, char *res_name);

Change-Id: Ie627e3619fea1876c5a52dce503e0f322dfad837
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
include/hal-power-interface.h
include/hal-power.h
src/hal-api-power.c

index b3cef4f423ec0c2e757d5594370d038f6022b3d8..1b5b57fbbdf08fee0578b6fc69ad0e927840bef8 100644 (file)
@@ -85,6 +85,16 @@ struct pass_resource_tmu_ops {
        int (*get_cooling_device_max_state)(char *cooling_device_name);
 };
 
+struct pass_resource_battery_ops {
+       /* Get and set the state of batterh charging */
+       int (*set_charging_status)(char *res_name, int state);
+       int (*get_charging_status)(char *res_name);
+
+       /* Get and set the battery charging current (unit: uA) */
+       int (*set_charging_current)(char *res_name, int charing_current_uA);
+       int (*get_charging_current)(char *res_name);
+};
+
 /*
  * Define the resource structure for CPU H/W.
  *
@@ -134,15 +144,18 @@ struct pass_resource_memory {
  * Define the resource structure for Battery H/W.
  *
  * @tmu                : function lists for the TMU (Thermal Management Unit).
+ * @battery    : function lists for the battery charging.
  */
 struct pass_resource_battery {
        struct pass_resource_tmu_ops tmu;
+       struct pass_resource_battery_ops battery;
 };
 
 /*
  * Define the resource structure for nonstandard H/W.
  *
  * @tmu                : function lists for the TMU (Thermal Management Unit).
+ * @battery    : function lists for the battery charging.
  *
  * Following function is Deprecated. (Not recommended for use)
  * @set_pmqos_data : function to bypass the scenario data to HAL.
@@ -154,6 +167,7 @@ struct pass_resource_battery {
  */
 struct pass_resource_nonstandard {
        struct pass_resource_tmu_ops tmu;
+       struct pass_resource_battery_ops battery;
 
        /*
         * NOTE: It is not propper method. But PASS must need to keep
index d3cc46278d550f629ccfc82beaba47a4bdfd8cd8..c1b78e5ec2841361992a8768a80da866641597c8 100644 (file)
@@ -102,6 +102,14 @@ int hal_power_thermal_get_cooling_device_state(unsigned int device_type, char *c
 /* Get maximum state of thermal cooling-device */
 int hal_power_thermal_get_cooling_device_max_state(unsigned int device_type, char *cooling_device_name);
 
+/* Get and set the batterh charging state */
+int hal_power_battery_set_charging_status(unsigned int device_type, char *res_name, int state);
+int hal_power_battery_get_charging_status(unsigned int device_type, char *res_name);
+
+/* Get and set the battery charging current (unit: uA) */
+int hal_power_battery_set_charging_current(unsigned int device_type, char *res_name, int charing_current_uA);
+int hal_power_battery_get_charging_current(unsigned int device_type, char *res_name);
+
 /**
  * Memory Operation for Memory H/W
  */
index 18e631f9a9e830fa03cd5dca688d10645c62df0e..e103ff9677aa4b0be8d58afc276be2475e5088dc 100644 (file)
@@ -134,6 +134,25 @@ static struct pass_resource_hotplug_ops *get_hotplug(hal_backend_power_funcs *fu
        return hotplug;
 }
 
+static struct pass_resource_battery_ops *get_charging(hal_backend_power_funcs *funcs,
+                                               int res_type)
+{
+       struct pass_resource_battery_ops *charging = NULL;
+
+       switch (res_type) {
+       case PASS_RESOURCE_BATTERY_ID:
+               if (funcs && funcs->battery)
+                       charging = &(funcs->battery->battery);
+               break;
+       case PASS_RESOURCE_NONSTANDARD_ID:
+               if (funcs && funcs->nonstandard)
+                       charging = &(funcs->nonstandard->battery);
+               break;
+       }
+
+       return charging;
+}
+
 EXPORT int hal_power_get_backend(unsigned int res_type)
 {
        if (!g_power_funcs) {
@@ -697,6 +716,92 @@ EXPORT int hal_power_thermal_get_cooling_device_max_state(unsigned int device_ty
        return tmu->get_cooling_device_max_state(cooling_device_name);
 }
 
+EXPORT int hal_power_battery_set_charging_status(unsigned int device_type,
+                                                       char *res_name,
+                                                       int state)
+{
+       struct pass_resource_battery_ops *charging;
+
+       if (!g_power_funcs)
+               return -ENOTSUP;
+
+       if (!res_name)
+               return -EINVAL;
+
+       charging = get_charging(g_power_funcs, device_type);
+       if (!charging)
+               return -EPERM;
+
+       if (!charging->set_charging_status)
+               return -ENOTSUP;
+
+       return charging->set_charging_status(res_name, state);
+}
+
+EXPORT int hal_power_battery_get_charging_status(unsigned int device_type,
+                                                       char *res_name)
+{
+       struct pass_resource_battery_ops *charging;
+
+       if (!g_power_funcs)
+               return -ENOTSUP;
+
+       if (!res_name)
+               return -EINVAL;
+
+       charging = get_charging(g_power_funcs, device_type);
+       if (!charging)
+               return -EPERM;
+
+       if (!charging->get_charging_status)
+               return -ENOTSUP;
+
+       return charging->get_charging_status(res_name);
+}
+
+EXPORT int hal_power_battery_set_charging_current(unsigned int device_type,
+                                                       char *res_name,
+                                                       int charing_current_uA)
+{
+       struct pass_resource_battery_ops *charging;
+
+       if (!g_power_funcs)
+               return -ENOTSUP;
+
+       if (!res_name)
+               return -EINVAL;
+
+       charging = get_charging(g_power_funcs, device_type);
+       if (!charging)
+               return -EPERM;
+
+       if (!charging->set_charging_current)
+               return -ENOTSUP;
+
+       return charging->set_charging_current(res_name, charing_current_uA);
+}
+
+EXPORT int hal_power_battery_get_charging_current(unsigned int device_type,
+                                                       char *res_name)
+{
+       struct pass_resource_battery_ops *charging;
+
+       if (!g_power_funcs)
+               return -ENOTSUP;
+
+       if (!res_name)
+               return -EINVAL;
+
+       charging = get_charging(g_power_funcs, device_type);
+       if (!charging)
+               return -EPERM;
+
+       if (!charging->get_charging_current)
+               return -ENOTSUP;
+
+       return charging->get_charging_current(res_name);
+}
+
 /**
  * Memory Operation for Memory H/W
  */