From patchwork Fri Nov 9 03:25:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 150603 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1645305ljp; Thu, 8 Nov 2018 19:26:02 -0800 (PST) X-Google-Smtp-Source: AJdET5eDTFNkvtMVsHHIXHQhU0FbvFmisouZBO4DQocerdcJVt+maRlcOv/UC8hB7iyTVBrOJDDs X-Received: by 2002:a63:63c3:: with SMTP id x186mr6048129pgb.330.1541733962314; Thu, 08 Nov 2018 19:26:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541733962; cv=none; d=google.com; s=arc-20160816; b=CZMFxsk7miqr4/dP21pE007yZ1mSZpUIdK5NjDxLzNLFzFE9ZZJ0WyBMCr4qBD7llS SrZ2G0skkvTgN5vBzTwD4dzpu0F/BEeSFZaA+7tjLHbQ+jdJDBK9eKBw/uUZZx8J7Q3o HCc/+Obc7Wk7ssj71/Lal/26j0p8ltzK0pXMWLinAfEifxwO5FxwWB8ECLj1VjTJREzd RC8SUdN3F++uSTQcDKGyLSSb9LaGD5QTG5xsZRQ8N2Lbh063CI6/SbmpbU4QsQP97kev VE2Q2tMybDNjXa6h/4kiaeX1ITn0WRowHxYT299iVfnkSRZ+thoryUNN3jViw7i71pMB AjxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=yX2sCd2EA1FTKfmRYjC58TpT5nQVf8lwKNV7j+JnwoA=; b=sJUAgtSIyZIyHpZQ++i1nnCSqiuZY8uRxLkhYHaBlYTFk6FhBLczWTn8GC4FqPgOnr u6DcfzdhCh3o8PmCAZiy5uaDfrU4HYD1lqORy3zSNcD6mbgtbiDgNrxeZVYVp1hoIG1o 9UebBC8l/y2EhqYdjGx/wBww2A/RH7Aomyw9VT8PAegu1b1qjzKnLB3KwhWDiOAXgzeR I67jVoLHWlxVFOOYAtdKH9RPvaibjKUcysEcgJT0FPWN/LQ2wk1JyaChiDrCAmTywqCk 3+hO9wXZSPlNi2Xu42z1nEyXT0hPEzU4PpaZqcHgAJm6AKjjrwXhUJYyTpjnnus0g8Ps O0sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GJwqF1YA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f10-v6si6038478plo.109.2018.11.08.19.26.01; Thu, 08 Nov 2018 19:26:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GJwqF1YA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727532AbeKINEi (ORCPT + 32 others); Fri, 9 Nov 2018 08:04:38 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:42690 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727378AbeKINEh (ORCPT ); Fri, 9 Nov 2018 08:04:37 -0500 Received: by mail-pl1-f195.google.com with SMTP id t6-v6so265416plo.9 for ; Thu, 08 Nov 2018 19:26:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=yX2sCd2EA1FTKfmRYjC58TpT5nQVf8lwKNV7j+JnwoA=; b=GJwqF1YAE8+XFqsMPGlLa5K1x5M0ynidJ3srGG1Gsug9GkYRPjW8nKPItLgwL/t5XL tRsXtSnck7I/I/g9dn12vUY8YP7xJLjaZ8iKmkIfoHGA+I8ODwETEG/KVDaE5g4hM0BS KNE4gfzekefEf9dP9Pl1Zfva2OtQGZMkNSStM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=yX2sCd2EA1FTKfmRYjC58TpT5nQVf8lwKNV7j+JnwoA=; b=cu/Skcj5yjnzsxxrLDNSreyBmuoJ0uugJ6wMYpa7lYN2fjurNa+33FTY2E4NR3wkb6 lKr+zndhGqKzaR/NenS8FjITJzJs1t7oGFZrTICMsRDzN30jNfXbH0+cuAH0dg0lI+A+ jMi7vrQjya1reZLFH7r3RdcluzdFTRk20rWW2e77OHMw/51GyrqWDiMPoNvYh3Pxlm8m heg1x0oi59IhsAy6nzH1dXHBrvLIBydHOu2FK0ieH4um9aPM+qzTJxEpKQX95klEvoEd QCuHUNjiAe5/jzGKuASKKM5RbrpykgHB47wO7nOT7t8UezKQEL74ErZG+JwMLgBqgDcc 93KQ== X-Gm-Message-State: AGRZ1gL3HkQlfR88SuhrYcnCw3h5mRnx5zCteB2ChbmHrXwEP9FHaSDJ 9dIFPDlawJ6M137zHiiF7BUz/g== X-Received: by 2002:a17:902:6b46:: with SMTP id g6-v6mr7176191plt.33.1541733959593; Thu, 08 Nov 2018 19:25:59 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id h7-v6sm6656675pfd.35.2018.11.08.19.25.55 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Nov 2018 19:25:58 -0800 (PST) From: Baolin Wang To: jic23@kernel.org Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, freeman.liu@unisoc.com, broonie@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [PATCH] iio: adc: sc27xx: Add ADC data conversion timeout Date: Fri, 9 Nov 2018 11:25:31 +0800 Message-Id: <208f9043fbd9b14b7a0c2743f68fa424388f5dcd.1541733478.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Freeman Liu Sometimes the ADC controller met some problems, and it will not complete the data conversion, that will can not wake up the read process any more to block users. So we should add one maximum conversion time to avoid this issue. Signed-off-by: Freeman Liu Signed-off-by: Baolin Wang --- drivers/iio/adc/sc27xx_adc.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) -- 1.7.9.5 diff --git a/drivers/iio/adc/sc27xx_adc.c b/drivers/iio/adc/sc27xx_adc.c index 7940b23..f7f7a189 100644 --- a/drivers/iio/adc/sc27xx_adc.c +++ b/drivers/iio/adc/sc27xx_adc.c @@ -52,6 +52,9 @@ /* Timeout (ms) for the trylock of hardware spinlocks */ #define SC27XX_ADC_HWLOCK_TIMEOUT 5000 +/* Timeout (ms) for ADC data conversion according to ADC datasheet */ +#define SC27XX_ADC_RDY_TIMEOUT 100 + /* Maximum ADC channel number */ #define SC27XX_ADC_CHANNEL_MAX 32 @@ -223,7 +226,14 @@ static int sc27xx_adc_read(struct sc27xx_adc_data *data, int channel, if (ret) goto disable_adc; - wait_for_completion(&data->completion); + ret = wait_for_completion_timeout(&data->completion, + msecs_to_jiffies(SC27XX_ADC_RDY_TIMEOUT)); + if (!ret) { + dev_err(data->dev, "read ADC data timeout\n"); + ret = -ETIMEDOUT; + } else { + ret = 0; + } disable_adc: regmap_update_bits(data->regmap, data->base + SC27XX_ADC_CTL,