From patchwork Tue Oct 1 17:08:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13818566 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2084.outbound.protection.outlook.com [40.107.21.84]) (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 BD4F71CC143 for ; Tue, 1 Oct 2024 17:08:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.84 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727802542; cv=fail; b=kThWt3Z+eigJCc9PgJrV6LagyQdMpq8i226M4tSfZE2mEPseaTH7nt56mRWxXmTCHq4usIX+dKeJEfVY0oLrqElu/kHd8msJn8wRYd6k30fqBUGMBbtLjpgAbkSkprHy8fPmqARIpEsFlUTmQrG+j0lR1/0q6ehsAQwHco8YAcY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727802542; c=relaxed/simple; bh=/mHi0IGhvDETCcr1sx1Tpq46kysDKfA0S20VyM9YTjA=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=ch+Cq9E4BYNr9qWpcRlApUsodHbrI7iLlyva3CCwz2SSihr8RYn66W63GxttzxA6/YG/NBQspAZ815tF1RkyayI3tx11UwFYkTu8xuLbFJXmSYG8rqfODrorp+fvhbRvuwQYiDD8K7XKihJiEvJW+b/c2GhyAE+R8F8cKE9ZmwI= 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=U6bBRUJ/; arc=fail smtp.client-ip=40.107.21.84 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="U6bBRUJ/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LbyPYjllrQn0tzoZNPdd2YZyJvZhgIc4r2D+hgkKhjDl48CCvVV1RMwG0SGOTbNTthJoNifXgYwkjvvH2XME8tA7T0nAXJVk9b/txNJTy3uAiz7jRXTEf+FbGGAQe32ZxkDYsZliF95xCxfhHuO3Cygzm6j7Hcc4Kqg4Zb2aDiix72pkJ1m4ARMS6gHcWDlainIm1aJ2etWFn9hrJiOAxS5Y8doptneeB9HIC+QL9ZLy4MlfYQ2rRncMDQ3ASkWpkpd680yRJLy7M0HbmW0VP7iWuFcSFOibgwTrGIt7dp3VWiswUenqJSavd1rlKtJyuoKSV6FuttHZGSl3zphqKQ== 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=r63hJtAXg34VgEEJLPki9brRwE37eXOv9n6xTXTxe6Q=; b=zNO8b6vIIYQOOaCVdx7OMt9vmdeEH08GAF7eKbAgXtwbpJbOLowyrwHm9I6MjyIMqmR8ecNe8kIJ2EWi/6HRfSI9av5F4MgZ3ysmDt77M0Y42P8xhx+eFvKsfd8AckAdf8ASBVziolyBckojzqi9JZHxlzHbitEBqh+8VpwYY8n6fIHHrVxuAinDT3kh5Qv8N9b6CMjHSHF4G5U5PvQ1xKSAAS9EmD4OZ4qmKS6EXAryk02UOm2nOmMZMIKk3JRaozbL4Nm6QKIyzF1bNu6i7QoBjiXR/Ctudj0aU6Z5JN4FEsq62m9EjlwojB8o9M8YvtCe1utQwKlBdweOxL3jiw== 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=r63hJtAXg34VgEEJLPki9brRwE37eXOv9n6xTXTxe6Q=; b=U6bBRUJ/h0ZhoIGWUs36JPMAXRkNQXKYU5G4blOmo2mSM0RMHSImtmSRZN2TV6CoX/Af0mgD7e/iksF4c/MON8SMsW7nM4rDK9o9/1j47KDTAFNW8fqMCIxxbl9a00vmxHZPG3J+0Ar45nao6wcHvEy4r8Rjzy/9/3i+ecGjfuOhbQOTaB2VgB+7Vh1SVudapstK+bZ/h/9XCsB0SyTPHuMFkAJd3dEd3r+nRXSPr0duT925QQtEP66U1g5uojkC/ay/kZ8yiFbUwXCSU3ycgg3lMUCsS9LUCYhbq9xyh6T+o5cNnNRNMro9aswuGrCS82wFMj6m68TdqyIqPIw+zw== 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 PA4PR04MB9710.eurprd04.prod.outlook.com (2603:10a6:102:268::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.15; Tue, 1 Oct 2024 17:08:56 +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.8005.024; Tue, 1 Oct 2024 17:08:56 +0000 From: Frank Li Date: Tue, 01 Oct 2024 13:08:21 -0400 Subject: [PATCH 2/3] i3c: master: Extend address status bit to 4 and add I3C_ADDR_SLOT_EXT_INIT Message-Id: <20241001-i3c_dts_assign-v1-2-6ba83dc15eb8@nxp.com> References: <20241001-i3c_dts_assign-v1-0-6ba83dc15eb8@nxp.com> In-Reply-To: <20241001-i3c_dts_assign-v1-0-6ba83dc15eb8@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=1727802526; l=9456; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=/mHi0IGhvDETCcr1sx1Tpq46kysDKfA0S20VyM9YTjA=; b=y90JXxQcloUIJ5ejLwIdojh+Jt7Upysp0mxEU+izogT4hkQ3H9XOiSCFxEazT4oFCSs9C0Qt6 e8HHIApOAsLDR5/fCL+B7eo+zH60AuGAqFD4u7R0WfRm6Hs9b4P5YOK X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR03CA0007.namprd03.prod.outlook.com (2603:10b6:a03:33a::12) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) 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: PAXPR04MB9642:EE_|PA4PR04MB9710:EE_ X-MS-Office365-Filtering-Correlation-Id: 6c01a988-db29-4a5f-3f1a-08dce23bbbd4 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|376014|7416014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?5JRBWAoOsplFBsNuc2CDNp8g/1R9xQH?= =?utf-8?q?94DvNcHlhK0vJN6q+tmTbjZWArNgHChWy/s9KGW3I0TBja0oT4EnjhuCNptXSYVoK?= =?utf-8?q?jG3wm82x3KyAX4moNO46f1eaxm47hFgbEYEhjwgUNZjR6PaRCITNJfaxtJvNEKYxD?= =?utf-8?q?ID64fYGICbghB/cXetbsHbqkDMykIwa1Kvcg7s5QBJzcj/kA7UOt3SvLryxlHi8mO?= =?utf-8?q?P4B3L8c5H2TDKhNw9mwU2fbuTgyEiNYrPUDXik+QLK53vCq6mXc+eG3TnBD+Zenrg?= =?utf-8?q?1BXFIPLoiT7jMS033iZ9lmr7p9JkZnC9SVmsc9T1FcFbi7UpaYMuS+/wFP2ZMvxDV?= =?utf-8?q?14WtDRJCWvTuMZV09PJl38Owq05qJRqxhFsI1Ape9QD68srXmn3hfk9bgP1x3mAux?= =?utf-8?q?hPdj/gFJfTiNdgwhIzqlskZaIiIbG+GFEXkrW/M52w+nfucwgvuehmVTVS6eQTtJl?= =?utf-8?q?aRvXeJRty7ejqRYJw8SJSWgwIMiGUoo42adBdfJOUymW7voYGV7Jg9uZIfZiGp6rW?= =?utf-8?q?TgejjYhIXeuNtqgam0v8T7qNuC39P1QAsfn97pKVPPatoOIboq1n9VkCJO0pI6pQN?= =?utf-8?q?TUJgoUuC4ayIVwkH10UToOQ34hiuvADaoPLeNb/SHcR8iaWrIKcZsXgcEU0oO9wyI?= =?utf-8?q?99Wn76jRPlwLkZb3XuuVEooDXJ9kg3w/zATxaEi53nc89UX1OwaJMHZCL6OibU2zB?= =?utf-8?q?jb9P4iDMbGfsLoTZW81d87C1aJE9ZDebWu/Yvz/mFcUON/Jp8FN3BADiMNdCSCcLU?= =?utf-8?q?vH0NyCEKq0BliKWHEHzpJ21iqUrqobMu6jLl5beKTQeM1QtQLmskTSYBL6m0GaO2e?= =?utf-8?q?i9DpODY8118fJtIj7F/5W4bQC7n8N0NKlYgHJiAQFPZJwXgN7441QyKPJTMVTJPcP?= =?utf-8?q?sQQu6vmwaVuqc5pdfKRy2JmTG+OKhGMUAgt+gkeMxCoIdCPDNXeex6LahsBnu+pw8?= =?utf-8?q?vzkvYpCpywKXkVl9Z971z38eobUNAx6+x4pOXWVdsqUOj3nIM4sUpZ3nyMEpmcnTS?= =?utf-8?q?5P2Quffxa3auDm0PofaRloXz4sVWYYMLYtl/JRhH3AVQlIz46OfZmPppAOG0aNYys?= =?utf-8?q?DdSCrtfoxQGRCaV2s6seKLBMabPgWprsdWbH9t5vWvTEucI5QtOY4Ttu8yHmoZU+f?= =?utf-8?q?IHQcJVkHnyJx02xasfEmIWxeHU+3iPm11Wcqcj40bxIFJsONmT7YYGQ+Hb6D1SVp4?= =?utf-8?q?FrGf3UgpRKhJnWxG8qQS6dlL8jSUvUGJ5Qrts48QI6W+d9CN+0MjsLEmdK3ug2Msp?= =?utf-8?q?ls7ocPhBkvzO2fIMqxsRaQ1sYqKWLoU+wfBq25qdqwaHwbovqy3sr+7Vf6OPilKih?= =?utf-8?q?L1L6aK1tbWTSc1MJu8vnW8BhhpK7I4QDGQ=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)(376014)(7416014)(52116014)(366016)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?i9Qs0/t/OhNtr56lokhrqVIGi7X4?= =?utf-8?q?1WQSJZTf4LVJKyUPipVj7LyslLKvjBnfNMhWpWc3rqYRXX937RL/mnZnch/QqDcNX?= =?utf-8?q?EfRvffkb2UQg3xFfQUvzL45zHhoc6/6MdLxlV3xyZ6og79cGS5uudDiYvuG9zZ+lV?= =?utf-8?q?qwJdRcM15dNzhmYe8cAx93IWaTEU9fhDhkHZKKGIV1fIpL3hQsVu7DEot9Z6tYLDo?= =?utf-8?q?kT9CholI97Jt1dxydaPVmE9lUq4/tIugWh0AZ33cSJuCONhc/kHy2fjru/Z2FP9BB?= =?utf-8?q?g1f0FQueEEltxGfomA+I0mAPTAITzw9DOpWuczLPqGXiT63YCXhlc92jhHAA+KbPF?= =?utf-8?q?vHuDqwvoZZnxlP33uhh9p2UgbVS9VP1jBlOfZYBsGa1DlI8WMMuLWY6z0vJu0TcUW?= =?utf-8?q?9zD68PY/GpnHCnvHSF7w/gOwfaWQMp3SsJITlNwWXFRagplLTt1kKIc6p/kYc4YvV?= =?utf-8?q?pvS0G/GQ6oYcw8Y8bd4zGqjeeEypyW4fmo7/LF60EHTitrOlpo47mu7lJnQ7krGOH?= =?utf-8?q?p2xY7+QCn5y4borbdqEyiLliZAYgwxRPtx2ktlbfC/475vOD0uhOCwQUnehV/72D8?= =?utf-8?q?WJMkqWlLayRgtPUrsggfr2zDDGyV5e5xkSyRcGGTKpdCZ9PAcR/dm2Dtwl9BgkoL2?= =?utf-8?q?KF9OWa8tQmiFIzH8vQFA0I9R8u8B6Af5a9cRWK2EUSQ68y4QTAkjWMG2g8gKeDqEQ?= =?utf-8?q?Cejbqp96xkJRET0Wl2Q19IeUsqsKSoVs6Pxzmpck2GuQwSHzBwPyvE+AJgiyRnNUD?= =?utf-8?q?aByV5kr0jH3uehNOIgkNHH25vGwIcWBqxR4AZriV20T8ZGpy8uQtXncP1KkWmDMzG?= =?utf-8?q?iGdVeeA5LU2cPbCaa+Gh8DeFrn6oh/9uSPSMr4nhHrmpGNgSPL4q31Pp/uy1OKxrK?= =?utf-8?q?/7I54D9hof26UJL+VsqcrcbNZi0m2sMY6eW/ULKc553kzZghPKEgliX09olOa4L9K?= =?utf-8?q?nrXTe6AWb+vNPaf3A7DkIH8WRH1XnfawqyjcAueam+u8XksuNJ4Q3rADBVVv5O+Oh?= =?utf-8?q?S7RO8yfjWrBjjqTat7yFsiJKmonSGM+OUp7hoSPwnCnak/loXDnT+QElG29vSxr9h?= =?utf-8?q?i9ugrAqrGdKM5UnUAemCLQ1uJfvKWk8B9VgDKiV2O8r0Rmj96Ncg+JYXyaizh7E/v?= =?utf-8?q?XxRjVDtFHG2doDJgd80fYgeK56sK51BeQsocg1YFPjcUFgUA3dnhYeZS71VUIRL0F?= =?utf-8?q?Ytnt2pwrjhUJ0qJhMBrXoh2Zh/ppo+cZLWdcd/dBG+VqbACI7agWRulMlcctqVzBx?= =?utf-8?q?ScGBu2NT++Vr5pJ5HtX/uQlgbfIeEMW+i6rdA7TOFlqaO+UhbUZa3Nd59wy7k/dzp?= =?utf-8?q?WB+nfqRku83frSppu4ftbm/lHiblTBRAiJHqKEhZs722XbxsAf8fIGubUl5jmUL3l?= =?utf-8?q?IV6EjP85r9PjJZ59sRZKaesWuHUpluA80mVmcSYkgku6BQmabAPzkALqiCNk5CJGt?= =?utf-8?q?+v/bgW1NKDADn0Jx9YqSjEBmjwer0CHPGPkPKjbjxV/hhtHccEGp8p+/wyhtYX7KP?= =?utf-8?q?QDogTg5suBk0?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6c01a988-db29-4a5f-3f1a-08dce23bbbd4 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2024 17:08:56.2788 (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: 8LAI+V/8CMcsQSf61t+tPEBvjB5P0ArLon33mQnlruYUV+rGjS88dWKfaWI49OPVRup6g6RPjZdX+gaKj1S4Cg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9710 Extend the address status bit to 4 and introduce the I3C_ADDR_SLOT_EXT_INIT 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 want a specific address (called as "init_dyn_addr"), which is typically specified by the DT's assigned-address property. (Lower addresses have higher IBI priority, and the target can adjust this by using the assigned-address property if using DT). The function i3c_master_add_i3c_dev_locked() will switch to this "init_dyn_addr" if it is not in use. Therefore, i3c_bus_get_free_addr() should return a free address that has not been claimed by any target devices as "init_dyn_addr" (indicated by I3C_ADDR_SLOT_EXT_INIT). 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 all of above address are already used, i3c_bus_get_free_addr() return one from the claimed as init_dyn_addr and free address slot. This ensures support devices as much as possible. Signed-off-by: Frank Li --- change from v3 to v4 - rewrite commit message and comment for i3c_bus_get_free_addr() --- drivers/i3c/master.c | 68 ++++++++++++++++++++++++++++++++++++++++------ include/linux/i3c/master.h | 7 +++-- 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index dcf8d23c5941a..a56cb281e6b6d 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_ext(struct i3c_bus *bus, u16 addr) { 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 & I3C_ADDR_SLOT_EXT_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_ext(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, int mask) { int bitpos = addr * I3C_ADDR_SLOT_STATUS_BITS; unsigned long *ptr; @@ -369,11 +375,22 @@ 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 void i3c_bus_set_addr_slot_status_ext(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_EXT_STATUS_MASK); +} + static bool i3c_bus_dev_addr_is_avail(struct i3c_bus *bus, u8 addr) { enum i3c_addr_slot_status status; @@ -383,11 +400,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 want a specific address (called as "init_dyn_addr"), which is + * typically specified by the DT's assigned-address property. (Lower addresses have higher IBI + * priority, and the target can adjust this by using the assigned-address property if using DT). + * The function i3c_master_add_i3c_dev_locked() will switch to this "init_dyn_addr" if it is not + * in use. + * + * Therefore, i3c_bus_get_free_addr() should return a free address that has not been claimed by any + * target devices 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 all of above address are already used, i3c_bus_get_free_addr() return one from the claimed as + * init_dyn_addr and free address slot. This ensures support devices as much as possible. + */ 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_ext(bus, addr); + 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 +1968,9 @@ 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_ext(&master->bus, + i3cboardinfo->init_dyn_addr, + I3C_ADDR_SLOT_I3C_DEV | I3C_ADDR_SLOT_EXT_INIT); /* * 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..57ad6044ac856 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_INIT: the bitmask represents addresses that are preferred by some devices, + * such as the "assigned-address" property in a device tree source (DTS). * 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_INIT = BIT(2), }; -#define I3C_ADDR_SLOT_STATUS_BITS 2 +#define I3C_ADDR_SLOT_STATUS_BITS 4 /** * struct i3c_bus - I3C bus object