Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3528194rdb; Wed, 13 Sep 2023 15:10:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHcIFLbTm+RGo0WMv7P1nyT2K69sDpBjPo1GY0vpaTQ2LcKHrkKysKTjS28y9fCSn0ulNz5 X-Received: by 2002:a17:90b:17cd:b0:26d:fcd:89b3 with SMTP id me13-20020a17090b17cd00b0026d0fcd89b3mr3710608pjb.8.1694643029292; Wed, 13 Sep 2023 15:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694643029; cv=none; d=google.com; s=arc-20160816; b=aBDPZrORnhYdFtxH3p9b8VjXC7sskRMf14Ub8iU/eeDLIpVQWkoQSmFYAsQ5/NCBUn 7IYnSHN51cA1zPX4sZrsaOBoTxEleHqFmjPHK4SwUaUh8cVj6xWog5A7tBNFbdjOQVzp tbLFB5sSOHlc8uMy0pFhWx4l4Tqx4gKv0GvQ5P0Ll1Ohqc8O7HEBIEYZnPudt7fYozcm Y8x9zgAdUkEVklSKYEuo3Su6shROR4bsaFOdwmY39vAUsFHNFhERss8boeXOrqY517ua ZB+5TcQC0IUXnU6+JEuBmi/KpobBh8+cG7epCkEhk3RDTOxzS58qviNrNRGCSqomFe4z mtLQ== 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=CuGfx9BoJ9bkYneGs2cyR7n4LT/CqFeUpDCQ0KYJW8M=; fh=V2IY9JiXP/LhUMpX66+Nr0N3VSfqLapXj8NIppeg0Gk=; b=SgziRZXSCNXVXrhOX2NSRI21o0onhPfftKduNMXso2DU/Y1iJUC6ju4X4Xlp6b7fMU U4Ct2yetZ9+PI2u/AAbatXXl4Lp+m+N/5RS/A9AAOhO6Qu9jvnHPrChTTbuF6Eh4SPsQ cYvuiPQO40+eDIhRDmMnBumwGmQNDdoSZZkpHMB4e1VQD/op5ERyIs3WPuKn0QKERqEV +uKyd9jumk5x7IvWdCPiqTlKbMGmlt1T1l0/WsmacoC+gaF183Alx09jd6d6tczZM5yp COz/XhpIoNE1SXwrHT6qFezY3RC8iR2z5E0M2VSXb2gl+y/nEFofLj7XMsbbuFF8PmFK axiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mev.co.uk header.s=20221208-6x11dpa4 header.b=qAVcf1Dc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id y6-20020a17090a86c600b00263419c5c00si231221pjv.50.2023.09.13.15.10.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 15:10:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@mev.co.uk header.s=20221208-6x11dpa4 header.b=qAVcf1Dc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 484DB8025049; Wed, 13 Sep 2023 09:44:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231604AbjIMQnn (ORCPT + 99 others); Wed, 13 Sep 2023 12:43:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231598AbjIMQnS (ORCPT ); Wed, 13 Sep 2023 12:43:18 -0400 Received: from smtp65.iad3a.emailsrvr.com (smtp65.iad3a.emailsrvr.com [173.203.187.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BC7A4227 for ; Wed, 13 Sep 2023 09:40:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mev.co.uk; s=20221208-6x11dpa4; t=1694623242; bh=Gqt0xUEjwvsOjmZu6WszvumHXpWvipdZWDL6ltORHoQ=; h=From:To:Subject:Date:From; b=qAVcf1DckYYJOLI5uqe3x8sEsRd2q6K9E7QazxFLM8YXAGfcH0ukD38Aj6gLLdeqJ q+K4y73WGFXHXJ7ZL6duQzgjRIlKA4r7VLdW70/draL4XsCk1PMLQPWKjr0U+H9Hhn 5yUKQiYIyVs97lWPwdwTOuIBbZjwj3JP51HZNGQA= X-Auth-ID: abbotti@mev.co.uk Received: by smtp25.relay.iad3a.emailsrvr.com (Authenticated sender: abbotti-AT-mev.co.uk) with ESMTPSA id 57C3E239A1; Wed, 13 Sep 2023 12:40:41 -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 v2 11/13] comedi: amplc_dio200_common: Refactor register access functions Date: Wed, 13 Sep 2023 17:40:11 +0100 Message-Id: <20230913164013.107520-12-abbotti@mev.co.uk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230913164013.107520-1-abbotti@mev.co.uk> References: <20230913164013.107520-1-abbotti@mev.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Classification-ID: bb5231ff-a70f-4c9d-8b55-93f03f91465d-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 (morse.vger.email [0.0.0.0]); Wed, 13 Sep 2023 09:44:29 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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. --- 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