From patchwork Fri Nov 25 09:09:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 84069 Delivered-To: patch@linaro.org Received: by 10.182.1.168 with SMTP id 8csp27227obn; Fri, 25 Nov 2016 01:13:24 -0800 (PST) X-Received: by 10.84.150.231 with SMTP id h94mr15303338plh.3.1480065204618; Fri, 25 Nov 2016 01:13:24 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id h65si43817221pfd.239.2016.11.25.01.13.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Nov 2016 01:13:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cACXp-0002LP-Ss; Fri, 25 Nov 2016 09:11:45 +0000 Received: from mail.free-electrons.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cACW7-0007lc-JP for linux-arm-kernel@lists.infradead.org; Fri, 25 Nov 2016 09:10:05 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id DF21120C89; Fri, 25 Nov 2016 10:09:37 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from qschulz.home (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 8EA5520BDF; Fri, 25 Nov 2016 10:09:37 +0100 (CET) From: Quentin Schulz To: sre@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com, wens@csie.org, linux@armlinux.org.uk, maxime.ripard@free-electrons.com, lee.jones@linaro.org Subject: [PATCH 02/10] power: supply: axp20x_usb_power: set min voltage and max current from sysfs Date: Fri, 25 Nov 2016 10:09:13 +0100 Message-Id: <20161125090921.23138-3-quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161125090921.23138-1-quentin.schulz@free-electrons.com> References: <20161125090921.23138-1-quentin.schulz@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161125_011000_330018_E67005BE X-CRM114-Status: GOOD ( 11.31 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- 1.0 FSL_HELO_HOME No description available. -0.0 SPF_PASS SPF: sender matches SPF record -1.4 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thomas.petazzoni@free-electrons.com, devicetree@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Quentin Schulz , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org AXP20X and AXP22X PMICs allow setting the min voltage and max current of VBUS power supply. This adds entries in sysfs to allow to do so. Signed-off-by: Quentin Schulz --- drivers/power/supply/axp20x_usb_power.c | 72 +++++++++++++++++++++++++++++++++ include/linux/mfd/axp20x.h | 3 ++ 2 files changed, 75 insertions(+) -- 2.9.3 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index b19754e..638cb52 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -155,6 +155,74 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, return 0; } +static int axp20x_usb_power_set_property(struct power_supply *psy, + enum power_supply_property psp, + const union power_supply_propval *val) +{ + struct axp20x_usb_power *power = power_supply_get_drvdata(psy); + int ret, val1; + + switch (psp) { + case POWER_SUPPLY_PROP_VOLTAGE_MIN: + switch (val->intval) { + case 4000000: + case 4100000: + case 4200000: + case 4300000: + case 4400000: + case 4500000: + case 4600000: + case 4700000: + val1 = (val->intval - 4000000) / 100000; + ret = regmap_update_bits(power->regmap, + AXP20X_VBUS_IPSOUT_MGMT, + AXP20X_VBUS_VHOLD_MASK, + val1 << 3); + if (ret) + return ret; + + return 0; + default: + return -EINVAL; + } + + return 0; + + case POWER_SUPPLY_PROP_CURRENT_MAX: + switch (val->intval) { + case 100000: + if (power->axp20x_id == AXP221_ID) + return -EINVAL; + case 500000: + case 900000: + val1 = (900000 - val->intval) / 400000; + ret = regmap_update_bits(power->regmap, + AXP20X_VBUS_IPSOUT_MGMT, + AXP20X_VBUS_CLIMIT_MASK, val1); + if (ret) + return ret; + + return 0; + default: + return -EINVAL; + } + + return 0; + + default: + return -EINVAL; + } + + return 0; +} + +static int axp20x_usb_power_prop_writeable(struct power_supply *psy, + enum power_supply_property psp) +{ + return psp == POWER_SUPPLY_PROP_VOLTAGE_MIN || + psp == POWER_SUPPLY_PROP_CURRENT_MAX; +} + static enum power_supply_property axp20x_usb_power_properties[] = { POWER_SUPPLY_PROP_HEALTH, POWER_SUPPLY_PROP_PRESENT, @@ -178,7 +246,9 @@ static const struct power_supply_desc axp20x_usb_power_desc = { .type = POWER_SUPPLY_TYPE_USB, .properties = axp20x_usb_power_properties, .num_properties = ARRAY_SIZE(axp20x_usb_power_properties), + .property_is_writeable = axp20x_usb_power_prop_writeable, .get_property = axp20x_usb_power_get_property, + .set_property = axp20x_usb_power_set_property, }; static const struct power_supply_desc axp22x_usb_power_desc = { @@ -186,7 +256,9 @@ static const struct power_supply_desc axp22x_usb_power_desc = { .type = POWER_SUPPLY_TYPE_USB, .properties = axp22x_usb_power_properties, .num_properties = ARRAY_SIZE(axp22x_usb_power_properties), + .property_is_writeable = axp20x_usb_power_prop_writeable, .get_property = axp20x_usb_power_get_property, + .set_property = axp20x_usb_power_set_property, }; static const struct of_device_id axp20x_usb_power_match[] = { diff --git a/include/linux/mfd/axp20x.h b/include/linux/mfd/axp20x.h index fec597f..8883595 100644 --- a/include/linux/mfd/axp20x.h +++ b/include/linux/mfd/axp20x.h @@ -56,6 +56,9 @@ enum { #define AXP20X_LDO24_V_OUT 0x28 #define AXP20X_LDO3_V_OUT 0x29 #define AXP20X_VBUS_IPSOUT_MGMT 0x30 + +#define AXP20X_VBUS_VHOLD_MASK GENMASK(5, 3) + #define AXP20X_V_OFF 0x31 #define AXP20X_OFF_CTRL 0x32 #define AXP20X_CHRG_CTRL1 0x33