From patchwork Tue Oct 8 15:18:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13826625 Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazon11011052.outbound.protection.outlook.com [52.101.65.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFF061E04B9 for ; Tue, 8 Oct 2024 15:18:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.65.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728400737; cv=fail; b=EN0sxEGrW91G2Gvcxl8Y/98xE3E2sa4XrGVCmI2sDRcmIiX4W0fisoxZ5PXlANW10HA4aXgYHNzVGqvQS/aJ4ghVw6On/kKIxyaS4QzsqwYXJO+EiDj6uzfdo4AmI8J0RvC0783va+H+wfGG0DGmKfYv9QcpOEVt1BA68DQL97g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728400737; c=relaxed/simple; bh=DM49R5v8+YMNDR9//TMHOLBKzBjtV69ySuusFjVM3qY=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=vAZOrXokIsqANpteRhQ2twXbpiFrpoHdByhg8yDpdI6Vm5pbiNR6cwuIXp0t3rGsdi8WjCFk5kQrYjez28bjNGfMaqp3h2TvyRjT5ElEt/mRC5UXxpSNvahpixu8MqPz2u281AP7ubGtF05sNbRz/YHykgIRIbI6X9LkZLfCoCY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=S0sc6oP+; arc=fail smtp.client-ip=52.101.65.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="S0sc6oP+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HGreRLiFMWsTP2plL6yEGXGK2OMRE/WOj5M4zmOfgrawzjqy9h/tKvFOHmsRarN4wzNjbUr3HwIr0vc54WEXJUJ1nMjmmCTTUv5gd9EHRFEcJM4qv68omoBYN5yAc+j7lUXVX9rxkUNTei8jmGCLtB2ntifBheRUHEaa1yf0pabExgKetgskufYIVGR0hMqIzAvBHP8oEyZ6I7n+3PCJMjN/1O0Sw98u506eDS3IFb0lXSn9pZeD93+qzaFSlB71MlsDDEkPLEGtf6v9Y9f3XEXNyMbf/g9el+Hoh4InEW8TObCo/3sSuHLxOfZNNsHDRZ8sCiwp7TObdhluz7Wf+g== 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=08TqXfMeHDz+1O9efCr97YY0qpO561DtJ9QcljgnDAw=; b=ARwXktwgsQdGZFloA04YHGUl17okMYFF2oyugjB+IO2o2xpBRw1I2aZDypsCTJyTRPw/e5ygmrNtY0Y8R37zyyifK7Ab8BCJe6t/Z5zrFWv+7fRf75g4BR4bOt7T361nRQ24r2xirLhJRC47V2r+fJWfxLmDzCbZPSY3bbW4rxWdcvdEKYsoiEHbpYFnCZFgENQZJtXTdUp3AtibZ63feeawCBEydQfbYckFz/SciJXxoqVFnCcTvRB5pfy4osM7j6ZTFz1uA5IryXLBu+wjrgiMt5249XpjpYvPliPvsvMieb/mctol0bxJpUik+yGlDu4UJeFdshskFU2LbkgJPA== 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=08TqXfMeHDz+1O9efCr97YY0qpO561DtJ9QcljgnDAw=; b=S0sc6oP+IiLDsmXL7w/UOdobBdHR2y3beiar0Hee0BJBRjAk36UriAGXAGU5Yik5xGybKXx0jPEa1KjtkNGNnfK7G10lcf5/sUbjsfoEuz3kPHLNzkeGoA/A0Wf7akDizIhNgKrflEoEXgDyg5vIoR/a8jdJFZ0k5claPReXE7h1blaO9sp3ea1Mb0GpeGjhg5bofOJ1MLZ4KGJ3TVdHIJ/gMSJFhc049tEeRKiHMzoY7Hp8ly7eNNR4hQlzpNYjySIokNKjbvosdS7xkEpyhjzyMCbaOHf9X+BFA6nsttealP6Cl/m2GUNdYJT//Ji9HNiKEJAIeMJh3dPq1IAEOQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB9PR04MB9626.eurprd04.prod.outlook.com (2603:10a6:10:309::18) by GV1PR04MB9151.eurprd04.prod.outlook.com (2603:10a6:150:26::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.16; Tue, 8 Oct 2024 15:18:50 +0000 Received: from DB9PR04MB9626.eurprd04.prod.outlook.com ([fe80::e81:b393:ebc5:bc3d]) by DB9PR04MB9626.eurprd04.prod.outlook.com ([fe80::e81:b393:ebc5:bc3d%3]) with mapi id 15.20.8026.019; Tue, 8 Oct 2024 15:18:50 +0000 From: Frank Li Date: Tue, 08 Oct 2024 11:18:25 -0400 Subject: [PATCH v7 2/3] i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_DESIRED Message-Id: <20241008-i3c_dts_assign-v7-2-96ec93d1f34c@nxp.com> References: <20241008-i3c_dts_assign-v7-0-96ec93d1f34c@nxp.com> In-Reply-To: <20241008-i3c_dts_assign-v7-0-96ec93d1f34c@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=1728400720; l=9439; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=DM49R5v8+YMNDR9//TMHOLBKzBjtV69ySuusFjVM3qY=; b=Y/5zhBvg8X6/Qsayadwo5NAKGThxoscxMRhH+p4wkb8KLg+9IwTPxgB5IvDzYkMViMwicvkBc aEgBOYryRubDxlAQ21oYyKlQGt/iMC68Szt/8mE1L4gZR772P74L46N X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR11CA0101.namprd11.prod.outlook.com (2603:10b6:a03:f4::42) To DB9PR04MB9626.eurprd04.prod.outlook.com (2603:10a6:10:309::18) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB9PR04MB9626:EE_|GV1PR04MB9151:EE_ X-MS-Office365-Filtering-Correlation-Id: 75433974-652d-4c6e-05ad-08dce7ac835c 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|52116014|7416014|366016|376014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?ezdfSS4DwvLSPgvFolJo7s92+fNslY2?= =?utf-8?q?iRdM1VE5lrjq4CtXZnG054c57a0aS1j1tdBUz+U/8cuB6gNbe0mNhHW3Qjb79MMFn?= =?utf-8?q?e/+8XbXJhySVwg4w6wW5x0H6uMcICZfK7jV2pfaILMH6ftRwb3T26LvqakWqdkfb8?= =?utf-8?q?Vitf40Fciwvd3Rr8qTWPdJDq4uGT7erwZCst0Q6yzcLDjXqfP6VzNFdyTIqPUJddD?= =?utf-8?q?DEPmK1eNqI10Qe34YSDr8F33Ka/QsEcttT7dQ2Msdw+RTtxtM1BQX6B9mwzs2C9jj?= =?utf-8?q?NzpbGqQYM+XzH79CjVVbV7g0zvm1GeG9NhSprAJ9q/DBccf47VmFDwgzGwqzW+Ak4?= =?utf-8?q?r2z6u1or6HLDjCBHMRUHg9GkhqesofktwKKfw5sNt0VvsV2F3iyeGxthl3G6VU2ak?= =?utf-8?q?i3NQJCZINZY4mQjqHJg0242nK9WLf0y1PGxXVPebx4FQIQEL/d6Uhoo7UKs/ml2rB?= =?utf-8?q?AXoPbG1hcINF+CpV8+n5SulJVKTdnOzEvDy4XI2fmkSeygyQ9qbgeTmS+5axSgpp/?= =?utf-8?q?lU4HiSfJfpRxER2MLjv97sUAMe8hLTLnDUhfWXcjXRDnwEeA/+LpG8CBhaa3uHduM?= =?utf-8?q?EPLXD1n3g03rdeywZHdZ7+iFvMk4SYcRC5u4m40k53BFt2EQhLGiu88zpGcajh90r?= =?utf-8?q?YYmU1UZHBnwulshRAaotf3Tal5uWHGfnzKzEw8ueQQK9OwlZp5sZTXlN+wQzBxfLo?= =?utf-8?q?LNj8wwgz1+JE7nZQWJ7w18T0M2tP/9eOg1xj0b6AA5M8GHYYoNifda3URVYlHXLE+?= =?utf-8?q?RC0qTk2tsi1OQb79E/ll9iEDSUU0SFC4p+d1bvh2DEBzsaEYmUM+//9srSGLHZvp/?= =?utf-8?q?ZnfvRBbHLm4r7F+C6JRAfRhpuDWkbjcpV8n10xFolyRymB4OK7pufOVwk7Mr1rcbA?= =?utf-8?q?umm06mzIYSaEMJspcxWI27hSS8EAQhCJGqx1MqCfA95uCiHpu4VrDdjNudzyO48xM?= =?utf-8?q?gPtrhQ0YvwRxbHSF6nozqtRUWwSHq/4vo28JHa1ohiFpJKDmHeaNDncsw0ipHynmc?= =?utf-8?q?iW44C+iZxum/r7CPXSGthcdFhcVAbTWYHhJA2ZhXG9sw9uNts3Y1dt7iNgvgbf+0G?= =?utf-8?q?ZaQyuL6eExJYAFlq6EkmV+IGOqv4rPqY1x9rzisxc1ij+s1DqxH0wOUdoQzOC+xvY?= =?utf-8?q?gGWF0yxBOSLwt1rq6+Z9fUzaX2OrBPreEDzyfLKGOMOHuT97IO+1Yp+jgi1wNEYva?= =?utf-8?q?MPCgX0khQL8qFENJGsPRMZYz8Lx592CHHV/t8F0Tnk2QOi/JRiplUbej/DVYCOp6O?= =?utf-8?q?0aIyqX0LiK3bE4ikIKB5KkVnF2HetedGpRw=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB9PR04MB9626.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(7416014)(366016)(376014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?wVl0Xv+1lTeGOq+snZbPbppAPMs6?= =?utf-8?q?asP+KPKrxAOL3Akewb+Am7gKKnIzCdZo/9i7gIrqlu64kOUbmzlWM/ByCNkk8A0oh?= =?utf-8?q?e5dGwBFPAof5lXpEqB5laSydOaWfZijTrOOsd6wAmEJsSnM6Mg9TXmPVHlB0DsOGR?= =?utf-8?q?ETVvE5isRSoffwCKBrs47/SsV54lbGu0xmqmlhaK7NUzakA/maZWoMgyuPC1hE5B9?= =?utf-8?q?aKc17t6UHewaHb5gTnKkb9VY/sdSTbpgYEEPZwFPuc44EZgn0vCw21enbsXHWfkCr?= =?utf-8?q?CnOxDdefdBNRvTZ0/eXguf0kfAZgKg/a24vG52m+dsL1IdsL4NQILg2vTd3VDIYHp?= =?utf-8?q?3xeRinmZH114t0MNsuZYSGB3lCrM3zAfn5RWHwMnhbkHAxXTnEBDVTIgoOz19ajR5?= =?utf-8?q?QPKhN5lR8vlBPvJrhR8N97iRkhVHSSWZFbgkys8eqAOOEnOJVYNc0ajQqXIQCG/vW?= =?utf-8?q?wjfD18rw8ddvQaEWLXC9lVb9R9CnN29e3pBm7IaNZ0WwqZFJWtWR/88Uo1PsJ1Cdi?= =?utf-8?q?SMYiYlBgZdZFPshTK7BP1QXummnyaN7S/0WHj2d/AHtTVD2QXoDuwbIfY76dikghz?= =?utf-8?q?kSbARRZw8A+4t1q5WkD7vJKdluKdifGg7ppFfVAoO4x6MkM+JoB39Q6ZWFnLmmJig?= =?utf-8?q?E2pXjhVs41AEOpeVrFpZaM4xI419QtoK+RSAZXg0cSj4EqjOYeQPEIbocrSbDYfO9?= =?utf-8?q?ru4XxWyB6qj5bH+PaV29wyFdepIfx4g8biUjGvRAJZgL6bnF1V9R3SLyMp5iKW8Dx?= =?utf-8?q?FnIaSYAs9dg17qP1kD0xo8OdQZrWe6M/cfWOlsV37Fm+E+wi5SXcVVBFnt/LfaFpg?= =?utf-8?q?AOnYOQlg3Snu4DTJh2larBaBjxJ6A1KGBIepkXaA4AiGXKRDewN5DkXBNI0FFhPA+?= =?utf-8?q?fH0hY9dwokPFqcbpB9FANlie3nel+Wj+tgFVj3xR3tw9XTieN/gb6k6lqTGIEjdTN?= =?utf-8?q?PDdO5qSD+iSi/5a8Iidwge+QXzHuVkhiGIYBfkrqgoOpxZWK7+p7lHct1dEtgai+c?= =?utf-8?q?0h1k/QF50KYAwcD+WrO0waIyc7ysQcxd3ZhXKLZKNy4W+Apx5DKNZSkm3AG/Gl/7u?= =?utf-8?q?/qj9TAs2uSa7IAqNO5e1e1o8jmHgUwV/vfQUfGEVIkkml3TbdQE/RgdSSHxwGrEJU?= =?utf-8?q?O85zxogVdQCDzpQh1+aNbFfnmnMxtmMnueTEbO860jUGlBoqwwHwRd+fyhnlbIleh?= =?utf-8?q?TC2J6oIWPK8kmR58k/UfszHCUWDCLpHEQ8wKoW8p1AuXhyW7hrI063ytPzcDDs0AG?= =?utf-8?q?J1KF3WDPkOkUFqM0LFFDh4MjcwBSHha4xWANvF9EBc7pw8sWFLquznVBc18IoHAUX?= =?utf-8?q?R5ep9pTdfGTbadXUVnmUNHgggJE5hOjz0rNmjpV12Zeyxj4H15ymSMTFPpo8LAbtI?= =?utf-8?q?0IjGWvD4m/FRI9LUgU7YAN/bOCYI7Nbj9WhvkeWyVJGbUh6wUW98thQOwfPkB1RjA?= =?utf-8?q?3jYnowLyMmAJXHHjz3YNg53X0I7Q+dl4Pc2KXddZsEIbXqk1hezK1LwU=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 75433974-652d-4c6e-05ad-08dce7ac835c X-MS-Exchange-CrossTenant-AuthSource: DB9PR04MB9626.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Oct 2024 15:18:50.4993 (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: Wbt7H1okrLvUtjQKUkve1STdF9THYaOShL/9FHvedbXdSQB81BuERBg7eRXqmtRwLybTqbePVKdlqXwg/0Fysg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB9151 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 v6 to v7 - always use i3c_bus_get_addr_slot_status_mask() in i3c_bus_get_free_addr - ((unsigned long)status & mask) in i3c_bus_set_addr_slot_status_mask() incase status bigger than mask; 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 | 65 ++++++++++++++++++++++++++++++++++++++-------- include/linux/i3c/master.h | 7 +++-- 2 files changed, 59 insertions(+), 13 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index dcf8d23c5941a..e0962a17de7f0 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,9 +375,14 @@ 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)status << (bitpos % BITS_PER_LONG); + *ptr &= ~((unsigned long)mask << (bitpos % BITS_PER_LONG)); + *ptr |= ((unsigned long)status & mask) << (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) @@ -383,13 +394,44 @@ 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(bus, 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_mask(bus, addr, + I3C_ADDR_SLOT_STATUS_MASK); if (status == I3C_ADDR_SLOT_FREE) return addr; } @@ -1918,9 +1960,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