From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796033453; b=HZZQ4wu9/EIURP+/xlgC69nbZMVvQywE8uu7wQajMdLuqZRJEpq6UNmu7lorYEulxvjw 0M5MmZtminzV3N6As6JJFO8FgEvbJuDPp1oAPiKgnF8VNGxnzkqLNWkbjpmx5Ge4gwQz0 eUi+sDCz8JWplzDBo6ddPmEF3R55ZMH8Mb0aEEvSTIbD+dlc45jTJI+KGbcV9SfWbPI9j 1x32dv63j3/krJa2VflADPa8ccGmjpVjcAz4k+J2Yj/M+b7CN4TGe5s0Ez6pkLq0IlPxo sOujo9XMqGel7GeocJpYLMT4SaC8fDylyYnqtwNOyHFI6RHsaMVLuyhIY9vFaHjO/Mw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796033453; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key; bh=4bL3z5QiC6rRqR6u924qghqHWkbxyHLBxKnx8tDmf0M=; b=d8Br+GSIyD0SupOKnIDG7cMx3LgW4kAVynu9WCLS/YEoR4avwhvuPUEjNdkuxciuNdGh RKd4+RZHigzTB0cZZdtlRavledrOh8GWOCJ+vetWM7rpus/IpAxCEjXWGOeBvrGoNkpOR kt2qk/eMOsCjvW2utVFN4WNSubSdpUn6QXufTPpec7gz+aiUO8pmAvnYSHfdu04+9qcz+ Dw/j3hh4OQSTLehBxiJdkCi705A4yjPcm28W4Hwv2agzOsvnZUlvbAOmt/AtwZQlLTZk1 KlKkYITeIDuRMJWhUH/BCGnBwahpDyUS7ubxZAY/ZhJnxScGtY4YR5i/y3RJKOC1iWw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=flipper.net; spf=pass smtp.mailfrom=flipper.net; dkim=pass header.d=flipper.net header.i=@flipper.net header.a=rsa-sha256 header.s=google header.b=R1jbKCOC; arc=none smtp.remote-ip=209.85.128.46 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA596606A31C for ; Mon, 30 Nov 2026 10:10:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EA596606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=flipper.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flipper.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flipper.net header.i=@flipper.net header.a=rsa-sha256 header.s=google header.b=R1jbKCOC Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4a2000d5fb1so60028155e9.1 for ; Mon, 30 Nov 2026 02:10:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flipper.net; s=google; t=1796033451; x=1796638251; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:content-type :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=4bL3z5QiC6rRqR6u924qghqHWkbxyHLBxKnx8tDmf0M=; b=R1jbKCOCv7MFEKHCl7H2YNesczl9KC1faqmv9CmX5uM/BS2/ngUJLNX/qrtWTSvuES gxUW1VnPkNYyqfCWMBjhyI+0HVYKUWrjkelu4ltkJsYS4Lph3rxXn/rI3kEhpX4HU8Kg qOsL/+Elvgz3I7qk5Iw57H1SsPfZm2e007E+KmF18hEoYP1UgyE0lTWGJ/RQCbiSG1t9 +eJx4HrP+nSgbnZR+utKhWrIzuuypDo+hDm2+BHjx9FCIxU11NbvjG9bJSQc6jJKmsgS 8tArSJ8YjPrVpllo6px4XcIuoekuBPD5peJPC9e7QJUYmd2qFTWT55F8w9W4XEEpWnR8 8Imw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796033451; x=1796638251; h=cc:to:message-id:content-transfer-encoding:content-type :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=4bL3z5QiC6rRqR6u924qghqHWkbxyHLBxKnx8tDmf0M=; b=izfNDq4ATLCpvuj3Iuj1duLn4tabFJDcar3kiiMIPigeuVzbZF4tgfc6PKwInjbbtB HrL8r+BUgu2ZW0iUIVTntzagmnt9PDSiAAW/lX6LdLld5JJrZS4mKBrD3L73mpeDqJVq Qw6anALFy/DrrAmfY2HhGuzJtlbyErH7lEz6/UNM9BosUBLCtWDOhGTBaChTa4ORJwQ/ 2HRbwtALFDZCQsCpgg68ErzDqLBOHuas32QeZmkHRxvpcuqkHx/zuiFAhhnDzQYeJzFo vrj859ajTiLsFrYu5nn3mPSFKq6vJsqb+nsalewD0yT/PUroAiPJOKmQQa3DESZ1THWf rueA== X-Forwarded-Encrypted: i=1; AL+hErElxipH0orx7M1BzdUaHGuiOOKPSa+Be878gyQmxgbLL6EpanFKwntB1lUCIKasqBVtqgNg04MtkrqFq+I=@vger.kernel.org X-Gm-Message-State: APuU4Z/8AXxzRnJu/stSFjAI6sCnPlXYYyTv5ToVnMBTSOsWzNxeUCeX PpIoNkuCNUTipXI9gcmfSDzS5Bs/hjyDBbULAQjmdbMnVSGJhOglNy0kn1kOsErxTkCjQnuanZU PIOaf X-Gm-Gg: AZFdTZdsM0+/gt3lGGCcb6TrNshw2Kcdktvr8fMMXlgOCN3KA9fpW1J2wlO4kXNw1WL 6jTOOwhGSZcbej6gttHjIjFUbtQ9FXf2mhE8WoGFOmU3bcqK+zloIz26oHa/j0AloNNhXgkBXyk pl5ItX81pUNpT5sUACGcEqDchaaNmdCjOVvipvFze7uMrDN6Bau0z3uj+95Aauyzwx7XDCxLPJd qoBFQVcUtf+fiuFuKsItbz9z1hW5RiekUHx6TYnbPXX61GjYMwXOrQZdNLAD+SwyjrUN7BTOmF2 S55a1XvRwqJ14xDWCLtMkppYTtvRc3fxaOTDIUXnLzx2N+H1wLjjnDQXwhHgPVasPp2cTVine1t F5X3xBiSib+3UK8Pqj1KTqGWy/6yl2GSpp2QGgdxCQTv2oXMeuRMJOAYwJy/oRCLCl/e7MhXQB3 8f5Yw3HQebbtU4PhBX3Vat+1V6YYUOuVv/Jdg+ujsTfBOjEq6VoMWt3cm3KrQQF028RPG5jN8VW b9RS35vt5J8prW/HmoGubdOXXCXg1OyT2wd5j0T06G74Y09jpOgL65Au9gFDNBhm+6Qw7dWBIDF L4QhgyxxM+irNjmYMW1c+S6zse6YTN2S6xrE9bN5hbL8/jpZ66OogtbtTgQoHvrv2OJLsJ5lVsP I2+z99lOrq69EVpDPCRh5QG0cOGXXIEM= X-Received: by 2002:a05:600c:3508:b0:4b2:3c81:d1 with SMTP id 5b1f17b1804b1-4bb88826921mr664036605e9.5.1796033451257; Mon, 30 Nov 2026 02:10:51 -0800 (PST) Received: from alchark-surface.localdomain (bba-86-98-194-229.alshamil.net.ae. [86.98.194.229]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb906cdcc1sm582002455e9.2.2026.11.30.02.10.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 02:10:50 -0800 (PST) From: Alexey Charkov Date: Mon, 30 Nov 2026 14:10:41 +0400 Subject: [PATCH] gpio: pca953x: Re-check level-triggered lines that stay active X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261130-pca953x-level-reenable-v1-1-a989d2505da4@flipper.net> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/yXMQQrCMBBG4auUWTvQpKS0XkVcTOKvnRJiSbQUS u9u1OW3eG+ngqwodG52yli16DNVmFNDYZL0AOutmmxre9Max0uQ0XUbR6yInIEkPoIFIkPfwTr nqcZLxl233/hy/bu8/Yzw+t7oOD6kRnKbegAAAA== X-Change-ID: 20261015-pca953x-level-reenable-aeaa863e255b To: Linus Walleij , Bartosz Golaszewski , Potin Lai Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Alexey Charkov X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5517; i=alchark@flipper.net; h=from:subject:message-id; bh=qdFDcHsehmVbrDC7ZOgJmNr6Fa6Jpvh0b42qAeMpa3s=; b=owGbwMvMwCW2adGNfoHIK0sZT6slMWTzeq8R/NgpPOmHm55rVt6UP4ahV25pORh7CGav5m9qs l4k/6SjYyILgxgXg6WYIsvcb0tspxrxzdrl4fEVZg4rE8gQaZEGBiBgYeDLTcwrNdIx0jPVNtQz NNIx1jFi4OIUgKmeNoGR4eqG181lV2qnLD00zV2RP03g255Fi9kP56g/Xfh0RWP2s50M/x1vXuv /1xvt+cU6qrzqmZh31ZbI/Wcf7Ny08X7dl4tZy/gB X-Developer-Key: i=alchark@flipper.net; a=openpgp; fpr=9DF6A43D95320E9ABA4848F5B2A2D88F1059D4A5 The expanders only interrupt when an input changes from the value last read, so they cannot express a level that is still active once its handler has run, or once its consumer re-enables the interrupt. That is the case whenever a new event comes in before the handler, or the deferred work of a consumer that disables its interrupt meanwhile, has cleared the last one. No input changes, the expander stays quiet, and the event sits unnoticed until an unrelated line on the same expander happens to change. On a board with a FUSB302 behind a TCA6416 this loses the source's Accept in most USB PD negotiations, so the sink keeps timing out and issuing hard resets for tens of seconds before it gets a contract. A FUSB302 driver that handles its interrupt in the IRQ thread rather than in deferred work stops getting interrupts within seconds of a burst of USB PD messages instead: its RX FIFO fills up and the chip stops acknowledging them. Wake the expander's interrupt thread, so that it reads the inputs and handles the line if it is still active, as a level-sensitive interrupt controller would, once a level-triggered interrupt has been handled, and when one is enabled, or switched to level triggering while enabled. Skip an interrupt the consumer keeps disabled after its handler, which would only spin until enabling it re-checks anyway. Do the scan in that thread rather than in the caller, so nested handlers stay serialized and never run under the locks of whoever enabled the interrupt. Hook .irq_enable rather than .irq_unmask: the core disables interrupts lazily without masking them, so re-enabling one does not unmask it. Fixes: 417b0f8d08f8 ("gpio: pca953x: Add support for level-triggered interrupts") Signed-off-by: Alexey Charkov --- drivers/gpio/gpio-pca953x.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 270cea8b4b49..e8ff948f392c 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -232,6 +232,7 @@ struct pca953x_chip { DECLARE_BITMAP(irq_trig_fall, MAX_LINE); DECLARE_BITMAP(irq_trig_level_high, MAX_LINE); DECLARE_BITMAP(irq_trig_level_low, MAX_LINE); + bool irq_level_recheck; #endif atomic_t wakeup_path; @@ -834,6 +835,19 @@ static void pca953x_irq_unmask(struct irq_data *d) set_bit(hwirq, chip->irq_mask); } +static void pca953x_irq_enable(struct irq_data *d) +{ + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); + struct pca953x_chip *chip = gpiochip_get_data(gc); + irq_hw_number_t hwirq = irqd_to_hwirq(d); + + pca953x_irq_unmask(d); + + if (test_bit(hwirq, chip->irq_trig_level_low) || + test_bit(hwirq, chip->irq_trig_level_high)) + chip->irq_level_recheck = true; +} + static int pca953x_irq_set_wake(struct irq_data *d, unsigned int on) { struct gpio_chip *gc = irq_data_get_irq_chip_data(d); @@ -899,6 +913,15 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d) pca953x_gpio_direction_input_unlocked(&chip->gpio_chip, level); out: + /* + * The chip only interrupts on input changes, so a level-triggered line + * that is already active when enabled would go unnoticed. + */ + if (chip->irq_level_recheck) { + chip->irq_level_recheck = false; + irq_wake_thread(chip->client->irq, chip); + } + mutex_unlock(&chip->irq_lock); } @@ -919,6 +942,9 @@ static int pca953x_irq_set_type(struct irq_data *d, unsigned int type) assign_bit(hwirq, chip->irq_trig_level_low, type & IRQ_TYPE_LEVEL_LOW); assign_bit(hwirq, chip->irq_trig_level_high, type & IRQ_TYPE_LEVEL_HIGH); + if ((type & IRQ_TYPE_LEVEL_MASK) && test_bit(hwirq, chip->irq_mask)) + chip->irq_level_recheck = true; + return 0; } @@ -946,6 +972,7 @@ static void pca953x_irq_print_chip(struct irq_data *data, struct seq_file *p) static const struct irq_chip pca953x_irq_chip = { .irq_mask = pca953x_irq_mask, .irq_unmask = pca953x_irq_unmask, + .irq_enable = pca953x_irq_enable, .irq_set_wake = pca953x_irq_set_wake, .irq_bus_lock = pca953x_irq_bus_lock, .irq_bus_sync_unlock = pca953x_irq_bus_sync_unlock, @@ -1035,6 +1062,7 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid) struct pca953x_chip *chip = devid; struct gpio_chip *gc = &chip->gpio_chip; DECLARE_BITMAP(pending, MAX_LINE); + bool recheck = false; int level; bool ret; @@ -1055,9 +1083,25 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid) handle_nested_irq(nested_irq); ret = 1; + + /* + * The chip interrupts again only once an input changes, + * so a level still active after its handler, as when a + * new event came in while the handler cleared the last + * one, would go unnoticed: read the inputs again. Not + * while the consumer keeps the interrupt disabled, which + * would only spin, as enabling it re-checks anyway. + */ + if ((test_bit(level, chip->irq_trig_level_low) || + test_bit(level, chip->irq_trig_level_high)) && + !irqd_irq_disabled(irq_get_irq_data(nested_irq))) + recheck = true; } } + if (recheck) + irq_wake_thread(chip->client->irq, chip); + return IRQ_RETVAL(ret); } --- base-commit: e5aad2bdbbee783611d32599f89cea3f12f9593d change-id: 20261015-pca953x-level-reenable-aeaa863e255b Best regards, -- Alexey Charkov