From patchwork Wed Sep 13 11:20:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Abbott X-Patchwork-Id: 140153 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp827403vqi; Thu, 14 Sep 2023 22:49:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgbdCVgMXjTZhfUlQ7FiH8G/ubeSrsUbC/xTKFGp9J59axcyVrTvq7EgSBEejCfrpHZGWP X-Received: by 2002:a05:6a00:851:b0:690:42d5:4332 with SMTP id q17-20020a056a00085100b0069042d54332mr820243pfk.6.1694756942955; Thu, 14 Sep 2023 22:49:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694756942; cv=none; d=google.com; s=arc-20160816; b=yl0MGQziqIVwLaO9t6EJKsAZ/ZkGfMIBmr6t0C4HteJGqgHxs0hG3Zi77scJ98QNO4 8Lakmh1Vq3CAVfOhiboIVyK9zmsZw1zcA6X5ePB6Ci3Q47yZwGcyckKjy2EuHeJr33ND 6+vYEvvgzp4DKFVv69Kwl/pcX8CWHNf5+obTbx7ee/s67OrG0Msp+IrfTJFmWzzqvPPz NZ2Fx0SuAM9/zdgCX4g/OGGY634XATplQ907hI2ylAuBDvFNXsSwrrxFqCPdJrIN1QF5 Gco3S/ho7zIS03mVgJ95UbHWOzwZVu34vUiX3QSMWcAuFsFOG5Oc3imfaI8Ylhlm2sjR iSBQ== 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=JGadvbd7WW7v8H9e4fqyI41HdpAmopH30WkSwOV87H8=; fh=kwtD2hwqQlovK7ZFEo+a1+lZVyuMpHjK7AWAyN3Ssmk=; b=M/k+fcbQhmhhIpz2+MtDW/PKs3HPN4rkAG0hJy+rcNlwKZMzedWUUbVLvNRMohjc19 gmbPCnJ32VGHj7hNoWiAtHQPyecw6xN8bleyFf4ZNkx2FBNpObBzSlAOGnRSuBVO4H7k 114UnJcJ2T17F7XvVti8R4cRFIUfITU6AdpevsHboVMAjr2QSphwhpNSpKILrwJ7fp3K PxHPglPLfni5mXmQYH3UIIdC4xWlDFmWkzV01BqHISx9mwI2PIsdgZyraqr7qV+pmegK Ur56jxJZfhUTc2qumBP8NGXtVWJ/dWVdtkqpdb1AUsZdcgvuDJwAgrndufn/Es9/38Ji m8ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mev.co.uk header.s=20221208-6x11dpa4 header.b=sEl2+aLn; 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id n25-20020a637219000000b0056c297d163asi2637235pgc.523.2023.09.14.22.49.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 22:49:02 -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=sEl2+aLn; 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 B0121820DA39; Wed, 13 Sep 2023 04:21:41 -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 S240187AbjIMLVl (ORCPT + 36 others); Wed, 13 Sep 2023 07:21:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240143AbjIMLVM (ORCPT ); Wed, 13 Sep 2023 07:21:12 -0400 Received: from smtp107.iad3b.emailsrvr.com (smtp107.iad3b.emailsrvr.com [146.20.161.107]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B7B11FFA for ; Wed, 13 Sep 2023 04:21:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mev.co.uk; s=20221208-6x11dpa4; t=1694604062; bh=jTD6S3A1Mblo08Ha6IHdDgLu3daAAvWNJ47NXzRPFbY=; h=From:To:Subject:Date:From; b=sEl2+aLn6Xc+W4/UAwUrBIoz//hn8cHie7Qub//h7gjId6fdYpfNlagJZ4SesJNeF 9lbYpxZpqanQlpGByKy5shOy4/weL4SmCLB1l+rsWikzy5uND+nG46eQx3vJVqZxBs d+GPqpS6WhTi6aVH/APWsO+ehRsGsTSgjCH7RRwE= X-Auth-ID: abbotti@mev.co.uk Received: by smtp6.relay.iad3b.emailsrvr.com (Authenticated sender: abbotti-AT-mev.co.uk) with ESMTPSA id E0A94200C1; Wed, 13 Sep 2023 07:21:01 -0400 (EDT) From: Ian Abbott To: linux-kernel@vger.kernel.org Cc: Arnd Bergmann , Niklas Schnelle , Ian Abbott Subject: [PATCH 12/13] comedi: amplc_dio200_common: Conditionally remove I/O port support Date: Wed, 13 Sep 2023 12:20:31 +0100 Message-Id: <20230913112032.90618-13-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 X-Classification-ID: e346d63c-f057-4595-b974-8be9cf32e1c1-13-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:21:41 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777081456446601140 X-GMAIL-MSGID: 1777081456446601140 In a future patch, the port I/O functions (`inb()`, `outb()`, and friends will only be declared in the `HAS_IOPORT` configuration option is enabled. The amplc_dio200_common module is used by the amplc_dio200 module (for ISA cards) and the amplc_dio200_pci module (for PCI and PCI Express cards). It supports both port I/O and memory-mapped I/O. Port I/O and memory-mapped I/O is confined to the `dio200___read8()`, `dio200___read32()`, `dio200___write8()` and `dio200___write32()` functions. Conditionally compile two versions of those functions. If the `CONFIG_HAS_PORTIO` macro is defined, call either the port I/O or memory mapped I/O functions depending on the `mmio` member of the `struct comedi_device`. If the `CONFIG_HAS_PORTIO` macro is undefined only call the memory-mapped I/O functions. Add a run-time check to `amplc_dio200_common_attach()` to return an error if the device wants to use port I/O when the `CONFIG_HAS_PORTIO` macro is undefined. The changes allow the module to be built even if the port I/O functions have not been declared. Cc: Arnd Bergmann Cc: Niklas Schnelle Signed-off-by: Ian Abbott --- drivers/comedi/drivers/amplc_dio200_common.c | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/comedi/drivers/amplc_dio200_common.c b/drivers/comedi/drivers/amplc_dio200_common.c index e6d63e89e7bf..b1a9b4c4a185 100644 --- a/drivers/comedi/drivers/amplc_dio200_common.c +++ b/drivers/comedi/drivers/amplc_dio200_common.c @@ -86,6 +86,8 @@ struct dio200_subdev_intr { unsigned int active:1; }; +#ifdef CONFIG_HAS_IOPORT + static unsigned char dio200___read8(struct comedi_device *dev, unsigned int offset) { @@ -120,6 +122,34 @@ static void dio200___write32(struct comedi_device *dev, outl(val, dev->iobase + offset); } +#else /* CONFIG_HAS_IOPORT */ + +static unsigned char dio200___read8(struct comedi_device *dev, + unsigned int offset) +{ + return readb(dev->mmio + offset); +} + +static void dio200___write8(struct comedi_device *dev, + unsigned int offset, unsigned char val) +{ + writeb(val, dev->mmio + offset); +} + +static unsigned int dio200___read32(struct comedi_device *dev, + unsigned int offset) +{ + return readl(dev->mmio + offset); +} + +static void dio200___write32(struct comedi_device *dev, + unsigned int offset, unsigned int val) +{ + writel(val, dev->mmio + offset); +} + +#endif /* CONFIG_HAS_IOPORT */ + static unsigned char dio200_read8(struct comedi_device *dev, unsigned int offset) { @@ -803,6 +833,12 @@ int amplc_dio200_common_attach(struct comedi_device *dev, unsigned int irq, unsigned int n; int ret; + if (!IS_ENABLED(CONFIG_HAS_IOPORT) && !dev->mmio) { + dev_err(dev->class_dev, + "error! need I/O port support\n"); + return -ENXIO; + } + ret = comedi_alloc_subdevices(dev, board->n_subdevs); if (ret) return ret;