Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp239928lqg; Thu, 11 Apr 2024 00:54:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXlGtO2LIL9eMvInjnNY2gM0mZg95IVZ/yT7HGxXbtj27n4UcnKW42l5HFOAWZrPohOyZP3WRUm28aXFWKC2I7B1Pf104+ndMYhYq0LtQ== X-Google-Smtp-Source: AGHT+IECZp3E4urqixmt/9RYYFTiHQS8Wpcv6EaBvZCm933Qh1FG0cGDEeO2HgszVjZK7Ky4aVSC X-Received: by 2002:a05:622a:1803:b0:434:342e:2b56 with SMTP id t3-20020a05622a180300b00434342e2b56mr5970794qtc.31.1712822064101; Thu, 11 Apr 2024 00:54:24 -0700 (PDT) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id y15-20020a05622a120f00b004365842cbdesi977081qtx.353.2024.04.11.00.54.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 00:54:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-140034-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=ZRFCE4wQ; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-140034-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140034-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C109F1C21563 for ; Thu, 11 Apr 2024 07:54:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B0A5813E8A1; Thu, 11 Apr 2024 07:54:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b="ZRFCE4wQ" Received: from SINPR02CU002.outbound.protection.outlook.com (mail-southeastasiaazolkn19011002.outbound.protection.outlook.com [52.103.65.2]) (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 6F33A2EAE5; Thu, 11 Apr 2024 07:54:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.103.65.2 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712822056; cv=fail; b=tBVp3bEkI0bdD7FFd+lLYs1ec8wC54z9ThhW14S5OAy3we9HGCGlrVs8xITilRMYcuMdqSUCr+YGuytqydNAPFc2/Uy+yuFhRtilRiZOWc2YNpXdu/JM1pa+m7q85ffKGXHGmhQb2uUiNq573a8+cFRjo/ez2sk6GvgOr37lRYw= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712822056; c=relaxed/simple; bh=b7HYP3rxgQ5ebfPlGmEGaLKoryuqFEJH8XNbdBvGQB4=; h=Message-ID:Date:Subject:To:Cc:References:From:In-Reply-To: Content-Type:MIME-Version; b=SJ+Y+8RgmFbgv2kHIqYpK1WKifrC1uzXbyl/A4eOXd7Xe1JIPm2zxdP7GZ4WjIvwBwWLQR0BinImCEQOkOBo7ZWVlf5KkKhhKVOKHi7TAqAN4Z8ioA3P8YMgfrsiVEAVZe5ma3iVh5X+4m3TWr7e+kI1Nu6fq7dxlsCFaELHp7A= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com; spf=pass smtp.mailfrom=outlook.com; dkim=pass (2048-bit key) header.d=outlook.com header.i=@outlook.com header.b=ZRFCE4wQ; arc=fail smtp.client-ip=52.103.65.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=outlook.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=outlook.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HsQFkLNGfFH3AYfnEo0JPlo5pVnRk8jdryPV8tK7iYZ6ej7fYb+yhkQLAmFhCbGMWosq6WuTer3npvL3/Tc1RuJ/0BXSQIf31EH2ZnQlkIHAGjOhST4CvGe4etQpQkvDYONyaVaUrrth0MqiAeBFJuiUKN6t3TG2LhBbI+QYbx4ADxufdtY4oUN1i7mOKlD/8dLTBpx88HYklfatD/JWg8aL/kvGyj67nmf/d96CdQNAtS2cnIls21w4Abaa2WIIyg84MCadCKRR4pLtzMcDcWqkPZvWZs0R8NYLr18NQqYqRZ94q368NDePAuYfNHhXJGtcBz0SIPdGtkxmeIFUoA== 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=VoHbTDuqrEcbb1ZH0/ZeG+R9CdfvCP2AJjFcXLKY3NE=; b=Q9oESwSrgWHKduDTKUwLlosgzKE6fDnIxYvn1OjCOPscKFetb5tQgl4QjVvz+UN/ezgAs48Lru7U3/+yIfjytmGJNNtZR+YEb+Ya6HDnqA+bDpJXHbST9PFbqlFK9nJ7RI1x0ERDSfsZDymPk9UqptzSTVm/QX+QJnhgFb+Zpu245irfuw6IBdrrh0SE2CJx3v3nhuvA68Gz2rjB2XWhrAXz9AmI9X90g+cCD1J4ERAYqeeZ2AE6e4pKHzOEXBBTyKgIIUe0wrfuS8YCxz2fXS4PJPT8DXlAtHIQzRZGBKt+C4DbDuxVVByGZ/tmmMzKEnTZHHsWaFsnFOvqrSIqPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VoHbTDuqrEcbb1ZH0/ZeG+R9CdfvCP2AJjFcXLKY3NE=; b=ZRFCE4wQwgOL82ykCDLM9oM1U0twn6xH8ATh8GqVphRkOPmXI1I0sZKd1bqNF62LGSowRCMGo9KgDXvOYVPjtF+AdLbIdmDBrmJZLSgGgtSXThP+waLN8+AzRuRiiNYiGWP7vyTemzn+Ad2kduTQwwTojzvR3CCE1veImFtkQP1HPAfioMWLZtiT5Yfz98VplwJHw7IdZKPpXURLjvB6o4re0kURuWU3pXTz00uVrfCKUc9Z4L/1LzOYMTUmgxlFg9U4CjUiy1nIOgjYr5CS6mtUNqXd5wxzXJGJm6qljYnkFAo3KE5m4lnr97M1MD4Jq01fwMQXcTl1C68R+WGH8Q== Received: from SEZPR06MB6959.apcprd06.prod.outlook.com (2603:1096:101:1ed::14) by SEYPR06MB5964.apcprd06.prod.outlook.com (2603:1096:101:d9::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Thu, 11 Apr 2024 07:54:08 +0000 Received: from SEZPR06MB6959.apcprd06.prod.outlook.com ([fe80::351e:200b:add4:6478]) by SEZPR06MB6959.apcprd06.prod.outlook.com ([fe80::351e:200b:add4:6478%7]) with mapi id 15.20.7409.053; Thu, 11 Apr 2024 07:54:08 +0000 Message-ID: Date: Thu, 11 Apr 2024 15:54:02 +0800 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC 2/2] clk: hisilicon: add support for PLL To: Stephen Boyd , Michael Turquette , Yang Xiwen via B4 Relay Cc: David Yang , Igor Opaniuk , Jorge Ramirez-Ortiz Gmail , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240225-pll-v1-0-fad6511479c6@outlook.com> <20240225-pll-v1-2-fad6511479c6@outlook.com> <8b517c5b165d2be77eaf02af1e031325.sboyd@kernel.org> Content-Language: en-US From: Yang Xiwen In-Reply-To: <8b517c5b165d2be77eaf02af1e031325.sboyd@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TMN: [gBeDLBkLdwVCjC4appKv1w13MLu0x2nLsR82asbgl4aNV73HHzLjdLN9iM1+lfwg] X-ClientProxiedBy: KL1PR01CA0155.apcprd01.prod.exchangelabs.com (2603:1096:820:149::10) To SEZPR06MB6959.apcprd06.prod.outlook.com (2603:1096:101:1ed::14) X-Microsoft-Original-Message-ID: <66670d73-9095-4bcb-aa90-db1aa515d56a@outlook.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB6959:EE_|SEYPR06MB5964:EE_ X-MS-Office365-Filtering-Correlation-Id: eeb67eac-db25-4377-f85b-08dc59fc90f3 X-MS-Exchange-SLBlob-MailProps: obhAqMD0nT9T0RiVOmbr8zTeQMuNXWEo1DI7h3jT4JUuZt9LO4wMaFgmcGyU7Rrd56JEk0eDI6OiuDQR9CiiZxXdwDqhYWNy0dBTsj57hhDTbnc8sjkpGwWvI5h4pFHFsbHUEOeE1IyTSF5HT+nricSV+peIMZWshIOT/js0jlHyEM+zm2qkV1IxO2OH60ttVjhe1X0k8NdAbNS6Y6pvYGVJnKKXsOtnhO3HiGGZSE/JaEvatuk6M0zHtPwVMuQMb/PKLYRINAVqqSjRoAv4X9uasHrmge7oEabCx2TqWplWw6nGQwL2CdvuxFhhSaZ5ukN+91vKGTht7wyZA3vu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V?= =?utf-8?B?TUJMMnZveDZqb2x6R05VVmkwcUg2RnZhMFZRK0ExTUZKYS9lNEZjeDZwaFJS?= =?utf-8?B?anAzVWRwTXptenJEMHIvMmEveGFMMzdOSFVVRzZHOGRVVlZYaWpnaS8rY0du?= =?utf-8?B?WlN6VTFFeTdTbHF1V0sxeEZLNEs5ZCtoc3pET3VsZmM0bVYvaloyN1N3bnhR?= =?utf-8?Q?1QTYBWkwjqZcORyqKsStt77+qNvYZ8xa4UPXUJR?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: eeb67eac-db25-4377-f85b-08dc59fc90f3 X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB6959.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2024 07:54:08.0669 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR06MB5964 On 4/11/2024 2:59 PM, Stephen Boyd wrote: > Quoting Yang Xiwen via B4 Relay (2024-02-24 08:56:10) >> diff --git a/drivers/clk/hisilicon/clk-pll.c b/drivers/clk/hisilicon/clk-pll.c >> new file mode 100644 >> index 000000000000..c5c07a65fcf4 >> --- /dev/null >> +++ b/drivers/clk/hisilicon/clk-pll.c >> @@ -0,0 +1,171 @@ >> +// SPDX-License-Identifier: GPL-2.0-or-later >> +/* >> + * PLL driver for HiSilicon SoCs >> + * >> + * Copyright 2024 (c) Yang Xiwen >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> + >> +#include "clk.h" >> + >> +/* PLL has two conf regs in total */ >> +#define HISI_PLL_CFG(n) ((n) * 4) > Isn't HISI_PLL_CFG1 or HISI_PLL_CFG0 shorter then? Okay. There aren't too many registers anyway. > >> + >> +/* reg 0 definitions */ >> +#define HISI_PLL_FRAC GENMASK(23, 0) >> +#define HISI_PLL_POSTDIV1 GENMASK(26, 24) >> +#define HISI_PLL_POSTDIV2 GENMASK(30, 28) >> + >> +/* reg 1 definitions */ >> +#define HISI_PLL_FBDIV GENMASK(11, 0) >> +#define HISI_PLL_REFDIV GENMASK(17, 12) >> +#define HISI_PLL_PD BIT(20) >> +#define HISI_PLL_FOUTVCOPD BIT(21) >> +#define HISI_PLL_FOUT4PHASEPD BIT(22) >> +#define HISI_PLL_FOUTPOSTDIVPD BIT(23) >> +#define HISI_PLL_DACPD BIT(24) >> +#define HISI_PLL_DSMPD BIT(25) >> +#define HISI_PLL_BYPASS BIT(26) >> + >> +/* >> + * Datasheet said the maximum is 3.2GHz, >> + * but tests show it can be very high > Sounds like you're over-clocking. Just follow the datasheet please. > >> + * >> + * Leave some margin here (8 GHz should be fine) >> + */ >> +#define HISI_PLL_FOUTVCO_MAX_RATE 8000000000 >> +/* 800 MHz */ >> +#define HISI_PLL_FOUTVCO_MIN_RATE 800000000 >> + >> +struct hisi_pll { >> + struct clk_hw hw; >> + void __iomem *base; >> + u8 postdiv1, postdiv2, refdiv; >> + u32 divisor; >> +}; >> + >> +#define to_hisi_pll(_hw) container_of(_hw, struct hisi_pll, hw) >> + >> +static int hisi_pll_prepare(struct clk_hw *hw) >> +{ >> + struct hisi_pll *pll = to_hisi_pll(hw); >> + u32 reg; >> + >> + reg = readl(pll->base + HISI_PLL_CFG(0)); >> + pll->postdiv1 = FIELD_GET(HISI_PLL_POSTDIV1, reg); >> + pll->postdiv2 = FIELD_GET(HISI_PLL_POSTDIV2, reg); >> + // We don't use frac, clear it > Kernel comments are /* like this */ > >> + reg &= ~HISI_PLL_FRAC; >> + writel(reg, pll->base + HISI_PLL_CFG(0)); >> + >> + reg = readl(pll->base + HISI_PLL_CFG(1)); >> + pll->refdiv = FIELD_GET(HISI_PLL_REFDIV, reg); >> + >> + pll->divisor = pll->refdiv * pll->postdiv1 * pll->postdiv2; >> + >> + // return -EINVAL if boot loader does not init PLL correctly > Yeah we got that by reading the code, no comment needed. > >> + if (pll->divisor == 0) { >> + pr_err("%s: PLLs are not initialized by boot loader correctly!\n", __func__); >> + return -EINVAL; >> + } >> + >> + return 0; >> +} >> + >> +static int hisi_pll_set_rate(struct clk_hw *hw, ulong rate, ulong parent_rate) >> +{ >> + struct hisi_pll *pll = to_hisi_pll(hw); >> + u64 fbdiv = rate * pll->divisor; >> + u32 reg; >> + >> + do_div(fbdiv, parent_rate); >> + >> + reg = readl(pll->base + HISI_PLL_CFG(1)); >> + reg &= ~HISI_PLL_FBDIV; >> + reg |= FIELD_PREP(HISI_PLL_FBDIV, fbdiv); >> + writel(reg, pll->base + HISI_PLL_CFG(1)); >> + >> + /* TODO: wait for PLL lock? */ > Yes? The PLL lock is not implemented for some SoC. I guess it's okay to simply ignore the lock flag. > >> + >> + return 0; >> +} >> + >> +static int hisi_pll_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) >> +{ >> + struct hisi_pll *pll = to_hisi_pll(hw); >> + u64 vco, ref_rate = req->best_parent_rate; >> + >> + if (ref_rate == 0) >> + return -EINVAL; >> + >> + do_div(ref_rate, pll->refdiv); >> + vco = clamp(req->rate * (pll->postdiv1 * pll->postdiv2), >> + HISI_PLL_FOUTVCO_MIN_RATE, HISI_PLL_FOUTVCO_MAX_RATE); >> + vco = rounddown(vco, ref_rate); >> + if (vco < HISI_PLL_FOUTVCO_MIN_RATE) >> + vco += ref_rate; >> + >> + do_div(vco, pll->postdiv1 * pll->postdiv2); >> + req->rate = vco; >> + >> + return 0; >> +} >> + >> +static ulong hisi_pll_recalc_rate(struct clk_hw *hw, ulong parent_rate) >> +{ >> + struct hisi_pll *pll = to_hisi_pll(hw); >> + u32 reg, fbdiv; >> + >> + reg = readl(pll->base + HISI_PLL_CFG(1)); >> + fbdiv = FIELD_GET(HISI_PLL_FBDIV, reg); >> + parent_rate *= fbdiv; >> + do_div(parent_rate, pll->divisor); >> + >> + return parent_rate; >> +} >> + >> +static const struct clk_ops hisi_pll_ops = { >> + .prepare = hisi_pll_prepare, >> + .set_rate = hisi_pll_set_rate, >> + .determine_rate = hisi_pll_determine_rate, >> + .recalc_rate = hisi_pll_recalc_rate, >> +}; >> + >> +/* >> + * devm_hisi_pll_register - register a HiSilicon PLL > Use kernel-doc please https://docs.kernel.org/doc-guide/kernel-doc.html > >> + * >> + * @dev: clk provider >> + * @name: clock name >> + * @parent_name: parent clock, usually 24MHz OSC >> + * #flags: CCF common flags >> + * @reg: register address > Missing Return: > >> + */ >> +struct clk *devm_clk_register_hisi_pll(struct device *dev, const char *name, const char *parent, >> + unsigned int flags, void __iomem *reg) >> +{ >> + struct hisi_pll *pll; >> + struct clk_init_data init; >> + >> + pll = devm_kzalloc(dev, sizeof(*pll), GFP_KERNEL); >> + if (!pll) >> + return ERR_PTR(-ENOMEM); >> + >> + if (!parent) >> + return ERR_PTR(-EINVAL); >> + >> + init.name = name; >> + init.ops = &hisi_pll_ops; >> + init.flags = flags; >> + init.parent_names = &parent; >> + init.num_parents = 1; >> + >> + pll->base = reg; >> + pll->hw.init = &init; >> + >> + return devm_clk_register(dev, &pll->hw); >> +} >> +EXPORT_SYMBOL_GPL(devm_clk_register_hisi_pll); >> diff --git a/drivers/clk/hisilicon/clk.h b/drivers/clk/hisilicon/clk.h >> index 7a9b42e1b027..8c59f3927152 100644 >> --- a/drivers/clk/hisilicon/clk.h >> +++ b/drivers/clk/hisilicon/clk.h >> @@ -103,6 +103,14 @@ struct hisi_gate_clock { >> const char *alias; >> }; >> >> +struct hisi_pll_clock { >> + unsigned int id; >> + const char *name; >> + const char *parent_name; > No string parent names for new code. Use struct clk_parent_data or > clk_hw directly. Would be inconsistent with other HiSilicon clock APIs. But i think it's okay. -- Regards, Yang Xiwen