From patchwork Wed Jan 10 17:52:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 761692 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2075.outbound.protection.outlook.com [40.107.20.75]) (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 B17E04EB2F; Wed, 10 Jan 2024 17:53:07 +0000 (UTC) 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 (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="AydPYmx4" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PklvnoS3eRrsuKI/oESu9ASvF0SwMBzWyeb8otH/UHKcVhcRp07y27niF9DIZsDHgdiLkwV4x8TdvQwQkW6qU1PvQZ0GTaaNj+rzMMOWCDyRGLuETpokdxH+0FVZOvxhW59UqkMrvAtzz+bqc8oZN0KKx4CDTl8HRBcXeKy3dqfUka9j9QoszxzncX4BnkfzJHDmJwEQsOEVTE19pEdtOU/tUwzD9EMIf66xtPGkOrLOMuIZ2nQQWPy532Wv1lCVIHrlIvbnMBsF7OL9mTw6HqlK+Bl69PrHgQOT5caYNgKr3VEUi4+KXriDYK4UGq4pb+mglEcJgKoXsW5p3lWkMQ== 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=TJqjdxYQGOe7eBpumvGxkqtfd0tBuGBzqxIW9xAyGlA=; b=ZAy3wLim8ufHRsRmEUn1GKrCdHVWOXbhgZyhvpdR1WrKTOSi5oU+RDi40naCcJOst3bYfVcJNbpKGG1E8PrnqYnREIuHeecO3ncud3rG+Y9lIHAuBgXTh7eIzThtWU0tLWvPd2zTfgYBdtkgZIc8pntiy3HSCg/CxUYhNtwC9p9QTVMrU5/OsVg+uJnlKNKaOtotSv3UqKpDfPIP2xx0EQnZDRqkWNt8SE8ARr4LCGjjRHrDdFRzudClyv5fMMjErS9poodh9ri7A8iOFuUxUlaSHghVOXOHFcD7Ts/+FBWmVUPoyOeD7qjjCBmzK++Lh2zUABdh//EyBBkLWaP0jQ== 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=TJqjdxYQGOe7eBpumvGxkqtfd0tBuGBzqxIW9xAyGlA=; b=AydPYmx4A5X2ZDRYJOXxrbgU2qv1jz04139w3vwKQm0oJY05ggkIVE68xmN0yxqOag/PwiGk8i4RT3bjnQrcjbu2v5uwl5eqUVxJ9zYuy1fELDLvlNRLWWo7quZgT0fxY8Tdiejsfs4v5U6HyGrwwhV/nUv7rPI/ulzmmueyEcQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB7511.eurprd04.prod.outlook.com (2603:10a6:20b:23f::5) by DB9PR04MB9332.eurprd04.prod.outlook.com (2603:10a6:10:36c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7181.17; Wed, 10 Jan 2024 17:53:05 +0000 Received: from AS8PR04MB7511.eurprd04.prod.outlook.com ([fe80::8ee3:bac5:a2da:d469]) by AS8PR04MB7511.eurprd04.prod.outlook.com ([fe80::8ee3:bac5:a2da:d469%4]) with mapi id 15.20.7159.020; Wed, 10 Jan 2024 17:53:04 +0000 From: Frank Li To: frank.li@nxp.com, robh@kernel.org Cc: alexandre.belloni@bootlin.com, conor.culhane@silvaco.com, gregkh@linuxfoundation.org, imx@lists.linux.dev, jirislaby@kernel.org, joe@perches.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, miquel.raynal@bootlin.com, zbigniew.lukwinski@linux.intel.com, devicetree@vger.kernel.org, krzysztof.kozlowski+dt@linaro.org, krzysztof.kozlowski@linaro.org Subject: [PATCH v2 6/7] i3c: add API i3c_dev_gettstatus_format1() to get target device status Date: Wed, 10 Jan 2024 12:52:20 -0500 Message-Id: <20240110175221.2335480-7-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240110175221.2335480-1-Frank.Li@nxp.com> References: <20240110175221.2335480-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR05CA0145.namprd05.prod.outlook.com (2603:10b6:a03:33d::30) To AS8PR04MB7511.eurprd04.prod.outlook.com (2603:10a6:20b:23f::5) 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: AS8PR04MB7511:EE_|DB9PR04MB9332:EE_ X-MS-Office365-Filtering-Correlation-Id: 1e8e635c-ab26-40a6-3c1c-08dc1204feec X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GByjKMOFA1gx6RQ7xxoLj2gQn5JOpGcPDrbRHVBEkME4/pi+5KV76pjtV2cmDGaM3lZ+KlMhayfMMoxGPT7ObLPX2qHKaqungrIyzdrxY+EqrBxNkvv/QZZMu+1KYZgY/Xie8Zegi8cIKlywZpfnZx3fgZ6RU8L/7Z75uqXYpbUaKCtokwEHuAnH+Xc5MIgPQ6pp0/lysJWRSmH/ll/iYHWmiE2u3962AopzHKFtLoyILSb8hb8mmlOd+aCNzImwagIza+t831EsMG6uWgckFZTtwxZdm2o0AsJ/75w2c3ohBZVbK5SyCc+UZt5iDtKzpRtNz7fcl/lFJSe1IBkyJzWav4d7BGQYw3BJ7U3pIxsG1sVcm/DXQJRBiUkDefqEdlhbbU25wt7VxoGfdtzZoWrwIRgJ3ZKvqdhDV8qxnH6JPCsP+MLM5ioHSAOJvbKWufZ322LE1/EOrgNZr5mF2qUhCu7dI9tV1ni7VPzFOkmOZ2ZHADENR0KsXfThgj7kwYTbBDWzjmWhnIjNd8Pg3l01zprDPelm5khWX/IG2KYXN1xz0UETE0ntXjLE8TDA8+L01uEICDHQ37Gui5DBQ9i+tcGjqvJXB6b1/kzkS6RpgDFr9G+p8gD4BdqHSuAM X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR04MB7511.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(39860400002)(366004)(346002)(396003)(136003)(376002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(6486002)(8676002)(8936002)(86362001)(5660300002)(4326008)(66556008)(66476007)(316002)(66946007)(7416002)(38350700005)(36756003)(2906002)(41300700001)(38100700002)(6512007)(52116002)(6666004)(83380400001)(6506007)(1076003)(26005)(2616005)(478600001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SXOxOmlXUOj6QMKGLXWkEMiPZwNlC6XPD81RsGvw7ZvpVQ4+FMgwFRKmtOXqWozUj2/4SmkF12p/hUK2+jKTN5PDdcs+SWE09YiZ/ne9GFHr60iPxU1VTSZJMNm1anCsIjWgI3LdmerlnBtGW8Yo1up7eq8yvlc84/YZ1SXZJ0KHH6vyYULLebIU2bQCy2WCyz7INL+xCJ/a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siFDeZuGoY+WNzFXiYSExaRkgT9rsEBjRqZI4h5Lk4pIEGNM+xOjqCN2BTj1u/pAKqeju4YmWZppEYvsLU88F916rq/B1x4E5zj+Fs6pHSj9lMlNAPoU4il61+RVpvU72xQv13V+0izy7Zv4VfT1/AESHK0Ozd6xtj/sfCr2+p/IWD3dJ/fnL5UxOzQhGSUukSvL6Ilt423nq4cnedhP36vFp2UBEwKB0DIW5f5qIJtb5h2kmvjxQxG+IyimBUiRlZSSp9rKMuK9F272Q3SVAmmNew0u+u/wlh6o= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1e8e635c-ab26-40a6-3c1c-08dc1204feec X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB7511.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jan 2024 17:53:04.7471 (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: DlXhbrcutyVNt88c8j/hgDrsrxwd2UHPuf53f5tnytENUt7YU3Hi1NoFn21yu2zFWY2ebH3sE25OReYUl5ws4w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9332 I3C standard 5.1.9.3.15 Get Device Status (GETSTATUS): Get request for one I3C Target Device to return its current status. Add API to fetch it with format1. Signed-off-by: Frank Li --- drivers/i3c/device.c | 24 ++++++++++++++++++++++++ drivers/i3c/internals.h | 1 + drivers/i3c/master.c | 26 ++++++++++++++++++++++++++ include/linux/i3c/device.h | 1 + 4 files changed, 52 insertions(+) diff --git a/drivers/i3c/device.c b/drivers/i3c/device.c index 1a6a8703dbc3a..aa26cf50ab9c6 100644 --- a/drivers/i3c/device.c +++ b/drivers/i3c/device.c @@ -196,6 +196,30 @@ void i3c_device_free_ibi(struct i3c_device *dev) } EXPORT_SYMBOL_GPL(i3c_device_free_ibi); +/** + * i3c_device_getstatus_format1() - Get device status with format 1. + * @dev: device for which you want to get status. + * @status: I3C status format 1 + * + * Return: 0 in case of success, a negative error core otherwise. + */ +int i3c_device_getstatus_format1(struct i3c_device *dev, u16 *status) +{ + int ret = -EINVAL; + + if (!status) + return -EINVAL; + + i3c_bus_normaluse_lock(dev->bus); + if (dev->desc) + ret = i3c_dev_getstatus_format1_locked(dev->desc, status); + + i3c_bus_normaluse_unlock(dev->bus); + + return ret; +} +EXPORT_SYMBOL_GPL(i3c_device_getstatus_format1); + /** * i3cdev_to_dev() - Returns the device embedded in @i3cdev * @i3cdev: I3C device diff --git a/drivers/i3c/internals.h b/drivers/i3c/internals.h index 908a807badaf9..976ad26ca79c2 100644 --- a/drivers/i3c/internals.h +++ b/drivers/i3c/internals.h @@ -24,4 +24,5 @@ int i3c_dev_enable_ibi_locked(struct i3c_dev_desc *dev); int i3c_dev_request_ibi_locked(struct i3c_dev_desc *dev, const struct i3c_ibi_setup *req); void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev); +int i3c_dev_getstatus_format1_locked(struct i3c_dev_desc *dev, u16 *status); #endif /* I3C_INTERNAL_H */ diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index d3b56c9f601e2..81611a3e3585a 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -2923,6 +2923,32 @@ void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev) dev->ibi = NULL; } +int i3c_dev_getstatus_format1_locked(struct i3c_dev_desc *dev, u16 *status) +{ + struct i3c_master_controller *master = i3c_dev_get_master(dev); + struct i3c_ccc_getstatus *format1; + struct i3c_ccc_cmd_dest dest; + struct i3c_ccc_cmd cmd; + int ret; + + format1 = i3c_ccc_cmd_dest_init(&dest, dev->info.dyn_addr, sizeof(*format1)); + if (!format1) + return -ENOMEM; + + i3c_ccc_cmd_init(&cmd, true, I3C_CCC_GETSTATUS, &dest, 1); + + ret = i3c_master_send_ccc_cmd_locked(master, &cmd); + if (ret) + goto out; + + *status = be16_to_cpu(format1->status); + +out: + i3c_ccc_cmd_dest_cleanup(&dest); + + return ret; +} + static int __init i3c_init(void) { int res; diff --git a/include/linux/i3c/device.h b/include/linux/i3c/device.h index ef6217da8253b..5f511bd400f11 100644 --- a/include/linux/i3c/device.h +++ b/include/linux/i3c/device.h @@ -345,4 +345,5 @@ void i3c_device_free_ibi(struct i3c_device *dev); int i3c_device_enable_ibi(struct i3c_device *dev); int i3c_device_disable_ibi(struct i3c_device *dev); +int i3c_device_getstatus_format1(struct i3c_device *dev, u16 *status); #endif /* I3C_DEV_H */