Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp650401rdb; Thu, 1 Feb 2024 22:31:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IFr5/VEH2jJD/S3vc8fUp5q03n3e/yj4HmvapK8EurmbaEURYqvMwouJ71uSsgh/EhcmUSv X-Received: by 2002:a05:6a00:9394:b0:6db:c583:1ac6 with SMTP id ka20-20020a056a00939400b006dbc5831ac6mr2136529pfb.9.1706855487982; Thu, 01 Feb 2024 22:31:27 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW8qQ5HzuGRGjJ+9vhIgwY8RrgXrd9zjp75GtVOYDvhvRdfgEjjGykQP85lCOVZotAKXLQsdz7qLtqJKqjs06siosF6411cxeYARiGBJA== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id p37-20020a056a0026e500b006dbb024d06bsi1020153pfw.43.2024.02.01.22.31.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 22:31:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49271-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@NXP1.onmicrosoft.com header.s=selector2-NXP1-onmicrosoft-com header.b=XW0nbITO; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-49271-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49271-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 137DFB23D0A for ; Fri, 2 Feb 2024 06:31:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D75F7179A1; Fri, 2 Feb 2024 06:30:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="XW0nbITO" Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2087.outbound.protection.outlook.com [40.107.7.87]) (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 DD85317571; Fri, 2 Feb 2024 06:30:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.7.87 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706855443; cv=fail; b=qAHC6ksWVu0Ha90idJP3UvKQLO9yuOGl2Imx+4RKdY4NWQZo7AZEijEntX9PIQAFZ3utvdFCPvWTr1jwdmp8z/txphCGCvnWJQl+QS6f1lk91YQdnld/plzNTIXENsr9wNPgrZn8/07ZWofIKqHSaz8VIUGbRPH9cQfCoQ9ilUE= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706855443; c=relaxed/simple; bh=MViT3hkNnubhods/T2GXBOQrZGQGrJ8dq58t1MAnuj8=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=mlFuNTDIPs4EEexgFvBiEavKC/P4SvuqcOo7dsKIpOaslhRmj7HjKGx2aIaA5X4GvnIe2dgLzk57EoINRIvm0AsHsJG8zAxTEOgN0tOmJlGubE4emHulytbldVIS49Asz8AbB6bW6ZW9XyHHIHlX+hfw/NZyQY2nMZgF2kcUntY= 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=XW0nbITO; arc=fail smtp.client-ip=40.107.7.87 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 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SI3sctGxh9rDZ1lxC6vCzagAT0x7mgfjWtSKq2fr1DfiNSvyEs4Dqslgkp/56BGeRJ4jwIUa0SG9DIeF3ztBGVOxHGh11ll42UcZ67KJS8S0uelFtEibFCFPI+DUvS3YrJNbQeSktKrEeEvCn5gKMBTQP3hjbfuJPkh1k/JNQ12p2/dIZrXUQqCM9IyKp7xABtKvybCQhbe9udWE+FqtBZgNlzWK1L3eXqoaioctZxPSvkaEi8iHyiQGS2XuscFRuRvd6w6WvJMzQKjTWh1nR3o+6tOm8zHw19ho2/q+rpYyCqZ9b0sQVeFgzLZKPNGIhup0pkKAQJL+LcUls3PdgA== 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=FIPmRhGYBZcC9nmdc3gAJL3q6sFDELDgVfbdQXGNaGM=; b=S6wms+knJHgr4mXFdQNIcI84KfAnT+IIb7eOFYZstt0h/BMmG+ibShgXUu0klaS49XRWZvhcnpzB+OTOGjmJgDdf1qslAqWBcwYEWFloRFRDaPI589SIM//VpI7Y9h0xpq8jKvJI5aItBDpZDUi/TNifKZ3sQGtTir7QwKgmIDi64axgv6B++f4gokLgPY3NpHsbsqdPl7t+GreieQHtHpd2My71Ui7kTsgKCvUT7iQgACBrdU/vS7GuuBBmM0mwmIMJPqvpMhcG6pkTDU/dI5c9+P1MGPqkc2Ii4KCpW8VxX6rnYxoD0+jJTmj3+Z9+IA2kwS7hSdicorIMH9WWFA== 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=FIPmRhGYBZcC9nmdc3gAJL3q6sFDELDgVfbdQXGNaGM=; b=XW0nbITOUrGWvLXHMZzWyv7L7nCCQ+1XTOAlftg/KGq6tWRYcNGytJSR0m9XKV2CgHVERgyivPleNbWTgWscOMAEQCvsm/12YjzPBl5ET84CIPox6wfx3OIk9amid8iGlth2ebjOrjVwjhSG9T5q98oL+NwW+QBBR5l97XdFlrE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) by AM9PR04MB8604.eurprd04.prod.outlook.com (2603:10a6:20b:43b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.26; Fri, 2 Feb 2024 06:30:37 +0000 Received: from DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::c499:8cef:9bb1:ced6]) by DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::c499:8cef:9bb1:ced6%3]) with mapi id 15.20.7249.027; Fri, 2 Feb 2024 06:30:37 +0000 From: "Peng Fan (OSS)" Date: Fri, 02 Feb 2024 14:34:41 +0800 Subject: [PATCH 3/5] firmware: arm_scmi: add initial support for i.MX MISC protocol Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240202-imx95-bbm-misc-v1-3-3cb743020933@nxp.com> References: <20240202-imx95-bbm-misc-v1-0-3cb743020933@nxp.com> In-Reply-To: <20240202-imx95-bbm-misc-v1-0-3cb743020933@nxp.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Sudeep Holla , Cristian Marussi , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Peng Fan X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706855688; l=10438; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=tZxW+mINZL8afIXv/OhfnOalP2oB6/24XR+jpplh/t8=; b=xFDp/C3pFXPgK+VoEN28yQfJ34LalKuNZCQTiO5cSvfEEMKug30ZKgjXULxmcUK53cqULm0ny vOhlbc24tWUAEHfmTMTr4ZUSzSUFaCRFQqD+AON066jNIpAGdg0zXVM X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI1PR02CA0048.apcprd02.prod.outlook.com (2603:1096:4:1f5::11) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) Precedence: bulk X-Mailing-List: linux-kernel@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: DU0PR04MB9417:EE_|AM9PR04MB8604:EE_ X-MS-Office365-Filtering-Correlation-Id: 24d53390-c4d5-42ec-c135-08dc23b877d3 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: JT8KgEXkPxIP1l6ylx2BraRpU6KPmqfr4ixZZ0TFLmCkG27x2p3ZMVv27cA2IEHmmYuASjXFF4BYGDKWsymIZTOlIe3CoAP4a76/V7CdQ1uElfwdALaNYpfmBdC+7XE/LWQr6I4noJXuGgM9AYqLhwMThFyyGl5u1nkb5tJEYhAjtZV+4yNKudkvub8qcLMggNmzXhxI9vyPCD7R66v1f4D43gWM9wnCRaOLsFvH3pXInx/PMNTww5DI4r4ZOaq5vDh2NmBu+Cpt4lFS8WgYrgQ6cndBMgSdMF1cEfr2z9v9UmxprnoEjB4wwy2Tuv0WmEaOY/2K+p+vV8vQx9CMnCgoaZ9VnzZanY1D1xyNXgZxhkFEwwF+cBOCIlUVBdgONgQinoegGv6ASugeH7i3j2qRXJfcS1ZaV1bQrEtzu9U8ssbRToMozkflB1fDAk5DvdMWwXJehK7Cw1Sr/7KS0v7cA3u+JufUZAnaxxDQG0eKVPgzvxn3JpEQBvj4Sv7s5DJIH4UY/HuyGN5Vf8N+IEh+g4dMFqOkUYDnXdRvV5SxGbyEgxo1ttTjCe1OM6xN6k8Dcdc1xtElNVW3rCCty3mRIgSUqU8GxClOD9Ehgw5+MpLTHcYXGAybu2UmMf+RoqQXdcZFA+DXyxKyoLE36A== 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)(376002)(39860400002)(346002)(136003)(366004)(396003)(230922051799003)(1800799012)(64100799003)(451199024)(186009)(9686003)(6512007)(6666004)(6506007)(52116002)(8936002)(921011)(4326008)(7416002)(2906002)(5660300002)(316002)(8676002)(66476007)(86362001)(66556008)(66946007)(38350700005)(26005)(36756003)(110136005)(41300700001)(6486002)(478600001)(83380400001)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B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HcSsyOSs3WEZNQk5rdW92OWhsRmcyZFFy?= =?utf-8?B?dkV5V1haaW4vWmdmL1hZNEtBeFUwN1NqZ1JZNkhHUzlYcnN1N1MraHpxdzlk?= =?utf-8?B?cmVxcEpESjRtY1JDYXJYK2p2OHU0SGkzaTBRQWZxZDRqaTNnMzBISGg2ZlB6?= =?utf-8?B?YVJiVEQzVEw1dk02NitnMG51eTVVMVZjQmcvRi9wYUJYZG9sb28rbGp3MDdh?= =?utf-8?B?NVF2U0RPZnNHV2xNRUx3SG9YM092a3duRksxYmUwbEZERDBiV29lY2NzVEZm?= =?utf-8?B?RlI5b1IrbWUvSUV6cytQNllaSWJiWkIwajFLTE8wa0JiM05hcy83ZGMvQlZm?= =?utf-8?Q?s0ZwsZJSRkKeBtneAZAHi/es9?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 24d53390-c4d5-42ec-c135-08dc23b877d3 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2024 06:30:37.2111 (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: pM8Ua20QLUpgZbfYKvI+futhA7/qAusPTTqIDy359ri9Fu5xy8hhxIyCxEjoKG9lHVhvWHlz6jWDbRbrNUg/bA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8604 From: Peng Fan The i.MX MISC protocol is for misc settings, such as gpio expander wakeup. 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 | 289 ++++++++++++++++++++++++++++++++ include/linux/scmi_nxp_protocol.h | 17 ++ 4 files changed, 317 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..7805d41cca4d --- /dev/null +++ b/drivers/firmware/arm_scmi/imx-sm-misc.c @@ -0,0 +1,289 @@ +// 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 0x0 + +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_ctrl; + u32 nr_reason; +}; + +struct scmi_msg_imx_misc_protocol_attributes { + __le32 attributes; +}; + +#define GET_REASONS_NR(x) le32_get_bits((x), GENMASK(23, 16)) +#define GET_CTRLS_NR(x) le32_get_bits((x), GENMASK(15, 0)) + +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[MISC_MAX_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_ctrl = GET_CTRLS_NR(attr->attributes); + mi->nr_reason = GET_REASONS_NR(attr->attributes); + dev_info(ph->dev, "i.MX MISC NUM CTRL: %d, NUM Reason: %d\n", + mi->nr_ctrl, mi->nr_reason); + } + + ph->xops->xfer_put(ph, t); + + return ret; +} + +static int scmi_imx_misc_ctrl_notify(const struct scmi_protocol_handle *ph, + u32 ctrl_id, u32 flags) +{ + struct scmi_imx_misc_info *mi = ph->get_priv(ph); + struct scmi_imx_misc_ctrl_notify_in *in; + struct scmi_xfer *t; + int ret; + + if (ctrl_id >= mi->nr_ctrl) + return -EINVAL; + + 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) +{ + struct scmi_imx_misc_info *mi = ph->get_priv(ph); + + return mi->nr_ctrl; +} + +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 = { + .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_info *mi = ph->get_priv(ph); + struct scmi_imx_misc_ctrl_get_out *out; + struct scmi_xfer *t; + int ret, i; + + if (ctrl_id >= mi->nr_ctrl) + return -EINVAL; + + ret = ph->xops->xfer_get_init(ph, SCMI_IMX_MISC_CTRL_GET, sizeof(u32), + sizeof(*out), &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++) + 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_info *mi = ph->get_priv(ph); + struct scmi_imx_misc_ctrl_set_in *in; + struct scmi_xfer *t; + int ret, i; + + if (ctrl_id >= mi->nr_ctrl) + 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, +}; + +module_scmi_protocol(scmi_imx_misc); diff --git a/include/linux/scmi_nxp_protocol.h b/include/linux/scmi_nxp_protocol.h index a2077e1ef5d8..45415a6ff845 100644 --- a/include/linux/scmi_nxp_protocol.h +++ b/include/linux/scmi_nxp_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 { @@ -47,4 +53,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 -- 2.37.1