linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] test_power: Add CHARGE_COUNTER and CURRENT properties
@ 2019-09-12 18:25 lecopzer
  2019-09-12 18:25 ` [PATCH v2 1/2] test_power: Add CHARGE_COUNTER properties lecopzer
  2019-09-12 18:26 ` [PATCH v2 2/2] test_power: Add CURRENT properties lecopzer
  0 siblings, 2 replies; 5+ messages in thread
From: lecopzer @ 2019-09-12 18:25 UTC (permalink / raw)
  To: lecopzer, sre, linux-pm, linux-kernel; +Cc: yj.chiang, lecopzer.chen

This series adds two common properties to test_power driver.
Most power supply drivers has these two properties, so add them to
test framework.


Changes in v2:
	- Seperate CHARGE_COUNTER and CURRENT into 2 patches.
	- Correct CHARGE_COUNTER whicch can be negative.


lecopzer (2):
  test_power: Add CHARGE_COUNTER properties
  test_power: Add CURRENT properties

 drivers/power/supply/test_power.c | 61 +++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] test_power: Add CHARGE_COUNTER properties
  2019-09-12 18:25 [PATCH v2 0/2] test_power: Add CHARGE_COUNTER and CURRENT properties lecopzer
@ 2019-09-12 18:25 ` lecopzer
  2019-10-14  5:46   ` Sebastian Reichel
  2019-09-12 18:26 ` [PATCH v2 2/2] test_power: Add CURRENT properties lecopzer
  1 sibling, 1 reply; 5+ messages in thread
From: lecopzer @ 2019-09-12 18:25 UTC (permalink / raw)
  To: lecopzer, sre, linux-pm, linux-kernel; +Cc: yj.chiang, lecopzer.chen

CHARGE_COUNTER is really general in other power supply drivers and
Android also has an interface to monitor CHARGE_COUNTER, so let's
add it into test framework.

Set default as -1000 is because the default status is
POWER_SUPPLY_STATUS_DISCHARGING, which means the counter should be
negative, and 1000 means not zero but small enough.

Signed-off-by: Lecopzer Chen <lecopzer.chen@mediatek.com>
---
 drivers/power/supply/test_power.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/drivers/power/supply/test_power.c b/drivers/power/supply/test_power.c
index c3cad2b6daba..70db8d20e138 100644
--- a/drivers/power/supply/test_power.c
+++ b/drivers/power/supply/test_power.c
@@ -33,6 +33,7 @@ static int battery_present		= 1; /* true */
 static int battery_technology		= POWER_SUPPLY_TECHNOLOGY_LION;
 static int battery_capacity		= 50;
 static int battery_voltage		= 3300;
+static int battery_charge_counter	= -1000;
 
 static bool module_initialized;
 
@@ -100,6 +101,9 @@ static int test_power_get_battery_property(struct power_supply *psy,
 	case POWER_SUPPLY_PROP_CHARGE_NOW:
 		val->intval = battery_capacity;
 		break;
+	case POWER_SUPPLY_PROP_CHARGE_COUNTER:
+		val->intval = battery_charge_counter;
+		break;
 	case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
 	case POWER_SUPPLY_PROP_CHARGE_FULL:
 		val->intval = 100;
@@ -135,6 +139,7 @@ static enum power_supply_property test_power_battery_props[] = {
 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
 	POWER_SUPPLY_PROP_CHARGE_FULL,
 	POWER_SUPPLY_PROP_CHARGE_NOW,
+	POWER_SUPPLY_PROP_CHARGE_COUNTER,
 	POWER_SUPPLY_PROP_CAPACITY,
 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
@@ -447,6 +452,21 @@ static int param_set_battery_voltage(const char *key,
 
 #define param_get_battery_voltage param_get_int
 
+static int param_set_battery_charge_counter(const char *key,
+					const struct kernel_param *kp)
+{
+	int tmp;
+
+	if (1 != sscanf(key, "%d", &tmp))
+		return -EINVAL;
+
+	battery_charge_counter = tmp;
+	signal_power_supply_changed(test_power_supplies[TEST_BATTERY]);
+	return 0;
+}
+
+#define param_get_battery_charge_counter param_get_int
+
 static const struct kernel_param_ops param_ops_ac_online = {
 	.set = param_set_ac_online,
 	.get = param_get_ac_online,
@@ -487,6 +507,11 @@ static const struct kernel_param_ops param_ops_battery_voltage = {
 	.get = param_get_battery_voltage,
 };
 
+static const struct kernel_param_ops param_ops_battery_charge_counter = {
+	.set = param_set_battery_charge_counter,
+	.get = param_get_battery_charge_counter,
+};
+
 #define param_check_ac_online(name, p) __param_check(name, p, void);
 #define param_check_usb_online(name, p) __param_check(name, p, void);
 #define param_check_battery_status(name, p) __param_check(name, p, void);
@@ -495,6 +520,7 @@ static const struct kernel_param_ops param_ops_battery_voltage = {
 #define param_check_battery_health(name, p) __param_check(name, p, void);
 #define param_check_battery_capacity(name, p) __param_check(name, p, void);
 #define param_check_battery_voltage(name, p) __param_check(name, p, void);
+#define param_check_battery_charge_counter(name, p) __param_check(name, p, void);
 
 
 module_param(ac_online, ac_online, 0644);
@@ -525,6 +551,10 @@ MODULE_PARM_DESC(battery_capacity, "battery capacity (percentage)");
 module_param(battery_voltage, battery_voltage, 0644);
 MODULE_PARM_DESC(battery_voltage, "battery voltage (millivolts)");
 
+module_param(battery_charge_counter, battery_charge_counter, 0644);
+MODULE_PARM_DESC(battery_charge_counter,
+	"battery charge counter (microampere-hours)");
+
 MODULE_DESCRIPTION("Power supply driver for testing");
 MODULE_AUTHOR("Anton Vorontsov <cbouatmailru@gmail.com>");
 MODULE_LICENSE("GPL");
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] test_power: Add CURRENT properties
  2019-09-12 18:25 [PATCH v2 0/2] test_power: Add CHARGE_COUNTER and CURRENT properties lecopzer
  2019-09-12 18:25 ` [PATCH v2 1/2] test_power: Add CHARGE_COUNTER properties lecopzer
@ 2019-09-12 18:26 ` lecopzer
  2019-10-14  5:46   ` Sebastian Reichel
  1 sibling, 1 reply; 5+ messages in thread
From: lecopzer @ 2019-09-12 18:26 UTC (permalink / raw)
  To: lecopzer, sre, linux-pm, linux-kernel; +Cc: yj.chiang, lecopzer.chen

CURRENT is really general in other battery drivers,
Android also has an interface to monitor CURRENT, so let's
add it into test framework.

The default value (1.6A) is just a random but reasonable value.

Signed-off-by: Lecopzer Chen <lecopzer.chen@mediatek.com>
---
 drivers/power/supply/test_power.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/drivers/power/supply/test_power.c b/drivers/power/supply/test_power.c
index 70db8d20e138..65c23ef6408d 100644
--- a/drivers/power/supply/test_power.c
+++ b/drivers/power/supply/test_power.c
@@ -34,6 +34,7 @@ static int battery_technology		= POWER_SUPPLY_TECHNOLOGY_LION;
 static int battery_capacity		= 50;
 static int battery_voltage		= 3300;
 static int battery_charge_counter	= -1000;
+static int battery_current		= 1600;
 
 static bool module_initialized;
 
@@ -118,6 +119,10 @@ static int test_power_get_battery_property(struct power_supply *psy,
 	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
 		val->intval = battery_voltage;
 		break;
+	case POWER_SUPPLY_PROP_CURRENT_AVG:
+	case POWER_SUPPLY_PROP_CURRENT_NOW:
+		val->intval = battery_current;
+		break;
 	default:
 		pr_info("%s: some properties deliberately report errors.\n",
 			__func__);
@@ -149,6 +154,8 @@ static enum power_supply_property test_power_battery_props[] = {
 	POWER_SUPPLY_PROP_SERIAL_NUMBER,
 	POWER_SUPPLY_PROP_TEMP,
 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
+	POWER_SUPPLY_PROP_CURRENT_AVG,
+	POWER_SUPPLY_PROP_CURRENT_NOW,
 };
 
 static char *test_power_ac_supplied_to[] = {
@@ -467,6 +474,21 @@ static int param_set_battery_charge_counter(const char *key,
 
 #define param_get_battery_charge_counter param_get_int
 
+static int param_set_battery_current(const char *key,
+					const struct kernel_param *kp)
+{
+	int tmp;
+
+	if (1 != sscanf(key, "%d", &tmp))
+		return -EINVAL;
+
+	battery_current = tmp;
+	signal_power_supply_changed(test_power_supplies[TEST_BATTERY]);
+	return 0;
+}
+
+#define param_get_battery_current param_get_int
+
 static const struct kernel_param_ops param_ops_ac_online = {
 	.set = param_set_ac_online,
 	.get = param_get_ac_online,
@@ -512,6 +534,11 @@ static const struct kernel_param_ops param_ops_battery_charge_counter = {
 	.get = param_get_battery_charge_counter,
 };
 
+static const struct kernel_param_ops param_ops_battery_current = {
+	.set = param_set_battery_current,
+	.get = param_get_battery_current,
+};
+
 #define param_check_ac_online(name, p) __param_check(name, p, void);
 #define param_check_usb_online(name, p) __param_check(name, p, void);
 #define param_check_battery_status(name, p) __param_check(name, p, void);
@@ -521,6 +548,7 @@ static const struct kernel_param_ops param_ops_battery_charge_counter = {
 #define param_check_battery_capacity(name, p) __param_check(name, p, void);
 #define param_check_battery_voltage(name, p) __param_check(name, p, void);
 #define param_check_battery_charge_counter(name, p) __param_check(name, p, void);
+#define param_check_battery_current(name, p) __param_check(name, p, void);
 
 
 module_param(ac_online, ac_online, 0644);
@@ -555,6 +583,9 @@ module_param(battery_charge_counter, battery_charge_counter, 0644);
 MODULE_PARM_DESC(battery_charge_counter,
 	"battery charge counter (microampere-hours)");
 
+module_param(battery_current, battery_current, 0644);
+MODULE_PARM_DESC(battery_current, "battery current (milliampere)");
+
 MODULE_DESCRIPTION("Power supply driver for testing");
 MODULE_AUTHOR("Anton Vorontsov <cbouatmailru@gmail.com>");
 MODULE_LICENSE("GPL");
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] test_power: Add CHARGE_COUNTER properties
  2019-09-12 18:25 ` [PATCH v2 1/2] test_power: Add CHARGE_COUNTER properties lecopzer
@ 2019-10-14  5:46   ` Sebastian Reichel
  0 siblings, 0 replies; 5+ messages in thread
From: Sebastian Reichel @ 2019-10-14  5:46 UTC (permalink / raw)
  To: lecopzer; +Cc: linux-pm, linux-kernel, yj.chiang, lecopzer.chen

[-- Attachment #1: Type: text/plain, Size: 4178 bytes --]

Hi,

On Fri, Sep 13, 2019 at 02:25:59AM +0800, lecopzer@gmail.com wrote:
> CHARGE_COUNTER is really general in other power supply drivers and
> Android also has an interface to monitor CHARGE_COUNTER, so let's
> add it into test framework.
> 
> Set default as -1000 is because the default status is
> POWER_SUPPLY_STATUS_DISCHARGING, which means the counter should be
> negative, and 1000 means not zero but small enough.
> 
> Signed-off-by: Lecopzer Chen <lecopzer.chen@mediatek.com>
> ---

Thanks, queued.

-- Sebastian

>  drivers/power/supply/test_power.c | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
> diff --git a/drivers/power/supply/test_power.c b/drivers/power/supply/test_power.c
> index c3cad2b6daba..70db8d20e138 100644
> --- a/drivers/power/supply/test_power.c
> +++ b/drivers/power/supply/test_power.c
> @@ -33,6 +33,7 @@ static int battery_present		= 1; /* true */
>  static int battery_technology		= POWER_SUPPLY_TECHNOLOGY_LION;
>  static int battery_capacity		= 50;
>  static int battery_voltage		= 3300;
> +static int battery_charge_counter	= -1000;
>  
>  static bool module_initialized;
>  
> @@ -100,6 +101,9 @@ static int test_power_get_battery_property(struct power_supply *psy,
>  	case POWER_SUPPLY_PROP_CHARGE_NOW:
>  		val->intval = battery_capacity;
>  		break;
> +	case POWER_SUPPLY_PROP_CHARGE_COUNTER:
> +		val->intval = battery_charge_counter;
> +		break;
>  	case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
>  	case POWER_SUPPLY_PROP_CHARGE_FULL:
>  		val->intval = 100;
> @@ -135,6 +139,7 @@ static enum power_supply_property test_power_battery_props[] = {
>  	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
>  	POWER_SUPPLY_PROP_CHARGE_FULL,
>  	POWER_SUPPLY_PROP_CHARGE_NOW,
> +	POWER_SUPPLY_PROP_CHARGE_COUNTER,
>  	POWER_SUPPLY_PROP_CAPACITY,
>  	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
>  	POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
> @@ -447,6 +452,21 @@ static int param_set_battery_voltage(const char *key,
>  
>  #define param_get_battery_voltage param_get_int
>  
> +static int param_set_battery_charge_counter(const char *key,
> +					const struct kernel_param *kp)
> +{
> +	int tmp;
> +
> +	if (1 != sscanf(key, "%d", &tmp))
> +		return -EINVAL;
> +
> +	battery_charge_counter = tmp;
> +	signal_power_supply_changed(test_power_supplies[TEST_BATTERY]);
> +	return 0;
> +}
> +
> +#define param_get_battery_charge_counter param_get_int
> +
>  static const struct kernel_param_ops param_ops_ac_online = {
>  	.set = param_set_ac_online,
>  	.get = param_get_ac_online,
> @@ -487,6 +507,11 @@ static const struct kernel_param_ops param_ops_battery_voltage = {
>  	.get = param_get_battery_voltage,
>  };
>  
> +static const struct kernel_param_ops param_ops_battery_charge_counter = {
> +	.set = param_set_battery_charge_counter,
> +	.get = param_get_battery_charge_counter,
> +};
> +
>  #define param_check_ac_online(name, p) __param_check(name, p, void);
>  #define param_check_usb_online(name, p) __param_check(name, p, void);
>  #define param_check_battery_status(name, p) __param_check(name, p, void);
> @@ -495,6 +520,7 @@ static const struct kernel_param_ops param_ops_battery_voltage = {
>  #define param_check_battery_health(name, p) __param_check(name, p, void);
>  #define param_check_battery_capacity(name, p) __param_check(name, p, void);
>  #define param_check_battery_voltage(name, p) __param_check(name, p, void);
> +#define param_check_battery_charge_counter(name, p) __param_check(name, p, void);
>  
>  
>  module_param(ac_online, ac_online, 0644);
> @@ -525,6 +551,10 @@ MODULE_PARM_DESC(battery_capacity, "battery capacity (percentage)");
>  module_param(battery_voltage, battery_voltage, 0644);
>  MODULE_PARM_DESC(battery_voltage, "battery voltage (millivolts)");
>  
> +module_param(battery_charge_counter, battery_charge_counter, 0644);
> +MODULE_PARM_DESC(battery_charge_counter,
> +	"battery charge counter (microampere-hours)");
> +
>  MODULE_DESCRIPTION("Power supply driver for testing");
>  MODULE_AUTHOR("Anton Vorontsov <cbouatmailru@gmail.com>");
>  MODULE_LICENSE("GPL");
> -- 
> 2.17.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/2] test_power: Add CURRENT properties
  2019-09-12 18:26 ` [PATCH v2 2/2] test_power: Add CURRENT properties lecopzer
@ 2019-10-14  5:46   ` Sebastian Reichel
  0 siblings, 0 replies; 5+ messages in thread
From: Sebastian Reichel @ 2019-10-14  5:46 UTC (permalink / raw)
  To: lecopzer; +Cc: linux-pm, linux-kernel, yj.chiang, lecopzer.chen

[-- Attachment #1: Type: text/plain, Size: 3941 bytes --]

Hi,

On Fri, Sep 13, 2019 at 02:26:00AM +0800, lecopzer@gmail.com wrote:
> CURRENT is really general in other battery drivers,
> Android also has an interface to monitor CURRENT, so let's
> add it into test framework.
> 
> The default value (1.6A) is just a random but reasonable value.
> 
> Signed-off-by: Lecopzer Chen <lecopzer.chen@mediatek.com>
> ---

Thanks, queued.

-- Sebastian

>  drivers/power/supply/test_power.c | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 
> diff --git a/drivers/power/supply/test_power.c b/drivers/power/supply/test_power.c
> index 70db8d20e138..65c23ef6408d 100644
> --- a/drivers/power/supply/test_power.c
> +++ b/drivers/power/supply/test_power.c
> @@ -34,6 +34,7 @@ static int battery_technology		= POWER_SUPPLY_TECHNOLOGY_LION;
>  static int battery_capacity		= 50;
>  static int battery_voltage		= 3300;
>  static int battery_charge_counter	= -1000;
> +static int battery_current		= 1600;
>  
>  static bool module_initialized;
>  
> @@ -118,6 +119,10 @@ static int test_power_get_battery_property(struct power_supply *psy,
>  	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
>  		val->intval = battery_voltage;
>  		break;
> +	case POWER_SUPPLY_PROP_CURRENT_AVG:
> +	case POWER_SUPPLY_PROP_CURRENT_NOW:
> +		val->intval = battery_current;
> +		break;
>  	default:
>  		pr_info("%s: some properties deliberately report errors.\n",
>  			__func__);
> @@ -149,6 +154,8 @@ static enum power_supply_property test_power_battery_props[] = {
>  	POWER_SUPPLY_PROP_SERIAL_NUMBER,
>  	POWER_SUPPLY_PROP_TEMP,
>  	POWER_SUPPLY_PROP_VOLTAGE_NOW,
> +	POWER_SUPPLY_PROP_CURRENT_AVG,
> +	POWER_SUPPLY_PROP_CURRENT_NOW,
>  };
>  
>  static char *test_power_ac_supplied_to[] = {
> @@ -467,6 +474,21 @@ static int param_set_battery_charge_counter(const char *key,
>  
>  #define param_get_battery_charge_counter param_get_int
>  
> +static int param_set_battery_current(const char *key,
> +					const struct kernel_param *kp)
> +{
> +	int tmp;
> +
> +	if (1 != sscanf(key, "%d", &tmp))
> +		return -EINVAL;
> +
> +	battery_current = tmp;
> +	signal_power_supply_changed(test_power_supplies[TEST_BATTERY]);
> +	return 0;
> +}
> +
> +#define param_get_battery_current param_get_int
> +
>  static const struct kernel_param_ops param_ops_ac_online = {
>  	.set = param_set_ac_online,
>  	.get = param_get_ac_online,
> @@ -512,6 +534,11 @@ static const struct kernel_param_ops param_ops_battery_charge_counter = {
>  	.get = param_get_battery_charge_counter,
>  };
>  
> +static const struct kernel_param_ops param_ops_battery_current = {
> +	.set = param_set_battery_current,
> +	.get = param_get_battery_current,
> +};
> +
>  #define param_check_ac_online(name, p) __param_check(name, p, void);
>  #define param_check_usb_online(name, p) __param_check(name, p, void);
>  #define param_check_battery_status(name, p) __param_check(name, p, void);
> @@ -521,6 +548,7 @@ static const struct kernel_param_ops param_ops_battery_charge_counter = {
>  #define param_check_battery_capacity(name, p) __param_check(name, p, void);
>  #define param_check_battery_voltage(name, p) __param_check(name, p, void);
>  #define param_check_battery_charge_counter(name, p) __param_check(name, p, void);
> +#define param_check_battery_current(name, p) __param_check(name, p, void);
>  
>  
>  module_param(ac_online, ac_online, 0644);
> @@ -555,6 +583,9 @@ module_param(battery_charge_counter, battery_charge_counter, 0644);
>  MODULE_PARM_DESC(battery_charge_counter,
>  	"battery charge counter (microampere-hours)");
>  
> +module_param(battery_current, battery_current, 0644);
> +MODULE_PARM_DESC(battery_current, "battery current (milliampere)");
> +
>  MODULE_DESCRIPTION("Power supply driver for testing");
>  MODULE_AUTHOR("Anton Vorontsov <cbouatmailru@gmail.com>");
>  MODULE_LICENSE("GPL");
> -- 
> 2.17.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-10-14 21:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-12 18:25 [PATCH v2 0/2] test_power: Add CHARGE_COUNTER and CURRENT properties lecopzer
2019-09-12 18:25 ` [PATCH v2 1/2] test_power: Add CHARGE_COUNTER properties lecopzer
2019-10-14  5:46   ` Sebastian Reichel
2019-09-12 18:26 ` [PATCH v2 2/2] test_power: Add CURRENT properties lecopzer
2019-10-14  5:46   ` Sebastian Reichel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).