Message ID | 20230215-immutable-chips-v2-3-d6b0e3f2d991@linaro.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2424404wrd; Tue, 7 Mar 2023 05:20:16 -0800 (PST) X-Google-Smtp-Source: AK7set+a/IRl7CdoC7CEi6MpSkvmYx7XKbjdCUJ8FcxQ5O5GMpLohXPHFuxmWjEQnxAeFWN/9CSM X-Received: by 2002:a17:902:ab41:b0:196:44d4:2453 with SMTP id ij1-20020a170902ab4100b0019644d42453mr11524840plb.7.1678195215819; Tue, 07 Mar 2023 05:20:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678195215; cv=none; d=google.com; s=arc-20160816; b=XqYbgVYLDUDu30FksVHf165foUfYoKyfXP9GYAN5NSLrciIVfg6N9Vem05TL6ITLMj i3IYcFuGyp1m0MpsPsZD8zMvh3G4pggJkHZ9R3SyXx0IsKyjJrKYUE05iB9+FJHDdnxR Gr9Es7gJUpcfOx08PLr7HAqVmvtARSV4thBK7tEpp4PPGlRSZsbEWJEOhCABZUMV2QMe r/sBuzSv3/+/jqlXqhW/cXAHxi0/mprumr50SvjabrVNLBMgeWTtMM3AyNA/75SwpW44 iIg/RYAw39w0BeT67RDWK0mcuhs2pXs4xFE4mtL9ljxC6I2YyDrcLwf9ba7H3The6HRx CmNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=b0p5EbpuJP6hwcjXoMYtiND4JppiiLVgXD+CFpX3rE4=; b=clH0kdye19QvYGieutgIia8mLyOKiQGZeQHTJ3c9obbX3XETlHSsHDP6Ow/vOnbaw4 pdNt9CO9NVXp+FGaOQp0pCMNOPq/hb4nwLaSb0Wq4pU7ln0epU9LR/jAgJNnuiwKUfep 5N/X5Hw2ODF2sNhu7cxdv/+wD/Ztxls2ZYGypBCo7jroOuT9okSx1bPg+NAgwj23dP/+ /2Jy9WcO84WqJKCPBjt53ejkV6gH+yK4v53qJnH3Nonh5QQn1IoIyFOZc9RKAmK0Xxjy cWHISYRRKNKY6XHvyVgXZLKPxyUq8mQSpRSYAEmcNcFnUk0tetVlzOu2ko4s5718HeEL 6B5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xFEOAYGu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kn15-20020a170903078f00b0019a96849d6dsi6032988plb.605.2023.03.07.05.20.03; Tue, 07 Mar 2023 05:20:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xFEOAYGu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230328AbjCGNFv (ORCPT <rfc822;toshivichauhan@gmail.com> + 99 others); Tue, 7 Mar 2023 08:05:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230143AbjCGNFb (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 7 Mar 2023 08:05:31 -0500 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C0E37B481 for <linux-kernel@vger.kernel.org>; Tue, 7 Mar 2023 05:05:00 -0800 (PST) Received: by mail-lf1-x12a.google.com with SMTP id r27so16941576lfe.10 for <linux-kernel@vger.kernel.org>; Tue, 07 Mar 2023 05:05:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678194288; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=b0p5EbpuJP6hwcjXoMYtiND4JppiiLVgXD+CFpX3rE4=; b=xFEOAYGuIoPsxPVhSwnYu52ahL7geiD4JVsX78tkiKB0nDxX66O85TkmquqlMnV3Cf KFT9X4bqt5tlWpqJAvS5nYwxT8BHqoEvAJLGm07IPzLBcFnoUfUsxg2mF5Bh7UxTpmcY br0YeIBO98Hp3nNOFbKpVqEqKRqnlIFsR0xn2ggRhWM1OOw0tzyYYawGXjt8jdbc8tP9 EJZOC7XmbmHahw2Q/qcEC1YKAtlX49HY9TO16gaaJt6v1uDqU55HClT+gx6G5+/3mLaQ Kb94zbPBynfFJXDzuqWS4ulOsWjA61IsdxelOB/Cc8MSGiAMkj8fP5wzey3fV3vui+RG 1pkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678194288; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b0p5EbpuJP6hwcjXoMYtiND4JppiiLVgXD+CFpX3rE4=; b=rrRi9kGUhBHOVG3MLLPJH2eNxD3Pw3EsQg6Uq13TAhGgg1tdhUYoQfiW9KXUsk4Gup doBnV8Q4wG/XFvHELnJWqkv0iizb8fyc62Rg1em9qKBmgPuoD9jJNBKgOUzydLHzIiAi /4tpxpXqfFNetwFCdmewoqP0UuXbeHujGrE70oOLs/mhrAxl2wOoKfj8qz+N98NJsqs7 HjyRppzi8pAxVlI0Wr/YqOcWE/JmE4HZkmchg9LWOv/Y8hEeoJq2dJ/WKY3xEfP8+kMN u2GBfEPNIbsgO9Bz/Ivwr9+WaD1L/C9w7kdnk0BhhmNvSbvJoSclMq4i5zECliV0oSyP Ki6g== X-Gm-Message-State: AO0yUKV1+xrN+f2YD5iC0/gVQe6uMnL3geiPJb2pZxiFIu/gHjE9bv2x Qun8NTuWdnrtyi1fHatv9FUVag== X-Received: by 2002:ac2:551d:0:b0:4dd:9a38:fcc with SMTP id j29-20020ac2551d000000b004dd9a380fccmr3973440lfk.63.1678194288471; Tue, 07 Mar 2023 05:04:48 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.219]) by smtp.gmail.com with ESMTPSA id w14-20020ac2598e000000b004caf992bba9sm2030548lfn.268.2023.03.07.05.04.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 05:04:48 -0800 (PST) From: Linus Walleij <linus.walleij@linaro.org> Date: Tue, 07 Mar 2023 14:04:45 +0100 Subject: [PATCH v2 03/16] gpio: aspeed: Convert to immutable irq_chip MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230215-immutable-chips-v2-3-d6b0e3f2d991@linaro.org> References: <20230215-immutable-chips-v2-0-d6b0e3f2d991@linaro.org> In-Reply-To: <20230215-immutable-chips-v2-0-d6b0e3f2d991@linaro.org> To: Mun Yew Tham <mun.yew.tham@intel.com>, Bartosz Golaszewski <brgl@bgdev.pl>, Joel Stanley <joel@jms.id.au>, Andrew Jeffery <andrew@aj.id.au>, Alban Bedel <albeu@free.fr>, Orson Zhai <orsonzhai@gmail.com>, Baolin Wang <baolin.wang@linux.alibaba.com>, Chunyan Zhang <zhang.lyra@gmail.com>, Jay Fang <f.fangjian@huawei.com>, Daniel Palmer <daniel@thingy.jp>, Romain Perier <romain.perier@gmail.com>, Santosh Shilimkar <ssantosh@kernel.org>, Kevin Hilman <khilman@kernel.org>, William Breathitt Gray <william.gray@linaro.org> Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-omap@vger.kernel.org, Linus Walleij <linus.walleij@linaro.org>, Marc Zyngier <maz@kernel.org> X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759715226262091140?= X-GMAIL-MSGID: =?utf-8?q?1759715226262091140?= |
Series |
Mass convert GPIO IRQ chips to be immutable
|
|
Commit Message
Linus Walleij
March 7, 2023, 1:04 p.m. UTC
Convert the driver to immutable irq-chip with a bit of intuition. Cc: Marc Zyngier <maz@kernel.org> Tested-by: Joel Stanley <joel@jms.id.au> Acked-by: Marc Zyngier <maz@kernel.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> --- drivers/gpio/gpio-aspeed.c | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-)
Comments
On Tue, 7 Mar 2023 at 13:04, Linus Walleij <linus.walleij@linaro.org> wrote: > > Convert the driver to immutable irq-chip with a bit of > intuition. > > Cc: Marc Zyngier <maz@kernel.org> > Tested-by: Joel Stanley <joel@jms.id.au> > Acked-by: Marc Zyngier <maz@kernel.org> > Signed-off-by: Linus Walleij <linus.walleij@linaro.org> > --- > drivers/gpio/gpio-aspeed.c | 44 ++++++++++++++++++++++++++++++++++++++------ > 1 file changed, 38 insertions(+), 6 deletions(-) > > diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c > index a94da80d3a95..9c4852de2733 100644 > --- a/drivers/gpio/gpio-aspeed.c > +++ b/drivers/gpio/gpio-aspeed.c > @@ -15,6 +15,7 @@ > #include <linux/module.h> > #include <linux/pinctrl/consumer.h> > #include <linux/platform_device.h> > +#include <linux/seq_file.h> > #include <linux/spinlock.h> > #include <linux/string.h> > > @@ -53,7 +54,7 @@ struct aspeed_gpio_config { > */ > struct aspeed_gpio { > struct gpio_chip chip; > - struct irq_chip irqc; > + struct device *dev; > raw_spinlock_t lock; > void __iomem *base; > int irq; > @@ -566,6 +567,10 @@ static void aspeed_gpio_irq_set_mask(struct irq_data *d, bool set) > > addr = bank_reg(gpio, bank, reg_irq_enable); > > + /* Unmasking the IRQ */ > + if (set) > + gpiochip_enable_irq(&gpio->chip, irqd_to_hwirq(d)); > + > raw_spin_lock_irqsave(&gpio->lock, flags); > copro = aspeed_gpio_copro_request(gpio, offset); > > @@ -579,6 +584,10 @@ static void aspeed_gpio_irq_set_mask(struct irq_data *d, bool set) > if (copro) > aspeed_gpio_copro_release(gpio, offset); > raw_spin_unlock_irqrestore(&gpio->lock, flags); > + > + /* Masking the IRQ */ > + if (!set) > + gpiochip_disable_irq(&gpio->chip, irqd_to_hwirq(d)); > } > > static void aspeed_gpio_irq_mask(struct irq_data *d) > @@ -1080,6 +1089,30 @@ int aspeed_gpio_copro_release_gpio(struct gpio_desc *desc) > } > EXPORT_SYMBOL_GPL(aspeed_gpio_copro_release_gpio); > > +static void aspeed_gpio_irq_print_chip(struct irq_data *d, struct seq_file *p) > +{ > + const struct aspeed_gpio_bank *bank; > + struct aspeed_gpio *gpio; > + u32 bit; > + int rc, offset; > + > + rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset); Why do we call this instead of using irq_data_get_irq_chip_data? Actually, the callback appears to do the same as the default implementation, so we could just drop it? from kernel/irq/proc.c: if (desc->irq_data.chip) { if (desc->irq_data.chip->irq_print_chip) desc->irq_data.chip->irq_print_chip(&desc->irq_data, p); else if (desc->irq_data.chip->name) seq_printf(p, " %8s", desc->irq_data.chip->name); A test on the rainier ast2600 bmc machine: # gpio-event-mon -n gpiochip0 -o 123 -r -f & # cat /proc/interrupts |grep gpio-event-mon 60: 0 0 1e780800.gpio 123 Edge gpio-event-mon > + if (rc) > + return; > + > + seq_printf(p, dev_name(gpio->dev)); > +} > + > +static const struct irq_chip aspeed_gpio_irq_chip = { > + .irq_ack = aspeed_gpio_irq_ack, > + .irq_mask = aspeed_gpio_irq_mask, > + .irq_unmask = aspeed_gpio_irq_unmask, > + .irq_set_type = aspeed_gpio_set_type, > + .irq_print_chip = aspeed_gpio_irq_print_chip, > + .flags = IRQCHIP_IMMUTABLE, > + GPIOCHIP_IRQ_RESOURCE_HELPERS, > +}; > + > /* > * Any banks not specified in a struct aspeed_bank_props array are assumed to > * have the properties: > @@ -1149,6 +1182,8 @@ static int __init aspeed_gpio_probe(struct platform_device *pdev) > if (IS_ERR(gpio->base)) > return PTR_ERR(gpio->base); > > + gpio->dev = &pdev->dev; > + > raw_spin_lock_init(&gpio->lock); > > gpio_id = of_match_node(aspeed_gpio_of_table, pdev->dev.of_node); > @@ -1208,12 +1243,9 @@ static int __init aspeed_gpio_probe(struct platform_device *pdev) > > gpio->irq = rc; > girq = &gpio->chip.irq; > - girq->chip = &gpio->irqc; > + gpio_irq_chip_set_chip(girq, &aspeed_gpio_irq_chip); > girq->chip->name = dev_name(&pdev->dev); > - girq->chip->irq_ack = aspeed_gpio_irq_ack; > - girq->chip->irq_mask = aspeed_gpio_irq_mask; > - girq->chip->irq_unmask = aspeed_gpio_irq_unmask; > - girq->chip->irq_set_type = aspeed_gpio_set_type; > + I was thinking we could make the interrupt registration unconditional, as there's always an irq in the device tree. Happy to send a follow up, or for you to fold in a change along the lines of this: --- a/drivers/gpio/gpio-aspeed.c +++ b/drivers/gpio/gpio-aspeed.c @@ -1091,14 +1091,7 @@ EXPORT_SYMBOL_GPL(aspeed_gpio_copro_release_gpio); static void aspeed_gpio_irq_print_chip(struct irq_data *d, struct seq_file *p) { - const struct aspeed_gpio_bank *bank; - struct aspeed_gpio *gpio; - u32 bit; - int rc, offset; - - rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset); - if (rc) - return; + struct aspeed_gpio *gpio = irq_data_get_irq_chip_data(d); seq_printf(p, dev_name(gpio->dev)); } @@ -1108,7 +1101,7 @@ static const struct irq_chip aspeed_gpio_irq_chip = { .irq_mask = aspeed_gpio_irq_mask, .irq_unmask = aspeed_gpio_irq_unmask, .irq_set_type = aspeed_gpio_set_type, - .irq_print_chip = aspeed_gpio_irq_print_chip, +// .irq_print_chip = aspeed_gpio_irq_print_chip, .flags = IRQCHIP_IMMUTABLE, GPIOCHIP_IRQ_RESOURCE_HELPERS, }; @@ -1170,6 +1163,7 @@ MODULE_DEVICE_TABLE(of, aspeed_gpio_of_table); static int __init aspeed_gpio_probe(struct platform_device *pdev) { const struct of_device_id *gpio_id; + struct gpio_irq_chip *girq; struct aspeed_gpio *gpio; int rc, i, banks, err; u32 ngpio; @@ -1238,27 +1232,25 @@ static int __init aspeed_gpio_probe(struct platform_device *pdev) /* Optionally set up an irqchip if there is an IRQ */ rc = platform_get_irq(pdev, 0); - if (rc > 0) { - struct gpio_irq_chip *girq; - - gpio->irq = rc; - girq = &gpio->chip.irq; - gpio_irq_chip_set_chip(girq, &aspeed_gpio_irq_chip); - girq->chip->name = dev_name(&pdev->dev); - - girq->parent_handler = aspeed_gpio_irq_handler; - girq->num_parents = 1; - girq->parents = devm_kcalloc(&pdev->dev, 1, - sizeof(*girq->parents), - GFP_KERNEL); - if (!girq->parents) - return -ENOMEM; - girq->parents[0] = gpio->irq; - girq->default_type = IRQ_TYPE_NONE; - girq->handler = handle_bad_irq; - girq->init_valid_mask = aspeed_init_irq_valid_mask; + if (rc < 0) { + return rc; } + gpio->irq = rc; + girq = &gpio->chip.irq; + gpio_irq_chip_set_chip(girq, &aspeed_gpio_irq_chip); + girq->chip->name = dev_name(&pdev->dev); + + girq->parent_handler = aspeed_gpio_irq_handler; + girq->num_parents = 1; + girq->parents = devm_kcalloc(&pdev->dev, 1, sizeof(*girq->parents), GFP_KERNEL); + if (!girq->parents) + return -ENOMEM; + girq->parents[0] = gpio->irq; + girq->default_type = IRQ_TYPE_NONE; + girq->handler = handle_bad_irq; + girq->init_valid_mask = aspeed_init_irq_valid_mask; + gpio->offset_timer = devm_kzalloc(&pdev->dev, gpio->chip.ngpio, GFP_KERNEL); if (!gpio->offset_timer) > girq->parent_handler = aspeed_gpio_irq_handler; > girq->num_parents = 1; > girq->parents = devm_kcalloc(&pdev->dev, 1, > > -- > 2.34.1 >
On Wed, Mar 8, 2023 at 2:22 AM Joel Stanley <joel@jms.id.au> wrote: > On Tue, 7 Mar 2023 at 13:04, Linus Walleij <linus.walleij@linaro.org> wrote: > > +static void aspeed_gpio_irq_print_chip(struct irq_data *d, struct seq_file *p) > > +{ > > + const struct aspeed_gpio_bank *bank; > > + struct aspeed_gpio *gpio; > > + u32 bit; > > + int rc, offset; > > + > > + rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset); > > Why do we call this instead of using irq_data_get_irq_chip_data? Because this is what the other irqchip callbacks do and I do not dare to do anything inventive or different as I can't really test the patches. > Actually, the callback appears to do the same as the default > implementation, so we could just drop it? So is chip->name always set to dev_name(dev) if we don't define it? I had no idea. I can respon with this change, the optional IRQ should be a separate patch I think? Yours, Linus Walleij
On Wed, 08 Mar 2023 01:21:50 +0000, Joel Stanley <joel@jms.id.au> wrote: > > On Tue, 7 Mar 2023 at 13:04, Linus Walleij <linus.walleij@linaro.org> wrote: > > > > Convert the driver to immutable irq-chip with a bit of > > intuition. > > > > Cc: Marc Zyngier <maz@kernel.org> > > Tested-by: Joel Stanley <joel@jms.id.au> > > Acked-by: Marc Zyngier <maz@kernel.org> > > Signed-off-by: Linus Walleij <linus.walleij@linaro.org> > > --- > > drivers/gpio/gpio-aspeed.c | 44 ++++++++++++++++++++++++++++++++++++++------ > > 1 file changed, 38 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c > > index a94da80d3a95..9c4852de2733 100644 > > --- a/drivers/gpio/gpio-aspeed.c > > +++ b/drivers/gpio/gpio-aspeed.c > > @@ -15,6 +15,7 @@ > > #include <linux/module.h> > > #include <linux/pinctrl/consumer.h> > > #include <linux/platform_device.h> > > +#include <linux/seq_file.h> > > #include <linux/spinlock.h> > > #include <linux/string.h> > > > > @@ -53,7 +54,7 @@ struct aspeed_gpio_config { > > */ > > struct aspeed_gpio { > > struct gpio_chip chip; > > - struct irq_chip irqc; > > + struct device *dev; > > raw_spinlock_t lock; > > void __iomem *base; > > int irq; > > @@ -566,6 +567,10 @@ static void aspeed_gpio_irq_set_mask(struct irq_data *d, bool set) > > > > addr = bank_reg(gpio, bank, reg_irq_enable); > > > > + /* Unmasking the IRQ */ > > + if (set) > > + gpiochip_enable_irq(&gpio->chip, irqd_to_hwirq(d)); > > + > > raw_spin_lock_irqsave(&gpio->lock, flags); > > copro = aspeed_gpio_copro_request(gpio, offset); > > > > @@ -579,6 +584,10 @@ static void aspeed_gpio_irq_set_mask(struct irq_data *d, bool set) > > if (copro) > > aspeed_gpio_copro_release(gpio, offset); > > raw_spin_unlock_irqrestore(&gpio->lock, flags); > > + > > + /* Masking the IRQ */ > > + if (!set) > > + gpiochip_disable_irq(&gpio->chip, irqd_to_hwirq(d)); > > } > > > > static void aspeed_gpio_irq_mask(struct irq_data *d) > > @@ -1080,6 +1089,30 @@ int aspeed_gpio_copro_release_gpio(struct gpio_desc *desc) > > } > > EXPORT_SYMBOL_GPL(aspeed_gpio_copro_release_gpio); > > > > +static void aspeed_gpio_irq_print_chip(struct irq_data *d, struct seq_file *p) > > +{ > > + const struct aspeed_gpio_bank *bank; > > + struct aspeed_gpio *gpio; > > + u32 bit; > > + int rc, offset; > > + > > + rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset); > > Why do we call this instead of using irq_data_get_irq_chip_data? > > Actually, the callback appears to do the same as the default > implementation, so we could just drop it? > > from kernel/irq/proc.c: > > if (desc->irq_data.chip) { > if (desc->irq_data.chip->irq_print_chip) > desc->irq_data.chip->irq_print_chip(&desc->irq_data, p); > else if (desc->irq_data.chip->name) > seq_printf(p, " %8s", desc->irq_data.chip->name); It only does the same thing *if* chip->name is set. And in this particular case it really shouldn't be set, as it isn't a constant string. > > A test on the rainier ast2600 bmc machine: > > # gpio-event-mon -n gpiochip0 -o 123 -r -f & > # cat /proc/interrupts |grep gpio-event-mon > 60: 0 0 1e780800.gpio 123 Edge gpio-event-mon > > > > > > + if (rc) > > + return; > > + > > + seq_printf(p, dev_name(gpio->dev)); > > +} > > + > > +static const struct irq_chip aspeed_gpio_irq_chip = { > > + .irq_ack = aspeed_gpio_irq_ack, > > + .irq_mask = aspeed_gpio_irq_mask, > > + .irq_unmask = aspeed_gpio_irq_unmask, > > + .irq_set_type = aspeed_gpio_set_type, > > + .irq_print_chip = aspeed_gpio_irq_print_chip, > > + .flags = IRQCHIP_IMMUTABLE, > > + GPIOCHIP_IRQ_RESOURCE_HELPERS, > > +}; > > + > > /* > > * Any banks not specified in a struct aspeed_bank_props array are assumed to > > * have the properties: > > @@ -1149,6 +1182,8 @@ static int __init aspeed_gpio_probe(struct platform_device *pdev) > > if (IS_ERR(gpio->base)) > > return PTR_ERR(gpio->base); > > > > + gpio->dev = &pdev->dev; > > + > > raw_spin_lock_init(&gpio->lock); > > > > gpio_id = of_match_node(aspeed_gpio_of_table, pdev->dev.of_node); > > @@ -1208,12 +1243,9 @@ static int __init aspeed_gpio_probe(struct platform_device *pdev) > > > > gpio->irq = rc; > > girq = &gpio->chip.irq; > > - girq->chip = &gpio->irqc; > > + gpio_irq_chip_set_chip(girq, &aspeed_gpio_irq_chip); > > girq->chip->name = dev_name(&pdev->dev); And this assignment will probably explode if, as expected, 'chip' is const and cannot be written to. I obviously didn't spot this when I first looked at these patches. M.
On Wed, Mar 8, 2023 at 2:23 PM Marc Zyngier <maz@kernel.org> wrote: > > > girq->chip->name = dev_name(&pdev->dev); > > And this assignment will probably explode if, as expected, 'chip' is > const and cannot be written to. > > I obviously didn't spot this when I first looked at these patches. Dang, I'll fix, then I will go over the rest of the patches and make sure I didn't miss any other of these name assignments. Thanks, Linus Walleij
diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c index a94da80d3a95..9c4852de2733 100644 --- a/drivers/gpio/gpio-aspeed.c +++ b/drivers/gpio/gpio-aspeed.c @@ -15,6 +15,7 @@ #include <linux/module.h> #include <linux/pinctrl/consumer.h> #include <linux/platform_device.h> +#include <linux/seq_file.h> #include <linux/spinlock.h> #include <linux/string.h> @@ -53,7 +54,7 @@ struct aspeed_gpio_config { */ struct aspeed_gpio { struct gpio_chip chip; - struct irq_chip irqc; + struct device *dev; raw_spinlock_t lock; void __iomem *base; int irq; @@ -566,6 +567,10 @@ static void aspeed_gpio_irq_set_mask(struct irq_data *d, bool set) addr = bank_reg(gpio, bank, reg_irq_enable); + /* Unmasking the IRQ */ + if (set) + gpiochip_enable_irq(&gpio->chip, irqd_to_hwirq(d)); + raw_spin_lock_irqsave(&gpio->lock, flags); copro = aspeed_gpio_copro_request(gpio, offset); @@ -579,6 +584,10 @@ static void aspeed_gpio_irq_set_mask(struct irq_data *d, bool set) if (copro) aspeed_gpio_copro_release(gpio, offset); raw_spin_unlock_irqrestore(&gpio->lock, flags); + + /* Masking the IRQ */ + if (!set) + gpiochip_disable_irq(&gpio->chip, irqd_to_hwirq(d)); } static void aspeed_gpio_irq_mask(struct irq_data *d) @@ -1080,6 +1089,30 @@ int aspeed_gpio_copro_release_gpio(struct gpio_desc *desc) } EXPORT_SYMBOL_GPL(aspeed_gpio_copro_release_gpio); +static void aspeed_gpio_irq_print_chip(struct irq_data *d, struct seq_file *p) +{ + const struct aspeed_gpio_bank *bank; + struct aspeed_gpio *gpio; + u32 bit; + int rc, offset; + + rc = irqd_to_aspeed_gpio_data(d, &gpio, &bank, &bit, &offset); + if (rc) + return; + + seq_printf(p, dev_name(gpio->dev)); +} + +static const struct irq_chip aspeed_gpio_irq_chip = { + .irq_ack = aspeed_gpio_irq_ack, + .irq_mask = aspeed_gpio_irq_mask, + .irq_unmask = aspeed_gpio_irq_unmask, + .irq_set_type = aspeed_gpio_set_type, + .irq_print_chip = aspeed_gpio_irq_print_chip, + .flags = IRQCHIP_IMMUTABLE, + GPIOCHIP_IRQ_RESOURCE_HELPERS, +}; + /* * Any banks not specified in a struct aspeed_bank_props array are assumed to * have the properties: @@ -1149,6 +1182,8 @@ static int __init aspeed_gpio_probe(struct platform_device *pdev) if (IS_ERR(gpio->base)) return PTR_ERR(gpio->base); + gpio->dev = &pdev->dev; + raw_spin_lock_init(&gpio->lock); gpio_id = of_match_node(aspeed_gpio_of_table, pdev->dev.of_node); @@ -1208,12 +1243,9 @@ static int __init aspeed_gpio_probe(struct platform_device *pdev) gpio->irq = rc; girq = &gpio->chip.irq; - girq->chip = &gpio->irqc; + gpio_irq_chip_set_chip(girq, &aspeed_gpio_irq_chip); girq->chip->name = dev_name(&pdev->dev); - girq->chip->irq_ack = aspeed_gpio_irq_ack; - girq->chip->irq_mask = aspeed_gpio_irq_mask; - girq->chip->irq_unmask = aspeed_gpio_irq_unmask; - girq->chip->irq_set_type = aspeed_gpio_set_type; + girq->parent_handler = aspeed_gpio_irq_handler; girq->num_parents = 1; girq->parents = devm_kcalloc(&pdev->dev, 1,