Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1922451imu; Sat, 5 Jan 2019 09:57:49 -0800 (PST) X-Google-Smtp-Source: ALg8bN5/Hp1Kj1Mwk6jxAH/pB1bpyxYcxt1qxgw2Q7Gz+azs+8WBi8QAw4wCDnbPf8bagn0R7w6h X-Received: by 2002:a63:e40c:: with SMTP id a12mr24625012pgi.28.1546711069064; Sat, 05 Jan 2019 09:57:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546711069; cv=none; d=google.com; s=arc-20160816; b=K81KOgRWSWWirX1E023YKlfelEKFgoKmze4/DHU1pdDNw1KTeFM+ndDtzQ9+PElSeg EmK/JRB11/jlncz7N8aXOITUQn+tMGGzrnkbd5oD/ylAS95OQyBaxgSdzgE8yVz2K+Cj Hr1xVdKAwYJM7RqjhW5dqZbpUTo+g3h2Jpqa1NxF+2dlMFXrgd/zrVutM+ece0pqFBpO 3RwjJ1JqSpP7bm3Ms4D22MPx0i44lRkICNLkQU0hu3OITs3dVJxsJMi87fambMgys16V Zq+VUbFj6aiiYLccNuX5RqY3Y+zEMN3j82CaLk9tAYnh6JMX7uTdUgcbup3etTWIFSkE lHJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=2k7xrByAGuxANa7QWv59YHiIrI29Wfm3EJ213/7T/AQ=; b=bPr/4lRK4RnPgCMES1wlE5t55Nbn5/vky02Ge2Tv946n/vBUQVVLOyCoBXNMQyeN+c LqYKgE09v+tACJbkl0ZmL5DjkmJYHqtucmPUk8h+8Zzee3wldfi16DTyH9kb/kUG0SCo Y0nXnyYgwpW2YHRINF5fxoTvbyg67p+B7e7tQh3p07ubUSmsOOZDerd37nTRocVuURMh 6hNFZ7GMMGF86axD6dZpHBC/d3w/bauJwl9DxqOlcXnqXjJ9mhlDBttQv4djtNvAcqNi kwpQJkKL5ba9FfOMXITzbMPVcn6u/9XNO6wUv8A/hASAYPW6xCpwHmmyNzx8qYsaDJuD vOmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=M6kqzt0O; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f11si54715924plr.341.2019.01.05.09.57.33; Sat, 05 Jan 2019 09:57:49 -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=@kernel.org header.s=default header.b=M6kqzt0O; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727059AbfAERzR (ORCPT + 99 others); Sat, 5 Jan 2019 12:55:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:48234 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727055AbfAERzQ (ORCPT ); Sat, 5 Jan 2019 12:55:16 -0500 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9CA3222314; Sat, 5 Jan 2019 17:55:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546710916; bh=ze70YVLrHSkambMqyHRknCK+tPO5y2Rm3lOFhnUerbk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=M6kqzt0OB4GtDInuhFF3oB2CWfTOGAeRSvzbwt1gfwUCCvk/Z7psSsyus7YDpQAi5 uz5Ob7T9UC0b5gUiBS+2Vj/YRMsVDwMq0BPS/0F780xZiYa8CPrS/2wFKGy7bT4Q55 GB3gHAhahMHPp+dDw85f6QGTVNr5L4WUKTjn132w= Date: Sat, 5 Jan 2019 17:55:11 +0000 From: Jonathan Cameron To: Jeremy Fertic Cc: Lars-Peter Clausen , Michael Hennerich , Hartmut Knaack , Peter Meerwald-Stadler , Greg Kroah-Hartman , linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Shreeya Patel Subject: Re: [PATCH v2 3/4] staging: iio: adt7316: fix the dac read calculation Message-ID: <20190105175511.2edcb939@archlinux> In-Reply-To: <20181223045743.10716-4-jeremyfertic@gmail.com> References: <20181223045743.10716-1-jeremyfertic@gmail.com> <20181223045743.10716-4-jeremyfertic@gmail.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 22 Dec 2018 21:57:42 -0700 Jeremy Fertic wrote: > The calculation of the current dac value is using the wrong bits of the > dac lsb register. Create two macros to shift the lsb register value into > lsb position, depending on whether the dac is 10 or 12 bit. Initialize > data to 0 so, with an 8 bit dac, the msb register value can be bitwise > ORed with data. > > Fixes: 35f6b6b86ede ("staging: iio: new ADT7316/7/8 and ADT7516/7/9 driver") > Signed-off-by: Jeremy Fertic Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it. Thanks, Jonathan > --- > drivers/staging/iio/addac/adt7316.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c > index 80cc3420036b..d7f3d68e525b 100644 > --- a/drivers/staging/iio/addac/adt7316.c > +++ b/drivers/staging/iio/addac/adt7316.c > @@ -47,6 +47,8 @@ > #define ADT7516_MSB_AIN3 0xA > #define ADT7516_MSB_AIN4 0xB > #define ADT7316_DA_DATA_BASE 0x10 > +#define ADT7316_DA_10_BIT_LSB_SHIFT 6 > +#define ADT7316_DA_12_BIT_LSB_SHIFT 4 > #define ADT7316_DA_MSB_DATA_REGS 4 > #define ADT7316_LSB_DAC_A 0x10 > #define ADT7316_MSB_DAC_A 0x11 > @@ -1392,7 +1394,7 @@ static IIO_DEVICE_ATTR(ex_analog_temp_offset, 0644, > static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip, > int channel, char *buf) > { > - u16 data; > + u16 data = 0; > u8 msb, lsb, offset; > int ret; > > @@ -1417,7 +1419,11 @@ static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip, > if (ret) > return -EIO; > > - data = (msb << offset) + (lsb & ((1 << offset) - 1)); > + if (chip->dac_bits == 12) > + data = lsb >> ADT7316_DA_12_BIT_LSB_SHIFT; > + else if (chip->dac_bits == 10) > + data = lsb >> ADT7316_DA_10_BIT_LSB_SHIFT; > + data |= msb << offset; > > return sprintf(buf, "%d\n", data); > }