From patchwork Fri Apr 5 12:39:28 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: 13619019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1E633CD11C2 for ; Fri, 5 Apr 2024 12:32:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To:In-Reply-To: References:Message-Id:Subject:Date:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=1nSskgTDf6Y7FLTjJEAAQp4UdijMfcjRStDmFGh80kg=; b=b+7EwxARgSI9iF5WKc0j2piulW aEyRoolhEh3SeOKhvlg5Fbg6uS9hiS9RdqNleZLgSKKlzlrj15lUNlcuj0okoAXtFba9nB2HXaoUf 78RRIGuzleED3Q19zMQ/QG9JUMowqhRZa3We8mxjFv62K6cIvtvvCEszpBtG1T9m1IHaWYyVRYd+2 AIkJokmNsUbXmJUmri1Xjpc5FGkIua7JxQeAEvaTSVWhcpe3+dirVu6NUxnai4vGu9yFGqBrp5jXw Zf2VTPvQjvyHG+w6lS1ZI5v/obuPuMM91IAbUCVWH8ivOMIDzocRfrC9G9cM5AyhIHavGywvEAVRg QkJbS6pg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsijz-00000006x5k-2lZi; Fri, 05 Apr 2024 12:32:19 +0000 Received: from mail-db8eur05on20722.outbound.protection.outlook.com ([2a01:111:f400:7e1a::722] helo=EUR05-DB8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsijs-00000006wot-35lA for linux-arm-kernel@lists.infradead.org; Fri, 05 Apr 2024 12:32:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YbOR2Bk3jOsCSs07kfbVXjxapqIve1OUfrIwTqf9LpkAocu+NwCldVvikMkLuzZUK7ng9ie8bW9GjnxUaSzYFNoQVp27/RC6KgkbFTR10gjNcg46OVkCWH6ALHhe2Eu7YiBMWJcWyZLjaApZEzgzsWdXyZo71Kkig5Xa1PMuGcyubbI1Y+s+f6zbo2UwW1vHHo5C0+KWJ5Vh51b4atDEMgAPLQ80r5cwUKMjauIfADnF4VQ8TKu6icKDMEOSO7xM2bLJLdOslPaq1Pd2k1xPm+nE64P9tS9glnhJujbugIjnt7LMW4WwIR17jwfwreYR7JdZ/zhMM2CexUveK/vuew== 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=qmLEKLDgTbuTKcvdN45vKFWC6Ra3feV6bbsCVFoin+Q=; b=Uu70MlunmDkq2ZwIrtzOtHLFpF5E6jJhSzJa3/rv6r8wiXXsSzIsyqcSEZP60/fzqppRuOc0Pw8YjAspdFMa5ksOQYwVFgyx+I7lWijMTfTh+lZZKwSeT9IyuyOXvjMJ5jFEsfY3tdrt/YW1cwxfGx24ucrRMJ5o6bLyE6SUorp4ZditBeI5FAqu9Iu80WzepuZRdH3Gz9B3qFkRV8TNDMupMmpTcq1EFdTWVcnXgFw7Iw0R+R90/+/McGiiqL2q7QvIQLsDcBJwFU4rRrwhmuMAzRJnwu3dxv24+BNKzU7ko0vWpqnQ1WwdD3GO7rF7t1dxd2PR0hCLU9G1XqJJIA== 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=qmLEKLDgTbuTKcvdN45vKFWC6Ra3feV6bbsCVFoin+Q=; b=NUVhu3pakuKSiULZ/H7pA7EXuIc/FJYUzu6cNYAqlPOcxo28ELyxPDw4DFqQiFKkllOQ+vMfq5b91B92JNmU2GY4/rljf7dcQE/tVcJHIujiUqZqhKKUS0JAGHLuDiaJRqmtmmwW94VJnsZ4zfX3IRFZYXV5ZVG+Q83SoTKhJhE= Received: from DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) by PA4PR04MB7744.eurprd04.prod.outlook.com (2603:10a6:102:c9::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Fri, 5 Apr 2024 12:32:03 +0000 Received: from DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::d30b:44e7:e78e:662d]) by DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::d30b:44e7:e78e:662d%4]) with mapi id 15.20.7386.037; Fri, 5 Apr 2024 12:32:03 +0000 From: "Peng Fan (OSS)" Date: Fri, 05 Apr 2024 20:39:28 +0800 Subject: [PATCH v2 6/6] firmware: imx: add i.MX95 MISC driver Message-Id: <20240405-imx95-bbm-misc-v2-v2-6-9fc9186856c2@nxp.com> References: <20240405-imx95-bbm-misc-v2-v2-0-9fc9186856c2@nxp.com> In-Reply-To: <20240405-imx95-bbm-misc-v2-v2-0-9fc9186856c2@nxp.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Sudeep Holla , Cristian Marussi Cc: Peng Fan , devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1712320792; l=4839; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=CxsTem4c2UkSyoEAgF9+D0rRRjQcCv/6gmp4AinHGy8=; b=t0H+mFmPeAYegC19iPxmWW1dcghnCrQMgG53u8dAzgygUK8ThK/tgn0DK6SYsIVPEdT1JQ5WU LDHzUHS2Ay5B/VlUQgXvwP3H+R18Mlzd0pXo8rDxksC895BaVAKj18D X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI1PR02CA0024.apcprd02.prod.outlook.com (2603:1096:4:1f4::12) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9417:EE_|PA4PR04MB7744:EE_ 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: Yq8+E9rnCZW6I0Eb6CsIV7q/C1ENaM8Xjw4q4nYv/7uxLJDC7qbkFMOZh81Lfo4F1L8gmjUMT6eBLSzKymj2/vxQ1v1ZdiqGAvi2AJtkMbgjbHNEMjwdtzzFjd++1QZ2NCK1MHywAc177jCYCnDc0gBLan5Xlt8AT29sBUCzy5jePWyyuGufaR2RneDCP0WZB7LSiWGc7fcow19zCFubrfuUpHQydwqMtfTdjoTlZlwNg5pSMMP+byOcibSYRSLvK9cfngTZdPZeGu691lT/OIeXi1N3RJizyERmtOjneiXRnPsgQ98SJ/dah04+N2K5gNWla89LiTdhYF8ktID2pHAYoCyF+ZvjTgiCdvNIkcS7V9zA5EtoqSjVZDKDwXnaHycKufKlniokCED6jiQMcG0Otk5vmAj4/KGRCazS7HjwGUusMSlGEigK9I0zHbheZ2qpkkDIcSIfCe6iw2hVPiE6nJIQCJcdxCR0DisK25Kwy96x1klYUuPcQ6/DVcgIFRXW5Uoj7BAK+QMbZbkgvy8RDgEodUYJJpRVzRaX3bUpWuBERUEFCewIyGkJ48YRMiW4UQXSmhB5mOhsOWt2sfpkr0RWvzUbLNiTW4l2F388L0lppNE76B/32QdtAdKyF8a1y385j9YJ9bcjsuphRfMWAW8MFAnSAmeYQVPe2k81DKmj5FT/XICiBgASrqCKlwjQW1a1lRETYTE4SayryalEk2a6v1PHSjPyZJ5ItZg= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU0PR04MB9417.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(7416005)(1800799015)(52116005)(366007)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?w2NkDXPiGCwAgCRlbmIrADm3szih?= =?utf-8?q?uQOMH1jAv7/MyEaQsCXdb0dlbC3qLHA/Ii22DTXuFtybASnLUPMpo8hRgezEKH3tk?= =?utf-8?q?wN7uelnJLx0TniW5lu+7q00C9e9j/alA3sRpigELehXwtX50NIGJdNZoa/SQEI/J4?= =?utf-8?q?Y8EVmQaSecuBYBmEFPrkv/hASWGj2ab1sckEwUifiyMbai67163xHT+KhKH7RONd5?= =?utf-8?q?6Da6ZZjdcz9ElYEaFc0tOZp39CCNB6HY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gHq49PRYZi+x+hJfWhJHPXQOK3oVPDm2?= =?utf-8?q?r6yDmXqGAb5iCh4uSAru57iU8MQyHVd1u+VEkvk3UbBG9dme6h5yoUEIXoCqxjlO8?= =?utf-8?q?qjYegNxRSEfZcZM5rt+wdayBzisO1cIF6hj5v4G3cshExeGv2xdSFE4xY6iBXll8L?= =?utf-8?q?zZmdXPtufwiyR3L/u4VwH8ghH2AxfWxC64WjxKD50YtHwPENGzUGYojnvLLzMXIJ2?= =?utf-8?q?o1iywnytbTz6tqbpyb3ukaiXZolrbERVyZu5Zua0AFyrQXpOFGNkCMWCEH2V40YOy?= =?utf-8?q?CyxAepsE2Zb1zBVkmr5wg2nzf9YQbeJCPTv+4K+GLeJqZNIQPG+h5ygSljyld7gW9?= =?utf-8?q?A1mSpjIKFXnpHJLvOcLA7iZKe0taUSwnpGhQiQZZmQ4a+rQIyMsdc2RBE4KFyV6FA?= =?utf-8?q?hWYtIpyc+24w?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4ef5d688-57ac-400a-cbc3-08dc556c65e4 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2024 12:32:03.5516 (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: QzxWKbIZAyDqDQR6R3aT6uPb9ry7HzpakoxeNvj4CqWRSYwDcmQLK8UGN8bbmWtF7bJ3ivo3U6SKhueiA2b5JA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7744 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240405_053213_019251_901B2308 X-CRM114-Status: GOOD ( 15.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Peng Fan The i.MX95 System manager exports SCMI MISC protocol for linux to do various settings, such as set board gpio expander as wakeup source. The driver is to add the support. Signed-off-by: Peng Fan --- drivers/firmware/imx/Makefile | 1 + drivers/firmware/imx/sm-misc.c | 92 +++++++++++++++++++++++++++++++++++++++++ include/linux/firmware/imx/sm.h | 33 +++++++++++++++ 3 files changed, 126 insertions(+) diff --git a/drivers/firmware/imx/Makefile b/drivers/firmware/imx/Makefile index fb20e22074e1..cb9c361d9b81 100644 --- a/drivers/firmware/imx/Makefile +++ b/drivers/firmware/imx/Makefile @@ -2,3 +2,4 @@ obj-$(CONFIG_IMX_DSP) += imx-dsp.o obj-$(CONFIG_IMX_SCU) += imx-scu.o misc.o imx-scu-irq.o rm.o imx-scu-soc.o obj-${CONFIG_IMX_SCMI_BBM_EXT} += sm-bbm.o +obj-${CONFIG_IMX_SCMI_MISC_EXT} += sm-misc.o diff --git a/drivers/firmware/imx/sm-misc.c b/drivers/firmware/imx/sm-misc.c new file mode 100644 index 000000000000..a5609de426f6 --- /dev/null +++ b/drivers/firmware/imx/sm-misc.c @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2024 NXP. + */ + +#include +#include +#include +#include +#include +#include + +static const struct scmi_imx_misc_proto_ops *imx_misc_ctrl_ops; +static struct scmi_protocol_handle *ph; +struct notifier_block scmi_imx_misc_ctrl_nb; + +int scmi_imx_misc_ctrl_set(u32 id, u32 val) +{ + if (!ph) + return -EPROBE_DEFER; + + return imx_misc_ctrl_ops->misc_ctrl_set(ph, id, 1, &val); +}; +EXPORT_SYMBOL(scmi_imx_misc_ctrl_set); + +int scmi_imx_misc_ctrl_get(u32 id, u32 *num, u32 *val) +{ + if (!ph) + return -EPROBE_DEFER; + + return imx_misc_ctrl_ops->misc_ctrl_get(ph, id, num, val); +} +EXPORT_SYMBOL(scmi_imx_misc_ctrl_get); + +static int scmi_imx_misc_ctrl_notifier(struct notifier_block *nb, + unsigned long event, void *data) +{ + return 0; +} + +static int scmi_imx_misc_ctrl_probe(struct scmi_device *sdev) +{ + const struct scmi_handle *handle = sdev->handle; + struct device_node *np = sdev->dev.of_node; + u32 src_id, evt_id, wu_num; + int ret, i; + + if (!handle) + return -ENODEV; + + imx_misc_ctrl_ops = handle->devm_protocol_get(sdev, SCMI_PROTOCOL_IMX_MISC, &ph); + if (IS_ERR(imx_misc_ctrl_ops)) + return PTR_ERR(imx_misc_ctrl_ops); + + scmi_imx_misc_ctrl_nb.notifier_call = &scmi_imx_misc_ctrl_notifier; + wu_num = of_property_count_u32_elems(np, "wakeup-sources"); + if (wu_num % 2) { + dev_err(&sdev->dev, "Invalid wakeup-sources\n"); + return -EINVAL; + } + + for (i = 0; i < wu_num; i += 2) { + WARN_ON(of_property_read_u32_index(np, "wakeup-sources", i, &src_id)); + WARN_ON(of_property_read_u32_index(np, "wakeup-sources", i + 1, &evt_id)); + ret = handle->notify_ops->devm_event_notifier_register(sdev, SCMI_PROTOCOL_IMX_MISC, + evt_id, + &src_id, + &scmi_imx_misc_ctrl_nb); + if (ret) + dev_err(&sdev->dev, "Failed to register scmi misc event: %d\n", src_id); + } + + return 0; + +} + +static const struct scmi_device_id scmi_id_table[] = { + { SCMI_PROTOCOL_IMX_MISC, "imx-misc-ctrl" }, + { }, +}; +MODULE_DEVICE_TABLE(scmi, scmi_id_table); + +static struct scmi_driver scmi_imx_misc_ctrl_driver = { + .name = "scmi-imx-misc-ctrl", + .probe = scmi_imx_misc_ctrl_probe, + .id_table = scmi_id_table, +}; +module_scmi_driver(scmi_imx_misc_ctrl_driver); + +MODULE_AUTHOR("Peng Fan "); +MODULE_DESCRIPTION("IMX SM MISC driver"); +MODULE_LICENSE("GPL"); diff --git a/include/linux/firmware/imx/sm.h b/include/linux/firmware/imx/sm.h new file mode 100644 index 000000000000..daad4bdf7d1c --- /dev/null +++ b/include/linux/firmware/imx/sm.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2024 NXP + */ + +#ifndef _SCMI_IMX_H +#define _SCMI_IMX_H + +#include +#include + +#define SCMI_IMX_CTRL_PDM_CLK_SEL 0 /* AON PDM clock sel */ +#define SCMI_IMX_CTRL_MQS1_SETTINGS 1 /* AON MQS settings */ +#define SCMI_IMX_CTRL_SAI1_MCLK 2 /* AON SAI1 MCLK */ +#define SCMI_IMX_CTRL_SAI3_MCLK 3 /* WAKE SAI3 MCLK */ +#define SCMI_IMX_CTRL_SAI4_MCLK 4 /* WAKE SAI4 MCLK */ +#define SCMI_IMX_CTRL_SAI5_MCLK 5 /* WAKE SAI5 MCLK */ + +#if IS_ENABLED(CONFIG_IMX_SCMI_MISC_EXT) +int scmi_imx_misc_ctrl_get(u32 id, u32 *num, u32 *val); +int scmi_imx_misc_ctrl_set(u32 id, u32 val); +#else +static inline int scmi_imx_misc_ctrl_get(u32 id, u32 *num, u32 *val) +{ + return -EOPNOTSUPP; +} + +static inline int scmi_imx_misc_ctrl_set(u32 id, u32 val); +{ + return -EOPNOTSUPP; +} +#endif +#endif