From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753411AbaIALEZ (ORCPT ); Mon, 1 Sep 2014 07:04:25 -0400 Received: from mail.mev.co.uk ([62.49.15.74]:39008 "EHLO mail.mev.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753385AbaIALEX (ORCPT ); Mon, 1 Sep 2014 07:04:23 -0400 From: Ian Abbott To: driverdev-devel@linuxdriverproject.org Cc: Greg Kroah-Hartman , Ian Abbott , H Hartley Sweeten , linux-kernel@vger.kernel.org Subject: [PATCH 14/28] staging: comedi: amplc_pci230: simplify pci230_ao_mangle_datum() Date: Mon, 1 Sep 2014 12:03:46 +0100 Message-Id: <1409569440-10979-15-git-send-email-abbotti@mev.co.uk> X-Mailer: git-send-email 2.0.4 In-Reply-To: <1409569440-10979-1-git-send-email-abbotti@mev.co.uk> References: <1409569440-10979-1-git-send-email-abbotti@mev.co.uk> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org `pci230_ao_mangle_datum()` converts comedi sample values for the AO subdevice to hardware register values. The comedi sample value will be an unsigned value in the range 0 to 4095 (assuming 12-bit resolution). The hardware wants the value shifted so the m.s. bit of the sample in in bit 15. If set to a bipolar range, it also expects a 2's complement value, so the top bit of the sample value needs to be inverted in that case. Simplify the existing code by doing the 2's complement conversion after the shift. That way, it is always bit 15 that is inverted regardless of the resolution. Signed-off-by: Ian Abbott --- drivers/staging/comedi/drivers/amplc_pci230.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c b/drivers/staging/comedi/drivers/amplc_pci230.c index 7fa9c70..e4151d7 100644 --- a/drivers/staging/comedi/drivers/amplc_pci230.c +++ b/drivers/staging/comedi/drivers/amplc_pci230.c @@ -583,17 +583,16 @@ static inline unsigned short pci230_ao_mangle_datum(struct comedi_device *dev, struct pci230_private *devpriv = dev->private; /* - * If a bipolar range was specified, mangle it - * (straight binary->twos complement). - */ - if (devpriv->ao_bipolar) - datum ^= 1 << (thisboard->ao_bits - 1); - - /* * PCI230 is 12 bit - stored in upper bits of 16 bit register (lower * four bits reserved for expansion). PCI230+ is also 12 bit AO. */ datum <<= (16 - thisboard->ao_bits); + /* + * If a bipolar range was specified, mangle it + * (straight binary->twos complement). + */ + if (devpriv->ao_bipolar) + datum ^= 0x8000; return datum; } -- 2.0.4 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from hemlock.osuosl.org (hemlock.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 9A4F51C2BDF for ; Mon, 1 Sep 2014 11:04:23 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 97E068B286 for ; Mon, 1 Sep 2014 11:04:23 +0000 (UTC) Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KoMdS3pU+WRC for ; Mon, 1 Sep 2014 11:04:23 +0000 (UTC) Received: from mail.mev.co.uk (mail.mev.co.uk [62.49.15.74]) by hemlock.osuosl.org (Postfix) with ESMTP id C92A98B277 for ; Mon, 1 Sep 2014 11:04:22 +0000 (UTC) From: Ian Abbott Subject: [PATCH 14/28] staging: comedi: amplc_pci230: simplify pci230_ao_mangle_datum() Date: Mon, 1 Sep 2014 12:03:46 +0100 Message-Id: <1409569440-10979-15-git-send-email-abbotti@mev.co.uk> In-Reply-To: <1409569440-10979-1-git-send-email-abbotti@mev.co.uk> References: <1409569440-10979-1-git-send-email-abbotti@mev.co.uk> List-Id: Linux Driver Project Developer List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: driverdev-devel-bounces@linuxdriverproject.org Sender: driverdev-devel-bounces@linuxdriverproject.org To: driverdev-devel@linuxdriverproject.org Cc: Greg Kroah-Hartman , Ian Abbott , linux-kernel@vger.kernel.org `pci230_ao_mangle_datum()` converts comedi sample values for the AO subdevice to hardware register values. The comedi sample value will be an unsigned value in the range 0 to 4095 (assuming 12-bit resolution). The hardware wants the value shifted so the m.s. bit of the sample in in bit 15. If set to a bipolar range, it also expects a 2's complement value, so the top bit of the sample value needs to be inverted in that case. Simplify the existing code by doing the 2's complement conversion after the shift. That way, it is always bit 15 that is inverted regardless of the resolution. Signed-off-by: Ian Abbott Reviewed-by: H Hartley Sweeten --- drivers/staging/comedi/drivers/amplc_pci230.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c b/drivers/staging/comedi/drivers/amplc_pci230.c index 7fa9c70..e4151d7 100644 --- a/drivers/staging/comedi/drivers/amplc_pci230.c +++ b/drivers/staging/comedi/drivers/amplc_pci230.c @@ -583,17 +583,16 @@ static inline unsigned short pci230_ao_mangle_datum(struct comedi_device *dev, struct pci230_private *devpriv = dev->private; /* - * If a bipolar range was specified, mangle it - * (straight binary->twos complement). - */ - if (devpriv->ao_bipolar) - datum ^= 1 << (thisboard->ao_bits - 1); - - /* * PCI230 is 12 bit - stored in upper bits of 16 bit register (lower * four bits reserved for expansion). PCI230+ is also 12 bit AO. */ datum <<= (16 - thisboard->ao_bits); + /* + * If a bipolar range was specified, mangle it + * (straight binary->twos complement). + */ + if (devpriv->ao_bipolar) + datum ^= 0x8000; return datum; } -- 2.0.4 _______________________________________________ devel mailing list devel@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel