Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=68.232.154.123 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796373313; b=FLt7enwEW5BjwaIH7EkLwkmiSK3XxXA3GDqvevnzDzVcQ/AyWC6k+E+yVrld/x98oX4E o7RKCND+xRrlqKtLoTKyHcfKniP4KakTesyikXst09Dh47ZlE7E5J5e0y2uYo55ctOw8o DIIdEUUO0OZ9JTvMvb5VIYG05I4Usxuy2mUxlPZWAEMV316Y0h6vy+U4xBL6uMc5Y98as oSOOgeZ8Onw/zzy/0dVKMWwJ9GcQhPmGUbV2I12I2F/0e6BUvr8ittCMML+T5r17bMfuo t7p5frBRtzj5I7NjyAt+tbw5Nky9e+B6b3NXRGjQFWB1KfchH9MlJwXuySCTy53KDOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796373313; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-Amp-Result:Received:Received:Received:From:To:CC: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:Content-Type; bh=D2W9FCrnfK10c44ukkheBiXRROFPaW9PjOdVGcmLXMg=; b=ozBN3C8DO9FKG8yIOJsbXRsu9CfoQpvnnMNvmPtmqq8u9ROv8UaLoF5igkpCs1LYdDJP nnGVc0vCLdbN8CnB9WCSQgo3EKbq0I836oBC042Fq++tsIGJUK3zcgyF1F+ue3juqPVbK OytnC5o8H6LEbbl+mGisht3UyQlvvOHnXW4GFtHl6ashubF3vwxwcKrLt1TkZF9BAy/C7 wOO4EOniBIdSB64jmIuDalsALvaoR3I1j1CwTGE3D1vdF1QV7pUdYP7N73qTU9CIPlZjF 1w6hTPzT6yLrGEUbZEW3dUt2pTqk/37ea6tWf+Onq+hQSUAhPI+rjFX8gFBFL/myzbw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass header.d=microchip.com header.i=@microchip.com header.a=rsa-sha256 header.s=mchp header.b=HoyMvldB; arc=none smtp.remote-ip=68.232.154.123 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0CD6D606A322 for ; Fri, 4 Dec 2026 08:35:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0CD6D606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.a=rsa-sha256 header.s=mchp header.b=HoyMvldB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1796373321; x=1827909321; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5UDQnlL8XAz2WbPqNKngctdyOir1hKwcHeSjLYFTQYY=; b=HoyMvldB8APYFJ0gzN5Yw0acIZZaDs30MlCrT0PcLDEQ/UegkfC/fnOR f7TzjtCuQzJcwgbs3HrHZ7puFalNoOmTEz+u85leoLObIRr7tB/mYQvil BT36mUTGyINi9YbwzZ+lRbryfV8BaP8Uz0V6ORb0icuEoJ1RAbW4y9jE2 WAfk2vpqe4jcJRXkh2glI0I30R+cA96PvAiOLQFcZhYJXnjc8iVEnASGY w9WMo8DM/xBrhFAxXcSLqATmalaA5C5J4GLcEVmkwHnBZjDxu+xHKdhqG 1CteXxxzw5ri8Izx1CcvzphnuVGMbcV8mAPf0sRM+H91kIJPxfvg0zy/e g==; X-CSE-ConnectionGUID: KE+Y5MyETkiYvu5iL/VLfg== X-CSE-MsgGUID: IehFW5C1QaStpM9rSURnlA== X-IronPort-AV: E=Sophos;i="6.29,78,1794898800"; d="scan'208";a="67665417" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 04 Dec 2026 01:35:19 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.58; Fri, 4 Dec 2026 01:35:09 -0700 Received: from che-ll-i67131.microchip.com (10.10.85.11) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.58 via Frontend Transport; Fri, 4 Dec 2026 01:35:06 -0700 From: Manikandan Muralidharan To: , , , , , , CC: Subject: [PATCH 2/3] i3c: mipi-i3c-hci: add Microchip quirk to derive SCL timings from gclk Date: Fri, 4 Dec 2026 14:04:48 +0530 Message-ID: <20261204083449.933526-3-manikandan.m@microchip.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261204083449.933526-1-manikandan.m@microchip.com> References: <20261204083449.933526-1-manikandan.m@microchip.com> 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-Transfer-Encoding: 8bit Content-Type: text/plain The SAMA7D65 I3C controller currently reuses the AMD OD/PP timing quirk, which the register values tuned for the AMD core clock.Introduce hci_quirks_mchp.c with mchp_cfg_od_pp_timing(), which derives the push-pull, open-drain, SDR1..SDR4 extended low count and bus free timings from the gclk rate and the bus I3C/I2C SCL rates, and gate it with a new HCI_QUIRK_MCHP_OD_PP_TIMING quirk. The timings are programmed from bus_init(), once the SCL rates are known, and from i3c_hci_reset_and_init() so that they are restored whenever the controller is reset. Signed-off-by: Manikandan Muralidharan --- drivers/i3c/master/mipi-i3c-hci/Makefile | 2 +- drivers/i3c/master/mipi-i3c-hci/core.c | 21 ++- drivers/i3c/master/mipi-i3c-hci/hci.h | 4 + .../i3c/master/mipi-i3c-hci/hci_quirks_mchp.c | 124 ++++++++++++++++++ 4 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c diff --git a/drivers/i3c/master/mipi-i3c-hci/Makefile b/drivers/i3c/master/mipi-i3c-hci/Makefile index e3d3ef757035..8139d3a049c0 100644 --- a/drivers/i3c/master/mipi-i3c-hci/Makefile +++ b/drivers/i3c/master/mipi-i3c-hci/Makefile @@ -4,5 +4,5 @@ obj-$(CONFIG_MIPI_I3C_HCI) += mipi-i3c-hci.o mipi-i3c-hci-y := core.o ext_caps.o pio.o dma.o \ cmd_v1.o cmd_v2.o \ dat_v1.o dct_v1.o \ - hci_quirks.o + hci_quirks.o hci_quirks_mchp.o obj-$(CONFIG_MIPI_I3C_HCI_PCI) += mipi-i3c-hci-pci.o diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c index 23853ca134fb..bc71871be2f0 100644 --- a/drivers/i3c/master/mipi-i3c-hci/core.c +++ b/drivers/i3c/master/mipi-i3c-hci/core.c @@ -183,6 +183,13 @@ static int i3c_hci_bus_init(struct i3c_master_controller *m) if (hci->quirks & HCI_QUIRK_RESP_BUF_THLD) amd_set_resp_buf_thld(hci); + /* Configure OD and PP timings once the bus SCL rates are known */ + if (hci->quirks & HCI_QUIRK_MCHP_OD_PP_TIMING) { + ret = mchp_cfg_od_pp_timing(hci); + if (ret) + return ret; + } + scoped_guard(spinlock_irqsave, &hci->lock) hci->irq_inactive = false; @@ -961,6 +968,10 @@ static int i3c_hci_reset_and_init(struct i3c_hci *hci) if (hci->quirks & HCI_QUIRK_OD_PP_TIMING) amd_set_od_pp_timing(hci); + /* Configure OD and PP timings from the gclk rate for Microchip platforms */ + if (hci->quirks & HCI_QUIRK_MCHP_OD_PP_TIMING) + return mchp_cfg_od_pp_timing(hci); + return 0; } @@ -1186,7 +1197,6 @@ static int i3c_hci_init(struct i3c_hci *hci) static int i3c_hci_probe(struct platform_device *pdev) { const struct mipi_i3c_hci_platform_data *pdata = pdev->dev.platform_data; - struct clk_bulk_data *clks; struct i3c_hci *hci; int irq, ret; @@ -1222,10 +1232,15 @@ static int i3c_hci_probe(struct platform_device *pdev) if (!hci->quirks && platform_get_device_id(pdev)) hci->quirks = platform_get_device_id(pdev)->driver_data; - ret = devm_clk_bulk_get_all_enabled(&pdev->dev, &clks); + ret = devm_clk_bulk_get_all_enabled(&pdev->dev, &hci->clks); if (ret < 0) return dev_err_probe(&pdev->dev, ret, "Failed to get clocks\n"); + hci->num_clks = ret; + + /* Microchip SCL timings are derived from the second (gclk) clock */ + if ((hci->quirks & HCI_QUIRK_MCHP_OD_PP_TIMING) && hci->num_clks < 2) + return dev_err_probe(&pdev->dev, -EINVAL, "Missing gclk\n"); ret = i3c_hci_init(hci); if (ret) @@ -1268,7 +1283,7 @@ static void i3c_hci_remove(struct platform_device *pdev) static const __maybe_unused struct of_device_id i3c_hci_of_match[] = { { .compatible = "mipi-i3c-hci", }, { .compatible = "microchip,sama7d65-i3c-hci", - .data = (void *)(ulong)(HCI_QUIRK_PIO_MODE | HCI_QUIRK_OD_PP_TIMING | + .data = (void *)(ulong)(HCI_QUIRK_PIO_MODE | HCI_QUIRK_MCHP_OD_PP_TIMING | HCI_QUIRK_RESP_BUF_THLD) }, {}, }; diff --git a/drivers/i3c/master/mipi-i3c-hci/hci.h b/drivers/i3c/master/mipi-i3c-hci/hci.h index 6a5b1f9875e1..0137c91e84cf 100644 --- a/drivers/i3c/master/mipi-i3c-hci/hci.h +++ b/drivers/i3c/master/mipi-i3c-hci/hci.h @@ -53,6 +53,8 @@ struct i3c_hci { void __iomem *EXTCAPS_regs; void __iomem *AUTOCMD_regs; void __iomem *DEBUG_regs; + struct clk_bulk_data *clks; + int num_clks; const struct hci_io_ops *io; void *io_data; const struct hci_cmd_ops *cmd; @@ -178,6 +180,7 @@ struct i3c_hci_dev_data { #define HCI_QUIRK_RPM_PARENT_MANAGED BIT(7) /* Runtime PM managed by parent device */ #define HCI_QUIRK_DMA_ABORT_REQUIRES_PIO_RESET BIT(8) /* Do PIO queue SW resets after DMA abort */ #define HCI_QUIRK_DMA_REQUIRES_HC_ABORT BIT(9) /* Use HC_CONTROL ABORT to abort DMA */ +#define HCI_QUIRK_MCHP_OD_PP_TIMING BIT(10) /* Set OD and PP timings from gclk for Microchip */ /* Vendor-specific SCL timing registers shared by the quirk files */ #define HCI_SCL_I3C_OD_TIMING 0x214 @@ -191,6 +194,7 @@ void mipi_i3c_hci_pio_reset_all_queues(struct i3c_hci *hci); void mipi_i3c_hci_dct_index_reset(struct i3c_hci *hci); void amd_set_od_pp_timing(struct i3c_hci *hci); void amd_set_resp_buf_thld(struct i3c_hci *hci); +int mchp_cfg_od_pp_timing(struct i3c_hci *hci); void i3c_hci_sync_irq_inactive(struct i3c_hci *hci); int i3c_hci_process_xfer(struct i3c_hci *hci, struct hci_xfer *xfer, int n); diff --git a/drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c b/drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c new file mode 100644 index 000000000000..dff319d6287f --- /dev/null +++ b/drivers/i3c/master/mipi-i3c-hci/hci_quirks_mchp.c @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * I3C HCI Microchip Quirks + * + * Copyright (C) 2026 Microchip Technology Inc. and its subsidiaries + * + * Author: Manikandan Muralidharan + */ + +#include +#include +#include +#include +#include +#include +#include "hci.h" + +/* Clock order fixed by the binding: pclk, gclk */ +#define MCHP_GCLK_IDX 1 + +#define SCL_I3C_TIMING_HCNT W0_MASK(23, 16) +#define SCL_I3C_TIMING_LCNT W0_MASK(7, 0) + +/* + * Microchip I3CC extended low-count timing (not part of the HCI standard). + * Each SDRx mode reuses the push-pull SCL-high count and stretches only the + * SCL-low period through its own field. + */ +#define MCHP_SCL_EXT_LCNT_TIMING 0x228 +#define MCHP_EXT_LCNT_SDR1 W0_MASK(7, 0) +#define MCHP_EXT_LCNT_SDR2 W0_MASK(15, 8) +#define MCHP_EXT_LCNT_SDR3 W0_MASK(23, 16) +#define MCHP_EXT_LCNT_SDR4 W0_MASK(31, 24) + +#define MCHP_BUS_FREE_TIMING 0x234 +#define MCHP_BUS_I3C_MST_FREE W0_MASK(15, 0) + +/* SDR1..SDR4 target SCL rates (Hz) */ +#define MCHP_I3C_SDR1_SCL_RATE 8000000 +#define MCHP_I3C_SDR2_SCL_RATE 6000000 +#define MCHP_I3C_SDR3_SCL_RATE 4000000 +#define MCHP_I3C_SDR4_SCL_RATE 2000000 + +#define MCHP_SCL_CNT_MIN 1 +#define MCHP_SCL_CNT_MAX 0xff /* each count field is 8 bits */ + +/* + * Cycles for one half of an SCL period. + * + * @core_rate: I3C peripheral (generic) clock rate + * @scl_rate: target rate for the phase/mode being programmed + * @base: cycles already used by the opposite half of the period + * + * Returns round_up(core_rate / scl_rate) - base, clamped to a non-zero + * 8-bit count. Shared by the PP low, OD high, and SDR1..4 extended low counts. + */ +static u8 mchp_scl_cnt(unsigned long core_rate, unsigned long scl_rate, u8 base) +{ + u32 period = DIV_ROUND_UP(core_rate, scl_rate); + + if (period <= base) + return MCHP_SCL_CNT_MIN; + + return min_t(u32, period - base, MCHP_SCL_CNT_MAX); +} + +int mchp_cfg_od_pp_timing(struct i3c_hci *hci) +{ + struct i3c_bus *bus = &hci->master.bus; + unsigned long core_rate, i2c_rate; + u32 ext_lcnt; + u8 hcnt, lcnt; + + /* SCL rates are only known once the bus mode has been set */ + if (!bus->scl_rate.i3c) + return 0; + + core_rate = clk_get_rate(hci->clks[MCHP_GCLK_IDX].clk); + if (!core_rate) + return -EINVAL; + + /* A pure I3C bus leaves the I2C rate unset, run open-drain at FM+ */ + i2c_rate = bus->scl_rate.i2c ?: I3C_BUS_I2C_FM_PLUS_SCL_MAX_RATE; + + /* + * Push-pull timing. SCL-high is time-bounded (kept below the 50 ns I2C + * spike-filter threshold so legacy I2C targets ignore the fast I3C + * clock); the low half then fills the rest of the I3C SCL period. + */ + hcnt = clamp_t(u32, DIV_ROUND_UP_ULL((u64)I3C_BUS_THIGH_MIXED_MAX_NS * core_rate, + NSEC_PER_SEC) - 1, + MCHP_SCL_CNT_MIN, MCHP_SCL_CNT_MAX); + lcnt = mchp_scl_cnt(core_rate, bus->scl_rate.i3c, hcnt); + reg_write(HCI_SCL_I3C_PP_TIMING, + FIELD_PREP(SCL_I3C_TIMING_HCNT, hcnt) | + FIELD_PREP(SCL_I3C_TIMING_LCNT, lcnt)); + + /* + * SDR1..SDR4 extended low counts. The SCL-high count is reused + * unchanged; EXT_LCNT_x is the total SDRx low count, so that + * period = PP_HCNT + EXT_LCNT_x. + */ + ext_lcnt = FIELD_PREP(MCHP_EXT_LCNT_SDR1, + mchp_scl_cnt(core_rate, MCHP_I3C_SDR1_SCL_RATE, hcnt)) | + FIELD_PREP(MCHP_EXT_LCNT_SDR2, + mchp_scl_cnt(core_rate, MCHP_I3C_SDR2_SCL_RATE, hcnt)) | + FIELD_PREP(MCHP_EXT_LCNT_SDR3, + mchp_scl_cnt(core_rate, MCHP_I3C_SDR3_SCL_RATE, hcnt)) | + FIELD_PREP(MCHP_EXT_LCNT_SDR4, + mchp_scl_cnt(core_rate, MCHP_I3C_SDR4_SCL_RATE, hcnt)); + reg_write(MCHP_SCL_EXT_LCNT_TIMING, ext_lcnt); + + /* Open-drain timing, ~50% duty derived from the I2C SCL rate */ + lcnt = mchp_scl_cnt(core_rate, 2 * i2c_rate, 0); + hcnt = mchp_scl_cnt(core_rate, i2c_rate, lcnt); + reg_write(HCI_SCL_I3C_OD_TIMING, + FIELD_PREP(SCL_I3C_TIMING_HCNT, hcnt) | + FIELD_PREP(SCL_I3C_TIMING_LCNT, lcnt)); + + /* Bus-free time matches the open-drain low period */ + reg_write(MCHP_BUS_FREE_TIMING, FIELD_PREP(MCHP_BUS_I3C_MST_FREE, lcnt)); + + return 0; +} -- 2.43.0