From patchwork Wed Jan 15 03:40:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 11333233 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 F40E11820 for ; Wed, 15 Jan 2020 03:41:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C83A924681 for ; Wed, 15 Jan 2020 03:41:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sholland.org header.i=@sholland.org header.b="YddlsDuS"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="OlJUdP6t" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729077AbgAODkv (ORCPT ); Tue, 14 Jan 2020 22:40:51 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:59385 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729045AbgAODkv (ORCPT ); Tue, 14 Jan 2020 22:40:51 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 44B732213F; Tue, 14 Jan 2020 22:40:50 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 14 Jan 2020 22:40:50 -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=1dk5aijTk6w4v CQgyLDInAxNbaNiMI7LvAOenwMv7lM=; b=YddlsDuS3TEiWMDGBvt7Sbx60qxiM 2A+9yvh2j+O7FBwABKkaPc5KR8WkMJwgVzNeysXQ/ck9BBkJyoJhcERz17Ur8+WQ Z8TY+2YVWT4/NdFzpkZMcvfnRh8Mzylda5HWks5Qkt25PmWfrpT2XW5jKrorev2m KLpF2Zg6L/vmkpCHDBWqaQlAcx85lk4pqPXovDuxTxIDlqMwg1BqkULaWzQRwYWZ JLjeh4etx7cRqKIAJLEoSvy4bIdIVs+1RWyBoAn4dydyX7uYD/k1IDTrlmzizsR8 PNlTrFXYQ6moFZ35Odd1J85+YtycVJkxkz996eYsJK2riOPaZZgQPVy0A== 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=1dk5aijTk6w4vCQgyLDInAxNbaNiMI7LvAOenwMv7lM=; b=OlJUdP6t gBxPK8GM31/AoobOTrFPvkp3BYnmmJYeOyOA2oXOxIMm3Wo36ts++D9At/ljRtUa CGgXEs3TvPm3gU6Y6qL4Q5cV2vZJtAOhNH8mmSRSMwlVFXXLArbc4/QVyxMr37ay 9wXyaphK9fdYl7KtzFWPHMzIykHoZ7h3v5sV5SqV3w+fq2pfth3yfbyYTG1wWJlD 4WvUL8LuGDaQgeOdT02S3/zG43MAB+SYqR1Uza/gSG5YS/OrxIaWggtjcHIyYA5g iwDlhBv1kCwj6qfSi+EpZY2CmPYUVbQ96aHnsNSvlI7qyQjsIUkSam71/qbxVo0M mziuMAYFjsdAmA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrtddvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepufgrmhhuvghl ucfjohhllhgrnhguuceoshgrmhhuvghlsehshhholhhlrghnugdrohhrgheqnecukfhppe ejtddrudefhedrudegkedrudehudenucfrrghrrghmpehmrghilhhfrhhomhepshgrmhhu vghlsehshhholhhlrghnugdrohhrghenucevlhhushhtvghrufhiiigvpedt 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 C6B0C30607B0; Tue, 14 Jan 2020 22:40:49 -0500 (EST) From: Samuel Holland To: Sebastian Reichel , Chen-Yu Tsai Cc: Oskari Lemmela , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Samuel Holland Subject: [PATCH v4 1/4] power: supply: axp20x_usb_power: Use a match structure Date: Tue, 14 Jan 2020 21:40:45 -0600 Message-Id: <20200115034048.24901-2-samuel@sholland.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200115034048.24901-1-samuel@sholland.org> References: <20200115034048.24901-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. This commit removes most variant checks from axp20x_usb_power_probe(). Other parts of the driver still do ID matching; they are left unchanged for now. Reviewed-by: Chen-Yu Tsai Signed-off-by: Samuel Holland --- drivers/power/supply/axp20x_usb_power.c | 86 ++++++++++++++++--------- 1 file changed, 57 insertions(+), 29 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index dd3f3f12e41d..cd7071057457 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)) @@ -461,9 +500,9 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) return -ENOMEM; platform_set_drvdata(pdev, power); - power->axp20x_id = (enum axp20x_variants)of_device_get_match_data( - &pdev->dev); + axp_data = of_device_get_match_data(&pdev->dev); + power->axp20x_id = axp_data->axp20x_id; power->regmap = axp20x->regmap; if (power->axp20x_id == AXP202_ID) { @@ -481,18 +520,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 +531,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 +550,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 +572,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 Wed Jan 15 03:40:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 11333235 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 E843914B4 for ; Wed, 15 Jan 2020 03:41:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC84F2467E for ; Wed, 15 Jan 2020 03:41:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sholland.org header.i=@sholland.org header.b="ahJ0WMUa"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="wXzqhRwu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728911AbgAODlM (ORCPT ); Tue, 14 Jan 2020 22:41:12 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:56633 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729048AbgAODkv (ORCPT ); Tue, 14 Jan 2020 22:40:51 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 957DD22131; Tue, 14 Jan 2020 22:40:50 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 14 Jan 2020 22:40:50 -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=xScHInzV3pGYC GSlKPZMPOWxtY3Fnc4q0/FsYlG3OLs=; b=ahJ0WMUaBq5GJoBURKIBPxBWo+VkF SsOOGKRlG2c+CR6dyZR7Eft4RVTDgPdLZu8zIHTgTZDn0a2ENIKuUNTLlBYkPbli dfYpSiQ2m3RTHaeRer5YgoTmDfQIz3nJa3t2Yv2ugHqFUyD0+Ac+rZTFHUUMe1gb YNyoKHmZ5T1y7uRJw0Fsn69dokf/wwYOWiAhAvWW6rwi1C42qUd7gFOTgYwGR9Sk l65zfDLsCmDYDaPj7RURLF09kV8V/S8BCkbC7QeZjY24fLwHRw+eT1DKHZMQ6CvP 7OFqneqa2pf7AaR9yzvlEP7lKkBwTQC8mm4Ds6adjiTJ7y2OwdA2sW44g== 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=xScHInzV3pGYCGSlKPZMPOWxtY3Fnc4q0/FsYlG3OLs=; b=wXzqhRwu k4x5z8PuP1ucVTKBjnwPRyG2sWniGCl1O7GFrUvRMvM6IPwQ9PnstkxGSXhJUtjA KHH+An/Ie2dnRlN2DkUC5gSV8UVxVO2GwfU1jYm8gzdJpP3Q2NdaLXdvcZcSvTw0 2WdLGZs4NE8xz5X4TOG4pvB3Bm7MsfKYkYEky+73SVYWOfQuxoUPi2SX5jPz3y1y gJW1xW2V5+quCyCeDp4Yt7FnNBroy8e4f9oq9VdtBpdXsUigdnYzwzrRwDHRBUAN P7PLG5LLCdfgJStGYywGTPw8cBI2VZxUL4uYnFE1nvxJmQkKKR8csfqBcWXNilUU xw1QD2TYAD42Vg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrtddvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepufgrmhhuvghl ucfjohhllhgrnhguuceoshgrmhhuvghlsehshhholhhlrghnugdrohhrgheqnecukfhppe ejtddrudefhedrudegkedrudehudenucfrrghrrghmpehmrghilhhfrhhomhepshgrmhhu vghlsehshhholhhlrghnugdrohhrghenucevlhhushhtvghrufhiiigvpedt 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 259FB30607CD; Tue, 14 Jan 2020 22:40:50 -0500 (EST) From: Samuel Holland To: Sebastian Reichel , Chen-Yu Tsai Cc: Oskari Lemmela , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Samuel Holland Subject: [PATCH v4 2/4] power: supply: axp20x_usb_power: Allow offlining Date: Tue, 14 Jan 2020 21:40:46 -0600 Message-Id: <20200115034048.24901-3-samuel@sholland.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200115034048.24901-1-samuel@sholland.org> References: <20200115034048.24901-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. Reviewed-by: Chen-Yu Tsai 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 cd7071057457..f14736041c41 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,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); @@ -363,6 +381,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; } From patchwork Wed Jan 15 03:40:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 11333229 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 403D7138D for ; Wed, 15 Jan 2020 03:41:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0A8932467C for ; Wed, 15 Jan 2020 03:41:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sholland.org header.i=@sholland.org header.b="Q2n9snhj"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="pA5wxifr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729095AbgAODky (ORCPT ); Tue, 14 Jan 2020 22:40:54 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:41373 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729061AbgAODkw (ORCPT ); Tue, 14 Jan 2020 22:40:52 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id EA65E22138; Tue, 14 Jan 2020 22:40:50 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 14 Jan 2020 22:40:50 -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=KQFR8kPZD6D3w XqLJBfc7mBAUnyFMy2alXybJXUpbSE=; b=Q2n9snhjH+4cJql1sJJMpyonzuqBW 35mTvRLw1oxMdFLKr01aelhSFSZpAFYev1Osn9WxgZcw+h/y9DRgq+ukMYRjdDJ8 EF2W4PBVKm+SBsMoFTOQwJnjm77TyvGjQx0ZRVieZskwLqbjWwheSkXlZIvh66cO yCj6Q/g2nZUdIWgkQt8vcdhXzLgFsJp0XrgOvJXIYCRYr4H8xbShHNIWkuFgsRrU dWW0GOcoMazBYDEyhT902dUWXyFDJHMs0tD9nEuz4KmOvWDgfJ8eUddAzObS1HCC Rl9/4ah3G2hAige7/VEfYPNxYq4eqpweMgACf3id/fUpduZVZq4SHAeSQ== 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=KQFR8kPZD6D3wXqLJBfc7mBAUnyFMy2alXybJXUpbSE=; b=pA5wxifr kokNJ0DYW1OemRzw5zorWd70gxjbOcYdqRYarS9DWCgHg+tbgcx2VkAvwngar06m Y5EWKqiQ3APAy4Npzyv9sqGzPrCfRBKW3lxyxrtqBa/DwhHLSOw/87BGg5pNJ9HS 4fSr5CV8FNb5vUwJd0dmMauaJ21mrxNQZnNuBiraoR0qUu1O7B3US9trlqz+z73Y xbQDI60tWvZGh5qQWnSF5kaPC2eoZK9nj0ea+EhqpdSBIHYnG/Ut9fJOdFxPFAP8 4WzgV2Qnf9pDJsrNWccAGdh06cM8J98xLJJeRJ17zdIMILANDHixhK7E2FsX+kkB LKequW3k2rEeEQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrtddvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepufgrmhhuvghl ucfjohhllhgrnhguuceoshgrmhhuvghlsehshhholhhlrghnugdrohhrgheqnecukfhppe ejtddrudefhedrudegkedrudehudenucfrrghrrghmpehmrghilhhfrhhomhepshgrmhhu vghlsehshhholhhlrghnugdrohhrghenucevlhhushhtvghrufhiiigvpedt 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 7883730602DE; Tue, 14 Jan 2020 22:40:50 -0500 (EST) From: Samuel Holland To: Sebastian Reichel , Chen-Yu Tsai Cc: Oskari Lemmela , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Samuel Holland Subject: [PATCH v4 3/4] power: supply: axp20x_usb_power: Add wakeup control Date: Tue, 14 Jan 2020 21:40:47 -0600 Message-Id: <20200115034048.24901-4-samuel@sholland.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200115034048.24901-1-samuel@sholland.org> References: <20200115034048.24901-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. Reviewed-by: Chen-Yu Tsai Signed-off-by: Samuel Holland --- drivers/power/supply/axp20x_usb_power.c | 83 ++++++++++++++++++++----- 1 file changed, 67 insertions(+), 16 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index f14736041c41..1732304bc96e 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) @@ -440,45 +443,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) { @@ -525,15 +568,19 @@ static int axp20x_usb_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; platform_set_drvdata(pdev, power); - axp_data = of_device_get_match_data(&pdev->dev); power->axp20x_id = axp_data->axp20x_id; power->regmap = axp20x->regmap; + power->num_irqs = axp_data->num_irq_names; if (power->axp20x_id == AXP202_ID) { /* Enable vbus valid checking */ @@ -568,19 +615,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); @@ -620,8 +670,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 Wed Jan 15 03:40:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 11333231 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 6BAFD1820 for ; Wed, 15 Jan 2020 03:41:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 49AED2467C for ; Wed, 15 Jan 2020 03:41:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sholland.org header.i=@sholland.org header.b="IieO7eXK"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CnqsbRPU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729098AbgAODkz (ORCPT ); Tue, 14 Jan 2020 22:40:55 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:38093 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728879AbgAODkw (ORCPT ); Tue, 14 Jan 2020 22:40:52 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 422AD22139; Tue, 14 Jan 2020 22:40:51 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 14 Jan 2020 22:40:51 -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=Zmlb3PnzNuoK+ 2LPTUjNJAzFl9+II7eFSLO3XnnS27A=; b=IieO7eXKZqxx0fy3qymRj23Uteh7L iDCLZQ8kHa9H0AQmVQTQ/gWT4Do7lZ4CUD6EBChy3hlvq93hpiNjymAGli1ce4GI 863oISQYFjCuPuhOrgClHsOrF8LI+faJPa+Y8H1nphH3WZ/BOeOZ5iCbXFOL1MQD NAWJwBfaLRMwdqbK0SZdaFpu1nh3XfItqPi5J9BTZ5wYXUuG9Q5WLptZer3Cpape +HaYz+/mRdosD844XSrzEZXeNy0HFZqNSDHzDTeM5TXvA8XCO69YmNrniw4WZqE2 /P8l/jTPLSlGB8KemIk7a0syfzMoT2yi0DfxQQSJZafWt1YBiJ4PnYGeA== 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=Zmlb3PnzNuoK+2LPTUjNJAzFl9+II7eFSLO3XnnS27A=; b=CnqsbRPU mazQZmpw5MqgXc8McNp2AqNohxEDbY9AOy3AZIC+f0RmGygTUR/sb38lT8JHxClj BVPk6CbXM8TlvDCSIq3lD98on4A2Ulfmk2RZ5I6GvvjY6BKUXyTosP+SxtUzvKHi ejVohwqkPNvGqFrg0964OTs0PzEkdrMv3OUOUjckJmfgz6FwYwBCv0XGJ9E/rHa8 COAwJX8z6/LqOoEbi3L2CoGNH1AMpIWbce6WIns5DA+BWoSEloym0bmWLXtx2etC OPGNaUIJGvBGmzCQgvrOAb+wJ1jBeJx7AeetDfKndZZWTRjaB+ZAQnQT4Y5IoB0E /7qQImf/d74pnw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrtddvgdeitdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepufgrmhhuvghl ucfjohhllhgrnhguuceoshgrmhhuvghlsehshhholhhlrghnugdrohhrgheqnecukfhppe ejtddrudefhedrudegkedrudehudenucfrrghrrghmpehmrghilhhfrhhomhepshgrmhhu vghlsehshhholhhlrghnugdrohhrghenucevlhhushhtvghrufhiiigvpedt 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 CA4C530607B0; Tue, 14 Jan 2020 22:40:50 -0500 (EST) From: Samuel Holland To: Sebastian Reichel , Chen-Yu Tsai Cc: Oskari Lemmela , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Samuel Holland Subject: [PATCH v4 4/4] power: supply: axp20x_usb_power: Only poll while offline Date: Tue, 14 Jan 2020 21:40:48 -0600 Message-Id: <20200115034048.24901-5-samuel@sholland.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200115034048.24901-1-samuel@sholland.org> References: <20200115034048.24901-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. Reviewed-by: Chen-Yu Tsai Signed-off-by: Samuel Holland --- 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 1732304bc96e..4fde24b5f35a 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) @@ -515,6 +525,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