Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5612693rdb; Wed, 13 Dec 2023 14:04:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IEbXXxTGuA1UrozUHBX3tdaJ9Qgdl8qwAoiIbrpdqkdAujBLcOVa75tpLPl7s6ew25/AtLb X-Received: by 2002:a17:902:8682:b0:1d0:cd9e:424b with SMTP id g2-20020a170902868200b001d0cd9e424bmr8289425plo.43.1702505095214; Wed, 13 Dec 2023 14:04:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702505095; cv=none; d=google.com; s=arc-20160816; b=nbGA4IMaguShZFHMN4IhubI+BLoQe6sNO7f4J9vHA3khOOZN8YzeoPIbmbhCZYnRLM 05knuuV0lPYxyzTRB3eK2BvOwqjSeXUlO4R7sKU+Hn9D5Dqz+dOIWU4ZUKt8UfmL5VQn jXumMLXA0fppBi3YRasBbWU6bBwNbDFKcmbds7IrcysveiFHWopCQm3dJzVuETvwW6co Kpu76UAy3jPj7hTVj0f0rVtO2iTyJGBhY10hV0eSaEhtReBCch1ofQ6OQ6oP9IYQ19ur M7+cTNiMwlos7hiRWhFC1uB/UpjI8KaqjkK87CF9c78N47c2w2GCmHi0lWbERwsiWPxy DpFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=S4OPTogfVv1ZY+r+8gNK2KKTBuXiCXIz5vFe+cYHeuU=; fh=8xtHa50zkXHxp7DpedwF8g6hulhYO6h/3RAaKW3+iV8=; b=GbzTKfqqjV0W0t7O4CHq9gZCGWjCSqHrTdzEZxNYUYn9OfbKwbk3xHJr+qw4lbX7Um JYWjfte3Fdw+7RcbsYxsykD7Wa1ll+olCU8mavNp903k6W2xuAHCmHdGLWIXvVf1x0dc 0kt/5mBVth77I5VBEO0C1C2fq1awB2a4rwuWCwQHaVfVIRczgLRPymrGYz3AP2qjNLQ2 TRY7LCb52zi7dsOX2qIsudmPS5b4MtX02SC5vjltfptMirzCNt5CuO8IphHtMeB4JdxN E8cxFMR94Pqs9VKOs6H1Kcj/jbLN8JyRlxig6yKtcd84kerrDTkX07kqpZk5T3tTLmvB gGLA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id e11-20020a170902b78b00b001d1d8f654d2si10150910pls.400.2023.12.13.14.04.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 14:04:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 081428076CB3; Wed, 13 Dec 2023 14:04:52 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229929AbjLMWEf (ORCPT + 99 others); Wed, 13 Dec 2023 17:04:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbjLMWEe (ORCPT ); Wed, 13 Dec 2023 17:04:34 -0500 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A9CDA3 for ; Wed, 13 Dec 2023 14:04:40 -0800 (PST) Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-58d1b767b2bso4780149eaf.2 for ; Wed, 13 Dec 2023 14:04:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702505079; x=1703109879; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=S4OPTogfVv1ZY+r+8gNK2KKTBuXiCXIz5vFe+cYHeuU=; b=PJNFy3YJbyvwerbUXPLauHcDwp+7kWXoONPWmqt+cjY2pL/FCjm7FvfXuUMVfwFMsY OELNgCYtdSFu9OoALQ8awCqsxs60q51qPPo8x7frN/ErtEDZoGrzOqwxlUN3XelRFlXz 9l1najAAe2y1MAR+VmGKFvCnwTuJNmCD+fyaalQoJv3vh9sRppV39YTY6Y8DbreaDTBA ecCwNS41uYA1Jl9TXSiEBSNLKkx17610bBZXmZPMQM59p+5zSYUQeFJnl2fq+XXKf696 oHT6xRpisRNeF73EtZRO7KIxeV2Vysu4I0+PaBcji8wRa1xAZ0U65+ax73/CS68V+BkM DK/g== X-Gm-Message-State: AOJu0YwcQ7vzvwSo1Dv+VAbOPlfklb8+EP5InzazOX6Ufv62BGvzJn/+ rObMw/NloucNe3Zm+fb0Og== X-Received: by 2002:a4a:6701:0:b0:58e:1c47:76c6 with SMTP id f1-20020a4a6701000000b0058e1c4776c6mr5289216ooc.18.1702505079242; Wed, 13 Dec 2023 14:04:39 -0800 (PST) Received: from herring.priv (66-90-144-107.dyn.grandenetworks.net. [66.90.144.107]) by smtp.gmail.com with ESMTPSA id az2-20020a056830458200b006d87b9d84bfsm2960478otb.12.2023.12.13.14.04.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 14:04:38 -0800 (PST) Received: (nullmailer pid 2150081 invoked by uid 1000); Wed, 13 Dec 2023 22:04:37 -0000 Date: Wed, 13 Dec 2023 16:04:37 -0600 From: Rob Herring To: Mark Hasemeyer Cc: LKML , Raul Rangel , David Gow , Greg Kroah-Hartman , Mark Brown , "Rafael J. Wysocki" , Takashi Iwai , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= Subject: Re: [PATCH v1 5/6] platform: Modify platform_get_irq_optional() to use resource Message-ID: <20231213220437.GA2115075-robh@kernel.org> References: <20231213110009.v1.1.Ifd0903f1c351e84376d71dbdadbd43931197f5ea@changeid> <20231213110009.v1.5.Ife9ebad2bbfbab3a05e90040f344d750aa0aac7e@changeid> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231213110009.v1.5.Ife9ebad2bbfbab3a05e90040f344d750aa0aac7e@changeid> X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Wed, 13 Dec 2023 14:04:52 -0800 (PST) On Wed, Dec 13, 2023 at 11:00:23AM -0700, Mark Hasemeyer wrote: > Unify handling of ACPI, GPIO, devictree, and platform resource > interrupts in platform_get_irq_optional(). Each of these subsystems > provide their own apis which provide IRQ information as a struct > resource. This simplifies the logic of the function and allows callers > to get more information about the irq by looking at the resource flags. > For example, whether or not an irq is wake capable. > > Rename the function to platform_get_irq_resource() to better describe > the function's new behavior. This is misleading as the original function is still there. The get_optional() functions are designed to not print an error message where as the non-optional variant will. You've broken that pattern here in that there is no platform_get_irq_resource_optional() (at least named that because your implementation is that since there is no error message). What about versions equivalent to platform_get_irq_byname() and platform_get_irq_byname_optional(), though I guess we need users first. > > Signed-off-by: Mark Hasemeyer > --- > > drivers/base/platform.c | 78 ++++++++++++++++++--------------- > include/linux/platform_device.h | 9 +++- > 2 files changed, 50 insertions(+), 37 deletions(-) > > diff --git a/drivers/base/platform.c b/drivers/base/platform.c > index 76bfcba250039..6b58bde776d4f 100644 > --- a/drivers/base/platform.c > +++ b/drivers/base/platform.c > @@ -151,9 +151,10 @@ EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource_byname); > #endif /* CONFIG_HAS_IOMEM */ > > /** > - * platform_get_irq_optional - get an optional IRQ for a device > + * platform_get_irq_resource - get an IRQ for a device and populate resource struct > * @dev: platform device > * @num: IRQ number index > + * @r: pointer to resource to populate with irq information. It is not modified on failure. > * > * Gets an IRQ for a platform device. Device drivers should check the return > * value for errors so as to not pass a negative integer value to the > @@ -162,59 +163,47 @@ EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource_byname); > * > * For example:: > * > - * int irq = platform_get_irq_optional(pdev, 0); > + * int irq = platform_get_irq_resource(pdev, 0, &res); > * if (irq < 0) > * return irq; > * > * Return: non-zero IRQ number on success, negative error number on failure. > */ > -int platform_get_irq_optional(struct platform_device *dev, unsigned int num) > +int platform_get_irq_resource(struct platform_device *dev, unsigned int num, struct resource *r) > { > int ret; > #ifdef CONFIG_SPARC > /* sparc does not have irqs represented as IORESOURCE_IRQ resources */ > if (!dev || num >= dev->archdata.num_irqs) > - goto out_not_found; > + return -ENXIO; > ret = dev->archdata.irqs[num]; > + if (ret >= 0) > + *r = (struct resource)DEFINE_RES_IRQ(ret); > goto out; > #else > - struct resource *r; > + struct resource *platform_res; > > if (IS_ENABLED(CONFIG_OF_IRQ) && dev->dev.of_node) { > - ret = of_irq_get(dev->dev.of_node, num); > + ret = of_irq_to_resource(dev->dev.of_node, num, r); > if (ret > 0 || ret == -EPROBE_DEFER) > goto out; > } > > - r = platform_get_resource(dev, IORESOURCE_IRQ, num); > - if (has_acpi_companion(&dev->dev)) { > - if (r && r->flags & IORESOURCE_DISABLED) { > - ret = acpi_irq_get(ACPI_HANDLE(&dev->dev), num, r); > - if (ret) > - goto out; > - } > - } > - > - /* > - * The resources may pass trigger flags to the irqs that need > - * to be set up. It so happens that the trigger flags for > - * IORESOURCE_BITS correspond 1-to-1 to the IRQF_TRIGGER* > - * settings. > - */ > - if (r && r->flags & IORESOURCE_BITS) { > - struct irq_data *irqd; > - > - irqd = irq_get_irq_data(r->start); > - if (!irqd) > - goto out_not_found; > - irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS); > - } > - > - if (r) { > + platform_res = platform_get_resource(dev, IORESOURCE_IRQ, num); > + if (platform_res && !(platform_res->flags & IORESOURCE_DISABLED)) { > + *r = *platform_res; > ret = r->start; > goto out; > } > > + if (has_acpi_companion(&dev->dev)) { > + ret = acpi_irq_get(ACPI_HANDLE(&dev->dev), num, r); > + if (!ret || ret == -EPROBE_DEFER) { > + ret = ret ?: r->start; > + goto out; > + } > + } > + > /* > * For the index 0 interrupt, allow falling back to GpioInt > * resources. While a device could have both Interrupt and GpioInt > @@ -223,21 +212,38 @@ int platform_get_irq_optional(struct platform_device *dev, unsigned int num) > * allows a common code path across either kind of resource. > */ > if (num == 0 && has_acpi_companion(&dev->dev)) { > - ret = acpi_dev_gpio_irq_get(ACPI_COMPANION(&dev->dev), num); > + ret = acpi_dev_get_gpio_irq_resource(ACPI_COMPANION(&dev->dev), NULL, > + num, r); > /* Our callers expect -ENXIO for missing IRQs. */ > - if (ret >= 0 || ret == -EPROBE_DEFER) > + if (!ret || ret == -EPROBE_DEFER) { > + ret = ret ?: r->start; > goto out; > + } > } > - > #endif > -out_not_found: > ret = -ENXIO; > out: > if (WARN(!ret, "0 is an invalid IRQ number\n")) > return -EINVAL; > + > + /* > + * The resources may pass trigger flags to the irqs that need > + * to be set up. It so happens that the trigger flags for > + * IORESOURCE_BITS correspond 1-to-1 to the IRQF_TRIGGER* > + * settings. > + */ > + if (ret > 0 && r->flags & IORESOURCE_BITS) { > + struct irq_data *irqd; > + > + irqd = irq_get_irq_data(r->start); > + if (!irqd) > + ret = -ENXIO; > + else > + irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS); We were not doing any of this in the DT or Sparc cases before. It's probably just redundant for DT. It might break Sparc. Rob