From patchwork Sun Jan 5 01:24:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 11318015 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E8426109A for ; Sun, 5 Jan 2020 01:24:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C636A24654 for ; Sun, 5 Jan 2020 01:24:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sholland.org header.i=@sholland.org header.b="QpxIgctn"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="We0UrstP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726333AbgAEBYS (ORCPT ); Sat, 4 Jan 2020 20:24:18 -0500 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:39455 "EHLO new2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726264AbgAEBYS (ORCPT ); Sat, 4 Jan 2020 20:24:18 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailnew.nyi.internal (Postfix) with ESMTP id 4AF99680A; Sat, 4 Jan 2020 20:24:17 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sat, 04 Jan 2020 20:24:17 -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=Dy/48p0+s/ET+ odKrtmc7mwr7XKM2LA6Yht3eu1MaYw=; b=QpxIgctnPZ3mHAnssfna7Js1Rr7DD UaQ8O6wSZcj840SbVEGu2CyHLfvnmpPqgJva4qDcrcFbCEG84NeOCLSCCuhmufo6 rujogvd3Ln/JDbe8tHo+cSBi5lf/jQXVBI+G0dTTo5cHNCab/V/TSmy/bIhg1lUC LrPeJIlKLGn7iHz+razqXb+AEq52XC29CLKMO/6gNSDqrG5PJNDceUA+IvIwDxJr OFTZXnllTcwjSmFxb6QNmIn+IcJ2bBSf9lkK/kzDjIpcnzolq1OhCgfNPQ8OHQpX t+osBJlBj3TphvJlPJUmnW7eb9RQxYXSHlb/vdpqdswdkhRplxnoH3ptQ== 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=Dy/48p0+s/ET+odKrtmc7mwr7XKM2LA6Yht3eu1MaYw=; b=We0UrstP 9RSLZMwzNQ3GPWwdRcK+ZsyRJn7TH4hmnMsY2IfLjA0yh+ydXqse/zC+UGWcRTaA vYyPcla2157BdGD5+8sYhGM5gIE4SpHZrIa8W1287KtlJ4bqHtRN8fzrBUathnNy gGBcAmas+tx0oLAL6GqKljCd1gdht04cJtHtpdmcXT6nJ7sp8aWBT3tqYOhNuqu2 BBqAKKUjRNxPlTxBN45Gp2cFNagXW53gjBoeGrL3mM2zxBX65see6yjWiP4p5A79 UIDAxQqQOnBjvozfH6TYpIAHy37GJNBdo+ewtfhd+GjSFMf0i7WaWyKOZEF3tmVD in55fiszPhJ/Gw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdegiedgfeegucetufdoteggodetrfdotf 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 6D58A80059; Sat, 4 Jan 2020 20:24:16 -0500 (EST) From: Samuel Holland To: Chen-Yu Tsai , Sebastian Reichel , Lee Jones , Hans de Goede , Oskari Lemmela , Quentin Schulz Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Samuel Holland , stable@vger.kernel.org Subject: [PATCH v2 1/9] mfd: axp20x: Mark AXP20X_VBUS_IPSOUT_MGMT as volatile Date: Sat, 4 Jan 2020 19:24:08 -0600 Message-Id: <20200105012416.23296-2-samuel@sholland.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200105012416.23296-1-samuel@sholland.org> References: <20200105012416.23296-1-samuel@sholland.org> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org On AXP288 and newer PMICs, bit 7 of AXP20X_VBUS_IPSOUT_MGMT can be set to prevent using the VBUS input. However, when the VBUS unplugged and plugged back in, the bit automatically resets to zero. We need to set the register as volatile to prevent regmap from caching that bit. Otherwise, regcache will think the bit is already set and not write the register. Fixes: cd53216625a0 ("mfd: axp20x: Fix axp288 volatile ranges") Cc: stable@vger.kernel.org Signed-off-by: Samuel Holland Reviewed-by: Chen-Yu Tsai --- drivers/mfd/axp20x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c index a4aaadaa0cb0..aa59496e4376 100644 --- a/drivers/mfd/axp20x.c +++ b/drivers/mfd/axp20x.c @@ -126,7 +126,7 @@ static const struct regmap_range axp288_writeable_ranges[] = { static const struct regmap_range axp288_volatile_ranges[] = { regmap_reg_range(AXP20X_PWR_INPUT_STATUS, AXP288_POWER_REASON), regmap_reg_range(AXP288_BC_GLOBAL, AXP288_BC_GLOBAL), - regmap_reg_range(AXP288_BC_DET_STAT, AXP288_BC_DET_STAT), + regmap_reg_range(AXP288_BC_DET_STAT, AXP20X_VBUS_IPSOUT_MGMT), regmap_reg_range(AXP20X_CHRG_BAK_CTRL, AXP20X_CHRG_BAK_CTRL), regmap_reg_range(AXP20X_IRQ1_EN, AXP20X_IPSOUT_V_HIGH_L), regmap_reg_range(AXP20X_TIMER_CTRL, AXP20X_TIMER_CTRL), From patchwork Sun Jan 5 01:24:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 11318013 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A4A514E3 for ; Sun, 5 Jan 2020 01:24:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 497D02465E for ; Sun, 5 Jan 2020 01:24:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sholland.org header.i=@sholland.org header.b="cCm48MGn"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="xvwRI77p" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726446AbgAEBYT (ORCPT ); Sat, 4 Jan 2020 20:24:19 -0500 Received: from new2-smtp.messagingengine.com ([66.111.4.224]:57263 "EHLO new2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726281AbgAEBYS (ORCPT ); Sat, 4 Jan 2020 20:24:18 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailnew.nyi.internal (Postfix) with ESMTP id A4FFF6BA3; Sat, 4 Jan 2020 20:24:17 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sat, 04 Jan 2020 20:24:17 -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=i9U9QABLYUJVc RUEMaC1sX18u3bMrWhbzdwLPT/XxuQ=; b=cCm48MGnRDJGDgnBFe+6YfL49S2ES PDNt4lS6MAUOAIkHj0H75nxOxqQUQnrK3l5g8WXjpJaQTlRXaRkt0LUnlmxrFNAI EDsVCM64h7Ah859EE1uMaIvU4M7CSzME0gD26PI6ba0+ee5j0//eb9+LJgOwq3uR KW+VPEygn4b8PTxYMnY65KkpbJKPe9H2q3ssAbx4QOLgUVei51/il9c3QQy/9We7 V63lDd03wtt9fQS/KAuwVCAt6ZBq1n+Z+svyrqgssFvMJ1p6mPRSWvs+p49oe+aM VZh2kswgIjrXgsVm81lZs7hRwiMjftIy1QiJ1W0HxaKHixj8/6Ka7vYyA== 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=i9U9QABLYUJVcRUEMaC1sX18u3bMrWhbzdwLPT/XxuQ=; b=xvwRI77p m0tSOjEby4PXvJOeAdnCPexlXOyxq3DqqKAHLAdprilfKfl/nwAYLhEAqWfu9TVK FpYlTCY44aBSl4j6sMOWEEOdpidBecLPGryvxbCPOuyyrQbIIl9q43UoLa9AdEPM yzZ6CTeqdi6CUJMOgpX66FBg18A8IQlrUIRAjAzN4wHrnJqYHI977bDjX/+0wCo1 KuoB1L75KCZzxJd4p2xqztNtU18YPXoEv47aoXAOtKHYFayziHeEhsL89yjmN2K2 PkYmoPIcU3Kq/6lL5SS69qvLi65vFLu2cD1GfpSOzj2zZSzI8Amteg4fi3W257Hb oNLNIapANrLk3Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdegiedgfeegucetufdoteggodetrfdotf 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 E9B778005A; Sat, 4 Jan 2020 20:24:16 -0500 (EST) From: Samuel Holland To: Chen-Yu Tsai , Sebastian Reichel , Lee Jones , Hans de Goede , Oskari Lemmela , Quentin Schulz Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Samuel Holland , stable@vger.kernel.org Subject: [PATCH v2 2/9] power: supply: axp20x_ac_power: Fix reporting online status Date: Sat, 4 Jan 2020 19:24:09 -0600 Message-Id: <20200105012416.23296-3-samuel@sholland.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200105012416.23296-1-samuel@sholland.org> References: <20200105012416.23296-1-samuel@sholland.org> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org AXP803/AXP813 have a flag that enables/disables the AC power supply input. This flag does not affect the status bits in PWR_INPUT_STATUS. Its effect can be verified by checking the battery charge/discharge state (bit 2 of PWR_INPUT_STATUS), or by examining the current draw on the AC input. Take this flag into account when getting the ONLINE property of the AC input, on PMICs where this flag is present. Fixes: 7693b5643fd2 ("power: supply: add AC power supply driver for AXP813") Cc: stable@vger.kernel.org Signed-off-by: Samuel Holland Reviewed-by: Chen-Yu Tsai --- drivers/power/supply/axp20x_ac_power.c | 31 +++++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/drivers/power/supply/axp20x_ac_power.c b/drivers/power/supply/axp20x_ac_power.c index 0d34a932b6d5..ca0a28f72a27 100644 --- a/drivers/power/supply/axp20x_ac_power.c +++ b/drivers/power/supply/axp20x_ac_power.c @@ -23,6 +23,8 @@ #define AXP20X_PWR_STATUS_ACIN_PRESENT BIT(7) #define AXP20X_PWR_STATUS_ACIN_AVAIL BIT(6) +#define AXP813_ACIN_PATH_SEL BIT(7) + #define AXP813_VHOLD_MASK GENMASK(5, 3) #define AXP813_VHOLD_UV_TO_BIT(x) ((((x) / 100000) - 40) << 3) #define AXP813_VHOLD_REG_TO_UV(x) \ @@ -40,6 +42,7 @@ struct axp20x_ac_power { struct power_supply *supply; struct iio_channel *acin_v; struct iio_channel *acin_i; + bool has_acin_path_sel; }; static irqreturn_t axp20x_ac_power_irq(int irq, void *devid) @@ -86,6 +89,17 @@ static int axp20x_ac_power_get_property(struct power_supply *psy, return ret; val->intval = !!(reg & AXP20X_PWR_STATUS_ACIN_AVAIL); + + /* ACIN_PATH_SEL disables ACIN even if ACIN_AVAIL is set. */ + if (power->has_acin_path_sel) { + ret = regmap_read(power->regmap, AXP813_ACIN_PATH_CTRL, + ®); + if (ret) + return ret; + + val->intval &= !!(reg & AXP813_ACIN_PATH_SEL); + } + return 0; case POWER_SUPPLY_PROP_VOLTAGE_NOW: @@ -224,21 +238,25 @@ static const struct power_supply_desc axp813_ac_power_desc = { struct axp_data { const struct power_supply_desc *power_desc; bool acin_adc; + bool acin_path_sel; }; static const struct axp_data axp20x_data = { - .power_desc = &axp20x_ac_power_desc, - .acin_adc = true, + .power_desc = &axp20x_ac_power_desc, + .acin_adc = true, + .acin_path_sel = false, }; static const struct axp_data axp22x_data = { - .power_desc = &axp22x_ac_power_desc, - .acin_adc = false, + .power_desc = &axp22x_ac_power_desc, + .acin_adc = false, + .acin_path_sel = false, }; static const struct axp_data axp813_data = { - .power_desc = &axp813_ac_power_desc, - .acin_adc = false, + .power_desc = &axp813_ac_power_desc, + .acin_adc = false, + .acin_path_sel = true, }; static int axp20x_ac_power_probe(struct platform_device *pdev) @@ -282,6 +300,7 @@ static int axp20x_ac_power_probe(struct platform_device *pdev) } power->regmap = dev_get_regmap(pdev->dev.parent, NULL); + power->has_acin_path_sel = axp_data->acin_path_sel; platform_set_drvdata(pdev, power); From patchwork Sun Jan 5 01:24:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 11317995 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DF564109A for ; Sun, 5 Jan 2020 01:24:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC2A724685 for ; Sun, 5 Jan 2020 01:24:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sholland.org header.i=@sholland.org header.b="Tuu+H7gG"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="C7W3q8EU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726548AbgAEBYV (ORCPT ); Sat, 4 Jan 2020 20:24:21 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:37327 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726373AbgAEBYT (ORCPT ); Sat, 4 Jan 2020 20:24:19 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 2B79521B5A; Sat, 4 Jan 2020 20:24:18 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sat, 04 Jan 2020 20:24:18 -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=+oIatr2C8rE1v lG4UtXIKFhzyVIliPbeiuok48925P8=; b=Tuu+H7gGssKemeSF0FmHrsgcgGpvP TTDQJfOMdQVtOZE7ACyIEBJH8tApgyZ9erLHjMIYgXBS+sBeGL0ZFOBjYpjf16ZG lwSGpFar2kVypWdZeKzv7KJQ7sN0cuFdCBrubYfukOVaxOZVHYkr0HsHo6auxNFL dtyjqY37TKb1jczruJf1ejhyZRbhKUlo1kalcQHKyzoStrQLXVBfC5OsyJypsXiB abUYZy3Iv3Xd/ApY1Rs0byur6C+AXaDOUFlUPVASITL4nZWfhdfymg333CzEgcIl KOLasEi470v6ZDi6vi4kn955DFhgpcU7IeILJNYtduQlk51h8N5rlSVdg== 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=+oIatr2C8rE1vlG4UtXIKFhzyVIliPbeiuok48925P8=; b=C7W3q8EU 9wInHZpikBAeNqAv0sz8pqcDbafAPmCN9/fn8PVC8Q728QkBU6O+0LBJ4J68w7VG ECdc8lxxRO8P94w2BZ/xVUwjpChyYgsUkXAq5y7t7GXUMZFp2mNTqr38qCPqK489 /0A04w5QavfSN45G0zau6VnfFGFuCFJjPKWFzShLc+GeNutBUB/hEytyUY2hev/K G3uthueZvCvcazqNfHicody796g/UtCGISR/XxDUQNmAqR9rAcmGtp7W3FkNKzyq pM9iSHgrimk8noS7dC2rJCpZ+okLY5ZzQaCJMOANeLVKYZzkmGUXufuibn7O5qAc u7jOIZYwGfQl2Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdegiedgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucfkph epjedtrddufeehrddugeekrdduhedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehsrghm uhgvlhesshhhohhllhgrnhgurdhorhhgnecuvehluhhsthgvrhfuihiivgepvd 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 7711A80059; Sat, 4 Jan 2020 20:24:17 -0500 (EST) From: Samuel Holland To: Chen-Yu Tsai , Sebastian Reichel , Lee Jones , Hans de Goede , Oskari Lemmela , Quentin Schulz Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Samuel Holland Subject: [PATCH v2 3/9] power: supply: axp20x_ac_power: Allow offlining Date: Sat, 4 Jan 2020 19:24:10 -0600 Message-Id: <20200105012416.23296-4-samuel@sholland.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200105012416.23296-1-samuel@sholland.org> References: <20200105012416.23296-1-samuel@sholland.org> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org AXP803/AXP813 have a flag that enables/disables the AC power supply input. Allow control of this flag via the ONLINE property on those variants. Signed-off-by: Samuel Holland Reviewed-by: Chen-Yu Tsai --- drivers/power/supply/axp20x_ac_power.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/axp20x_ac_power.c b/drivers/power/supply/axp20x_ac_power.c index ca0a28f72a27..bc2663cd47fa 100644 --- a/drivers/power/supply/axp20x_ac_power.c +++ b/drivers/power/supply/axp20x_ac_power.c @@ -24,6 +24,7 @@ #define AXP20X_PWR_STATUS_ACIN_AVAIL BIT(6) #define AXP813_ACIN_PATH_SEL BIT(7) +#define AXP813_ACIN_PATH_SEL_TO_BIT(x) (!!(x) << 7) #define AXP813_VHOLD_MASK GENMASK(5, 3) #define AXP813_VHOLD_UV_TO_BIT(x) ((((x) / 100000) - 40) << 3) @@ -157,6 +158,11 @@ static int axp813_ac_power_set_property(struct power_supply *psy, struct axp20x_ac_power *power = power_supply_get_drvdata(psy); switch (psp) { + case POWER_SUPPLY_PROP_ONLINE: + return regmap_update_bits(power->regmap, AXP813_ACIN_PATH_CTRL, + AXP813_ACIN_PATH_SEL, + AXP813_ACIN_PATH_SEL_TO_BIT(val->intval)); + case POWER_SUPPLY_PROP_VOLTAGE_MIN: if (val->intval < 4000000 || val->intval > 4700000) return -EINVAL; @@ -183,7 +189,8 @@ static int axp813_ac_power_set_property(struct power_supply *psy, static int axp813_ac_power_prop_writeable(struct power_supply *psy, enum power_supply_property psp) { - return psp == POWER_SUPPLY_PROP_VOLTAGE_MIN || + return psp == POWER_SUPPLY_PROP_ONLINE || + psp == POWER_SUPPLY_PROP_VOLTAGE_MIN || psp == POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT; } From patchwork Sun Jan 5 01:24:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 11318003 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2EBE8138D for ; Sun, 5 Jan 2020 01:24:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F1CA82465E for ; Sun, 5 Jan 2020 01:24:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sholland.org header.i=@sholland.org header.b="Bmngpm/p"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="H9rY78IO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726515AbgAEBYU (ORCPT ); Sat, 4 Jan 2020 20:24:20 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:46859 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726264AbgAEBYT (ORCPT ); Sat, 4 Jan 2020 20:24:19 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id ACB4C21B62; Sat, 4 Jan 2020 20:24:18 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sat, 04 Jan 2020 20:24:18 -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=WrStUasd4Cc83 ADtqUJg0NBcBBfCEyykALqqb1HDxp0=; b=Bmngpm/p82u8HlP8dz+JVbgpI0tV4 V/s5M75CDS0laVWRnoHAX1taL1WU0A3IF9aG9BFT7TtlT49jEWqq0MLtMUj6gb61 5S7nj+jabFawxBU1XgRv3J5DpggvfNPflMWtreg3hgN5UTdmmfTE04A0CEt+m/RA s07CSYTlPZdcPKktq67MVvX2dpOdOlPP5DrqN0k94dq8u/7JiwjesiVbLbhq64eB BTHmDaMCcNnzyYJWmWFgslt59MZl1WdGiKpjMBjdQuDeQCqqxWQVYxN3YI8aaP0+ HHHNmvX25ol+BkC+1YsoR9fiKOevB/UFQ1HCPyaSSY1sqaJKqSUaPMdlg== 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=WrStUasd4Cc83ADtqUJg0NBcBBfCEyykALqqb1HDxp0=; b=H9rY78IO aP7yVg65WG7IvewRQlW+irQdD8dX/AptJVHGHVU4UOmS6VTNewm9UR0h7e5vUf00 RCdKj3iOjC08cEXxaBkem+wMhfmTLa+5uiDH0qSzXRkXKq/EKmfxa+JWrNiFd3rY T/kiqAvx7wBtMNmvJh4Tbjp9Z/Cu6rs4Od9YB1qQzQBSUG0gcrINQZaCvQr1R5qs nOUt5qVTUKp8l6PS7Tp+4PJocKRux8Iyp6Ml47YFnJOvTqUj2ahLgB69YV6gOEg0 E2M2XJQcUDzJkL/xowSiUpfptiipBz4c4PS0t1xJr1OcEwY49mQfbN/Gcd/0uG1R ++qe4KpmioKL9Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdegiedgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucfkph epjedtrddufeehrddugeekrdduhedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehsrghm uhgvlhesshhhohhllhgrnhgurdhorhhgnecuvehluhhsthgvrhfuihiivgepvd 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 0016980061; Sat, 4 Jan 2020 20:24:17 -0500 (EST) From: Samuel Holland To: Chen-Yu Tsai , Sebastian Reichel , Lee Jones , Hans de Goede , Oskari Lemmela , Quentin Schulz Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Samuel Holland Subject: [PATCH v2 4/9] power: supply: axp20x_ac_power: Add wakeup control Date: Sat, 4 Jan 2020 19:24:11 -0600 Message-Id: <20200105012416.23296-5-samuel@sholland.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200105012416.23296-1-samuel@sholland.org> References: <20200105012416.23296-1-samuel@sholland.org> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The AC power supply input can be used as a wakeup source. Hook up the ACIN_PLUGIN IRQ to trigger wakeup based on userspace configuration. To do this, we must remember the list of IRQs for the life of the device. To know how much space to allocate for the flexible array member, we switch from using a NULL sentinel to using an array length. Because we now depend on the specific order of the IRQs (we assume ACIN_PLUGIN is first and always present), failing to acquire an IRQ during probe must be a fatal error. To avoid spuriously waking up the system when the AC power supply is not configured as a wakeup source, we must explicitly disable all non- wake IRQs during system suspend. This is because the SoC's NMI input is shared among all IRQs on the AXP PMIC. Due to the use of regmap-irq, the individual IRQs within the PMIC are nested threaded interrupts, and are therefore not automatically disabled during system suspend. The upshot is that if any other device within the MFD (such as the power key) is an enabled wakeup source, all enabled IRQs within the PMIC will cause wakeup. We still need to call enable_irq_wake() when we *do* want wakeup, in case those other wakeup sources on the PMIC are all disabled. Signed-off-by: Samuel Holland Reviewed-by: Chen-Yu Tsai Reviewed-by: Chen-Yu Tsai --- drivers/power/supply/axp20x_ac_power.c | 91 +++++++++++++++++++++----- 1 file changed, 74 insertions(+), 17 deletions(-) diff --git a/drivers/power/supply/axp20x_ac_power.c b/drivers/power/supply/axp20x_ac_power.c index bc2663cd47fa..177b5c1eee8f 100644 --- a/drivers/power/supply/axp20x_ac_power.c +++ b/drivers/power/supply/axp20x_ac_power.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,8 @@ struct axp20x_ac_power { struct iio_channel *acin_v; struct iio_channel *acin_i; bool has_acin_path_sel; + unsigned int num_irqs; + unsigned int irqs[]; }; static irqreturn_t axp20x_ac_power_irq(int irq, void *devid) @@ -242,38 +245,86 @@ static const struct power_supply_desc axp813_ac_power_desc = { .set_property = axp813_ac_power_set_property, }; +static const char * const axp20x_irq_names[] = { + "ACIN_PLUGIN", + "ACIN_REMOVAL", +}; + struct axp_data { const struct power_supply_desc *power_desc; + const char * const *irq_names; + unsigned int num_irq_names; bool acin_adc; bool acin_path_sel; }; static const struct axp_data axp20x_data = { .power_desc = &axp20x_ac_power_desc, + .irq_names = axp20x_irq_names, + .num_irq_names = ARRAY_SIZE(axp20x_irq_names), .acin_adc = true, .acin_path_sel = false, }; static const struct axp_data axp22x_data = { .power_desc = &axp22x_ac_power_desc, + .irq_names = axp20x_irq_names, + .num_irq_names = ARRAY_SIZE(axp20x_irq_names), .acin_adc = false, .acin_path_sel = false, }; static const struct axp_data axp813_data = { .power_desc = &axp813_ac_power_desc, + .irq_names = axp20x_irq_names, + .num_irq_names = ARRAY_SIZE(axp20x_irq_names), .acin_adc = false, .acin_path_sel = true, }; +#ifdef CONFIG_PM_SLEEP +static int axp20x_ac_power_suspend(struct device *dev) +{ + struct axp20x_ac_power *power = dev_get_drvdata(dev); + int i = 0; + + /* + * Allow wake via ACIN_PLUGIN only. + * + * As nested threaded IRQs are not automatically disabled during + * suspend, we must explicitly disable the remainder of the IRQs. + */ + if (device_may_wakeup(&power->supply->dev)) + enable_irq_wake(power->irqs[i++]); + while (i < power->num_irqs) + disable_irq(power->irqs[i++]); + + return 0; +} + +static int axp20x_ac_power_resume(struct device *dev) +{ + struct axp20x_ac_power *power = dev_get_drvdata(dev); + int i = 0; + + if (device_may_wakeup(&power->supply->dev)) + disable_irq_wake(power->irqs[i++]); + while (i < power->num_irqs) + enable_irq(power->irqs[i++]); + + return 0; +} +#endif + +static SIMPLE_DEV_PM_OPS(axp20x_ac_power_pm_ops, axp20x_ac_power_suspend, + axp20x_ac_power_resume); + static int axp20x_ac_power_probe(struct platform_device *pdev) { struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); struct power_supply_config psy_cfg = {}; struct axp20x_ac_power *power; const struct axp_data *axp_data; - static const char * const irq_names[] = { "ACIN_PLUGIN", "ACIN_REMOVAL", - NULL }; int i, irq, ret; if (!of_device_is_available(pdev->dev.of_node)) @@ -284,12 +335,14 @@ static int axp20x_ac_power_probe(struct platform_device *pdev) return -EINVAL; } - power = devm_kzalloc(&pdev->dev, sizeof(*power), GFP_KERNEL); + axp_data = of_device_get_match_data(&pdev->dev); + + power = devm_kzalloc(&pdev->dev, + struct_size(power, irqs, axp_data->num_irq_names), + GFP_KERNEL); if (!power) return -ENOMEM; - axp_data = of_device_get_match_data(&pdev->dev); - if (axp_data->acin_adc) { power->acin_v = devm_iio_channel_get(&pdev->dev, "acin_v"); if (IS_ERR(power->acin_v)) { @@ -308,6 +361,7 @@ static int axp20x_ac_power_probe(struct platform_device *pdev) power->regmap = dev_get_regmap(pdev->dev.parent, NULL); power->has_acin_path_sel = axp_data->acin_path_sel; + power->num_irqs = axp_data->num_irq_names; platform_set_drvdata(pdev, power); @@ -321,20 +375,22 @@ static int axp20x_ac_power_probe(struct platform_device *pdev) return PTR_ERR(power->supply); /* Request irqs after registering, as irqs may trigger immediately */ - for (i = 0; irq_names[i]; i++) { - irq = platform_get_irq_byname(pdev, irq_names[i]); + for (i = 0; i < axp_data->num_irq_names; i++) { + irq = platform_get_irq_byname(pdev, axp_data->irq_names[i]); if (irq < 0) { - dev_warn(&pdev->dev, "No IRQ for %s: %d\n", - irq_names[i], irq); - continue; + dev_err(&pdev->dev, "No IRQ for %s: %d\n", + axp_data->irq_names[i], irq); + return irq; } - irq = regmap_irq_get_virq(axp20x->regmap_irqc, irq); - ret = devm_request_any_context_irq(&pdev->dev, irq, + power->irqs[i] = regmap_irq_get_virq(axp20x->regmap_irqc, irq); + ret = devm_request_any_context_irq(&pdev->dev, power->irqs[i], axp20x_ac_power_irq, 0, DRVNAME, power); - if (ret < 0) - dev_warn(&pdev->dev, "Error requesting %s IRQ: %d\n", - irq_names[i], ret); + if (ret < 0) { + dev_err(&pdev->dev, "Error requesting %s IRQ: %d\n", + axp_data->irq_names[i], ret); + return ret; + } } return 0; @@ -357,8 +413,9 @@ MODULE_DEVICE_TABLE(of, axp20x_ac_power_match); static struct platform_driver axp20x_ac_power_driver = { .probe = axp20x_ac_power_probe, .driver = { - .name = DRVNAME, - .of_match_table = axp20x_ac_power_match, + .name = DRVNAME, + .of_match_table = axp20x_ac_power_match, + .pm = &axp20x_ac_power_pm_ops, }, }; From patchwork Sun Jan 5 01:24:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 11318011 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ED4E8138D for ; Sun, 5 Jan 2020 01:24:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CB408215A4 for ; Sun, 5 Jan 2020 01:24:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sholland.org header.i=@sholland.org header.b="H2bybVP7"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="a7mfwQs0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726524AbgAEBYn (ORCPT ); Sat, 4 Jan 2020 20:24:43 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:42023 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726481AbgAEBYU (ORCPT ); Sat, 4 Jan 2020 20:24:20 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 2A1FC21CBA; Sat, 4 Jan 2020 20:24:19 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sat, 04 Jan 2020 20:24:19 -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=eR/RTzq+jdWmJ Il0pyBHpgF8i6B4qMRvVJ2hxPiiC9Y=; b=H2bybVP7T3rc77Vr+cGdbZti7LXhL Rpkk/4WZbExkZKqfu/GqE0aeOaSf1rDjPX4vQUnVCDoNO84VnJrziXqgZDvu0b4W uYhtS1gGGLIFnjw8WMyqglnP0ESvgH1c44ea9ewchHgwKnNLOo4MzTTYe2wwfjiG IM/AKE48IDg9DeQR1HNRrGAtIZo8iE4sToCkSmL1GrpF76CK5gSYzsAFEReRa9EQ zK7O2QkU29YSde4mDMzpwrURfhCzujZjLrIlkECxvaOKKYyQtEtsw3pvm/PB13+L /M+7vkKmYCJx1Wje6uEkjks5T0ML0BecOc8oe9nUDX6qeUGrQ4783YClg== 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=eR/RTzq+jdWmJIl0pyBHpgF8i6B4qMRvVJ2hxPiiC9Y=; b=a7mfwQs0 K/hQoxhyuqH4cIBI5TqzDyTdglHMR3ObdJ/6kNATi/VudK7Ea/kLlJMb70KJYQkH 72lD3/U0c03lZgJwp+hUMceLOcxcyXbIVb5+MLyTlSMnKDKne6rjFh2G0OlmD19x Mc4lmZrkCrUKBUKFo0rBO4Kw/nJQG90FIa/ufHVzTSVZ2MvMZgSxEny62oDpj2yk 0/lmpQ8hyDE6Tt+OJSwrNeZ+lcTyExf9u0cpDKy+QPhsdRBcusbhfvkxmqLjNCZ+ TH/7vaiSwANqbUKwOFqVVbhcFXv6FZFg03HpSecquX66NHjAp6AN7h+srb+QOzg4 dC9SkBWeRShvOw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdegiedgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucfkph epjedtrddufeehrddugeekrdduhedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehsrghm uhgvlhesshhhohhllhgrnhgurdhorhhgnecuvehluhhsthgvrhfuihiivgepvd 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 766CF80059; Sat, 4 Jan 2020 20:24:18 -0500 (EST) From: Samuel Holland To: Chen-Yu Tsai , Sebastian Reichel , Lee Jones , Hans de Goede , Oskari Lemmela , Quentin Schulz Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Samuel Holland Subject: [PATCH v2 5/9] power: supply: axp20x_usb_power: Remove unused device_node Date: Sat, 4 Jan 2020 19:24:12 -0600 Message-Id: <20200105012416.23296-6-samuel@sholland.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200105012416.23296-1-samuel@sholland.org> References: <20200105012416.23296-1-samuel@sholland.org> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org This member of struct axp20x_usb_power is not used anywhere. Remove it. Signed-off-by: Samuel Holland Reviewed-by: Chen-Yu Tsai --- drivers/power/supply/axp20x_usb_power.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index 5f0a5722b19e..dd3f3f12e41d 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -57,7 +57,6 @@ #define DEBOUNCE_TIME msecs_to_jiffies(50) struct axp20x_usb_power { - struct device_node *np; struct regmap *regmap; struct power_supply *supply; enum axp20x_variants axp20x_id; @@ -465,7 +464,6 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) power->axp20x_id = (enum axp20x_variants)of_device_get_match_data( &pdev->dev); - power->np = pdev->dev.of_node; power->regmap = axp20x->regmap; if (power->axp20x_id == AXP202_ID) { From patchwork Sun Jan 5 01:24:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 11318005 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1B76C138D for ; Sun, 5 Jan 2020 01:24:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E37F12465D for ; Sun, 5 Jan 2020 01:24:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sholland.org header.i=@sholland.org header.b="c77H3IeU"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qZ1Nbzxk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727158AbgAEBYn (ORCPT ); Sat, 4 Jan 2020 20:24:43 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:36831 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726487AbgAEBYU (ORCPT ); Sat, 4 Jan 2020 20:24:20 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id A344521CDD; Sat, 4 Jan 2020 20:24:19 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sat, 04 Jan 2020 20:24:19 -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=H82xRxh61bgTh G+kaAbvv3z6nkx0cTMFo2BWr0/QYbw=; b=c77H3IeUZSF1kcVIXfRFWOYzUCA71 IXzRQ/4tRnzSA66hVCj6f4dBbJuYCIz+F50z4SjePtjunwfBidUYOta2hgtxEFyL 29GthbH01MF8OqY3AKaArKQH+B8VfIHvnfmXs+mL7bTOaix9ZTDbOXN+7yGEzkVw YeiBmQZTpvmlFOfh54DVFZJXhv4LyX012mVTQBxkgIwYrA52gZnDUXspJZG5Ehsu 9ZPpa04OeWodSH1SqnAGNURqVoHToBvVbodvQ5WnxvL5gDgYnZrWXOF/5Cb6GBGP C1cJIUhTWtug0g/kw+n56HMDngZWEWqvfxoH+rHHfWjXM8B3dIJAAa3Eg== 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=H82xRxh61bgThG+kaAbvv3z6nkx0cTMFo2BWr0/QYbw=; b=qZ1Nbzxk 25tCskdnJaT6zhKqgbVs8q5NiBhL+2CJCZJtn2ByRaEkUBCkWWs1WGK3tyfb9Jys 0KKU3NLEtUseej5PDgEoVCxKRjn3nageA/FwbJEcgNdwhassfls2j/tsTaqEKvvA 1Mt8QMLq0ptxENjadF11vh1LVZ6DRVw+4ezJOaRTzQsarwIm/Vd+WuAxLwBHdBYc n+vNmXOCRZomjUse1IU7iHJ8P1hJPiu3jd5nlW8UH6TYZoIoWjBX2ikOVb+HNgOx c3IS0poOsxlTmCX5N0lTRWLTjvk5MWlbzCp+6z0gNl/DAwstdG9cG3CtvM7U76LK Z/FXJKldTv31Jg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdegiedgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucfkph epjedtrddufeehrddugeekrdduhedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehsrghm uhgvlhesshhhohhllhgrnhgurdhorhhgnecuvehluhhsthgvrhfuihiivgepvd 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 F30F080061; Sat, 4 Jan 2020 20:24:18 -0500 (EST) From: Samuel Holland To: Chen-Yu Tsai , Sebastian Reichel , Lee Jones , Hans de Goede , Oskari Lemmela , Quentin Schulz Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Samuel Holland Subject: [PATCH v2 6/9] power: supply: axp20x_usb_power: Use a match structure Date: Sat, 4 Jan 2020 19:24:13 -0600 Message-Id: <20200105012416.23296-7-samuel@sholland.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200105012416.23296-1-samuel@sholland.org> References: <20200105012416.23296-1-samuel@sholland.org> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Instead of ad-hoc variant ID checks throughout the code, let's start moving the variant-specific details to a match structure. This allows for future flexibility, and it better matches the other axp20x power supply drivers. Signed-off-by: Samuel Holland Reviewed-by: Chen-Yu Tsai --- drivers/power/supply/axp20x_usb_power.c | 91 ++++++++++++++++--------- 1 file changed, 60 insertions(+), 31 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index dd3f3f12e41d..2d7272e19a87 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -405,6 +405,50 @@ static const struct power_supply_desc axp22x_usb_power_desc = { .set_property = axp20x_usb_power_set_property, }; +static const char * const axp20x_irq_names[] = { + "VBUS_PLUGIN", + "VBUS_REMOVAL", + "VBUS_VALID", + "VBUS_NOT_VALID", + NULL +}; + +static const char * const axp22x_irq_names[] = { + "VBUS_PLUGIN", + "VBUS_REMOVAL", + NULL +}; + +struct axp_data { + const struct power_supply_desc *power_desc; + const char * const *irq_names; + enum axp20x_variants axp20x_id; +}; + +static const struct axp_data axp202_data = { + .power_desc = &axp20x_usb_power_desc, + .irq_names = axp20x_irq_names, + .axp20x_id = AXP202_ID, +}; + +static const struct axp_data axp221_data = { + .power_desc = &axp22x_usb_power_desc, + .irq_names = axp22x_irq_names, + .axp20x_id = AXP221_ID, +}; + +static const struct axp_data axp223_data = { + .power_desc = &axp22x_usb_power_desc, + .irq_names = axp22x_irq_names, + .axp20x_id = AXP223_ID, +}; + +static const struct axp_data axp813_data = { + .power_desc = &axp22x_usb_power_desc, + .irq_names = axp22x_irq_names, + .axp20x_id = AXP813_ID, +}; + static int configure_iio_channels(struct platform_device *pdev, struct axp20x_usb_power *power) { @@ -440,12 +484,7 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); struct power_supply_config psy_cfg = {}; struct axp20x_usb_power *power; - static const char * const axp20x_irq_names[] = { "VBUS_PLUGIN", - "VBUS_REMOVAL", "VBUS_VALID", "VBUS_NOT_VALID", NULL }; - static const char * const axp22x_irq_names[] = { - "VBUS_PLUGIN", "VBUS_REMOVAL", NULL }; - const char * const *irq_names; - const struct power_supply_desc *usb_power_desc; + const struct axp_data *axp_data; int i, irq, ret; if (!of_device_is_available(pdev->dev.of_node)) @@ -456,15 +495,16 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) return -EINVAL; } + axp_data = of_device_get_match_data(&pdev->dev); + power = devm_kzalloc(&pdev->dev, sizeof(*power), GFP_KERNEL); if (!power) return -ENOMEM; - platform_set_drvdata(pdev, power); - power->axp20x_id = (enum axp20x_variants)of_device_get_match_data( - &pdev->dev); - power->regmap = axp20x->regmap; + power->axp20x_id = axp_data->axp20x_id; + + platform_set_drvdata(pdev, power); if (power->axp20x_id == AXP202_ID) { /* Enable vbus valid checking */ @@ -481,18 +521,6 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) if (ret) return ret; - - usb_power_desc = &axp20x_usb_power_desc; - irq_names = axp20x_irq_names; - } else if (power->axp20x_id == AXP221_ID || - power->axp20x_id == AXP223_ID || - power->axp20x_id == AXP813_ID) { - usb_power_desc = &axp22x_usb_power_desc; - irq_names = axp22x_irq_names; - } else { - dev_err(&pdev->dev, "Unsupported AXP variant: %ld\n", - axp20x->variant); - return -EINVAL; } if (power->axp20x_id == AXP813_ID) { @@ -504,17 +532,18 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) psy_cfg.of_node = pdev->dev.of_node; psy_cfg.drv_data = power; - power->supply = devm_power_supply_register(&pdev->dev, usb_power_desc, + power->supply = devm_power_supply_register(&pdev->dev, + axp_data->power_desc, &psy_cfg); if (IS_ERR(power->supply)) return PTR_ERR(power->supply); /* Request irqs after registering, as irqs may trigger immediately */ - for (i = 0; irq_names[i]; i++) { - irq = platform_get_irq_byname(pdev, irq_names[i]); + for (i = 0; axp_data->irq_names[i]; i++) { + irq = platform_get_irq_byname(pdev, axp_data->irq_names[i]); if (irq < 0) { dev_warn(&pdev->dev, "No IRQ for %s: %d\n", - irq_names[i], irq); + axp_data->irq_names[i], irq); continue; } irq = regmap_irq_get_virq(axp20x->regmap_irqc, irq); @@ -522,7 +551,7 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) axp20x_usb_power_irq, 0, DRVNAME, power); if (ret < 0) dev_warn(&pdev->dev, "Error requesting %s IRQ: %d\n", - irq_names[i], ret); + axp_data->irq_names[i], ret); } INIT_DELAYED_WORK(&power->vbus_detect, axp20x_usb_power_poll_vbus); @@ -544,16 +573,16 @@ static int axp20x_usb_power_remove(struct platform_device *pdev) static const struct of_device_id axp20x_usb_power_match[] = { { .compatible = "x-powers,axp202-usb-power-supply", - .data = (void *)AXP202_ID, + .data = &axp202_data, }, { .compatible = "x-powers,axp221-usb-power-supply", - .data = (void *)AXP221_ID, + .data = &axp221_data, }, { .compatible = "x-powers,axp223-usb-power-supply", - .data = (void *)AXP223_ID, + .data = &axp223_data, }, { .compatible = "x-powers,axp813-usb-power-supply", - .data = (void *)AXP813_ID, + .data = &axp813_data, }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, axp20x_usb_power_match); From patchwork Sun Jan 5 01:24:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 11318001 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC162109A for ; Sun, 5 Jan 2020 01:24:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9054424654 for ; Sun, 5 Jan 2020 01:24:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sholland.org header.i=@sholland.org header.b="aG63STUP"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MxUC43Y9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726608AbgAEBYV (ORCPT ); Sat, 4 Jan 2020 20:24:21 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:46859 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726504AbgAEBYU (ORCPT ); Sat, 4 Jan 2020 20:24:20 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 1DE7D21DFB; Sat, 4 Jan 2020 20:24:20 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sat, 04 Jan 2020 20:24:20 -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=aq+SCX2ysa3GN XpW7Iu1dniHsmrxkX+iV1kY3kri6/Q=; b=aG63STUPdUgAi83lALGXu7nDyzZ16 9AuIrnD77aY66A2o2eGB+2PWTHjgZCptI9T49Zvd9WT2bkziAUGhJndzHPL+11BF om/Gu2HP+aJrCFvPP0Vo6CrKryaQZ1uNc+OIprv+XrGkBkgdDN0BR9pITC4FH74I j7Es278cU81EfPTrTSmbi7IkaVw6VrUJ6vVjT1Mc2ejkKjqhj/zb2ENwEsOMO6cY r2ik5ls6Y4gv5CiKiXtTepiUbgNeY1FQHJHs1tfetBAzrWHMJUPCUxRleerkD8/b gMyk58QlA0fUbbAQP4Z7Fhqf2pAeJEYG2F9HHNFyR7uVcM+KuVjZh4e2Q== 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=aq+SCX2ysa3GNXpW7Iu1dniHsmrxkX+iV1kY3kri6/Q=; b=MxUC43Y9 KibCUcJzJxDK/qf1bn5xTutsErZVA8I0bHAZeiEwqL/Zj1uEcALsirdPaUAHcIcL JpZQiDBdKDLCjU9f2JMvK7oS0Qp0/rnc/QbEcCqqjeVFmIkdZPIAR100oVu3NwLv vk6vdX58s1xFIdS7OzQnyioep60BmXyFgFNr7jGECfJdg8h050iHIPuDqfq3CuhM YyRT/+tqSXVUq8M/engIZ3T3dCNqB2enelzZhj3j9bEiMf6I7xm3Sc0iIXAJJ2Hj g/hHBTDXY1CGM0pVf0ssHyw9cHjFf7Fe1/tSR+W7LyHkRdKlQbdtsZJea5YijuT+ enlPIbCBZa71KQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdegiedgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucfkph epjedtrddufeehrddugeekrdduhedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehsrghm uhgvlhesshhhohhllhgrnhgurdhorhhgnecuvehluhhsthgvrhfuihiivgepvd 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 75F4980059; Sat, 4 Jan 2020 20:24:19 -0500 (EST) From: Samuel Holland To: Chen-Yu Tsai , Sebastian Reichel , Lee Jones , Hans de Goede , Oskari Lemmela , Quentin Schulz Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Samuel Holland Subject: [PATCH v2 7/9] power: supply: axp20x_usb_power: Allow offlining Date: Sat, 4 Jan 2020 19:24:14 -0600 Message-Id: <20200105012416.23296-8-samuel@sholland.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200105012416.23296-1-samuel@sholland.org> References: <20200105012416.23296-1-samuel@sholland.org> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@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 Reviewed-by: Chen-Yu Tsai --- drivers/power/supply/axp20x_usb_power.c | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index 2d7272e19a87..68443f264dff 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 @@ -263,6 +266,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) { @@ -344,6 +357,9 @@ 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: + 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); @@ -363,6 +379,17 @@ 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); + + /* + * Both AXP2xx and AXP8xx have a VBUS path select flag. + * On AXP2xx, setting the flag enables VBUS (ignoring N_VBUSEN). + * On AXP8xx, setting the flag disables VBUS (ignoring N_VBUSEN). + * So we only expose the control on AXP8xx where it is meaningful. + */ + 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; } From patchwork Sun Jan 5 01:24:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 11317999 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F092109A for ; Sun, 5 Jan 2020 01:24:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2754624654 for ; Sun, 5 Jan 2020 01:24:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sholland.org header.i=@sholland.org header.b="GzTWIcdk"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="R8bTQnzZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726989AbgAEBYc (ORCPT ); Sat, 4 Jan 2020 20:24:32 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:54713 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726524AbgAEBYW (ORCPT ); Sat, 4 Jan 2020 20:24:22 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 9B7E821E1C; Sat, 4 Jan 2020 20:24:20 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sat, 04 Jan 2020 20:24:20 -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=aPDicKjX3sog9 HY23eYR9Pr3L9SQJGUFYqDzDzZMHU8=; b=GzTWIcdkBLPWoeLKkDrAjzJMfcG74 gbf+PLZojPxGFeCdnIPev7Im2hO7PUTSwvcJAh7IHRNPRnNPvLJs0jNv9ZC4Yg7D LZG9I3sum5Q65YQJJQho5v+A3Us+menODm1B5zl2R2VXUnaciMIab513kqzTV90d qrXg1E8B4q8pDcoPmtE1D8uECFxYTM+vCHUIZOf6DhpHJK1OM94YDs82fjLjTyCy +mQbp+ME5HCD36DfcOZeHXiiXtWRe8e18d7gWDGnN9YdXXKr1hJB/RPNewQG6rxt z515ThIDLysCB6p2Ds7tDdxPtCt7+8mODDoiFXwIV65jby270s6qzOVKA== 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=aPDicKjX3sog9HY23eYR9Pr3L9SQJGUFYqDzDzZMHU8=; b=R8bTQnzZ wOWOhE06N2VonHKjZytslEoAfA6hhb37RL5Qz2aqY7Zi6kCevPDvmt9iryG0dNF7 Kkgwou5CSIpjSciXjmiVLHC7s0ZYta6/MsXHkCORwSxuhCgqKi8Rx6trQLRsae9x ODxc2TLNjdVS9pu3S3zMXMnXuCwyF3JefdwpTQbobXPhnASHwaBr4UV+DqOh5xZb o66SgKuxauyjr28X/9uThKKvj1gpQn9AK4WqCHj4TcyH86vBxKV/I7voioWgaQBM Lp6UrS/quS53AwwqxLiWaQdkJSd18seJIUr9ymiD6jA01WuouBTfSy8YWt/VTY7K Dn1RIsoAm0Q9zw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdegiedgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucfkph epjedtrddufeehrddugeekrdduhedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehsrghm uhgvlhesshhhohhllhgrnhgurdhorhhgnecuvehluhhsthgvrhfuihiivgepvd 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 E8E7B80062; Sat, 4 Jan 2020 20:24:19 -0500 (EST) From: Samuel Holland To: Chen-Yu Tsai , Sebastian Reichel , Lee Jones , Hans de Goede , Oskari Lemmela , Quentin Schulz Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Samuel Holland Subject: [PATCH v2 8/9] power: supply: axp20x_usb_power: Add wakeup control Date: Sat, 4 Jan 2020 19:24:15 -0600 Message-Id: <20200105012416.23296-9-samuel@sholland.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200105012416.23296-1-samuel@sholland.org> References: <20200105012416.23296-1-samuel@sholland.org> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The USB power supply input can be used as a wakeup source. Hook up the VBUS_PLUGIN IRQ to trigger wakeup based on userspace configuration. To do this, we must remember the list of IRQs for the life of the device. To know how much space to allocate for the flexible array member, we switch from using a NULL sentinel to using an array length. Because we now depend on the specific order of the IRQs (we assume VBUS_PLUGIN is first and always present), failing to acquire an IRQ during probe must be a fatal error. To avoid spuriously waking up the system when the USB power supply is not configured as a wakeup source, we must explicitly disable all non- wake IRQs during system suspend. This is because the SoC's NMI input is shared among all IRQs on the AXP PMIC. Due to the use of regmap-irq, the individual IRQs within the PMIC are nested threaded interrupts, and are therefore not automatically disabled during system suspend. The upshot is that if any other device within the MFD (such as the power key) is an enabled wakeup source, all enabled IRQs within the PMIC will cause wakeup. We still need to call enable_irq_wake() when we *do* want wakeup, in case those other wakeup sources on the PMIC are all disabled. Signed-off-by: Samuel Holland Reviewed-by: Chen-Yu Tsai --- drivers/power/supply/axp20x_usb_power.c | 80 ++++++++++++++++++++----- 1 file changed, 65 insertions(+), 15 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index 68443f264dff..0d033954c4dc 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -67,6 +68,8 @@ struct axp20x_usb_power { struct iio_channel *vbus_i; struct delayed_work vbus_detect; unsigned int old_status; + unsigned int num_irqs; + unsigned int irqs[]; }; static irqreturn_t axp20x_usb_power_irq(int irq, void *devid) @@ -437,45 +440,85 @@ static const char * const axp20x_irq_names[] = { "VBUS_REMOVAL", "VBUS_VALID", "VBUS_NOT_VALID", - NULL }; static const char * const axp22x_irq_names[] = { "VBUS_PLUGIN", "VBUS_REMOVAL", - NULL }; struct axp_data { const struct power_supply_desc *power_desc; const char * const *irq_names; + unsigned int num_irq_names; enum axp20x_variants axp20x_id; }; static const struct axp_data axp202_data = { .power_desc = &axp20x_usb_power_desc, .irq_names = axp20x_irq_names, + .num_irq_names = ARRAY_SIZE(axp20x_irq_names), .axp20x_id = AXP202_ID, }; static const struct axp_data axp221_data = { .power_desc = &axp22x_usb_power_desc, .irq_names = axp22x_irq_names, + .num_irq_names = ARRAY_SIZE(axp22x_irq_names), .axp20x_id = AXP221_ID, }; static const struct axp_data axp223_data = { .power_desc = &axp22x_usb_power_desc, .irq_names = axp22x_irq_names, + .num_irq_names = ARRAY_SIZE(axp22x_irq_names), .axp20x_id = AXP223_ID, }; static const struct axp_data axp813_data = { .power_desc = &axp22x_usb_power_desc, .irq_names = axp22x_irq_names, + .num_irq_names = ARRAY_SIZE(axp22x_irq_names), .axp20x_id = AXP813_ID, }; +#ifdef CONFIG_PM_SLEEP +static int axp20x_usb_power_suspend(struct device *dev) +{ + struct axp20x_usb_power *power = dev_get_drvdata(dev); + int i = 0; + + /* + * Allow wake via VBUS_PLUGIN only. + * + * As nested threaded IRQs are not automatically disabled during + * suspend, we must explicitly disable the remainder of the IRQs. + */ + if (device_may_wakeup(&power->supply->dev)) + enable_irq_wake(power->irqs[i++]); + while (i < power->num_irqs) + disable_irq(power->irqs[i++]); + + return 0; +} + +static int axp20x_usb_power_resume(struct device *dev) +{ + struct axp20x_usb_power *power = dev_get_drvdata(dev); + int i = 0; + + if (device_may_wakeup(&power->supply->dev)) + disable_irq_wake(power->irqs[i++]); + while (i < power->num_irqs) + enable_irq(power->irqs[i++]); + + return 0; +} +#endif + +static SIMPLE_DEV_PM_OPS(axp20x_usb_power_pm_ops, axp20x_usb_power_suspend, + axp20x_usb_power_resume); + static int configure_iio_channels(struct platform_device *pdev, struct axp20x_usb_power *power) { @@ -524,12 +567,15 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) axp_data = of_device_get_match_data(&pdev->dev); - power = devm_kzalloc(&pdev->dev, sizeof(*power), GFP_KERNEL); + power = devm_kzalloc(&pdev->dev, + struct_size(power, irqs, axp_data->num_irq_names), + GFP_KERNEL); if (!power) return -ENOMEM; power->regmap = axp20x->regmap; power->axp20x_id = axp_data->axp20x_id; + power->num_irqs = axp_data->num_irq_names; platform_set_drvdata(pdev, power); @@ -566,19 +612,22 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) return PTR_ERR(power->supply); /* Request irqs after registering, as irqs may trigger immediately */ - for (i = 0; axp_data->irq_names[i]; i++) { + for (i = 0; i < axp_data->num_irq_names; i++) { irq = platform_get_irq_byname(pdev, axp_data->irq_names[i]); if (irq < 0) { - dev_warn(&pdev->dev, "No IRQ for %s: %d\n", - axp_data->irq_names[i], irq); - continue; + dev_err(&pdev->dev, "No IRQ for %s: %d\n", + axp_data->irq_names[i], irq); + return irq; + } + power->irqs[i] = regmap_irq_get_virq(axp20x->regmap_irqc, irq); + ret = devm_request_any_context_irq(&pdev->dev, power->irqs[i], + axp20x_usb_power_irq, 0, + DRVNAME, power); + if (ret < 0) { + dev_err(&pdev->dev, "Error requesting %s IRQ: %d\n", + axp_data->irq_names[i], ret); + return ret; } - irq = regmap_irq_get_virq(axp20x->regmap_irqc, irq); - ret = devm_request_any_context_irq(&pdev->dev, irq, - axp20x_usb_power_irq, 0, DRVNAME, power); - if (ret < 0) - dev_warn(&pdev->dev, "Error requesting %s IRQ: %d\n", - axp_data->irq_names[i], ret); } INIT_DELAYED_WORK(&power->vbus_detect, axp20x_usb_power_poll_vbus); @@ -618,8 +667,9 @@ static struct platform_driver axp20x_usb_power_driver = { .probe = axp20x_usb_power_probe, .remove = axp20x_usb_power_remove, .driver = { - .name = DRVNAME, - .of_match_table = axp20x_usb_power_match, + .name = DRVNAME, + .of_match_table = axp20x_usb_power_match, + .pm = &axp20x_usb_power_pm_ops, }, }; From patchwork Sun Jan 5 01:24:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 11317997 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 88391109A for ; Sun, 5 Jan 2020 01:24:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5D2BD2467A for ; Sun, 5 Jan 2020 01:24:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sholland.org header.i=@sholland.org header.b="myTbfkLw"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="pOWEEMBo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726927AbgAEBYc (ORCPT ); Sat, 4 Jan 2020 20:24:32 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:56563 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726488AbgAEBYW (ORCPT ); Sat, 4 Jan 2020 20:24:22 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 2671721E92; Sat, 4 Jan 2020 20:24:22 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sat, 04 Jan 2020 20:24:22 -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=Jm4NPFOs74xdA A/X94Ro/cYVSaTnCwH5Zv4H2w/Sd+k=; b=myTbfkLwBhF9nDCF3lhUHSpTKDKQt v3I2TM2h7PQT62fHiQQf6K94v5eSaCrx1pvfiYoMTY5CH+PCa0NLQP6ETdS+NBlu UfhfGBAJognk8gcwiHpsl6c6Hy4NeF2ZmaHCQQ9j/7mF9t1X+yIZ9mWxzX98IJ8B g+iUmNorCzOPvi49YNh1Dn0zp+2tTN9aVmlZp7ZFIbUuJAXC7ZM9Gmji8IBRS41N ipHHCBvgcDq7EeWn98GoqxUCFlBklKnJ7yQ6hxH3MmxvZPvWEN2Z0hewpA4Hqmf/ NdhPpMV5PoxYU+eDrz00aKyMhf6fPXRvltcdgf7LJxWE9n2xTtup900xA== 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=Jm4NPFOs74xdAA/X94Ro/cYVSaTnCwH5Zv4H2w/Sd+k=; b=pOWEEMBo Fc/4T80lDtuVNJCevjvsdZm8YT5uJfa1ToMLy6ypyCkuRq/NDRw85RdpeNKl9qEK yB7QkZt0gNy/ogiyY8lxC0G6SpWnrAjpIl2NTSA8+Rz7pSmdMf5J5MqttRC+D4uM 0LZe5DfmTJuScRZPZQ/LbxeuOwYsXWvH9E8OmUQFdgy6DecRV4TwR7hSeV7z4bd5 0WG7W5vu26gqp5ke1w2kqRbkRjXJHZz9TW0lfJjDtkLTt6z70fThgvaOpELyZEyT Tq6UuCxSgqMUZjAIX0LI+UR3g2I/XKa1IXnCR/bHZMrrIO6KCa23WMCCuI0T3hUQ agUctgpmFI2wOQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdegiedgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucfkph epjedtrddufeehrddugeekrdduhedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehsrghm uhgvlhesshhhohhllhgrnhgurdhorhhgnecuvehluhhsthgvrhfuihiivgepvd 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 70BF680059; Sat, 4 Jan 2020 20:24:20 -0500 (EST) From: Samuel Holland To: Chen-Yu Tsai , Sebastian Reichel , Lee Jones , Hans de Goede , Oskari Lemmela , Quentin Schulz Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Samuel Holland Subject: [PATCH v2 9/9] power: supply: axp20x_usb_power: Only poll while offline Date: Sat, 4 Jan 2020 19:24:16 -0600 Message-Id: <20200105012416.23296-10-samuel@sholland.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200105012416.23296-1-samuel@sholland.org> References: <20200105012416.23296-1-samuel@sholland.org> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Investigation on the AXP803 shows that VBUS_PLUGIN/VBUS_REMOVAL IRQs are triggered on the rising/falling edge of AXP20X_PWR_STATUS_VBUS_USED. The reason IRQs do not arrive while N_VBUSEN/DRIVEVBUS is high is because AXP20X_PWR_STATUS_VBUS_USED also never goes high. This also means that if VBUS is online, a VBUS_REMOVAL IRQ is received immediately on setting N_VBUSEN/DRIVEVBUS high (and VBUS_PLUGIN shortly after it is set back low). This was also verified to be the case when manually offlining VBUS through AXP20X_VBUS_PATH_SELECT. As long as VBUS is online, a present->absent transition necessarily implies an online->offline transition. Since will cause an IRQ, there is no need to poll while VBUS is online. To ensure the driver's view of VBUS online status remains accurate, unconditionally poll once when receiving an IRQ and when resuming. If VBUS is still online at that time, polling will cease until the next VBUS_REMOVAL IRQ. Signed-off-by: Samuel Holland Reviewed-by: Chen-Yu Tsai --- drivers/power/supply/axp20x_usb_power.c | 30 +++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index 0d033954c4dc..4bf119082e91 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -68,16 +68,32 @@ struct axp20x_usb_power { struct iio_channel *vbus_i; struct delayed_work vbus_detect; unsigned int old_status; + unsigned int online; unsigned int num_irqs; unsigned int irqs[]; }; +static bool axp20x_usb_vbus_needs_polling(struct axp20x_usb_power *power) +{ + /* + * Polling is only necessary while VBUS is offline. While online, a + * present->absent transition implies an online->offline transition + * and will triger the VBUS_REMOVAL IRQ. + */ + if (power->axp20x_id >= AXP221_ID && !power->online) + return true; + + return false; +} + static irqreturn_t axp20x_usb_power_irq(int irq, void *devid) { struct axp20x_usb_power *power = devid; power_supply_changed(power->supply); + mod_delayed_work(system_wq, &power->vbus_detect, DEBOUNCE_TIME); + return IRQ_HANDLED; } @@ -97,17 +113,11 @@ static void axp20x_usb_power_poll_vbus(struct work_struct *work) power_supply_changed(power->supply); power->old_status = val; + power->online = val & AXP20X_PWR_STATUS_VBUS_USED; out: - mod_delayed_work(system_wq, &power->vbus_detect, DEBOUNCE_TIME); -} - -static bool axp20x_usb_vbus_needs_polling(struct axp20x_usb_power *power) -{ - if (power->axp20x_id >= AXP221_ID) - return true; - - return false; + if (axp20x_usb_vbus_needs_polling(power)) + mod_delayed_work(system_wq, &power->vbus_detect, DEBOUNCE_TIME); } static int axp20x_get_current_max(struct axp20x_usb_power *power, int *val) @@ -512,6 +522,8 @@ static int axp20x_usb_power_resume(struct device *dev) while (i < power->num_irqs) enable_irq(power->irqs[i++]); + mod_delayed_work(system_wq, &power->vbus_detect, DEBOUNCE_TIME); + return 0; } #endif