From patchwork Wed Jul 31 12:56: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: 13748720 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013052.outbound.protection.outlook.com [52.101.67.52]) (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 622981B3750; Wed, 31 Jul 2024 12:47:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722430073; cv=fail; b=N68UGi22egOYsA73RtvOtPafhjUmQb7hvUK6wouwuf92gQpbZdiIls78MClbAPD3TcGOMD8W8jUA6dSfBCxi/9N2KfDjX0m3hAkSGAJb7o3qBR0QnQuFCSaP3dpkrbqHXGwPqBVEQ2B8MM+ad0wzgBaLXiWs/pvZLRjqoOjZdgs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722430073; c=relaxed/simple; bh=lB0din7YUuASkUYMScY/zMN+DX9irTFze5qsm4nmRik=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=bb/xvKdYrtPIvcN+sDR577Gzzdw2D8GoZWusV0TyCT7nE5fN9fSoGqEnwK1qAwq72yxfQEyetdZ0oBn2fO2JV4Li+8BsOJbGRCEup0KDvPf0pmDmHBgIM4nwMZmCXqbVl/dsEn4PIcVGAte8n0FN0en/t6330yRZGIa1EFywnG8= 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=ESMrakXZ; arc=fail smtp.client-ip=52.101.67.52 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="ESMrakXZ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=g5QN5FvDphkFViJ76j7p1RvoU6sDUGIu1t36VB2WvGeEoczJAqL4UeuWs8iyFplAgP+xGYnj2o53aSIJeEYcYyUfxbRKEuVNIy0onrc5cEaQqytcRVafoNI9+w04yXN6x1KsQdce0OxlNrbsyUAMQ19mbwaWtuT+6RmcxZegQi7SZNT/XfIXiooPDAMarpWhi37yQx3knJYuV9U/sH7zcEtJnapamCDXEZkKJsjEkvLbM/HXYitghVThWqzgsW8K8TbccMoKn9UHSKTx47/eJUCqd+SK3VE705iWIricXfXj3ZG1kFAs/9eR/xSQhhIq/RvweDN8I4zNhphe97Rz0A== 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=2y1quUvokU0Up4oQp8r3/9zDfWHRyol2aqI1a4ysBr4=; b=ZtrfqBw8kV/Wb8O6w+ggYnNNOGrKBd5gv5sw+kjmFNPAutAa0GMouQFks5I31ogSUQH9afMR9W6bs5XV0vtpqAbrVt3NXitNzjjySFyK9rmc3uNQ3TUjG2Wt15zQA6DNU2tk6JGO49C6IvCsFT1n0KB1FI/DhN1RY6k6MkYyN585abSl7uCd/NZjuH6zP7PayhmpwIHhjiGi9N/H0RPwwbr4XFZAjsG5HpDAc3qlYKK3tN+kEtyguwXY01mM5fGtAGKw7gy9iSqSvAxABKscuxEWNFtWP3arohQDDbzSvv6BtQ4bT2UPihkwomUefmNOs0I0SDVh1G59f2+R4EtN+A== 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=2y1quUvokU0Up4oQp8r3/9zDfWHRyol2aqI1a4ysBr4=; b=ESMrakXZr1HMAx/OnutmfG/mJQFnC6Ya2jVuk/3Vj5UPV5xGhZix1kw5bxlJgnapVs3GmHYM9n3HlXOg3NEfNCA7gmXST+BjMttnY/Iy4GV5JEblPgNi++YilgG5FSERfgCjE9oQbC8Sp1fReSuHxQyC4CXvUZqVPxofQTHd+7M+42ezECLV6mjYCxSj8vXTJ07B39vmJ3TGWnBjgVgwT1SW4DDMvcwibYP/pINeLoiwBLpiMYsUwP7O7MU/Be3bywbamXc3KafvX1mtnSTZI167uIBoRhD9F9tW5/xCtBdtoXGw0M1vbeUbE6XMdmOIj22idwjnfapM0tZ3JBx7wg== 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 AS8PR04MB7735.eurprd04.prod.outlook.com (2603:10a6:20b:2a5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.19; Wed, 31 Jul 2024 12:47:44 +0000 Received: from PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630]) by PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630%4]) with mapi id 15.20.7784.020; Wed, 31 Jul 2024 12:47:44 +0000 From: "Peng Fan (OSS)" Date: Wed, 31 Jul 2024 20:56:10 +0800 Subject: [PATCH v7 6/7] rtc: support i.MX95 BBM RTC Message-Id: <20240731-imx95-bbm-misc-v2-v7-6-a41394365602@nxp.com> References: <20240731-imx95-bbm-misc-v2-v7-0-a41394365602@nxp.com> In-Reply-To: <20240731-imx95-bbm-misc-v2-v7-0-a41394365602@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=1722430577; l=6360; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=Oy5Gyoso0Y/G/kwZwRlXVgA45ZaX4xes2SzW2BSybKo=; b=LAM7679d6oIlUq8nhpfhhaN+/2UB7pSIBfwX1XVyEmiMjnmrA75iZVe3tFMOCfbba8bn/4JjS JLxlgJxtBKuBi+pEHw/AnrTQ3wBIabcyOhX/HfFbUaJ/+65M8UxhmA2 X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI2PR02CA0027.apcprd02.prod.outlook.com (2603:1096:4:195::14) To PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) Precedence: bulk X-Mailing-List: linux-input@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: PAXPR04MB8459:EE_|AS8PR04MB7735:EE_ X-MS-Office365-Filtering-Correlation-Id: ab3fe108-5eb1-4a65-17a0-08dcb15ef956 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|7416014|376014|1800799024|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?NDxZD34kjfYOEU+n5rVKx51pmdfD0vu?= =?utf-8?q?JkxVAXtM7wgxcmjBVWj7dvH86rEBWiR/N5OpC8cDbgrQ5FEB7nRmXQDOf0iD5iihn?= =?utf-8?q?wKmJX6IrdXE7lu46NwvvlHwHVkj7iCrI2T+/vF7kz8b2lTvlBqVBrvnl/V8jFHsiZ?= =?utf-8?q?C4odDTVvPyd4K61H+VLwbErbwsYvE4H6DhZUej1NKHELW1FbQXAiDFJEUWaBacYJp?= =?utf-8?q?tUTRqolBDMFCn/9elg0ZC+DthqByLlhxQHu2VacJL8l+aAn6ZrKVHq+jQJ7jdv2Qv?= =?utf-8?q?WsJnkH4yhWn4G4cQCQu/O+GkBEin3FR+QEdUADuRy7hD0ff534hAl9P65xEv/2h9T?= =?utf-8?q?3I14142+M0FDWIvnXDkhFpmjS9JmR0LqEPzN8P8JSXx/MHkOue3BzutDizPdqlroV?= =?utf-8?q?Xfak5hLvO+xczjL7NFcEMw8/EIIZ/VQeIg8cgBnwSLmITkFa4slBBDsihjx0YBkrM?= =?utf-8?q?2Fj0BjhMFZOvL1ptVwpEivdntC+/Z11izD4me2jHc5jmeq3TP0oBw6ii66Vf1V4qN?= =?utf-8?q?lZzGizCNXixphoL2dgFoh00AjfH0sslhK8NC/1JQI4HqBcZox5XK0MOVkvLFgzPjt?= =?utf-8?q?hnk1u1FMRhudPaL4HRhFV9tQSyW+iDzJtGHoKIF6QaZV2nLpdxTnXgHvN2lywESFT?= =?utf-8?q?IEWmqot/IcQ1Qe8H77zGxsBxPFhEkvhPdVo6KaeI8YuocbLe6iXMDAHrh0t8849Cc?= =?utf-8?q?JGeroSTJ642wsA8gOHDpkDGgJAyrB4n97g1wIM9gcf7HCgaRUWh7eSPJl51ISFzGR?= =?utf-8?q?SRpFtalr+TspZOiqlARFTW6hBAVgGvluzG5LXFu62Z1agvssLPfRsLM+kMECRKttq?= =?utf-8?q?yTdpA9/II92mvZ3eU6hDVvtEfljcon953bi/vp4cabBbTrje2RA/1GW6yBYIIgsGG?= =?utf-8?q?4L3LIL9V9nkfkOkLUArL0tp5s/633g7CvHGyWVwXTG5qROj93fOaF3DS3JKBnwUH0?= =?utf-8?q?/692jfUxzdPr/E02ycAnPyya+LY+vykoQ6P+gGYUFlYvQyiBr5rdV2f/3bfVLUiVj?= =?utf-8?q?i28hWhrW1QX2n58VHG52xu39a94uqRkf7bD95edZGF/LkbU6EOLRVJ0uulCh1GR4d?= =?utf-8?q?s4Jr/IuQMOBHILgXiOpK9yad8NzFuKxLGYqoIi+TnrCneaFSdrNK5uLFCYwfZ/StE?= =?utf-8?q?VOglqTYH47QiwfrwUwr7Yj33P0YbywkOSMSeRu5Cda6AsmaoQqzgEPR1vDoQn7l/h?= =?utf-8?q?o7b+mA8EtLpprSC6Ln7ju4dSaNOVfJ1xUovna/peBjYEzqCSiURUd95sqqrJ/rFS1?= =?utf-8?q?wdCRBMZ9MJsQG63M/pE7kzYm9WekWP99xmB9D47C8dYo+UFlLhs1ENfKYNL6uV/JI?= =?utf-8?q?Gwg6dEZIy/6V3p0RNeu3twrlIyd9t32EWraXG/NhIK3NEdtm8php1sg=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)(7416014)(376014)(1800799024)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?U4uppM8iuYIoVc7Hhtr9bB+TiI4i?= =?utf-8?q?1Aj5olnu+expzfNqUmFbl/BdWz9OlzP/j+MCZaUjcBVv2CVkPl6k4a1HbMaJJyVcq?= =?utf-8?q?mtQz6c8bm9Oyw08pW4nS7z0oI6XWXOmqaxH1A9NEhN7l0LgcmSvUU5zkgftNBPDVK?= =?utf-8?q?6seZc+XU/hQ6v0VUG50lF8YXL9EcOB6n+Sj3og4vMEmwyQLpiwOn2IDrBMQgeblEd?= =?utf-8?q?+XFVudUf+4g0h9n7P6UToXP8Fsl5PK5YJpa9jb0wj+dyOqXpwFAfwX1GNhAITYTut?= =?utf-8?q?PeJE+hbmOCTuIvczXWkGe9mWh1m/E5UtzMg2i/0kJM2irDwM4J/zy2FwpIvhvOW2m?= =?utf-8?q?ZD7uWqUfXPwZ8I8ydFKNTZKEnjedfyi3bFpubsElyndfcR8vj4bBJbkThIp1b7sdp?= =?utf-8?q?tubryCJSB1tjIiOtp0NQWTFUs5skpMiYvfzNZPQ+8+QoU8tMuT8l6l9DyP62bjDPi?= =?utf-8?q?IlnFjLUqTZD6Pr/9F04flLG2ka0QfYIUBBnmX9PDxFGBICPscLsAr9D7RfmhSE+Ds?= =?utf-8?q?2donRNszJ+RJ6lgZ5bII8Mcv9xEdLMN0CaqiXQVjUfb9AQnmHBU4WYtiPQ3+7obIm?= =?utf-8?q?iIKEok9f597ryEjUsSEtieHofv/PozWwEe0vr/mW4I/ngQWgRGTKthg3KCyYWwE17?= =?utf-8?q?W7EgFKzupSUa40XImPYwQZo42q26jUVqr2Fkc3ZLxdZur8k4FnQMgUudgbdW31x54?= =?utf-8?q?Uxd/x4S+TsoYrbarsUNuxaywKSWAHVvxX1ygy76qGHXud0vLj1gszd6s902hNtTew?= =?utf-8?q?zhC9RQAlRyRNo9TcS+EV8WmCnECd4hGqu3iOuMG5XU1/YZXiqNoOpPbl6/LcpDyKX?= =?utf-8?q?9XiLRR3+CBwSm53qs5UlZ3OysilEuN9yPQgKAD2u9c5Hkhth+dAi1cmJ/JwWRWmFp?= =?utf-8?q?NBfy01s9li1P44H3oGQLag9t8934gA5dpWQzsiW6qMuu8m0JlOvz8W9J7x2L6jIfg?= =?utf-8?q?TlC3y5CgdxPVi4cixoaFrY1iLXY+3l5EzQwB4cbZK49wpXVu7Xan88SUN4JlbAJvO?= =?utf-8?q?cGUPgtMZRcloszfUa23NL5y2wWsUcmfnSTXeVGbrgTERuCUfIt3hezWym26BZ/LPD?= =?utf-8?q?OfhR8D/Jr7lN2+NMfVAWa7XPcvMCHGIv0bGPTTDh5fWUhvk618Kyyv0pVGtbouOPW?= =?utf-8?q?/fnigUpqXanRTHQlRibh+IBP543npGEVQdFTURgOtvx7ZmT/GMC7hWzTBY312x4GS?= =?utf-8?q?U1q1/k/MvrIX6Sl85B9ZohorKN2fpgCEQDXw65NEA6D+kJezixmSjGf9I0o5Z6jhm?= =?utf-8?q?8xJ3sQX3peeWzqBHdpumDV3gmGMZYYlwNytb7SuFOEs3x5jIQAdnOJ+NhcvN3BuKa?= =?utf-8?q?TM8uzxzmqyN5kUAefKP83fCryteY2ppk4S2dqzLtPtTmqSAwaUkUWLcIfOLlgJMKW?= =?utf-8?q?1QHpIdlVgfOa5QD/QBNu2FdEbf722dSH/OdW8jc7Sk1V7VjHoGf6aUI2bKeumUul0?= =?utf-8?q?KfXVkUpvDtH0h7rDA5fmRby0tYjzdpPNK/t7OvsjyC7IIvzd+miFFNAgmMtC8sytc?= =?utf-8?q?OFnFq2lWYBMH?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ab3fe108-5eb1-4a65-17a0-08dcb15ef956 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 12:47:44.8720 (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: nMC2Lj8GM/REbjKjSZ5S8TwODRCZSPk/trjIr+IxTYLjr93WvGXw/afcj94CpVOgkhubjo7Cgl6qJ/UcPHDqIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7735 From: Peng Fan The BBM module provides RTC feature. To i.MX95, this module is managed by System Manager and exported System Control Management Interface(SCMI). Linux could use i.MX SCMI BBM Extension protocol to use RTC feature. This driver is to use SCMI interface to get/set RTC. Reviewed-by: Cristian Marussi Signed-off-by: Peng Fan --- drivers/rtc/Kconfig | 8 +++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-imx-sm-bbm.c | 162 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+) diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 2a95b05982ad..8122bfeba8c0 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -1827,6 +1827,14 @@ config RTC_DRV_BBNSM This driver can also be built as a module, if so, the module will be called "rtc-bbnsm". +config RTC_DRV_IMX_BBM_SCMI + depends on IMX_SCMI_BBM_EXT || COMPILE_TEST + default y if ARCH_MXC + tristate "NXP i.MX BBM SCMI RTC support" + help + If you say yes here you get support for the NXP i.MX BBSM SCMI + RTC module. + config RTC_DRV_IMX_SC depends on IMX_SCU depends on HAVE_ARM_SMCCC diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 3004e372f25f..8ee79cb18322 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -74,6 +74,7 @@ obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o obj-$(CONFIG_RTC_DRV_HYM8563) += rtc-hym8563.o obj-$(CONFIG_RTC_DRV_IMXDI) += rtc-imxdi.o obj-$(CONFIG_RTC_DRV_IMX_SC) += rtc-imx-sc.o +obj-$(CONFIG_RTC_DRV_IMX_BBM_SCMI) += rtc-imx-sm-bbm.o obj-$(CONFIG_RTC_DRV_ISL12022) += rtc-isl12022.o obj-$(CONFIG_RTC_DRV_ISL12026) += rtc-isl12026.o obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o diff --git a/drivers/rtc/rtc-imx-sm-bbm.c b/drivers/rtc/rtc-imx-sm-bbm.c new file mode 100644 index 000000000000..daa472be7c80 --- /dev/null +++ b/drivers/rtc/rtc-imx-sm-bbm.c @@ -0,0 +1,162 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2024 NXP. + */ + +#include +#include +#include +#include +#include +#include + +struct scmi_imx_bbm { + const struct scmi_imx_bbm_proto_ops *ops; + struct rtc_device *rtc_dev; + struct scmi_protocol_handle *ph; + struct notifier_block nb; +}; + +static int scmi_imx_bbm_read_time(struct device *dev, struct rtc_time *tm) +{ + struct scmi_imx_bbm *bbnsm = dev_get_drvdata(dev); + struct scmi_protocol_handle *ph = bbnsm->ph; + u64 val; + int ret; + + ret = bbnsm->ops->rtc_time_get(ph, 0, &val); + if (ret) + return ret; + + rtc_time64_to_tm(val, tm); + + return 0; +} + +static int scmi_imx_bbm_set_time(struct device *dev, struct rtc_time *tm) +{ + struct scmi_imx_bbm *bbnsm = dev_get_drvdata(dev); + struct scmi_protocol_handle *ph = bbnsm->ph; + u64 val; + + val = rtc_tm_to_time64(tm); + + return bbnsm->ops->rtc_time_set(ph, 0, val); +} + +static int scmi_imx_bbm_alarm_irq_enable(struct device *dev, unsigned int enable) +{ + struct scmi_imx_bbm *bbnsm = dev_get_drvdata(dev); + struct scmi_protocol_handle *ph = bbnsm->ph; + + /* scmi_imx_bbm_set_alarm enables the irq, just handle disable here */ + if (!enable) + return bbnsm->ops->rtc_alarm_set(ph, 0, false, 0); + + return 0; +} + +static int scmi_imx_bbm_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) +{ + struct scmi_imx_bbm *bbnsm = dev_get_drvdata(dev); + struct scmi_protocol_handle *ph = bbnsm->ph; + struct rtc_time *alrm_tm = &alrm->time; + u64 val; + + val = rtc_tm_to_time64(alrm_tm); + + return bbnsm->ops->rtc_alarm_set(ph, 0, true, val); +} + +static const struct rtc_class_ops smci_imx_bbm_rtc_ops = { + .read_time = scmi_imx_bbm_read_time, + .set_time = scmi_imx_bbm_set_time, + .set_alarm = scmi_imx_bbm_set_alarm, + .alarm_irq_enable = scmi_imx_bbm_alarm_irq_enable, +}; + +static int scmi_imx_bbm_rtc_notifier(struct notifier_block *nb, unsigned long event, void *data) +{ + struct scmi_imx_bbm *bbnsm = container_of(nb, struct scmi_imx_bbm, nb); + struct scmi_imx_bbm_notif_report *r = data; + + if (r->is_rtc) + rtc_update_irq(bbnsm->rtc_dev, 1, RTC_AF | RTC_IRQF); + else + pr_err("Unexpected bbm event: %s\n", __func__); + + return 0; +} + +static int scmi_imx_bbm_rtc_init(struct scmi_device *sdev) +{ + const struct scmi_handle *handle = sdev->handle; + struct device *dev = &sdev->dev; + struct scmi_imx_bbm *bbnsm = dev_get_drvdata(dev); + int ret; + + bbnsm->rtc_dev = devm_rtc_allocate_device(dev); + if (IS_ERR(bbnsm->rtc_dev)) + return PTR_ERR(bbnsm->rtc_dev); + + bbnsm->rtc_dev->ops = &smci_imx_bbm_rtc_ops; + bbnsm->rtc_dev->range_max = U32_MAX; + + bbnsm->nb.notifier_call = &scmi_imx_bbm_rtc_notifier; + ret = handle->notify_ops->devm_event_notifier_register(sdev, SCMI_PROTOCOL_IMX_BBM, + SCMI_EVENT_IMX_BBM_RTC, + NULL, &bbnsm->nb); + if (ret) + return ret; + + return devm_rtc_register_device(bbnsm->rtc_dev); +} + +static int scmi_imx_bbm_rtc_probe(struct scmi_device *sdev) +{ + const struct scmi_handle *handle = sdev->handle; + struct device *dev = &sdev->dev; + struct scmi_protocol_handle *ph; + struct scmi_imx_bbm *bbnsm; + int ret; + + if (!handle) + return -ENODEV; + + bbnsm = devm_kzalloc(dev, sizeof(*bbnsm), GFP_KERNEL); + if (!bbnsm) + return -ENOMEM; + + bbnsm->ops = handle->devm_protocol_get(sdev, SCMI_PROTOCOL_IMX_BBM, &ph); + if (IS_ERR(bbnsm->ops)) + return PTR_ERR(bbnsm->ops); + + bbnsm->ph = ph; + + device_init_wakeup(dev, true); + + dev_set_drvdata(dev, bbnsm); + + ret = scmi_imx_bbm_rtc_init(sdev); + if (ret) + device_init_wakeup(dev, false); + + return ret; +} + +static const struct scmi_device_id scmi_id_table[] = { + { SCMI_PROTOCOL_IMX_BBM, "imx-bbm-rtc" }, + { }, +}; +MODULE_DEVICE_TABLE(scmi, scmi_id_table); + +static struct scmi_driver scmi_imx_bbm_rtc_driver = { + .name = "scmi-imx-bbm-rtc", + .probe = scmi_imx_bbm_rtc_probe, + .id_table = scmi_id_table, +}; +module_scmi_driver(scmi_imx_bbm_rtc_driver); + +MODULE_AUTHOR("Peng Fan "); +MODULE_DESCRIPTION("IMX SM BBM RTC driver"); +MODULE_LICENSE("GPL");