Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3585463rdb; Wed, 13 Sep 2023 17:27:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHe6eXF9rkZfBTxNfjktKPXCbk/ThswIhyqYcyVvenY+KBg6YQa7NeLtF+muijewWnEZ378 X-Received: by 2002:a05:6358:c613:b0:13c:d344:e414 with SMTP id fd19-20020a056358c61300b0013cd344e414mr3000002rwb.2.1694651248191; Wed, 13 Sep 2023 17:27:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694651248; cv=none; d=google.com; s=arc-20160816; b=c9CjZTAt46O/Hv8/4keu5Y1nKEEX0DSI3h7rzVJKAWgt9Y0fFt5az3fEVznOuFcEmd GGAC5+JsOTjiY3R2xLb8WO1x9NFtxJ9/yR1yrDIh3Uyz2F9O1KgPjLRqT3/YEkuOse9V muamaIR0FI3XHWB+ruaH+bP4ji/e4G4M15o8aCOFDCeJqQ0Txj+7Yg8a2TIhSEYBJC3e fnoUA0z0HpOyJYYIffZ+u/OBlfUa+coh51zaQSUKu9IzODfCBoSGGaESrN9ft2MuaXdB 6YkuHSgi1CxxEYUBxvMr9OdJKeirNZafW95UVEiIdGqBqzFOH+YFJ2LzDrYCsf1hSsKs v5QA== 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=zovre+NnhUMGhOe7jQl9tW++eT//p/nK1ciGC0rd9Tk=; fh=V2IY9JiXP/LhUMpX66+Nr0N3VSfqLapXj8NIppeg0Gk=; b=Ax0oTzXs41zkzwQ0PKyg2kfrq5n3q4z2mbpTl4w0MKrKrqM2n0oyxd+DxJMHTAgoIK roczFo4Peepq8XhpGYJSLcC2uZFYd6SyofAYCNlFWZ51b41a/uQXeuKNBigNHpnY4/q3 chnU0zDNKs3p5txsSI8tYtG1GPXYwWtgONYlthgT4rw628pvCSEtO6UG+RhTqlEzrFqb u7ylKe9U+gOrlYeK3U4V6nkGl5h4/DRkzxQiVpS8sXPxe4lJBCSuaZi4mkGa+vdJONYL YKwY8Ml6vaeU0Zp8GRtQU3fzDwSEyZMTzgPo2zNuciM7KVxw35ebpYQnCEuGg7XLBQs0 58Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mev.co.uk header.s=20221208-6x11dpa4 header.b=lOBme9cQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id a185-20020a6390c2000000b0056da0ae25a0si279468pge.441.2023.09.13.17.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 17:27:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@mev.co.uk header.s=20221208-6x11dpa4 header.b=lOBme9cQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 2506E8455593; Wed, 13 Sep 2023 10:08:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231686AbjIMRIJ (ORCPT + 99 others); Wed, 13 Sep 2023 13:08:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231202AbjIMRHt (ORCPT ); Wed, 13 Sep 2023 13:07:49 -0400 Received: from smtp112.iad3a.emailsrvr.com (smtp112.iad3a.emailsrvr.com [173.203.187.112]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDABF1FD4 for ; Wed, 13 Sep 2023 10:07:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mev.co.uk; s=20221208-6x11dpa4; t=1694624856; bh=LVG4pa4at5j33GVC1eLu+Pgx6Tm/UOqR60TbS2+ntqk=; h=From:To:Subject:Date:From; b=lOBme9cQepKZx5EK+P5udqI7NWj0IAWTfbVQAXdrL8Fp+qKHdd2GeMj5/OzkgGHuL jRZJ2NvkGfdjsKjbB2k4HY2rjyWsl7vEA+qnlf0Tjf1nOGCTtFxYqW95STaHgXKax0 XTYZjPLo+XBNeDE1quFQh1195vhg47Yoois/90Dw= X-Auth-ID: abbotti@mev.co.uk Received: by smtp39.relay.iad3a.emailsrvr.com (Authenticated sender: abbotti-AT-mev.co.uk) with ESMTPSA id D746E4277; Wed, 13 Sep 2023 13:07:35 -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 v3 11/13] comedi: amplc_dio200_common: Refactor register access functions Date: Wed, 13 Sep 2023 18:07:10 +0100 Message-Id: <20230913170712.111719-12-abbotti@mev.co.uk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230913170712.111719-1-abbotti@mev.co.uk> References: <20230913164013.107520-1-abbotti@mev.co.uk> <20230913170712.111719-1-abbotti@mev.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Classification-ID: 19793052-af61-4898-a406-82596fa230be-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 (howler.vger.email [0.0.0.0]); Wed, 13 Sep 2023 10:08:13 -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_IOPORT` changes. Cc: Arnd Bergmann Cc: Niklas Schnelle Signed-off-by: Ian Abbott --- v2: Correct `HAS_PORTIO` to `HAS_IOPORT` in commit description. v3: N/A. --- 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