Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp37062ybe; Thu, 12 Sep 2019 15:11:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzWZjCVi17BVEJ5gUD6SpxVqlQ+gJd+HshoP2PqNaS0Xn671Bz+kGIkDYtjJuOj5Sy+8nnd X-Received: by 2002:a17:906:f205:: with SMTP id gt5mr32127047ejb.279.1568326262135; Thu, 12 Sep 2019 15:11:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568326262; cv=none; d=google.com; s=arc-20160816; b=GFL0aMZK70Jic4Y4MmEr13StD5//dUH4DYGCWE1S3LuklELWRX3sLjdhNbadRyNfbp qH90Ifx+y2IjipHkoTMI7QvdrjahiR6o992CLMqUn1O1xD3TbkAPAs5o8U7RI6h7ENT+ j6xkShulTdr9DGdP3hMEq4R5x7VfWT9IzTGN0K1i30iHWuAnCt85XLsi/ST1cPTv4fvP RuovUH2fJ3q70SiWGbpeLRWigPJpmuA/cDcYeb87nTxHFG3iiUJWdOAw6Ujw9AeLhR5D 5b/Y3ja183N6yx7AOnkWZej7JmiwBCHXlYPWe4sgs1kfmK3bp4FKmENeNXknycJMPhde L7OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=JzxKcqXd0tvz5LO/KYD3/ViyFB8ewNV3niaA2nj26EY=; b=lsX1U5uvDCOttxR8nBRqHzqJFFAZM0ACfU57MCN2o1x8McXYe8QsYdWGAcX2gTNbUd DtpI2POwVtD0bwV8ASRuu78fqOEZW5M2SBU0QWGo0IXU9ryBWGbWYfyWU1/RxupKxcvA u1PUbp5wYNA4hydmM6+yokyNolbC+8I+2/zO5OnFygGq5SN6PVPACjmRsCWmEvK+pD2l UTbIX8WSMG0Rzc4yZFSClHwCkeMtA/i8XAViqrbkA7kK1EahNdAf5CsV7r01izzs3BLs W/KNTo3e+ubk28c+BjtGsHtvrbw9enPJ+yzrcMSrTmOv52UDAdhhy79ZPifNLuYhfu79 FaJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sICe4ZZr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o24si13286631ejb.296.2019.09.12.15.10.38; Thu, 12 Sep 2019 15:11:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sICe4ZZr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727157AbfILS00 (ORCPT + 99 others); Thu, 12 Sep 2019 14:26:26 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43614 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727041AbfILS0Z (ORCPT ); Thu, 12 Sep 2019 14:26:25 -0400 Received: by mail-pf1-f194.google.com with SMTP id d15so16482672pfo.10; Thu, 12 Sep 2019 11:26:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JzxKcqXd0tvz5LO/KYD3/ViyFB8ewNV3niaA2nj26EY=; b=sICe4ZZruTXL7Q4M72Lf+MAHFS976VA6f0RYw+X0z6F77rJBAUO5Ik0j1UUsfSsYiS o/xbGiQV7itYEVHw9fSmRwmOm8Gb4m0gpvUt2tHAXsFkcEvPcwYjN+W6nrnOxWhw1q1i wxrP4EuO//JoD8yVVkgh+pkSeOT71RzhsA7eI+O0K7yoKi6P42Yy0ciICxTXY5iXLpco oV8Dr5L+T4uqPE7thYaNuXnA6iZLKLlpoJbqQrApr03/wNcQcATt8UgjH3bTLKM75bHh 6Dqa+mi1iUrtYV905ktMx6CuA/nY0pPQtIdt0xW/PwgixQWhIGtf5mhx7bsnNsLu8Jin TiiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JzxKcqXd0tvz5LO/KYD3/ViyFB8ewNV3niaA2nj26EY=; b=Pjgv4nDlGdwCn+8s9MlS+5tpR22EK9ZP/QRzsn40UjHZgXkbWxCwL303RMe1aK93Xf Bw7Jzhw1a59G/Q/BxcmkPgDUWz/ECgxxotkIXjfJaFktXOjUUxFpXlQ4gOrIzm4vW1/y UTm+w2vuJs7ZW9TBqSyHreS8Xp8MHOFCgUJSRhPMgBsPWfqOaWxqX7rr1LJZTBeom49n hqlCdb+h01K0hkioE1YcmXb9xUV2fKxRoAq6AM/bCmrrVBZa3dESKZ9tWGtNIGyd5HEQ UcaFQbHmwv47RfHunNGyhO9f8puoN1pm3Vyitpigj6+yMNu8AmoCuaiZwjfY3caVjWSh JcQg== X-Gm-Message-State: APjAAAX567QMSWn2hdOab/yTtRZb7FjEoEWT3piBXq5lmQMWxjMkYTwM dSphg4WNOj2HScWYWSXS2EI= X-Received: by 2002:a17:90a:26e3:: with SMTP id m90mr64095pje.57.1568312784860; Thu, 12 Sep 2019 11:26:24 -0700 (PDT) Received: from localhost.localdomain (61-231-52-128.dynamic-ip.hinet.net. [61.231.52.128]) by smtp.gmail.com with ESMTPSA id r1sm20747382pgv.70.2019.09.12.11.26.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2019 11:26:24 -0700 (PDT) From: lecopzer@gmail.com X-Google-Original-From: lecopzer.chen@mediatek.com To: lecopzer@gmail.com, sre@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yj.chiang@mediatek.com, lecopzer.chen@mediatek.com Subject: [PATCH v2 1/2] test_power: Add CHARGE_COUNTER properties Date: Fri, 13 Sep 2019 02:25:59 +0800 Message-Id: <20190912182600.24211-2-lecopzer.chen@mediatek.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190912182600.24211-1-lecopzer.chen@mediatek.com> References: <20190912182600.24211-1-lecopzer.chen@mediatek.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 "); MODULE_LICENSE("GPL"); -- 2.17.1