From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9A18C433E0 for ; Fri, 26 Feb 2021 14:30:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64E8964F14 for ; Fri, 26 Feb 2021 14:30:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230096AbhBZO3z (ORCPT ); Fri, 26 Feb 2021 09:29:55 -0500 Received: from hostingweb31-40.netsons.net ([89.40.174.40]:55741 "EHLO hostingweb31-40.netsons.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229949AbhBZO3p (ORCPT ); Fri, 26 Feb 2021 09:29:45 -0500 Received: from [77.244.183.192] (port=64786 helo=melee.dev.aim) by hostingweb31.netsons.net with esmtpa (Exim 4.93) (envelope-from ) id 1lFe73-001EWE-GE; Fri, 26 Feb 2021 15:29:01 +0100 From: Luca Ceresoli To: Lee Jones , devicetree@vger.kernel.org Cc: Luca Ceresoli , Rob Herring , Keerthy , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mfd: lp87565: handle optional reset pin Date: Fri, 26 Feb 2021 15:28:52 +0100 Message-Id: <20210226142852.19632-2-luca@lucaceresoli.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210226142852.19632-1-luca@lucaceresoli.net> References: <20210226142852.19632-1-luca@lucaceresoli.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - hostingweb31.netsons.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lucaceresoli.net X-Get-Message-Sender-Via: hostingweb31.netsons.net: authenticated_id: luca+lucaceresoli.net/only user confirmed/virtual account not confirmed X-Authenticated-Sender: hostingweb31.netsons.net: luca@lucaceresoli.net X-Source: X-Source-Args: X-Source-Dir: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Optionally handle the NRST pin (active low reset) in order to start from a known state during boot and to shut down the chip when rebooting. Signed-off-by: Luca Ceresoli --- drivers/mfd/lp87565.c | 27 +++++++++++++++++++++++++++ include/linux/mfd/lp87565.h | 1 + 2 files changed, 28 insertions(+) diff --git a/drivers/mfd/lp87565.c b/drivers/mfd/lp87565.c index 9c21483d9653..a52ab76febb3 100644 --- a/drivers/mfd/lp87565.c +++ b/drivers/mfd/lp87565.c @@ -5,6 +5,7 @@ * Author: Keerthy */ +#include #include #include #include @@ -64,6 +65,24 @@ static int lp87565_probe(struct i2c_client *client, return ret; } + lp87565->reset_gpio = devm_gpiod_get_optional(lp87565->dev, "reset", + GPIOD_OUT_LOW); + if (IS_ERR(lp87565->reset_gpio)) { + ret = PTR_ERR(lp87565->reset_gpio); + if (ret == -EPROBE_DEFER) + return ret; + } + + if (lp87565->reset_gpio) { + gpiod_set_value_cansleep(lp87565->reset_gpio, 1); + /* The minimum assertion time is undocumented, just guess */ + usleep_range(2000, 4000); + + gpiod_set_value_cansleep(lp87565->reset_gpio, 0); + /* Min 1.2 ms before first I2C transaction */ + usleep_range(1500, 3000); + } + ret = regmap_read(lp87565->regmap, LP87565_REG_OTP_REV, &otpid); if (ret) { dev_err(lp87565->dev, "Failed to read OTP ID\n"); @@ -83,6 +102,13 @@ static int lp87565_probe(struct i2c_client *client, NULL, 0, NULL); } +static void lp87565_shutdown(struct i2c_client *client) +{ + struct lp87565 *lp87565 = i2c_get_clientdata(client); + + gpiod_set_value_cansleep(lp87565->reset_gpio, 1); +} + static const struct i2c_device_id lp87565_id_table[] = { { "lp87565-q1", 0 }, { }, @@ -95,6 +121,7 @@ static struct i2c_driver lp87565_driver = { .of_match_table = of_lp87565_match_table, }, .probe = lp87565_probe, + .shutdown = lp87565_shutdown, .id_table = lp87565_id_table, }; module_i2c_driver(lp87565_driver); diff --git a/include/linux/mfd/lp87565.h b/include/linux/mfd/lp87565.h index 94cb581af34b..4c895072d91b 100644 --- a/include/linux/mfd/lp87565.h +++ b/include/linux/mfd/lp87565.h @@ -252,5 +252,6 @@ struct lp87565 { u8 rev; u8 dev_type; struct regmap *regmap; + struct gpio_desc *reset_gpio; }; #endif /* __LINUX_MFD_LP87565_H */ -- 2.30.0