From patchwork Tue Sep 10 05:16:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Song X-Patchwork-Id: 13797954 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 6C940ECE564 for ; Tue, 10 Sep 2024 05:08:11 +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:References:In-Reply-To: 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: List-Owner; bh=2Lr+g46YZbFbjIGR+5G5nZWbqIdPwHBdJJMuP7mRRtI=; b=BaYdA8yXr0VgQj coozXdWDksYyOw9uE71NKMgynkJO4gr68CVEVIgoxfi6DTnyxK+X8TDIl35QbGOarnKDT34D0yc7Z Vnk5lhTH7F3Qskqa0tELlzvggO4On1aHKiXg0j5VURTHZFBn5gTd8XEl/aS1LnT7RG2k0gCGXiT2l /mPxJg8Fv4RzP0/0cWA384FLnU7esbqG93nrn/D1SwkMXz7O+19NgrhqpkAox7rrmtkuxMM9u1jau 2thn+o8A1dXnRs1UcUHoBXCg77NKmVwJvhzX8pGkHz2dXOYDo97Vd7RGix4vovVF2o8QtPkmzh0cb YvrjOfwJmQmsfQTW5hzg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1snt6o-00000004I9V-3YIg; Tue, 10 Sep 2024 05:08:11 +0000 Received: from mail-northeuropeazlp170120003.outbound.protection.outlook.com ([2a01:111:f403:c200::3] helo=DU2PR03CU002.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1snt6b-00000004I2X-2n2p for linux-i3c@lists.infradead.org; Tue, 10 Sep 2024 05:08:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FyFy/9Kem+9Q1gvQK2T4Q2aKYslVuCtEL5UNVlpGsYP+R/r26r1jhyDSVYiCNy989GquynFgNnirc55L/LXBweuxM75uU4ppXCKRZnJx3fYAbdAevIZjHlxGmRn+vXalVj4/+W4bbPKmamtnpEeH6/G/xuQgFs9hzi9W6AHzeIAfzIvtzag+KeFSJrs+ou5BMNlqy5bEl8eRRAdz9sJKxsYpKqTF91FUp+4T8hE5SuDOVgp+st8J4mIe8wbEtsRJ6tJb3hj1f8BB/ckGxcYcVTB7fENym0xkzMHCjPcCXrqyfevaH6HT4mwfOMzSBYxfprajLwN9uxk6unzX/TekgA== 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=7jgYPtL5RXLvu2IOq7Dn3zXwwd7MgHjU4MVS06875VE=; b=BXY9BJ+vjYJ0Pg3R7JNPwirZF6qGJRR6iScmgRzAdX0n74I37USmRVTbiLTueOCwpqp/OMAdB/klHcft6ZpURoYMiMFjsjQ+/T95W0SyhDFYCkmzfM2s4o8f8P/OLd5kZa0VX1Hnn9kvNpoCaSfTL4YMTwW/yBDdowlvwNb2C24Aquz73cMIFYeO+w2Tzbkds6NrEFWcAHtp5GdizqIlEVKkGzWtky92LyewNUrf2orjOw9SVoYj7psilCFmfE5cx0pxX4lKeFlJTBQlUcjI3s9KG68g3qFSdwV57vpQkOnr8gvjssTTnwduMpeFQ1eAjyFdGWKpiIJhx/GTDJFr/g== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7jgYPtL5RXLvu2IOq7Dn3zXwwd7MgHjU4MVS06875VE=; b=gWKhufzAcGGz9lE+8X4y54ubk+RpJc36q02PNiiNkGpkri77r5ixwVhes0G7AHA6iVaMqUnBdooJ5qgP1cgiLsNbwQpK1z/DArafnLlGbPEAIP9F6qDqGbJ1LQiLxCpU5634Aq7UBR2rgCW/1m9OoD+nSsj9Se+P78+ZlY1FkchrxkzWyl8v4xtLivKs74Hrq4a2DaKSUuU+LDGw0vJU7Qy2tbzj0LoJtCjhEvXYCqWbijN2+6zDHLiW/4rlXbA7uBgrevWrgSHe0uFCsGaDazWYM3uDV1JEhYrXROvfcKuaIdcZg9xLKZ7ukNbIkGiulehOBtgcGsv5p40hI1Rk8w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB7PR04MB5003.eurprd04.prod.outlook.com (2603:10a6:10:1a::19) by VI1PR04MB7134.eurprd04.prod.outlook.com (2603:10a6:800:12e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.23; Tue, 10 Sep 2024 05:07:41 +0000 Received: from DB7PR04MB5003.eurprd04.prod.outlook.com ([fe80::68ea:5937:4fa7:db2b]) by DB7PR04MB5003.eurprd04.prod.outlook.com ([fe80::68ea:5937:4fa7:db2b%6]) with mapi id 15.20.7918.024; Tue, 10 Sep 2024 05:07:41 +0000 From: carlos.song@nxp.com To: alexandre.belloni@bootlin.com, miquel.raynal@bootlin.com, conor.culhane@silvaco.com, frank.li@nxp.com Cc: linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev Subject: [PATCH V5 2/2] i3c: master: svc: use slow speed for first broadcast address Date: Tue, 10 Sep 2024 13:16:26 +0800 Message-Id: <20240910051626.4052552-2-carlos.song@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910051626.4052552-1-carlos.song@nxp.com> References: <20240910051626.4052552-1-carlos.song@nxp.com> X-ClientProxiedBy: SG2PR01CA0197.apcprd01.prod.exchangelabs.com (2603:1096:4:189::8) To DB7PR04MB5003.eurprd04.prod.outlook.com (2603:10a6:10:1a::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB5003:EE_|VI1PR04MB7134:EE_ X-MS-Office365-Filtering-Correlation-Id: 913486fb-98ac-4e8c-6418-08dcd1567f29 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: YRCNy1gdCjUlDh+GM7VDLiYe0UfiMNH7MVi5cd0jcv+z8uhFljaSnJN939U50xeMXia89/8pwRfZujGjcIr4a4h1+lJx9NUM1Y3Og5LZu2zMgZLveBhvm/fAmH5DSJr/k7AMgg6tMXbclZABbqmj5qzHB83dl04mbVfulYbfFEPCU/PHr0MOwpwOte7B9Lsz9+Onw20Ib4NnwPn0P9RMsurN1NVIstIRwXc/9f84SooorQAZAnPZwtQ2xFw1Hg2fbRxBKNcmt/sVtza96JyGxCiP8CPTv68ONcoEuHZul7ek/t/xIioHaGO3U+LD+DqEO5MsIFpDySfnnq7E1OR1MLewdpH6bCN633fnAEqpgYAFKUl0KPWHWrBk+rxjIekKlkxVuBNQeNyGII4qulAXRHCzs8oj2vU1zPPJ6rGnD+q+HQEkk9PdlhPP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prd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(52116014)(366016)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sWhYhBv+b9fRYwa+AdRDcZhJ/ki2Xm6mPHekOk13YiPkl/OlzvAuoFwYudE8rYiYusfu1Nm3KWYX5skCJEqulGu7yUh3/3FFPYaBXtQXOoSO8ceZoAEABL2PzqDTqV8iAxQp3KgfvqrhVCvUJw86ey+IfPVW01M3Zw8T43fASa6wOcXf6GK5+amsUQcpG8qsuQZduDCXLoQ/YNAaW7qMSO5PkPXSwXiMZZ/LeDKiF3OWJ/6s+DaV2HQHtNB+XYsF1cAWbU+whVD6usP/jLHpeoGvIloLdkgEy/y6nRcimOcd/z19V+YykhztgpFIdo6HcMVhv8jVOGlsJ126h8/POm6p3cNooSmteoMiiPFkGEv9nDcJ0Wcxg/AHIPepY7PXAgbqNAJ3pRG/rGqVzLZFxWXNQcK/mAC9rlQRGyVqKbbCvIQk+5avL1B1sWZ2WzJurFaI5SEQ7U4wG8pwqkCagjVArIQeMYZglOIL2wg8o5JSAPw9Nf/GjAO1Jj9rKmCgAe2A841u+psCOvunCNoQhuNb5pIXyE3psicnxDkEtmUw9CIJFu62wAeKtQ0LoA9KDMJXpFA9s3uc5yzb/hxAwU7bRx1H/68Py7CXpbGoi0m5E6CfcLfZZxe1r/J1E1P5H6Z5pF974sfrm7/pg3KNKqksrnkmCntMgm8qJv5wZuE8X3Gl9eReuOZalVYA8YISxRBeVgTPqLMyIOh4gkZQSZizEOR+0pjldRoZcZeG21v/zbyKpL0qBI61wMIU7xImHnuouNjiM0mdhaH/Fnw9r0Db3amrxQfMrshRIJ+FPLyK1wy67Tkme9VcZwizlnTGED5ZPrjECupOz+Nw23LITwdPTs6sWH9Wcr9bXGqjoQi2aBlmC77HSVMEEvq3iUu6WQOfGINdWUP+MYljg1yGdPZ0tbwQNlx+R5+Z54RV8QyGbOttlssmrMr4/ljM8YLOkBLjnJns/7ihHDlHuBF2N7hZkv5q3ihOiIxELQvtKEEOIOdH/rmsN/b4NO5Mr9FV128ltxmrPsoOPKJenqKL9T5wUOl7c2fwiBIYzu7C7ajUkKDHYML94n9oYepegUNMErSwWaER18eRwlcxXkxyfwmQw3S4EOh2tqHQVnB+7gJ3iThDuznyLUtAWE0UP15RmomKPMCQAoucxzePwr3AaI/BlT2N/jHdoH8gJxIVqt1ZY3FvoOWeiKwRNfPl6l2tpnwyE5V7a/ssLr8qUjREyB3sttgg0+UWd8+3f2I0kgtLfOuhWfCh6RXOfnEdQETC/jMAOvMSf2H50Dx2lKQOUy0yJwWv6+SfnWz5KVTludV2s97UbNfi2mqs7NxdFp5Dq2bdv0mj39NaYxxa59M/juHICsxqldDrBqe7/rovdQD9ojNpp/yCafeFXCs2lI/5Gxvn1Cp8SCMe3RjD6mHP9bb7akk5ZzS4vueg1J1FRVUVJ8N8Xm7Oy11OWZrbObjILkwEY7NagAn1O2PTnFnePU8N0hQQhmpX0rK98ctIjM2VHc33UfsrNWYP8ux9RK1/1vI0h6F05HUeamFX59t7Zjsjm2y/CHPuHNsGARObF1yWmVxRX7EfwRsI/AJcmKfG X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 913486fb-98ac-4e8c-6418-08dcd1567f29 X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB5003.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 05:07:41.5801 (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: gCvUoyupMj1pgeRTpml5nwUwCHMTABB8mfmA1LQDQcLQMyVFp6NiThNj9DWno+5WhsFo//RzANEpx1PHd46T1w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7134 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240909_220757_796795_DE1775D8 X-CRM114-Status: GOOD ( 18.21 ) 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 I3C controller should support adjusting open drain timing for the first broadcast address to make I3C device working as a i2c device can see slow broadcast address to close its Spike Filter to change working at i3c mode. Signed-off-by: Carlos Song Reviewed-by: Frank Li --- Change for V5: - No change. Resend this patch to list after subscribe to mail list. Change for V4: - No change. Send out together with I3C master.c fix patch. Change for V3: - No change. But miss sending it with I3C master.c fix patch. Change for V2: - Adjust variable definition order - Add mctrl_config description to fix build warning --- drivers/i3c/master/svc-i3c-master.c | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c index 7c30f58e344b..423db3dca257 100644 --- a/drivers/i3c/master/svc-i3c-master.c +++ b/drivers/i3c/master/svc-i3c-master.c @@ -184,6 +184,7 @@ struct svc_i3c_regs_save { * @ibi.lock: IBI lock * @lock: Transfer lock, protect between IBI work thread and callbacks from master * @enabled_events: Bit masks for enable events (IBI, HotJoin). + * @mctrl_config: Configuration value in SVC_I3C_MCTRL for setting speed back. */ struct svc_i3c_master { struct i3c_master_controller base; @@ -214,6 +215,7 @@ struct svc_i3c_master { } ibi; struct mutex lock; int enabled_events; + u32 mctrl_config; }; /** @@ -531,6 +533,54 @@ static irqreturn_t svc_i3c_master_irq_handler(int irq, void *dev_id) return IRQ_HANDLED; } +static int svc_i3c_master_set_speed(struct i3c_master_controller *m, + enum i3c_open_drain_speed speed) +{ + struct svc_i3c_master *master = to_svc_i3c_master(m); + struct i3c_bus *bus = i3c_master_get_bus(&master->base); + u32 ppbaud, odbaud, odhpp, mconfig; + unsigned long fclk_rate; + int ret; + + ret = pm_runtime_resume_and_get(master->dev); + if (ret < 0) { + dev_err(master->dev, "<%s> Cannot get runtime PM.\n", __func__); + return ret; + } + + switch (speed) { + case I3C_OPEN_DRAIN_SLOW_SPEED: + fclk_rate = clk_get_rate(master->fclk); + if (!fclk_rate) { + ret = -EINVAL; + goto rpm_out; + } + /* + * Set 50% duty-cycle I2C speed to I3C OPEN-DRAIN mode, so the first + * broadcast address is visible to all I2C/I3C devices on the I3C bus. + * I3C device working as a I2C device will turn off its 50ns Spike + * Filter to change to I3C mode. + */ + mconfig = master->mctrl_config; + ppbaud = FIELD_GET(GENMASK(11, 8), mconfig); + odhpp = 0; + odbaud = DIV_ROUND_UP(fclk_rate, bus->scl_rate.i2c * (2 + 2 * ppbaud)) - 1; + mconfig &= ~GENMASK(24, 16); + mconfig |= SVC_I3C_MCONFIG_ODBAUD(odbaud) | SVC_I3C_MCONFIG_ODHPP(odhpp); + writel(mconfig, master->regs + SVC_I3C_MCONFIG); + break; + case I3C_OPEN_DRAIN_NORMAL_SPEED: + writel(master->mctrl_config, master->regs + SVC_I3C_MCONFIG); + break; + } + +rpm_out: + pm_runtime_mark_last_busy(master->dev); + pm_runtime_put_autosuspend(master->dev); + + return ret; +} + static int svc_i3c_master_bus_init(struct i3c_master_controller *m) { struct svc_i3c_master *master = to_svc_i3c_master(m); @@ -624,6 +674,7 @@ static int svc_i3c_master_bus_init(struct i3c_master_controller *m) SVC_I3C_MCONFIG_I2CBAUD(i2cbaud); writel(reg, master->regs + SVC_I3C_MCONFIG); + master->mctrl_config = reg; /* Master core's registration */ ret = i3c_master_get_free_addr(m, 0); if (ret < 0) @@ -1658,6 +1709,7 @@ static const struct i3c_master_controller_ops svc_i3c_master_ops = { .disable_ibi = svc_i3c_master_disable_ibi, .enable_hotjoin = svc_i3c_master_enable_hotjoin, .disable_hotjoin = svc_i3c_master_disable_hotjoin, + .set_speed = svc_i3c_master_set_speed, }; static int svc_i3c_master_prepare_clks(struct svc_i3c_master *master)