From patchwork Mon Jan 20 02:25:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan (OSS)" X-Patchwork-Id: 13944691 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2055.outbound.protection.outlook.com [40.107.241.55]) (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 9A69A1494C2 for ; Mon, 20 Jan 2025 02:26:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.241.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737340005; cv=fail; b=WHJrzaP6NHXCIB1NmovJS7eA3K9IiCqWnpJqqLG1kJ49VEIkSicW8ia9SPVVx/LLDtu33pgmR2TGfTKYe8RL9gBc2RPho5OZX8Xgf2etAcsf9AXcsaA3JqvLU908wSGz5qLjgfg8JTCVNeN0gvMBv5IV274CbLjDXur6F0oGKv0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737340005; c=relaxed/simple; bh=Gkwmu72GW/T8BO4fFQuc9k2zZWr3upHH3QZnD9ouLP4=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=DQQ8dvnOpvLllhkG70uW5NWzw0vNdP0Sw2jjEeJo1b3Xmu94TXnQnqgxEfDdbFEkgwNP3pSN5mVVzvHMnqPkW4TTOI2H+U5gKjJIXGJUzdvcpk++o4d7BnHwG1FZ7SXaI2nzEInweCL5jAHkbGHDxB5N3sHaP7GKbI7Hp2wBrLg= 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=hKMrbcf5; arc=fail smtp.client-ip=40.107.241.55 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="hKMrbcf5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EPYvAu+EtnxssWrwRuv3ZUoXwY65PfGoY+7jrhC63ODXDVznPaZ3CQ1k1UQ/YI+ZbsqWPZjdYgwe+ttxfJYqLmwZkZzbejFOmeQTti80PXJJbLUOlV3pswEyy6bgzQp6SbON3VefUba8VJRaftjgsrtbbO3onaWV8iyHwV6RVDvM8e+1yv9LX8RpGcNT6PkQ3923cGwI9fGdoEYYQMIxUQyWE9AUMy5afu+/VRSPC2k6jkhJi3EBwu6vM5HTp5ja87r9+NNC+JdN7WlTsheqPsXLnG5lDEfacZS372yyajr2l3841Qniw5r7BpUpvyz1/wbd3Y+/ELxFLap+npzr6w== 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=jl8nAGY/ZjoDzYb1Yak58SewtrQzOg8+j/EYm1sobVo=; b=c7gl+0hGGBjGF+YKRi0FXZXpbV7Ixq1aNpaxemjTaBnv29tA1Q6HmVmZa2RvDAQPm4mHZccVs9De0WHhoqPcxeeUcIhzXss1c9n7Lu6eeqN2Kt2uRJ6DS0jRykpM4HdSb2JUTRA93x4A0QeG8fvSD5gv4S3ld8uwdPc6Vq7EK6Hh754I4IVDQPeDiOZPDWhmjVIcjQtt0AOzDrGowouNX0LBtSzvquFvG4ezXYJ4dl4YA/PRVjJktGtfUtyy/gLuYlvtOKaJD1rsqm+jna6sARBrsz/reGFBtIZjefGF/mf12I6DMvqcfyuHBbnUJaImPJ2MH5YdB8dqU+auiapSPw== 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=jl8nAGY/ZjoDzYb1Yak58SewtrQzOg8+j/EYm1sobVo=; b=hKMrbcf532RNiBz1a/saqM+z7CeisO46Vwsg6La8X7PcW5SXFFb1eJVz1dqXXwNmvsrPCGiB+84sWauu9B6PiGclwJ7sTEERMNCNJlO9E2SSA/n26MRIna2W+hoOL+ZuZga3RELbYfHcLNeiouNt+PT1huTyANYrNJuyKx3JR2DjnQqXT2jZWPG7OFI23NLSmqOifRTWFxSm06iv9/6r3Rz0NxJotZWLlfkQjYP1pfvXxDGIaBUzWVrTMwyTJYSzCIPKPp/E5juWShLgjlrBswvvP6OBYbjl4J44oTe9C56o0ZDDhQFF+zzVrMI+1IJOLGzlDT/4IaylXr17ZkCdmg== 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 AS8PR04MB8690.eurprd04.prod.outlook.com (2603:10a6:20b:429::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.17; Mon, 20 Jan 2025 02:26:41 +0000 Received: from PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630]) by PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630%5]) with mapi id 15.20.8356.020; Mon, 20 Jan 2025 02:26:41 +0000 From: "Peng Fan (OSS)" Date: Mon, 20 Jan 2025 10:25:36 +0800 Subject: [PATCH 4/4] rtc: imx-sm-bbm: Support multiple RTCs Message-Id: <20250120-rtc-v1-4-08c50830bac9@nxp.com> References: <20250120-rtc-v1-0-08c50830bac9@nxp.com> In-Reply-To: <20250120-rtc-v1-0-08c50830bac9@nxp.com> To: Sudeep Holla , Cristian Marussi , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Alexandre Belloni Cc: arm-scmi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org, Peng Fan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1737339953; l=5574; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=iF6bDJjhb1QTl2LY4lI/hL+omPn4K8AgkYH5lkX3plk=; b=DG4qxX2zPOrPVsqm/bacn+JQDSZJol1U5HpUMP+2sMFsZeh8uJ+JyjQIkmvudRyPhmviz4duP CY1fjZZ/0WXB9jqOjFmvAuM+ldiD46k0m4kJNlbON2es7/cawLP8kxl X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2P153CA0038.APCP153.PROD.OUTLOOK.COM (2603:1096:4:c6::7) 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_|AS8PR04MB8690:EE_ X-MS-Office365-Filtering-Correlation-Id: 20befcec-14d9-466e-f6c7-08dd38f9dfe6 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|376014|7416014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?56jKp9YWhNMuDNZAYOHZowa/ZxBysgm?= =?utf-8?q?8Fc/VETWT/UNqN3osSehcPQ2G9EgRGCunmwfwweUPgu/OJKdAtSDZNdV7RwzSUBnH?= =?utf-8?q?I8+cxvQjP2auycINp9228qcQ3f8fOr4d/x82mHrEmeZyQzGMBKD6p5Cy0ojHYJgnf?= =?utf-8?q?1E+1y2sFcYkRcHZ5fT/b4y6UmIhn6oK6THe8knyGja/0mRRoAB89mJJ/sFRvjd2Va?= =?utf-8?q?LOyPL8NdjCGJZ5mEDVcEMMNRVY1Yf9tdSv8CSHtiNTd2xKkGHKRw+U7RlL86nLOQu?= =?utf-8?q?ae37I50GN75rtmcXQSli+EHeu4Fpgd9bMd1jMbrraJj/M2v9KAq6+0hdWmn0Mwb8F?= =?utf-8?q?37dGxIpEiHXHyrOxEvS93Zru3BwPN/nIYjvkMltQ0U1e715sg9O4VHYe1mEl78+Sz?= =?utf-8?q?nNQmhYUzt4aT5SRtDdqHgIkClUHCt+EtPOL2LzAmpe502TrJXjt9iPFsiLDhMwD4c?= =?utf-8?q?vgReaHcTRpide2+/7gsbT+gWSfWwCmyXjjSUdg97uBpeocU1L5z8s7nM3u3Qmk8jk?= =?utf-8?q?YE2cMvGNwX0UJqdXnfPoE43dAWyaD3A4Ppyu5zt4l23+cruAAmBWJQnBH62zndkPz?= =?utf-8?q?0GVMVKA2G1jbK9SynabD0TgwmTGRBmX2GuvtzWHWI0l9sE1NaiVOle2rYW3qmJh0G?= =?utf-8?q?f7w9QYdEcbzaPTeNvjxYidqPylw+5Ki1bqbLk14CsHnrTZdQpPkkqUrCREfis7G4D?= =?utf-8?q?LgavFn2cUg27TYV4B+bzNxNBhiNRQ0sB0xhXKEG5gb596u4GCZc3iSIz6BxMI+w85?= =?utf-8?q?FySLP0laLivMiBBj65d8Ccci0Eaq0i7Ggk1N/Dx6aI1U5yO04sZTqab0St/+84Qsy?= =?utf-8?q?8PiyW6+SIJ94nakZYdQh3dHyTO9YDqfOb+r0w/HQDlxMpGRGaEbs1G0oaUAO3NkX6?= =?utf-8?q?KAoZNITx0RZU/iye6p+Eu4xkn8TrGNp96oMKXCO+Sq+KswLwqOP89n36jWq72cIQK?= =?utf-8?q?O5ULQNI3xtV4v9YczsmF6QrmvSZzCH59QVI/0ds/EDuTJBh+bY3pAQB4BEVmAIjMU?= =?utf-8?q?qVxLcXPhG89B4rUXjCi+vlSCs9HkTQC69hcCgp2Y3C9etJO57voypPJ0wv8TvCbDt?= =?utf-8?q?tqhwOcGVTzMNAMpSQBj80IdjvWg0p6h31CtvyB75Oh3I2l2m8hFPLt0Wus+UjZcc3?= =?utf-8?q?ZEVYbdnX0FLUSdcfaHb+j9A8hU9Kk2oJhWKE0kdfwv/HuQPYgmCUCnaUajKKebVes?= =?utf-8?q?JgsCC5h9fb0bHYERYQ8tvtxv/F3X+HddjwZRT6slkBgjbdVg6BFldboELNsWWIc0k?= =?utf-8?q?9cTzvOFKJz6uFgz3VCTrr3bZS+L/+I7PYK9AqxHnrI0F+lgFNYArgNEmhZusvoip5?= =?utf-8?q?Fna1Wc1UMKG+osk/HdwSa2pKXDhbuDcdCiquqiQW2LD8JNS/6GaDYTfA1fVEup/ga?= =?utf-8?q?crOu8eEVGQj?= 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)(376014)(7416014)(52116014)(366016)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?3NSxGlSFPcSy8dzsW7ZtVFKEvgKH?= =?utf-8?q?YVFzPPlerNNS4vAhGOieXGy4hDzvNMtjlCXCYejv/XETVdSVN7rTN60lwHV42zQL+?= =?utf-8?q?z1e1Y9MRkl3EcEnAu6cw3UYtii1t7x/jbDkKdzWSTga/E+kOEQfsJvmJgEcxQB4VQ?= =?utf-8?q?1bQoILMw5AkJ49Zsc+bVjxi0vYAq+KZvLtqmpPglEiATdUdT0qQgmjwLhHtePcPz5?= =?utf-8?q?ihEZVGTYlwIyN/zmTddVEd/cE74PuhiYUUoW45GTfSHMhfjBxgwLFod12R77SAi6p?= =?utf-8?q?0Tm00tS3uyh4r+sXAxeg0d4+1u0TaQ3e74Ag20Kl/hLHmOJjqBvXq5GodH0TDOQtg?= =?utf-8?q?AZIPtwQehbvz8gon3aYludOlz1u6N/WCnH+hpFv3MgWB+tF4rs3YQDgBgGoB/7Wrh?= =?utf-8?q?yZxn58zi/8JDzcvV13YvNVRup0Hx555Nep7HUUktrrmdbcr+ae+/CEjZNhK8mEKhD?= =?utf-8?q?GKyh5/oKkqKiyhtfmccG1gnt2dWx5PLt5gDFpBR7Gif3FvFlDccP76tXsZvBVGkSZ?= =?utf-8?q?kO/syqtZHiuNxMLMM4/lOxxamdp4xbWaQwhtOpCLwvRPvYiFaKeLP8MCeXycp6+a4?= =?utf-8?q?dxqyErDME+BvaD3NeuG2HRa/ZHJxr4nncX7TvbGV6yeQPnn6cSym3wfhyw66WtSsi?= =?utf-8?q?AYDXyA/LIBHOHGDxJQFv5W6TWqou187wj2wovtbARtlM47xAn+HbtjaDobuo+ItSc?= =?utf-8?q?r3oyNFzLe6elBn1baYc0zOFYRw6ItL6M8GKFDquI1vF1jNKHDXWuycP6hxXQpqQYo?= =?utf-8?q?F8cusbgbEhdtGJ8txab99ASwnhAgiVpuK6hZvTonUNmfPZN6bSJ0Ru/BcgcaxzgXz?= =?utf-8?q?Anuv2v6PAZKycCHOv//4jCjOZDDwBmM0BCGvmtF2kjJBCUaaf592mVSos0j8o8gqt?= =?utf-8?q?59LzBVR3cI1UqkHkGUHslH+oPQwFSBYFnm99jofMrhUny2MflGSR89W/cjbvXx+mN?= =?utf-8?q?Y7Pb//X4rL4ERPqM8sdZIRtxEmagBHLKxhzCST4iSI5rCIegwmtrYLTavJx0YRSUL?= =?utf-8?q?mlalGiblyRlWX7XdY+kzEPPh7A3kckI/JUyi6FMvrV8XoLFMzbFduNgUeHOrDGW8i?= =?utf-8?q?UVAzIi4esiKNlikKVHHdPzOj9uz3ld3dExGJXf64glanpahq5BT+VNV2jcYhGPnru?= =?utf-8?q?welc4ILC/e8XVn2C/SoJt+4riDXUjdqMBlIOPMbciIafeX8hq25jgP5HHPFmnWV5N?= =?utf-8?q?PDigHg8kjAHSIu3waI5GGrEOcN/CgXu6zDoTiqYFsEuqX29hoXA+7G8Hu6BjNLax7?= =?utf-8?q?btEyvf2XvOJNs74+qUMAPNcb2EiNDPjNXbnGEGNra50NTDAPZ/BVSgtQFQ74eztJN?= =?utf-8?q?CIHNbxNDuyZ/B/bnI94OrIjE0TfekOfbi97ULs0kozT+Qt7mBrBeYjA/WPeDBWrQB?= =?utf-8?q?hdVVBwF7h0xR/JSSjqKkck+pQYFWfDtRXxwoHZ2g8tqrPuwsDI7eBNcCVaBlQu3if?= =?utf-8?q?wFKAIh8hqUR122/Sd+qyIpO8Ywd0nxYD0PLNU5HbtTfdCTnAIkxlxS/WkK1S8eli4?= =?utf-8?q?5KQH6W5C71rx?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 20befcec-14d9-466e-f6c7-08dd38f9dfe6 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jan 2025 02:26:41.1846 (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: D9S848fhkD2m4+eyC5EyCJl4p1xMTgyrGu6NBQh6IEd66ooj9mwphedY3hA6cp1refMMwB7f1IzvksQU+L6RBg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8690 From: Peng Fan i.MX95 EVK has two RTCs exported by SCMI BBM protocol. Current driver only enables the 1st RTC inside BBNSM module, leaving the board RTC not used by Linux. To use the 2nd RTC, use 'bbm_info' to get the number of RTCs, register them all, and set 'bbnsm' as private info for rtc device to know which RTC it is when using rtc_class_ops to access rtc device. Signed-off-by: Peng Fan --- drivers/rtc/rtc-imx-sm-bbm.c | 69 +++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/drivers/rtc/rtc-imx-sm-bbm.c b/drivers/rtc/rtc-imx-sm-bbm.c index daa472be7c80697aa3cd3432eccef0c877e4c378..a29b30555d0c0581ecaa8b79760209dc780d2f0e 100644 --- a/drivers/rtc/rtc-imx-sm-bbm.c +++ b/drivers/rtc/rtc-imx-sm-bbm.c @@ -15,16 +15,18 @@ struct scmi_imx_bbm { struct rtc_device *rtc_dev; struct scmi_protocol_handle *ph; struct notifier_block nb; + u32 bbm_rtc_id; }; static int scmi_imx_bbm_read_time(struct device *dev, struct rtc_time *tm) { - struct scmi_imx_bbm *bbnsm = dev_get_drvdata(dev); + struct rtc_device *rtc = to_rtc_device(dev); + struct scmi_imx_bbm *bbnsm = rtc->priv; struct scmi_protocol_handle *ph = bbnsm->ph; u64 val; int ret; - ret = bbnsm->ops->rtc_time_get(ph, 0, &val); + ret = bbnsm->ops->rtc_time_get(ph, bbnsm->bbm_rtc_id, &val); if (ret) return ret; @@ -35,37 +37,40 @@ static int scmi_imx_bbm_read_time(struct device *dev, struct rtc_time *tm) static int scmi_imx_bbm_set_time(struct device *dev, struct rtc_time *tm) { - struct scmi_imx_bbm *bbnsm = dev_get_drvdata(dev); + struct rtc_device *rtc = to_rtc_device(dev); + struct scmi_imx_bbm *bbnsm = rtc->priv; struct scmi_protocol_handle *ph = bbnsm->ph; u64 val; val = rtc_tm_to_time64(tm); - return bbnsm->ops->rtc_time_set(ph, 0, val); + return bbnsm->ops->rtc_time_set(ph, bbnsm->bbm_rtc_id, 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 rtc_device *rtc = to_rtc_device(dev); + struct scmi_imx_bbm *bbnsm = rtc->priv; 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 bbnsm->ops->rtc_alarm_set(ph, bbnsm->bbm_rtc_id, 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 rtc_device *rtc = to_rtc_device(dev); + struct scmi_imx_bbm *bbnsm = rtc->priv; 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); + return bbnsm->ops->rtc_alarm_set(ph, bbnsm->bbm_rtc_id, true, val); } static const struct rtc_class_ops smci_imx_bbm_rtc_ops = { @@ -83,19 +88,18 @@ static int scmi_imx_bbm_rtc_notifier(struct notifier_block *nb, unsigned long ev if (r->is_rtc) rtc_update_irq(bbnsm->rtc_dev, 1, RTC_AF | RTC_IRQF); else - pr_err("Unexpected bbm event: %s\n", __func__); + pr_err("Unexpected bbm event: %s, bbm_rtc_id: %u\n", __func__, bbnsm->bbm_rtc_id); return 0; } -static int scmi_imx_bbm_rtc_init(struct scmi_device *sdev) +static int scmi_imx_bbm_rtc_init(struct scmi_device *sdev, struct scmi_imx_bbm *bbnsm) { 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); + bbnsm->rtc_dev = devm_rtc_allocate_device_priv(dev, bbnsm); if (IS_ERR(bbnsm->rtc_dev)) return PTR_ERR(bbnsm->rtc_dev); @@ -105,7 +109,7 @@ static int scmi_imx_bbm_rtc_init(struct scmi_device *sdev) 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); + &bbnsm->bbm_rtc_id, &bbnsm->nb); if (ret) return ret; @@ -118,29 +122,42 @@ static int scmi_imx_bbm_rtc_probe(struct scmi_device *sdev) struct device *dev = &sdev->dev; struct scmi_protocol_handle *ph; struct scmi_imx_bbm *bbnsm; - int ret; + const struct scmi_imx_bbm_proto_ops *ops; + int ret, i; + u32 nr_rtc; if (!handle) return -ENODEV; - bbnsm = devm_kzalloc(dev, sizeof(*bbnsm), GFP_KERNEL); - if (!bbnsm) - return -ENOMEM; + ops = handle->devm_protocol_get(sdev, SCMI_PROTOCOL_IMX_BBM, &ph); + if (IS_ERR(ops)) + return PTR_ERR(ops); - 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; + ret = ops->bbm_info(ph, &nr_rtc, NULL); + if (ret) + return ret; device_init_wakeup(dev, true); - dev_set_drvdata(dev, bbnsm); + for (i = 0; i < nr_rtc; i++) { + bbnsm = devm_kzalloc(dev, sizeof(*bbnsm), GFP_KERNEL); + if (!bbnsm) { + ret = -ENOMEM; + goto fail; + } - ret = scmi_imx_bbm_rtc_init(sdev); - if (ret) - device_init_wakeup(dev, false); + bbnsm->ops = ops; + bbnsm->ph = ph; + bbnsm->bbm_rtc_id = i; + ret = scmi_imx_bbm_rtc_init(sdev, bbnsm); + if (ret) + goto fail; + } + + return 0; +fail: + device_init_wakeup(dev, false); return ret; }