From patchwork Tue Sep 1 02:10:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Dannenberg X-Patchwork-Id: 7102491 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 18AA9BEEC1 for ; Tue, 1 Sep 2015 02:12:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7627E2068F for ; Tue, 1 Sep 2015 02:11:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3BE2720698 for ; Tue, 1 Sep 2015 02:11:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754790AbbIACLv (ORCPT ); Mon, 31 Aug 2015 22:11:51 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:55512 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754794AbbIACLu (ORCPT ); Mon, 31 Aug 2015 22:11:50 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id t812BSmH028675; Mon, 31 Aug 2015 21:11:28 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id t812BSv0021097; Mon, 31 Aug 2015 21:11:28 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.224.2; Mon, 31 Aug 2015 21:11:28 -0500 Received: from beast.tx.rr.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id t812AkYb004175; Mon, 31 Aug 2015 21:11:25 -0500 From: Andreas Dannenberg To: Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse , Laurentiu Palcu , Krzysztof Kozlowski CC: , , Andreas Dannenberg Subject: [PATCH 10/13] power: bq24257: Add in_ilimit setting support Date: Mon, 31 Aug 2015 21:10:32 -0500 Message-ID: <1441073435-12349-11-git-send-email-dannenberg@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1441073435-12349-1-git-send-email-dannenberg@ti.com> References: <1441073435-12349-1-git-send-email-dannenberg@ti.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch allows reading (and writing, if the the automatic setting of in_ilimit is disabled) the input current limit through the POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT sysfs property. This property is being exposed as writable in order to allow userspace to re-configure the charge current at runtime based on system-level knowledge or user input. Signed-off-by: Andreas Dannenberg --- drivers/power/bq24257_charger.c | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/power/bq24257_charger.c b/drivers/power/bq24257_charger.c index 7b66030..42cc6fe 100644 --- a/drivers/power/bq24257_charger.c +++ b/drivers/power/bq24257_charger.c @@ -312,6 +312,41 @@ static int bq24257_set_charge_type(struct bq24257_device *bq, return bq24257_field_write(bq, F_CE, 0); } +static int bq24257_get_input_current_limit(struct bq24257_device *bq, + union power_supply_propval *val) +{ + int ret; + + ret = bq24257_field_read(bq, F_IILIMIT); + if (ret < 0) + return ret; + + /* + * The "External ILIM" and "Production & Test" modes are not exposed + * through this driver and not being covered by the lookup table. + * Should such a mode have become active let's return an error rather + * than exceeding the bounds of the lookup table and returning + * garbage. + */ + if (ret >= BQ24257_IILIMIT_MAP_SIZE) + return -ENODATA; + + val->intval = bq24257_iilimit_map[ret]; + + return 0; +} + +static int bq24257_set_input_current_limit(struct bq24257_device *bq, + const union power_supply_propval *val) +{ + if (!bq->in_ilimit_autoset_disable) + return -EPERM; + + return bq24257_field_write(bq, F_IILIMIT, bq24257_find_idx( + val->intval, bq24257_iilimit_map, + BQ24257_IILIMIT_MAP_SIZE)); +} + static int bq24257_power_supply_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) @@ -404,6 +439,10 @@ static int bq24257_power_supply_get_property(struct power_supply *psy, val->intval = bq24257_iterm_map[bq->init_data.iterm]; break; + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + ret = bq24257_get_input_current_limit(bq, val); + break; + default: ret = -EINVAL; } @@ -426,6 +465,9 @@ static int bq24257_power_supply_set_property(struct power_supply *psy, case POWER_SUPPLY_PROP_CHARGE_TYPE: ret = bq24257_set_charge_type(bq, val); break; + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + ret = bq24257_set_input_current_limit(bq, val); + break; default: ret = -EINVAL; } @@ -440,6 +482,7 @@ static int bq24257_power_supply_property_is_writeable(struct power_supply *psy, { switch (psp) { case POWER_SUPPLY_PROP_CHARGE_TYPE: + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: return true; default: return false; @@ -779,6 +822,7 @@ static enum power_supply_property bq24257_power_supply_props[] = { POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, + POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, }; static char *bq24257_charger_supplied_to[] = {