From patchwork Tue Mar 7 13:04:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 65455 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2421513wrd; Tue, 7 Mar 2023 05:14:31 -0800 (PST) X-Google-Smtp-Source: AK7set8eH49+foRaF644myHy1eI03jTp65Dzh5TE0NVHli7PEIHNLI8s3kb9d49Wi5YhGnxQ9GBy X-Received: by 2002:aa7:db53:0:b0:4af:6c25:f04b with SMTP id n19-20020aa7db53000000b004af6c25f04bmr13223581edt.13.1678194871481; Tue, 07 Mar 2023 05:14:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678194871; cv=none; d=google.com; s=arc-20160816; b=FQUJ3g+s5QWHg+Q0AV/DgANc9RfThhtEXLgtFdqA0ZdymQYRlOZXUjSx4grleqDzX9 jubyn2WshqhrB1+xIUgWhXM+ZySFkqZ732UOFSFMWDmi66S0USswjRawxDSOE/St1LdD onPiWleghQhs56xWTPG2h3vQts4SuPx7EO/CRD0Wk+7TZ6F2SEOSf5RPNAZG83gkHWeM DbZ17ISg3qWdWaQERokvqxc9wyoZi9HUGizAThsk8oObS/dF+c42cwjgh1V7tJDUDzHb IiTlbJz+NH0a/iPYx/t9y0bkgEYIjeNrwlZXOCEP08Cd5okMOv+ngIys40T/5m4+se6P ATxQ== 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=vYLgGoAAs4DcH8LZQncbtVAjj3rbStL1HUOVD02/kfE=; b=OW48VjeU2TxGVEeLSc7oAjqd4mYn6U+4SJEdiHOyL6ImBLoXu0F4s8vIFWbOByUIvz PUVRCfKEr9rXOVJ5xTdaocUdZKJhZzsr8w/Ikl0Ig31wiGoz5n9m7kSRRXFsDfF5ckUO 6AGD6KOjMH8/IWz1uJ7YSymMWYfA/6tncqzdcuQOgwgFm6dN9lH+ZAYzuA1n6Xqnvqb6 ukLIwg3Z6/f3mesViywxhj50VbGYyhIyLjFr8qWXjk/PNBsw28xu53VsBkXRETHz9J4K MmNJYzlp4wkZpMEbw6S4xpmHSx813YzQg0/0IK4KTlS9lUjHfmiKjFdyh3Be6r9NzlO4 Xrjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xFksW1uc; 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 w21-20020a056402071500b004ad15de0646si3507066edx.591.2023.03.07.05.14.07; Tue, 07 Mar 2023 05:14:31 -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=xFksW1uc; 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 S230286AbjCGNGp (ORCPT + 99 others); Tue, 7 Mar 2023 08:06:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230267AbjCGNFm (ORCPT ); Tue, 7 Mar 2023 08:05:42 -0500 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 284687B4B7 for ; Tue, 7 Mar 2023 05:05:14 -0800 (PST) Received: by mail-lf1-x135.google.com with SMTP id bi9so17002590lfb.2 for ; Tue, 07 Mar 2023 05:05:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678194300; 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=vYLgGoAAs4DcH8LZQncbtVAjj3rbStL1HUOVD02/kfE=; b=xFksW1ucR4VOlqND6VFtfCf8TmvKFAMaPgfmp89lUYxRs/sod65QrfiIah7Gh/Dy39 u1yUTnfZG8eABAidi24UpO/uHNb/HrPCEKyWBVqrM4etXND3x8pr2PkwDDULloTm6G0U 7FYs892dZq4G1/2pi5X+pCiqihETM0BZ055oUEhbh5iBVT17MORRCwbHuucrepQR9XKV G2GHTrQefD4prN4B1VTCjuXQlFJ1YUWHxu19RLWtFzIjQOmIDiSYjOPamg/ffYDJK8pE sErqOCZ1CIxpOatarkfbwdhpirqgqiDTVzDqc/j4E0TjqBk5tXkuGpeHuS09pFbq1VI7 vDvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678194300; 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=vYLgGoAAs4DcH8LZQncbtVAjj3rbStL1HUOVD02/kfE=; b=AwTroZj7fYmliLWJeQvK3IrP3cO3y3hPiMU8wW8F3bIvz+gSTEvJXNJ+qY8J242en5 gRPpEnyRSL4jDE4APNXTNn24iOmuQ3Qaq02myewbTv+6/gKwR48rSBrdGEayUFs8vQTt l/oZvUX/e9bDPbBoztHBWyL+0Cy2cg+87tu4BlCO1PRtDgFmGm6zKsqmg7sBJC8DnTRW Rb1gcUMRMVZuRokdOirzdS31Xyps0jUCQKShxh8FhhIUI6dIsq6jylR+WTDkmKmi2eeR lVWTg290+R45Lfrp1x9Taux2ajeqOJvJ5srawG5sEJJVZQLzBXZst7QPJnsmDBuOoKBq 96Jw== X-Gm-Message-State: AO0yUKXjqiWcYjvx3w6UZhweFg6hBklSL3aSrlB/s0oi0wdk6+TE9e8C gM1SCDI7GdpjBIuW0sn2kfl/XQ== X-Received: by 2002:a05:6512:144:b0:4db:513f:fe2a with SMTP id m4-20020a056512014400b004db513ffe2amr4069156lfo.23.1678194300102; Tue, 07 Mar 2023 05:05:00 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 05:04:59 -0800 (PST) From: Linus Walleij Date: Tue, 07 Mar 2023 14:04:56 +0100 Subject: [PATCH v2 14/16] gpio: omap: Convert to immutable irq_chip MIME-Version: 1.0 Message-Id: <20230215-immutable-chips-v2-14-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 , Bartosz Golaszewski , Joel Stanley , Andrew Jeffery , Alban Bedel , Orson Zhai , Baolin Wang , Chunyan Zhang , Jay Fang , Daniel Palmer , Romain Perier , Santosh Shilimkar , Kevin Hilman , William Breathitt Gray 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 , Marc Zyngier , Tony Lindgren 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=unavailable 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759714865575049948?= X-GMAIL-MSGID: =?utf-8?q?1759714865575049948?= Convert the driver to immutable irq-chip with a bit of intuition. This driver require some special care: .irq_ack() was copied from dummy_irq_chip where it was defined as noop. This only makes sense if using handle_edge_irq() that will unconditionally call .irq_ack() to avoid a crash, but this driver is not ever using handle_edge_irq() so just avoid assigning .irq_ack(). A separate chip had to be created for the non-wakeup instance. Cc: Marc Zyngier Reviewed-by: Tony Lindgren Tested-by: Tony Lindgren Acked-by: Marc Zyngier Signed-off-by: Linus Walleij --- drivers/gpio/gpio-omap.c | 68 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c index 1cbd040cf796..a08be5bf6808 100644 --- a/drivers/gpio/gpio-omap.c +++ b/drivers/gpio/gpio-omap.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +48,7 @@ struct gpio_regs { struct gpio_bank { void __iomem *base; const struct omap_gpio_reg_offs *regs; + struct device *dev; int irq; u32 non_wakeup_gpios; @@ -681,6 +683,7 @@ static void omap_gpio_mask_irq(struct irq_data *d) omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); omap_set_gpio_irqenable(bank, offset, 0); raw_spin_unlock_irqrestore(&bank->lock, flags); + gpiochip_disable_irq(&bank->chip, offset); } static void omap_gpio_unmask_irq(struct irq_data *d) @@ -690,6 +693,7 @@ static void omap_gpio_unmask_irq(struct irq_data *d) u32 trigger = irqd_get_trigger_type(d); unsigned long flags; + gpiochip_enable_irq(&bank->chip, offset); raw_spin_lock_irqsave(&bank->lock, flags); omap_set_gpio_irqenable(bank, offset, 1); @@ -708,6 +712,40 @@ static void omap_gpio_unmask_irq(struct irq_data *d) raw_spin_unlock_irqrestore(&bank->lock, flags); } +static void omap_gpio_irq_print_chip(struct irq_data *d, struct seq_file *p) +{ + struct gpio_bank *bank = omap_irq_data_get_bank(d); + + seq_printf(p, dev_name(bank->dev)); +} + +static const struct irq_chip omap_gpio_irq_chip = { + .irq_startup = omap_gpio_irq_startup, + .irq_shutdown = omap_gpio_irq_shutdown, + .irq_mask = omap_gpio_mask_irq, + .irq_unmask = omap_gpio_unmask_irq, + .irq_set_type = omap_gpio_irq_type, + .irq_set_wake = omap_gpio_wake_enable, + .irq_bus_lock = omap_gpio_irq_bus_lock, + .irq_bus_sync_unlock = gpio_irq_bus_sync_unlock, + .irq_print_chip = omap_gpio_irq_print_chip, + .flags = IRQCHIP_MASK_ON_SUSPEND | IRQCHIP_IMMUTABLE, + GPIOCHIP_IRQ_RESOURCE_HELPERS, +}; + +static const struct irq_chip omap_gpio_irq_chip_nowake = { + .irq_startup = omap_gpio_irq_startup, + .irq_shutdown = omap_gpio_irq_shutdown, + .irq_mask = omap_gpio_mask_irq, + .irq_unmask = omap_gpio_unmask_irq, + .irq_set_type = omap_gpio_irq_type, + .irq_bus_lock = omap_gpio_irq_bus_lock, + .irq_bus_sync_unlock = gpio_irq_bus_sync_unlock, + .irq_print_chip = omap_gpio_irq_print_chip, + .flags = IRQCHIP_MASK_ON_SUSPEND | IRQCHIP_IMMUTABLE, + GPIOCHIP_IRQ_RESOURCE_HELPERS, +}; + /*---------------------------------------------------------------------*/ static int omap_mpuio_suspend_noirq(struct device *dev) @@ -986,8 +1024,7 @@ static void omap_gpio_mod_init(struct gpio_bank *bank) writel_relaxed(0, base + bank->regs->ctrl); } -static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc, - struct device *pm_dev) +static int omap_gpio_chip_init(struct gpio_bank *bank, struct device *pm_dev) { struct gpio_irq_chip *irq; static int gpio; @@ -1023,12 +1060,12 @@ static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc, } bank->chip.ngpio = bank->width; + irq = &bank->chip.irq; /* MPUIO is a bit different, reading IRQ status clears it */ if (bank->is_mpuio && !bank->regs->wkup_en) - irqc->irq_set_wake = NULL; - - irq = &bank->chip.irq; - irq->chip = irqc; + gpio_irq_chip_set_chip(irq, &omap_gpio_irq_chip_nowake); + else + gpio_irq_chip_set_chip(irq, &omap_gpio_irq_chip); irq->handler = handle_bad_irq; irq->default_type = IRQ_TYPE_NONE; irq->num_parents = 1; @@ -1361,7 +1398,6 @@ static int omap_gpio_probe(struct platform_device *pdev) struct device_node *node = dev->of_node; const struct omap_gpio_platform_data *pdata; struct gpio_bank *bank; - struct irq_chip *irqc; int ret; pdata = device_get_match_data(dev); @@ -1374,21 +1410,7 @@ static int omap_gpio_probe(struct platform_device *pdev) if (!bank) return -ENOMEM; - irqc = devm_kzalloc(dev, sizeof(*irqc), GFP_KERNEL); - if (!irqc) - return -ENOMEM; - - irqc->irq_startup = omap_gpio_irq_startup, - irqc->irq_shutdown = omap_gpio_irq_shutdown, - irqc->irq_ack = dummy_irq_chip.irq_ack, - irqc->irq_mask = omap_gpio_mask_irq, - irqc->irq_unmask = omap_gpio_unmask_irq, - irqc->irq_set_type = omap_gpio_irq_type, - irqc->irq_set_wake = omap_gpio_wake_enable, - irqc->irq_bus_lock = omap_gpio_irq_bus_lock, - irqc->irq_bus_sync_unlock = gpio_irq_bus_sync_unlock, - irqc->name = dev_name(&pdev->dev); - irqc->flags = IRQCHIP_MASK_ON_SUSPEND; + bank->dev = dev; bank->irq = platform_get_irq(pdev, 0); if (bank->irq <= 0) { @@ -1452,7 +1474,7 @@ static int omap_gpio_probe(struct platform_device *pdev) omap_gpio_mod_init(bank); - ret = omap_gpio_chip_init(bank, irqc, dev); + ret = omap_gpio_chip_init(bank, dev); if (ret) { pm_runtime_put_sync(dev); pm_runtime_disable(dev);