From patchwork Tue Jan 2 21:07:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Hasemeyer X-Patchwork-Id: 184465 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4686551dyb; Tue, 2 Jan 2024 13:14:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IGanSmJLNNkgi5hZ90/s/VbIOEhCvvbrCQ9UW7zeUaWcBv0460xi7vESlxlEUen4VXc1NGF X-Received: by 2002:a05:622a:1489:b0:428:a6b:128f with SMTP id t9-20020a05622a148900b004280a6b128fmr10752101qtx.18.1704230066268; Tue, 02 Jan 2024 13:14:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704230066; cv=none; d=google.com; s=arc-20160816; b=UBq1Y+v5PkaT1yOPZZPpswhOWH8B2YhdNEU80oMJDomJh8iU+THI+2GAyEdSHxiRH4 ja88E+yeChSu1l2ZUOWy163Wr0ytxJooQcX4GL3Th40rpezBWnksSHpuK3g4+12HfSU/ dPOaVY5iHdlxz6h3e5d++HR6iA5k6t899z6NWsJIWjPSqz5lmqu0PfvpOEofI+JNlRsS X1J3MfiGEypOThVsP1O1rR+J+rQ9FqQCl7w71Hh8rwCMIhQ4Do4DuYTASpPCdIgnsGkz 4U4jHLY4nwV5KEJ5xXEFV2lFRrVuE54sKiGBBY9VosPuCirZE7uSZbsyDF3BVEHSE9Eq jQhQ== 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=ukfFPOjxIuuxKMITUORsVWUdW86ng+CgXwCq16suFWg=; fh=GIXp3Un6gCk2tdqRQywS+QjQ3DWCya/DIYXQDtsL7bI=; b=Wr82aCKgyXU6D3cfKROsw+dg0N99LdDRdqzDWOZ1/+HzCE7gj/kl/HrWjNeHpvAy1J 1OylVuIMvSkWQrCFHuVUGfpRetMfZ8YRQmC82x4aweyV5GIgldkDXBL2+bo9N4TYt+1V aD0ty5Uy6DtDoctgIgp8jXQfBp5CE6avOE3YXMMh/+E7CXWQtocuKkt34rndK11XVrGe fA/c1P2nso478SusTwqFD5B6kOwHC9ffnJPJn9Rds60TBBpdt3ek3iZtPdM33u1g6CT8 qCA5DxR6bM48xZoxcA6os8wcfaY1fhdCVQ3Ak47k6yY3cQDImYaD3/zUyLC0eW7QaAKw feYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BuKTDh26; spf=pass (google.com: domain of linux-kernel+bounces-14842-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14842-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id o7-20020a05622a044700b0042783779803si28485227qtx.441.2024.01.02.13.14.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 13:14:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14842-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BuKTDh26; spf=pass (google.com: domain of linux-kernel+bounces-14842-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14842-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 06A641C22B3C for ; Tue, 2 Jan 2024 21:14:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB00D199D5; Tue, 2 Jan 2024 21:09:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="BuKTDh26" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) (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 CCAE018EB4 for ; Tue, 2 Jan 2024 21:09:00 +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-f43.google.com with SMTP id ca18e2360f4ac-7bade847536so342478539f.0 for ; Tue, 02 Jan 2024 13:09:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1704229740; x=1704834540; 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=ukfFPOjxIuuxKMITUORsVWUdW86ng+CgXwCq16suFWg=; b=BuKTDh26A6XoTsL9jU4OHGP74zfboMwfa682+h1xxyYoT9Wy7X034wmDLOa2XtgGHj JNnJTueHayzv1E/RFzT1boN8Y1067xCddRoyDnwSi86lGooWovPJ5qzmDFOKvWp7DZNC KTbZD5Zoa8/3Fc58AX59iHYNm4dEDn288uGp0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704229740; x=1704834540; 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=ukfFPOjxIuuxKMITUORsVWUdW86ng+CgXwCq16suFWg=; b=K52+dZkqcwUdL33k4c+ykNU8wUHeT5xaWGV5wZr90RMEwtUK5C+lS6ddG2qBcTVoLc JnLbkKCGkC4HMDLXSoBpTdF4EzRAxf3hYnQp5njVc0qO/4q4Co+NbrHaW6HKJEotwQb3 Lf/E32cMk6D29mRWojNQhYZ0lytJ3aERZS3HM3sTTyxtfQ4ED+eyOVSLlumvPXoVGLrt Aa5ZFXB5qZKJ+4gtvm65AUFm06ZIoFJ49ZbO1viq/gWHS5tjc+tX/SkZmKowBjaXa2o3 tML1v8HexstfoMTPIb5EFERjFoGljyudhNmLzxBFd8UwTWVr3hdMBtMLiWmCUgA1Fnsk 8j6Q== X-Gm-Message-State: AOJu0YyrsPQfNixsVE/3fKMIV3UOHfGgo038iL7ASkudUQW6aSh4A1sQ 1zEQ88GMgKCNa9y3fe/ZzINBgUIbMYtK+KQVj/cM4ZK8A1+O X-Received: by 2002:a5d:9a17:0:b0:7bb:41bd:715f with SMTP id s23-20020a5d9a17000000b007bb41bd715fmr12202311iol.39.1704229739844; Tue, 02 Jan 2024 13:08:59 -0800 (PST) Received: from markhas1.lan (71-218-50-136.hlrn.qwest.net. [71.218.50.136]) by smtp.gmail.com with ESMTPSA id bo18-20020a056638439200b0046993034c91sm6956978jab.77.2024.01.02.13.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 13:08:59 -0800 (PST) From: Mark Hasemeyer To: LKML Cc: Sudeep Holla , AngeloGioacchino Del Regno , Rob Herring , Andy Shevchenko , Krzysztof Kozlowski , Konrad Dybcio , Raul Rangel , Tzung-Bi Shih , Mark Hasemeyer , Frank Rowand , Rob Herring , devicetree@vger.kernel.org Subject: [PATCH v4 18/24] of: irq: add wake capable bit to of_irq_resource() Date: Tue, 2 Jan 2024 14:07:42 -0700 Message-ID: <20240102140734.v4.18.I29b26a7f3b80fac0a618707446a10b6cc974fdaf@changeid> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog In-Reply-To: <20240102210820.2604667-1-markhas@chromium.org> References: <20240102210820.2604667-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: 1787014745978577063 X-GMAIL-MSGID: 1787014745978577063 Add wake capability information to the IRQ resource. Wake capability is assumed based on conventions provided in the devicetree wakeup-source binding documentation. An interrupt is considered wake capable if the following are true: 1. A wakeup-source property exits in the same device node as the interrupt. 2. The IRQ is marked as dedicated by setting its interrupt-name to "wakeup". The wakeup-source documentation states that dedicated interrupts can use device specific interrupt names and device drivers are still welcome to use their own naming schemes. This API is provided as a helper if one is willing to conform to the above conventions. The ACPI subsystems already provides similar APIs that allow one to query the wake capability of an IRQ. This brings closer feature parity to the devicetree. Reviewed-by: Rob Herring Signed-off-by: Mark Hasemeyer --- Changes in v4: -Add Rob's Reviewed-by tag from v2 -Ignored Andy's Reviewed-by tag per his request: https://lore.kernel.org/all/ZYxgQn8L7ENkc0AJ@smile.fi.intel.com/ Changes in v3: -Use DEFINE_RES_IRQ_NAMED_FLAGS macro Changes in v2: -Update logic to return true only if wakeup-source property and "wakeup" interrupt-name are defined -irq->IRQ, api->API drivers/of/irq.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/drivers/of/irq.c b/drivers/of/irq.c index 174900072c18c..cdecdc3515f88 100644 --- a/drivers/of/irq.c +++ b/drivers/of/irq.c @@ -383,11 +383,39 @@ int of_irq_parse_one(struct device_node *device, int index, struct of_phandle_ar } EXPORT_SYMBOL_GPL(of_irq_parse_one); +/** + * __of_irq_wake_capable - Determine whether a given IRQ index is wake capable + * + * The IRQ is considered wake capable if the following are true: + * 1. wakeup-source property exists + * 2. provided IRQ index is labelled as a dedicated wakeirq + * + * This logic assumes the provided IRQ index is valid. + * + * @dev: pointer to device tree node + * @index: zero-based index of the IRQ + * Return: True if provided IRQ index for #dev is wake capable. False otherwise. + */ +static bool __of_irq_wake_capable(const struct device_node *dev, int index) +{ + int wakeindex; + + if (!of_property_read_bool(dev, "wakeup-source")) + return false; + + wakeindex = of_property_match_string(dev, "interrupt-names", "wakeup"); + return wakeindex >= 0 && wakeindex == index; +} + /** * of_irq_to_resource - Decode a node's IRQ and return it as a resource * @dev: pointer to device tree node - * @index: zero-based index of the irq + * @index: zero-based index of the IRQ * @r: pointer to resource structure to return result into. + * + * Return: Linux IRQ number on success, or 0 on the IRQ mapping failure, or + * -EPROBE_DEFER if the IRQ domain is not yet created, or error code in case + * of any other failure. */ int of_irq_to_resource(struct device_node *dev, int index, struct resource *r) { @@ -399,6 +427,7 @@ int of_irq_to_resource(struct device_node *dev, int index, struct resource *r) /* Only dereference the resource if both the * resource and the irq are valid. */ if (r && irq) { + u32 irq_flags; const char *name = NULL; memset(r, 0, sizeof(*r)); @@ -409,9 +438,11 @@ int of_irq_to_resource(struct device_node *dev, int index, struct resource *r) of_property_read_string_index(dev, "interrupt-names", index, &name); - r->start = r->end = irq; - r->flags = IORESOURCE_IRQ | irqd_get_trigger_type(irq_get_irq_data(irq)); - r->name = name ? name : of_node_full_name(dev); + irq_flags = irqd_get_trigger_type(irq_get_irq_data(irq)); + if (__of_irq_wake_capable(dev, index)) + irq_flags |= IORESOURCE_IRQ_WAKECAPABLE; + + *r = DEFINE_RES_IRQ_NAMED_FLAGS(irq, name ?: of_node_full_name(dev), irq_flags); } return irq;