From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10ACC3B6BF1 for ; Wed, 27 May 2026 20:10:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779912618; cv=none; b=rDSKOJMTYCX07Ffm2oyyZkGBD3L/qgaKHCkXo1RGU+DgX3LVaxTiq8+qPM4mb+FVmiszrjs5zlByShM0dmDLkxu7hIaDbHXYVGVnGU73o3H5jlQTOwYocE3ZARhb3r4xEIrpMNNMmYp/leztRyhteNZzNwHW+A1x8xqqzKl7lqA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779912618; c=relaxed/simple; bh=gLLA3yyHeohOG2GTebtGSeCoVbwDGh3LRV+lAp+ifus=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Vj1k4Yb7rNOhj03bO6ew5a9FFKt1zhcSj18q7OAP/nMjl19AYHjigxPzzzzMtpVGQVnuQFg8yS1LOhB9moiYImSkVplD7BpljsAnvL1GS5zpQfs7pVM3/hVJade4HK4/hBFdYvqk2J9EZIoT5AoEtGanPTOFjYF+3YndaOP+DOk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=wkennington.com; spf=none smtp.mailfrom=wkennington.com; dkim=pass (2048-bit key) header.d=wkennington-com.20251104.gappssmtp.com header.i=@wkennington-com.20251104.gappssmtp.com header.b=RAVHXciU; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=wkennington.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=wkennington.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wkennington-com.20251104.gappssmtp.com header.i=@wkennington-com.20251104.gappssmtp.com header.b="RAVHXciU" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-3665a90bcd3so12971910a91.1 for ; Wed, 27 May 2026 13:10:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wkennington-com.20251104.gappssmtp.com; s=20251104; t=1779912616; x=1780517416; darn=vger.kernel.org; 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=GMbCijtkQtm47ZP7cdCWnRygezzmp+zq/74mENw1x54=; b=RAVHXciUfUq/r/RAgBJdyhM7nrO+8tHloSJOAak+jn2SkVO8Z8knegn8iodVycpva+ ADGXGjP965deWfdB8rknCZYtpSkGr5w9YQFyL+6F88pJjsVkjCAogu/WraeeW910GJLq QDrlmVvmvI6imIPdTFNL0ol+VP86BliOCYlNidQQ9NAi+ZDQlDcNCkxyZguIKMcweT+6 CodtS0qIu8guZxo4MTHpPOx8MRUbMx45NHzCB0jrB3ctvcWGDKgUoHoBV3bOzxYp9Pw5 0yi+cXVc6l3G5/yIFvtXhXS7P+33+L2jD25802nZa0szJ2O/6Oo4FKF1zAAheLrELayz 4THw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779912616; x=1780517416; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=GMbCijtkQtm47ZP7cdCWnRygezzmp+zq/74mENw1x54=; b=qQe+LHGWncgG8WK+UCqjiDROWm5BVo+7BcEHjiGBymGa0NhTJ4RDEfQ4HeSWsnv6MK +ALGCo7L3TZYg8YGNIWYoy3kbyq8kNAN+jizyuxGexeTQTSzC4HL0rJ1MyQGr9/qZJVH 4icLd/MNAxRG6FxcQzxRdqSisiwbvtboF24uk3pZuO4B5CPSRLBIaBMQyK7aO+6qR9P3 ZN30CE8Pwen+ZIIaiJ1Rlns8F0DX3weTtzbOdg7DEy/h/deyAeQ88G/tZwykJg65dV+z +nb704tzuwkU1qzmu6wCrp0ceMyyHnCHz8jbo83SPhDFpHlFc+S4QDSdJs6hFP1SuaJJ 0f8Q== X-Forwarded-Encrypted: i=1; AFNElJ8iTSDzIbWawRZrAQH3MeSPkrpnHxJfbAoCeBgpPeSvaRnkMI5N15Q0Lv7gJJSQ7M/POqBn5A9zVAr2k44=@vger.kernel.org X-Gm-Message-State: AOJu0Yxd6ld0Q1tF5VWFO9MmPqtGiM8Cv3b6f768TzTc26evnwKgNKvd K7jK+bcn/MYFV6GTqRWBQgXmjboNaFzBm6nmvpvfgE1xbZPWF26iZbJEnwVCvPZNj/+mRz+OI/1 gBlQ9s8vcbg== X-Gm-Gg: Acq92OGI/gQKQac0nja0zW3gM20MupRXyXQyq8UpQihGx1wumF2+jhMF/VD2PuCFH8q bmGb4ckiaYgwbFbEo4JPor8n8/GjymTfurSA+v6BLVlApTub27alG2KXLtA/tC4xMmPuIA6UQ4b M0xY3pZsKo58aiV3Zj7I9GjLz/d3E2HOuwyeet/pUgmRv8ZSkPPqUbUHg1pPI8Szip6gAABjh3x sdVWxq2RKMo52isQ3cXTBD1HuvRInv4zNaLfBk1r0RaBFF3Unb1hUAfhGY91d3lgeyFSBw4IsJi LPAHLLMm8P8M22n1l8+FXVYHje6RCH2YV/D34KWh2P5T9gdd1NozcMN9Fca8zctIRUFxvW961KM KonwKCQZoKZP6IqKTa0+qVUDw5bD6ucF77ZfjunC1Fhqlzv4lcPAexABhBb6qCQNaHwaysrChLl yo/bnKVsQgdV34LAk80hFMPuzDWDOTf0BP9hRE3L0Obz3lrAa+7r8yvDueiSKeHDRA+TNT3nSSw c+svyrWVH+fy1O0Bp6mnPk= X-Received: by 2002:a17:90a:c88d:b0:369:73a:326a with SMTP id 98e67ed59e1d1-36a6760034amr24042873a91.13.1779912616350; Wed, 27 May 2026 13:10:16 -0700 (PDT) Received: from wakbuild.c.googlers.com (27.117.125.34.bc.googleusercontent.com. [34.125.117.27]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-36a71d9416csm21875253a91.3.2026.05.27.13.10.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 13:10:15 -0700 (PDT) From: "William A. Kennington III" Date: Wed, 27 May 2026 20:09:52 +0000 Subject: [PATCH RESEND v5 4/4] i2c: designware: Handle active target cleanly 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="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260527-dw-i2c-v5-4-3483057f8d67@wkennington.com> References: <20260527-dw-i2c-v5-0-3483057f8d67@wkennington.com> In-Reply-To: <20260527-dw-i2c-v5-0-3483057f8d67@wkennington.com> To: Mika Westerberg , Andy Shevchenko , Jan Dabros , Andi Shyti Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, "William A. Kennington III" X-Mailer: b4 0.14.3 When the I2C controller attempts a new transaction while the target controller is shutting down or restarting, it can lead to bus lockups and system bootloops if the hardware enters an inconsistent state. Address this by ensuring that the internal state machines are properly cleared when disabling the controller if target activity is detected. If the controller remains active after disabling, perform a bus recovery to reset it to a known good state. Signed-off-by: William A. Kennington III Reviewed-by: Andy Shevchenko --- drivers/i2c/busses/i2c-designware-common.c | 8 ++++++++ drivers/i2c/busses/i2c-designware-master.c | 31 ++++++++++++++++++------------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c index ef618d3e1ace..7d9c6a5148cd 100644 --- a/drivers/i2c/busses/i2c-designware-common.c +++ b/drivers/i2c/busses/i2c-designware-common.c @@ -633,6 +633,14 @@ void __i2c_dw_disable(struct dw_i2c_dev *dev) abort_needed = (raw_intr_stats & DW_IC_INTR_MST_ON_HOLD) || (ic_stats & DW_IC_STATUS_MASTER_HOLD_TX_FIFO_EMPTY); + + /* + * If we are in target mode and there is activity, we should also + * trigger an abort to clear the internal state machines. + */ + if (dev->mode == DW_IC_SLAVE && (ic_stats & DW_IC_STATUS_SLAVE_ACTIVITY)) + abort_needed = true; + if (abort_needed) { if (!(enable & DW_IC_ENABLE_ENABLE)) { regmap_write(dev->map, DW_IC_ENABLE, DW_IC_ENABLE_ENABLE); diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c index de929b91d5ea..7a301c8b604e 100644 --- a/drivers/i2c/busses/i2c-designware-master.c +++ b/drivers/i2c/busses/i2c-designware-master.c @@ -785,18 +785,25 @@ __i2c_dw_xfer_one_part(struct dw_i2c_dev *dev, struct i2c_msg *msgs, size_t num) * IC_RAW_INTR_STAT.MASTER_ON_HOLD holding SCL low. Check if * controller is still ACTIVE before disabling I2C. */ - if (i2c_dw_is_controller_active(dev)) - dev_err(dev->dev, "controller active\n"); - - /* - * We must disable the adapter before returning and signaling the end - * of the current transfer. Otherwise the hardware might continue - * generating interrupts which in turn causes a race condition with - * the following transfer. Needs some more investigation if the - * additional interrupts are a hardware bug or this driver doesn't - * handle them correctly yet. - */ - __i2c_dw_disable_nowait(dev); + if (i2c_dw_is_controller_active(dev)) { + /* + * If the controller is still active after the timeout, attempt a + * bus recovery to clear any potentially locked state. + */ + dev_err(dev->dev, "controller active after xfer, recovering\n"); + i2c_recover_bus(&dev->adapter); + i2c_dw_init(dev); + } else { + /* + * We must disable the adapter before returning and signaling the end + * of the current transfer. Otherwise the hardware might continue + * generating interrupts which in turn causes a race condition with + * the following transfer. Needs some more investigation if the + * additional interrupts are a hardware bug or this driver doesn't + * handle them correctly yet. + */ + __i2c_dw_disable_nowait(dev); + } if (dev->msg_err) return dev->msg_err; -- 2.54.0.794.g4f17f83d09-goog