Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3673767rdb; Wed, 13 Sep 2023 21:40:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEuHwclFPJWgAIHgeuTci1vwFKLZ+FjJxf4fW+JeKKxTPIPdKOQD3h2xs8Hskdt9bNrQfhl X-Received: by 2002:a05:620a:172c:b0:76c:707e:8fdc with SMTP id az44-20020a05620a172c00b0076c707e8fdcmr5921093qkb.6.1694666442990; Wed, 13 Sep 2023 21:40:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694666442; cv=none; d=google.com; s=arc-20160816; b=akbF/ouXDJQwwj3fAEMvpYmnupNLxA7iuu3/OiF9MvxshSoRnzAhdePihWG3HfUYPe J3vRkVusIlPRYqXD+0lSKpmJs5go74UZSDD0QQpOui9vW0D4Yb/HGA+OWmeIeFgwGxAD K/klzxw8CW3F3RffEwlrmV9hmOtEJGCRuYtzFv5heo1jUQHHMhL4x+1focZgvtEezcbd bTtB0z+Y8wJBv1ZczvbFY+bc5EuH/ik39RE/x0cNA74M6iETDAsk8+hySTVA91nMJf39 hCNRjCqUcG9OC3lqqBUeAw28zTwq9KLh7zHHgL9wWrxF9aa6EBsH6O//6usEEgpK5EJI Qidg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hH6wJzXMgqPwumYM31XLC1tLMzx/YThsefhzjlMqmyY=; fh=V2IY9JiXP/LhUMpX66+Nr0N3VSfqLapXj8NIppeg0Gk=; b=sZP9ALSezT/7Lq2YaGySIEnJy/w9dEL29u317MFiwhemMsr8g1a7AjXYtnXT0q7nhq lDTSMXLoFL0kILtJXUurLg5pp8xBz6uvXFFeDro/GzK+PkA0KQgOQxjYcuueezwD3gVw whm63kDag0mwvge6V3S9INQvKQzI2Kj+HPjRLMgwQBYKYHVY6bEMpLb1aCyqTExiINWL IiaCvpyJbzlI7ZVSENYigSrOIfhD7GTw4QNroQD3aNs8cnz8jPGebZT5fGT3DMsiKgK8 CxmyTccJ8t7Y0lwSqkfMMpFXj8v4eJ2+TytgsJzoqaZsSEUQyxyIikhedVcABAZ0sSUI nYbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mev.co.uk header.s=20221208-6x11dpa4 header.b="CysSO0/y"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=mev.co.uk Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id f19-20020a056a0022d300b0068bc14cabc0si816137pfj.31.2023.09.13.21.40.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 21:40:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@mev.co.uk header.s=20221208-6x11dpa4 header.b="CysSO0/y"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=mev.co.uk Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id AAF67820E535; Wed, 13 Sep 2023 04:33:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240576AbjIMLdv (ORCPT + 99 others); Wed, 13 Sep 2023 07:33:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240476AbjIMLdd (ORCPT ); Wed, 13 Sep 2023 07:33:33 -0400 Received: from smtp75.iad3a.emailsrvr.com (smtp75.iad3a.emailsrvr.com [173.203.187.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A8D21FC3 for ; Wed, 13 Sep 2023 04:33:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mev.co.uk; s=20221208-6x11dpa4; t=1694604801; bh=ksLlkWZwHcv286ezdkSmNkFGXAPDZINrMsbQLaeKFwg=; h=From:To:Subject:Date:From; b=CysSO0/yfZIR3RYSURAAmveLFonc3+ZtUFkLcky19B3mL9yEdHOG96Wl8bAvsF8v6 wfItTHT4hyVgxkj5OJgB2bGIPc3WwARtdtehlz00uncxi1mQKqeBNNeDyowyNIqnfe D3W2Xspx8CdxmjfxGZwaRt5a7H+p2bjaecgFDKsA= X-Auth-ID: abbotti@mev.co.uk Received: by smtp26.relay.iad3a.emailsrvr.com (Authenticated sender: abbotti-AT-mev.co.uk) with ESMTPSA id A5E39424A; Wed, 13 Sep 2023 07:33:20 -0400 (EDT) From: Ian Abbott To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , Ian Abbott , H Hartley Sweeten , Arnd Bergmann , Niklas Schnelle Subject: [PATCH 11/13] comedi: amplc_dio200_common: Refactor register access functions Date: Wed, 13 Sep 2023 12:32:45 +0100 Message-Id: <20230913113247.91749-12-abbotti@mev.co.uk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230913113247.91749-1-abbotti@mev.co.uk> References: <20230913113247.91749-1-abbotti@mev.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Classification-ID: 007ec4bd-2574-475a-9bbd-5a4f93b29aec-12-1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 13 Sep 2023 04:33:53 -0700 (PDT) The `dio200_read8()`, `dio200_write8()`, `dio200_read32()` and `dio200_write32()` functions apply a right-shift to the register offset for some devices and then perform the actual register access. Factor the register access part out to new functions `dio200___read8()`, `dio200___write8()`, `dio200___read32()`, and `dio200___write32()`. This will reduce duplicated code in a subsequent patch that will conditionally compile support for port I/O as part of the `HAS_PORTIO` changes. Cc: Arnd Bergmann Cc: Niklas Schnelle Signed-off-by: Ian Abbott --- drivers/comedi/drivers/amplc_dio200_common.c | 52 ++++++++++++++------ 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/drivers/comedi/drivers/amplc_dio200_common.c b/drivers/comedi/drivers/amplc_dio200_common.c index 19166cb26f5e..e6d63e89e7bf 100644 --- a/drivers/comedi/drivers/amplc_dio200_common.c +++ b/drivers/comedi/drivers/amplc_dio200_common.c @@ -86,6 +86,40 @@ struct dio200_subdev_intr { unsigned int active:1; }; +static unsigned char dio200___read8(struct comedi_device *dev, + unsigned int offset) +{ + if (dev->mmio) + return readb(dev->mmio + offset); + return inb(dev->iobase + offset); +} + +static void dio200___write8(struct comedi_device *dev, + unsigned int offset, unsigned char val) +{ + if (dev->mmio) + writeb(val, dev->mmio + offset); + else + outb(val, dev->iobase + offset); +} + +static unsigned int dio200___read32(struct comedi_device *dev, + unsigned int offset) +{ + if (dev->mmio) + return readl(dev->mmio + offset); + return inl(dev->iobase + offset); +} + +static void dio200___write32(struct comedi_device *dev, + unsigned int offset, unsigned int val) +{ + if (dev->mmio) + writel(val, dev->mmio + offset); + else + outl(val, dev->iobase + offset); +} + static unsigned char dio200_read8(struct comedi_device *dev, unsigned int offset) { @@ -94,9 +128,7 @@ static unsigned char dio200_read8(struct comedi_device *dev, if (board->is_pcie) offset <<= 3; - if (dev->mmio) - return readb(dev->mmio + offset); - return inb(dev->iobase + offset); + return dio200___read8(dev, offset); } static void dio200_write8(struct comedi_device *dev, @@ -107,10 +139,7 @@ static void dio200_write8(struct comedi_device *dev, if (board->is_pcie) offset <<= 3; - if (dev->mmio) - writeb(val, dev->mmio + offset); - else - outb(val, dev->iobase + offset); + dio200___write8(dev, offset, val); } static unsigned int dio200_read32(struct comedi_device *dev, @@ -121,9 +150,7 @@ static unsigned int dio200_read32(struct comedi_device *dev, if (board->is_pcie) offset <<= 3; - if (dev->mmio) - return readl(dev->mmio + offset); - return inl(dev->iobase + offset); + return dio200___read32(dev, offset); } static void dio200_write32(struct comedi_device *dev, @@ -134,10 +161,7 @@ static void dio200_write32(struct comedi_device *dev, if (board->is_pcie) offset <<= 3; - if (dev->mmio) - writel(val, dev->mmio + offset); - else - outl(val, dev->iobase + offset); + dio200___write32(dev, offset, val); } static unsigned int dio200_subdev_8254_offset(struct comedi_device *dev, -- 2.40.1