Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1547602pxb; Thu, 16 Sep 2021 09:40:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlOfm265WZjAydB6RbZScITWc4yqWBL/I7dl1louL3n2DhNL1hR1fRFLlZzccYB1ghdoFs X-Received: by 2002:aa7:ca19:: with SMTP id y25mr7349372eds.197.1631810412926; Thu, 16 Sep 2021 09:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631810412; cv=none; d=google.com; s=arc-20160816; b=YzWj+qDqhmNoRM4orFgIXWeqTXQkESTbojKufyn3+oYIWMpjvwKIERPU41XUWimJrI MnfBY+t6iEcKcaLFn6DFC64JMY8v2yI0Xw4UvOHaRwkMvGljkmPlOEQkYAxyTmQ/qeKo 0986QEN40hmV9ZtyjLCQkcKlZyVNUaq2CLw1aAhyR58YxrBoR9hwxv3n+73RjYiel6bh QAYNYbJdsqbmatHLMgdQLfzB5gFPVnfx+IBl1w5mvGoHT5w1zhhQj9guy9Ro//+95rnj l/nmcM+12YmXtU6hfzeFPwYe1fJJqWOa2a90/fd2LkJq9qyYeayj82DSECnVfo92Rm3g stcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IQhxyXa17gYKCO+f5X7jBOrnikI5yMAfXBEMHUcXAa4=; b=tYbssE8x3s3qzbROBX0N0trrUG0HnwburltGecmeEO4kfouqAOLMOfqDOSCrQ4bx4v xDbRQAM8utWbgMMGCjdoeQDXrMm5UfWCzT+xxy+uP5F8113bbEaCIeAR5feILIirkp/X WYxMhKEWTvxKeqm9iYsz1YpOXQnPqCQOkuZJtl7MkFxIc2uI5b14zBCv0+Edm0LCZ2Kj a3vNRVYSAw37RI/5/C+7sxKSR00uIIFRrBozdxTOFLaBLlrtPtxVse7CQLFRWYz1glkn XjnJialaTIdPiqxAgItgb9yR5QUn0cYETqYf/40VgeAihY+zcWQaedmSZRRcRkLfXNgj TG7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Zs7WLImk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p6si4283112edb.407.2021.09.16.09.39.47; Thu, 16 Sep 2021 09:40:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Zs7WLImk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243469AbhIPQh6 (ORCPT + 99 others); Thu, 16 Sep 2021 12:37:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:38074 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242763AbhIPQ3b (ORCPT ); Thu, 16 Sep 2021 12:29:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0637A61373; Thu, 16 Sep 2021 16:18:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631809113; bh=rBUMzl3onosp598T5s5G9TA9eIJrYtyHlU6jND7CCzQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zs7WLImkW0ierOsQTejD613SaV5c9DE9gQM8cvg1wlElmtLYQGQGrXOlokD5lqCvs RzPcx19ZhgM4uXZiGrf+e+dwHBk9nuIftTkHqTgrKpuPOJIC/EwJU4Xuu0AqvxrQ9x hPEEfhpLuga+nj94d0kexpH8lN/p8Odc9vcuyEa4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Drew Fustini , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 5.13 034/380] iio: ltc2983: fix device probe Date: Thu, 16 Sep 2021 17:56:31 +0200 Message-Id: <20210916155805.125385937@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155803.966362085@linuxfoundation.org> References: <20210916155803.966362085@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nuno Sá commit b76d26d69ecc97ebb24aaf40427a13c808a4f488 upstream. There is no reason to assume that the IRQ rising edge (indicating that the device start up phase is done) will happen after we request the IRQ. If the device is already up by the time we request it, the call to 'wait_for_completion_timeout()' will timeout and we will fail the device probe even though there's nothing wrong. Fix it by just polling the status register until we get the indication that the device is up and running. As a side effect of this fix, requesting the IRQ is also moved to after the setup function. Fixes: f110f3188e563 ("iio: temperature: Add support for LTC2983") Reported-and-tested-by: Drew Fustini Reviewed-by: Drew Fustini Signed-off-by: Nuno Sá Reviewed-by: Andy Shevchenko Cc: Link: https://lore.kernel.org/r/20210811133220.190264-2-nuno.sa@analog.com Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/temperature/ltc2983.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) --- a/drivers/iio/temperature/ltc2983.c +++ b/drivers/iio/temperature/ltc2983.c @@ -89,6 +89,8 @@ #define LTC2983_STATUS_START_MASK BIT(7) #define LTC2983_STATUS_START(x) FIELD_PREP(LTC2983_STATUS_START_MASK, x) +#define LTC2983_STATUS_UP_MASK GENMASK(7, 6) +#define LTC2983_STATUS_UP(reg) FIELD_GET(LTC2983_STATUS_UP_MASK, reg) #define LTC2983_STATUS_CHAN_SEL_MASK GENMASK(4, 0) #define LTC2983_STATUS_CHAN_SEL(x) \ @@ -1362,17 +1364,16 @@ put_child: static int ltc2983_setup(struct ltc2983_data *st, bool assign_iio) { - u32 iio_chan_t = 0, iio_chan_v = 0, chan, iio_idx = 0; + u32 iio_chan_t = 0, iio_chan_v = 0, chan, iio_idx = 0, status; int ret; - unsigned long time; - - /* make sure the device is up */ - time = wait_for_completion_timeout(&st->completion, - msecs_to_jiffies(250)); - if (!time) { + /* make sure the device is up: start bit (7) is 0 and done bit (6) is 1 */ + ret = regmap_read_poll_timeout(st->regmap, LTC2983_STATUS_REG, status, + LTC2983_STATUS_UP(status) == 1, 25000, + 25000 * 10); + if (ret) { dev_err(&st->spi->dev, "Device startup timed out\n"); - return -ETIMEDOUT; + return ret; } st->iio_chan = devm_kzalloc(&st->spi->dev, @@ -1492,10 +1493,11 @@ static int ltc2983_probe(struct spi_devi ret = ltc2983_parse_dt(st); if (ret) return ret; - /* - * let's request the irq now so it is used to sync the device - * startup in ltc2983_setup() - */ + + ret = ltc2983_setup(st, true); + if (ret) + return ret; + ret = devm_request_irq(&spi->dev, spi->irq, ltc2983_irq_handler, IRQF_TRIGGER_RISING, name, st); if (ret) { @@ -1503,10 +1505,6 @@ static int ltc2983_probe(struct spi_devi return ret; } - ret = ltc2983_setup(st, true); - if (ret) - return ret; - indio_dev->name = name; indio_dev->num_channels = st->iio_channels; indio_dev->channels = st->iio_chan;