From patchwork Thu Jul 18 07:41:58 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: 13736143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4D1CBC3DA49 for ; Thu, 18 Jul 2024 07:36:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To: In-Reply-To:References:Message-Id:Content-Transfer-Encoding:Content-Type: Subject:Date:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2y1quUvokU0Up4oQp8r3/9zDfWHRyol2aqI1a4ysBr4=; b=C0FRZcVWUiTkqAw6pGTLW5N9n4 UBjnntCuoVDS7LexVQazHkYakEQpSwSj6gcrM9NB0Ocze+Vk9mwUwqTkZ9jdMWB/ufpbbqF357xM6 sOKB9oVfNwt0S8O/v0Rcf5uC+H7Mpxf2DqvvH6EFAsucnCUKD7fXPjXsYCmJcTqWQGQ5tEM8diee3 AGrJQ7bJt6H93B7D+yKhgqllkkuyl0EwQasyAlc0dinWpk90yNInlYTYEejRmTTvYiNSHaCLFOvQF Uo0K5ts+nbwLGq9QsJW75tpnsZnEhbYNILWEvQjgQn2IcRuH+bg65oMN6V/jBUIwiMJQQonrCW6pQ cdI2DyTA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sULgH-0000000GEBQ-0DPg; Thu, 18 Jul 2024 07:36:01 +0000 Received: from mail-northeuropeazlp170130004.outbound.protection.outlook.com ([2a01:111:f403:c200::4] helo=DUZPR83CU001.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sULdx-0000000GD17-1JGO for linux-arm-kernel@lists.infradead.org; Thu, 18 Jul 2024 07:33:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ev0FjIhoobc34/HglEqRtqErXYfc6PWqS6yKbs8mI3IcKuGrfOWfpmtfmfq0MAmfqvja95NDecnnogVIIPNaUolExownZ0WYfsyjBYmvxEGjzS05dV3lQTm96wmiu0r9jMwFhkAtDfv8oodk2nL/R5V+ygjzFSlUT6xuoNOANah3ARQ4OFOvAYYsT91nWtIMVYCPuqyQf4oQ0Bs14YjrBbSQvNq/onKpvrPpISb177XWqqk23/NQi1CPPQgSN31ED+LJzoN2EUw3M6dVBJ3mQQ/zAGB7oSWWjuI4zkgQ6MkfDlBTXPdrEQHtd3ihhxPWt1WpjpbMMR8Q/jgs8QGaig== 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=RIyzEJsFepTE9C44vFUwaMgi8bwrxksCvYsy4FMCgH0PmzSSxr1v2rN0lEPv3f14H0zNaYOsJqUCJ/TJLg2GdTOPhBPMwzBfzxnNjrxeNDGD4OvqGSk7CSAIsl5GNYqipDRocYc9qBRq0zSkET6OJ9RbejPU6nFJtGJkPaoLLp4qLVnULKfYKxwDMDt/9FDcNUgJ/vSWTvqSzUqF0h+7PHHcOCwZtPgo5Zr0JsBvkaoJEiUKIOsv0DdH9Zm3txexL5FMAVcp/IFlL2DvYDTAqkd0uDAvwYlfWXg9zlJiFW/eXuAZh4i7rcqj92vUCAmSQoUpBIaeLbi9eZ6UBfihoQ== 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=2y1quUvokU0Up4oQp8r3/9zDfWHRyol2aqI1a4ysBr4=; b=P4SUAsDnjgox1+Hghb8BkHqO85PiHEm8gtbAoSvMAZU8VzXmGhZIDutEv+jIOMwqL3RkvVJrHIEGvzB/Q2fApJrsPs4Ybgse6TpT5qC9zcQTLYE7cTKhCVsoCr3JjaFwiHUC8CbVA9v2bHK2/6XvO2O3jyUpa/2xOPzTLbycECM= 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 DU4PR04MB10457.eurprd04.prod.outlook.com (2603:10a6:10:561::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.16; Thu, 18 Jul 2024 07:33:35 +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.7762.020; Thu, 18 Jul 2024 07:33:34 +0000 From: "Peng Fan (OSS)" Date: Thu, 18 Jul 2024 15:41:58 +0800 Subject: [PATCH v6 6/7] rtc: support i.MX95 BBM RTC Message-Id: <20240718-imx95-bbm-misc-v2-v6-6-18f008e16e9d@nxp.com> References: <20240718-imx95-bbm-misc-v2-v6-0-18f008e16e9d@nxp.com> In-Reply-To: <20240718-imx95-bbm-misc-v2-v6-0-18f008e16e9d@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Alexandre Belloni , Dmitry Torokhov Cc: Peng Fan , 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.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1721288528; l=6360; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=Oy5Gyoso0Y/G/kwZwRlXVgA45ZaX4xes2SzW2BSybKo=; b=UooGqUwQLeY4oe45kIQCm7dZbgJOYK8IfktPuFuUCX4/fVei42lH1hL/3EhMfMtvSbbhLchNK MVqqgU+QZVyAstleaZVKdySeDh+NFDrwbIFAmbCup6kIxHucKN8o2uB X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI1PR02CA0046.apcprd02.prod.outlook.com (2603:1096:4:1f5::14) To PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8459:EE_|DU4PR04MB10457:EE_ X-MS-Office365-Filtering-Correlation-Id: 475db741-ad46-48b5-cfe4-08dca6fbee7f 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|1800799024|366016|52116014|376014|7416014|921020|38350700014; X-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iWXyURXzEsHveZIVCe3zpPFH64Ny6cLoZuomtFVJINOyB4RZun535?= =?utf-8?q?UIgFK3ONtcD0QgerfQW2m/AfyuT3ZZc5IopOR4TrhDEKvrzd1tALGRDlJ1e5bHjTU?= =?utf-8?q?q0yF6LjEfpVQnqd/Whsi+A7V7P4199QCtEXI+KSNId8ZnQF2sxabrXY/4FmeMDblk?= =?utf-8?q?bN84sFhnMgF9AESDvXT0pDp71hsjjPRVrlRBYMK72vXESn53g4RfHg8bn5RnsRuVs?= =?utf-8?q?urfjdUdI685QiEjC2PJyljzvaNQlSi7yeEW7UgXTkps2mAZ0BHdmWjGnV3fmQCaS8?= =?utf-8?q?ZTLuRpP1g4I3Vfgm0u9Lrbgw1yiS/e3V0JPupECOl6dxOk1UvQt4L+KjbEHfF+2Uw?= =?utf-8?q?OmgC8XMp5bYWw+wZYWpTpbw3RrwD8psEyi5y73dqpiBAydbatWwbQ63Ghlp9LwapZ?= =?utf-8?q?1rfGgnIbhJAdZubIkleq5d1ON4ox0pvolJgSTKNHyJxp3Gr1GOkIn/5zoSXAeohV2?= =?utf-8?q?QZNQZZJ4fbteqR/5YF3v48yUpAXfMeC6k9A8Sy1uQeTnm7cr9Cy5JpM=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)(1800799024)(366016)(52116014)(376014)(7416014)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?AC8vOipPpWoW19bZOY8haxKeSH5p?= =?utf-8?q?Qp3PccKtptU8seRXz3xnb51viStwGMhHmpCdzK48/pUCJB5tzbZLtCXexKqc46JkQ?= =?utf-8?q?OGXk8mPAqa7wNeZFS88WeJaubSIOTyTGYXKRfrGW8CZ7ViYldyLoKqOn+6M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mV?= =?utf-8?q?Elh390Jm0meYVljqAloqw/m56ePNmWPcOVxbX+gCKeiEVjTXNLZVu5tlmLGGL2Rgr?= =?utf-8?q?tVi0eP9MkqDw4ZkynHh/VSsJp5pHwHWTFWKV8wIbyMMu4kqRl2dv3VTSChY9tlwlf?= =?utf-8?q?nunThMRlGESll4JNNyhKj1Qbn90V3tZFrpH1yaifm53aqxIZm80RlkCKOFyVg+MrW?= =?utf-8?q?VAZ7y1o4tFsSTm7F6o6ihRXGZhnjsGVW0FIB7zoX8gtTrQQPSMmcGS+airDVF7Zkx?= =?utf-8?q?+LctSZMZOL/mASIzG5M2rzl7RXdgvp4Zo2lZhBgj2MoNjQiSZdln815TOagfxxjWT?= =?utf-8?q?pfFdMQwS4nVi8QHUjeNR9WZzYbWYo2Ty/izbjLQBDCUmU7BklBLR9te7uFJNQgifQ?= =?utf-8?q?AB57+oS26yqEPSuxxCOucrYnHVglTvaSMAsFH7Ykrz/s+8mMEQz3xUrJ0IfYKgkpA?= =?utf-8?q?peJdq2La0y1cu3kbEmeLw8ebH5peExA6CggeXRPsWYnMjIFxdZFbQYgmbNnqtO3X/?= =?utf-8?q?qHH3irupXJsG?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 475db741-ad46-48b5-cfe4-08dca6fbee7f X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2024 07:33:34.9005 (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: hE2p74/rIiNvChS+MEZpKWFcyASgI9ELRR4Tdyy/wTHKuTFj5JegEtUyOogAguJXatPKVhxFXLumo/poaea96g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU4PR04MB10457 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240718_003337_641610_5311BDAB X-CRM114-Status: GOOD ( 18.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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");