Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp123940lqh; Mon, 6 May 2024 13:25:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXIpa1iGavW5hCk83O/x63bTi1AAYBPH6+wxKAdwfFx3fh2NhkUNZOp3PkfGSVDhiz82ZvKxJV7vGdAIZy0lFqb5+CQiWjYeb8FJba/cA== X-Google-Smtp-Source: AGHT+IEJXehZzRldQmWOfblAKpqJ5bF3Ls3mn/X6vIji69TwEdLesR5JkxpiwABe7WoVYd0aVTg8 X-Received: by 2002:ae9:e604:0:b0:790:9f13:2ed0 with SMTP id z4-20020ae9e604000000b007909f132ed0mr1383289qkf.22.1715027114387; Mon, 06 May 2024 13:25:14 -0700 (PDT) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u21-20020a05620a023500b0079294b11666si3814015qkm.367.2024.05.06.13.25.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 13:25:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170388-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-170388-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170388-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 227A01C216CD for ; Mon, 6 May 2024 20:25:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 610DC15B111; Mon, 6 May 2024 20:25:06 +0000 (UTC) Received: from fgw21-7.mail.saunalahti.fi (fgw21-7.mail.saunalahti.fi [62.142.5.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52A5715697B for ; Mon, 6 May 2024 20:25:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.142.5.82 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715027105; cv=none; b=l1oOjVtXZMVkqjCsqoU74DUxd4QrsEQ3q4Jk/GLpri8bV8NPGg47vl/cdMeVWDnVVYrzFYLuB+lPxpB/V7u1JsETKnQGoOf0ufR3FGw/PRdXz68lukgk3oi08H15rhSktd2XD/1jGrkHMimuVn+tK8IQJKrO6Ghs2NhQVggnw4I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715027105; c=relaxed/simple; bh=OzxiMiUHBbbpYgDGpErM2Rdbdry7RtUB3JL+n/5EiFw=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=F1K34T5WHekD2osd1yz6ryOE8SbO/gKTO+r4wCHkTOtCOBxlVb0i1CM+7JxFIWpCoz/SURE/MAd6mLSxTEyBjLnwPhpi+JUpWs35VRfpQBJz1h60CSmCBPo7rTj8Mnrr56Z3NFmvS9uQeK2BHowjABxktCCA+rdk/XG1hBM5y3g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=fail smtp.mailfrom=gmail.com; arc=none smtp.client-ip=62.142.5.82 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=gmail.com Received: from localhost (88-113-25-208.elisa-laajakaista.fi [88.113.25.208]) by fgw20.mail.saunalahti.fi (Halon) with ESMTP id b7117dea-0be6-11ef-b3cf-005056bd6ce9; Mon, 06 May 2024 23:25:01 +0300 (EEST) From: Andy Shevchenko Date: Mon, 6 May 2024 23:25:01 +0300 To: Alex Soo Cc: Linus Walleij , Bartosz Golaszewski , Hal Feng , Ley Foon Tan , Jianlong Huang , Emil Renner Berthing , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Drew Fustini , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-riscv@lists.infradead.org, Paul Walmsley , Palmer Dabbelt , Albert Ou Subject: Re: [RFC PATCH v3 6/7] gpiolib: enable GPIO interrupt to wake up a system from sleep Message-ID: References: <20240503111436.113089-1-yuklin.soo@starfivetech.com> <20240503111436.113089-7-yuklin.soo@starfivetech.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240503111436.113089-7-yuklin.soo@starfivetech.com> Fri, May 03, 2024 at 07:14:35PM +0800, Alex Soo kirjoitti: > Add function gpiochip_wakeup_irq_setup() to configure and enable a > GPIO pin with interrupt wakeup capability according to user-defined > wakeup-gpios property in the device tree. Interrupt generated by > toggling the logic level (rising/falling edge) on the specified > GPIO pin can wake up a system from sleep mode. .. > +static irqreturn_t gpio_wake_irq_handler(int irq, void *data) > +{ > + struct irq_data *irq_data = data; > + > + if (!irq_data || irq != irq_data->irq) Hmm... When irq_data can be NULL? > + return IRQ_NONE; > + > + return IRQ_HANDLED; > +} .. > +static int gpiochip_wakeup_irq_setup(struct gpio_chip *gc) > +{ > + struct device *dev = gc->parent; > + struct gpio_irq_chip *girq = &gc->irq; > + struct gpio_desc *wakeup_gpiod; > + struct irq_desc *wakeup_irqd; > + struct irq_domain *irq_domain; > + struct irq_data *irq_data; > + unsigned int offset; > + int wakeup_irq; > + int ret; > + > + if (!(device_property_read_bool(dev, "wakeup-source"))) Too many parentheses. > + return 0; > + > + irq_domain = girq->domain; > + Unneeded blank line. Ditto for all similar cases. > + if (!irq_domain) { > + dev_err(dev, "Couldn't allocate IRQ domain\n"); > + return -ENXIO; return dev_err_probe(...); Ditto for all similar cases. > + } .. > + wakeup_gpiod = devm_gpiod_get_optional(dev, "wakeup", GPIOD_IN); > + > + if (IS_ERR(wakeup_gpiod)) { > + dev_err(dev, "invalid wakeup gpio: %lu\n", PTR_ERR(wakeup_gpiod)); > + return PTR_ERR(wakeup_gpiod); > + } > + if (!wakeup_gpiod) { > + dev_dbg(dev, "property wakeup-gpios is not defined\n"); > + return 0; > + } > + > + offset = gpio_chip_hwgpio(wakeup_gpiod); > + wakeup_irq = gpiod_to_irq(wakeup_gpiod); > + if (wakeup_irq < 0) { > + dev_err(dev, "failed to convert wakeup GPIO to IRQ\n"); > + return wakeup_irq; > + } > + irq_domain->ops->map(irq_domain, wakeup_irq, offset); > + wakeup_irqd = irq_to_desc(wakeup_irq); > + irq_data = irq_get_irq_data(wakeup_irq); What these lines are for? > + girq->handler = handle_edge_irq; > + > + if (!(wakeup_irqd->status_use_accessors & IRQ_NOREQUEST)) { > + device_init_wakeup(dev, 1); > + ret = devm_request_threaded_irq(dev, wakeup_irq, NULL, > + gpio_wake_irq_handler, > + IRQF_TRIGGER_FALLING | > + IRQF_TRIGGER_RISING | What's wrong with the flags from DT? > + IRQF_ONESHOT | > + IRQF_SHARED, > + "pm-wakeup-gpio", irq_data); > + if (ret) { > + dev_err(dev, "unable to request wakeup IRQ: %d\n", ret); > + return ret; > + } > + } -- With Best Regards, Andy Shevchenko