From patchwork Thu Jul 18 09:13:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Song X-Patchwork-Id: 13736272 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2DD14C3DA61 for ; Thu, 18 Jul 2024 09:18:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=vsKwON9jwsmuZMUuvxKB7Gax0RDcidJokzNQYlAbiiM=; b=lewscFN5jHFlbK qtn6GZAOdg3LRoLhsGNKeGY9KM+Evv6Q5w++S7OFhsfguNZJ9PDDx9SqG9Lu5DCbJWKSXDBd5Xdan cvbNdpW9mpyufug/2D3sMODfVQZeSMeuoLcjqN+WNFO53KjnJIgL/WfkpLk4JQdWhvAvaP5vEZ3ee mYgyYsv1Nc+lf5TGgokcw4ZZpjGxcqfAmr+E+wAondeprlbKEYMXCGHZyMQ3LCWy6U3V7eJz+C7nE gj+fg/VxKDu8exedBS9mfEg/ypqMNHliuvPnt7Rft8KgvSgWOE4v0oGBlb2dOkHavE88WTE9GC88U o/7/IAstIT1Wikgw7sdA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sUNH6-0000000GXNd-364O; Thu, 18 Jul 2024 09:18:08 +0000 Received: from mail-northeuropeazlp170130004.outbound.protection.outlook.com ([2a01:111:f403:c200::4] helo=DUZPR83CU001.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sUNCZ-0000000GWmu-1x2C for linux-i3c@lists.infradead.org; Thu, 18 Jul 2024 09:13:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MYO2OvOzVtSxc/iAyD0ubdDr4N6J/UF8YvuxNst/mVo+Sgw5jXxt79n0zv4GZi6IdUr5NqgXeNaQjqS60NaFkDNZARHmfuqnbXL4udJPieC7goRLX4nfaG5cL3SQmKC6oGRqWu2fq1O7D3M9Pk9fMFzgLhIvlTPCb//k+p5VFYqHa/sdb2LBRr85NaklLGXPNPmtt4FMj2ygSo9apR5m31pQ2pYk6T0OeZihnLogLoUur3rs4ddiOAwFkl7NPw+BrZscJbjz7w6fqLo31x+5E2TQBSCBjmV2B9w/uyoamoNcqNc0mCTPuqVUV7Q7rfbwAlIWrtr4eJiSU593qXfD7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OVxkjXZu70mi6S09FPpIPAXl7P4S6f4ecJB4HIGZT6w=; b=SUjVDFxa1W5Af+y2KucBWT9GmnBxCuFXYJ+by3fWeQLvKEGrLOjUcPwNtn9D0GYWY3GPCaZlInUizJXnNeg4b9Z7MOwfXklI+SM60sp0ZCtdSRiG/F2x2InjmOTy/LCNORCn+5vtfHF2HyxBsEA2dubfhdfx7eWu8NQxXHI3R7uNsQmMbpqkFNDwrGKxrkom+R7q0UbMBC3585sHNgHNKaC8NaCIImFl4A71qLv5ZFhSWkD0riDAlmhYc6ZuyabKo7lRsfNPsTqRZAx7Q6bHzoquUDx166+Vwf4YOdoiSgPXeiEnQ4DPoOfcCuvala6DF3vg9R0loomKn+k4w8/fAA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OVxkjXZu70mi6S09FPpIPAXl7P4S6f4ecJB4HIGZT6w=; b=pBEEDI/inUzpLWHHXBUwbHaT9aoCq6PqsZLkXfp0cfVh3XO+AaOHOjYgS9Cd2xCMkjM0FIa6YpeBE71lE4xvBvViqTV9Vxv//Ugj8zujxmm6iirz5o2AmJlbb/6OssnAv3X7KDyBZ4XpbNNnuC8vIBWR2YSHSXadHhLj2Db4MPw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5005.eurprd04.prod.outlook.com (2603:10a6:803:57::30) by PA1PR04MB10263.eurprd04.prod.outlook.com (2603:10a6:102:455::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.29; Thu, 18 Jul 2024 09:13:18 +0000 Received: from VI1PR04MB5005.eurprd04.prod.outlook.com ([fe80::3a57:67cf:6ee0:5ddb]) by VI1PR04MB5005.eurprd04.prod.outlook.com ([fe80::3a57:67cf:6ee0:5ddb%7]) with mapi id 15.20.7784.017; Thu, 18 Jul 2024 09:13:17 +0000 From: carlos.song@nxp.com To: miquel.raynal@bootlin.com, conor.culhane@silvaco.com, alexandre.belloni@bootlin.com, frank.li@nxp.com Cc: linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH v2] i3c: master: svc: adjust SDR according to i3c spec Date: Thu, 18 Jul 2024 17:13:28 +0800 Message-Id: <20240718091329.3788619-1-carlos.song@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SG2PR04CA0203.apcprd04.prod.outlook.com (2603:1096:4:187::22) To VI1PR04MB5005.eurprd04.prod.outlook.com (2603:10a6:803:57::30) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5005:EE_|PA1PR04MB10263:EE_ X-MS-Office365-Filtering-Correlation-Id: 4a98c670-b49b-47a4-6633-08dca709dc6f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|366016|376014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: /BQeIK4bYkX7dXpHXthwBrCgTXenC5zPGLzRcgIx3Zx4RYQrhyV8iwEX2keB62of6VE5Cmdb4IIM+tg+Ns4N3+W5zhJ/4PL/rxbiZRoPSkFSfUwtsBPMT5kdnDJ4wEBm58JlIps8lzimJEozxDEFH/ayBf4YMCuQ8nW+Ao5L8I2Wn950bJSr4iQqEWiWbIPOcNa6o5FYJwnwDDeaJs3nMymA4+DRORJmrfu95krEdGQ3UrnZcSo3ESVyzfzB6tiUXLAjLaV5DgNASGQnSoxce9tCd4wn0QG+GEVb3N7jHN5ofHJb8ioxpYL1CcfQL8eQPti8uIUDY3tXI6Qq0fnln1bfPLfmD37kYqw3SBwxivp9NKU1TNZCIVBDOwRzbT0orVZ6O6Kvt+1syR/G9HpieCjytwLCkYobEo9X4uTks89DNTiC9ebdZ8kH1fWus+0rfetgIEVJNp8ARYoTMGGejg0mbjGnuLt27C+gadtnX19Ywhiz28zLu6xrargU8nukMfg9RLGvSHpDsXI0O7DVfKj7XLUr4hiPFW+nAgB8xOnZiJ94NCK+UMGGnfcgrb49QlIpLCG94dAbyukQrmgfIq4UjvBl71OJf2jeBI3jeAdcqLTIJVI9ju4zucB9O1ESx7ZVntSQmHdHUxXbraCterLUXZEqTxmGXqnZpXJQ3uuPTBY+c2UmTpgR7vSY6DYBIeLopsdkAuLdc60Xt4st+06DvFwhklDzhRklVQD/TjdQXTxvIkfqngc6gvQUGLHHqSxknnuHnwYtEJGHzKrP/oCYe9yicYBrxgVoRaBAsn27A0XCI6r6+/Lpu43MTtKAYHUaNwVTAEcktSSQJhH0DyuEXvg3BhnTbbRGZLiRzxOLc8nBj/n82FMKvcW87MBgpdMF9mVbfksSsdkzyVpPQ5oMCBRWvzw6Ne226fp9Ml5eVHexUKUyvzHt9bKk35FZNHkSl0tBkR08PT0xzu0dvAQGF/Kmxm6dg7WRiqmXzd0TAl42FrctkTuSEyz9Z8basSUSbmuZY48d1LHXjwm883Qur2vlHxFH4wEckq2tAz+B1TO0rFGgKqwmr8dvN2fAvM0rXKv2WLTrjnqmQp3AxmzGp9xS75BCJdk8lrTRdZsA/2+M0bGlbtipKPwQMXrke5g8CPyk0S6Tc5oppKzS8Ix7M3ZqTadT53Y9D3oKc/vJw4tAGPP+WK/l62AtJ84iSBZ36tLTr7qQ+A77dUKa8talkdSQDxZAwrReCARouGv12/aSrISaWeFSOlwgdm1rrFa7Lbna+Ghu195u4m0fWBAj2x4N7u4wn79qt+2lg86NasAwALqjmTCnPG1GNF+ws4REhyW8IFEAgp6m9vJq7OYKWnn85/uaK+NaAcHWUpMA05n56GRNMjNPUb7bxn5j4eCEPz5F3LJHYVupqt+spw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5005.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(366016)(376014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RKh497Xwve4tPjIfmvZ26H0Wave+nqB6i3M9NNqmnjUppGz3WoI28bSjggTUPO7ALhvfOa+gSHOh8hMb7xV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Kvib3mBCw1mZ0r5QO1A3lk/WtSudWPoMndn9NiZ+KA2XGZO30QgF4v5aD/wUvU6FMcTGk5/NfaD1FsaICdMqE1Lppbz9weMnZk62BHuAdJYeKFVsPkDrCFQMr4s54c9xjlFDZLc27O3v2zAIURm4RbcsUWFNZu/AtqsuM2pf7NMtQRhpd+2MxoXJaBSFtdikS1+aObiBHEzczU3r3CzI5hAULxV+vbLqoenV9M/hfTmi7mZ89bOedOTB6+vYFgcc6ATah4lVHB2Jfp44bLphJo3GjEjjhOGYJyPO+1nccSOtegGGjEuBFLl68DpvHboLzwb8ibJeGB5uikfXuQk+Vv1FhXVOhfYLMfMmzV9cB2ujxhiSIFczJ9V3D3wRq49ZIG4nJPvRq2m5WA+vb8g0dNUYgEqfFMDGsMvdrfYeJO9x8gYp193Hspb53mYpZ X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4a98c670-b49b-47a4-6633-08dca709dc6f X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5005.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2024 09:13:17.7913 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xryOYqWHgCZc+Vft/rMKHerPEYn/VuWUtuAJZU1QgHhNUfUGReRTAxwdxatgnJ85z4wYxz9vA5nPI/wRmiLzUw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA1PR04MB10263 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240718_021327_541435_815D9318 X-CRM114-Status: GOOD ( 15.69 ) X-Mailman-Approved-At: Thu, 18 Jul 2024 02:18:07 -0700 X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org From: Carlos Song According to I3C Specification(Version 1.1) 5.1.2.4 "Use of Clock Speed to Prevent Legacy I2C Devices From Seeing I3C traffic", when slow i2c devices(FM/FM+ rate i2c frequency without 50ns filter) works on i3c bus, i3c SDR should work at FM/FM+ rate. Adjust timing for difference mode. Signed-off-by: Clark Wang Signed-off-by: Carlos Song Reviewed-by: Frank Li --- Change for V2: - Correct I3C clk configuration and simplify the code: Pure I3C mode and MIXED-FAST I3C mode just use the same i3c clk configuration: 1. i3c push-pull timing is 40ns high and 40ns low at 12.5Mhz 2. i3c open-darin timing is 40ns high and 200ns low at ~4Mhz 3. i2cbaud should be different between Pure I3C mode and MIXED-FAST I3C mode. --- drivers/i3c/master/svc-i3c-master.c | 31 ++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c index e80c002991f7..78116530f431 100644 --- a/drivers/i3c/master/svc-i3c-master.c +++ b/drivers/i3c/master/svc-i3c-master.c @@ -127,6 +127,8 @@ /* This parameter depends on the implementation and may be tuned */ #define SVC_I3C_FIFO_SIZE 16 +#define SVC_I3C_PPBAUD_MAX 15 +#define SVC_I3C_QUICK_I2C_CLK 4170000 #define SVC_I3C_EVENT_IBI BIT(0) #define SVC_I3C_EVENT_HOTJOIN BIT(1) @@ -535,6 +537,7 @@ static int svc_i3c_master_bus_init(struct i3c_master_controller *m) struct i3c_bus *bus = i3c_master_get_bus(m); struct i3c_device_info info = {}; unsigned long fclk_rate, fclk_period_ns; + unsigned long i2c_period_ns, i2c_scl_rate, i3c_scl_rate; unsigned int high_period_ns, od_low_period_ns; u32 ppbaud, pplow, odhpp, odbaud, odstop, i2cbaud, reg; int ret; @@ -555,12 +558,15 @@ static int svc_i3c_master_bus_init(struct i3c_master_controller *m) } fclk_period_ns = DIV_ROUND_UP(1000000000, fclk_rate); + i2c_period_ns = DIV_ROUND_UP(1000000000, bus->scl_rate.i2c); + i2c_scl_rate = bus->scl_rate.i2c; + i3c_scl_rate = bus->scl_rate.i3c; /* * Using I3C Push-Pull mode, target is 12.5MHz/80ns period. * Simplest configuration is using a 50% duty-cycle of 40ns. */ - ppbaud = DIV_ROUND_UP(40, fclk_period_ns) - 1; + ppbaud = DIV_ROUND_UP(fclk_rate / 2, i3c_scl_rate) - 1; pplow = 0; /* @@ -570,7 +576,7 @@ static int svc_i3c_master_bus_init(struct i3c_master_controller *m) */ odhpp = 1; high_period_ns = (ppbaud + 1) * fclk_period_ns; - odbaud = DIV_ROUND_UP(240 - high_period_ns, high_period_ns) - 1; + odbaud = DIV_ROUND_UP(fclk_rate, SVC_I3C_QUICK_I2C_CLK * (1 + ppbaud)) - 2; od_low_period_ns = (odbaud + 1) * high_period_ns; switch (bus->mode) { @@ -579,20 +585,27 @@ static int svc_i3c_master_bus_init(struct i3c_master_controller *m) odstop = 0; break; case I3C_BUS_MODE_MIXED_FAST: - case I3C_BUS_MODE_MIXED_LIMITED: /* * Using I2C Fm+ mode, target is 1MHz/1000ns, the difference * between the high and low period does not really matter. */ - i2cbaud = DIV_ROUND_UP(1000, od_low_period_ns) - 2; + i2cbaud = DIV_ROUND_UP(i2c_period_ns, od_low_period_ns) - 2; odstop = 1; break; + case I3C_BUS_MODE_MIXED_LIMITED: case I3C_BUS_MODE_MIXED_SLOW: - /* - * Using I2C Fm mode, target is 0.4MHz/2500ns, with the same - * constraints as the FM+ mode. - */ - i2cbaud = DIV_ROUND_UP(2500, od_low_period_ns) - 2; + /* I3C PP + I3C OP + I2C OP both use i2c clk rate */ + if (ppbaud > SVC_I3C_PPBAUD_MAX) { + ppbaud = SVC_I3C_PPBAUD_MAX; + pplow = DIV_ROUND_UP(fclk_rate, i3c_scl_rate) - (2 + 2 * ppbaud); + } + + high_period_ns = (ppbaud + 1) * fclk_period_ns; + odhpp = 0; + odbaud = DIV_ROUND_UP(fclk_rate, i2c_scl_rate * (2 + 2 * ppbaud)) - 1; + + od_low_period_ns = (odbaud + 1) * high_period_ns; + i2cbaud = DIV_ROUND_UP(i2c_period_ns, od_low_period_ns) - 2; odstop = 1; break; default: