Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3500996ybl; Sun, 12 Jan 2020 19:54:32 -0800 (PST) X-Google-Smtp-Source: APXvYqyRCCbMgKS1a9+MXln+y835mFJW2kautceQhHHKp2gDLxqPST6zO5NjJgs9yCOP4xU9R6Fe X-Received: by 2002:aca:f354:: with SMTP id r81mr10659504oih.90.1578887672031; Sun, 12 Jan 2020 19:54:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578887672; cv=none; d=google.com; s=arc-20160816; b=TVKfrN8rWJNF9YYYM7QTu7cI5NRSVVz4fExVUKZL8R5KyG8f72JvfHCWdIfNhBUVu5 btBAP6nzt/XfYiF8Fdk+xR6o5LBlGJh5t038d4+eEsM3M0rLb4j4RNAMSfbEznohVarG zg1zwcnGlZgqRW34SnER0DiO8FQsm3n1wI6m5MpedhOBJm5ZbZd+P+5fZmG0CyQHmaiA pOVn9Ugvoq6M0uC9llydudsNqxKy3VXT2H6GJSsuwKAmb+P9SxeTypWv/CbReasU0/I3 K+t0ekAzmIIR+vmlQdfbpxMmrO+Wq4XhSK99W10v2PT/sx0K8VAa7tlkPvfkUkpSMghS R8kQ== 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:dkim-signature; bh=QsrYjH3pog1x9Yu7X2EoVn84/WFrvdNx4X6XL4205Xk=; b=bhZ1O+hDbV7LQ+ZASm6OWn+/tivXd3hWODHvUMNrsebXO613IFhFAO6q+FU9O8lqJI QE/QVKiyZwfNo1GvKGSuGtGWUE1nOAAYsCO1/cYWkDCPxZKNxBWzcP1FuJiHx0+hSTb7 fzt1+6Tqp0GhfJrL/Ablj3P09T38VvVrHg58DBobwv5+NA95Zuhepr+N7pDpO9FXQonf 0Nz/RoHoKYU+r2En/Zmxirb0B6kVjYTJD0EMj/yZlrby81VaPYi2RivCrWt514TyIupI mt5XG7SmordqV1ZoiqwFCcdvaWuIh/Le2VPshkfUfRCj4l6716VG9KH1o2hvj2yuSUNk TgLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sholland.org header.s=fm1 header.b=eVtmgj42; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=JAg9WQO1; 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 n9si6013667ota.103.2020.01.12.19.54.20; Sun, 12 Jan 2020 19:54:32 -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; dkim=pass header.i=@sholland.org header.s=fm1 header.b=eVtmgj42; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=JAg9WQO1; 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 S2387606AbgAMDxX (ORCPT + 99 others); Sun, 12 Jan 2020 22:53:23 -0500 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:45297 "EHLO out2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387569AbgAMDxP (ORCPT ); Sun, 12 Jan 2020 22:53:15 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 3ADDF21D46; Sun, 12 Jan 2020 22:53:14 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sun, 12 Jan 2020 22:53:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=QsrYjH3pog1x9 Yu7X2EoVn84/WFrvdNx4X6XL4205Xk=; b=eVtmgj42u4UmlaLcrp2/OMZbazRg9 8CPWcovnBhkxK3CetXjnPx9eQB6nVMzam7Xl9l8jbZjv1O7t9XYZjaV9B2msVZTr 4IF3zJfo/mObId+hHKDukSX+Mqo9Ko20enZ4HDywTRr0CnLdw0cMGrhiTvnvCKzo UsAf7Ytsf/u6ikVpw9OQXLyd50PsLXAI2jfbQQH8QvbYM0RxJZbyLuMnkIqVi9Wr X1QH1beimpKBo3dU7XYLGykpdnye9vScS/Ga/LLyYv9MjwwvGmejMqpYydiPOd5O jF2WzC0e0QspnJdRo/jpqKm9LOI5N7Zu9vtCGXxtNfDf6qwlz0h5TAxuA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=QsrYjH3pog1x9Yu7X2EoVn84/WFrvdNx4X6XL4205Xk=; b=JAg9WQO1 BhVDnSn12bWD6RmzG3CBXwQtf0HNy0F+mJyLyIfCo4swS1th+a7sSw5yGhFkbU7C 6wIfpTUmtYWurwGmvBTPfe3mwrNfCcelQjaQaRDR7c7DA+d24Xb1fqpOvPkSGOwf fCyzm3/fFatA/3Bq/FBBuKuSVjFWeB+D9n8FS9YuwiwIFwrQ2VHBDqIp1Ab69xFA Ae7iEaJmFAWFdJ4OEI8ZsnDUS9XYInpDds+LS8w5N6ufZBopHfMk/sUfIgjrsxFW IYcmDW9rv3mJge8mUZgJE4hZKdUhQaHmjRLIqblLC0jgQbTLTol6NxXujlpGIRh+ 1CpmHw8p36vGtw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdeiledgieeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucfkph epjedtrddufeehrddugeekrdduhedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehsrghm uhgvlhesshhhohhllhgrnhgurdhorhhgnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from titanium.stl.sholland.net (70-135-148-151.lightspeed.stlsmo.sbcglobal.net [70.135.148.151]) by mail.messagingengine.com (Postfix) with ESMTPA id 9FF8D8005B; Sun, 12 Jan 2020 22:53:13 -0500 (EST) From: Samuel Holland To: Chen-Yu Tsai , Sebastian Reichel , Oskari Lemmela Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Samuel Holland Subject: [PATCH v3 6/8] power: supply: axp20x_usb_power: Allow offlining Date: Sun, 12 Jan 2020 21:53:08 -0600 Message-Id: <20200113035310.18950-7-samuel@sholland.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200113035310.18950-1-samuel@sholland.org> References: <20200113035310.18950-1-samuel@sholland.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 AXP803/AXP813 have a flag that enables/disables the USB power supply input. Allow control of this flag via the ONLINE property on those variants. It may be necessary to offline the USB power supply input when using the USB port in OTG mode, or to allow userspace to disable charging. When the USB VBUS input is disabled via the PATH_SEL bit, the VBUS_USED bit in PWR_INPUT_STATUS is cleared, so there is no change needed when getting the property. Signed-off-by: Samuel Holland --- drivers/power/supply/axp20x_usb_power.c | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index cd89ee12dd18..3b3cc1e33f19 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -29,6 +29,9 @@ #define AXP20X_USB_STATUS_VBUS_VALID BIT(2) +#define AXP20X_VBUS_PATH_SEL BIT(7) +#define AXP20X_VBUS_PATH_SEL_OFFSET 7 + #define AXP20X_VBUS_VHOLD_uV(b) (4000000 + (((b) >> 3) & 7) * 100000) #define AXP20X_VBUS_VHOLD_MASK GENMASK(5, 3) #define AXP20X_VBUS_VHOLD_OFFSET 3 @@ -261,6 +264,16 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, return 0; } +static int axp813_usb_power_set_online(struct axp20x_usb_power *power, + int intval) +{ + int val = !intval << AXP20X_VBUS_PATH_SEL_OFFSET; + + return regmap_update_bits(power->regmap, + AXP20X_VBUS_IPSOUT_MGMT, + AXP20X_VBUS_PATH_SEL, val); +} + static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power, int intval) { @@ -342,6 +355,11 @@ static int axp20x_usb_power_set_property(struct power_supply *psy, struct axp20x_usb_power *power = power_supply_get_drvdata(psy); switch (psp) { + case POWER_SUPPLY_PROP_ONLINE: + if (power->axp20x_id != AXP813_ID) + return -EINVAL; + return axp813_usb_power_set_online(power, val->intval); + case POWER_SUPPLY_PROP_VOLTAGE_MIN: return axp20x_usb_power_set_voltage_min(power, val->intval); @@ -361,6 +379,18 @@ static int axp20x_usb_power_set_property(struct power_supply *psy, static int axp20x_usb_power_prop_writeable(struct power_supply *psy, enum power_supply_property psp) { + struct axp20x_usb_power *power = power_supply_get_drvdata(psy); + + /* + * The VBUS path select flag works differently on on AXP288 and newer: + * - On AXP20x and AXP22x, the flag enables VBUS (ignoring N_VBUSEN). + * - On AXP288 and AXP8xx, the flag disables VBUS (ignoring N_VBUSEN). + * We only expose the control on variants where it can be used to force + * the VBUS input offline. + */ + if (psp == POWER_SUPPLY_PROP_ONLINE) + return power->axp20x_id == AXP813_ID; + return psp == POWER_SUPPLY_PROP_VOLTAGE_MIN || psp == POWER_SUPPLY_PROP_CURRENT_MAX; } -- 2.23.0