From patchwork Wed Feb 28 04:31:05 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: 13574857 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 45D37C47DD9 for ; Wed, 28 Feb 2024 04:23:33 +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=BYcfFNKA4N7soDdEMlTZSiugEl J15K2cqPkWtoAko5kxY6peSJFGYYnLX+IgdeKc2+E73sQUzgSDAACjaMXQWmwGsfyoqk87JcSwDjo q0A1W0WbpJ+XmeSX7rooicakrXKpPqgFCmQ/1oSQF+2mfFnhvxLvQsYbWNI9svQCFPGo7k+jQwU3w N8NckuIhqRpnTxrfESKBdFAXlMIuoMW87R648Q8tyGp0Tjhr6d2xVnDTYlpwu1TOZ3BeCyWRvobjm c2iBSMiEa/fLdPSZi8mcvhitpDVX08+hJQKeofkdLJVEkwTJMUrtbkBaSg58qbOKmEJU8D/NEA7/i ZjzV01+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfBTX-00000007xOI-0D8q; Wed, 28 Feb 2024 04:23:23 +0000 Received: from mail-vi1eur05on20600.outbound.protection.outlook.com ([2a01:111:f403:2613::600] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfBTI-00000007xCS-2LJJ for linux-arm-kernel@lists.infradead.org; Wed, 28 Feb 2024 04:23:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PSaLLXLfuCx+wZJY8YfbgKYf48+3wBwYFfiz5ddya1+cwUQLUZIhYssVQo75zH9fR96I4gizJ5Y5GJSw3KS5Q4DnC6yD9bwL88Qdzu5baF+quHHLNRGIylaPHzxjODL8oj875rrTk9DZ0UAh27k4uB4K9PSZLckjfi6XnnjHWmaUbMHVW0FENDA4E6U+KlkcU+KXn+O7VkJ4dxldEftu7DrRCpU5ZR5H5w5Y+ZNOOl0BTMe08+iCSPuhxYoxoWsI3hlZDwtoFzBeWt6VjiEb1psPLNsJcPEmJwXGuajw3cRj3BeVkxE3PLtKfilxatpRDN+s7xXehgAcSmjLul5+Kg== 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=iJtsVrsu/RRLv3A7uvo/vMnOxW+tKnO1OO4tL6uhXVvClNes1UMJ4ZyBaR2kbEyt0Bh1af56fAo8kTGwef9Y+Oz6HoXTV/7ljVs/GrNppenL3wuGWS2j9nscCLCXRHDGOPd8I6DK6inBT2n/ADhnNdqzZ7wITj/xVOVsY2+xW3qqGUc6t1ItrI6ZObo2x8NWFjClQpjT1F0feFWG7e7AUweBlPLW6s/2BfvHyhT4uyC8CNDqrYonis9wf4XNrl+xOqOJdWHrkoyQA9xtB9rNfMzVOB7bf5b/Y+c7P7UfpWLzscE9aD0OLj2F+uonz44HnGhzU0G9kTWfCYPX177d8g== 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=Vab4CauhqeS5Xc6DwHmhy3aq8IgllZfXpNI9OAm/qj+Fop6ock/N0yZSOoWJumnNF05dDQqfgZRfmXpl2Oe7UhPYWkU6LLvff8TPIGfkqklvOlSdkJYQPwolEL6gkn27umnp6Z6OEUlr+50gV4xDl0xbk2I5nKcLkKhgmpXOcoQ= 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 GVXPR04MB10071.eurprd04.prod.outlook.com (2603:10a6:150:11a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Wed, 28 Feb 2024 04:23: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 04:23:02 +0000 From: "Peng Fan (OSS)" Date: Wed, 28 Feb 2024 12:31:05 +0800 Subject: [PATCH 2/2] clk: imx: add i.MX95 BLK CTL clk driver Message-Id: <20240228-imx95-blk-ctl-v1-2-9b5ae3c14d83@nxp.com> References: <20240228-imx95-blk-ctl-v1-0-9b5ae3c14d83@nxp.com> In-Reply-To: <20240228-imx95-blk-ctl-v1-0-9b5ae3c14d83@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=1709094675; l=13492; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=xdgyrgvjxybTyzDq8X/GTHuUjGIxReFNUQBlt7Wg4qY=; b=WgblZVVeGQHSl14sz7C0ASKpaE7ZPRrECKgAvYIQimT5VlcHq4Nuwx4THNPsng0PajrtKRokz MEwzK7rH9xwC8Mvr23++B5Mq0kOfKDBb1nbLb/lacEWgVpKBj+u4Wug X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI2PR01CA0017.apcprd01.prod.exchangelabs.com (2603:1096:4:191::19) 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_|GVXPR04MB10071:EE_ X-MS-Office365-Filtering-Correlation-Id: 30a2b881-aa73-4a34-4a3d-08dc3814f416 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: FJaONLvQUzkUBX2Uwvw1CZT0cDZJ7wNCMKFxT5qrEHlUPYkAUVnljcsyMyFOawc+/zYSNW0LLqa/m6iGpBEueyl6SR0Vw2japjbSOzZdmHkAZbbk6wj5dbMmho/Iq889b9tUh1HhDf7Ps/OpNDQKUtH6L0PBIeaNC3CBAzH1qV/R7eG2QrXsntnNfanpwrUsiufmN+HPpl4XrZ54tb/Jep3ZgKktnhx7nW3uNPuHgsxIoaplKVo3Lye68xCWcVPhyJHiB9lDjgapujeWi/6cKvoqzxgfsaGjuhejQojpkZ5vruCcarQ7ZXQ3Sjl7l5pASwPfbUwm8x4Z+F0nnJ/1SNVSjkJWhNI9foAXDcFdjW2fnvOyhjKPfmnBers4BZYQn94r+XT7coVYQLLM73KOF3fovcEydPlXJl4ensWWxG9BrpShBzHQU8r4PMaeI6VX7OgK2AiqGvU8McQC1WgZhmt75nkWTkIlhUObgJ6McdvpYtGb0i5W14cHZo/pyUwRY83+I6QcrUlw0Z3usuO1EONg8t5+CzpUV4DrqTh4tdbw5aiK8agBzuBsHlFi6wTtYjgRIGnQm43zepH1uX8Ha4k61BC6EK+DkUX/HwmiAnMzA53TjKDWcdLW3v4dAQNlQZJDJ0UNLzr2dvlYwH4DABE1LbTPLwTE1teHv7gSdgirvyRlQFb+YD3BEf2flHTM+TT5R+X1XuqWiTJIFaRIa8lHC49LA55WqEn1b/uoYPU= 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?6RJbsOSpc7tUnlBCmBmEybnXVSRz?= =?utf-8?q?lxClA+wwM8fdRM+f5h7q8ohZuTix4377B61gbZrrciUefJBShL9qiEsjk+onqKX34?= =?utf-8?q?Jc7S2Tjet52IVWS++HLMKuzPxV3YuT76KDrZ9WmLiVZjS5xx07tRrsDfRh6OF/Jnf?= =?utf-8?q?9Uw4SYvjPCx+5Dr/xeXKq2MWYHZ4rV4bcO1ZvxzanWd2rEtlTJhx58RyrhDdDyozh?= =?utf-8?q?0cvNqJefAhcP5OZe2U18qoXYkrFnmKBFtT7CFtpFJmNz+zL6iruKUbi89S67xrdDb?= =?utf-8?q?qnK8fYTsFBPZlzQe7T3/2dwf5C1bMGjmcc8aR/Oq2Gjv5T3cF9z/qllDUONIj0Q3t?= =?utf-8?q?UQ09oOWJ+kH/T6EvFL96fYmH/DDLIZdJVleTPYKFSqpuzo2Pzm+1YeS2Ml3lFwdTI?= =?utf-8?q?yLk6QkcbGjH4aBGdQT5DbSyCOdMNWbFkOXOikVez/U5UfsesaasiP+umr0LkbIcPZ?= =?utf-8?q?oXgx2LPo1BMVMW24HGZ079TS9ky9P6tlIqf8XTxafwVimP9AFhv3nlAT08N9q5Ahb?= =?utf-8?q?hF29ncVjET9fws9YvwIM79ZpUKsS0IT/mTzaYx0E/vYbAcVmt4UnVMv1YKMgGSbh+?= =?utf-8?q?/TTskh2ZHqsqVkPdV4AI0ByFL0s4hUbzNd1mVPJlrKFqULlxFs9lNd0GtecjkJO48?= =?utf-8?q?FfLMFEwz6S3kWJ/ukEI8bu/4UP2xnTPgugTzAOdFotQFbDrfLTuH9sQYZv3WLP0NE?= =?utf-8?q?zynG/cfPhvuFE2UW5s/uxA9uP7dnCHfQ15zzdM/4E/TXM8v5Dnyf9I9CGAYNwVnCr?= =?utf-8?q?FEKjfQvOMJXjnfcF9fY4qYyKMLa0luCQv8QOYOKG+V+Rq0Ic2xFHzDSgzUujwXX7c?= =?utf-8?q?UPo0c9J3+zO1qcKY5iCmRpKVzLacCP+64sHRwF1U29v13iSe4YzrwDAQ8jDI3LVgi?= =?utf-8?q?iYKbzdBYrSId9kO349USCXRTr8bdh8OtIXjMQKpvdoF3r8GCZanlL0VhgDLaC3UP4?= =?utf-8?q?6bn08mU+kTWdsXV/Hyef6JCxFSn2DauaBxM6RJQV1YnWt4S+10V68dsfFGY57JPVz?= =?utf-8?q?VbflazXhlQhXrpbdNI1JDxxg3yDdokt3N4UfNtzmeYFwbsm/jbd1hKnmB9vHJN1Kn?= =?utf-8?q?zIWIvYkgui9sC4n3rMnako2bjf43LnpghZ11vnFNOkFZKlo6xxOqsTmFivu/TO0ek?= =?utf-8?q?2KM4GgYN9IPtHGCU/gkMrLDxxigdnb0RbXBPeccscAgFfdaWZL+F+bLrlAAFO/lXh?= =?utf-8?q?3XQgimj83Ny0y7qWbn8Fy3NcHLqkGoiHOsSyiReFXhXsVMdE/8E/jHDkN02zheyaT?= =?utf-8?q?9U0wfyCsq9QCnvMOY6UJUKp8AbXUaLxKs67TmOpPN9xrLqwty9B1zattzh7wInAu1?= =?utf-8?q?6bkKoqCyTjrcsoy9Fzi9h8S8Lh8e9X4FmgUffPVP3YkiWkKQYwxX+i6xmIyt3qnxj?= =?utf-8?q?mWGr5Sqfe7OIBHKRBWobN+jU7nY+AlyjZg17XP/FACR27hUNTXZx+JgXK0lZpdPlz?= =?utf-8?q?SkDbzaBbveY+JkeSOWQZ9a25mc6IoC8kWsuuv20MDy/gcROma3xmM4XYIqt3rUvbI?= =?utf-8?q?yhZHac0zoal2?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30a2b881-aa73-4a34-4a3d-08dc3814f416 X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 04:23:02.6791 (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: cwULBlt5HXbNnBtWIF4QrTN/nFG464teOP5et7Ev9AYeG+AyI02v0k8XOnivyMqWsB8IkYf6/VpVsk32hDYl2Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB10071 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240227_202308_914945_41F300D6 X-CRM114-Status: GOOD ( 15.59 ) 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");