Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3463562rdb; Wed, 13 Sep 2023 12:50:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFn9aQpolVjq5tYscsqHmO2GZD5I+Nv51H2+dqLriThIs20SRLBvXL4+i7YiiNg0m0MtTqH X-Received: by 2002:a17:902:9b91:b0:1c3:bc7b:8805 with SMTP id y17-20020a1709029b9100b001c3bc7b8805mr3242827plp.52.1694634604433; Wed, 13 Sep 2023 12:50:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694634604; cv=none; d=google.com; s=arc-20160816; b=wY9yWvcrgdpUzoqa13QKIx0i9/78iuRWbdYQnKDrkNVpvR7SUsbfQmYw4U2i0z1nWZ 4CaqJoztnxOLibhG7G7y6bw+BRL3VWMu2CXB6xsYvXRTzc1LAj3gwirIy25JB5KmX0zv fJSJHZFGHQCkXZqteqRxo0+zy6MaxOf/P7XWi7WwwAkW2rMlODHSySuUFKn1rdztC8Tq iTfZAzElC1/938rYvz8O7j93qgEcZ7eWDv/hwWFHYNeK+elue/mfDizaJRLTlt49Wr7z zcsyigBmpOBwP5QaxFc4lm9RATTF2U2E8Cma6NIqHrOgf5O+4dJJvYEW8d+aJcGJB4m6 oPyw== 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=kwtD2hwqQlovK7ZFEo+a1+lZVyuMpHjK7AWAyN3Ssmk=; b=ZAzJT8xERSrWzyVAFKJHg1r2JW8yx7+HhLQrgARGemAg+1v4TCEdDagBWxZQ9ApYFd oZwfQNr2bPtusiN4aH4uS+aPtgJwOuPGyBnGr6NFZI48XgzLBgxJPISSk1AP1z80uqVo Q+rX/v0L/KLba9VZ48qdKokYPPL7iWsETWFe97F1eU+R2WoAzOb/P2mZxYLlnpDcm9Ox xosaL865FEQqCPGmMTAiPMI3NytBsyagPtP3pobw7eWbzN2CzX62PMXFuwyaARuNwJD1 o6PqjcsC2Gk7PRtNDACCOj0o4NFNr6VMUh8KkfLppieVgvmwZ3o2E6uTuUhAiIGgZIjm FrFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mev.co.uk header.s=20221208-6x11dpa4 header.b=mLVZK50m; 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 m18-20020a170902f65200b001c3411c9b83si869plg.454.2023.09.13.12.50.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 12:50:04 -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=mLVZK50m; 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 394E7842E806; Wed, 13 Sep 2023 04:21:37 -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 S240017AbjIMLVi (ORCPT + 99 others); Wed, 13 Sep 2023 07:21:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240118AbjIMLVH (ORCPT ); Wed, 13 Sep 2023 07:21:07 -0400 Received: from smtp109.iad3b.emailsrvr.com (smtp109.iad3b.emailsrvr.com [146.20.161.109]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B5492121 for ; Wed, 13 Sep 2023 04:21:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mev.co.uk; s=20221208-6x11dpa4; t=1694604061; bh=ksLlkWZwHcv286ezdkSmNkFGXAPDZINrMsbQLaeKFwg=; h=From:To:Subject:Date:From; b=mLVZK50mGvC36nVwdE8aNNtUQYlIjcpcwWR+SVuvvIkjk4BcZI7rComBUwrbarZT/ tL9DNtaKvAji/f7z/OtNEJLM2V3kBGxoXsxG1kJ7hcfNo6KBl719gCPas0DFFzaTFu 6HaqitK4YdxEu3pUz5D9ogOMmA42aJdXaKLk7Img= X-Auth-ID: abbotti@mev.co.uk Received: by smtp6.relay.iad3b.emailsrvr.com (Authenticated sender: abbotti-AT-mev.co.uk) with ESMTPSA id CC808200F9; Wed, 13 Sep 2023 07:21:00 -0400 (EDT) From: Ian Abbott To: linux-kernel@vger.kernel.org Cc: Arnd Bergmann , Niklas Schnelle , Ian Abbott Subject: [PATCH 11/13] comedi: amplc_dio200_common: Refactor register access functions Date: Wed, 13 Sep 2023 12:20:30 +0100 Message-Id: <20230913112032.90618-12-abbotti@mev.co.uk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230913112032.90618-1-abbotti@mev.co.uk> References: <20230913112032.90618-1-abbotti@mev.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Classification-ID: e346d63c-f057-4595-b974-8be9cf32e1c1-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 04:21:37 -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