From patchwork Fri Jun 21 07:04:41 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: 806441 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2088.outbound.protection.outlook.com [40.107.22.88]) (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 AD16716D334; Fri, 21 Jun 2024 06:56:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.88 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718952984; cv=fail; b=hYNzpVLDBgVAZK4r67UAHI4C+P5Th6gspBrAzMvfd1ZZFLGGQE10RJ06NHFgsX9BZWBN2weS2PLlDXN+EKoNNYV8RMfjnz75X3orfMpFArfuAELoxAFL9l7LSTzk0eJpIO1ytB0oIGAs+264TgOcTK/B/DtQdRO/Vf/7dxmT5v0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718952984; c=relaxed/simple; bh=CqMGW21wLzQwHCQSMNma+Vvw2YS/kHx8/LptB3z0aIg=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=NXqkQIvofFZkVNajR+eCirrBmErOQ4eyJyPSuCFaaslBzmMupehhvWUSWPoUeXw2GUAdUIkegH2CZ5al8myWTA0S2mkEsTks0k7nkxrDMVnd6bpbgwmkKqrApNN21RMcvaZ3kOB3SwZv6Tab3xGc0TgtLZznMqUzAiF9YrVBdCI= 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=UI/3inGG; arc=fail smtp.client-ip=40.107.22.88 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="UI/3inGG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eFg9s5Dp1r8m7WtLpXbg9/Rim8aWoLZbOEzJ2uhPhMjlSBD/QA1F86i+OZzmhduAsKI8EPVtEP/I72N2/s1g5lMeccdSNUDVQlrkkENw4jtiC2ACAFgRiuYicM5Qq6ROUor5zwOD6wi2NmPuKsorGlwpq2NgMShV+OZN518lccVa1NqJYRk06lOwhb6vXn7oJIuHauL8yN8MScggP8ueddQJMjdiwREPjodrcAaq2ni31UIxlIH1kP1t5g/lsbcTnr7oRJ8sglFB97zb+kDU/MGVzmEBDZ/OB8bzzMsVMa0Gn1q9qnxwIVIkqdPUVjyKnnzkTvoloQyvpLVqt1W1DQ== 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=fWJNKk3jgwCNHoMe46PPOkniwkqxONFBhlGDDTjK5QU=; b=BHMCPHjApc9HKIE4tM9BJcdo5wiTBDH3hr1uaHXJmIE4jxRyPNscBltfFgsBzctvatE7Y7tGFTa/2bR3JRtidK7s00Yjs4vvuMBiUiwk0xgMmwSai5MW4nCrDXDAv5sK3j9T1Pk4EckYDtoPE0QjoWUZmkA3/3XcLkDuGIEZNlkAswPs8JLliG75EW3tPZGDqXw85OiNWhC5OSmOIrvG/bImm9mI4aaL4aSTdfcc9kjqGA8MW9U6tXPRZn2VMq0m7wJ6FzhiIkHf9VlqW997ZpxoVlj9q8Nd5v5miTFpBTL7OVH7SXEvWl/GSIKLaT2JipchUuM3Thwu0sb9s09cFw== 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=fWJNKk3jgwCNHoMe46PPOkniwkqxONFBhlGDDTjK5QU=; b=UI/3inGGSJJVA5PAgngl0YDhFRixMCY1Nxm3d56QQoKSxAA8vP3EpRmliYeQaW4rV59uKieBjtNT6jV9plXC+HQn6kJuw5/frvliVLXZs8PSnXOCRk+e+TTQMORwQPpzLxsSPax5Ss84LByqgfqQi9UpzoJJAeY+Xkw1yshD/4M= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM6PR04MB5941.eurprd04.prod.outlook.com (2603:10a6:20b:9e::16) by GV1PR04MB10426.eurprd04.prod.outlook.com (2603:10a6:150:1cc::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.19; Fri, 21 Jun 2024 06:56:18 +0000 Received: from AM6PR04MB5941.eurprd04.prod.outlook.com ([fe80::9f4e:b695:f5f0:5256]) by AM6PR04MB5941.eurprd04.prod.outlook.com ([fe80::9f4e:b695:f5f0:5256%4]) with mapi id 15.20.7698.017; Fri, 21 Jun 2024 06:56:18 +0000 From: "Peng Fan (OSS)" Date: Fri, 21 Jun 2024 15:04:41 +0800 Subject: [PATCH v5 6/7] rtc: support i.MX95 BBM RTC Message-Id: <20240621-imx95-bbm-misc-v2-v5-6-b85a6bf778cb@nxp.com> References: <20240621-imx95-bbm-misc-v2-v5-0-b85a6bf778cb@nxp.com> In-Reply-To: <20240621-imx95-bbm-misc-v2-v5-0-b85a6bf778cb@nxp.com> To: Jonathan Corbet , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Peng Fan , Alexandre Belloni , Dmitry Torokhov Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, arm-scmi@vger.kernel.org, linux-rtc@vger.kernel.org, linux-input@vger.kernel.org X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1718953487; l=6289; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=3stfAX6GDrY2yBI8qtkGNlp9Yy53JQgBChIeJkCcYsU=; b=lpdaEaKWf70vtixuRA2/MHtFiMqlaDNTv4mxP597gAdLj+D7yFjG77tszgA3/F0QA6nT8PB4L RVmgTlu91HDCIpJ6UHizg/MMCKLbUR/YE+VmrIpFO0sknoivOiK2t2S X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2PR01CA0122.apcprd01.prod.exchangelabs.com (2603:1096:4:40::26) To AM6PR04MB5941.eurprd04.prod.outlook.com (2603:10a6:20b:9e::16) 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: AM6PR04MB5941:EE_|GV1PR04MB10426:EE_ X-MS-Office365-Filtering-Correlation-Id: d5e00da9-c5ad-49c4-f526-08dc91bf4082 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230037|1800799021|366013|52116011|7416011|376011|921017|38350700011; X-Microsoft-Antispam-Message-Info: =?utf-8?q?Fv1ceZHCxzp3xo8tHBeCxNZIP0lZaQN?= =?utf-8?q?4UhXxlYMiFV69TxbgPSnmb8tidxgeewsLyfzZ+xqCc/npYm3CG9zVxMJVFrZ3LKXR?= =?utf-8?q?UUU17SKaeps7YGDrI+JyLLUDkX2B87BFIji90mwFC/clMEPORTvcVPoz3EKYGIGmG?= =?utf-8?q?KfkLtOLenf3yd4F98tVaQ4pNXmAKk3inIaGKCAofJGz6JkBeC4Ef0fjZ3BQ3InRcC?= =?utf-8?q?P81z4i9XNHa/F5A6SWx6W8SnMnoYVqP9F5++Qfo0aUeR8RpjZi7k5A/vyFDBTfkaX?= =?utf-8?q?j1EFei9odEettoSirRjoF4Ds+HNi6Ld+v6OMlrH2E1SljlxqvFNQ/Py5vPmQ86q0X?= =?utf-8?q?Qyge/Jle1VbQPG3wOr/wwouOckcqO6Lcqacnk8D32WKcx/pIOUN1Od8fxBhw8zoaX?= =?utf-8?q?aikurf5ZxQoPbhCwTcAqGYWe20gkz2rS8MpF9PpwhtH1RME7zVJOnpxW4o0+LJYJY?= =?utf-8?q?jtfROMWlj79O34Qb5uc9G9rhy3QQh7V/cng0ETe2PNMJO5d2URfcrCT0Mn5Rrd3KJ?= =?utf-8?q?vB2TVP/S2olzDyZSdXVtibRy60VxkKKDm5b5/1pFFKJIiLyAKq3RgvQhJbSfVa9Kk?= =?utf-8?q?7imVPPGd9IdntOOeRh4Vb4EGplofRkbZB6y8lwBhn1GDc7y4Tb9Z+7q1eJruQHJro?= =?utf-8?q?/CoHIPLhETBPaDID7+NfRZJksVjqPQ7cMrap9N/lNTebXKA7Za/48tsqK77RkfmME?= =?utf-8?q?c2E95/zWSSufoPK3d0k1AMRI0I853fQnqGZAqGwWxg0VADR85W8WwQHfVbAOXdGsd?= =?utf-8?q?o8HGD6TsaCdp01q0/LK1tWMoMU7RM4IVTOit0vAbj/U1sv1oCaLQieMCJVAbsHZ99?= =?utf-8?q?qrhqA0ZHNFERvFWE4spCWlGh/6hty/y22xceU1jDBhs3syru+1Kvjx613dbscMuAF?= =?utf-8?q?ebiSSJ7GTlPzsDdNn6Vb6FokeuY66Si5knpknEOoqlRRzTN+BM+yki9/7mlGPa8BN?= =?utf-8?q?SrSfRBhp/KCTU2DRVdKKkkzVoZadOZq/3aSnB0lp9qj/IWVfCdfZctDj3wYJoYthC?= =?utf-8?q?EWw09F1Sg2dJ2etgCMGukHpJquFrOciAfoAf50W14y5e19PYCG7rLJhXwFCFj3V1F?= =?utf-8?q?27PSu8tznA07UOpy74fl0A3Sn35U4iSntIGvm8Yj8rysaU7f7Tl4Z+1FkEmoQMcKX?= =?utf-8?q?RfEvLNT2OWgIIqLldf3A6S8H0ZhXueZx12hPMMjnPbs8yLJhPkQRZvSeDjdurh8Qa?= =?utf-8?q?hRESlrclydhKsy+pGuhFFrQ3iEEw9YR4q95fdqRgH0y0gM4Nxr7URaphz4hEESUi/?= =?utf-8?q?sgSCR3CzMqmfNuiir862xK1MoxohUWAgawLh1rF2WtPylSvPNhHmVObTn9OHGLTpB?= =?utf-8?q?SdPvjGWecvX+?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR04MB5941.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230037)(1800799021)(366013)(52116011)(7416011)(376011)(921017)(38350700011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?hAWdWoFl6Q41ldo8bZuo6fvmDKEp?= =?utf-8?q?SFH9qLJcBrFAd/ccqEGxrRg+OoW+kGz0PaIhotlVy31zC9gQlKNftsvqBR5eb2Yxd?= =?utf-8?q?Llxloe1yfzsfzaUpOJE26OTjy52P2usn7L0oAvtQ47GG3sBAqVfrDiOSYvX4YXxUn?= =?utf-8?q?OzIyr1lFc/a0v+GRYVseBnsUIka5+J+YxeX4uoNgSxU4pqqPPegbXv5GVJ2QAGm+k?= =?utf-8?q?f0Fr3yskIvDGeqriOXdJpk0g53fh90SbOoTposjW3IWOoipuhVzk9Wli+JTmsdsSz?= =?utf-8?q?3RsYy+Vle9bfomOBSGFtU7W7y2qjA8hnSs7SqbVV0ZbhHQFS6wHXxVJ3D2YoVCupF?= =?utf-8?q?9QYpuw+r8oebCRnsRli/xQdnbQJxMHoAHHPTUuNC9S8GnZ+cK1uljYwUoG0j9ewpU?= =?utf-8?q?ZQTDNt9sKhkrS4kyCPuEHOwEvb41a+mlugwAuW3ZPMdZkMGkgZjddFpSezb9EX0xz?= =?utf-8?q?PA7okEqBSM42JWa3B9mE25A2baTOARrb3I4+cEReStFIQj+XDefJLGhWS6rv1yUug?= =?utf-8?q?y3OW+Mfo8u2SPqvkc4PdNYXJ599cd5NDalMNigZ2PkO0r9TejHmXVJGniByOYJ1Pe?= =?utf-8?q?lNk4FWUrZDMxm4GuvrwMxNStmf32Tl3LwU0UtHdu+bNPcbbPLt2g2mzKoFZHbSMDK?= =?utf-8?q?f8GXpDmomHb/x8u0GRE3Kv0qFVjxJDqbIZIigJ21LO+GxGvU483rDIG4ReyFv+CXp?= =?utf-8?q?3FzJV8wPMaIhJTlB/F8tFI8xfltebXg371xyg5T+S4lQsOA1troCkBOt6QB1L0cXG?= =?utf-8?q?B7z9eJ/RBseqqnIgqVZFC435YZql4gJEqaNwCshEcMNe8FOTVfD8ONdRQZpTWvVGe?= =?utf-8?q?vgUP8sghVgt1Mt9PJ5jkehj/CcGvTVd9WNHP+PvxuNaeUhem/53bjz/UOKuY0CI8z?= =?utf-8?q?2CE6qPeM+VOjkzCRHA30gGtcP2MuSk5TLQ/8n5l5vpdapOuJ73Gr00WHccRHI82tE?= =?utf-8?q?0xwVapV1WYnTKW2XZiAWsqr0Iz5bGhHMf1qthfIZMPHBPDUOVyW4r68IFuZHXSWMC?= =?utf-8?q?xzRBh/M9d4sGdC8iSbx/JydfirDbu8zXgktzliDZJHxXSgaNLwtGbEkDALEM62UQZ?= =?utf-8?q?A68irGYabFSRSVHKtDKkBlNe0kXtSMxalbgQz81x3nr3Eo41Jr/owABKzGcMGPcAh?= =?utf-8?q?rgYMI4A1qQPl1LT2jjQbhRgX08f90B1QuHgLjLMSgGLsxGK+LVTDWXVrciX6FU0fW?= =?utf-8?q?ZK0doka2rx5Ea5aJYE5yDFWtqsIEu8HOf2WRAbgxvBBi3PtYOdcLp4q33/TCXx2RD?= =?utf-8?q?fR93rKVmZOpNyISWNRexPLRDC/Urq5ZUc6jko79DLyZ2n4C1mddddQREgGuC5Aa9v?= =?utf-8?q?m7hWPBbo5fA0KVxDSy539R7yOuQzj9qk4WbQyEZUY+a7uJdf2ctP9xW9eRavPAEQd?= =?utf-8?q?NEHGTbgtjxiMSoOErxCcjfzt1rXVEv0Oqq4iOM2SZHgtux6xKRTbDiFRYiJmDiLKH?= =?utf-8?q?hmbpZuOm+MJCO2qpyu8LT8sOpo49lOhJjsjFbDRTzXmxcm6DffJ5VAzwUUmDUqI5/?= =?utf-8?q?pOY509uTPJV4?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d5e00da9-c5ad-49c4-f526-08dc91bf4082 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB5941.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2024 06:56:18.8318 (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: 3+2tW1uSKcaq430a3oHeOaKlc/rrJ2Rcc1D7+ZmCt8X26sCMVAHg+V4MVJHU80mlftxHa7LrCUKA5HwRIKihZw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB10426 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. Signed-off-by: Peng Fan Reviewed-by: Cristian Marussi --- drivers/rtc/Kconfig | 8 +++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-imx-sm-bbm.c | 168 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 177 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..a634e5915d2b --- /dev/null +++ b/drivers/rtc/rtc-imx-sm-bbm.c @@ -0,0 +1,168 @@ +// 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) { + dev_err(dev, "%s: %d\n", __func__, 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; + int ret; + + val = rtc_tm_to_time64(tm); + + ret = bbnsm->ops->rtc_time_set(ph, 0, val); + if (ret) + dev_err(dev, "%s: %d\n", __func__, ret); + + return ret; +} + +static int scmi_imx_bbm_alarm_irq_enable(struct device *dev, unsigned int enable) +{ + 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; + int ret; + + val = rtc_tm_to_time64(alrm_tm); + + ret = bbnsm->ops->rtc_alarm_set(ph, 0, val); + if (ret) + dev_err(dev, "%s: %d\n", __func__, ret); + + return ret; +} + +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_min = 0; + bbnsm->rtc_dev->range_max = U32_MAX; + + ret = devm_rtc_register_device(bbnsm->rtc_dev); + if (ret) + return ret; + + bbnsm->nb.notifier_call = &scmi_imx_bbm_rtc_notifier; + return handle->notify_ops->devm_event_notifier_register(sdev, SCMI_PROTOCOL_IMX_BBM, + SCMI_EVENT_IMX_BBM_RTC, + NULL, &bbnsm->nb); +} + +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");