From patchwork Wed Jul 31 12:56:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan (OSS)" X-Patchwork-Id: 13748717 Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazon11012060.outbound.protection.outlook.com [52.101.66.60]) (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 C8F601B012D; Wed, 31 Jul 2024 12:47:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.66.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722430055; cv=fail; b=t9Z6VYrNE7de+yriyd2gJdkozOmWIBMvIQHMaZL0chBGRz6IDNtRXDgUOjBYjR1ixBX4S/UU+iaYSkPM0BqpcxoLOcQGnGM5D+S/atrwC01rpKFIKe2gh5lhnf1KKgeO1QdgXuTsBdX4U0VrbrUD5eCQg/l9jZLApdjHhp6xzt4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722430055; c=relaxed/simple; bh=3ZrXc7dyEXDQLmXy4+anzWutGGiAYR2nUe71CkcL+bs=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=lz7cDkWY+3moC4pps1+//Pt9ODnSub9io9z0i49mw5FwQjWFHF0ka/pydqI6D8BIZ+Z+zMNh1zJFh6U4PqT/gZVEdV4J0d9HFFQmd95f2VaXYN2GwZlkmpk3Nyruj6l+gsn9Es9wmONxsIHq8vrHX6LXr0gmIQGXZUBODKb9Wgc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com; spf=pass smtp.mailfrom=oss.nxp.com; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b=OFxN+QYo; arc=fail smtp.client-ip=52.101.66.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="OFxN+QYo" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EvreRyHwOwpQxxLHHabqWj0e7A0Wlt0HLBW/LfWCkLRK2ao7t/run0F8zny7s9le0KHN4G2KLJlT9une+TMRu8AI85CqIBaO3VSxaIEFzkW6+q38+fcz2gcj6h2GmTDagO+c1zurE9RrGstwCAbHS24JNlrJeY8yvCNU08fZBLXLygFVIikjG191BU828S2rWQ1FtHLbBdvzNzTirotibfDStBjTYDgaE8OkrFv4Ts9z2JFyDogMh9p8EwMOA18RU0HpZ8q0Z5+Uvi3fSfiZD0289QdR8MJ6azy+UiDWIaCHwZWEuvJF8UIAqeAc3Vg7/WEKxCGaV8BTUEHKwSZWrg== 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=b3D20n0bAzqcjLjXnBhoWSF/wj8T59kOpyVPxkul4Tg=; b=coe86apywIRM5mXjSQHKVBf6iQremFYXPcGB+zOoGtxiXqTun7F8AHAcQfI+aaTARrsxMdtOA5nBnkfh+iWb5d0ze6SzcbiQ8gepH67cBNO1fEldW0w6Tg6ugE5rmvdifytHhdy64GgxBzZWloM9ElmKWbMbbKpIbfu07eOxR/Vc8/xDMXvStrNNU0iwlzIzTdnw0IgrWdHEnaK+Sn7JRVG30yXUYqhhJwzGvqrQU4ZHL123nvpVv20ipJBVYuVZ/UZR8VoGqSPQdaE0lUX5wZECrPz+ubSAY+YVTGm6N1u/IcX8FtHqCGa7F53uwsKTswaiZDM0JFzZ6PW6QZ/SUg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=b3D20n0bAzqcjLjXnBhoWSF/wj8T59kOpyVPxkul4Tg=; b=OFxN+QYofMuH1qJsLgZdlliuwdlbjR1n+XTEcxkD699vWA1M2g4aSgUCCLEzUC86cP4vcQ8Q3p+zKYj0H0glLJETvbEqpIVjKp5cFLAKfkKGJE/7Vdq6EU9CdgWetvPf/VTyc9oKwKr4Et5DyfOhtgehfdskYCpFBBFE2K6kxAVRZo7/hkMOVtg0fn1Ue68+aLwnP5I+iXr1fkkJh9c9gyOuzXUYTsXbyacq2MtPdn8uoOammXuXptEhS7QKEVIQsmcA+rNQR6zNoSLmnczRfX7jnHjt/KMcClGF9fto5aB+imtIDpECom4UBXENauq7s7DSCZ+g6Qd2v7/1meR73w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) by AS8PR04MB7735.eurprd04.prod.outlook.com (2603:10a6:20b:2a5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.19; Wed, 31 Jul 2024 12:47:29 +0000 Received: from PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630]) by PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630%4]) with mapi id 15.20.7784.020; Wed, 31 Jul 2024 12:47:29 +0000 From: "Peng Fan (OSS)" Date: Wed, 31 Jul 2024 20:56:07 +0800 Subject: [PATCH v7 3/7] firmware: arm_scmi: add initial support for i.MX MISC protocol Message-Id: <20240731-imx95-bbm-misc-v2-v7-3-a41394365602@nxp.com> References: <20240731-imx95-bbm-misc-v2-v7-0-a41394365602@nxp.com> In-Reply-To: <20240731-imx95-bbm-misc-v2-v7-0-a41394365602@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Peng Fan , Alexandre Belloni , Dmitry Torokhov Cc: arm-scmi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-rtc@vger.kernel.org, linux-input@vger.kernel.org X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722430577; l=11462; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=Yc9fGdHVGpzX3AJqC0pvTwDCGUbMJnSIzJSsTgCSQww=; b=cn640NhUfp1RbVo4Gd+rQXRv6ThedXJ58myTsfVE3KGMRB6SgWkntdFVOmsOGmoSkEmrJW9pW fNAwlF/JLvqDmrm4ipW/v9IP866VOBPH9T4NsO9je+j2pYKJnQ0ljw7 X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI2PR02CA0027.apcprd02.prod.outlook.com (2603:1096:4:195::14) To PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8459:EE_|AS8PR04MB7735:EE_ X-MS-Office365-Filtering-Correlation-Id: bac46ca2-45a8-4e8e-bd0a-08dcb15ef00b X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|52116014|7416014|376014|1800799024|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?dlsg5rHNHQbxN2IwfnFBOqsgPoVF8rI?= =?utf-8?q?c+0oNT5am8+snKNMop6boUiTE+IciQiGRSVv2vxQtK2rPKFZ8wNeakeIJbPHd0h8H?= =?utf-8?q?86y+jMEKD9gUMlNgFh14a+Qk5qjJPf0jL+ZGPmsOu5VhjgE0WgaY4VMfZMXuay/SV?= =?utf-8?q?0K7ovm4seitnm1bhJDJfoGDHZhGn0XX8pN0MJfWbXBQCEu0G76ycTfoQAhokG/o76?= =?utf-8?q?AqHQgDj2Zt5mUNj8zMqdy2MkmCG7w3i5emgrAFSCNFQUUvpeufI0wbz3svR+SzKvU?= =?utf-8?q?yUvoa0TZp4BK4Z6yejSFch+ZFhiV9ZmrGsh7tuCr5+8lEFI90tvr6I/ISKg2+xQ+H?= =?utf-8?q?q4sXNsFPH47Ee0pQIsdjV+0sBLnITnf63oUQW/s8Kuq/LFaOXAQKQdNpKDxWuvC8w?= =?utf-8?q?ephWZzxrDpd0GMMQT4cn7jQt1XgklNwTm0JBChT/9l3k9AT/zkj2kM+kARYH9IL+b?= =?utf-8?q?IvlUkk6+/UJxh/2wFESZgx/pX8RIrLcOLID4rbTkwCAOJbXJatpRvvxKna969sAp5?= =?utf-8?q?guwk3xF/PKX7qdLCVqerRz52XuPTAshSCtHAL+wrDD1AP1TBCtCHT1O/EVYDKIpW1?= =?utf-8?q?U6sMJza79Ogzjs8cGggbgmZc6N9iJpbpPTgA4L7YW+3M0vT88qBjBuFgVoVqh+PRA?= =?utf-8?q?Wqri+h2hp/jEfZ42wysmQIRbU6apcx6C3jy4+YwCnlBAahMV1SrQZqyrm1mi6Yl6I?= =?utf-8?q?myxCGqoojFP3FOTCsffmgSDuvVRLpOuPCJPiqE3BnS4eFcABcM2nlvT0coNX4ydHG?= =?utf-8?q?QvOwZsV4dzZiwCdIllukfs9yQEBiYKKJPgKJivztR/rRtZqgnbjPrmkpOB1QODMN+?= =?utf-8?q?AHsA2T958TE7UkMOw1Cn/5i5es2XHVaSG9mLvXigFH1fdDGlhZupz7Q4VVWxYTkda?= =?utf-8?q?CgJTkJnMtJz5xdiCis+tL7/4iBz3TIBklxxgAWuoO5QxCyM/0eTJIY49L2TknaHdU?= =?utf-8?q?PErcdfam8JkI3IdkovJoISG5AJP6ZJco3q5jWem8htwG91lYuy0zspUOeqhBvKxE5?= =?utf-8?q?o6ct3ca+aJkg9jn/xiQCg7p2iFjMJKnyF31a+HgZ7hE+ZMlpduQZsRY+DDgbYxIy9?= =?utf-8?q?3ceUy6mqaWL96+83tOnHgiml1jPyVQmfae+A6CcnhO1B3pre+T/x+GaYf8LAVGj3d?= =?utf-8?q?4ene9lQQfX9kh/w4MtOpX7YS9kra0kHQ+AQ3KEtuHeMW3Ikdxpz3TQVAd6JTJU4lI?= =?utf-8?q?UYYmlHd/eIszFcwDGn5xCyM78l5V0aTTQMQTAVaccEaTX/34Kan6ovNSxwSahpGtr?= =?utf-8?q?E5YwYqmccuZwJBrVCSTVUpkitFWsIlC3QP9x1rgkDme1j25JrPvUmLZkAI3c/OnNn?= =?utf-8?q?WWPwgg0WkljvL8OB9e/R49EFIqmhfrI8YpAuWI7LX2KYER68dXO12zw=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB8459.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(52116014)(7416014)(376014)(1800799024)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?sQd3DTk5IEjM6TFAI+OXHq52bb29?= =?utf-8?q?9IeFWlMKiNwMP2woH8i0Pr7BRXXl8bxnb9/zYVa177/3jZm9PmnONULDLzc8AZllt?= =?utf-8?q?/YRmZ1UZfQGo/UR67YaDTuykHu+pdrfHj932Zrp5AncChkfSsMIlgih2HnbsT14CJ?= =?utf-8?q?QrL69+n1R57/zEmTIBko4yK7sotUzJTHOmAtr3vLmcQpgnswgbOmeyHpD+vwh7DpY?= =?utf-8?q?csUy4J5qN3o2QRwzjm61zltF/eDCmv5gtznZI9ozgL4ipEM+yW9g2U2y6qFYNmYdj?= =?utf-8?q?1UYArwZb/8Me0Z6dtOs13F9mp1vLbCUy0MW9EISgHIHUmPnyIN6fIK+avewC3Sl4X?= =?utf-8?q?vvwl4E311QO6LS8hurUKtGYErMaXQa4ELQiYv2KKjGMB7+2NmyfP91aWdkpO5fbKv?= =?utf-8?q?/iHu/yY7x+cGA8+R75lNVi4DtM+/KWKjrk6vHZZl7RrRAeiFq5QcuDVeNhlEn7B3P?= =?utf-8?q?sSlaqTDnggYobb/NenmPgPq+XKeDohfLYb1RSDRZ19MHDELfKwo25FD+Zv6yrRQ4J?= =?utf-8?q?LpsGIogpkPfDkVc6xL1vOWlGOBshJ0aNthIqwj/69V0I4O4SbIyCPtooZKpHu6CKv?= =?utf-8?q?XyPqRUhOtgl5oomIiSSduwwO5uu/rZ3Gb0EnlB3/Mv+jJvOAS7g4Qsg5PQovf12Tq?= =?utf-8?q?EBEgjwfySA54vy+daJI7TlregDw8TNQ6+z6/TjikUAZVOcp9tHDddY9Oep0euAqD2?= =?utf-8?q?0oosOWp4SH6xM7YnXr4BJtt9N9DiyUHy2387NQAABYKOV6UF0qLrn3t75LXAZTEIq?= =?utf-8?q?0R4guFvfit/Mwf0NOS/Ulzowct9+OPPKb42xrUfYtIhltEV6bDEHrL7pg8s2xfJ7N?= =?utf-8?q?HP1ERTCzbmi/6+JyZqy3DdYnSFbPgeKFJd4AAjxDNE6Jbd36Dfb/x8wOvGycDD9H0?= =?utf-8?q?nScNXXMfvBjrLisoibbTX0nk3lvlLaCdV8Go/+FyngIvOjBZlBxtCyaq6d3FtHXzB?= =?utf-8?q?4LdY/4+nRBksFrXrgD2/1HkMESTu01/AHvoGl6qMadSVMTY2qQsDgDSxhJT9q8wmX?= =?utf-8?q?AJNmMLfJnD1oRiaKhA72/CFH5DyhVaRqO/Nq0ABL7DaZctQiiE1wUBcXzyQh67pKs?= =?utf-8?q?DuvaUziL3W+i/7bUhT2ZPJy7TlK4z+7QLJW9Tvs+4Ujgf4AM5XtYthFmSMqMtDDaE?= =?utf-8?q?DNaxtzimJDmM/Bov0u9AzojDJ/8YiyljUEIvgmPG8lCBcNU/Cq0w8KMmp1tDexxYK?= =?utf-8?q?4bNyVV55fOPxwLR0biFIOlQZpA3fYSLx4CBA4uYjwAiavaf7Qk5sPiGUdx+t+j9n9?= =?utf-8?q?Lq72Vuy0ACzUqw+99oGbXYBGiVddLUg6Qycg3px6pB8XWTqcxub4z5KhcWZOne+85?= =?utf-8?q?hJeHk81jz4Dc3tgF7zV1eVuTY3rF6MDV1CNbJ3nxiFC2qRlszd1v67aNvP0blpVPk?= =?utf-8?q?i2U2VtiD9vjn1f2uN4jeEaaCnLrzvcQ8aFHS13LgMzkzfv1wJlCd0zjtLzUh2NloH?= =?utf-8?q?EVAZcLpjgwYBVjjnZ0Nsux1dmK7w5yZQFzpTm2ErmWN++n5ogSrongdi+qvuO5nzS?= =?utf-8?q?ze/kyw15Ksgj?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: bac46ca2-45a8-4e8e-bd0a-08dcb15ef00b X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 12:47:29.3321 (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: rc0NYNX1wv+OLYnXWoPW+MNHGQ0NxTRzXfoa8WbSOjflNzm9FhIQJ/EItpnMH2VvybdeVBKiNvQnKK6xtRp1wA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7735 From: Peng Fan i.MX95 System Manager(SM) firmware includes a SCMI vendor protocol, SCMI MISC protocol which includes controls that are misc settings/actions that must be exposed from the SM to agents. They are device specific and are usually define to access bit fields in various mix block control modules, IOMUX_GPR, and other General Purpose registers, Control Status Registers owned by the SM. Reviewed-by: Cristian Marussi Signed-off-by: Peng Fan --- drivers/firmware/arm_scmi/imx/Kconfig | 9 + drivers/firmware/arm_scmi/imx/Makefile | 1 + drivers/firmware/arm_scmi/imx/imx-sm-misc.c | 315 ++++++++++++++++++++++++++++ include/linux/scmi_imx_protocol.h | 17 ++ 4 files changed, 342 insertions(+) diff --git a/drivers/firmware/arm_scmi/imx/Kconfig b/drivers/firmware/arm_scmi/imx/Kconfig index 4b6ac7febe8f..e9d015859eaa 100644 --- a/drivers/firmware/arm_scmi/imx/Kconfig +++ b/drivers/firmware/arm_scmi/imx/Kconfig @@ -11,4 +11,13 @@ config IMX_SCMI_BBM_EXT This driver can also be built as a module. +config IMX_SCMI_MISC_EXT + tristate "i.MX SCMI MISC EXTENSION" + depends on ARM_SCMI_PROTOCOL || (COMPILE_TEST && OF) + default y if ARCH_MXC + help + This enables i.MX System MISC control logic such as gpio expander + wakeup + + This driver can also be built as a module. endmenu diff --git a/drivers/firmware/arm_scmi/imx/Makefile b/drivers/firmware/arm_scmi/imx/Makefile index a7dbdd20dbb9..d3ee6d544924 100644 --- a/drivers/firmware/arm_scmi/imx/Makefile +++ b/drivers/firmware/arm_scmi/imx/Makefile @@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_IMX_SCMI_BBM_EXT) += imx-sm-bbm.o +obj-$(CONFIG_IMX_SCMI_MISC_EXT) += imx-sm-misc.o diff --git a/drivers/firmware/arm_scmi/imx/imx-sm-misc.c b/drivers/firmware/arm_scmi/imx/imx-sm-misc.c new file mode 100644 index 000000000000..ca79d86d542c --- /dev/null +++ b/drivers/firmware/arm_scmi/imx/imx-sm-misc.c @@ -0,0 +1,315 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * System control and Management Interface (SCMI) NXP MISC Protocol + * + * Copyright 2024 NXP + */ + +#define pr_fmt(fmt) "SCMI Notifications MISC - " fmt + +#include +#include +#include +#include +#include +#include +#include + +#include "../protocols.h" +#include "../notify.h" + +#define SCMI_PROTOCOL_SUPPORTED_VERSION 0x10000 + +#define MAX_MISC_CTRL_SOURCES GENMASK(15, 0) + +enum scmi_imx_misc_protocol_cmd { + SCMI_IMX_MISC_CTRL_SET = 0x3, + SCMI_IMX_MISC_CTRL_GET = 0x4, + SCMI_IMX_MISC_CTRL_NOTIFY = 0x8, +}; + +struct scmi_imx_misc_info { + u32 version; + u32 nr_dev_ctrl; + u32 nr_brd_ctrl; + u32 nr_reason; +}; + +struct scmi_msg_imx_misc_protocol_attributes { + __le32 attributes; +}; + +#define GET_BRD_CTRLS_NR(x) le32_get_bits((x), GENMASK(31, 24)) +#define GET_REASONS_NR(x) le32_get_bits((x), GENMASK(23, 16)) +#define GET_DEV_CTRLS_NR(x) le32_get_bits((x), GENMASK(15, 0)) +#define BRD_CTRL_START_ID BIT(15) + +struct scmi_imx_misc_ctrl_set_in { + __le32 id; + __le32 num; + __le32 value[]; +}; + +struct scmi_imx_misc_ctrl_notify_in { + __le32 ctrl_id; + __le32 flags; +}; + +struct scmi_imx_misc_ctrl_notify_payld { + __le32 ctrl_id; + __le32 flags; +}; + +struct scmi_imx_misc_ctrl_get_out { + __le32 num; + __le32 val[]; +}; + +static int scmi_imx_misc_attributes_get(const struct scmi_protocol_handle *ph, + struct scmi_imx_misc_info *mi) +{ + int ret; + struct scmi_xfer *t; + struct scmi_msg_imx_misc_protocol_attributes *attr; + + ret = ph->xops->xfer_get_init(ph, PROTOCOL_ATTRIBUTES, 0, + sizeof(*attr), &t); + if (ret) + return ret; + + attr = t->rx.buf; + + ret = ph->xops->do_xfer(ph, t); + if (!ret) { + mi->nr_dev_ctrl = GET_DEV_CTRLS_NR(attr->attributes); + mi->nr_brd_ctrl = GET_BRD_CTRLS_NR(attr->attributes); + mi->nr_reason = GET_REASONS_NR(attr->attributes); + dev_info(ph->dev, "i.MX MISC NUM DEV CTRL: %d, NUM BRD CTRL: %d,NUM Reason: %d\n", + mi->nr_dev_ctrl, mi->nr_brd_ctrl, mi->nr_reason); + } + + ph->xops->xfer_put(ph, t); + + return ret; +} + +static int scmi_imx_misc_ctrl_validate_id(const struct scmi_protocol_handle *ph, + u32 ctrl_id) +{ + struct scmi_imx_misc_info *mi = ph->get_priv(ph); + + /* + * [0, BRD_CTRL_START_ID) is for Dev Ctrl which is SOC related + * [BRD_CTRL_START_ID, 0xffff) is for Board Ctrl which is board related + */ + if ((ctrl_id < BRD_CTRL_START_ID) && (ctrl_id > mi->nr_dev_ctrl)) + return -EINVAL; + if (ctrl_id >= BRD_CTRL_START_ID + mi->nr_brd_ctrl) + return -EINVAL; + + return 0; +} + +static int scmi_imx_misc_ctrl_notify(const struct scmi_protocol_handle *ph, + u32 ctrl_id, u32 evt_id, u32 flags) +{ + struct scmi_imx_misc_ctrl_notify_in *in; + struct scmi_xfer *t; + int ret; + + ret = scmi_imx_misc_ctrl_validate_id(ph, ctrl_id); + if (ret) + return ret; + + ret = ph->xops->xfer_get_init(ph, SCMI_IMX_MISC_CTRL_NOTIFY, + sizeof(*in), 0, &t); + if (ret) + return ret; + + in = t->tx.buf; + in->ctrl_id = cpu_to_le32(ctrl_id); + in->flags = cpu_to_le32(flags); + + ret = ph->xops->do_xfer(ph, t); + + ph->xops->xfer_put(ph, t); + + return ret; +} + +static int +scmi_imx_misc_ctrl_set_notify_enabled(const struct scmi_protocol_handle *ph, + u8 evt_id, u32 src_id, bool enable) +{ + int ret; + + /* misc_ctrl_req_notify is for enablement */ + if (enable) + return 0; + + ret = scmi_imx_misc_ctrl_notify(ph, src_id, evt_id, 0); + if (ret) + dev_err(ph->dev, "FAIL_ENABLED - evt[%X] src[%d] - ret:%d\n", + evt_id, src_id, ret); + + return ret; +} + +static void * +scmi_imx_misc_ctrl_fill_custom_report(const struct scmi_protocol_handle *ph, + u8 evt_id, ktime_t timestamp, + const void *payld, size_t payld_sz, + void *report, u32 *src_id) +{ + const struct scmi_imx_misc_ctrl_notify_payld *p = payld; + struct scmi_imx_misc_ctrl_notify_report *r = report; + + if (sizeof(*p) != payld_sz) + return NULL; + + r->timestamp = timestamp; + r->ctrl_id = p->ctrl_id; + r->flags = p->flags; + if (src_id) + *src_id = r->ctrl_id; + dev_dbg(ph->dev, "%s: ctrl_id: %d flags: %d\n", __func__, + r->ctrl_id, r->flags); + + return r; +} + +static const struct scmi_event_ops scmi_imx_misc_event_ops = { + .set_notify_enabled = scmi_imx_misc_ctrl_set_notify_enabled, + .fill_custom_report = scmi_imx_misc_ctrl_fill_custom_report, +}; + +static const struct scmi_event scmi_imx_misc_events[] = { + { + .id = SCMI_EVENT_IMX_MISC_CONTROL, + .max_payld_sz = sizeof(struct scmi_imx_misc_ctrl_notify_payld), + .max_report_sz = sizeof(struct scmi_imx_misc_ctrl_notify_report), + }, +}; + +static struct scmi_protocol_events scmi_imx_misc_protocol_events = { + .queue_sz = SCMI_PROTO_QUEUE_SZ, + .ops = &scmi_imx_misc_event_ops, + .evts = scmi_imx_misc_events, + .num_events = ARRAY_SIZE(scmi_imx_misc_events), + .num_sources = MAX_MISC_CTRL_SOURCES, +}; + +static int scmi_imx_misc_ctrl_get(const struct scmi_protocol_handle *ph, + u32 ctrl_id, u32 *num, u32 *val) +{ + struct scmi_imx_misc_ctrl_get_out *out; + struct scmi_xfer *t; + int ret, i; + int max_msg_size = ph->hops->get_max_msg_size(ph); + int max_num = (max_msg_size - sizeof(*out)) / sizeof(__le32); + + ret = scmi_imx_misc_ctrl_validate_id(ph, ctrl_id); + if (ret) + return ret; + + ret = ph->xops->xfer_get_init(ph, SCMI_IMX_MISC_CTRL_GET, sizeof(u32), + 0, &t); + if (ret) + return ret; + + put_unaligned_le32(ctrl_id, t->tx.buf); + ret = ph->xops->do_xfer(ph, t); + if (!ret) { + out = t->rx.buf; + *num = le32_to_cpu(out->num); + + if (*num >= max_num || + *num * sizeof(__le32) > t->rx.len - sizeof(__le32)) { + ph->xops->xfer_put(ph, t); + return -EINVAL; + } + + for (i = 0; i < *num; i++) + val[i] = le32_to_cpu(out->val[i]); + } + + ph->xops->xfer_put(ph, t); + + return ret; +} + +static int scmi_imx_misc_ctrl_set(const struct scmi_protocol_handle *ph, + u32 ctrl_id, u32 num, u32 *val) +{ + struct scmi_imx_misc_ctrl_set_in *in; + struct scmi_xfer *t; + int ret, i; + int max_msg_size = ph->hops->get_max_msg_size(ph); + int max_num = (max_msg_size - sizeof(*in)) / sizeof(__le32); + + ret = scmi_imx_misc_ctrl_validate_id(ph, ctrl_id); + if (ret) + return ret; + + if (num > max_num) + return -EINVAL; + + ret = ph->xops->xfer_get_init(ph, SCMI_IMX_MISC_CTRL_SET, sizeof(*in), + 0, &t); + if (ret) + return ret; + + in = t->tx.buf; + in->id = cpu_to_le32(ctrl_id); + in->num = cpu_to_le32(num); + for (i = 0; i < num; i++) + in->value[i] = cpu_to_le32(val[i]); + + ret = ph->xops->do_xfer(ph, t); + + ph->xops->xfer_put(ph, t); + + return ret; +} + +static const struct scmi_imx_misc_proto_ops scmi_imx_misc_proto_ops = { + .misc_ctrl_set = scmi_imx_misc_ctrl_set, + .misc_ctrl_get = scmi_imx_misc_ctrl_get, + .misc_ctrl_req_notify = scmi_imx_misc_ctrl_notify, +}; + +static int scmi_imx_misc_protocol_init(const struct scmi_protocol_handle *ph) +{ + struct scmi_imx_misc_info *minfo; + u32 version; + int ret; + + ret = ph->xops->version_get(ph, &version); + if (ret) + return ret; + + dev_info(ph->dev, "NXP SM MISC Version %d.%d\n", + PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version)); + + minfo = devm_kzalloc(ph->dev, sizeof(*minfo), GFP_KERNEL); + if (!minfo) + return -ENOMEM; + + ret = scmi_imx_misc_attributes_get(ph, minfo); + if (ret) + return ret; + + return ph->set_priv(ph, minfo, version); +} + +static const struct scmi_protocol scmi_imx_misc = { + .id = SCMI_PROTOCOL_IMX_MISC, + .owner = THIS_MODULE, + .instance_init = &scmi_imx_misc_protocol_init, + .ops = &scmi_imx_misc_proto_ops, + .events = &scmi_imx_misc_protocol_events, + .supported_version = SCMI_PROTOCOL_SUPPORTED_VERSION, + .vendor_id = "NXP", + .sub_vendor_id = "IMX", +}; +module_scmi_protocol(scmi_imx_misc); diff --git a/include/linux/scmi_imx_protocol.h b/include/linux/scmi_imx_protocol.h index 2df2ea0f1809..066216f1357a 100644 --- a/include/linux/scmi_imx_protocol.h +++ b/include/linux/scmi_imx_protocol.h @@ -15,6 +15,7 @@ enum scmi_nxp_protocol { SCMI_PROTOCOL_IMX_BBM = 0x81, + SCMI_PROTOCOL_IMX_MISC = 0x84, }; struct scmi_imx_bbm_proto_ops { @@ -30,6 +31,7 @@ struct scmi_imx_bbm_proto_ops { enum scmi_nxp_notification_events { SCMI_EVENT_IMX_BBM_RTC = 0x0, SCMI_EVENT_IMX_BBM_BUTTON = 0x1, + SCMI_EVENT_IMX_MISC_CONTROL = 0x0, }; struct scmi_imx_bbm_notif_report { @@ -39,4 +41,19 @@ struct scmi_imx_bbm_notif_report { unsigned int rtc_id; unsigned int rtc_evt; }; + +struct scmi_imx_misc_ctrl_notify_report { + ktime_t timestamp; + unsigned int ctrl_id; + unsigned int flags; +}; + +struct scmi_imx_misc_proto_ops { + int (*misc_ctrl_set)(const struct scmi_protocol_handle *ph, u32 id, + u32 num, u32 *val); + int (*misc_ctrl_get)(const struct scmi_protocol_handle *ph, u32 id, + u32 *num, u32 *val); + int (*misc_ctrl_req_notify)(const struct scmi_protocol_handle *ph, + u32 ctrl_id, u32 evt_id, u32 flags); +}; #endif