From patchwork Tue Dec 26 19:21:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Hasemeyer X-Patchwork-Id: 183358 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1057684dyb; Tue, 26 Dec 2023 11:28:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IGt2+0jc2z02QwogXP+Wmhturmaz8hyafSnX2Uwgn3aEyxgkUKJBIi3En0ygGsyevNs8jtT X-Received: by 2002:a17:906:101b:b0:a23:617d:1bbc with SMTP id 27-20020a170906101b00b00a23617d1bbcmr6761506ejm.15.1703618908606; Tue, 26 Dec 2023 11:28:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703618908; cv=none; d=google.com; s=arc-20160816; b=K9sCgJmDa1Qar3zhDEh/8aNv2ueQdwPnMwALc/DeB+/m4DC0Y2uzTuY35Tkvi6slt7 x1rBSYs8I5I4l3KrdhYiHqvI3JWT2fPpE+r4PAvhXiik6VNHZRAmyIkHqCrg/fT93QPl d7+o2WIotgB7z9J1OLQw+6km1Mn4nAkszNQCJf8Q4QQw8NLo+uhXdJfW7gpnu7rIODzN LseWN0OWNATkbJpN+Ima8/RJ5eUYo/UK0dakIFk1H6+CBwDNRv2zmr42/KCgs6iHsI8g SDzi59TwUg12eJv0Lrwnr3YV3M1C3hBalmlobvx5MaUEiQmQbw8RTS3Ysyhhcw7ZoNUt bDqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=K6tsT/7sNyFm2KzBYrGyHG8VbifTdBXO1YqorM6Zb+w=; fh=k3jBscO6F+H+gwcRTl5hehJGhl+HbFOexsbGFSZMU+w=; b=CPaBa3lJMhq1ya8M1OLMMnsfRI7mXFIwe+/Is2U8RXc1u/pHleykA48pYy0Ht8FFr0 8EsbBx7Pj4Jx7ll9djvwiCt6JENFTLSmToXCjvOT+wgFPkgmd079/n5JqMuHNEiIXiUx htL63cRlDXwIr+/kHW+0i98ZQHCzXHRktrr71u+mwyOTsL6QNtcvbpAVPBB2heEb3pSF 4HdouzCVH4xlDj2D03d5bGthhoaU3mhyY16P1qaobwZniyb0mJKmQvzkCVV9z0EWm8zY /9Bs0hidDiQTG+KQ3zh2NIOAIBUgWB5d7MzVjiCLACN62/KyC/kCgHW8+92fICg9+sca WPsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bHItEUsm; spf=pass (google.com: domain of linux-kernel+bounces-11651-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11651-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id qx26-20020a170906fcda00b00a269798110fsi5844499ejb.1006.2023.12.26.11.28.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 11:28:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11651-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bHItEUsm; spf=pass (google.com: domain of linux-kernel+bounces-11651-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11651-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 16D8B1F22961 for ; Tue, 26 Dec 2023 19:28:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F2ACB21100; Tue, 26 Dec 2023 19:22:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="bHItEUsm" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-io1-f50.google.com (mail-io1-f50.google.com [209.85.166.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E63E51C2B3 for ; Tue, 26 Dec 2023 19:22:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-io1-f50.google.com with SMTP id ca18e2360f4ac-7ba8e33dd0cso199200339f.0 for ; Tue, 26 Dec 2023 11:22:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1703618542; x=1704223342; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K6tsT/7sNyFm2KzBYrGyHG8VbifTdBXO1YqorM6Zb+w=; b=bHItEUsmLdLELfxu2a7Vav32ZUZKFGm/r2pKp6NddrvcTDMD3tUiN6xgdz9R+y0EOG 9mKwOb6vsMh/rGTBpfcAa0V1Z1YVYUvUJd8ORvZJJazCURZhu+NpdsN4IRKwXRZ/wA2h 77xCpoxKFfUUdwBxSQe4jk7WoRyn2g8hWI6Zo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703618542; x=1704223342; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K6tsT/7sNyFm2KzBYrGyHG8VbifTdBXO1YqorM6Zb+w=; b=NQSZym0Ox+lOFwcZsYEd4+Rp2ly61X0Jt73xCCu6wv9DNL5C/auAV06YVJkGz2Iumw Ydrxkas3DnpZaoyGYee+T08w7yk3FwUOItC0qqcez/61R5ZzHaIA6A6af/hbcgHT3y3O GS+T2pPyQaJu6iZ9lIF8SdInGcMm4BTV5wJBWklvB2UWkb4niiUEeVQefZsR0YBhHgES KfME+hSKl8u/yutS8rExZvbkIgdI9A9R/qdlhS+xf5ZjNUjm8QAIcLXfk3HG8KnTAa5/ fvUp876GRmqvNRZ/xZI7n7FHeAOijI4XRyCmPwfXPPKm8LIjKog8V33jEyvxTrDJWwJB kO6Q== X-Gm-Message-State: AOJu0YwaEVNLluhovCW5/bBn8REuEmBJq6KGEgWmN7IHiQIhB24CHfMS XbiDwbsZWs0NDOZXE9m26paMecvHkEURkwh3BEQ0d8nJRSx5 X-Received: by 2002:a05:6602:181a:b0:7ba:9ac4:3a49 with SMTP id t26-20020a056602181a00b007ba9ac43a49mr8155131ioh.17.1703618541957; Tue, 26 Dec 2023 11:22:21 -0800 (PST) Received: from markhas1.lan (71-218-50-136.hlrn.qwest.net. [71.218.50.136]) by smtp.gmail.com with ESMTPSA id gw3-20020a0566381ee300b0046b692e719esm3207609jab.150.2023.12.26.11.22.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 11:22:21 -0800 (PST) From: Mark Hasemeyer To: LKML Cc: AngeloGioacchino Del Regno , Krzysztof Kozlowski , Rob Herring , Konrad Dybcio , Sudeep Holla , Andy Shevchenko , Raul Rangel , Tzung-Bi Shih , Mark Hasemeyer , David Gow , Greg Kroah-Hartman , Mark Brown , "Rafael J. Wysocki" , Takashi Iwai , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Subject: [PATCH v3 23/24] platform: Modify platform_get_irq_optional() to use resource Date: Tue, 26 Dec 2023 12:21:27 -0700 Message-ID: <20231226122113.v3.23.Ife9ebad2bbfbab3a05e90040f344d750aa0aac7e@changeid> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog In-Reply-To: <20231226192149.1830592-1-markhas@chromium.org> References: <20231226192149.1830592-1-markhas@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786373900442647722 X-GMAIL-MSGID: 1786373900442647722 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. Signed-off-by: Mark Hasemeyer Reviewed-by: Andy Shevchenko --- Changes in v3: -Remove PTR_ERR check -Move platform_res assignment -Check for irq == 0 to trigger WARN msg -Refactor error handling of acpi_dev_get_gpio_irq_resource() to be consistent with fwnode_irq_get_resource() -Remove extra blank lines -Initialize struct resource on stack Changes in v2: -irq->IRQ -Remove cast to struct resource -Conform to get_optional() function naming -Revert move of irq_get_irq_data() -Add NULL check on struct resource* -Use fwnode to retrieve IRQ for DT/ACPI drivers/base/platform.c | 70 ++++++++++++++++++++++----------- include/linux/platform_device.h | 3 ++ 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 10c5779634182..bb6ece1303746 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -151,9 +151,11 @@ 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_optional - get an optional IRQ for a device and + * populate the resource struct * @dev: platform device * @num: IRQ number index + * @r: pointer to resource to populate with IRQ information. * * 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,39 +164,33 @@ EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource_byname); * * For example:: * - * int irq = platform_get_irq_optional(pdev, 0); + * int irq = platform_get_irq_resource_optional(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_optional(struct platform_device *dev, + unsigned int num, struct resource *r) { int ret; + + if (!r) + return -EINVAL; #ifdef CONFIG_SPARC /* sparc does not have irqs represented as IORESOURCE_IRQ resources */ if (!dev || num >= dev->archdata.num_irqs) goto out_not_found; ret = dev->archdata.irqs[num]; + if (ret > 0) + *r = DEFINE_RES_IRQ(ret); goto out; #else struct fwnode_handle *fwnode = dev_fwnode(&dev->dev); - struct resource *r; - - if (is_of_node(fwnode)) { - ret = of_irq_get(to_of_node(fwnode), num); - if (ret > 0 || ret == -EPROBE_DEFER) - goto out; - } - r = platform_get_resource(dev, IORESOURCE_IRQ, num); - if (is_acpi_device_node(fwnode)) { - if (r && r->flags & IORESOURCE_DISABLED) { - ret = acpi_irq_get(ACPI_HANDLE_FWNODE(fwnode), num, r); - if (ret) - goto out; - } - } + ret = fwnode_irq_get_resource(fwnode, num, r); + if (ret >= 0 || ret == -EPROBE_DEFER) + goto out; /* * The resources may pass trigger flags to the irqs that need @@ -202,7 +198,9 @@ int platform_get_irq_optional(struct platform_device *dev, unsigned int num) * IORESOURCE_BITS correspond 1-to-1 to the IRQF_TRIGGER* * settings. */ - if (r && r->flags & IORESOURCE_BITS) { + struct resource *platform_res = platform_get_resource(dev, IORESOURCE_IRQ, num); + + if (platform_res && platform_res->flags & IORESOURCE_BITS) { struct irq_data *irqd; irqd = irq_get_irq_data(r->start); @@ -211,7 +209,8 @@ int platform_get_irq_optional(struct platform_device *dev, unsigned int num) irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS); } - if (r) { + if (platform_res) { + *r = *platform_res; ret = r->start; goto out; } @@ -224,7 +223,8 @@ 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 && is_acpi_device_node(fwnode)) { - ret = acpi_dev_gpio_irq_get(to_acpi_device_node(fwnode), num); + ret = acpi_dev_get_gpio_irq_resource(to_acpi_device_node(fwnode), NULL, num, r); + ret = ret ?: r->start; /* Our callers expect -ENXIO for missing IRQs. */ if (ret >= 0 || ret == -EPROBE_DEFER) goto out; @@ -238,7 +238,7 @@ int platform_get_irq_optional(struct platform_device *dev, unsigned int num) return -EINVAL; return ret; } -EXPORT_SYMBOL_GPL(platform_get_irq_optional); +EXPORT_SYMBOL_GPL(platform_get_irq_resource_optional); /** * platform_get_irq - get an IRQ for a device @@ -270,6 +270,32 @@ int platform_get_irq(struct platform_device *dev, unsigned int num) } EXPORT_SYMBOL_GPL(platform_get_irq); +/** + * platform_get_irq_optional - get an optional IRQ for a device + * @dev: platform device + * @num: IRQ number index + * + * 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 + * request_irq() APIs. This is the same as platform_get_irq(), except that it + * does not print an error message if an IRQ can not be obtained. + * + * For example:: + * + * int irq = platform_get_irq_optional(pdev, 0); + * 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) +{ + struct resource r = {}; + + return platform_get_irq_resource_optional(dev, num, &r); +} +EXPORT_SYMBOL_GPL(platform_get_irq_optional); + /** * platform_irq_count - Count the number of IRQs a platform device uses * @dev: platform device diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index 7a41c72c19591..2117f817d9c9c 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -102,6 +102,9 @@ devm_platform_ioremap_resource_byname(struct platform_device *pdev, extern int platform_get_irq(struct platform_device *, unsigned int); extern int platform_get_irq_optional(struct platform_device *, unsigned int); +extern int platform_get_irq_resource_optional(struct platform_device *dev, + unsigned int num, + struct resource *r); extern int platform_irq_count(struct platform_device *); extern int devm_platform_get_irqs_affinity(struct platform_device *dev, struct irq_affinity *affd,