From patchwork Wed Sep 9 00:12:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Dannenberg X-Patchwork-Id: 7143901 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F20419F1BF for ; Wed, 9 Sep 2015 00:14:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1302820650 for ; Wed, 9 Sep 2015 00:14:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B05E1207F2 for ; Wed, 9 Sep 2015 00:14:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754229AbbIIAOE (ORCPT ); Tue, 8 Sep 2015 20:14:04 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:45820 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754236AbbIIAOD (ORCPT ); Tue, 8 Sep 2015 20:14:03 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id t890DZs6016020; Tue, 8 Sep 2015 19:13:35 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id t890DZPl022382; Tue, 8 Sep 2015 19:13:35 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.224.2; Tue, 8 Sep 2015 19:13: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 t890D0S8019642; Tue, 8 Sep 2015 19:13:33 -0500 From: Andreas Dannenberg To: Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse , Laurentiu Palcu , Krzysztof Kozlowski CC: , , Andreas Dannenberg Subject: [PATCH v2 09/13] power: bq24257: Allow input current limit sysfs access Date: Tue, 8 Sep 2015 19:12:33 -0500 Message-ID: <1441757557-7266-10-git-send-email-dannenberg@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1441757557-7266-1-git-send-email-dannenberg@ti.com> References: <1441757557-7266-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 D+/D- USB signal-based charger type detection is disabled) of the input current limit through the POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT sysfs property. This allows userspace to see what charger was detected and to re-configure the maximum current drawn from the external supply at runtime based on system-level knowledge or user input. Signed-off-by: Andreas Dannenberg Reviewed-by: Laurentiu Palcu --- 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 886040c..f0602b3 100644 --- a/drivers/power/bq24257_charger.c +++ b/drivers/power/bq24257_charger.c @@ -315,6 +315,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) @@ -403,6 +438,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; } @@ -425,6 +464,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; } @@ -439,6 +481,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; @@ -778,6 +821,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[] = {