Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1055826pxa; Wed, 12 Aug 2020 22:12:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytupowIpfmLqJUZaRYayNCEE+x8l52uhJJ1viUckS/YOVf8T7iyJuedtvR3vnbE1HjWMiM X-Received: by 2002:a17:906:8149:: with SMTP id z9mr3095593ejw.356.1597295570726; Wed, 12 Aug 2020 22:12:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597295570; cv=none; d=google.com; s=arc-20160816; b=MJRdur4Va/57QZF8gKjOuBO8ZVL9tZY/5qRClq426qbazd92W4iWOdvD+SNEWOSYzt 54vuDlbPZhcwdw1vbraEjP5ad5VD7fm0RnQLz1XerS56i/0d8IMM08wrk+T3UzB2IhpY vSfclxsRX6kGOimGOrC29jsuExKSANfnoh68xxCY2WBTJg4iCMl6vjFmJOMnmP3O0rRn pzP86RjbwhNGjLEN7tIACwTs1URdHy2KdoIy6KZ9aFeYE7+27J2SYWL0Bgr53u4xuZf5 cJzdPG7Ms1jqkHyHZCHiWb8fa+mCK9XuN95lkqFq7lZhukPNCRwbPUOFjxS19LVy0NEv DCxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tea+4k1B/HQFagig/As/WEVEROeIYcdzTJzUHMCDyq0=; b=aJTCv0Yj6jXp4/tupk07V78QnGM8sLbOszfEq+9cN8G2zMNgI8CXCZW6F97hymMRxD k6qxwXK6Wfpb39+kBFOSDCDIvbBJiClcIaN1NGVBcufceDupcSAuKHm8qzH5srjxJvme QZ6b6BsLac8zns5UV3LcTzqwjHUArP43VnLPWkqGC4sd1hme0Ge9rWTqplw6XwbWNF09 /EmaYmH+pf58tl+vlbnBK85KeDc8HD0Mc7O71qJwwhCxKhgXFdSNkGKYfItq4uMIGYOw lV20rJNZ+fJ3sOkjM0km1zs1QwRMhftafHpwA+4Rvaov9VLIrdi46J+5uIC+JFwObGnK RlPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CG3sm1We; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ch2si2669304edb.244.2020.08.12.22.12.27; Wed, 12 Aug 2020 22:12:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CG3sm1We; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726334AbgHMFLM (ORCPT + 99 others); Thu, 13 Aug 2020 01:11:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726042AbgHMFLL (ORCPT ); Thu, 13 Aug 2020 01:11:11 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C268FC061383 for ; Wed, 12 Aug 2020 22:11:11 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id 74so2192677pfx.13 for ; Wed, 12 Aug 2020 22:11:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tea+4k1B/HQFagig/As/WEVEROeIYcdzTJzUHMCDyq0=; b=CG3sm1WeX4MSMZlGZZmfrsCDMTBFRdu4ZhOKSJiLq8MMmTvf3+dlq5rShHooQxqwNJ WKUqw0ONXJCWqE7ijIl0Uf0nQcaYZLTqPFL+uYOs/uj8dzjwQPPHVoyVMvbXAwgOEALv 9YveoQgc+K8ing6MaFYJipqCivUwRMbyLlvyI= 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:mime-version:content-transfer-encoding; bh=tea+4k1B/HQFagig/As/WEVEROeIYcdzTJzUHMCDyq0=; b=EY9XDo3JsucGwnYxs/HIjc3LrLg4ORHoPlIXpWAtvD3dHJlqRYoR6FRuP31Z39nRy0 s9y29NzrLCGzCzBA5WOq0T+VkM9T+it4gO7l8wo2RkC2z0i2ACcCs2z51KgRvFoZWub+ RQI4dXciwOLI9r9dst83189hEd+jUcwEwqB3yctrooK8ad8M6jAdv0NHEkNjqBLPRWl/ 2eN0XnnT04wNX9uwU4Jk3GHDaAcTy5EyDOSDfYgj6Th2G5DbGGkj5munD9VExxGwA9SZ skuCb2hvyQuJOlBSLqpwTk+T0be6wycfFvr4Zkc63BMKWvHXsj6v8YboP8MRJdP982CH 8xBA== X-Gm-Message-State: AOAM532EA2+9U7NfTGmW7gVWPso1WjlzVWfBooND9H8BlIuFNOuaX2Pv sDyjyELG1b2o911ANSdKPP1PDQ== X-Received: by 2002:a63:cb0e:: with SMTP id p14mr2156402pgg.351.1597295471265; Wed, 12 Aug 2020 22:11:11 -0700 (PDT) Received: from ikjn-p920.tpe.corp.google.com ([2401:fa00:1:10:f693:9fff:fef4:a8fc]) by smtp.gmail.com with ESMTPSA id fh14sm3720153pjb.38.2020.08.12.22.11.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Aug 2020 22:11:10 -0700 (PDT) From: Ikjoon Jang To: Sebastian Reichel , linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, drinkcat@chromium.org, Ikjoon Jang Subject: [PATCH v3 1/2] power: supply: sbs-battery: combine get_presence_and_health Date: Thu, 13 Aug 2020 13:10:07 +0800 Message-Id: <20200813051008.3461515-2-ikjn@chromium.org> X-Mailer: git-send-email 2.28.0.236.gb10cc79966-goog In-Reply-To: <20200813051008.3461515-1-ikjn@chromium.org> References: <0200811065307.2094930-1-ikjn@chromium.org> <20200813051008.3461515-1-ikjn@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch enables calling sbs_get_battery_presence_and_health() without checking its chip type. No functional changes. Signed-off-by: Ikjoon Jang --- drivers/power/supply/sbs-battery.c | 73 +++++++++++++++--------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index 83b9924033bd..6acb4ea25d2a 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -389,37 +389,6 @@ static bool sbs_bat_needs_calibration(struct i2c_client *client) return !!(ret & BIT(7)); } -static int sbs_get_battery_presence_and_health( - struct i2c_client *client, enum power_supply_property psp, - union power_supply_propval *val) -{ - int ret; - - /* Dummy command; if it succeeds, battery is present. */ - ret = sbs_read_word_data(client, sbs_data[REG_STATUS].addr); - - if (ret < 0) { /* battery not present*/ - if (psp == POWER_SUPPLY_PROP_PRESENT) { - val->intval = 0; - return 0; - } - return ret; - } - - if (psp == POWER_SUPPLY_PROP_PRESENT) - val->intval = 1; /* battery present */ - else { /* POWER_SUPPLY_PROP_HEALTH */ - if (sbs_bat_needs_calibration(client)) { - val->intval = POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED; - } else { - /* SBS spec doesn't have a general health command. */ - val->intval = POWER_SUPPLY_HEALTH_UNKNOWN; - } - } - - return 0; -} - static int sbs_get_ti_battery_presence_and_health( struct i2c_client *client, enum power_supply_property psp, union power_supply_propval *val) @@ -478,6 +447,41 @@ static int sbs_get_ti_battery_presence_and_health( return 0; } +static int sbs_get_battery_presence_and_health( + struct i2c_client *client, enum power_supply_property psp, + union power_supply_propval *val) +{ + struct sbs_info *chip = i2c_get_clientdata(client); + int ret; + + if (chip->flags & SBS_FLAGS_TI_BQ20ZX5) + return sbs_get_ti_battery_presence_and_health(client, psp, val); + + /* Dummy command; if it succeeds, battery is present. */ + ret = sbs_read_word_data(client, sbs_data[REG_STATUS].addr); + + if (ret < 0) { /* battery not present*/ + if (psp == POWER_SUPPLY_PROP_PRESENT) { + val->intval = 0; + return 0; + } + return ret; + } + + if (psp == POWER_SUPPLY_PROP_PRESENT) + val->intval = 1; /* battery present */ + else { /* POWER_SUPPLY_PROP_HEALTH */ + if (sbs_bat_needs_calibration(client)) { + val->intval = POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED; + } else { + /* SBS spec doesn't have a general health command. */ + val->intval = POWER_SUPPLY_HEALTH_UNKNOWN; + } + } + + return 0; +} + static int sbs_get_battery_property(struct i2c_client *client, int reg_offset, enum power_supply_property psp, union power_supply_propval *val) @@ -780,12 +784,7 @@ static int sbs_get_property(struct power_supply *psy, switch (psp) { case POWER_SUPPLY_PROP_PRESENT: case POWER_SUPPLY_PROP_HEALTH: - if (chip->flags & SBS_FLAGS_TI_BQ20ZX5) - ret = sbs_get_ti_battery_presence_and_health(client, - psp, val); - else - ret = sbs_get_battery_presence_and_health(client, psp, - val); + ret = sbs_get_battery_presence_and_health(client, psp, val); /* this can only be true if no gpio is used */ if (psp == POWER_SUPPLY_PROP_PRESENT) -- 2.28.0.236.gb10cc79966-goog