From patchwork Wed May 29 17:09:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 2631851 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 2AE963FC23 for ; Wed, 29 May 2013 17:11:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965048Ab3E2RLH (ORCPT ); Wed, 29 May 2013 13:11:07 -0400 Received: from www.linutronix.de ([62.245.132.108]:57945 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759712Ab3E2RKG (ORCPT ); Wed, 29 May 2013 13:10:06 -0400 Received: from localhost ([127.0.0.1] helo=localhost.localdomain) by Galois.linutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1Uhjsz-0000T6-Q6; Wed, 29 May 2013 19:10:06 +0200 From: Sebastian Andrzej Siewior To: linux-input@vger.kernel.org, linux-iio@vger.kernel.org Cc: sameo@linux.intel.com, jic23@cam.ac.uk, dmitry.torokhov@gmail.com, balbi@ti.com, Sebastian Andrzej Siewior Subject: [PATCH 5/5] iio/ti_am335x_adc: check if we found the value Date: Wed, 29 May 2013 19:09:56 +0200 Message-Id: <1369847397-27451-6-git-send-email-bigeasy@linutronix.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1369847397-27451-1-git-send-email-bigeasy@linutronix.de> References: <1369847397-27451-1-git-send-email-bigeasy@linutronix.de> X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1, SHORTCIRCUIT=-0.0001 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Usually we get all the values we wanted but it is possible, that te ADC unit is busy performing the conversation for the HW events. In that case -EBUSY is returned and the user may re-call the function. Signed-off-by: Sebastian Andrzej Siewior Acked-by: Jonathan Cameron --- drivers/iio/adc/ti_am335x_adc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c index df2de4c..6a00874 100644 --- a/drivers/iio/adc/ti_am335x_adc.c +++ b/drivers/iio/adc/ti_am335x_adc.c @@ -161,6 +161,7 @@ static int tiadc_read_raw(struct iio_dev *indio_dev, int i; unsigned int fifo1count, read; u32 step = UINT_MAX; + bool found = false; /* * When the sub-system is first enabled, @@ -185,10 +186,14 @@ static int tiadc_read_raw(struct iio_dev *indio_dev, fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT); for (i = 0; i < fifo1count; i++) { read = tiadc_readl(adc_dev, REG_FIFO1); - if (read >> 16 == step) + if (read >> 16 == step) { *val = read & 0xfff; + found = true; + } } tiadc_writel(adc_dev, REG_SE, STPENB_STEPENB); + if (found == false) + return -EBUSY; return IIO_VAL_INT; }