From patchwork Fri Apr 12 10:47:10 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: 13627587 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2061.outbound.protection.outlook.com [40.107.20.61]) (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 67B1954FA2 for ; Fri, 12 Apr 2024 10:39:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.61 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712918378; cv=fail; b=g64e/ySaFACjjKGOe70oNvUOO0QX16K+IedJqyPatzShqh+lyFHPLucZlXHmwblAdVxzMk71Zk+tBR4m9LtdfeREjW/ZYF1ICHfQ5xUc0diQvX89pZcNZPEAFnIjlW2gYcaBFVkOwu8nTevrD7uxcSjMminVQ84ya0hZdiCfGvg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712918378; c=relaxed/simple; bh=C4070NxHXEdRIlRISs0kV2A5J6MbWwBKttj8TBpWHOE=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=cRasBDNEprhcfBz6W7lTxQup7fkl5vB6eSdCeifAzhOxQ446MH5VTQve0fYT9iYzN+t2Na1GoVX6+FNHg/lcEVaCJzqOOB1qso59QWanjOGzjKV/x2qM67qs8hYLv/qgM9oS+UbfDYUHWgGCh1Ai5Wnd6Fa0UbOA0Ejr84u8t1k= 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=fgSVhAZJ; arc=fail smtp.client-ip=40.107.20.61 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="fgSVhAZJ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CIAGSMSkAslz5UmqUyzLR+edIgEvwlsxQMJ1dxen4FUt/3a9YcFY6eHQnHEg7ibbFhVRumh+KLX8YB44NI0uAWeHrPS+ivSfFJ5z0QuqwoilZI/4P6Cj6kcdrvGsBWud4fUks+29E691bVnxGD6K4bxMA4zNROnF93fiPqhzz2+Yn1bxwzfdNuKmjFuYHAPowqcZ50WgJUxcN2kdpmVBYIyyoveD3rtBgdmsr2UErxgxKOoxtDm7s1lkiV1GgAXVeoJQ9FfJvn3mcu9KUr+ZF/2XuuGxN/04Ryot78Qb2ipx87SdEtRJIKIL2DWV6E+6Kh6E2Sp6D3ivoviXHk3TYw== 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=G6TFiOzYXzLz97ME1+nCCA5wS2Nvj09TuZS0aNywfIo=; b=DmIm/OeZ0fur6t3FPLMKrbBYBY95yU2CTRLBE+Im2rxyMRZtxy55eC/dw6y2nRKuN9oQnpnXGHzV5MfcExtRi3HGA8mZFFCRGAd0uVVjVhM23WUmuzoRJwxw7r/mRH0ppZAFTQRu7TQOkPoRWxy8JP7PUaCaJI4HRJPMhOjaauRzqzgBoMWGulJWaELEckB8rh7MlkzeaerQZJZx51a6H/90727jMdJyD+RTzctRUoY+CLpa6z0BcynDmrxypacjXIRyO7IW35bocM52/h2ur/DOr6z+H5QSw6Cv/oRr3TAo0YYxRYu7u4VaBxZE1clYgEneGW7s7uhq/dUAsrpRlA== 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=G6TFiOzYXzLz97ME1+nCCA5wS2Nvj09TuZS0aNywfIo=; b=fgSVhAZJojgA6BsxHtLcpAsvcwlrvF/UXl1kFvDi7ajfzWKO+/52LxxtV8HhOy+pSqY3Q4D6Zv0Xyuii7Cf4OlZJ5UgS75qOu0aXaBgwqGGZRPqI7DmI2kohkfj6MyRp/Scpv8dePNc/d1UN3h3PClXCgwBPOK2bSqWAFDOZNTU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from PA4PR04MB9416.eurprd04.prod.outlook.com (2603:10a6:102:2ab::21) by PA4PR04MB7839.eurprd04.prod.outlook.com (2603:10a6:102:c9::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Fri, 12 Apr 2024 10:39:34 +0000 Received: from PA4PR04MB9416.eurprd04.prod.outlook.com ([fe80::9d65:d883:afbd:7f54]) by PA4PR04MB9416.eurprd04.prod.outlook.com ([fe80::9d65:d883:afbd:7f54%3]) with mapi id 15.20.7409.039; Fri, 12 Apr 2024 10:39:34 +0000 From: "Peng Fan (OSS)" Date: Fri, 12 Apr 2024 18:47:10 +0800 Subject: [PATCH v3 4/6] firmware: arm_scmi: add initial support for i.MX MISC protocol Message-Id: <20240412-imx95-bbm-misc-v2-v3-4-4380a4070980@nxp.com> References: <20240412-imx95-bbm-misc-v2-v3-0-4380a4070980@nxp.com> In-Reply-To: <20240412-imx95-bbm-misc-v2-v3-0-4380a4070980@nxp.com> To: Jonathan Corbet , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Sudeep Holla , Cristian Marussi Cc: Peng Fan , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1712918849; l=11303; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=CgPGaPP+YJI903GGXjqbanZ6FzgOXN8sDyrSQkwxsuo=; b=nO2OqQETwxI/cFUeaQfBal7d7p+xBU5KcKwUO8yYPYkyHd/FqWY3vjbgQUn7I11/bMM5+eWwJ XhqnEPuZQ1DC060KgpZyICGd6x79BCjPmj4Zl12FiYPO0YYnG0DcyXY X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2PR06CA0243.apcprd06.prod.outlook.com (2603:1096:4:ac::27) To PA4PR04MB9416.eurprd04.prod.outlook.com (2603:10a6:102:2ab::21) 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: PA4PR04MB9416:EE_|PA4PR04MB7839:EE_ X-MS-Office365-Filtering-Correlation-Id: 0db023f7-b29d-495b-ceb3-08dc5adcd828 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Hze5dTG15AT4/CTZnfMD74BUT8DQcHSak7LHtdI77KJ3xJrABIY+8JollP1F/ELAvy7aQspIGFQiAnGF+rE5+Y6xpmqOQPew7fhZdXTTltdZs9wY/116KB3guelcYE6SR38fxBHHFS2lxdzWhuBjFNnjQAd/UXPoRImcgrk2+mv9reFobUV88G0/Z0mhVOsj273zB2cT8OYzlnCG29Vs+tXhvrRlP++pspGijO9k4wllNC8gZzkq6lmGX7MJb6pmQL4L6FRUnW5RgMrVlkgbJGTCcf3DwzYTQ57S8V9kWBseWQg30VzmmV/NNcrfCyylhjkMLBFskucDLsTx+fbA9LTyS7Q6Vb6IKbWF9vbMG6gbbRi5A+U8c7FUfhTNQPUlQ99Th6fRiLuXZYg3gZ1xuHazrEli/1t8L4qHGffCibfqs3pRVGY7PhNheNVA9ZlagCoTibMgQwM9jEWb0I7b0RqoGMYbPPjA9mcfDaP7hdZi+UF/jyY5GQs6tM6EZMQPUR2t6NfSW+w6ko3Of0NzEa4K9awU1LSRcipgY4bRFA464hJPysKzjevniRFKSlmm6qkLn7+Xmt38RUsUbDyz50pJmvMxfYrt8W/b0PZkk+h7UAcYrc4soINQC4+eFqlvy8FhNzZndEu4M5hMDAuef8uDEMdGKbcNpcFln1sxtVmg0K9gKHB3KisCrc7EimFo2HVlfWNRLpfSVgFjnme3wJRefpsXHVpcqImRmeNJokU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PA4PR04MB9416.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(52116005)(1800799015)(376005)(366007)(921011)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?PNQr4KrfSFuObXVlfJxNW9zaR7bq?= =?utf-8?q?dHgTO7/S6Bn5NyAlN/VEENv9h6+g6opHcGiF2e4aPRMdvbxZ3MiUjxwMEaHpMZSfO?= =?utf-8?q?rxfuPyY/Wg0zwAyxx6HiKKnStSJWKgyRBx2obrmopi3/xGLeUxyujfDYg8atKjDZv?= =?utf-8?q?ATTR7lE7/5Iw2NfKUfpVYyaojFZFWdDnNGr87JIGgFY1MSqFRhsoMTYCT9tXdgzIs?= =?utf-8?q?C/SKa2oeagqSP4lyJmdM8Z3R0CYScEuHSD+3p22qIbvlkEb8vofBop8hdO1kERCJJ?= =?utf-8?q?94tQloM+0gkVnx9CknT1PcPF6Crt8s+U0tt0EcTU8tNV9VglbLVgnWHRfONMveShV?= =?utf-8?q?3BXu6yIfJkHXoRAi3LYLl2tixTA5d7T/xNUV0xoE0nTr6Ve40SF/W6KW/LNUFH6g4?= =?utf-8?q?STvjDoSTtyuT3SlRAi4qLUiEgzO96pHx78aOJa/CsgYeMaewRsiaJlXEJemrGr6vu?= =?utf-8?q?AuLybl9nwHgH74xF4HF1BkX885Xx0vkMRSXDpgojFHZ9fi2kw4MM6wS3kjT1fwJUh?= =?utf-8?q?KlKCMI2sr4YMEbPPkln0CHYbm04JQJeoWyjQ9W16OWiWTkNU7gx+716XD4jvV6hET?= =?utf-8?q?ur1bPBnWtZUrtG7dIQVcx0fU1X1515/ypqtPMFUIc7H5xgtmog7/Fj8Q1cwPdeei9?= =?utf-8?q?tGShoKpFQRlK+U7BaZYd4+PiHY/UwfxUYvFyb2huyOfwmNxyAH+9S+O4ZWBSGJb/h?= =?utf-8?q?XWnWEf9/vrsZM40exNdYzaJCCVZYOkFJaavigiA1XLqDA6dsNicawKXu29vwLdf7B?= =?utf-8?q?ud77k2AMAqUrpZeTsPE+43MezWPmV8lLmtYoi8PLt7OvyjHMBMy1uUDjDpatKB+3u?= =?utf-8?q?RfkJsLmQ39dEAHjoyW44ItOoxsgk4vx3/isdTIVFrWedwpyJ3YPAYA/LmvyRG+sf2?= =?utf-8?q?3UifJA77jdsxd6Sf5XKJBE6x3Q9qc0qTT3T8Ig0egu7N35IXsoqTyHHgiez7F001S?= =?utf-8?q?dxGhk9u7Wqt+ycpG6e5kyeoZwNqVlnnBmEbB9hbX7pL1+JCJS37JIXGA9r8sfJmxL?= =?utf-8?q?s2ne62LBaT1hDItxlqCqsr7PvFeDsWaDX9AM/TZb37Zx+RrtjRdfD/9lqRYmIbNH+?= =?utf-8?q?8XF9WVX/2ad52fzE3kZ9/Lj3e8ZRfaMjhudmYSWdZ6b6oiSK1IJwJi225K8f7sVXR?= =?utf-8?q?3jy6Jv6SxnqaBFMQOyvILDRrqsVgffixfQ0eB16bCUmSRxO67lM33174Zgpyv7Kug?= =?utf-8?q?n7crkZJYF+20Xh4INYrfh0C3Kd2RXsnwoIrFfPkrLBjHN8OGSox1RIl/JI2gYvcW8?= =?utf-8?q?3o4FLFZKZo277vFUKx4yOr7YrOWEJUtJywG2fbNM9oVhkHnYeYfZnvl+aStt7IIFb?= =?utf-8?q?pc61AQXH67Kudqbl3TXnXca/dliUIsS27rZMP80T6IOgZ6ptpZdIab7MlHZUzMRhY?= =?utf-8?q?XL88qqBYu1V9lOTQZjJp0wiyNUKdUbyOybYy6FTbEtnZav4xnHXsXl9A1tnFa46X8?= =?utf-8?q?H+SoNn/hpFvx2YOXgfOUaAzMdK3NqKHCeLppJFNyozODp9uhDaXyhVZPNX5k6v9nF?= =?utf-8?q?XtfEprRVHAru?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0db023f7-b29d-495b-ceb3-08dc5adcd828 X-MS-Exchange-CrossTenant-AuthSource: PA4PR04MB9416.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2024 10:39:34.6575 (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: 9/YX4gJWSvKUhKxBT3zn5cUsfo8KVMipiEsGlsptBcy4fMPeS3V32Y1ggamwxaRJrP639x5cunOqU8x65rhsEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7839 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. Signed-off-by: Peng Fan --- drivers/firmware/arm_scmi/Kconfig | 10 ++ drivers/firmware/arm_scmi/Makefile | 1 + drivers/firmware/arm_scmi/imx-sm-misc.c | 305 ++++++++++++++++++++++++++++++++ include/linux/scmi_imx_protocol.h | 17 ++ 4 files changed, 333 insertions(+) diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig index 56d11c9d9f47..bfeae92f6420 100644 --- a/drivers/firmware/arm_scmi/Kconfig +++ b/drivers/firmware/arm_scmi/Kconfig @@ -191,3 +191,13 @@ config IMX_SCMI_BBM_EXT 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. diff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi/Makefile index 327687acf857..a23fde721222 100644 --- a/drivers/firmware/arm_scmi/Makefile +++ b/drivers/firmware/arm_scmi/Makefile @@ -12,6 +12,7 @@ scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_VIRTIO) += virtio.o scmi-transport-$(CONFIG_ARM_SCMI_TRANSPORT_OPTEE) += optee.o scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o system.o voltage.o powercap.o scmi-protocols-$(CONFIG_IMX_SCMI_BBM_EXT) += imx-sm-bbm.o +scmi-protocols-$(CONFIG_IMX_SCMI_MISC_EXT) += imx-sm-misc.o scmi-module-objs := $(scmi-driver-y) $(scmi-protocols-y) $(scmi-transport-y) obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-core.o diff --git a/drivers/firmware/arm_scmi/imx-sm-misc.c b/drivers/firmware/arm_scmi/imx-sm-misc.c new file mode 100644 index 000000000000..1b0ec2281518 --- /dev/null +++ b/drivers/firmware/arm_scmi/imx-sm-misc.c @@ -0,0 +1,305 @@ +// 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 + +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[MISC_MAX_VAL]; +}; + +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); + + 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 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; + + ret = scmi_imx_misc_ctrl_notify(ph, src_id, enable ? 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 int scmi_imx_misc_ctrl_get_num_sources(const struct scmi_protocol_handle *ph) +{ + return GENMASK(15, 0); +} + +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; + *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 = { + .get_num_sources = scmi_imx_misc_ctrl_get_num_sources, + .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_DISABLED, + .max_payld_sz = sizeof(struct scmi_imx_misc_ctrl_notify_payld), + .max_report_sz = sizeof(struct scmi_imx_misc_ctrl_notify_report), + }, + { + .id = SCMI_EVENT_IMX_MISC_CONTROL_FALLING_EDGE, + .max_payld_sz = sizeof(struct scmi_imx_misc_ctrl_notify_payld), + .max_report_sz = sizeof(struct scmi_imx_misc_ctrl_notify_report), + }, + { + .id = SCMI_EVENT_IMX_MISC_CONTROL_RISING_EDGE, + .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), +}; + +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 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; + + 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); + for (i = 0; i < *num && i < MISC_MAX_VAL; 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; + + ret = scmi_imx_misc_ctrl_validate_id(ph, ctrl_id); + if (ret) + return ret; + + if (num > MISC_MAX_VAL) + 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, +}; + +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, +}; +module_scmi_protocol(scmi_imx_misc); diff --git a/include/linux/scmi_imx_protocol.h b/include/linux/scmi_imx_protocol.h index 90ce011a4429..a69bd4a20f0f 100644 --- a/include/linux/scmi_imx_protocol.h +++ b/include/linux/scmi_imx_protocol.h @@ -13,8 +13,14 @@ #include #include +#define SCMI_PAYLOAD_LEN 100 + +#define SCMI_ARRAY(X, Y) ((SCMI_PAYLOAD_LEN - (X)) / sizeof(Y)) +#define MISC_MAX_VAL SCMI_ARRAY(8, uint32_t) + enum scmi_nxp_protocol { SCMI_PROTOCOL_IMX_BBM = 0x81, + SCMI_PROTOCOL_IMX_MISC = 0x84, }; struct scmi_imx_bbm_proto_ops { @@ -42,4 +48,15 @@ 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); +}; #endif