Received: by 10.223.185.116 with SMTP id b49csp5612780wrg; Tue, 27 Feb 2018 17:09:26 -0800 (PST) X-Google-Smtp-Source: AH8x227TlxzY5DxL1C6skld0Boq2X5NzZhVMNDI3WtMvj5/ZujtbDchjL1icbZqe6vSzdg8eat2q X-Received: by 2002:a17:902:b711:: with SMTP id d17-v6mr16018358pls.23.1519780166661; Tue, 27 Feb 2018 17:09:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519780166; cv=none; d=google.com; s=arc-20160816; b=m+GbYtFeiRinjxJnx21XK5zaLgoN+zNkCYVdKDJJvzsbeNg9UDd70dJxqZsMgrqPsc bulRo3Qvb22Ws+vV0cN9PjeY/pR5nDS2TihRY1RWld+lyHLIdV5B0LZSe0Op6BMdzWPw IwGAm1hYmQQgBJkMVumxl/vYwrnHm6Nq7a+dQOv3gjDX26MgAyXjOYn9EGK7CRpURH4Y UmHUjZBaUVm2inK38VZEYHMX+XnJp+F5HvkQb0E9FRgTOWzTRGEEKtbBo3Iyjq4H63VW /FtR2TH5YbMIou+OV+QwhOS6P2FhkRRtJUVhioj4hfBLbhYSdJHsDxnYMPbnoigAhQXB e3Gw== 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:arc-authentication-results; bh=r5fduV1tUTDk3f0J5UOoeu1OSLS8n+1xQ8IzYCgaToM=; b=A28RJ1xrSxQ3pG5qjqFFxvsMjwiW++6Za5ZNB8tiBmNaJHCLKiX/u6bQGBfYwBLAg5 O5J1kUFtOZCNYj8ofidEddno4jSrcUORFBNL4FlfOCsYBrSQNALpJQNbhrbmwKACtPLS z3L87pGB4k31cmRkXzOzeTdkCjOgeURjdkR+4Exo6SiC7KCVrdamaAGAItVYv2t3W9rL acYSAmp06D0AW1DU4jtKnAmhtsWvPrjzXesUryOFvMDjSG1WJU0JUG0Uu/XvfVUApYh8 qF9Z1AFvF5nwTUaOkzukH7eOhJnjGesO2SL+xNhY9SK0TMTstOizPWng6V7p9TeZqsBt Oh/g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r22si327287pfj.140.2018.02.27.17.09.11; Tue, 27 Feb 2018 17:09:26 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751934AbeB1BGl (ORCPT + 99 others); Tue, 27 Feb 2018 20:06:41 -0500 Received: from nala.villavu.com ([188.165.243.101]:44473 "EHLO nala.villavu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751463AbeB1BGS (ORCPT ); Tue, 27 Feb 2018 20:06:18 -0500 Received: from a82-161-36-93.adsl.xs4all.nl ([82.161.36.93] helo=chrometwo.fritz.box) by nala.villavu.com with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.85) (envelope-from ) id 1eqqCF-0003dd-8F; Wed, 28 Feb 2018 02:06:15 +0100 From: Merlijn Wajer To: linux-omap@vger.kernel.org Cc: merlijn@wizzup.org, =?UTF-8?q?Pali=20Roh=C3=A1r?= , "Andrew F. Davis" , Sebastian Reichel , Liam Breck , Matt Ranostay , Thomas Gleixner , Greg Kroah-Hartman , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/1] power: supply: bq27xxx: Call power_supply_changed on status change Date: Wed, 28 Feb 2018 02:04:44 +0100 Message-Id: <20180228010452.1713-2-merlijn@wizzup.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180228010452.1713-1-merlijn@wizzup.org> References: <20180228010452.1713-1-merlijn@wizzup.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Merlijn Wajer --- drivers/power/supply/bq27xxx_battery.c | 59 +++++++++++++++++----------------- include/linux/power/bq27xxx_battery.h | 1 + 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c index 0a203672744c..218d153fb431 100644 --- a/drivers/power/supply/bq27xxx_battery.c +++ b/drivers/power/supply/bq27xxx_battery.c @@ -1527,6 +1527,31 @@ static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di) return POWER_SUPPLY_HEALTH_GOOD; } +static int bq27xxx_battery_read_status(struct bq27xxx_device_info *di) +{ + int status; + + if (di->opts & BQ27XXX_O_ZERO) { + if (di->cache.flags & BQ27000_FLAG_FC) + status = POWER_SUPPLY_STATUS_FULL; + else if (di->cache.flags & BQ27000_FLAG_CHGS) + status = POWER_SUPPLY_STATUS_CHARGING; + else if (power_supply_am_i_supplied(di->bat) > 0) + status = POWER_SUPPLY_STATUS_NOT_CHARGING; + else + status = POWER_SUPPLY_STATUS_DISCHARGING; + } else { + if (di->cache.flags & BQ27XXX_FLAG_FC) + status = POWER_SUPPLY_STATUS_FULL; + else if (di->cache.flags & BQ27XXX_FLAG_DSC) + status = POWER_SUPPLY_STATUS_DISCHARGING; + else + status = POWER_SUPPLY_STATUS_CHARGING; + } + + return status; +} + void bq27xxx_battery_update(struct bq27xxx_device_info *di) { struct bq27xxx_reg_cache cache = {0, }; @@ -1547,6 +1572,7 @@ void bq27xxx_battery_update(struct bq27xxx_device_info *di) cache.time_to_full = -ENODATA; cache.charge_full = -ENODATA; cache.health = -ENODATA; + cache.status = bq27xxx_battery_read_status(di); } else { if (di->regs[BQ27XXX_REG_TTE] != INVALID_REG_ADDR) cache.time_to_empty = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTE); @@ -1559,6 +1585,7 @@ void bq27xxx_battery_update(struct bq27xxx_device_info *di) if (di->regs[BQ27XXX_REG_AE] != INVALID_REG_ADDR) cache.energy = bq27xxx_battery_read_energy(di); cache.health = bq27xxx_battery_read_health(di); + cache.status = bq27xxx_battery_read_status(di); } if (di->regs[BQ27XXX_REG_CYCT] != INVALID_REG_ADDR) cache.cycle_count = bq27xxx_battery_read_cyct(di); @@ -1570,7 +1597,7 @@ void bq27xxx_battery_update(struct bq27xxx_device_info *di) di->charge_design_full = bq27xxx_battery_read_dcap(di); } - if (di->cache.capacity != cache.capacity) + if ((di->cache.capacity != cache.capacity) || (di->cache.status != cache.status)) power_supply_changed(di->bat); if (memcmp(&di->cache, &cache, sizeof(cache)) != 0) @@ -1625,34 +1652,6 @@ static int bq27xxx_battery_current(struct bq27xxx_device_info *di, return 0; } -static int bq27xxx_battery_status(struct bq27xxx_device_info *di, - union power_supply_propval *val) -{ - int status; - - if (di->opts & BQ27XXX_O_ZERO) { - if (di->cache.flags & BQ27000_FLAG_FC) - status = POWER_SUPPLY_STATUS_FULL; - else if (di->cache.flags & BQ27000_FLAG_CHGS) - status = POWER_SUPPLY_STATUS_CHARGING; - else if (power_supply_am_i_supplied(di->bat) > 0) - status = POWER_SUPPLY_STATUS_NOT_CHARGING; - else - status = POWER_SUPPLY_STATUS_DISCHARGING; - } else { - if (di->cache.flags & BQ27XXX_FLAG_FC) - status = POWER_SUPPLY_STATUS_FULL; - else if (di->cache.flags & BQ27XXX_FLAG_DSC) - status = POWER_SUPPLY_STATUS_DISCHARGING; - else - status = POWER_SUPPLY_STATUS_CHARGING; - } - - val->intval = status; - - return 0; -} - static int bq27xxx_battery_capacity_level(struct bq27xxx_device_info *di, union power_supply_propval *val) { @@ -1733,7 +1732,7 @@ static int bq27xxx_battery_get_property(struct power_supply *psy, switch (psp) { case POWER_SUPPLY_PROP_STATUS: - ret = bq27xxx_battery_status(di, val); + ret = bq27xxx_simple_value(di->cache.status, val); break; case POWER_SUPPLY_PROP_VOLTAGE_NOW: ret = bq27xxx_battery_voltage(di, val); diff --git a/include/linux/power/bq27xxx_battery.h b/include/linux/power/bq27xxx_battery.h index e6187f524f2c..4f27656045fd 100644 --- a/include/linux/power/bq27xxx_battery.h +++ b/include/linux/power/bq27xxx_battery.h @@ -49,6 +49,7 @@ struct bq27xxx_reg_cache { int flags; int power_avg; int health; + int status; }; struct bq27xxx_device_info { -- 2.16.2