From patchwork Fri Jun 21 07:04:38 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: 13706917 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2088.outbound.protection.outlook.com [40.107.22.88]) (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 71ACD16C688 for ; Fri, 21 Jun 2024 06:56:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.88 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718952963; cv=fail; b=JTQ7EQbkasw4mbeYKaS7fkioKRtDrdp2cjwhkTpmlvoSHjcuBriYA0lwTkaHTko4V+/agTyLkGI4F+2kb0O7ZLV8V+VMEFp3YWfLWP/yeZCsMHYzsVH9jtOQ3WB9aKvXDGK0L9IVl6atbBxV/M8p+ySPzntWh/sTxNwfqVUOBw8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718952963; c=relaxed/simple; bh=xR9UW4Jdz0yuYEI1aBoF4HryZ/pqGfpyfS/4R150Ms0=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=jyxh00bQ2VU9uXlWKjgpV2Z0FdoED/BZf0kar3NB/LSD7uWdfAxWusx/9YKlC1y19m8E2wV+FfziyqImcZ0Li/51jwjk1oZUqYSAuDP6iNcFg+jeITE1aoH/XAHJFd6NsYDvij/02Dwv9YrnO/aKY0X6zEa6K/QdFBxQde6wgTs= 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 (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b=UniJaokW; arc=fail smtp.client-ip=40.107.22.88 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 (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="UniJaokW" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dTVE9j7jQCTeuWuTkUx31QNKXDr+geqw6ldGCHszBZGIzJxRiKRtiSoic1YQv2zFJfeym+D+DZlq70e3pWComRUurGj3ByAHXPeJweAB5kFh25qeRpPx0itEmUvsaNV1Tgk8CIo9mnWZZ3hegDdzEFUGU2pLz19O+SyoXRDNcyT6uV9autFRjT+ece646aoUKCnb0S6iLF4r9wB3/ahpNjKTheCXIz2abZQqIZZoOI4Nt4Hs4uKuy7GHSmESkG9Wy+2IOuOzsd35+9nPIvfs0jmxiI+p4aGcaqXqgK7kmUJVAu/n8KfQ4naiqMakErguf7cy2NAWDNkqGnKsFW5oBA== 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=QAZe/XpfLU5x78InrIRx8wxQbwTt+69hCuXdxwFNfvE=; b=L1wL5Xe0L7vV5h80SZoiSuHHkjIu0UYP+FDynKEbJpqTXRkUXEqMvrmiaq+rvWYhIJ6xYeYOBSzlas0bLQq3r04MylU+egs6Ql0Ehgtl+2FXKaUWD74Xm9ayiDZWfWcpzpvNKAw55Bac2o8QjRvZnj4Jt6FZLUESJD7KoA3QWx2HLFx3Xh8IKpct4YkgtM6dGMclYaNPA8pOq6SGEFP7O5CIlXhjMHSySnjR5zGAxB2oPDcnTvQnRBZO8yecmhF9hFh3bZrREYKHCeN3B824vfzynCKk12CAAXqR6c+0gyXuDIVVh8dTMWIv9b3QEudtiEJ0j+5+4b1tq008U7uDqw== 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=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QAZe/XpfLU5x78InrIRx8wxQbwTt+69hCuXdxwFNfvE=; b=UniJaokWFDKFbSYo4N5FU2wvKZUtMOq8Q96++NZluMoEP49CP5DAykaTvQxeHIiTL0NXv9y9GW6gNoVyT4/nQqRKEF2aR7jRRx9iFYnw4BK1KLESHDy7/+w++BJ+5hE+PH7asOoSiYkJNNroTHodJjoCznOXpvwfSqpOyIcjlgQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM6PR04MB5941.eurprd04.prod.outlook.com (2603:10a6:20b:9e::16) by GV1PR04MB10426.eurprd04.prod.outlook.com (2603:10a6:150:1cc::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.19; Fri, 21 Jun 2024 06:55:58 +0000 Received: from AM6PR04MB5941.eurprd04.prod.outlook.com ([fe80::9f4e:b695:f5f0:5256]) by AM6PR04MB5941.eurprd04.prod.outlook.com ([fe80::9f4e:b695:f5f0:5256%4]) with mapi id 15.20.7698.017; Fri, 21 Jun 2024 06:55:58 +0000 From: "Peng Fan (OSS)" Date: Fri, 21 Jun 2024 15:04:38 +0800 Subject: [PATCH v5 3/7] firmware: arm_scmi: add initial support for i.MX BBM protocol Message-Id: <20240621-imx95-bbm-misc-v2-v5-3-b85a6bf778cb@nxp.com> References: <20240621-imx95-bbm-misc-v2-v5-0-b85a6bf778cb@nxp.com> In-Reply-To: <20240621-imx95-bbm-misc-v2-v5-0-b85a6bf778cb@nxp.com> To: Jonathan Corbet , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Peng Fan , Alexandre Belloni , Dmitry Torokhov Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, arm-scmi@vger.kernel.org, linux-rtc@vger.kernel.org, linux-input@vger.kernel.org X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1718953487; l=13884; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=qf3BvGVUQfUDNPRd2U+n/wlDtywN4BIpyG9Mq65nrws=; b=apGCZPhiN53JTpgT+P0ea8VkUib3ZGs1/MDFvxRPwZFzc56zuBGpGfc3uEOJc26H+ook2OBsC BSe8I8sDFLqBtwVTzX2ytop69Tt7rmr5W5DeIlhW1wvfTDJvFMie9+3 X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2PR01CA0122.apcprd01.prod.exchangelabs.com (2603:1096:4:40::26) To AM6PR04MB5941.eurprd04.prod.outlook.com (2603:10a6:20b:9e::16) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB5941:EE_|GV1PR04MB10426:EE_ X-MS-Office365-Filtering-Correlation-Id: ec9fdc89-9fd5-41d1-06b9-08dc91bf33c6 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|1800799021|366013|52116011|7416011|376011|921017|38350700011; X-Microsoft-Antispam-Message-Info: =?utf-8?q?dP8Z8hA8McA/6T0Etc0XxpdGGdOsLnH?= =?utf-8?q?j7whPfrvI2xn4cGPG7hfTQYCnbIhDdp5fJvfh6CcUCsVvu3K8kqFZ2EK4JBlvVB1D?= =?utf-8?q?nw5UA/yL/G3gE3B0Yof4S3VwAC4J9fAKVDRTSAH5ZOCnw7waJ/lO+B3tvz9/v8a5L?= =?utf-8?q?lfudwHHa+QqAX3uKtdcg/6KVZ7ibVWcBcnNSVPGS87HU73lD/GHiThFCBtgGdP//g?= =?utf-8?q?uDHgr9PYZu/nMc3xl2Biniom9O3ELHMtsEa6rkqMfFXoGJVjKqdt6T208nQVTRBY3?= =?utf-8?q?+rQYKPth9vYCQInOe14MbGmTMblpXj0If5zqOUPdpL6o5NWmTGdbsdel/GEYMISaD?= =?utf-8?q?SN5cSV6XKusChjF8dAhh/rD3DOcqdsEBoYWwlmALWc4qwOHrs/jigR468NVP4Rlku?= =?utf-8?q?8fDiRaIxl0xj6JXNhPn8GVdGhumFhjW4KMiK7ahcikKbwQBc0Lvx7eF9feNxCMc+v?= =?utf-8?q?zLsBI4/4GL/u5YQ0y6NSB3th5sjy0TwQj8Q2j7URfpnG0f4g+JK/s7XPXr21W5LUn?= =?utf-8?q?TK/lrTfTN9oCbcE45VBObXqijFtGlUgHnFHzY7L0ViVrc6MGD/TLH9yd7gq9eT9P6?= =?utf-8?q?jRsVGB3zLy4EK3kIQpIe0YZj48vUyKs7rHAZTbFVTqnAnCpZ7wJADroc42IjEkb5M?= =?utf-8?q?ghEJ2hKswvINKvQhnXGoSgMIDybiQm40bxzUIUhjkTMfpaaBP/9yb+gHt9ttdAz4c?= =?utf-8?q?+t/c3fkOwvFmHJkk/RDAxNG/lfzoM9DpXDKNsEtH0XcErbKFWgw/8Ayeyu3f1P0fW?= =?utf-8?q?HQDE+OPrtXAZY5UDbu5vAQrPSJ8SDA9J3ne3Ymslzeef3LfLpswwqCisKx/OsByYW?= =?utf-8?q?jG2WZA/f6h6d4k06T861q8a1illOuHRAZJbZa0HrJLqU7Y0YgecgORguIMiilitWn?= =?utf-8?q?9zV2tkafc2GA0LdGHh6YPh2duguQy+HTG+t/VaM1zaz2Z++sOB+q/uOs742VNuzbk?= =?utf-8?q?msobDfDQ1th5+zosEb/nVX1UUZ3qnICKGUulIy+Brvt29F5Iv3JKaO/LyZ9QBUv85?= =?utf-8?q?U1bG5igAHOkF5fDIopj2I+05EPlV+Go6QbUY9YnolBaTG1uWi7g6PfEsf1xLeeLWj?= =?utf-8?q?FQTWDqLLxcSMtuOd5Le4J7ahMkdQaIfehsq8iPOSrCrSTlhMTL/KhxF8sBHPXi2Je?= =?utf-8?q?Rx0PvnW2qW8cOeN/Kopf4GwaYgO0SUvVQeZTsR8xUqzMhHQAkQfBlciI6xr0ZWtja?= =?utf-8?q?SjwdjSKl8K9MXDJ7cjdN7gCpL6PBtzbjqr0mHxh64p9+AmYDDlPuFqjkBOabTNkzH?= =?utf-8?q?8ElCuKacvzaOT/oXtj0JbsTxkWINhy6U06ccKK1iir6fi8Zqi6I3g98etH2R7vZXC?= =?utf-8?q?Gm9lQ9PJXNUF?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB5941.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230037)(1800799021)(366013)(52116011)(7416011)(376011)(921017)(38350700011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Ce2CBxwbE8W7t+IYUpvwSbEE2HBu?= =?utf-8?q?kpLwOO6N+Tf1aY++MzqoIKDU7tTKMv5QIU3eYuaFhS7WqXfcqPfoJ6PJ0nz71hN50?= =?utf-8?q?zCFx4L/v+26BqyFRY6P9wDZT8ejC1GJZU16F4HOs1redNrtBGSagvkJC/v/rOz+lh?= =?utf-8?q?Vc9Thm3HiEWNwzMOvTc/aF2fWf1UQE3jYSp8h4Iw3YgJ3soZn/SBewrxNapIkQB5p?= =?utf-8?q?Rh7tyadMPBKyGrUr+OvK8csaBGVt1caSiE+SAX9k/bA3v3vtUkc6e0/VUnVEvklM7?= =?utf-8?q?wvptYar7rjxYpZ0UegPO0cZQBbztCNwFwH4dRg51XhPBd9pNamhQm6mpNJBVkwv1T?= =?utf-8?q?VslsamIj7i18afULMCStvPJAPjoTHirRu3jySBtCNkiNd9lWsWBE28nC2patfWURb?= =?utf-8?q?ydKvlmVqChpCS2wKGM4O6Gg+fvOsCqlid5pIF1BRX95Ah3veQs9woWwUOgABsBjqk?= =?utf-8?q?fjXCbeHtIKEieP/W0z/+3ecfmxHRicY4Pw1qdoVatJ93gIKfUpoXsUcITd1pccyp4?= =?utf-8?q?YgJFdMdci8T3Ntv2ggodrc4ZS+4e1cKlSaeiwnW87msQlxd80HLiiBW3FgVYrOQ/F?= =?utf-8?q?yWBU/gn2PnMruzzGBKZDP+Uqea7pETLByKvohfKIIXZltRxUWGyCuFNPz8oM5yiDE?= =?utf-8?q?Ywdrb98mljVZ25hGUVn5DQJDMn6UOVFYGvZAMJ3V/fPo0BO2bb0mUDUa2i6Es3cwn?= =?utf-8?q?wXuyAbPM1Evgl5nRRMdihR6usDPKRv/A23E6n8C8xo+73U21eY21VdKAE0HO1sGwL?= =?utf-8?q?Bn8Hi0Ep52mlpqOm/sl/zjaKERF4aSPQMBboOnCk8Ny4zl/hyJo6H4Sz552s1GExw?= =?utf-8?q?qedRKVfzaMl9MFlhW9dvsIKklyssvkeHUi8ZwGLzBH+5LqKmt2jPpieXXb/QKlFjE?= =?utf-8?q?/tth0V581AuGs/QOQmTmduubLgdWno57hg/Bzrx7W403mFGa8IBJvzQeoLOdRY/IN?= =?utf-8?q?ZfE/sFm2v33hTosHUbX0pHqwZOsnQWv/p6L1gBTiJ+w8zWvIPuRX6MTju4vOcgvHM?= =?utf-8?q?gLJDuDZdJxPCW8bdtpBqF6lG3dkFkB32mzHnvUa5aWQQnGX9HNEjGC4jc1GvizmUP?= =?utf-8?q?ofSKGu20M05PD3kuOYdEUji9SfeEKMCawVLbBar0VKWAgP9Ue3ScI9KoKs/KqDxaJ?= =?utf-8?q?Xt0WVifhwlKs/sBhuybXw5Oun/d9EiX0w2ZQY0lSpcXN/cR7tLVOS5Xx+4E7njrxi?= =?utf-8?q?vJQ7m8DUK4KUPAeoUOD7NCTZ6GOZDAOqMX6kb6OFB5rLHU24+zo/CBbzmS3J5+DX/?= =?utf-8?q?t2TImBcecitcZJZ+2es/pUeKeRH1JchBXqfP0J/e2U8VlhDrBzZuTj4IaCIccmvsY?= =?utf-8?q?jjucL8dEX2kS7WvitW9RQ9NWxRNYGnnCtaeU6XFv+dJ1f0zhsC492NA3sbAW+Q7N1?= =?utf-8?q?vtvRKOR+vKmTH1KgCa9JPrd1jBYAo4vc6Y9O6/Jg2GJGGSzY0lVEINSgjKqlC6Lyw?= =?utf-8?q?C+4h/WmLIH1MombsZNdNf1R52KZnal1KEgfsnO6UUqOZi1y9063lui4H+J/CYkvTC?= =?utf-8?q?5s0evQku2PaJ?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ec9fdc89-9fd5-41d1-06b9-08dc91bf33c6 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB5941.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2024 06:55:58.0997 (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: J4uqN5bj6nKMiormAF8k73VDuclKo1wu7XiINyI3v4LmK4at7QSo2cCW3Hs3UXH7uRYMzGqvyt6+KyoJzD90tg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB10426 From: Peng Fan i.MX95 has a battery-backed module(BBM), which has persistent storage (GPR), an RTC, and the ON/OFF button. The System Manager(SM) firmware use SCMI vendor protocol(SCMI BBM) to let agent be able to use GPR, RTC and ON/OFF button. Reviewed-by: Cristian Marussi Signed-off-by: Peng Fan --- drivers/firmware/arm_scmi/Kconfig | 2 + drivers/firmware/arm_scmi/Makefile | 1 + drivers/firmware/arm_scmi/imx/Kconfig | 14 ++ drivers/firmware/arm_scmi/imx/Makefile | 2 + drivers/firmware/arm_scmi/imx/imx-sm-bbm.c | 379 +++++++++++++++++++++++++++++ include/linux/scmi_imx_protocol.h | 42 ++++ 6 files changed, 440 insertions(+) diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig index aa5842be19b2..79846cbaf71b 100644 --- a/drivers/firmware/arm_scmi/Kconfig +++ b/drivers/firmware/arm_scmi/Kconfig @@ -180,4 +180,6 @@ config ARM_SCMI_POWER_CONTROL called scmi_power_control. Note this may needed early in boot to catch early shutdown/reboot SCMI requests. +source "drivers/firmware/arm_scmi/imx/Kconfig" + endmenu diff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi/Makefile index fd59f58ce8a2..fb9407fef60c 100644 --- a/drivers/firmware/arm_scmi/Makefile +++ b/drivers/firmware/arm_scmi/Makefile @@ -16,6 +16,7 @@ scmi-module-objs := $(scmi-driver-y) $(scmi-protocols-y) $(scmi-transport-y) obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-core.o obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-module.o +obj-$(CONFIG_ARM_SCMI_PROTOCOL) += imx/ obj-$(CONFIG_ARM_SCMI_POWER_CONTROL) += scmi_power_control.o diff --git a/drivers/firmware/arm_scmi/imx/Kconfig b/drivers/firmware/arm_scmi/imx/Kconfig new file mode 100644 index 000000000000..4b6ac7febe8f --- /dev/null +++ b/drivers/firmware/arm_scmi/imx/Kconfig @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0-only +menu "ARM SCMI NXP i.MX Vendor Protocols" + +config IMX_SCMI_BBM_EXT + tristate "i.MX SCMI BBM EXTENSION" + depends on ARM_SCMI_PROTOCOL || (COMPILE_TEST && OF) + default y if ARCH_MXC + help + This enables i.MX System BBM control logic which supports RTC + and BUTTON. + + 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 new file mode 100644 index 000000000000..a7dbdd20dbb9 --- /dev/null +++ b/drivers/firmware/arm_scmi/imx/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_IMX_SCMI_BBM_EXT) += imx-sm-bbm.o diff --git a/drivers/firmware/arm_scmi/imx/imx-sm-bbm.c b/drivers/firmware/arm_scmi/imx/imx-sm-bbm.c new file mode 100644 index 000000000000..559ad9f7088c --- /dev/null +++ b/drivers/firmware/arm_scmi/imx/imx-sm-bbm.c @@ -0,0 +1,379 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * System Control and Management Interface (SCMI) NXP BBM Protocol + * + * Copyright 2024 NXP + */ + +#define pr_fmt(fmt) "SCMI Notifications BBM - " fmt + +#include +#include +#include +#include +#include +#include +#include + +#include "../protocols.h" +#include "../notify.h" + +#define SCMI_PROTOCOL_SUPPORTED_VERSION 0x10000 + +enum scmi_imx_bbm_protocol_cmd { + IMX_BBM_GPR_SET = 0x3, + IMX_BBM_GPR_GET = 0x4, + IMX_BBM_RTC_ATTRIBUTES = 0x5, + IMX_BBM_RTC_TIME_SET = 0x6, + IMX_BBM_RTC_TIME_GET = 0x7, + IMX_BBM_RTC_ALARM_SET = 0x8, + IMX_BBM_BUTTON_GET = 0x9, + IMX_BBM_RTC_NOTIFY = 0xA, + IMX_BBM_BUTTON_NOTIFY = 0xB, +}; + +#define GET_RTCS_NR(x) le32_get_bits((x), GENMASK(23, 16)) +#define GET_GPRS_NR(x) le32_get_bits((x), GENMASK(15, 0)) + +#define SCMI_IMX_BBM_NOTIFY_RTC_UPDATED BIT(2) +#define SCMI_IMX_BBM_NOTIFY_RTC_ROLLOVER BIT(1) +#define SCMI_IMX_BBM_NOTIFY_RTC_ALARM BIT(0) + +#define SCMI_IMX_BBM_RTC_ALARM_ENABLE_FLAG BIT(0) + +#define SCMI_IMX_BBM_NOTIFY_RTC_FLAG \ + (SCMI_IMX_BBM_NOTIFY_RTC_UPDATED | SCMI_IMX_BBM_NOTIFY_RTC_ROLLOVER | \ + SCMI_IMX_BBM_NOTIFY_RTC_ALARM) + +#define SCMI_IMX_BBM_EVENT_RTC_MASK GENMASK(31, 24) + +struct scmi_imx_bbm_info { + u32 version; + int nr_rtc; + int nr_gpr; +}; + +struct scmi_msg_imx_bbm_protocol_attributes { + __le32 attributes; +}; + +struct scmi_imx_bbm_set_time { + __le32 id; + __le32 flags; + __le32 value_low; + __le32 value_high; +}; + +struct scmi_imx_bbm_get_time { + __le32 id; + __le32 flags; +}; + +struct scmi_imx_bbm_alarm_time { + __le32 id; + __le32 flags; + __le32 value_low; + __le32 value_high; +}; + +struct scmi_msg_imx_bbm_rtc_notify { + __le32 rtc_id; + __le32 flags; +}; + +struct scmi_msg_imx_bbm_button_notify { + __le32 flags; +}; + +struct scmi_imx_bbm_notify_payld { + __le32 flags; +}; + +static int scmi_imx_bbm_attributes_get(const struct scmi_protocol_handle *ph, + struct scmi_imx_bbm_info *pi) +{ + int ret; + struct scmi_xfer *t; + struct scmi_msg_imx_bbm_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) { + pi->nr_rtc = GET_RTCS_NR(attr->attributes); + pi->nr_gpr = GET_GPRS_NR(attr->attributes); + } + + ph->xops->xfer_put(ph, t); + + return ret; +} + +static int scmi_imx_bbm_notify(const struct scmi_protocol_handle *ph, + u32 src_id, int message_id, bool enable) +{ + int ret; + struct scmi_xfer *t; + + if (message_id == IMX_BBM_RTC_NOTIFY) { + struct scmi_msg_imx_bbm_rtc_notify *rtc_notify; + + ret = ph->xops->xfer_get_init(ph, message_id, + sizeof(*rtc_notify), 0, &t); + if (ret) + return ret; + + rtc_notify = t->tx.buf; + rtc_notify->rtc_id = cpu_to_le32(0); + rtc_notify->flags = + cpu_to_le32(enable ? SCMI_IMX_BBM_NOTIFY_RTC_FLAG : 0); + } else if (message_id == IMX_BBM_BUTTON_NOTIFY) { + struct scmi_msg_imx_bbm_button_notify *button_notify; + + ret = ph->xops->xfer_get_init(ph, message_id, + sizeof(*button_notify), 0, &t); + if (ret) + return ret; + + button_notify = t->tx.buf; + button_notify->flags = cpu_to_le32(enable ? 1 : 0); + } else { + return -EINVAL; + } + + ret = ph->xops->do_xfer(ph, t); + + ph->xops->xfer_put(ph, t); + return ret; +} + +static enum scmi_imx_bbm_protocol_cmd evt_2_cmd[] = { + IMX_BBM_RTC_NOTIFY, + IMX_BBM_BUTTON_NOTIFY +}; + +static int scmi_imx_bbm_set_notify_enabled(const struct scmi_protocol_handle *ph, + u8 evt_id, u32 src_id, bool enable) +{ + int ret, cmd_id; + + if (evt_id >= ARRAY_SIZE(evt_2_cmd)) + return -EINVAL; + + cmd_id = evt_2_cmd[evt_id]; + ret = scmi_imx_bbm_notify(ph, src_id, cmd_id, enable); + if (ret) + pr_debug("FAIL_ENABLED - evt[%X] dom[%d] - ret:%d\n", + evt_id, src_id, ret); + + return ret; +} + +static void *scmi_imx_bbm_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_bbm_notify_payld *p = payld; + struct scmi_imx_bbm_notif_report *r = report; + + if (sizeof(*p) != payld_sz) + return NULL; + + if (evt_id == SCMI_EVENT_IMX_BBM_RTC) { + r->is_rtc = true; + r->is_button = false; + r->timestamp = timestamp; + r->rtc_id = le32_get_bits(p->flags, SCMI_IMX_BBM_EVENT_RTC_MASK); + r->rtc_evt = le32_get_bits(p->flags, SCMI_IMX_BBM_NOTIFY_RTC_FLAG); + dev_dbg(ph->dev, "RTC: %d evt: %x\n", r->rtc_id, r->rtc_evt); + *src_id = r->rtc_evt; + } else if (evt_id == SCMI_EVENT_IMX_BBM_BUTTON) { + r->is_rtc = false; + r->is_button = true; + r->timestamp = timestamp; + dev_dbg(ph->dev, "BBM Button\n"); + *src_id = 0; + } else { + WARN_ON_ONCE(1); + return NULL; + } + + return r; +} + +static const struct scmi_event scmi_imx_bbm_events[] = { + { + .id = SCMI_EVENT_IMX_BBM_RTC, + .max_payld_sz = sizeof(struct scmi_imx_bbm_notify_payld), + .max_report_sz = sizeof(struct scmi_imx_bbm_notif_report), + }, + { + .id = SCMI_EVENT_IMX_BBM_BUTTON, + .max_payld_sz = sizeof(struct scmi_imx_bbm_notify_payld), + .max_report_sz = sizeof(struct scmi_imx_bbm_notif_report), + }, +}; + +static const struct scmi_event_ops scmi_imx_bbm_event_ops = { + .set_notify_enabled = scmi_imx_bbm_set_notify_enabled, + .fill_custom_report = scmi_imx_bbm_fill_custom_report, +}; + +static const struct scmi_protocol_events scmi_imx_bbm_protocol_events = { + .queue_sz = SCMI_PROTO_QUEUE_SZ, + .ops = &scmi_imx_bbm_event_ops, + .evts = scmi_imx_bbm_events, + .num_events = ARRAY_SIZE(scmi_imx_bbm_events), + .num_sources = 1, +}; + +static int scmi_imx_bbm_rtc_time_set(const struct scmi_protocol_handle *ph, + u32 rtc_id, u64 sec) +{ + struct scmi_imx_bbm_info *pi = ph->get_priv(ph); + struct scmi_imx_bbm_set_time *cfg; + struct scmi_xfer *t; + int ret; + + if (rtc_id >= pi->nr_rtc) + return -EINVAL; + + ret = ph->xops->xfer_get_init(ph, IMX_BBM_RTC_TIME_SET, sizeof(*cfg), 0, &t); + if (ret) + return ret; + + cfg = t->tx.buf; + cfg->id = cpu_to_le32(rtc_id); + cfg->flags = 0; + cfg->value_low = cpu_to_le32(lower_32_bits(sec)); + cfg->value_high = cpu_to_le32(upper_32_bits(sec)); + + ret = ph->xops->do_xfer(ph, t); + + ph->xops->xfer_put(ph, t); + + return ret; +} + +static int scmi_imx_bbm_rtc_time_get(const struct scmi_protocol_handle *ph, + u32 rtc_id, u64 *value) +{ + struct scmi_imx_bbm_info *pi = ph->get_priv(ph); + struct scmi_imx_bbm_get_time *cfg; + struct scmi_xfer *t; + int ret; + + if (rtc_id >= pi->nr_rtc) + return -EINVAL; + + ret = ph->xops->xfer_get_init(ph, IMX_BBM_RTC_TIME_GET, sizeof(*cfg), + sizeof(u64), &t); + if (ret) + return ret; + + cfg = t->tx.buf; + cfg->id = cpu_to_le32(rtc_id); + cfg->flags = 0; + + ret = ph->xops->do_xfer(ph, t); + if (!ret) + *value = get_unaligned_le64(t->rx.buf); + + ph->xops->xfer_put(ph, t); + + return ret; +} + +static int scmi_imx_bbm_rtc_alarm_set(const struct scmi_protocol_handle *ph, + u32 rtc_id, u64 sec) +{ + struct scmi_imx_bbm_info *pi = ph->get_priv(ph); + struct scmi_imx_bbm_alarm_time *cfg; + struct scmi_xfer *t; + int ret; + + if (rtc_id >= pi->nr_rtc) + return -EINVAL; + + ret = ph->xops->xfer_get_init(ph, IMX_BBM_RTC_ALARM_SET, sizeof(*cfg), 0, &t); + if (ret) + return ret; + + cfg = t->tx.buf; + cfg->id = cpu_to_le32(rtc_id); + cfg->flags = SCMI_IMX_BBM_RTC_ALARM_ENABLE_FLAG; + cfg->value_low = cpu_to_le32(lower_32_bits(sec)); + cfg->value_high = cpu_to_le32(upper_32_bits(sec)); + + ret = ph->xops->do_xfer(ph, t); + + ph->xops->xfer_put(ph, t); + + return ret; +} + +static int scmi_imx_bbm_button_get(const struct scmi_protocol_handle *ph, u32 *state) +{ + struct scmi_xfer *t; + int ret; + + ret = ph->xops->xfer_get_init(ph, IMX_BBM_BUTTON_GET, 0, sizeof(u32), &t); + if (ret) + return ret; + + ret = ph->xops->do_xfer(ph, t); + if (!ret) + *state = get_unaligned_le32(t->rx.buf); + + ph->xops->xfer_put(ph, t); + + return ret; +} + +static const struct scmi_imx_bbm_proto_ops scmi_imx_bbm_proto_ops = { + .rtc_time_get = scmi_imx_bbm_rtc_time_get, + .rtc_time_set = scmi_imx_bbm_rtc_time_set, + .rtc_alarm_set = scmi_imx_bbm_rtc_alarm_set, + .button_get = scmi_imx_bbm_button_get, +}; + +static int scmi_imx_bbm_protocol_init(const struct scmi_protocol_handle *ph) +{ + u32 version; + int ret; + struct scmi_imx_bbm_info *binfo; + + ret = ph->xops->version_get(ph, &version); + if (ret) + return ret; + + dev_info(ph->dev, "NXP SM BBM Version %d.%d\n", + PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version)); + + binfo = devm_kzalloc(ph->dev, sizeof(*binfo), GFP_KERNEL); + if (!binfo) + return -ENOMEM; + + ret = scmi_imx_bbm_attributes_get(ph, binfo); + if (ret) + return ret; + + return ph->set_priv(ph, binfo, version); +} + +static const struct scmi_protocol scmi_imx_bbm = { + .id = SCMI_PROTOCOL_IMX_BBM, + .owner = THIS_MODULE, + .instance_init = &scmi_imx_bbm_protocol_init, + .ops = &scmi_imx_bbm_proto_ops, + .events = &scmi_imx_bbm_protocol_events, + .supported_version = SCMI_PROTOCOL_SUPPORTED_VERSION, + .vendor_id = "NXP", + .sub_vendor_id = "IMX", +}; +module_scmi_protocol(scmi_imx_bbm); diff --git a/include/linux/scmi_imx_protocol.h b/include/linux/scmi_imx_protocol.h new file mode 100644 index 000000000000..e59aedaa4aec --- /dev/null +++ b/include/linux/scmi_imx_protocol.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * SCMI Message Protocol driver NXP extension header + * + * Copyright 2024 NXP. + */ + +#ifndef _LINUX_SCMI_NXP_PROTOCOL_H +#define _LINUX_SCMI_NXP_PROTOCOL_H + +#include +#include +#include +#include + +enum scmi_nxp_protocol { + SCMI_PROTOCOL_IMX_BBM = 0x81, +}; + +struct scmi_imx_bbm_proto_ops { + int (*rtc_time_set)(const struct scmi_protocol_handle *ph, u32 id, + uint64_t sec); + int (*rtc_time_get)(const struct scmi_protocol_handle *ph, u32 id, + u64 *val); + int (*rtc_alarm_set)(const struct scmi_protocol_handle *ph, u32 id, + u64 sec); + int (*button_get)(const struct scmi_protocol_handle *ph, u32 *state); +}; + +enum scmi_nxp_notification_events { + SCMI_EVENT_IMX_BBM_RTC = 0x0, + SCMI_EVENT_IMX_BBM_BUTTON = 0x1, +}; + +struct scmi_imx_bbm_notif_report { + bool is_rtc; + bool is_button; + ktime_t timestamp; + unsigned int rtc_id; + unsigned int rtc_evt; +}; +#endif