From patchwork Thu Oct 26 07:41:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Buddhabhatti, Jay" X-Patchwork-Id: 13437322 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 8D350C25B6F for ; Thu, 26 Oct 2023 07:42:36 +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:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=E2XaI2ILjQV7ApsVapivlt6ifc7kNuaewgFj/5sC6PI=; b=sCA1RpEVF5SSam n26gsufJfng8ursNAnuEa37hBbp39PMRRpUuZBZnZkAX4gNshEyFAdgWL3pP0mROceKR+VQTwOGyz EPIX9+/lmVqQArUTRAepHtoWEaWuBQXJ26RJpTKFiASGXnrom2u88FD/rrlOIIkatvDSqCx+seKlJ tFo7Qp2DAfCHpIjtJRXjpx/wddlIRcF21kriOZPQUBceA2TSDUZfU20lijesWhYtplEOz8gEDnSie +rKR36LvX5NCpg3GkdtziGDqDyZafYixqrPIbLrHmGENySfInOqeTJ5Hh1rgW+VNnx3cfW2pdAzaF EWhTaXmxQEZ2XEbh21FQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qvv0N-00DsIH-0k; Thu, 26 Oct 2023 07:42:11 +0000 Received: from mail-mw2nam10on20628.outbound.protection.outlook.com ([2a01:111:f400:7e89::628] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qvv0E-00DsFx-1q for linux-arm-kernel@lists.infradead.org; Thu, 26 Oct 2023 07:42:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Uyodx2Ka6B9wm1aj9XGoA0og/xrb+ZN7Wbnm+hkqKYiCJ2Xs7KQed1zv7kceUeX9qQdgPrYj800+HGgyQZgR9IKDbtNjbvCTcpRs8uN6WijTDn+FRvnLictodclTe1ZoV7/bHvZZ/DZyVmKWpEBCNd9iJpAWrGFEr6M7h3Fl7Hr9x8THdib0YzB3t5PVrKuHULPVwDUeKrFK8HaEZgwG9onnhaQ2g90OYjl6q1cXuL6p9d9HtmOS3cnuI1mjnFuisX7hSfhxwLD+FqazKlwN5Sy+6SyPCUQgiHg+/Qfdnl13IsL9JY+InrpX5/E+VX3aIQRKzDIwHaJozzco0HWC+Q== 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=f0si0XF/0Y7YucdFXCNg3Xr799yC2PhchuwuP9wxUP8=; b=TG3CJO2jWU0Tfc1qEKepTuXy6KV7VEeFm6SKAnyJPtzi+sLUgl1osP8Iw5FGgZcV1IGsohORtqutc35xYEj0XSmvIrkJfJybpZ262yPI1HEgjZcHDfYzQCjAWBwU+QeGKW/rARyNf9CZlQX4nAqf2C6TEwRes5Jwyhx52J6YX/4STgAmkP0vUm8Cig0VWCpZ3j53VJYVFZ3RwWYSPpMda/pdljBroKkPBgO23/K7gzwWTs/cIDIzaTMQlPAO/dvEdde7gl0dkWFHW2U1wNTbTg3vmVnx1ggzum+Cgm5hoABz7/VdJFxpBUh8AKznWrRVOeVpM4G7h0AmrJDsfQQCeQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=baylibre.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=f0si0XF/0Y7YucdFXCNg3Xr799yC2PhchuwuP9wxUP8=; b=3rpfq2EnsIhBjzbfMm019aaQKfG/CRcIGl24gjHFUEmo5u73aa9LA7fHTqGNl55aAkMPvXlJx6tgJdD15+Z4U7HZF/bw1e/j8XoE6ytyqMfewqLSOUje4i2Cs2yYIJGZqwwk0jpWj3JKjPVw1cev/MfD8hK537tgTewgl7ZjDSo= Received: from MW4P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::13) by SJ2PR12MB7895.namprd12.prod.outlook.com (2603:10b6:a03:4c6::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.29; Thu, 26 Oct 2023 07:41:54 +0000 Received: from CO1PEPF000044F8.namprd21.prod.outlook.com (2603:10b6:303:8b:cafe::ea) by MW4P221CA0008.outlook.office365.com (2603:10b6:303:8b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.22 via Frontend Transport; Thu, 26 Oct 2023 07:41:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1PEPF000044F8.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6954.0 via Frontend Transport; Thu, 26 Oct 2023 07:41:53 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Thu, 26 Oct 2023 02:41:52 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Thu, 26 Oct 2023 02:41:51 -0500 Received: from xsjarunbala50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.32 via Frontend Transport; Thu, 26 Oct 2023 02:41:51 -0500 From: Jay Buddhabhatti To: , , , CC: , , , Jay Buddhabhatti Subject: [PATCH v2 1/2] drivers: clk: zynqmp: calculate closest mux rate Date: Thu, 26 Oct 2023 00:41:47 -0700 Message-ID: <20231026074148.7927-2-jay.buddhabhatti@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231026074148.7927-1-jay.buddhabhatti@amd.com> References: <20231026074148.7927-1-jay.buddhabhatti@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F8:EE_|SJ2PR12MB7895:EE_ X-MS-Office365-Filtering-Correlation-Id: eca3618e-1e13-4e17-35da-08dbd5f70604 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ftSSnLMHHrrmxscUSrikwJCZf/z3MV55MEcjqS8d4OKLJ/2GTOMjCEIDmHWbc+dAsQJcK5BNK4a/0fhV0lhUtJuHAWhu+F2625jB7b031tDfrDKQfe+hidnBtzctqdv45KyH1XLRFAmtjGysPdnokH8kRe8DR4bS5iq8Iu92qCo72DhUqgWkEXOgimFbUwpATj6yZnTZjDhPwLer3pjhUaSOyeuHjY7swPo1o4vUXJUm2pplKuod3rn1/vYctZEoW6ou4zPHZrQ9cJYmljijlkt3zLydrWE8DiAM3Mi1S38iOqnz/0RA/uRROV2vxmlhJjeQ2WM13SM7pQ922ne7c+Bc8gI0vQxm3p1rCR/w26nrr+gNXH39SliZyliICMOHXKnPU5exvvUZnsUlpvepKu5htjZQQ/vYyP9VePBuVioebw9Wc7bJUa5fO5O34buKL3tJIIYZwT184hU0VRLlPCyDzUcI9dsQU9/qDD9m9IBtqQYWm5R0ICkkeh54OvBkjLgVFZJuj3hHILeeQ0f92FRVU3sjd1Im4ERa8DuAb43gTJjl93FxJFUnFzIC+VFIhR+r8cOTO2vGxSs4oY7pAL1zYJT8ext4drEd2gJK7oRT4a5PD7JnVHgk+bLYBKPDgdZ3QIcJvGRZlzmirQDt02cNIe5PIZ7wTaTxYWFYJkphkPy/TT0vQgHnWCoBFmiuX9JgffzumpvhbIu3bEwsnXkbDM6kLv88VB3NBA7h2u+rk47yl+65axHyVevlLNzRQBaqxzCIFSY+3ct6ltQcMQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(376002)(136003)(396003)(346002)(230922051799003)(451199024)(186009)(82310400011)(64100799003)(1800799009)(36840700001)(46966006)(40470700004)(81166007)(26005)(1076003)(40460700003)(36860700001)(2906002)(41300700001)(86362001)(44832011)(5660300002)(36756003)(8936002)(8676002)(4326008)(54906003)(110136005)(478600001)(82740400003)(70206006)(356005)(316002)(70586007)(40480700001)(2616005)(83380400001)(47076005)(426003)(336012)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2023 07:41:53.6072 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eca3618e-1e13-4e17-35da-08dbd5f70604 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000044F8.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB7895 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231026_004202_612698_2160F983 X-CRM114-Status: GOOD ( 13.62 ) 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 Currently zynqmp clock driver is not calculating closest mux rate and because of that Linux is not setting proper frequency for CPU and not able to set given frequency for dynamic frequency scaling. E.g., In current logic initial acpu clock parent and frequency as below apll1 0 0 0 2199999978 0 0 50000 Y acpu0_mux 0 0 0 2199999978 0 0 50000 Y acpu0_idiv1 0 0 0 2199999978 0 0 50000 Y acpu0 0 0 0 2199999978 0 0 50000 Y After changing acpu frequency to 549999994 Hz using CPU freq scaling its selecting incorrect parent which is not closest frequency. rpll_to_xpd 0 0 0 1599999984 0 0 50000 Y acpu0_mux 0 0 0 1599999984 0 0 50000 Y acpu0_div1 0 0 0 533333328 0 0 50000 Y acpu0 0 0 0 533333328 0 0 50000 Y Parent should remain same since 549999994 = 2199999978 / 4. So use __clk_mux_determine_rate_closest() generic function to calculate closest rate for mux clock. After this change its selecting correct parent and correct clock rate. apll1 0 0 0 2199999978 0 0 50000 Y acpu0_mux 0 0 0 2199999978 0 0 50000 Y acpu0_div1 0 0 0 549999995 0 0 50000 Y acpu0 0 0 0 549999995 0 0 50000 Y Fixes: 3fde0e16d016 ("drivers: clk: Add ZynqMP clock driver") Signed-off-by: Jay Buddhabhatti --- drivers/clk/zynqmp/clk-mux-zynqmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clk/zynqmp/clk-mux-zynqmp.c b/drivers/clk/zynqmp/clk-mux-zynqmp.c index 60359333f26d..9b5d3050b742 100644 --- a/drivers/clk/zynqmp/clk-mux-zynqmp.c +++ b/drivers/clk/zynqmp/clk-mux-zynqmp.c @@ -89,7 +89,7 @@ static int zynqmp_clk_mux_set_parent(struct clk_hw *hw, u8 index) static const struct clk_ops zynqmp_clk_mux_ops = { .get_parent = zynqmp_clk_mux_get_parent, .set_parent = zynqmp_clk_mux_set_parent, - .determine_rate = __clk_mux_determine_rate, + .determine_rate = __clk_mux_determine_rate_closest, }; static const struct clk_ops zynqmp_clk_mux_ro_ops = { From patchwork Thu Oct 26 07:41:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Buddhabhatti, Jay" X-Patchwork-Id: 13437321 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 907EDC25B48 for ; Thu, 26 Oct 2023 07:42:35 +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:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=dnlqPqyXCZbp14c24Gnz3LgoOTpxlbijey8KNcRFtfs=; b=DxZCuk3CNRGHRX Hjf6q7AuGxt9fx2CkpHQZSCmn27rzYljLRdzC2GOSx84qCmOsEX2sTyPXLpgYQCzcQA/PkNnU3pn3 0GrZ5gwgCxmB/gvlG7IGQQ6ihkDTbv2jYrjaJTOxG2o71SUWAeX5U0+GJayIFL/0FXUwoOOl/LuCt 5KO+X5IfZYPlQEKhWMJ4oKN58YLl6RYpYTAtytJyEkwyNMgwc4sC1rS0PYpql6/aSqCVA8ZWXsW7Y 0gCoBtGH4VQ+BbjfsS+6UtWUH9ilEJyd8zldbFDAmz4PzyGAzpliSXGy4lQv5+buVqQQP0AlOecD0 igOMYxmj/KrAMJy4V4KQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qvv0N-00DsId-2c; Thu, 26 Oct 2023 07:42:11 +0000 Received: from mail-bn1nam02on2062b.outbound.protection.outlook.com ([2a01:111:f400:7eb2::62b] helo=NAM02-BN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qvv0F-00DsG5-0N for linux-arm-kernel@lists.infradead.org; Thu, 26 Oct 2023 07:42:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IaIycbKwN4hxKzrFOVc0SXDZHQ8V3YInJO9uA5xcdt3GOXZzEt/xto0mANE4HY8UMUvDt5Wfc7MSQQ+ikIqxhSOEwXpz84B4VnojrgFzrcLrVkIGtd9sH+BM+1gQhf8AIG91vhUZjiEVKun2FJO2ClTPctRWExIgi9qyjqzM468InHdCUDyJaECESUEKrzl7+ipVBIxZe9aFk2wJlWKquWg9ACnZ+RnqYbMiqKPJu9EhcvvUVA/lJhqA4PHNRv/mF6b1ovK7gGAWGeceOnx1XSgDJM1eY6RWiSdKCn5vVvLVcLGyQLrbe1JKXG/10/JwCU1CuiVHU0lhL6mjInn8rw== 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=zlRqJg2qMSFYAUx4SKubFDFhDCiP2ETTgr8I2+g+9bI=; b=MsbzGIUfKAhEGjjC5180X6nY2NDl+jBuXY37uVY33cX/tkULrlCSg5Zkitdwf7C2z6m3DLwerUceftOSj0g5S6A9GhYyN6Y7fxoeJH03+1UHZQNtHWfEzjVJOcajZ8byT49Bsn8PcaPDhZitJixrPfZHCKpBxFfVsG/sTZQSYi845o3Uo68zbSZtJ8/dD0ZlvLHpNJxQsKilqLengGt8Jui75oZjZU6DXGqEc/raqpNCIlHTFbkKxedtiLvVDfNVblGcIPLnoouY/QaAwMqgLLE4fJHVIGZTotkMnwAUvFjIbeBk7L2RBvFgsaU3nmqz1ZAp7guotEBfCPsj1thAVg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=baylibre.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zlRqJg2qMSFYAUx4SKubFDFhDCiP2ETTgr8I2+g+9bI=; b=C2vyqDu97VhBA6J8YwcuPL6Cl4hqLiHaKz65dCbS7DbBz/Q9nmE3/flFRhnIxOygtsIjLIQbD01ntYMbA69qE8+Y3qWA1v3l522IbUiCCO+8DBvg8/kDV2BS5W6Vm6aOmgwpELIJgJ1yMB87m2dahMG3JFTLwUUHcNOloNtIg7U= Received: from DM6PR08CA0057.namprd08.prod.outlook.com (2603:10b6:5:1e0::31) by SJ0PR12MB5636.namprd12.prod.outlook.com (2603:10b6:a03:42b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.29; Thu, 26 Oct 2023 07:41:53 +0000 Received: from DS2PEPF00003445.namprd04.prod.outlook.com (2603:10b6:5:1e0:cafe::91) by DM6PR08CA0057.outlook.office365.com (2603:10b6:5:1e0::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.19 via Frontend Transport; Thu, 26 Oct 2023 07:41:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS2PEPF00003445.mail.protection.outlook.com (10.167.17.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6933.18 via Frontend Transport; Thu, 26 Oct 2023 07:41:53 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Thu, 26 Oct 2023 02:41:52 -0500 Received: from xsjarunbala50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.32 via Frontend Transport; Thu, 26 Oct 2023 02:41:52 -0500 From: Jay Buddhabhatti To: , , , CC: , , , Jay Buddhabhatti Subject: [PATCH v2 2/2] drivers: clk: zynqmp: update divider round rate logic Date: Thu, 26 Oct 2023 00:41:48 -0700 Message-ID: <20231026074148.7927-3-jay.buddhabhatti@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231026074148.7927-1-jay.buddhabhatti@amd.com> References: <20231026074148.7927-1-jay.buddhabhatti@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF00003445:EE_|SJ0PR12MB5636:EE_ X-MS-Office365-Filtering-Correlation-Id: 0f345716-9c1e-4a4b-f50c-08dbd5f705bf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RZTJtkLIYw64W395kilzcaXyxXN1Kv4+Aft63HZB7i9v2/0A9WAeuBuhTH/QaTUEFEp0KSzPKcc9l6gQnXaBvYC/jY08vpXO6buC1dcHPYB8Z8DBrqcNuwSTBpoMCHDzUWnrPt34aKlvbFNJvcIXq+RfjB5OdzUmQGQPfR8FM/yo6ldf/PJkUz6ALIAhWdR7r4qkbg+4ML17yw95ZxZy4PCXaMTcbxWRSh9tGO3pm/PM8LyoQGdUuaL/j8gBVw1rnsSdNMoWvKTrh7CAaEW6f5MoYSzGQnmxEFxnHDSfYQ6vHTE2Ku/9saYVs8v/BgaaepiOIZqxHJkKPhICLOuKxcOcpxx92VNdHBmei3PY2D4Nv7srJYRE03SAVO5yFIDZMAcE/XWmThYZztYJkja3Ukx0yhZcAu8iTFP6dgZW7QdSqsefd/YM1TZkeUrUVXJckTY0s/yCQORX43nWRhEwPzGXDwLyn+oiG+rvejWZaE41TfIDdiaReKRG1sebtmulQmc1ryYwoYeJtTRhjbqZ7W0uhqy1G+ZotPD/oZ6xx8nv0uGVPC4t05eXzg1nU8XkXoGgMSuwyVsaWVGWVxR6W/HY8r4BBCKj23X9lejxMlASYufTqEmLzZ517DUaUcMC+S58QiDYNHEdJ7rBVXjKuiVXpcbBZ7/O9lLM9y9Dof5xcA5E99Y8Y8yhZmdrbp3e8YcfysdJBruEj4qCzWOuHrbz3Czva85jmZiAkSCyybMhWtDD2s8PRN1p91jZdvaty6h2PkWP5H89r6SQ1mN81w== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(39860400002)(376002)(396003)(136003)(230922051799003)(451199024)(186009)(1800799009)(82310400011)(64100799003)(40470700004)(46966006)(36840700001)(40480700001)(40460700003)(83380400001)(4326008)(36860700001)(2906002)(26005)(8676002)(36756003)(82740400003)(47076005)(81166007)(426003)(336012)(44832011)(1076003)(2616005)(356005)(86362001)(8936002)(478600001)(316002)(6666004)(5660300002)(110136005)(41300700001)(70206006)(54906003)(70586007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2023 07:41:53.2536 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0f345716-9c1e-4a4b-f50c-08dbd5f705bf X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS2PEPF00003445.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5636 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231026_004203_156670_D8727F64 X-CRM114-Status: GOOD ( 12.43 ) 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 Currently zynqmp divider round rate is considering single parent and calculating rate and parent rate accordingly. But if divider clock flag is set to SET_RATE_PARENT then its not trying to traverse through all parent rate and not selecting best parent rate from that. So use common divider_round_rate() which is traversing through all clock parents and its rate and calculating proper parent rate. Fixes: 3fde0e16d016 ("drivers: clk: Add ZynqMP clock driver") Signed-off-by: Jay Buddhabhatti --- drivers/clk/zynqmp/divider.c | 66 +++--------------------------------- 1 file changed, 5 insertions(+), 61 deletions(-) diff --git a/drivers/clk/zynqmp/divider.c b/drivers/clk/zynqmp/divider.c index 33a3b2a22659..5a00487ae408 100644 --- a/drivers/clk/zynqmp/divider.c +++ b/drivers/clk/zynqmp/divider.c @@ -110,52 +110,6 @@ static unsigned long zynqmp_clk_divider_recalc_rate(struct clk_hw *hw, return DIV_ROUND_UP_ULL(parent_rate, value); } -static void zynqmp_get_divider2_val(struct clk_hw *hw, - unsigned long rate, - struct zynqmp_clk_divider *divider, - u32 *bestdiv) -{ - int div1; - int div2; - long error = LONG_MAX; - unsigned long div1_prate; - struct clk_hw *div1_parent_hw; - struct zynqmp_clk_divider *pdivider; - struct clk_hw *div2_parent_hw = clk_hw_get_parent(hw); - - if (!div2_parent_hw) - return; - - pdivider = to_zynqmp_clk_divider(div2_parent_hw); - if (!pdivider) - return; - - div1_parent_hw = clk_hw_get_parent(div2_parent_hw); - if (!div1_parent_hw) - return; - - div1_prate = clk_hw_get_rate(div1_parent_hw); - *bestdiv = 1; - for (div1 = 1; div1 <= pdivider->max_div;) { - for (div2 = 1; div2 <= divider->max_div;) { - long new_error = ((div1_prate / div1) / div2) - rate; - - if (abs(new_error) < abs(error)) { - *bestdiv = div2; - error = new_error; - } - if (divider->flags & CLK_DIVIDER_POWER_OF_TWO) - div2 = div2 << 1; - else - div2++; - } - if (pdivider->flags & CLK_DIVIDER_POWER_OF_TWO) - div1 = div1 << 1; - else - div1++; - } -} - /** * zynqmp_clk_divider_round_rate() - Round rate of divider clock * @hw: handle between common and hardware-specific interfaces @@ -174,6 +128,7 @@ static long zynqmp_clk_divider_round_rate(struct clk_hw *hw, u32 div_type = divider->div_type; u32 bestdiv; int ret; + u8 width; /* if read only, just return current value */ if (divider->flags & CLK_DIVIDER_READ_ONLY) { @@ -193,23 +148,12 @@ static long zynqmp_clk_divider_round_rate(struct clk_hw *hw, return DIV_ROUND_UP_ULL((u64)*prate, bestdiv); } - bestdiv = zynqmp_divider_get_val(*prate, rate, divider->flags); - - /* - * In case of two divisors, compute best divider values and return - * divider2 value based on compute value. div1 will be automatically - * set to optimum based on required total divider value. - */ - if (div_type == TYPE_DIV2 && - (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT)) { - zynqmp_get_divider2_val(hw, rate, divider, &bestdiv); - } + width = fls(divider->max_div); - if ((clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) && divider->is_frac) - bestdiv = rate % *prate ? 1 : bestdiv; + rate = divider_round_rate(hw, rate, prate, NULL, width, divider->flags); - bestdiv = min_t(u32, bestdiv, divider->max_div); - *prate = rate * bestdiv; + if (divider->is_frac && (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) && (rate % *prate)) + *prate = rate; return rate; }