From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fgw23-7.mail.saunalahti.fi (fgw23-7.mail.saunalahti.fi [62.142.5.84]) (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 50A5056B76 for ; Mon, 6 May 2024 20:25:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.142.5.84 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715027105; cv=none; b=PBfEU4BS1Hkj6cEBJi+dZOXJiebC5sqSNctcoQVvjKcHeu5VgJjNlDLqgJOG0eWr35SGkgLNamwzMDKTrNNhaGfUXVwAh/KYQboydj9ZrN/n3qRMGpOBGklASCh9QpAn8S7N7Pu5pWJ9iVDGmhvaInb+x1CvCXoT04E2BrVGRmI= 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.84 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: devicetree@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