Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1561036imu; Sun, 16 Dec 2018 03:46:48 -0800 (PST) X-Google-Smtp-Source: AFSGD/WUsmEHUOnULD/ierhvZ3ZmCeXC05v/3nqESWDiROS8lumc1fSxunbLQ4Oe7tYAPk88nQnQ X-Received: by 2002:a17:902:7848:: with SMTP id e8mr9485314pln.100.1544960808170; Sun, 16 Dec 2018 03:46:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544960808; cv=none; d=google.com; s=arc-20160816; b=miP0jFciTT3uERaT4wQcimvkD3mnlnI563gGtdJRosLxdP2yMmCjY/XSaoMOq2+dUJ lio8gH9PdRJAKqKFAmVCuWL/DDUPnalIaGYmupYNshkw57G9/HC7fhk+UaIxTRjFig/w UJ0ok3as+oOme9bFhMKCy5ybcU7lfXdjiD4gz5FANUHRjTZe5y4cYN5NLwXtXvLl1jCN Ehqj/kIlmP17iFPLj5LX1yLTryD89CfuwZ7gBHdQQceFPl31P85Wk396QyakhxBV7WMG UPwFuDuv0ZHyyLWdRphyTyD6UWvpcU3civCGtKS//nd2j1qIluhbeZICpCJdvEPOyKXM 4S0Q== 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=3LLeoWb53QEA49fgRzlW2L8WAiZ+PcycEEInSaHt49w=; b=bgTAhM0BVZkkS51Rumwr0k/B/rzPPYb/XVKFP28S7qLorsro35MmEwk2zo8aXuQ0d6 baRJF2Wcq1Pd0H/WGQC6FP3GXFarlT0Df7V7SnMHhRyJ4GKAlvqkvFXf11yMThfO+jIZ 9IYXCmpJXo5+ZqUUC+L6en/DziMP6EDhu7mntRcHI+INi9WmciGub4PZCug8VCfr3WPb Qe0hNoW9+NKw7z0sQtpe4nuBShn+wEVnAoEck+B9ovWSj+Vx1fhLX6YI+qfu6BXE3bGz T77BcjUHsQ4JSIrcSxjUdE71E7PlBQF6YyzZ390q8OORlgw686guEK5FYpThvfQUVnIB dsEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=infhno3X; 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 q8si8251325plr.382.2018.12.16.03.46.31; Sun, 16 Dec 2018 03:46:48 -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=infhno3X; 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 S1730199AbeLPLpi (ORCPT + 99 others); Sun, 16 Dec 2018 06:45:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:57140 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729820AbeLPLph (ORCPT ); Sun, 16 Dec 2018 06:45:37 -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 35CE3217FB; Sun, 16 Dec 2018 11:45:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544960736; bh=Y/6thFYvlIRLgXsiCfX9HYMUbncgupeIWrOqHrZX73U=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=infhno3XaAzCK8HkeH/hb99Xjj0Ke+PxLNTJwk01Bhas+bkGTw+FqDF0FEDPgQVzi ZruVT3PnyjRwZYXtKYYVL332CAD4kQNmF3ehxZBiG45yszbb7ZyWkQBBABWj6R2bZj QgFFM6VaMy4/WEgK1wZi0i6+8w4QukvXNsBJsn0w= Date: Sun, 16 Dec 2018 11:45:31 +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 Subject: Re: [PATCH 05/11] staging: iio: adt7316: fix the dac read calculation Message-ID: <20181216114531.67bab793@archlinux> In-Reply-To: <20181212005503.28054-6-jeremyfertic@gmail.com> References: <20181212005503.28054-1-jeremyfertic@gmail.com> <20181212005503.28054-6-jeremyfertic@gmail.com> X-Mailer: Claws Mail 3.17.2 (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 Tue, 11 Dec 2018 17:54:57 -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. > > Signed-off-by: Jeremy Fertic This looks good, but with the previous 2 patches under discussion I'll hold this one for v2. 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 eee7c04f93f4..b7d12d003ddc 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 > @@ -1403,7 +1405,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; > > @@ -1428,7 +1430,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); > }