From patchwork Wed Sep 13 11:32:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Abbott X-Patchwork-Id: 138907 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp1177830vqx; Wed, 13 Sep 2023 08:47:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHIIQlJqbuklo/Ag3nxsxi6EsVacT/ukWL219b0YMjyblFqtiT6a5hilmtKE4T663shKUQG X-Received: by 2002:a05:6a00:2e87:b0:68f:f38d:f758 with SMTP id fd7-20020a056a002e8700b0068ff38df758mr2937568pfb.34.1694620045261; Wed, 13 Sep 2023 08:47:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694620045; cv=none; d=google.com; s=arc-20160816; b=MfKuUmmRUHkbiXrUq1oj67hxc9/iUF1at/IZJadLozEQ6Onag8L9fjnTdXSpiG506t Q/QiqztAbk3DSFc/aJikFvcUltPT4G7pUnuSRshexUTpg1hdw+wgpQwXORUMrSjBPRmT AGLqEjQwSYYGXR7RUaUUZ2z+rGFKag46YzFWK36kxrrQ+GXCvyegPV6Uka2/x0bOumV5 TGa/AR4cqVs6+3tV79xInoGJuADuPGpmCAH5WjXCILRX9uAsM8bwvRzsq2zMS8fve1oJ mRoXGVhzuGZ9qWj8ApCe2wkvX3h9/gVdBa0j+L479JAjZSOIVJ/fmuS0FU9JmM+J+dDq A/nw== 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=V2IY9JiXP/LhUMpX66+Nr0N3VSfqLapXj8NIppeg0Gk=; b=UYmzbQOlKXr/1M7ze30bWec2+ER7Tu5AoyT1tpee72uX0fw9vjCvuvWowyY45ZA5lT +FAe7MXlWNpIYmOtT18H4Lp03NWQgqOi7JJixNp07ulqZqOD7R4OgXKQSM34XnAHgZYJ MDW9cJiFhq0wFXwFeMSDfjOQeHwwUKPWiAo1VWL3IiZLLr1donwcTlja4hWfXyCNASq6 8uQIyv3YyAqynQE7GIPhAVPCDyG28R8LEt5yMNh6iXwbGXdFegrhbtjjqmCuoN37vszf Vw3uhUOJ4AAKN5P+mqprZ6qSzlW8pcfOGWXF4iPRT2o7kqBWBR6rw1eoqCEdycz+HoAR 3ZQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mev.co.uk header.s=20221208-6x11dpa4 header.b=uWRCzmyV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id cl6-20020a056a0032c600b0068fe23ffe60si3927418pfb.250.2023.09.13.08.47.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 08:47:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@mev.co.uk header.s=20221208-6x11dpa4 header.b=uWRCzmyV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 7443A806E1C4; Wed, 13 Sep 2023 04:35:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240588AbjIMLdx (ORCPT + 36 others); Wed, 13 Sep 2023 07:33:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240494AbjIMLde (ORCPT ); Wed, 13 Sep 2023 07:33:34 -0400 Received: from smtp72.iad3a.emailsrvr.com (smtp72.iad3a.emailsrvr.com [173.203.187.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E01C1FE9 for ; Wed, 13 Sep 2023 04:33:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mev.co.uk; s=20221208-6x11dpa4; t=1694604803; bh=jTD6S3A1Mblo08Ha6IHdDgLu3daAAvWNJ47NXzRPFbY=; h=From:To:Subject:Date:From; b=uWRCzmyVb+JF2ogY8fIBQ1guWcCnRVFnMS+P4+DWN8XEYPm+SjoHSaSYPEyebY0cE 0RvKwX01XphmY+hu1oEOhRJnLbXkuQi7u+aRMSd6zQu5euizrd0PvmjQQGOam98Qn0 i7iOYLCbIhVYFAzZ2eKT/XF3PcGnQlDRnEo2Id70= X-Auth-ID: abbotti@mev.co.uk Received: by smtp26.relay.iad3a.emailsrvr.com (Authenticated sender: abbotti-AT-mev.co.uk) with ESMTPSA id 0238E424B; Wed, 13 Sep 2023 07:33:21 -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 12/13] comedi: amplc_dio200_common: Conditionally remove I/O port support Date: Wed, 13 Sep 2023 12:32:46 +0100 Message-Id: <20230913113247.91749-13-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 X-Classification-ID: 007ec4bd-2574-475a-9bbd-5a4f93b29aec-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 (pete.vger.email [0.0.0.0]); Wed, 13 Sep 2023 04:35:15 -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 pete.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776937908624338410 X-GMAIL-MSGID: 1776937908624338410 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;