From patchwork Tue Jun 6 07:25:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raymond Hackley X-Patchwork-Id: 689929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2501FC77B7A for ; Tue, 6 Jun 2023 07:26:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235732AbjFFH0G (ORCPT ); Tue, 6 Jun 2023 03:26:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236176AbjFFH0C (ORCPT ); Tue, 6 Jun 2023 03:26:02 -0400 Received: from mail-0201.mail-europe.com (mail-0201.mail-europe.com [51.77.79.158]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56BBEF3 for ; Tue, 6 Jun 2023 00:26:01 -0700 (PDT) Date: Tue, 06 Jun 2023 07:25:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1686036357; x=1686295557; bh=cqi05JE2UZTUwpQahBrP8KQeeAYBK+IxnIt+uQJM6Ig=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=OerX7hRkQirL5keZ8U3FyWNueZuOrBWokhHYxJLwqcMEjFo0SP3I1Bj/5sn7ie02n a2M/Smgyx9xoOvkEnYQrqQSMHvDjjkaiK6nZHeFxU0pNZUNXUrrC2vfqn/lLybKVAl 7sx19Kpumd8jpHndie6IdAt4/ZgQhHhQsOU1zHwC2BT3sPRvOvMoQDmGXUChjZ9vqz mpPvowqh4JKzSTmsZbzkC2WxsNe7xISJg4oR+NS0COLdzlyo0Py40kHmCqy8ugTKpf 6lwvxchTbyOBuE5xneDKLXvCIboO/Fc/ZM6hTmbNnK5PfzF579szw718DGiknxf7o/ HV+VS2DBCfOwg== To: linux-kernel@vger.kernel.org From: Raymond Hackley Cc: Krzysztof Kozlowski , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Liam Girdwood , Mark Brown , Michael Walle , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Jeremy Kerr , Raymond Hackley , netdev@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 2/2] NFC: nxp-nci: Add pad supply voltage pvdd-supply Message-ID: <20230606072454.145106-1-raymondhackley@protonmail.com> In-Reply-To: <20230606071824.144990-1-raymondhackley@protonmail.com> References: <20230606071824.144990-1-raymondhackley@protonmail.com> Feedback-ID: 49437091:user:proton MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org PN547/553, QN310/330 chips on some devices require a pad supply voltage (PVDD). Otherwise, the NFC won't power up. Implement support for pad supply voltage pvdd-supply that is enabled by the nxp-nci driver so that the regulator gets enabled when needed. Signed-off-by: Raymond Hackley --- drivers/nfc/nxp-nci/i2c.c | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/nfc/nxp-nci/i2c.c b/drivers/nfc/nxp-nci/i2c.c index d4c299be7949..e2d16111daa4 100644 --- a/drivers/nfc/nxp-nci/i2c.c +++ b/drivers/nfc/nxp-nci/i2c.c @@ -35,6 +35,7 @@ struct nxp_nci_i2c_phy { struct gpio_desc *gpiod_en; struct gpio_desc *gpiod_fw; + struct regulator *pvdd; int hard_fault; /* * < 0 if hardware error occurred (e.g. i2c err) @@ -263,6 +264,22 @@ static const struct acpi_gpio_mapping acpi_nxp_nci_gpios[] = { { } }; +static void nxp_nci_i2c_poweroff(void *data) +{ + struct nxp_nci_i2c_phy *phy = data; + struct device *dev = &phy->i2c_dev->dev; + struct regulator *pvdd = phy->pvdd; + int r; + + if (!IS_ERR(pvdd) && regulator_is_enabled(pvdd)) { + r = regulator_disable(pvdd); + if (r < 0) + dev_warn(dev, + "Failed to disable regulator pvdd: %d\n", + r); + } +} + static int nxp_nci_i2c_probe(struct i2c_client *client) { struct device *dev = &client->dev; @@ -298,6 +315,34 @@ static int nxp_nci_i2c_probe(struct i2c_client *client) return PTR_ERR(phy->gpiod_fw); } + phy->pvdd = devm_regulator_get_optional(dev, "pvdd"); + if (IS_ERR(phy->pvdd)) { + r = PTR_ERR(phy->pvdd); + if (r != -ENODEV) { + if (r != -EPROBE_DEFER) + dev_err(dev, + "Failed to get regulator pvdd: %d\n", + r); + return r; + } + } else { + r = regulator_enable(phy->pvdd); + if (r < 0) { + nfc_err(dev, + "Failed to enable regulator pvdd: %d\n", + r); + return r; + } + } + + r = devm_add_action_or_reset(dev, nxp_nci_i2c_poweroff, phy); + if (r < 0) { + nfc_err(dev, "Failed to install poweroff handler: %d\n", + r); + nxp_nci_i2c_poweroff(phy); + return r; + } + r = nxp_nci_probe(phy, &client->dev, &i2c_phy_ops, NXP_NCI_I2C_MAX_PAYLOAD, &phy->ndev); if (r < 0) @@ -319,6 +364,8 @@ static void nxp_nci_i2c_remove(struct i2c_client *client) nxp_nci_remove(phy->ndev); free_irq(client->irq, phy); + + nxp_nci_i2c_poweroff(phy); } static const struct i2c_device_id nxp_nci_i2c_id_table[] = {