From patchwork Wed Feb 28 05:43:06 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: 13574900 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 9D66FC47DD9 for ; Wed, 28 Feb 2024 05:35:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To:In-Reply-To: References:Message-Id: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=rg3FZmH/y+w77TGh0CtYriswarALoAmSK/4bCsbM3A8=; b=LGjPcBozg2gTWs+EEfF/dj08nI Ne41Y/jkdhMNZGfS2JERcC6Jc3gh9d7HBP/Qb2Rre4P2VfnjN3TMNDDkrNezkIFC2U1s0ahaPyy30 dsV3rD7D30m9uyA9EpbokHAmfnYzW3P23HCPVzz4MgIPBCsvlthX7TRBjg7Uk6wokxTiPZCr7HY1J SIaltvfY46TbOfGVFyfzwvrr1Z7xiENigurEuSCFTR0H2J6+CJvDWkCzeYhaFkP5T4E9DJfJSb95K OWRzGM75iIpjDKTjOXZEoKfaAAYGlgoVdgQAqrPwxsm296OP6C1Xw+jZ/kbmKr5nZm7FkdG/aZt65 xP947YGg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfCb9-0000000862P-2Ujc; Wed, 28 Feb 2024 05:35:19 +0000 Received: from mail-vi1eur04on20601.outbound.protection.outlook.com ([2a01:111:f403:2611::601] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfCax-000000085uw-0Fqk for linux-arm-kernel@lists.infradead.org; Wed, 28 Feb 2024 05:35:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fvbB9EmQQK8U3LjafLfcTVsj/OeZ1pVT61LJiX4+v69cNbMUd/BLOzNICj9DOUeCwcwbFlCdlGdJMUZ6Uc6du25AKZ3fQdjtjd0+NQ4TpBMuS6lpWoHwe229RvGQ433Ja/Wpmtgn8Qi87SrStbmj1AMPh/qd8SSw9hDSy7uDE2zhJtxJK+MrS8DECVZowUOlNHSNRxKCy988HTmHgeuQSbs1kD396JOTIWiLWUjsUZJ2Gfot3EsQkM8evybuDO01gqQ2LhomHA5E4Fit4dr4lTLH4nwGjUEwYqe5tEOQ+nNKyiDEuzZD5mZ//BxXOQsKuK6GGhcvoxJiSOhfmFbI1Q== 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=VWFZDVTupKRHqGzPzOcozEj38Hip9TgR0m5LQhPIOCE=; b=boAo3WD2rBmAkH9l/4rkrbycJP0qHfeXW38Y6KiQDPDm5urYTdU0QeDqjJhTNwDfPKwwtyjk1mFmTTYVd19l7mxbhejpkeJIL/aDTWvvEhVAFytQSAYiCLqbfQru0RgkJ/UuvnHOhjrPRIwKvlkv39zyQtg07kFDdwbEztXOzHIGucXUoq6/NF8/xcp/mehXzky1hhxF+txGqmRBlKB07JlVAKSl9F8uyNSmWgnngbOFTmuleUX7WR9ArTvvqll40nAU+IGrO6ngxksmldRiUf0mFeHcIyeW1lok6czkuJKN9GyEaSYW8tsB+2njTTII/sGbDq/p7SiP7pkawK0ZvA== 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=VWFZDVTupKRHqGzPzOcozEj38Hip9TgR0m5LQhPIOCE=; b=YEKuBjinq5IfiKDTh7KwQ3Lqqb4XPegV6ubbGTbuIS82n6aEcQwuwdR74TrLihk16CkKSfd8sZ2m6z8O/Ts851OokLNlAI/5EbtZIs6Vp0m24qygmLQMGNrYr7IWyTfzU3pwGsmKd41UkmTD8vsKvv4MJPWIHy7o55xWXex03OA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) by AS8PR04MB7525.eurprd04.prod.outlook.com (2603:10a6:20b:29b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.36; Wed, 28 Feb 2024 05:35:02 +0000 Received: from DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::1232:ed97:118f:72fd]) by DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::1232:ed97:118f:72fd%4]) with mapi id 15.20.7316.034; Wed, 28 Feb 2024 05:35:01 +0000 From: "Peng Fan (OSS)" Date: Wed, 28 Feb 2024 13:43:06 +0800 Subject: [PATCH v2 2/2] clk: imx: add i.MX95 BLK CTL clk driver Message-Id: <20240228-imx95-blk-ctl-v2-2-ffb7eefb6dcd@nxp.com> References: <20240228-imx95-blk-ctl-v2-0-ffb7eefb6dcd@nxp.com> In-Reply-To: <20240228-imx95-blk-ctl-v2-0-ffb7eefb6dcd@nxp.com> To: Abel Vesa , Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam Cc: linux-clk@vger.kernel.org, imx@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Peng Fan X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1709098992; l=13492; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=xdgyrgvjxybTyzDq8X/GTHuUjGIxReFNUQBlt7Wg4qY=; b=f9YFYxZSOWqKPqciCGeucA2E7VHpuRFnz0L7kbuHPCzs5l45CeaGfETmDDMXMButZmoao1z/S eVWZIs2/uVbAcCRHdhqBbitj4q3zqrgja0wymAosk4YQMPY5XFBHj0a X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI1PR02CA0034.apcprd02.prod.outlook.com (2603:1096:4:1f6::10) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR04MB9417:EE_|AS8PR04MB7525:EE_ X-MS-Office365-Filtering-Correlation-Id: d67fad88-177a-4c9b-e49d-08dc381f0292 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FVT1nnSrpMr+52UcuWgLCaBgrthTqCIoN+qJkcvTeNWB9FBub6aP5Hiv3AFEMMDLGRYbNCFI/hgu5LDOzgY5bGALPhW5JR5v1jntHpMBoIRdREv7fDllakJoeGf7zi96RjuBctrV7RfKjddoSA/VBFJRi+Vj9MBdUGO2DsuPwMbCnZz4cug/5AxgmyBFEP3ry2nLxlrwapT/6KofSrIMB019Klmdp7ADUkpaV/n7uuhJs6kMO1BA9QVT270noj3HEU0KyuXeAA4FuUHFLT4qE38xGs7idWlVFq7P6FNExfom6omyRFP0/IiNyQ+naxhf2Jc8IQTyT6Mkxcft4bAyMB5ZN/cF9Fy6UAjTrwmQ2GQyKOb+hXIlJWdZgsl1IrumQxkpjKD8Skq0JA+ZDoTgmH6KOdoVcTtSD8lUn/PCrv6msnj95L+sCGLZysR5CBOwlGLnohnWF5CSK4kQNTKVvjIfc5KqJerRWQOK8uTPkFrWCUQdvKeSgqFOQSwsDU/c7tZACNwwaN/geVoSmn7o1cKNPrIcz6sw3LFo9uGYp1U9IVFsaLT5+ez+vY0SqYbtiqvG9bsuCi/eSs+ycEYEgOp6L+JecbRakwe1nyWnT7BUxMngwglErb7TheCLzygjPbPQpekbu++Uv7cXvxq7Di2YcLv/GJob7WTSpCNlu2UmEFc50iORaJ3txUShLegTrvIrs9J1QIIcl4Oo1uQG16WC1REiuKqkiRsxFa5txRs= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU0PR04MB9417.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(921011)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?n250vnGahK0jrnFExIyjr/KsNF2i?= =?utf-8?q?ENqESiTtp1rrVFBktC42IG4DGT85aTrOMA+dpMRaTxpdevYSdizfNyAoHi3a9EWm4?= =?utf-8?q?Gc844NVnBCS7hd0EkGyC/L7aJhx0Ju9/PwubCcZQ2upfXjOjAR07LM5KbQRZRY+be?= =?utf-8?q?KIEp4Cs0NGJsbpUcH+9iVeDCDC+QayYKD1+jerF0UDmH9Ykw1j1m676Z91cp7ei/C?= =?utf-8?q?b2dxFSXjIztYV7nkfkNR3csAafhdoeZbANrg8s3hnjciXjcJlbIULYCBOpAAJyz/F?= =?utf-8?q?ngNLQFsTvEETDZtv9d3V8GHg7OB3WFuHu+5DNtCa0aJ5oWRCkFMPu41NuMwZ1kUkB?= =?utf-8?q?icWhUXrUQn0U5mWfd6Ubhpc1ynoj5vaMoHjxYHcZh/TaSmkh560HKZ8iekOIjKnwA?= =?utf-8?q?D0D6hmk0ZAYriTtoa8t2trbYs0OaU05UHEWLTC/KBk8M+xK6/4v5Doo+CneCcJYwE?= =?utf-8?q?5P6nLWP1JqBTsO3i15pDq5X1WFH+bCt7NINccda0iaYh/CfshrTbW+i8wJgv+hn5i?= =?utf-8?q?NRjySkDBQHHThfaQo3m8SQZZpOg7Bj4ky58X55BrIUfrGOJbYOAM9nql5j9zpzrn5?= =?utf-8?q?TmtmZaSU7WorkemXnoYWxNo242D8Wdda2Yb/hBbSWeODZk+8MEaaD4LeG/laN7mqJ?= =?utf-8?q?Su/whKLq/8NdHl9JPEfbZO6aYReQYuSjbCCDIocdSz382HP/6+DRWAHl4Iq5nFlDZ?= =?utf-8?q?fj3uBKSPpt8aDkZSo4lGMxXjh6ol1tsCAciWMYaHkh+JRvkL/fVjI2r6B8KcSqhS/?= =?utf-8?q?iwrL0yNyO37mtIYx6e4cCgp5Aeml9qSuCueLoEor4V9yjuJwJhTNXQ8O9cOFZ1s4y?= =?utf-8?q?NTXlbNl3MIXAVZnosOjzDYOp1hpGonxJd3ZQqQfFgO7F0FCeeP3O2Sya8hQFaRPLj?= =?utf-8?q?zl6mh1vL+5jwPSvhIG7A91Od4WUxu0Y7/XyMXG+a4mLS7uvb33svtWStZKyMIe90l?= =?utf-8?q?34OvoRxrsAyi+vi7iAeeTVjG/K5mdXzun/84exdfX63AVqTo6s1+3XA27f17Uq6lN?= =?utf-8?q?fAOfUQIaHqQ2YcCfDdftaJoPIJS8fGLtnaOpUzM2/9qYXLZ4mKeFBZOLDemsKrbC9?= =?utf-8?q?5Et6etfibMxAui04DgsHu3fQU2lSl90+c/Oya7TrzHkgkwo/46xWq9qzWksRwrmxh?= =?utf-8?q?GTJ4/3if3nP1GiVEx9iZmCJ2HCF+roCMGIaSKAaTw1Cf28TKH98BtAp0/NIojbSWN?= =?utf-8?q?kf5Lctw3AkSTrCNX/NeINeOw0K1dcH9PCkXnakJcsAI37NsGX7uP4wBMMsrntfR3n?= =?utf-8?q?WftdqE7cGLveLEzRd/gT/VXNS2o29q5y4JBuBV4yKSemdVcvnSnxddcw2Dz6SjzL6?= =?utf-8?q?NlGGnLqWwzeIycjwxxb8STdWxmJX4I5aR7wTED6YHIRnvNqf8DXnvFTX4NqoEsP39?= =?utf-8?q?OBvsLIyqnkq68UnNSkS3U37U89rqJQPMgrFqP8XIxpo6vgthb6rHP98T7MYHa5Uaf?= =?utf-8?q?BKlJzP4MddxI4Mq8dL49K5ywe4WibOBoNXjlrMOn/QQOsjy0pSJpJ5+Pv830dyfRv?= =?utf-8?q?aQwGZ0QwP4wV?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d67fad88-177a-4c9b-e49d-08dc381f0292 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 05:35:01.8996 (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: lrlyRdJS0R5cU0NX/Hj6vzJCCSAe/vRKUyI8200sOEouirH5KV1bmRtx5Kl5uz5/RNviQMjEZs0hv8X9kbZvaQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7525 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240227_213507_178187_F1DFAFFB X-CRM114-Status: GOOD ( 16.09 ) 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 i.MX95 has BLK CTL modules in various MIXes, the BLK CTL modules support clock features such as mux/gate/div. This patch is to add the clock feature of BLK CTL modules Signed-off-by: Peng Fan --- drivers/clk/imx/Kconfig | 7 + drivers/clk/imx/Makefile | 1 + drivers/clk/imx/clk-imx95-blk-ctl.c | 438 ++++++++++++++++++++++++++++++++++++ 3 files changed, 446 insertions(+) diff --git a/drivers/clk/imx/Kconfig b/drivers/clk/imx/Kconfig index db3bca5f4ec9..6da0fba68225 100644 --- a/drivers/clk/imx/Kconfig +++ b/drivers/clk/imx/Kconfig @@ -114,6 +114,13 @@ config CLK_IMX93 help Build the driver for i.MX93 CCM Clock Driver +config CLK_IMX95_BLK_CTL + tristate "IMX95 Clock Driver for BLK CTL" + depends on ARCH_MXC || COMPILE_TEST + select MXC_CLK + help + Build the clock driver for i.MX95 BLK CTL + config CLK_IMXRT1050 tristate "IMXRT1050 CCM Clock Driver" depends on SOC_IMXRT || COMPILE_TEST diff --git a/drivers/clk/imx/Makefile b/drivers/clk/imx/Makefile index d4b8e10b1970..03f2b2a1ab63 100644 --- a/drivers/clk/imx/Makefile +++ b/drivers/clk/imx/Makefile @@ -31,6 +31,7 @@ obj-$(CONFIG_CLK_IMX8MP) += clk-imx8mp.o clk-imx8mp-audiomix.o obj-$(CONFIG_CLK_IMX8MQ) += clk-imx8mq.o obj-$(CONFIG_CLK_IMX93) += clk-imx93.o +obj-$(CONFIG_CLK_IMX95_BLK_CTL) += clk-imx95-blk-ctl.o obj-$(CONFIG_MXC_CLK_SCU) += clk-imx-scu.o clk-imx-lpcg-scu.o clk-imx-acm.o clk-imx-scu-$(CONFIG_CLK_IMX8QXP) += clk-scu.o clk-imx8qxp.o \ diff --git a/drivers/clk/imx/clk-imx95-blk-ctl.c b/drivers/clk/imx/clk-imx95-blk-ctl.c new file mode 100644 index 000000000000..4448b7a3a2a3 --- /dev/null +++ b/drivers/clk/imx/clk-imx95-blk-ctl.c @@ -0,0 +1,438 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2024 NXP + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + CLK_GATE, + CLK_DIVIDER, + CLK_MUX, +}; + +struct imx95_blk_ctl { + struct device *dev; + spinlock_t lock; + struct clk *clk_apb; + + void __iomem *base; + /* clock gate register */ + u32 clk_reg_restore; +}; + +struct imx95_blk_ctl_clk_dev_data { + const char *name; + const char * const *parent_names; + u32 num_parents; + u32 reg; + u32 bit_idx; + u32 bit_width; + u32 clk_type; + u32 flags; + u32 flags2; + u32 type; +}; + +struct imx95_blk_ctl_dev_data { + const struct imx95_blk_ctl_clk_dev_data *clk_dev_data; + u32 num_clks; + bool rpm_enabled; + u32 clk_reg_offset; +}; + +static const struct imx95_blk_ctl_clk_dev_data vpublk_clk_dev_data[] = { + [IMX95_CLK_VPUBLK_WAVE] = { + .name = "vpublk_wave_vpu", + .parent_names = (const char *[]){ "vpu", }, + .num_parents = 1, + .reg = 8, + .bit_idx = 0, + .type = CLK_GATE, + .flags = CLK_SET_RATE_PARENT, + .flags2 = CLK_GATE_SET_TO_DISABLE, + }, + [IMX95_CLK_VPUBLK_JPEG_ENC] = { + .name = "vpublk_jpeg_enc", + .parent_names = (const char *[]){ "vpujpeg", }, + .num_parents = 1, + .reg = 8, + .bit_idx = 1, + .type = CLK_GATE, + .flags = CLK_SET_RATE_PARENT, + .flags2 = CLK_GATE_SET_TO_DISABLE, + }, + [IMX95_CLK_VPUBLK_JPEG_DEC] = { + .name = "vpublk_jpeg_dec", + .parent_names = (const char *[]){ "vpujpeg", }, + .num_parents = 1, + .reg = 8, + .bit_idx = 2, + .type = CLK_GATE, + .flags = CLK_SET_RATE_PARENT, + .flags2 = CLK_GATE_SET_TO_DISABLE, + } +}; + +static const struct imx95_blk_ctl_dev_data vpublk_dev_data = { + .num_clks = IMX95_CLK_VPUBLK_END, + .clk_dev_data = vpublk_clk_dev_data, + .rpm_enabled = true, + .clk_reg_offset = 8, +}; + +static const struct imx95_blk_ctl_clk_dev_data camblk_clk_dev_data[] = { + [IMX95_CLK_CAMBLK_CSI2_FOR0] = { + .name = "camblk_csi2_for0", + .parent_names = (const char *[]){ "camisi", }, + .num_parents = 1, + .reg = 0, + .bit_idx = 0, + .type = CLK_GATE, + .flags = CLK_SET_RATE_PARENT, + .flags2 = CLK_GATE_SET_TO_DISABLE, + }, + [IMX95_CLK_CAMBLK_CSI2_FOR1] = { + .name = "camblk_csi2_for1", + .parent_names = (const char *[]){ "camisi", }, + .num_parents = 1, + .reg = 0, + .bit_idx = 1, + .type = CLK_GATE, + .flags = CLK_SET_RATE_PARENT, + .flags2 = CLK_GATE_SET_TO_DISABLE, + }, + [IMX95_CLK_CAMBLK_ISP_AXI] = { + .name = "camblk_isp_axi", + .parent_names = (const char *[]){ "camaxi", }, + .num_parents = 1, + .reg = 0, + .bit_idx = 4, + .type = CLK_GATE, + .flags = CLK_SET_RATE_PARENT, + .flags2 = CLK_GATE_SET_TO_DISABLE, + }, + [IMX95_CLK_CAMBLK_ISP_PIXEL] = { + .name = "camblk_isp_pixel", + .parent_names = (const char *[]){ "camisi", }, + .num_parents = 1, + .reg = 0, + .bit_idx = 5, + .type = CLK_GATE, + .flags = CLK_SET_RATE_PARENT, + .flags2 = CLK_GATE_SET_TO_DISABLE, + }, + [IMX95_CLK_CAMBLK_ISP] = { + .name = "camblk_isp", + .parent_names = (const char *[]){ "camisi", }, + .num_parents = 1, + .reg = 0, + .bit_idx = 6, + .type = CLK_GATE, + .flags = CLK_SET_RATE_PARENT, + .flags2 = CLK_GATE_SET_TO_DISABLE, + } +}; + +static const struct imx95_blk_ctl_dev_data camblk_dev_data = { + .num_clks = IMX95_CLK_CAMBLK_END, + .clk_dev_data = camblk_clk_dev_data, + .clk_reg_offset = 0, +}; + +static const struct imx95_blk_ctl_clk_dev_data lvds_clk_dev_data[] = { + [IMX95_CLK_DISPMIX_LVDS_PHY_DIV] = { + .name = "ldb_phy_div", + .parent_names = (const char *[]){ "ldbpll", }, + .num_parents = 1, + .reg = 0, + .bit_idx = 0, + .bit_width = 1, + .type = CLK_DIVIDER, + .flags2 = CLK_DIVIDER_POWER_OF_TWO, + }, + [IMX95_CLK_DISPMIX_LVDS_CH0_GATE] = { + .name = "lvds_ch0_gate", + .parent_names = (const char *[]){ "ldb_phy_div", }, + .num_parents = 1, + .reg = 0, + .bit_idx = 1, + .bit_width = 1, + .type = CLK_GATE, + .flags = CLK_SET_RATE_PARENT, + .flags2 = CLK_GATE_SET_TO_DISABLE, + }, + [IMX95_CLK_DISPMIX_LVDS_CH1_GATE] = { + .name = "lvds_ch1_gate", + .parent_names = (const char *[]){ "ldb_phy_div", }, + .num_parents = 1, + .reg = 0, + .bit_idx = 2, + .bit_width = 1, + .type = CLK_GATE, + .flags = CLK_SET_RATE_PARENT, + .flags2 = CLK_GATE_SET_TO_DISABLE, + }, + [IMX95_CLK_DISPMIX_PIX_DI0_GATE] = { + .name = "lvds_di0_gate", + .parent_names = (const char *[]){ "ldb_pll_div7", }, + .num_parents = 1, + .reg = 0, + .bit_idx = 3, + .bit_width = 1, + .type = CLK_GATE, + .flags = CLK_SET_RATE_PARENT, + .flags2 = CLK_GATE_SET_TO_DISABLE, + }, + [IMX95_CLK_DISPMIX_PIX_DI1_GATE] = { + .name = "lvds_di1_gate", + .parent_names = (const char *[]){ "ldb_pll_div7", }, + .num_parents = 1, + .reg = 0, + .bit_idx = 4, + .bit_width = 1, + .type = CLK_GATE, + .flags = CLK_SET_RATE_PARENT, + .flags2 = CLK_GATE_SET_TO_DISABLE, + }, +}; + +static const struct imx95_blk_ctl_dev_data lvds_csr_dev_data = { + .num_clks = IMX95_CLK_DISPMIX_LVDS_CSR_END, + .clk_dev_data = lvds_clk_dev_data, + .clk_reg_offset = 0, +}; + +static const struct imx95_blk_ctl_clk_dev_data dispmix_csr_clk_dev_data[] = { + [IMX95_CLK_DISPMIX_ENG0_SEL] = { + .name = "disp_engine0_sel", + .parent_names = (const char *[]){"videopll1", "dsi_pll", "ldb_pll_div7", }, + .num_parents = 4, + .reg = 0, + .bit_idx = 0, + .bit_width = 2, + .type = CLK_MUX, + .flags = CLK_SET_RATE_NO_REPARENT | CLK_SET_RATE_PARENT, + }, + [IMX95_CLK_DISPMIX_ENG1_SEL] = { + .name = "disp_engine1_sel", + .parent_names = (const char *[]){"videopll1", "dsi_pll", "ldb_pll_div7", }, + .num_parents = 4, + .reg = 0, + .bit_idx = 2, + .bit_width = 2, + .type = CLK_MUX, + .flags = CLK_SET_RATE_NO_REPARENT | CLK_SET_RATE_PARENT, + } +}; + +static const struct imx95_blk_ctl_dev_data dispmix_csr_dev_data = { + .num_clks = IMX95_CLK_DISPMIX_END, + .clk_dev_data = dispmix_csr_clk_dev_data, + .clk_reg_offset = 0, +}; + +static int imx95_bc_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + const struct imx95_blk_ctl_dev_data *bc_data; + struct imx95_blk_ctl *bc; + struct clk_hw_onecell_data *clk_hw_data; + struct clk_hw **hws; + void __iomem *base; + int i, ret; + + bc = devm_kzalloc(dev, sizeof(*bc), GFP_KERNEL); + if (!bc) + return -ENOMEM; + bc->dev = dev; + dev_set_drvdata(&pdev->dev, bc); + + spin_lock_init(&bc->lock); + + base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(base)) + return PTR_ERR(base); + + bc->base = base; + bc->clk_apb = devm_clk_get(dev, NULL); + if (IS_ERR(bc->clk_apb)) + return dev_err_probe(dev, PTR_ERR(bc->clk_apb), "failed to get APB clock\n"); + + ret = clk_prepare_enable(bc->clk_apb); + if (ret) { + dev_err(dev, "failed to enable apb clock: %d\n", ret); + return ret; + } + + bc_data = of_device_get_match_data(dev); + if (!bc_data) + return devm_of_platform_populate(dev); + + clk_hw_data = devm_kzalloc(dev, struct_size(clk_hw_data, hws, bc_data->num_clks), + GFP_KERNEL); + if (!clk_hw_data) + return -ENOMEM; + + if (bc_data->rpm_enabled) + pm_runtime_enable(&pdev->dev); + + clk_hw_data->num = bc_data->num_clks; + hws = clk_hw_data->hws; + + for (i = 0; i < bc_data->num_clks; i++) { + const struct imx95_blk_ctl_clk_dev_data *data = &bc_data->clk_dev_data[i]; + void __iomem *reg = base + data->reg; + + if (data->type == CLK_MUX) { + hws[i] = clk_hw_register_mux(dev, data->name, data->parent_names, + data->num_parents, data->flags, reg, + data->bit_idx, data->bit_width, + data->flags2, &bc->lock); + } else if (data->type == CLK_DIVIDER) { + hws[i] = clk_hw_register_divider(dev, data->name, data->parent_names[0], + data->flags, reg, data->bit_idx, + data->bit_width, data->flags2, &bc->lock); + } else { + hws[i] = clk_hw_register_gate(dev, data->name, data->parent_names[0], + data->flags, reg, data->bit_idx, + data->flags2, &bc->lock); + } + if (IS_ERR(hws[i])) { + ret = PTR_ERR(hws[i]); + dev_err(dev, "failed to register: %s:%d\n", data->name, ret); + goto cleanup; + } + } + + ret = of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get, clk_hw_data); + if (ret) + goto cleanup; + + ret = devm_of_platform_populate(dev); + if (ret) { + of_clk_del_provider(dev->of_node); + goto cleanup; + } + + if (pm_runtime_enabled(bc->dev)) + clk_disable_unprepare(bc->clk_apb); + + return 0; + +cleanup: + for (i = 0; i < bc_data->num_clks; i++) { + if (IS_ERR_OR_NULL(hws[i])) + continue; + clk_hw_unregister(hws[i]); + } + + if (bc_data->rpm_enabled) + pm_runtime_disable(&pdev->dev); + + return ret; +} + +#ifdef CONFIG_PM +static int imx95_bc_runtime_suspend(struct device *dev) +{ + struct imx95_blk_ctl *bc = dev_get_drvdata(dev); + + clk_disable_unprepare(bc->clk_apb); + return 0; +} + +static int imx95_bc_runtime_resume(struct device *dev) +{ + struct imx95_blk_ctl *bc = dev_get_drvdata(dev); + + return clk_prepare_enable(bc->clk_apb); +} +#endif + +#ifdef CONFIG_PM_SLEEP +static int imx95_bc_suspend(struct device *dev) +{ + struct imx95_blk_ctl *bc = dev_get_drvdata(dev); + const struct imx95_blk_ctl_dev_data *bc_data; + int ret; + + bc_data = of_device_get_match_data(dev); + if (!bc_data) + return 0; + + if (bc_data->rpm_enabled) { + ret = pm_runtime_get_sync(bc->dev); + if (ret < 0) { + pm_runtime_put_noidle(bc->dev); + return ret; + } + } + + bc->clk_reg_restore = readl(bc->base + bc_data->clk_reg_offset); + + return 0; +} + +static int imx95_bc_resume(struct device *dev) +{ + struct imx95_blk_ctl *bc = dev_get_drvdata(dev); + const struct imx95_blk_ctl_dev_data *bc_data; + + bc_data = of_device_get_match_data(dev); + if (!bc_data) + return 0; + + writel(bc->clk_reg_restore, bc->base + bc_data->clk_reg_offset); + + if (bc_data->rpm_enabled) + pm_runtime_put(bc->dev); + + return 0; +} +#endif + +static const struct dev_pm_ops imx95_bc_pm_ops = { + SET_RUNTIME_PM_OPS(imx95_bc_runtime_suspend, imx95_bc_runtime_resume, NULL) + SET_SYSTEM_SLEEP_PM_OPS(imx95_bc_suspend, imx95_bc_resume) +}; + +static const struct of_device_id imx95_bc_of_match[] = { + { .compatible = "nxp,imx95-cameramix-csr", .data = &camblk_dev_data }, + { .compatible = "nxp,imx95-display-master-csr", }, + { .compatible = "nxp,imx95-dispmix-lvds-csr", .data = &lvds_csr_dev_data }, + { .compatible = "nxp,imx95-dispmix-csr", .data = &dispmix_csr_dev_data }, + { .compatible = "nxp,imx95-netcmix-blk-ctrl", }, + { .compatible = "nxp,imx95-vpumix-csr", .data = &vpublk_dev_data }, + { /* Sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, imx95_blk_ctl_match); + +static struct platform_driver imx95_bc_driver = { + .probe = imx95_bc_probe, + .driver = { + .name = "imx95-blk-ctl", + .of_match_table = of_match_ptr(imx95_bc_of_match), + .pm = &imx95_bc_pm_ops, + }, +}; +module_platform_driver(imx95_bc_driver); + +MODULE_DESCRIPTION("NXP i.MX95 blk ctl driver"); +MODULE_LICENSE("GPL");