From nobody Sat Oct 18 02:17:38 2025 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 43BB1C433FE for ; Wed, 19 Oct 2022 08:46:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231545AbiJSIq5 (ORCPT ); Wed, 19 Oct 2022 04:46:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231368AbiJSIpX (ORCPT ); Wed, 19 Oct 2022 04:45:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 557155053B; Wed, 19 Oct 2022 01:44:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0518F617D7; Wed, 19 Oct 2022 08:40:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A967C433C1; Wed, 19 Oct 2022 08:40:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666168853; bh=z6BUKnQXIYEmBq/uQLvhq8qTqLB0q2qvgDL8SK8Bizo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EcHf2maQ+V8AumTUUIMMO+ALOdHnSI+egh5dGaNG2dyfQQfxosRvvAACNxaoRBRay JmK7b9E440lSpwVAYDs/EW+Igd8a3YCZFzN0QOxTzJEeg1t48ZPV3sY221FS9IMeem /HEL/lcaVZqw7pDWkVKGC/5SDGR/oKil0C6KHhwk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eddie James , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 6.0 028/862] iio: pressure: dps310: Reset chip after timeout Date: Wed, 19 Oct 2022 10:21:55 +0200 Message-Id: <20221019083251.249994910@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Eddie James commit 7b4ab4abcea4c0c10b25187bf2569e5a07e9a20c upstream. The DPS310 chip has been observed to get "stuck" such that pressure and temperature measurements are never indicated as "ready" in the MEAS_CFG register. The only solution is to reset the device and try again. In order to avoid continual failures, use a boolean flag to only try the reset after timeout once if errors persist. Fixes: ba6ec48e76bc ("iio: Add driver for Infineon DPS310") Cc: Signed-off-by: Eddie James Reviewed-by: Andy Shevchenko Link: https://lore.kernel.org/r/20220915195719.136812-3-eajames@linux.ibm.c= om Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/pressure/dps310.c | 74 ++++++++++++++++++++++++++++++++++++-= ----- 1 file changed, 64 insertions(+), 10 deletions(-) --- a/drivers/iio/pressure/dps310.c +++ b/drivers/iio/pressure/dps310.c @@ -89,6 +89,7 @@ struct dps310_data { s32 c00, c10, c20, c30, c01, c11, c21; s32 pressure_raw; s32 temp_raw; + bool timeout_recovery_failed; }; =20 static const struct iio_chan_spec dps310_channels[] =3D { @@ -393,11 +394,69 @@ static int dps310_get_temp_k(struct dps3 return scale_factors[ilog2(rc)]; } =20 +static int dps310_reset_wait(struct dps310_data *data) +{ + int rc; + + rc =3D regmap_write(data->regmap, DPS310_RESET, DPS310_RESET_MAGIC); + if (rc) + return rc; + + /* Wait for device chip access: 2.5ms in specification */ + usleep_range(2500, 12000); + return 0; +} + +static int dps310_reset_reinit(struct dps310_data *data) +{ + int rc; + + rc =3D dps310_reset_wait(data); + if (rc) + return rc; + + return dps310_startup(data); +} + +static int dps310_ready_status(struct dps310_data *data, int ready_bit, in= t timeout) +{ + int sleep =3D DPS310_POLL_SLEEP_US(timeout); + int ready; + + return regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG, ready, rea= dy & ready_bit, + sleep, timeout); +} + +static int dps310_ready(struct dps310_data *data, int ready_bit, int timeo= ut) +{ + int rc; + + rc =3D dps310_ready_status(data, ready_bit, timeout); + if (rc) { + if (rc =3D=3D -ETIMEDOUT && !data->timeout_recovery_failed) { + /* Reset and reinitialize the chip. */ + if (dps310_reset_reinit(data)) { + data->timeout_recovery_failed =3D true; + } else { + /* Try again to get sensor ready status. */ + if (dps310_ready_status(data, ready_bit, timeout)) + data->timeout_recovery_failed =3D true; + else + return 0; + } + } + + return rc; + } + + data->timeout_recovery_failed =3D false; + return 0; +} + static int dps310_read_pres_raw(struct dps310_data *data) { int rc; int rate; - int ready; int timeout; s32 raw; u8 val[3]; @@ -409,9 +468,7 @@ static int dps310_read_pres_raw(struct d timeout =3D DPS310_POLL_TIMEOUT_US(rate); =20 /* Poll for sensor readiness; base the timeout upon the sample rate. */ - rc =3D regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG, ready, - ready & DPS310_PRS_RDY, - DPS310_POLL_SLEEP_US(timeout), timeout); + rc =3D dps310_ready(data, DPS310_PRS_RDY, timeout); if (rc) goto done; =20 @@ -448,7 +505,6 @@ static int dps310_read_temp_raw(struct d { int rc; int rate; - int ready; int timeout; =20 if (mutex_lock_interruptible(&data->lock)) @@ -458,10 +514,8 @@ static int dps310_read_temp_raw(struct d timeout =3D DPS310_POLL_TIMEOUT_US(rate); =20 /* Poll for sensor readiness; base the timeout upon the sample rate. */ - rc =3D regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG, ready, - ready & DPS310_TMP_RDY, - DPS310_POLL_SLEEP_US(timeout), timeout); - if (rc < 0) + rc =3D dps310_ready(data, DPS310_TMP_RDY, timeout); + if (rc) goto done; =20 rc =3D dps310_read_temp_ready(data); @@ -756,7 +810,7 @@ static void dps310_reset(void *action_da { struct dps310_data *data =3D action_data; =20 - regmap_write(data->regmap, DPS310_RESET, DPS310_RESET_MAGIC); + dps310_reset_wait(data); } =20 static const struct regmap_config dps310_regmap_config =3D {