From patchwork Thu Oct 3 20:14:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13821541 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 0F1B0CF34C3 for ; Thu, 3 Oct 2024 20:14:56 +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:Cc:To:In-Reply-To: References:Message-Id:Subject:Date:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=SoiJuKnSqk3G2D7usLW9Qzgk7QM8rucwBLke6ekNUPg=; b=VEebxFFuXJbszWhbJmMldafT/C 63ZlyAiVqLJzApD6cRaSgZzVNCFUXqo7lXeXXOwo/yvjvzKtt3SYBTBAFiNSQ02iJM/PsFhRfbSIt z5whJ+K6EYXCKqGPcUsGdAM7G6P2ej3K5bKZl+loB/noP1nVhtf7yoQjWu4sCovpTaV2IrAQ3onZ+ txGouLU9DEc7jZC/YYqpNebyvJNC4MHbGCwNXWlUAg8uzLpR/1ZMmnhhaGfhDJW5AnismFaN/LwP7 qX91/rYWq5qNHv2A7eS9BgLRHM0GcINmoVEg6346MCoC+2AqNNEj4IKx9no0c/S6hKPI7b1japHJk 8OsausDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1swSDv-0000000AHOW-3Bif; Thu, 03 Oct 2024 20:14:55 +0000 Received: from mail-northeuropeazlp170110001.outbound.protection.outlook.com ([2a01:111:f403:c200::1] helo=DB3PR0202CU003.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1swSDt-0000000AHMn-1Epj for linux-i3c@lists.infradead.org; Thu, 03 Oct 2024 20:14:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JyG6C6e8hB2ThZcvJmAGMuWutIhrgbAPATVEClEVqvt0Qb17yDW30gOmpIbEvYX8CnrmErusvTYIm1DbprDFfoyaOe9uHtqYKAcigvnCTvk6ojp8Nylu9ih1r0P7prqytmho/r1sRWzJ8rU12fQLjn2SVqwsBrerEOT4TswO1Ba7NuSA0Ogsr4rnlB40gf/dqB8Nt5CCKtj+xbYW92keMxFGv+jogjaS/yct64oOh82OrYPT36YOABNUc3/x0WYY5Tkz8UpctDfpeWzCTWojHuYYePEr4Me+S0bFp66p71RSsSYJzD5eU35C83FJd1t5auHLuJMVliOqdbRCt5x8gQ== 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=1AutemPq5Uze2cW43m6UfBAV9GC9qmzLYuHVO74gWdc=; b=l0EmjAAnjeSa5C3oMseK8RDPStjjnIwvWZBxrzIM/hkviPNGFOIHQqdBUfKrlHWMeIjfB+5SPgGCTqhyNVDwZRmS7NhoukecWegDfPDx2o0aPDKMOQyJu1MPsxQKN3Bqkdyg+ZNejvS7Z/7FUUiwIhkgaDWpArM2GcWSFCeYjfeommLT1b4KAnbsTItR+7TvNp2MhrI6Lvut/rp6wtg49Ru8xrkecrIbw9zbX3BweGHjRFlpi+tTB69ijwEyIjF5g1qpLXJeKUkhSP7m43+Kt8DUfrbreE3/U8YCgqzA1VvmkJnvQzz7OSPKwGKeD65ifMNX5dpaBRtCXjkK2J+fQw== 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=1AutemPq5Uze2cW43m6UfBAV9GC9qmzLYuHVO74gWdc=; b=J4t2iVd4j0ryeV4QUaoq721b5hjDBrQcgGdZ4xu0vYwUH+VDV/pEk+imtnkQJBh+SMXNag3I4Twho4cVPDnd/TJvzZgTytzPO1MZ/+Dm1eHFe93bOL1WQ2rtwT4syzSs0r7K/HpnaOLS9mX6wABOrfnJpEqlLZPLPyWsJzWGFWCz+yZUw9E7N6Kx5IkGNgNp146GYoaNHuzz+SMR1tS6gyX2058kMCQiwRiFc/SDDX8HQw9bskFEhQejAAM4sB1mfia0H57e4fyGqbqhJ0uDMRjX6P1owmCYCABM+LyDp8NG06NuJaqDD3/eXAPSPe6DU78Hrr0Y9YFxnSEUeheZ7g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by PR3PR04MB7481.eurprd04.prod.outlook.com (2603:10a6:102:87::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24; Thu, 3 Oct 2024 20:14:49 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8026.016; Thu, 3 Oct 2024 20:14:49 +0000 From: Frank Li Date: Thu, 03 Oct 2024 16:14:20 -0400 Subject: [PATCH v6 2/3] i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_DESIRED Message-Id: <20241003-i3c_dts_assign-v6-2-eae2569c92ca@nxp.com> References: <20241003-i3c_dts_assign-v6-0-eae2569c92ca@nxp.com> In-Reply-To: <20241003-i3c_dts_assign-v6-0-eae2569c92ca@nxp.com> To: Alexandre Belloni Cc: linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, arnd@arndb.de, bbrezillon@kernel.org, boris.brezillon@collabora.com, conor.culhane@silvaco.com, gregkh@linuxfoundation.org, imx@lists.linux.dev, miquel.raynal@bootlin.com, pthombar@cadence.com, ravindra.yashvant.shinde@nxp.com, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1727986479; l=9085; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=rzbrQPx0d2MOqsRyyCB0fUBaULbidlCEWYXgPMvvdlY=; b=eGcMTUdulnGr5kNKzZqZ4nRcY751Gpu3hXzHQNFg0+cppo9aKjmdGlkvaDYncqU1reU/pfGhq kxLbu9QdsW3DdkbHKSMkYMivPh4al2XXjzi5LRLzQ113N8ex6P9KYdl X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY1P220CA0008.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:59d::16) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PR3PR04MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: f214ace0-38a9-4e08-f870-08dce3e80835 X-LD-Processed: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|52116014|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Adx3WVFBoBtKprWJV2yYkGrXK8IUPh6?= =?utf-8?q?wCR2YNdb352D7z7cvu6ltJDxCrQfgFEKZMfKrYyN3rVp7HgM4S6HMxCpm0nqL7ZOi?= =?utf-8?q?L+sF2ij8YQVVQiXijReWjuGaQzfobx78N7SgeHMwQ9CHLaid/koTxAcHjtwTOruqI?= =?utf-8?q?yR9Gpe8ElHn3pGkDeqBBdledfPJyCOXzofn5G1t+RZsXUzvE9YMjkepfaWoPcvhvr?= =?utf-8?q?lwX0HFt4v2RtjQhg8nlGtN+eL39MapH2V2e2YS3iB38HMtFXB9YEFMUBWYTRuq1YX?= =?utf-8?q?iwPpN3khidYvDnBtho6lMlhuLvPx5TDI2ZFbr1dSA6CAGeFuM0kb88/SNFUtQM4SC?= =?utf-8?q?rf1taVOQCOkO9PkBAxEWqaKlnTNNTD/zfzwR8gW6+TQR9YiTwXQ0NWO08lblCOCAs?= =?utf-8?q?FOjD92OzgE7u3VNRRCGS3OWehCH+z9JtKYCvrdkFfqYfUiWYh45+aloltst9nTFfL?= =?utf-8?q?vcJ11sWpGoHKf7AWOT/9xwNzNgLlSbyg9vaMWvR9142tob9KdOTUDZfTjuXyzYs10?= =?utf-8?q?nUTFANVMItrJ1A7jcks7QgSrN7VfybQZkikAaydcWvOgYblm0688Uvd2bvycpGyrk?= =?utf-8?q?MFIejQYr+I/7BWkMw5c/KQnDf8XcsJtWEdl9OAM0L3Z/XWoygy4xeXgxeAaKXDGZg?= =?utf-8?q?cao5ZjSz/zTZ4ZxBYs1C9ePM2647JE9dpq8JkKCigYNAUa53TU5gOBZGkCLv0i0OY?= =?utf-8?q?AEoJA1hOBklMJ3kRpICBCOu7rEazyne4zF4yzXHyze05IOnRwKcKWrtQOGiwhjyhN?= =?utf-8?q?jicNTKNkUGnEPTzqr8YUJ87iiCnDJS4csCRp9ySdaSRpy44v1OZyIHBLzvmf4w3h3?= =?utf-8?q?H9BKIsblK5srIqVdaUtPCzjLC/o9ER/nvR3Wpmna+WWtkfHuTmTJdDy2Nf0+a+Lpk?= =?utf-8?q?0k6ljHOnQws/vBbUgR+aXMCz3UztOMYMUen9nO3JyOnVq52QDWisEx2U36c30sZQ4?= =?utf-8?q?6aWwqztmfoIpT6m2UrcWrTvUOliKRqRHX+q19n/UgBQocMI6yH6/jb+lTgOlxkc9e?= =?utf-8?q?scOEFzrW3Qev+oqmfbbjygymCwxpm8pTWk69Km90mj36RbLOdpWrnpPOnHfWAdJOw?= =?utf-8?q?YXGwPbHh8W3K+2eZWmuI2FSQXxV/stqEWzCLS0o0Mo9rdBszBm1xrt2R+WQYoZ0eN?= =?utf-8?q?pBdmFnHTZZt9BxK7+prSts+3NkUcB1pLRXnUGhMfwEcH/hoPARUy83reL/dIsvAkE?= =?utf-8?q?9lIyZckfiFg9aRXdYjGQpyuzzDPwLNOXDFIhH9XOMiQWwicVjFsH5fmV91Xvj3gLX?= =?utf-8?q?bgBFcDQvtTNwFN3CyBDdFQgoOBBCH928mFA=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(52116014)(376014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?AzAkmb75BFGnn0IJO1IIrTXkwjHW?= =?utf-8?q?gsdDpcQC+7kos9z/litVAkUIzxPZex6t5yc3ehTUaj/0w2/yK0XwTDHCjnnubbUzN?= =?utf-8?q?Wp7m/OkoPHv6aRDsZeqm7kq12hvjyIloozUQhJyZ5NYf8cUC+6JNA4KB1a+VebBmJ?= =?utf-8?q?m0gRNjGRtL056Z/p5NZa60nIT3YWMX91r8J9pxH97hO44N+XETESe+XPtXqkGgEbk?= =?utf-8?q?fVpyE7smIH9j36p8KQhKGF0vUlcz0LZCZRiToYkj/qh59Ccg6lWMrR1aU9z3Qdpxe?= =?utf-8?q?5JYbTKBQTzLRK/zUM0s/jOVRpo+69xGhE24YrQQVQW5TqW3EdmDGkanvNBUy8B0cS?= =?utf-8?q?NL5dBPMmBd5FLSLiaOoVQSxzfNjXWSRYdlq2KsqQiZJQpUY4tv/NSgx7F1gRENicx?= =?utf-8?q?4IjPinNzTKfG5J1B3DwQclK5DX13E8SJLzZ//riBzbipj7zPQJfK1pp/AMQDPDelQ?= =?utf-8?q?pGW5I8J9HFW3BU9lzk97FjVi0ttM9SkG73/6EXR1aiewlKfS8V9ovsQc/WPn16P0f?= =?utf-8?q?4pdwi8CEmKdZfkAsgFojdwyyH4qEnI1iVHXI2+sefMlZqo0keWVlQbYb+TXSu81U/?= =?utf-8?q?6kM2+qdp0sBMv5Ywdc+13tkYTF8saDIFEe4tz/3zs8nuZmJk13MhDjN2Bx+HJNIPD?= =?utf-8?q?CCtH99manHAWE8RarpXpTnLWQbGrGrULJY73JHWlXtXtaoy0hRHhTA2X4HVbP8+Oa?= =?utf-8?q?6s4QWaEgGI3LwZkaKs2n9pIN22sEpyqnWKffhc6E/fMwoqk7jE8uEgszRjBF5KC1G?= =?utf-8?q?HHxBEsxvO0uXnysgFLRvsYsRrWPp9Hr7N6eRktb/86VWR+M86WlVFfM7q3PgpiVrz?= =?utf-8?q?xSJQwj0Ipv67GWtbSnZH93pU7juywHhaTjm64/Vordmh9aIfx7g3zs/lzXbHqJ3wp?= =?utf-8?q?kIjjKAKibZ8pvqIwSkNyDJWAuuoeFdszVhbHVqS5V6zQmjPB+axkECeoPsv0ieoQG?= =?utf-8?q?F1CQGJl3FLBDbAqMOHnXu7T4J3NRowDYAegc5zSTD+HA5R1BDmCExaMYSZPbnGbaB?= =?utf-8?q?li11XNN0E8Ow4OH823gx4Gw1r9mjuNQAmLy6W61nSSzOuDlgtm7CGVSXF2mieQWQj?= =?utf-8?q?zNpemptssH2QDmp6rMXlylc6HWxk9tiCNpmd/5TmU/gl4X7brqx6zxrvHKEPPVNKY?= =?utf-8?q?Y00TPy075Okr8wFC0//opSbIhkDWYUk444q893aoeuJIgXPY7DF6sFkX7xel0KxYL?= =?utf-8?q?LsKFCz6Hw0FtqGrj8UT8mMKPC9VvsqzK16u9HfSpSBqiERmb30/e6yd/I6jvZzVsv?= =?utf-8?q?qQVPzdMhvuA4QWMGxa7IEY8f1vLJmce0X6wHJ+3h7wbPggjG6cf4AyjKg1inm2Ad3?= =?utf-8?q?7Yy+4jRJWGdURjt0HA2lJ2ucxLFJmagqu+vuypPnoQMcjqakWUtf/nKKZrwGvcS2V?= =?utf-8?q?LiDtnbGf2ybjpkmBAIPCP3fmQQTxPUTGBpF+nJnuqBtU/18SMnGVL1mEPzgmbcMb8?= =?utf-8?q?F92rc8EyCaqFVhIS0Ft4vqIJawfKLE0BiLWXcQRFo/qaQA5bhjxGlJoQ=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f214ace0-38a9-4e08-f870-08dce3e80835 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2024 20:14:49.0905 (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: RtealSHcvvDFkwYhNRVyuJU/y/8UzMhh7sfZvIrpUH0adq270tb1pd9qFREEaNeKuvGlCQKT4Apn7/5H61Tiyw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7481 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241003_131453_517611_DFFEDF31 X-CRM114-Status: GOOD ( 15.77 ) 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 Extend the address status bit to 4 and introduce the I3C_ADDR_SLOT_EXT_DESIRED macro to indicate that a device prefers a specific address. This is generally set by the 'assigned-address' in the device tree source (dts) file. ┌────┬─────────────┬───┬─────────┬───┐ │S/Sr│ 7'h7E RnW=0 │ACK│ ENTDAA │ T ├────┐ └────┴─────────────┴───┴─────────┴───┘ │ ┌─────────────────────────────────────────┘ │ ┌──┬─────────────┬───┬─────────────────┬────────────────┬───┬─────────┐ └─►│Sr│7'h7E RnW=1 │ACK│48bit UID BCR DCR│Assign 7bit Addr│PAR│ ACK/NACK│ └──┴─────────────┴───┴─────────────────┴────────────────┴───┴─────────┘ Some master controllers (such as HCI) need to prepare the entire above transaction before sending it out to the I3C bus. This means that a 7-bit dynamic address needs to be allocated before knowing the target device's UID information. However, some I3C targets may request specific addresses (called as "init_dyn_addr"), which is typically specified by the DT-'s assigned-address property. Lower addresses having higher IBI priority. If it is available, i3c_bus_get_free_addr() preferably return a free address that is not in the list of desired addresses (called as "init_dyn_addr"). This allows the device with the "init_dyn_addr" to switch to its "init_dyn_addr" when it hot-joins the I3C bus. Otherwise, if the "init_dyn_addr" is already in use by another I3C device, the target device will not be able to switch to its desired address. If the previous step fails, fallback returning one of the remaining unassigned address, regardless of its state in the desired list. Signed-off-by: Frank Li --- Change from v5 to v6 - fix version number, should start v5 - change to I3C_ADDR_SLOT_EXT_DESIRED - remove _ext function and direct use _mask function - rework commit message and comments according to Miquèl's feedback. - change mask type to u32 change from v3 to v4 - rewrite commit message and comment for i3c_bus_get_free_addr() --- drivers/i3c/master.c | 60 +++++++++++++++++++++++++++++++++++++++------- include/linux/i3c/master.h | 7 ++++-- 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index dcf8d23c5941a..68411f1cf80d6 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -345,7 +345,7 @@ const struct bus_type i3c_bus_type = { EXPORT_SYMBOL_GPL(i3c_bus_type); static enum i3c_addr_slot_status -i3c_bus_get_addr_slot_status(struct i3c_bus *bus, u16 addr) +i3c_bus_get_addr_slot_status_mask(struct i3c_bus *bus, u16 addr, u32 mask) { unsigned long status; int bitpos = addr * I3C_ADDR_SLOT_STATUS_BITS; @@ -356,11 +356,17 @@ i3c_bus_get_addr_slot_status(struct i3c_bus *bus, u16 addr) status = bus->addrslots[bitpos / BITS_PER_LONG]; status >>= bitpos % BITS_PER_LONG; - return status & I3C_ADDR_SLOT_STATUS_MASK; + return status & mask; } -static void i3c_bus_set_addr_slot_status(struct i3c_bus *bus, u16 addr, - enum i3c_addr_slot_status status) +static enum i3c_addr_slot_status +i3c_bus_get_addr_slot_status(struct i3c_bus *bus, u16 addr) +{ + return i3c_bus_get_addr_slot_status_mask(bus, addr, I3C_ADDR_SLOT_STATUS_MASK); +} + +static void i3c_bus_set_addr_slot_status_mask(struct i3c_bus *bus, u16 addr, + enum i3c_addr_slot_status status, u32 mask) { int bitpos = addr * I3C_ADDR_SLOT_STATUS_BITS; unsigned long *ptr; @@ -369,11 +375,16 @@ static void i3c_bus_set_addr_slot_status(struct i3c_bus *bus, u16 addr, return; ptr = bus->addrslots + (bitpos / BITS_PER_LONG); - *ptr &= ~((unsigned long)I3C_ADDR_SLOT_STATUS_MASK << - (bitpos % BITS_PER_LONG)); + *ptr &= ~((unsigned long)mask << (bitpos % BITS_PER_LONG)); *ptr |= (unsigned long)status << (bitpos % BITS_PER_LONG); } +static void i3c_bus_set_addr_slot_status(struct i3c_bus *bus, u16 addr, + enum i3c_addr_slot_status status) +{ + i3c_bus_set_addr_slot_status_mask(bus, addr, status, I3C_ADDR_SLOT_STATUS_MASK); +} + static bool i3c_bus_dev_addr_is_avail(struct i3c_bus *bus, u8 addr) { enum i3c_addr_slot_status status; @@ -383,11 +394,41 @@ static bool i3c_bus_dev_addr_is_avail(struct i3c_bus *bus, u8 addr) return status == I3C_ADDR_SLOT_FREE; } +/* + * ┌────┬─────────────┬───┬─────────┬───┐ + * │S/Sr│ 7'h7E RnW=0 │ACK│ ENTDAA │ T ├────┐ + * └────┴─────────────┴───┴─────────┴───┘ │ + * ┌─────────────────────────────────────────┘ + * │ ┌──┬─────────────┬───┬─────────────────┬────────────────┬───┬─────────┐ + * └─►│Sr│7'h7E RnW=1 │ACK│48bit UID BCR DCR│Assign 7bit Addr│PAR│ ACK/NACK│ + * └──┴─────────────┴───┴─────────────────┴────────────────┴───┴─────────┘ + * Some master controllers (such as HCI) need to prepare the entire above transaction before + * sending it out to the I3C bus. This means that a 7-bit dynamic address needs to be allocated + * before knowing the target device's UID information. + * + * However, some I3C targets may request specific addresses (called as "init_dyn_addr"), which is + * typically specified by the DT-'s assigned-address property. Lower addresses having higher IBI + * priority. If it is available, i3c_bus_get_free_addr() preferably return a free address that is + * not in the list of desired addresses (called as "init_dyn_addr"). This allows the device with + * the "init_dyn_addr" to switch to its "init_dyn_addr" when it hot-joins the I3C bus. Otherwise, + * if the "init_dyn_addr" is already in use by another I3C device, the target device will not be + * able to switch to its desired address. + * + * If the previous step fails, fallback returning one of the remaining unassigned address, + * regardless of its state in the desired list. + */ static int i3c_bus_get_free_addr(struct i3c_bus *bus, u8 start_addr) { enum i3c_addr_slot_status status; u8 addr; + for (addr = start_addr; addr < I3C_MAX_ADDR; addr++) { + status = i3c_bus_get_addr_slot_status_mask(bus, addr, + I3C_ADDR_SLOT_EXT_STATUS_MASK); + if (status == I3C_ADDR_SLOT_FREE) + return addr; + } + for (addr = start_addr; addr < I3C_MAX_ADDR; addr++) { status = i3c_bus_get_addr_slot_status(bus, addr); if (status == I3C_ADDR_SLOT_FREE) @@ -1918,9 +1959,10 @@ static int i3c_master_bus_init(struct i3c_master_controller *master) goto err_rstdaa; } - i3c_bus_set_addr_slot_status(&master->bus, - i3cboardinfo->init_dyn_addr, - I3C_ADDR_SLOT_I3C_DEV); + i3c_bus_set_addr_slot_status_mask(&master->bus, + i3cboardinfo->init_dyn_addr, + I3C_ADDR_SLOT_I3C_DEV | I3C_ADDR_SLOT_EXT_DESIRED, + I3C_ADDR_SLOT_EXT_STATUS_MASK); /* * Only try to create/attach devices that have a static diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h index 2100547b2d8d2..6e5328c6c6afd 100644 --- a/include/linux/i3c/master.h +++ b/include/linux/i3c/master.h @@ -298,7 +298,8 @@ enum i3c_open_drain_speed { * @I3C_ADDR_SLOT_I2C_DEV: address is assigned to an I2C device * @I3C_ADDR_SLOT_I3C_DEV: address is assigned to an I3C device * @I3C_ADDR_SLOT_STATUS_MASK: address slot mask - * + * @I3C_ADDR_SLOT_EXT_DESIRED: the bitmask represents addresses that are preferred by some devices, + * such as the "assigned-address" property in a device tree source. * On an I3C bus, addresses are assigned dynamically, and we need to know which * addresses are free to use and which ones are already assigned. * @@ -311,9 +312,11 @@ enum i3c_addr_slot_status { I3C_ADDR_SLOT_I2C_DEV, I3C_ADDR_SLOT_I3C_DEV, I3C_ADDR_SLOT_STATUS_MASK = 3, + I3C_ADDR_SLOT_EXT_STATUS_MASK = 7, + I3C_ADDR_SLOT_EXT_DESIRED = BIT(2), }; -#define I3C_ADDR_SLOT_STATUS_BITS 2 +#define I3C_ADDR_SLOT_STATUS_BITS 4 /** * struct i3c_bus - I3C bus object