From patchwork Thu Nov 30 22:44:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 748955 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="HF4JB5zM" Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2049.outbound.protection.outlook.com [40.107.20.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CED9E133; Thu, 30 Nov 2023 14:44:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O1Tnr6CtkKJdDOMyZKLrx5RUMBKlZTUAkkqQ9R7PX7YdNopTkrdeuOD8iZfPUhk0G69ALWfKs0+vEZELGNs1LSg++Dp+EJfCoAbo6W6rFebFXYTCqJx/t8bp9kUvniDtTVsomZ4IputrlCIsY4K+m+nMPvcvesl0TbHirofLVKA/3qjRP5FwGJmdTaqDMKpZU9BNXggsdsuzxdePjGI7HBD3QvlANF46sjqymgn7hdvqP8Rnh1Qnp+xDblojuW8MXkgQGoc0gp/N6/DPB+qtRJZjL1tNNSpnRcGGuqZPcNf40f7E8ZTbTehoiLcSs4aaWjJ1xVOwZFfluGkDBn/vpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=piRRPE5LWefhXJGz8Zoeuo2aGktvTAfCXdTndUIkNMo=; b=HkVL368v8mxpgYDy/hf/xqExb9kVmohc0O1wieG5sdEl6EYiki5kINipEGZOiuE8IHv5qyukyqnxDaphMPZXvoZGTSfnVX8Az+7caneYbragLrAgUZlg1JxK4UdtNHvbwUKceL0xxqxkHqv5xsxk3tj7rndfhvRNmDwmCVwVN+LR/JtNRceAGAeAHIaz1T0sM6+Cfd0Vi7QC8YfW5ndP9CUXMzKYyUi4SZKFfkQXhOpPnT2Xdm/0rjM6lfwjRK5lDIm5Uz7Luo189LlwpfiVN1yQV+30FK5JAt4S9lkf6S13EDMeckfmbDmF9pPRrElNT7f79JYvLvwdacb3d4G8+Q== 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=piRRPE5LWefhXJGz8Zoeuo2aGktvTAfCXdTndUIkNMo=; b=HF4JB5zMU6MA03UyJTGBvokbvKrQNZ2twzXw7EUdq7f9y0vCi/r/gwrCZu7F8XCw0Cvl8fOOs4kmaLIJW+lEuqCrdnDbzTmIYQkuFzgstBvnWs/lz74HDZnqQXEYsx7kGHbb2Nm8JAxPwKtKF+Bq/MbzQbS+W3T/8FkJKW9It74= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) by AS8PR04MB8851.eurprd04.prod.outlook.com (2603:10a6:20b:42e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.13; Thu, 30 Nov 2023 22:44:31 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40%6]) with mapi id 15.20.7046.015; Thu, 30 Nov 2023 22:44:31 +0000 From: Frank Li To: miquel.raynal@bootlin.com Cc: Frank.li@nxp.com, alexandre.belloni@bootlin.com, conor.culhane@silvaco.com, imx@lists.linux.dev, joe@perches.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, zbigniew.lukwinski@linux.intel.com, gregkh@linuxfoundation.org, jirislaby@kernel.org, linux-serial@vger.kernel.org Subject: [PATCH v5 1/7] i3c: master: add enable(disable) hot join in sys entry Date: Thu, 30 Nov 2023 17:44:02 -0500 Message-Id: <20231130224408.3591288-2-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130224408.3591288-1-Frank.Li@nxp.com> References: <20231130224408.3591288-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR03CA0212.namprd03.prod.outlook.com (2603:10b6:a03:39f::7) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|AS8PR04MB8851:EE_ X-MS-Office365-Filtering-Correlation-Id: 4c0f1593-a1aa-4e26-54d7-08dbf1f5eaff X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H/IsMfOfLZG5xMjJGMeKRFFahLm+7Y9CbQ+CvSySgNCnVe6Vym7OpS4MfYaNgRFPQN9Gfna0w2fysNg2DrURvcKFst5LEmEbuA8H2kACtTK8H/9JpRh5o+iOUNbeXaC0JzoMiXoqvrPSmDLCiImw4NR3KqNXVlsIB+ZhKx8cpL7GEARfpdE7L2H0bodEBR5X8wp26rkz7Bd+B7Lc2B4/tuEMDCXBKjS90KXOMC7MlTqDZdMgcFHY8r+GNK0q8Vyc+uRO3E4Y6xCfcaETuZIoX0IFLfHsl1LQKt/YsFdK89dJRPiE6hpxSinOx7feJxKIwoeip91/QQ3rrfDHdUnG6sV0S9S4ILUgwhW76XDqklacE3hVoBQNEZqi17J/Gc+Z0X6zH+T0xFUcmqvjDvjYqsvSeOKm6Pu0mFUN0xnsMTFVn8+tsdNes9Ukqm4UI/0DK7WQ/U3D5xhg0lTPICZ9jmZS/izlMNI7EC6bBZAXY+r2y3OfDFDb0XeiLGUaF56bm+/ql16PBUSUkb3Ph3JHvtjZi7yM7A4qCWPenQbio63tuvktAUdyoJpF5dy0IXnu1mPAnVw62eyYNeJ2CY6hLzwSM1O1FHDMztEOdnal3sshX+LT3XK9nWtDbUgie0kFMnQVjctYKSn1maSj2oR1qPRamxGwPw0s+dQ38NHPHNE= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR04MB4838.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(346002)(39860400002)(396003)(136003)(366004)(376002)(230922051799003)(451199024)(1800799012)(186009)(64100799003)(86362001)(6512007)(5660300002)(36756003)(41300700001)(6506007)(38350700005)(8676002)(52116002)(478600001)(2906002)(6486002)(6666004)(26005)(83380400001)(7416002)(2616005)(1076003)(4326008)(8936002)(66946007)(6916009)(66476007)(66556008)(38100700002)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Fyz3Wr0E6CxghMhdQtxaErEpN4Xq9xRk9ASI7wEE72sVXSOGANvD23vH4KREOjSvuqW2Pb9XLET95CtfNXSzya5z7bGmRRGhecDGeFI9jkU0tdzUbQoWqgnVJga67E0SVE8Nj1RdNYzWWWNLGIcS5lORxDhFcfTNdlaMHfg8F2oF0Je1A/G3yBjxjQdzfF77FWFNUDuGu1Ue6J8GtzXTlm0x9sZezUb2jyphD5kDx1CoFNw+/QTLtMJzqzZ0ulmLZCsscP3CV0en7i04A+Pg28DiB2xdWaQLmHYKY1huwzZXYKSfRknU4c1nBhZ3YnP+KbRvsdfb4Xew7GrMygqiBRpBvY45kL+NPbCcXaIDiygvjAsqZar8VLQLU0UpeKQE4V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IzYSNk9/PB919ixqVj79UAdQQ5fuENc8jcFtrY5CEFdd3wPVDjypm/yOxVFr9sN7u2rhMvnWolQPyWYA7swxOp/Ls6yvVEJJd+lI6KZ+2J9mq7SCeLVOyHK1nYj6vvi7Kd9xv6wA3BKt34 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4c0f1593-a1aa-4e26-54d7-08dbf1f5eaff X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2023 22:44:31.6465 (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: Fusjs34tGb2zGU9D/kHIBWBsU7uEp+GlIVIdxks3DOuXRazXygNhmz/GDu3xuTnGMfZRJiopjJhZIyyCC/2Dcw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8851 Add hotjoin entry in sys file system allow user enable/disable hotjoin feature. Add (*enable(disable)_hotjoin)() to i3c_master_controller_ops. Add api i3c_master_enable(disable)_hotjoin(); Signed-off-by: Frank Li --- Notes: Change from v4 to v5 - using kstrtobool() > + if (!master || > + !master->ops || > + !master->ops->enable_hotjoin || > + !master->ops->disable_hotjoin > + ) break into two if, which will be more clear. and one line is 101 chars. Change from v3 to v4 -none Change from v1 to v2. - Hotjoin control by sys entry, default enable hotjoin, which standard i3c feature, user can disable by echo 0 > /sys/bus/i3c/i3c-0/hotjoin drivers/i3c/master.c | 83 ++++++++++++++++++++++++++++++++++++++ include/linux/i3c/master.h | 5 +++ 2 files changed, 88 insertions(+) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 08aeb69a78003..d3b56c9f601e2 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -526,6 +526,88 @@ static ssize_t i2c_scl_frequency_show(struct device *dev, } static DEVICE_ATTR_RO(i2c_scl_frequency); +static int i3c_set_hotjoin(struct i3c_master_controller *master, bool enable) +{ + int ret; + + if (!master || !master->ops) + return -EINVAL; + + if (!master->ops->enable_hotjoin || !master->ops->disable_hotjoin) + return -EINVAL; + + i3c_bus_normaluse_lock(&master->bus); + + if (enable) + ret = master->ops->enable_hotjoin(master); + else + ret = master->ops->disable_hotjoin(master); + + master->hotjoin = enable; + + i3c_bus_normaluse_unlock(&master->bus); + + return ret; +} + +static ssize_t hotjoin_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i3c_bus *i3cbus = dev_to_i3cbus(dev); + int ret; + bool res; + + if (!i3cbus->cur_master) + return -EINVAL; + + if (kstrtobool(buf, &res)) + return -EINVAL; + + ret = i3c_set_hotjoin(i3cbus->cur_master->common.master, res); + if (ret) + return ret; + + return count; +} + +/* + * i3c_master_enable_hotjoin - Enable hotjoin + * @master: I3C master object + * + * Return: a 0 in case of success, an negative error code otherwise. + */ +int i3c_master_enable_hotjoin(struct i3c_master_controller *master) +{ + return i3c_set_hotjoin(master, true); +} +EXPORT_SYMBOL_GPL(i3c_master_enable_hotjoin); + +/* + * i3c_master_disable_hotjoin - Disable hotjoin + * @master: I3C master object + * + * Return: a 0 in case of success, an negative error code otherwise. + */ +int i3c_master_disable_hotjoin(struct i3c_master_controller *master) +{ + return i3c_set_hotjoin(master, false); +} +EXPORT_SYMBOL_GPL(i3c_master_disable_hotjoin); + +static ssize_t hotjoin_show(struct device *dev, struct device_attribute *da, char *buf) +{ + struct i3c_bus *i3cbus = dev_to_i3cbus(dev); + ssize_t ret; + + i3c_bus_normaluse_lock(i3cbus); + ret = sysfs_emit(buf, "%d\n", i3cbus->cur_master->common.master->hotjoin); + i3c_bus_normaluse_unlock(i3cbus); + + return ret; +} + +static DEVICE_ATTR_RW(hotjoin); + static struct attribute *i3c_masterdev_attrs[] = { &dev_attr_mode.attr, &dev_attr_current_master.attr, @@ -536,6 +618,7 @@ static struct attribute *i3c_masterdev_attrs[] = { &dev_attr_pid.attr, &dev_attr_dynamic_address.attr, &dev_attr_hdrcap.attr, + &dev_attr_hotjoin.attr, NULL, }; ATTRIBUTE_GROUPS(i3c_masterdev); diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h index 0b52da4f23467..65b8965968af2 100644 --- a/include/linux/i3c/master.h +++ b/include/linux/i3c/master.h @@ -452,6 +452,8 @@ struct i3c_master_controller_ops { int (*disable_ibi)(struct i3c_dev_desc *dev); void (*recycle_ibi_slot)(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot); + int (*enable_hotjoin)(struct i3c_master_controller *master); + int (*disable_hotjoin)(struct i3c_master_controller *master); }; /** @@ -487,6 +489,7 @@ struct i3c_master_controller { const struct i3c_master_controller_ops *ops; unsigned int secondary : 1; unsigned int init_done : 1; + unsigned int hotjoin: 1; struct { struct list_head i3c; struct list_head i2c; @@ -543,6 +546,8 @@ int i3c_master_register(struct i3c_master_controller *master, const struct i3c_master_controller_ops *ops, bool secondary); void i3c_master_unregister(struct i3c_master_controller *master); +int i3c_master_enable_hotjoin(struct i3c_master_controller *master); +int i3c_master_disable_hotjoin(struct i3c_master_controller *master); /** * i3c_dev_get_master_data() - get master private data attached to an I3C