From patchwork Fri Aug 23 09:05:22 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: 13774792 Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazon11011002.outbound.protection.outlook.com [52.101.70.2]) (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 E9131181B88 for ; Fri, 23 Aug 2024 08:57:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.70.2 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724403442; cv=fail; b=ZAvbgbBU6mH8aaX3gUdRdHaPFvJwwG4jZGqntpe5rVoZ8AtkZtJslvSp+TgeqNgnuupsQcz5ns1Ff1ZZqn4Hi8EIFdimBRJcKsQ9Nw0Fxgq2DtX39mzP87hEO9NwwNxlxkoCJt4MupmH5Ee2cEUYOAyxH71wPkDfK+sXEQDdw0c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724403442; c=relaxed/simple; bh=NUOF7J33SNo0WE5FvoAYCztsP3E+EVDnUROpA/hQ67c=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=dmnUP3bn4K+ymLRPtFrx40Ud0Z4KT47de1/6KINMO0s0bvRCVVURekNw8p6z5SWiXKt3Lri91F+6POBtBIHCiUuWP85N2+r/PvcFXf9/iWVKE1gT8o5F5S1YJlVyw8dLehmnZj4Ravk7zK8x9g82hrIoWBYPB8NZffGKDHrLhVs= 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=v2bDBJom; arc=fail smtp.client-ip=52.101.70.2 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="v2bDBJom" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IUUhXaSptVKNDre5NUJUjzb8Gn10VdFlVrx1HDZWMBnYzAaFSXfZE4gaPDeKy7dKEnGBzfe1JsYGqikXZPjeRp1jalMm4T3r07vipfXnGPzyed7LAW/Zk+T2RhQwnaU5VkCbrJLN9Hl2I6Uom7tph2ASpQ1JDCW1DJmxfx6MopyJ7ZVudSurxOZGqXUpPirlf4wY7b+F6pM1yvPCcmS+lb/B97AzIZ/s2/ndDhG0pEQMQJnnHSThCUFmOA2w9esSURz030cpXYqMOpmUrEYdacYooXyQ+PorcN59zy81sYvp6MiVSoDVxgPcPeURPL66DEtB89HBmmKNTAuPIT2IUg== 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=MApvW3b6HF5krhWAKtG9pIQgpnnDtvNLy3JI/M1wEEg=; b=N8tGnU1ZxRGIvrdS7IA62y3RewvomTSAztjwyXIduZ/q1XiSDBnOiOxBoG5Z8QXyV2WTRi0hMhMnrRlhFWtTSd3ESW87/KfUJcYO3dt+krRMiDLaxClJkFz2yjxpYIMLOOVTg43nIlomBAxUX2cRsh0tcHBkHHqnACG4EGt+XRk0mKdMEbfA4zrSncqsEdeNxUenTExB1LzqY4FyKcQeA38lbbMJD/oLBX20UUPQbo5tzlr9pmY5qG3SkYoZizQkRSMs03lqXIpnU9a398hI2ISlaocAPYw8t6J5TRFPJbrkPr7Ge/ddXkNqJUqX60yI3g5j7BF84ZyD+3shN4W2gw== 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=MApvW3b6HF5krhWAKtG9pIQgpnnDtvNLy3JI/M1wEEg=; b=v2bDBJom0jzQb+ds1WE048L0l5EKlu0uwywTy8L87CcgzoCzo4b3Oc8yplLVcdGKMWiadYxdEh97Q6OdNW+xIK5qsGH74wtJAO8HtUltCEr2Sf8BBwHeM2re4bZdc3Kkmw8DhEAYpRGUNSjmwNNE+mo8O2wXSz3puoBnr49D9tm+wXrv3Hyh8tyJwOgCOt02ECPwGWHbedaSOjDXD1lAgOG/HEyGbHvbe4+qBjt89oy8E+tg3ZYQMAqJIAV2n02yghWK9jTqYq5NKoFON0vkhGpgNzO4ipQ9XnQcZWIJnLYggY8jUbqq82g3mhODK4ZWPQnL3s3MnCosrM5rnm+jTw== 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 DBAPR04MB7271.eurprd04.prod.outlook.com (2603:10a6:10:1a6::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21; Fri, 23 Aug 2024 08:57:16 +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:16 +0000 From: "Peng Fan (OSS)" Date: Fri, 23 Aug 2024 17:05:22 +0800 Subject: [PATCH v8 6/7] rtc: support i.MX95 BBM RTC Message-Id: <20240823-imx95-bbm-misc-v2-v8-6-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=6360; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=ipvnuf27dki3nO9pw5HIbOzHnHeM3TfS1+lCPTW3Gr4=; b=L+uoU8QWjKkQ5+bYjVE7wTz6p1zamPRg84KpvfOqpxuEH6yA25EHKLSpsMjwANrtlCgmUJo9H uv9zYQeyD8KCQPUFx6qLDUL5e+kklm2M6GCYuBIkKLGK/XF8CbOXml1 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_|DBAPR04MB7271:EE_ X-MS-Office365-Filtering-Correlation-Id: 6cd11d93-247c-4006-6ca8-08dcc351962e 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|376014|7416014|1800799024|52116014|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?FipZWp3LZia10Epz2JP9ipreFjpblFS?= =?utf-8?q?ZNKMzoQvL/m9FQyIIU2csplJmSj1L/nZ4DV8emSQ3LQ58Di1LaQZIM8BZ80X5LLfv?= =?utf-8?q?idOqUSIDixUn/uEej3fxa0+YwWvY2DFVPe36St7h0DDmh7PWUo90AsCOG2RgKkN2v?= =?utf-8?q?w4j8I+OHZSh4KU8Wy4QsV+KA/RQ+KWO6ZPdjh8AZSIhoQ9k387Yzdpjr7D9EdPg6d?= =?utf-8?q?SiwJ4MVfWPWklhUdrYdj+ip7Ag0mm3I5H9b4SVCOIXVDElaSIm8ctNHFnAzdGylVe?= =?utf-8?q?1iTB9TE6cUozUbkqziReVEJ0pZJ2hnmhDUAgv4xIbW6QVbbGun5U35QOMFAUYM4UB?= =?utf-8?q?zHdYA9hWqg3H6msfZPE6EX9Ti6EOT6rTO/pXw9cJZmRMhzElKP2sw0SkCO7uIcheH?= =?utf-8?q?gmK3Fp8k2H+3ghcnzy2GDPXgnuxiH0kKFXYPu326TsS8TFtTrfjWMUt+Nss0YQlAe?= =?utf-8?q?DqYg6HXpExtsDivTXPfovtCT75ZwvfIPfNdTgxykPNDIrV9nuQ+cJiS23QrDpgsfU?= =?utf-8?q?ZSooqE2ndVidAvZO1EVilTSpQwKfjIfqoRcRqDfzgoySrkZnqvmWQ15uNBvU5QBsU?= =?utf-8?q?z3kd4wk55iB3FmWjsXlYLVBH5bZmEj8P91lV+Qt7rOrqk04V2h5XiwZXr7NfHM9xo?= =?utf-8?q?ayPGVml5iyBWnVk+vH1bBX4EsgHX/Eo5vr+JXqikGoEJitK36RkXLTvALH5xX+XOI?= =?utf-8?q?/svyeXGbLwwr5I+Cs5pGZ1ZEEIt830GgP/u90X01lwYz5RqgMTPnfd7MRLOD8JcBc?= =?utf-8?q?vOKvlbHNO51P2CpoPi7+GXweT9Uy6IA4I6BZzpob2wtxEvMHECgC6C4LtjhXC5i6x?= =?utf-8?q?WDsqKeMk3RXJlkC+phdQCMIWZmZAX59UOtMSz1QGMoIoOZfcfR9iyrf781Jt7rk2W?= =?utf-8?q?ZLSaM13de++ils9bfUmegen/ZRsN0o+RH3gUhTASRszicOm3bCqAzkTZ8tp8oaiMM?= =?utf-8?q?a14MxybuHDMcKAnus/p9bTiAQ+hUhdFR9GDg+FRvMZaiBtrJ5G5sCcKJBb6dU+vb9?= =?utf-8?q?HbLTGNwTnabqGanwgIsxZjT8f2Nw+bELYHNpFGsWNS3oq9YIMX9EpbXfKJBW4P3JN?= =?utf-8?q?O9wXqBZfG51f7JCuyyh1bodmO+IzJ8GOYCFf2mtZgTB/IJ/GibCzQnv5B8x+g2WbE?= =?utf-8?q?HAtO1xsvlC6hQF/+/YQ/H4Js5D8as13so96W7FDMS0sE5utymuYK2kufmOUQJcqAW?= =?utf-8?q?yLOiO5bBB/o2xVU8YUrcDW1LOBy2IHglr6AI8egdocj8LtbfgzfnGhi0/6ZYWeC6X?= =?utf-8?q?JWreClzT0FBy9GR0hN6VRSz8uwvM+iuQ6oY/h81OcFkGzACM0n4ScxwvCapHdG9dD?= =?utf-8?q?VJyJOoXD/HqUTMHleUFz91tnNM1x8GE7PKH3IFtoT+kRnnXK0Yi5qxo=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)(376014)(7416014)(1800799024)(52116014)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Rr+/vbSOp0BljZ7PjYPujzfDUiB4?= =?utf-8?q?cG4fQMg71q8XPYOHNwh/5Nur5MyYUozGHUct5LfZaV7sEs4gQ8KjXGu0C6GhpWF+t?= =?utf-8?q?V7zKDXArmPeeIRV9T5wiynsZ1Jnhi3VNgRGsOejbcQgeYO+OaXkO1++tCzvi4OHw+?= =?utf-8?q?6hTZ4m0GCF0twjn8XccDkUvqIb4/bwdprMvXwuCMNX/QNCpcOmf0WH/HmxOq7HYRV?= =?utf-8?q?kJyazVGnG61AlAL91vBY75mTstkSha0LlgE5hpO9s7JkjJ4tL6oi+xCkoo30RoIdJ?= =?utf-8?q?s7wlhAGj4Vd+HJKEov5mq0hpe3sF24jrlOPDB5eHBna9wjsG+uE2B2W0XNuDhT2y1?= =?utf-8?q?UF22Oe1D5Q1qoqvM1DO8cfiaqbePJoDyRjX5nwMzZwMw+yFOrFbbl9y+9PvlqSrnR?= =?utf-8?q?8OLG6zpngKLYjUwlojiStkYcUujmOYAE6h0bgX48mtRkLwt0s7UqG9sAXaWw9mNBV?= =?utf-8?q?+FSaInkefqjGOli1udi+QnL2rZoryBBF8dnjtoWmNUBQN3Foj3K895VvLJGM/veK3?= =?utf-8?q?jP2qNz/51YW+4DKzfnJUn0xO4bAvWFTUd7TIg+BzR5xDRZay60D860NP6hnpYlW7f?= =?utf-8?q?K0LzsJEsb6wWrAJczQOwkdQAs3H0UiQDyBXWnANX9E9gDx0Bupj7BN5KZ1M/9FLgN?= =?utf-8?q?cc4+su94n/O5TUtesELSEcC4MfOqBd4gvj0dBuXi0Snmy6lMIptuQ+ceKMsER0FEa?= =?utf-8?q?oGUOwbjXnXREEPm8oXWWMra+H81E5mbR9fk9kUJFdtE1SDpNFuOTE1KdFaqQzyiUc?= =?utf-8?q?A4T8NApco9hXp9A2/c3uFY47wUuPJlmiErQDBpviVM3k9xqx6uJd/FZoYuDHHET2L?= =?utf-8?q?d2bqRsA70w0VcvQZ8FaxYRFSfZQ5X2XyNwdmA7ZfIYdsQV6z8pi9s+iuTvMBIsW8m?= =?utf-8?q?J/dmuzWpb8piFjFniTVxJc6LI65ApZfKHw2mNPlIkRoyfYv172ngpEH3SR0h4UaYd?= =?utf-8?q?sG7L2Wcv01gC2iXROsrawFNzGrvmqfZydfuu6qs4jjgozNWii9s8NnnQtJsGx/2UE?= =?utf-8?q?8XHcbwsWJacYggEqop+ZbTNv4/K7AIMF7dvGT062G2OfDGWSkkixSKuJpuKOyUzda?= =?utf-8?q?iHSDWv3xRahxLs8m7nG8gHmOR9LTf/HYX7RmbUmFoMAE33XjgTLPlnNr//agoEPGJ?= =?utf-8?q?YZbHruBnKoKnwYT50T0aKkvz5AUseKkU1czJiGrdUrbLu5d1DxVus4Ahi0GObN1Nz?= =?utf-8?q?HntotmwuN/YoZSlUoMoqyYFbOLwMYffeucnyDWmDJE18qjkhvhJdbIFU/Z51I3T88?= =?utf-8?q?2xUJxnPZAM4aunM1TIV0beaNV7qVC7NFwYvVXig2EOUouopZP+IZcisGQkcCV5fik?= =?utf-8?q?XO3HVDudfyAmz3hTIC+0mD6z7GuEdn70VOp20ygLNA0tbQDbGLWJKptasf1GEZ2mA?= =?utf-8?q?n9Ht7ws/JsLPR+DRaGSYDUo52tAzuQg+eOz0//Due+siLLu8n4Jdxvzzaukn19TAR?= =?utf-8?q?8Y4Ea5KK4YzCZKRO+3WoJHKQGmpFZXRXm45Sy/QiJR3bf+OWA0d5IqVfwpKZML3Nu?= =?utf-8?q?MPEufiFhTCHW?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6cd11d93-247c-4006-6ca8-08dcc351962e 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:16.0454 (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: c1u2bVMBau0Mfi01SO0rc50Zc6gWdm5JIZiS0hfcYxLRlY610mifPjw+1+iUHjz7PQ1YEJjrdFY1iPxlzXr7Vg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR04MB7271 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 Acked-by: Alexandre Belloni --- 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 b3469f6986e9..ea416938ad24 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");