From patchwork Wed Sep 17 08:23:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sanchayan X-Patchwork-Id: 4923101 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 204B5BEEA5 for ; Wed, 17 Sep 2014 08:26:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 62DB0201B4 for ; Wed, 17 Sep 2014 08:26:45 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1B462201CD for ; Wed, 17 Sep 2014 08:26:44 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XUAXo-000277-Qi; Wed, 17 Sep 2014 08:24:56 +0000 Received: from mail-pa0-x22c.google.com ([2607:f8b0:400e:c03::22c]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XUAXc-0001u6-OG for linux-arm-kernel@lists.infradead.org; Wed, 17 Sep 2014 08:24:45 +0000 Received: by mail-pa0-f44.google.com with SMTP id kx10so1696900pab.31 for ; Wed, 17 Sep 2014 01:24:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references:mime-version:content-type :content-transfer-encoding; bh=z06Q7nkMH7MWurkDGBEPBmNxJtmunpZGb++Bs2pgxDA=; b=WS+16DXD+Hv5ZQM8iyEMXnZejQByohvJwo1x90a2AKkgc3MKzJ43+BaboD10H+CTfg 8VaHo+vkLLO4zjRoxDeLH8Qwv1zF/2bPRjfIKw7ZXpw/znRfD9DaPO6svO/CPqr9Y9uh 18zlgYkFqipgbrmu56SsdujSGCem8LtKZQltG4DIbvmStevm1M7LD6laOX9lHoLItM1q z2KAqQvTcjxlsQCAMuSBLvF4mJKiu0lhsf1zBxfcEpvwI4dysb7B6Tuti5N2/2cr4/kN x9KJd2lfNSF9d2VxNzKOGwEKzcnJAiI0JgdDgYt20rfT6rA/TCNUUktZPvlT7rrgx1kf CnUw== X-Received: by 10.66.156.42 with SMTP id wb10mr2360568pab.155.1410942263553; Wed, 17 Sep 2014 01:24:23 -0700 (PDT) Received: from pallav-Inspiron-660s.toradex.int ([115.115.225.206]) by mx.google.com with ESMTPSA id sl9sm16165588pbc.46.2014.09.17.01.24.20 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 17 Sep 2014 01:24:22 -0700 (PDT) From: Sanchayan Maity To: shawn.guo@freescale.com Subject: =?UTF-8?q?=5BPATCH=202/2=5D=20ARM=3A=20imx=3A=20vf610-adc=3A=20Add=20temperature=20sensor=20support?= Date: Wed, 17 Sep 2014 13:53:17 +0530 Message-Id: <0cd6b1bdf146a0c9024a804742078ce77a38e184.1410873422.git.maitysanchayan@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140917_012444_870547_A96D7CE1 X-CRM114-Status: GOOD ( 16.44 ) X-Spam-Score: -0.8 (/) Cc: linux@arm.linux.org.uk, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, stefan@agner.ch, Sanchayan Maity , linux-arm-kernel@lists.infradead.org, B38611@freescale.com, jic23@kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Vybrid ADC module includes a temperature sensor which is connected to channel number 26. This patch adds support for the sensor. The raw value is read and the temperature calculated in degree Celsius which is returned using the IIO_CHAN_INFO_PROCESSED option. Signed-off-by: Sanchayan Maity --- drivers/iio/adc/vf610_adc.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/drivers/iio/adc/vf610_adc.c b/drivers/iio/adc/vf610_adc.c index 44799eb5..aa682aa 100644 --- a/drivers/iio/adc/vf610_adc.c +++ b/drivers/iio/adc/vf610_adc.c @@ -91,7 +91,7 @@ #define VF610_ADC_CAL 0x80 /* Other field define */ -#define VF610_ADC_ADCHC(x) ((x) & 0xF) +#define VF610_ADC_ADCHC(x) ((x) & 0x1F) #define VF610_ADC_AIEN (0x1 << 7) #define VF610_ADC_CONV_DISABLE 0x1F #define VF610_ADC_HS_COCO0 0x1 @@ -137,7 +137,7 @@ struct vf610_adc { struct clk *clk; u32 vref_uv; - u32 value; + int value; struct regulator *vref; struct vf610_adc_feature adc_feature; @@ -153,6 +153,15 @@ struct vf610_adc { BIT(IIO_CHAN_INFO_SAMP_FREQ), \ } +#define VF610_ADC_TEMPERATURE_CHAN(_idx, _chan_type) { \ + .type = (_chan_type), \ + .indexed = 1, \ + .channel = (_idx), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ +} + static const struct iio_chan_spec vf610_adc_iio_channels[] = { VF610_ADC_CHAN(0, IIO_VOLTAGE), VF610_ADC_CHAN(1, IIO_VOLTAGE), @@ -170,6 +179,7 @@ static const struct iio_chan_spec vf610_adc_iio_channels[] = { VF610_ADC_CHAN(13, IIO_VOLTAGE), VF610_ADC_CHAN(14, IIO_VOLTAGE), VF610_ADC_CHAN(15, IIO_VOLTAGE), + VF610_ADC_TEMPERATURE_CHAN(26, IIO_TEMP), /* sentinel */ }; @@ -451,6 +461,7 @@ static int vf610_read_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: + case IIO_CHAN_INFO_PROCESSED: mutex_lock(&indio_dev->mlock); reinit_completion(&info->completion); @@ -468,7 +479,24 @@ static int vf610_read_raw(struct iio_dev *indio_dev, return ret; } - *val = info->value; + switch (chan->type) { + case IIO_VOLTAGE: + *val = info->value; + break; + case IIO_TEMP: + /* + * Calculate in degree celsius times 1000 + * Using sensor slope of 1.84 mV/°C and + * V at 25°C of 696mv + */ + info->value -= 864; + info->value = 25000 - info->value * 1000000 / 1840; + *val = info->value; + break; + default: + break; + } + mutex_unlock(&indio_dev->mlock); return IIO_VAL_INT;