From patchwork Fri Aug 23 09:05:19 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: 13774789 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2056.outbound.protection.outlook.com [40.107.21.56]) (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 F1FF114B97B for ; Fri, 23 Aug 2024 08:57:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.56 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724403426; cv=fail; b=gyZ9wondq+uaddAosWOG1RN/Tjc4P/vH/IZfZ2EIFJ0U9jdN2LIR3QmVb81xzNHFRVbWedRgr8QMsHpy00YVrAHJfNwQfwGLfKisRxYcMkQBpqAFxNCHou2wgz+P4j0Ag9vf0g/9+Ok11VvrUJXQDXlvsTTaMdsxwVurkcl+ibQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724403426; c=relaxed/simple; bh=YzX+egaADaOvLdccNeRElzHXSKX3T40Ex3hk4ikMEtI=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=QfM5QXuqa3MASayWeG7/O4Bdp2zGMnBAbxti9dpSC4i2XUbw1hBLCHpecvEguHESvf7Kc9ruCf02iG3TzknS5edOrUBfqqH7zLxM38IvzF/APYtSPTJ4Ahzog7/lODvXgkj4F4Ic9Prcr+ntTpRuswRLLtv0M1wOWdM9JMQlHuw= 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=OBs3h10f; arc=fail smtp.client-ip=40.107.21.56 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="OBs3h10f" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=B2ODFO3Dz7gEtNdfi4cccNtwf2eCqIV5rbnMKj1DB1eDyyBzPC4F/eZSgHUmYkhtMrMHR0vqBt1d8oGFpJjuqVSqcEZOukhEqko5IAYdUS7HDf6F9A1xYSut/jRBNDasyy7OUdyA/h+OLQ2P/u+6+cg87VXrfnCMZKahAaiQPo2ArF6CmxMSjWUKxKJiMcKZ1+fUraNt5uZMgF6PA8V9Q3MHGvMl7Jyv5hDVL75eHRdjXapTnX7S2tRhbZrosTU2jv1POfHaGQXtyVWVYN6SedaiywQVJGmgFDlqN+l5fJfCGGu09O4pcOhSlGyQyAcmd5oWLXA9QsiF/e9fMKDK0g== 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=lKPhPaPubDMB7T0nU+qx5zkB3qjRgawlZplzI8gYwOE=; b=sytRDX4zcztZ1uyqQoouRM+pVOn8+cnrn6i8j6XeZWjSmBtgdxYWjldSvWObnVbZoamUM85zhuIHY6iLOz0Ts9NEZaxOcpisivrYkAkfiocY8sHnouT5XKma0q2QMmwwLbrd/09ZHkDUelVUGB3GD+iEJQqcyzKsxpFkqoU0otLX4Yk+6E9XX5rCOp00+7wzDKvhP0cX9TTFfOM4lvhSNAzunoQym+/Y60SNIeXZ/gKTRaqu0yHer1+/TkgbBEKFageIhNLVBKdHAk08eo1pYH2EVkA3Cca2HiaOYYovADwa/1wMrYVUX71CtDoLqPwLcCZ5KvVHhX5YapWAyl8p2g== 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=lKPhPaPubDMB7T0nU+qx5zkB3qjRgawlZplzI8gYwOE=; b=OBs3h10f4Bm2pmFM3H9Fvmsp7tRhYj6mReJe8fNGNKebdTgcHr5P3GXJMUc+iPq7BJO1Ch0D7z9AjCthz7rDysTREFn4SBVz1XQv1dVbPa7lu+6Fh3+wQ0RyE4GPLpp75Ey0VELXRMTLucZ9Y0D/s6o+DX+OL5T0p42HjmgqK0EDpZGysVptFLNghXTx3y7vE/xCn/ym3OmP4nDSGjANp1/bf4C1pSR9RQXkauCWfl5CFdRduNTjF0A6zTCx2Q6F1PqPriK6eT7HPXRUQliH2gYe8gkY3QiU4XAG+qVTalUQPtAIryPn16YrVCa5dlOY6LaJ5iTste3UaLv4rUk5gA== 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 PA1PR04MB10892.eurprd04.prod.outlook.com (2603:10a6:102:488::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.19; Fri, 23 Aug 2024 08:57:00 +0000 Received: from PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630]) by PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630%6]) with mapi id 15.20.7897.014; Fri, 23 Aug 2024 08:57:00 +0000 From: "Peng Fan (OSS)" Date: Fri, 23 Aug 2024 17:05:19 +0800 Subject: [PATCH v8 3/7] firmware: arm_scmi: add initial support for i.MX MISC protocol Message-Id: <20240823-imx95-bbm-misc-v2-v8-3-e600ed9e9271@nxp.com> References: <20240823-imx95-bbm-misc-v2-v8-0-e600ed9e9271@nxp.com> In-Reply-To: <20240823-imx95-bbm-misc-v2-v8-0-e600ed9e9271@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=1724403944; l=11659; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=N3sn+AcOHmdt2ArwuyQeJTgG5UtWBpIYOiQIExKZQWY=; b=+bQv8asYhO7Fm7whDpt8aPxtyaIvZsRhrCgVf2JMVI4yIEd1YJxYMc3r2MOfRGtDbJeGGtiR2 qMkfi2CA//eDXwMSmUxZpHuLP8Ylo3QPI/Ax2XG6PuJK09i2HCpSYgs X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2PR01CA0173.apcprd01.prod.exchangelabs.com (2603:1096:4:28::29) To PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) 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: PAXPR04MB8459:EE_|PA1PR04MB10892:EE_ X-MS-Office365-Filtering-Correlation-Id: 53ae84dc-a6af-462e-0e50-08dcc3518d16 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|376014|1800799024|7416014|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?jQ3RLRkraqwIFNHtN//1/T8VjAV6JDG?= =?utf-8?q?WG8Im1eb2pS1OaKqLkmBqCznbd3eG0Vb4DfMNHtw9tIFQqsAL4FV6puoLLLC47l8A?= =?utf-8?q?+iWJLo1ATOVtQ+DyDNApmON2hyqzK6eekr438jKK2CQscowvG3GGBuWkiB/PyIh7B?= =?utf-8?q?6tXqjHal09Oh4MFuKOMGViSA7fbpTMmwhN2tiCoR5eBFi8Da8dyCdNbhim1RPXUg3?= =?utf-8?q?oNm5JLhp06Z5lAWvw7845eMYeIGRd0IxvyterkxwB+mhUaORdi6UZXOEbHlzAz+6N?= =?utf-8?q?75q01w5RkFygngZ5fSoHm9Ab4Ir0lxvms6NRSa0a6ZMlNnf15+u2L8pFti5PiMTPb?= =?utf-8?q?nyKxYAhOuFQDq/gcsmGN92vxZWv0FyuY6lIBdrmyGbhnxQ7R6F9pQgbWq1EGgvtao?= =?utf-8?q?MQjmdppkyw63Nr7zssc3u4/8IYaJ+gBpxvO03z0queTiAsooFiCb+iOc2vuLpzXNQ?= =?utf-8?q?y9DpTe9bL6F47I7DziXW0tDNmzjGWc+LVQzmQeFmbxqfsettiugOQgf5OjvHyKLil?= =?utf-8?q?qVK7xhjF3Mf+b7dO81S7bQhJaM0FJ0C/KxqE5SZXngWWXUYcPkCR31Va3p3OMoUFa?= =?utf-8?q?zLjkcZc8aa6FRQVYD5j9bygVPY4gPtzJkpGcoQImTZjIiwqF4bQ52Xajm2mcqTF/P?= =?utf-8?q?fs78WuOeNCxiDmFOKHG7/yHOw/pIvdb/YGMXHhVYP2GtIIFjR6aiXSIP95lcTnyRi?= =?utf-8?q?paPJ+zCd3VJ3kEKRlWLbd7igPfUL1xHRBkxI3SE28//OdLLk1fix6+lNfBk4G4u5M?= =?utf-8?q?EQWQoEVdX9xQ9IQpPVM0jG4jpNmx2u9Y/UsM9Oz+uncLOO87fCjRYyKOCiLtAu36k?= =?utf-8?q?H1o6ZGc0pwIrcn/dhjmAHBnx5amus1r+/ZQnsGzDpqNu3tK37d2XIfjcZ9Xc6QhX3?= =?utf-8?q?v/8q3dRCiuMvqgNQt43SX7UtvPt57erfWuc99KF2cCQPelLdokZ2sk0Qv2uP5NHsj?= =?utf-8?q?S7HqnjAAFXiH60O0C0BGFjtDX065QGoYt+LpjDgzG9RAoMb6QH4lOVu9Xu8FjCzvS?= =?utf-8?q?TS8WnEd2/d8HGfvlQGHZw6aXDbparzy1lVvn0ocAYP+oswUydeuouaLmd0An3gKwz?= =?utf-8?q?Fva/FnJdo7eRARLszAQOgpDBXQNcOhQGz0q0waHCQbY8SxWfRt7H0IAVGsk4vBux5?= =?utf-8?q?6GXbZ6BaLnxJNOPMwO1TWXkeJAZ9jOw25wsVoCDXBAwDbBCwJl2j9OteUEzrTcvUv?= =?utf-8?q?hi46jMT5XJUVFtj5tWy2nUFsFMTl8mPZsW8Q+fhtdq/0/c6PTEG23zkYbvIucUCqo?= =?utf-8?q?Q+ZiIzXfkWiEpG38h9MvRlsoilDRHbCKfQK/PdMZ5fNNjmactma+EBMRglyzbVfav?= =?utf-8?q?1RFKKQ0+Izk+szZp7a9qoNIfHjQlpPYPD6EBq2B/ikVCbeOcD4W7tLQ=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)(376014)(1800799024)(7416014)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?JY920e159EuOzIBiMAn1qIxc2qo/?= =?utf-8?q?1s9qHqQ154K3cxaKmUm61GiBVQ3hz0NpAmreSwfYymmDqkHEO0TATx2TLhJuIQY9f?= =?utf-8?q?Nofow2wwslRgO2ebA/Gfv3mw6rQ9NfgcwujwFhrDA3dfINIU13htbvgqkLzkmPu8Y?= =?utf-8?q?Yu1ot8M0ghxIt+qyBLev6aiaffVSYg4ADYcFKaiLESJXp13aj2tJpkNJRGbJgbpnb?= =?utf-8?q?FmRqO5FjE4DlDjSmQuvx3Y7Ze2UH69XRVcueHSJzizTh/Os6Pc7TncsUzNIjwAYvU?= =?utf-8?q?u3HoR8yjt0EZby72LFCVXTY7Ac9ifeevTeqPIGNdUjhvP723boH7qUT97ITW+acZm?= =?utf-8?q?4YhoB20djQzdHpxBYKLJdfCtRUOn8n6ACUIHV5pV2AtXbhDQaawFJRXsIL46HKTcr?= =?utf-8?q?BKZXGinN6bNRHyU91gDa4cpuVvCqhYIGnb/8RY9zaVL3aA9/KoWvvlIjNFVAezHYX?= =?utf-8?q?t/N7+d6MOUmmvt9OGzg6JKVHubqyjCFSpS2QB5HP+oL0ZHHktR56tzFC+QFG66gzY?= =?utf-8?q?eowSO2hIZoFX0nCQsQe0D9kJnoUw/I4uyTB6L+zwSNLtUj4+qfGPSTsRihniHIPC8?= =?utf-8?q?qa2JfUSVPjV+Qtq90GCLmXxD8xmo6Z474mUrB1Y00GzbC8YvNG96/sRULmHAPm7xP?= =?utf-8?q?TtVHEceiDznVTkCGzOQnO/ncW2ZjaiZtaVvP8eLuZ09IRU3dKB0V0amSrzFH9CRx4?= =?utf-8?q?f2qP0iws/tCOEu15AN7ttMzqY6YrGmGhrtj41aQ1m2/8jVr11BA9Or2o9e7HRO5gx?= =?utf-8?q?TQ/wpei/Po0yp10w/NzK60Kw9E3cNhud3HnhEKvwA0YV1tpTlBpnDAb0yAOQCKVjQ?= =?utf-8?q?6WuXG2wx24azzlR+dhuY36bf8xG1CH3Jfgu2Mmhb1VbBa23qzIlHGiiunjR3iPY9P?= =?utf-8?q?KtIqWTRQjjllpyKOUXzf+tN/vDXjWC4Dgeo/VH2SE3tqK6jkYNAb0uvT4JFFyg/mz?= =?utf-8?q?VrDt+tudzhDcLmHKx0r9r8GAvnvxSB9jrySgTxAdNCwOnfDbXfgl7zpfyDa060BY4?= =?utf-8?q?BO9PLL+TOqA3r5CQfzj/xBRXZ/jfW8cPaqrZVgVV+oXmoz4x+MF9KnNfly2ovzS0+?= =?utf-8?q?XojYuMypZjLxsAU563SX2Ae+rypt3RFhDAWTsQRm0HfebRruR29EQFDyQOu2MUxGp?= =?utf-8?q?PmtZDtaovu8FWBkjW9GDULFo2Z88N+syQVXnLAXsGqJSvY88BPdWzHGVpSxvri8jX?= =?utf-8?q?lPRcom+kmrU/QZJ9a4mLf+fwtXeclvvShIBVDjs8pRcp5H6nN39fZBxsVSFQpjJoz?= =?utf-8?q?rYeBeZQWI5rYss3ngCJk1kHWjsj0bdUM1a41O4L9B5Z1UK9ShiUAStcI26NzCthQR?= =?utf-8?q?8ANSMCCBHqZwOjSxBIBd+Ir631t6m6Mp6dwSkl0bqHWrPAQqvFniaaXrUIQqkXkfW?= =?utf-8?q?45Db1/vUMHY/rEUMzW80bKvZM8Js2zWA+64khhMH4tZBU/THw4u16I428YPgtHOH0?= =?utf-8?q?7sgWMDFHKyUxCPe7yn2aNOUZg3pk2eX1hlFfbaud40Qs+JtD6MRvSnzA3YYSNu2Dd?= =?utf-8?q?gYEQSOyhuI/w?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 53ae84dc-a6af-462e-0e50-08dcc3518d16 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 08:57:00.7468 (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: fCkoyp6Ku8xu+vmUQ8I02vWTJfB+CJfMafTnGF/88fJKBF+a4GAr6XXdewe43rfwxujCYUbxUDPFTUPit9ZF8g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA1PR04MB10892 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/vendors/imx/Kconfig | 10 + drivers/firmware/arm_scmi/vendors/imx/Makefile | 1 + .../firmware/arm_scmi/vendors/imx/imx-sm-misc.c | 315 +++++++++++++++++++++ include/linux/scmi_imx_protocol.h | 17 ++ 4 files changed, 343 insertions(+) diff --git a/drivers/firmware/arm_scmi/vendors/imx/Kconfig b/drivers/firmware/arm_scmi/vendors/imx/Kconfig index 51ccbd038627..e9d015859eaa 100644 --- a/drivers/firmware/arm_scmi/vendors/imx/Kconfig +++ b/drivers/firmware/arm_scmi/vendors/imx/Kconfig @@ -9,5 +9,15 @@ config IMX_SCMI_BBM_EXT This enables i.MX System BBM control logic which supports RTC and BUTTON. + 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/vendors/imx/Makefile b/drivers/firmware/arm_scmi/vendors/imx/Makefile index a7dbdd20dbb9..d3ee6d544924 100644 --- a/drivers/firmware/arm_scmi/vendors/imx/Makefile +++ b/drivers/firmware/arm_scmi/vendors/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/vendors/imx/imx-sm-misc.c b/drivers/firmware/arm_scmi/vendors/imx/imx-sm-misc.c new file mode 100644 index 000000000000..0e93a81e579a --- /dev/null +++ b/drivers/firmware/arm_scmi/vendors/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