From patchwork Sun Jul 23 16:22:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangfl X-Patchwork-Id: 124516 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1360085vqg; Sun, 23 Jul 2023 10:30:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlG131pQqRptJ8TfySR3sjkPZEzn2fcuvK8vZqxdlbq0J1gnlCR4WC5ES9lH+6Kftb85GX3u X-Received: by 2002:a17:903:2445:b0:1b8:a7ec:38c5 with SMTP id l5-20020a170903244500b001b8a7ec38c5mr7402287pls.57.1690133448269; Sun, 23 Jul 2023 10:30:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690133448; cv=none; d=google.com; s=arc-20160816; b=DY/EOlb/QIf6KkZBIL1NDRG42MpmS3IZpmBXbHhRWn8qQY4krFM3Y96IRmIlBL83nw 1iw6sbB5w1fIBDxONdP8xpt1P9ZfJ/luU5SN75iMJ571NbDcICJvov1RphEcdAuY6MMW E4MYrxz8uJjbvCWxftVqvMKPbalgFv9bz5n0xChGyTuFSFGuRjAZmgn+XbDA4kDkNpJ4 bUO3eOG6i3FlbSNdaDLI8H1KcWYkY2RTc4tia+zNtrhSICBLKZwAH6p7rSgmCoAirblc wGYq5LVojEarfJXUU6KSy5HWG52nT8/9wIcC7cdVt82IsTiiqSBtuqyGjp64+piMRod0 yuYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nC80tf2Fqm9NV1HkrgmsaoEnP1GJqadflAYCzRO4B1o=; fh=6op8AbJPoSQyJcsI0L5qUJDM8pym4PtkpWqFZ6dkle0=; b=f9siAOtzHoyZu3wJq+0fq9WuxVl9XEhAp5Yf8lqxnkcIhO2sUnd++ba9j9kuAsjF/J stbpOF2A/pWC5B83kbtmJD77VDR2IDxockIJvFbZDmIA7X1IN9+OgYBwQA38tmaG3RbN o35DkiuZ6kX0gA6G5K5Oacdjdjm8Fwn8IrczLE+sdeIO8qrjN3DtPRhQbs0roqHX2pj4 +stRYm7g795Bhvk4c5Lkbiccjw9v9AG0YV9SFYn8VsiG/qTvph9OgXUsTGOfPja9vbds TGdV4ftqhPJvORwUforbd3c3hj4YQMgCT1JXR76TJlNxkhsv/2sC1DHb8wFjL8r6duSd DXtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ocjCaFiK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ij14-20020a170902ab4e00b001bb86cdf12bsi3057469plb.147.2023.07.23.10.30.33; Sun, 23 Jul 2023 10:30:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ocjCaFiK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229809AbjGWQYR (ORCPT + 99 others); Sun, 23 Jul 2023 12:24:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229537AbjGWQYL (ORCPT ); Sun, 23 Jul 2023 12:24:11 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FE9CE7F; Sun, 23 Jul 2023 09:23:45 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-53fa455cd94so1848120a12.2; Sun, 23 Jul 2023 09:23:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690129418; x=1690734218; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nC80tf2Fqm9NV1HkrgmsaoEnP1GJqadflAYCzRO4B1o=; b=ocjCaFiKtIzplKvPtoFuX6XwXSSF7vAO3+JLcljBsiqsRF941PjtOQYeAcUw38T3p4 ymth6n3JivTbjphSrZY7Ld/pQLahaiRI0jW2wAlGPW4yAr/AFsnuD+uKSoPCmCrtmYLd HT4kMHJj+TZxvEteuUfdf2rJXJ2VIL+CwdNQYri5KXIHndzS4wwAC/Zvl9xPZwlBD+GW bMqWYYm/yxS7VuB8u2yctHWRizsJM/4QVlhf5DoXngtocWGWNLjVwwgeFO0VAc8RDfku wLkCAmMpvKiHc5eR4KaqJsyDXI/6dgpg8Yl001uOZaUTVhyHwQIOCpt4vXU0LalgyM5j ke9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690129418; x=1690734218; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nC80tf2Fqm9NV1HkrgmsaoEnP1GJqadflAYCzRO4B1o=; b=GskJGMh/4se3MBUP0Uwz3BdkNqHM6fbjk0sWS8WolFKnV1LEnFKNntCFryVthi3Uaw NbYiPDp/5OLfhOHX0YWVZf1hs64Z71w6sgJD4VtAzHvg1NuMX71zw2u6vOIq1yKon893 NuEkrKuxfMIaKV/kzuCQjL8+bEt+V8fLDlitjfg01H2L+ZOS+b/Xqcn8KjF4K/PXG4fQ +FcdDspVu0ByN8k9MNGAcgr2W7VIEIIbNvkiW14I0yj72hzFf0wqOv6jE4hGVsqV03Q0 q6LLkViCc9hnzjcXm58pn4vTxHkahNMuMgnsnXcHcDez2J/E3/QHouMGT3UHi0UEnldI fVpQ== X-Gm-Message-State: ABy/qLZ4oeqKwMtDi3/DfZRIfXO0KO6p8iVCIJCJ2tt7siHFr/6RSO6a rnWQYM1c+KdaBQkWFTdNuhPrrhyqQps0eBWg X-Received: by 2002:a17:90a:8a13:b0:263:661e:e0dc with SMTP id w19-20020a17090a8a1300b00263661ee0dcmr5930107pjn.25.1690129418604; Sun, 23 Jul 2023 09:23:38 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.245.199]) by smtp.gmail.com with ESMTPSA id u3-20020a17090aae8300b00265a7145fe5sm6883787pjq.41.2023.07.23.09.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 09:23:38 -0700 (PDT) From: David Yang To: linux-clk@vger.kernel.org Cc: David Yang , Michael Turquette , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH v5 01/13] clk: hisilicon: Add helper functions for platform driver Date: Mon, 24 Jul 2023 00:22:26 +0800 Message-Id: <20230723162245.35033-2-mmyangfl@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230723162245.35033-1-mmyangfl@gmail.com> References: <20230723162245.35033-1-mmyangfl@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772233370858562541 X-GMAIL-MSGID: 1772233370858562541 Helper functions extract common operations on platform drivers. During migration to devm APIs, (virtual) fixed clocks were found hard on devm APIs, since they often depended by crucial peripherals, thus require early initialization before device probing, and cannot use devm APIs. One solution to this problem is to add a "fixed-clock" node to device tree, independent to clock device, and make those peripherals depend on that. However, there is also some devices that do use fixed clocks provided by drivers, for example clk-hi3660.c . To simplify codes, we migrate clocks of other types to devm APIs, while keep fixed clocks self-managed, alongside with struct hisi_clock_data, and remove devm-managed hisi_clock_data. hisi_clk_alloc() will be removed in the following patch. Signed-off-by: David Yang --- drivers/clk/hisilicon/clk.c | 157 ++++++++++++++++++++++++++++++++++ drivers/clk/hisilicon/clk.h | 46 +++++++++- drivers/clk/hisilicon/crg.h | 5 ++ drivers/clk/hisilicon/reset.c | 42 +++++++++ 4 files changed, 248 insertions(+), 2 deletions(-) diff --git a/drivers/clk/hisilicon/clk.c b/drivers/clk/hisilicon/clk.c index 54d9fdc93599..aa8908714cd0 100644 --- a/drivers/clk/hisilicon/clk.c +++ b/drivers/clk/hisilicon/clk.c @@ -88,6 +88,25 @@ struct hisi_clock_data *hisi_clk_init(struct device_node *np, } EXPORT_SYMBOL_GPL(hisi_clk_init); +void hisi_clk_free(struct device_node *np, struct hisi_clock_data *data) +{ + if (data->clks) { + if (data->clks->fixed_rate_clks_num) + hisi_clk_unregister_fixed_rate(data->clks->fixed_rate_clks, + data->clks->fixed_rate_clks_num, + data); + if (data->clks->fixed_factor_clks_num) + hisi_clk_unregister_fixed_factor(data->clks->fixed_factor_clks, + data->clks->fixed_factor_clks_num, + data); + } + + of_clk_del_provider(np); + kfree(data->clk_data.clks); + kfree(data); +} +EXPORT_SYMBOL_GPL(hisi_clk_free); + int hisi_clk_register_fixed_rate(const struct hisi_fixed_rate_clock *clks, int nums, struct hisi_clock_data *data) { @@ -341,3 +360,141 @@ void __init hi6220_clk_register_divider(const struct hi6220_divider_clock *clks, data->clk_data.clks[clks[i].id] = clk; } } + +static size_t hisi_clocks_get_nr(const struct hisi_clocks *clks) +{ + if (clks->nr) + return clks->nr; + + return clks->fixed_rate_clks_num + clks->fixed_factor_clks_num + + clks->mux_clks_num + clks->phase_clks_num + + clks->divider_clks_num + clks->gate_clks_num + + clks->gate_sep_clks_num + clks->customized_clks_num; +} + +int hisi_clk_early_init(struct device_node *np, const struct hisi_clocks *clks) +{ + struct hisi_clock_data *data; + int ret; + + data = hisi_clk_init(np, hisi_clocks_get_nr(clks)); + if (!data) + return -ENOMEM; + data->clks = clks; + + ret = hisi_clk_register_fixed_rate(clks->fixed_rate_clks, + clks->fixed_rate_clks_num, data); + if (ret) + goto err; + + ret = hisi_clk_register_fixed_factor(clks->fixed_factor_clks, + clks->fixed_factor_clks_num, data); + if (ret) + goto err; + + np->data = data; + return 0; + +err: + hisi_clk_free(np, data); + return ret; +} +EXPORT_SYMBOL_GPL(hisi_clk_early_init); + +static int hisi_clk_register(struct device *dev, const struct hisi_clocks *clks, + struct hisi_clock_data *data) +{ + int ret; + + if (clks->mux_clks_num) { + ret = hisi_clk_register_mux(clks->mux_clks, + clks->mux_clks_num, data); + if (ret) + return ret; + } + + if (clks->phase_clks_num) { + ret = hisi_clk_register_phase(dev, clks->phase_clks, + clks->phase_clks_num, data); + if (ret) + return ret; + } + + if (clks->divider_clks_num) { + ret = hisi_clk_register_divider(clks->divider_clks, + clks->divider_clks_num, data); + if (ret) + return ret; + } + + if (clks->gate_clks_num) { + ret = hisi_clk_register_gate(clks->gate_clks, + clks->gate_clks_num, data); + if (ret) + return ret; + } + + if (clks->gate_sep_clks_num) { + hisi_clk_register_gate_sep(clks->gate_sep_clks, + clks->gate_sep_clks_num, data); + } + + if (clks->clk_register_customized && clks->customized_clks_num) { + ret = clks->clk_register_customized(dev, clks->customized_clks, + clks->customized_clks_num, data); + if (ret) + return ret; + } + + return 0; +} + +int hisi_clk_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + const struct hisi_clocks *clks; + struct hisi_clock_data *data; + int ret; + + clks = of_device_get_match_data(dev); + if (!clks) + return -ENOENT; + + if (!np->data) { + ret = hisi_clk_early_init(np, clks); + if (ret) + return ret; + } + + data = np->data; + np->data = NULL; + + if (clks->prologue) { + ret = clks->prologue(dev, data); + if (ret) + goto err; + } + + ret = hisi_clk_register(dev, clks, data); + if (ret) + goto err; + + platform_set_drvdata(pdev, data); + return 0; + +err: + hisi_clk_free(np, data); + return ret; +} +EXPORT_SYMBOL_GPL(hisi_clk_probe); + +void hisi_clk_remove(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct hisi_clock_data *data = platform_get_drvdata(pdev); + + hisi_clk_free(np, data); +} +EXPORT_SYMBOL_GPL(hisi_clk_remove); diff --git a/drivers/clk/hisilicon/clk.h b/drivers/clk/hisilicon/clk.h index 7a9b42e1b027..87b17e9b79a3 100644 --- a/drivers/clk/hisilicon/clk.h +++ b/drivers/clk/hisilicon/clk.h @@ -17,10 +17,12 @@ #include struct platform_device; +struct hisi_clocks; struct hisi_clock_data { - struct clk_onecell_data clk_data; - void __iomem *base; + struct clk_onecell_data clk_data; + void __iomem *base; + const struct hisi_clocks *clks; }; struct hisi_fixed_rate_clock { @@ -103,6 +105,39 @@ struct hisi_gate_clock { const char *alias; }; +struct hisi_clocks { + /* if 0, sum all *_num */ + size_t nr; + + int (*prologue)(struct device *dev, struct hisi_clock_data *data); + + const struct hisi_fixed_rate_clock *fixed_rate_clks; + size_t fixed_rate_clks_num; + + const struct hisi_fixed_factor_clock *fixed_factor_clks; + size_t fixed_factor_clks_num; + + const struct hisi_mux_clock *mux_clks; + size_t mux_clks_num; + + const struct hisi_phase_clock *phase_clks; + size_t phase_clks_num; + + const struct hisi_divider_clock *divider_clks; + size_t divider_clks_num; + + const struct hisi_gate_clock *gate_clks; + size_t gate_clks_num; + + const struct hisi_gate_clock *gate_sep_clks; + size_t gate_sep_clks_num; + + const void *customized_clks; + size_t customized_clks_num; + int (*clk_register_customized)(struct device *dev, const void *clks, + size_t num, struct hisi_clock_data *data); +}; + struct clk *hisi_register_clkgate_sep(struct device *, const char *, const char *, unsigned long, void __iomem *, u8, @@ -113,6 +148,7 @@ struct clk *hi6220_register_clkdiv(struct device *dev, const char *name, struct hisi_clock_data *hisi_clk_alloc(struct platform_device *, int); struct hisi_clock_data *hisi_clk_init(struct device_node *, int); +void hisi_clk_free(struct device_node *np, struct hisi_clock_data *data); int hisi_clk_register_fixed_rate(const struct hisi_fixed_rate_clock *, int, struct hisi_clock_data *); int hisi_clk_register_fixed_factor(const struct hisi_fixed_factor_clock *, @@ -154,4 +190,10 @@ hisi_clk_unregister(mux) hisi_clk_unregister(divider) hisi_clk_unregister(gate) +/* helper functions for platform driver */ + +int hisi_clk_early_init(struct device_node *np, const struct hisi_clocks *clks); +int hisi_clk_probe(struct platform_device *pdev); +void hisi_clk_remove(struct platform_device *pdev); + #endif /* __HISI_CLK_H */ diff --git a/drivers/clk/hisilicon/crg.h b/drivers/clk/hisilicon/crg.h index 803f6ba6d7a2..bd8e76b1f6d7 100644 --- a/drivers/clk/hisilicon/crg.h +++ b/drivers/clk/hisilicon/crg.h @@ -22,4 +22,9 @@ struct hisi_crg_dev { const struct hisi_crg_funcs *funcs; }; +/* helper functions for platform driver */ + +int hisi_crg_probe(struct platform_device *pdev); +void hisi_crg_remove(struct platform_device *pdev); + #endif /* __HISI_CRG_H */ diff --git a/drivers/clk/hisilicon/reset.c b/drivers/clk/hisilicon/reset.c index 93cee17db8b1..c7d4c9ea7183 100644 --- a/drivers/clk/hisilicon/reset.c +++ b/drivers/clk/hisilicon/reset.c @@ -6,11 +6,15 @@ */ #include +#include #include #include #include #include #include + +#include "clk.h" +#include "crg.h" #include "reset.h" #define HISI_RESET_BIT_MASK 0x1f @@ -116,3 +120,41 @@ void hisi_reset_exit(struct hisi_reset_controller *rstc) reset_controller_unregister(&rstc->rcdev); } EXPORT_SYMBOL_GPL(hisi_reset_exit); + +int hisi_crg_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct hisi_crg_dev *crg; + int ret; + + crg = devm_kmalloc(dev, sizeof(*crg), GFP_KERNEL); + if (!crg) + return -ENOMEM; + + ret = hisi_clk_probe(pdev); + if (ret) + return ret; + + crg->rstc = hisi_reset_init(pdev); + if (!crg->rstc) { + ret = -ENOMEM; + goto err; + } + + platform_set_drvdata(pdev, crg); + return 0; + +err: + hisi_clk_remove(pdev); + return ret; +} +EXPORT_SYMBOL_GPL(hisi_crg_probe); + +void hisi_crg_remove(struct platform_device *pdev) +{ + struct hisi_crg_dev *crg = platform_get_drvdata(pdev); + + hisi_reset_exit(crg->rstc); + hisi_clk_remove(pdev); +} +EXPORT_SYMBOL_GPL(hisi_crg_remove); From patchwork Sun Jul 23 16:22:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangfl X-Patchwork-Id: 124521 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1384922vqg; Sun, 23 Jul 2023 11:45:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlHf1cV84HIPR5Ed4rFqpU+7YvQm+fMZk/N8TVxMK+A3ZlAmWTZvrVrskQ2zKveI/vCwo5/q X-Received: by 2002:a17:906:8a64:b0:994:5340:22f4 with SMTP id hy4-20020a1709068a6400b00994534022f4mr8339355ejc.6.1690137907805; Sun, 23 Jul 2023 11:45:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690137907; cv=none; d=google.com; s=arc-20160816; b=HA4OfyxHmZAqtttYZFiUBOUagdHflEjpxXCOJZXXUZI9zdfMMgRYaaqyIVjnyiGF4h IjZlY9UwwU44r8WhqfziwfSWSpyXkBnevUdS4WrN0fgC4R7/cLoKz4y3fbGVwTCE4BxV FWw7mi354fFfqioooJ2Tr5bWFyi/vx9lZE52KVYIrXNS838N49oQ+D3t+TdP9WzIZgnd aoqscX/M8FTSPcmZBZFeYSU3YDkAIsufnO2yFPRYuwlPyHov8YctrMBVFqsPVeEqsGim iyEizISWpkNedeoCpDWewSsyHyQzKMuLcM9OTeejKfpg7ntET48Kp5gCtvFxTaHed/uk huEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/NCW8TcGCgCLz1s5frmIovLcUfj5F4c7j2JB7dPJVhc=; fh=jI3Q7yktBjtl2ksHX/9EGqaANb6lEblpacKg3RfzuA8=; b=pNgwFMieXyjmFk43XPm3/lb576ZzBTrlk/l8KDw3Zxlz66Q3Ch/Cb6xnRvjJKrdTVq V+heKGNOVDQ31/wY4Ru+d1TaTxmzDdol6YOdrcdc60pHsPvtAoEnGgdEth8xvHxDR5kO /eS0ohetnS0AeW3tsSK3O1z1/H9Pt3ejN8lM4LeEGCXEK9NkhL9dKyBRmv7zL7S3tnsX ZGF+WwlhykVngQ7meGrCriBNvQIKGAfKymmERxzLSS8UI4HXXx9a2AfelxnjVf/j2hZs 7b8k+u9zhGpWE6aN4T6UPufeXdAPtTZcK6AGMqdh03vcqohtXgmj//tSEcZs7NxzlfGa MDQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=XA4lMrWx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j8-20020a17090643c800b009929d998ab4si5158458ejn.738.2023.07.23.11.44.44; Sun, 23 Jul 2023 11:45:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=XA4lMrWx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229773AbjGWQY2 (ORCPT + 99 others); Sun, 23 Jul 2023 12:24:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229947AbjGWQYX (ORCPT ); Sun, 23 Jul 2023 12:24:23 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD4FD1BC5; Sun, 23 Jul 2023 09:23:55 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1bba2318546so1927625ad.1; Sun, 23 Jul 2023 09:23:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690129432; x=1690734232; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/NCW8TcGCgCLz1s5frmIovLcUfj5F4c7j2JB7dPJVhc=; b=XA4lMrWxb9O0bXJv9tXIuGqEblnbUW9GvP5gA76thS7UYYTq7LisBR0flM9xpUb4Bi 2M9zCWIYRCtx0hDqrCvqycpgP3BX/VW2bRH8QYShbMfHq6F43EMIgDYTzUKkvnkfEJ3v RMZSaymBrW8tKQGz0bzNv6JHXac7AOkQ3+yEGCSQmI487LrCKE0aVPeSroLG0Locdf2Q 2lB3oavIyr8yFoiZwog2rh9wTaO86xhs+fXhZFBQ5qesknQzFhc+7Pynl2DXyKC3Pub+ TGlVQmmAFM8a0fFxxoL3e9snsMdPq8AK/N6mQ+nbVf4ZYqvtO6X5osXJM6enqvZrtEIn jk0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690129432; x=1690734232; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/NCW8TcGCgCLz1s5frmIovLcUfj5F4c7j2JB7dPJVhc=; b=SVbRRU1tsr3Ymzfecf30QWh5vZaeLGBqOycydKsKFwlPb+3oADb5bJ9KtoKxWBEolf gWZ/k/tUp2q57+biFwizKvKIkjGrisqu9E8zWexhp+IZLCKcF2nBXkBcDOpamDxyEL24 ukyRMpjwdabg8I/Fb0nYdpty9hpfhmCitMVBNzFoXOPXzkiVlXVX/RdT0Wsm+1MroNI/ 4kccJjDKsaC5Qsm9E9yBI+tlGycHQ1zTwFrRRtyZdLbaCyyLfOEWC9xsK7GF4dbMe6iw 9cup4E5P++3yXR2Jw2hYamIQ/P/37Tt0z2ZZfC8TcZ+kg+PC7P9XDDHssvDgp32gHg+w WXuQ== X-Gm-Message-State: ABy/qLZQeE9qylQ9c6HSswbJi0kRPdz/JLM+cVEV53ETSaJNIGmM+xCH jGZttRt/jMD5E8FO8ntbqi6OJ4+YNBs6Mlp/ X-Received: by 2002:a17:903:2288:b0:1b8:a56b:989d with SMTP id b8-20020a170903228800b001b8a56b989dmr10704114plh.6.1690129431691; Sun, 23 Jul 2023 09:23:51 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.245.199]) by smtp.gmail.com with ESMTPSA id u3-20020a17090aae8300b00265a7145fe5sm6883787pjq.41.2023.07.23.09.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 09:23:51 -0700 (PDT) From: David Yang To: linux-clk@vger.kernel.org Cc: David Yang , Michael Turquette , Stephen Boyd , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , linux-kernel@vger.kernel.org Subject: [PATCH v5 02/13] clk: hisilicon: hi3516cv300: Use helper functions Date: Mon, 24 Jul 2023 00:22:27 +0800 Message-Id: <20230723162245.35033-3-mmyangfl@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230723162245.35033-1-mmyangfl@gmail.com> References: <20230723162245.35033-1-mmyangfl@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772238047178368065 X-GMAIL-MSGID: 1772238047178368065 Use common helper functions and register clks with a single of_device_id data. Signed-off-by: David Yang --- drivers/clk/hisilicon/crg-hi3516cv300.c | 171 +++--------------------- 1 file changed, 17 insertions(+), 154 deletions(-) diff --git a/drivers/clk/hisilicon/crg-hi3516cv300.c b/drivers/clk/hisilicon/crg-hi3516cv300.c index fe1bd3e3f988..93db2be9229c 100644 --- a/drivers/clk/hisilicon/crg-hi3516cv300.c +++ b/drivers/clk/hisilicon/crg-hi3516cv300.c @@ -12,7 +12,6 @@ #include #include "clk.h" #include "crg.h" -#include "reset.h" /* hi3516CV300 core CRG */ #define HI3516CV300_INNER_CLK_OFFSET 64 @@ -126,67 +125,14 @@ static const struct hisi_gate_clock hi3516cv300_gate_clks[] = { { HI3516CV300_USB2_PHY_CLK, "clk_usb2_phy", NULL, 0, 0xb8, 7, 0, }, }; -static struct hisi_clock_data *hi3516cv300_clk_register( - struct platform_device *pdev) -{ - struct hisi_clock_data *clk_data; - int ret; - - clk_data = hisi_clk_alloc(pdev, HI3516CV300_CRG_NR_CLKS); - if (!clk_data) - return ERR_PTR(-ENOMEM); - - ret = hisi_clk_register_fixed_rate(hi3516cv300_fixed_rate_clks, - ARRAY_SIZE(hi3516cv300_fixed_rate_clks), clk_data); - if (ret) - return ERR_PTR(ret); - - ret = hisi_clk_register_mux(hi3516cv300_mux_clks, - ARRAY_SIZE(hi3516cv300_mux_clks), clk_data); - if (ret) - goto unregister_fixed_rate; - - ret = hisi_clk_register_gate(hi3516cv300_gate_clks, - ARRAY_SIZE(hi3516cv300_gate_clks), clk_data); - if (ret) - goto unregister_mux; - - ret = of_clk_add_provider(pdev->dev.of_node, - of_clk_src_onecell_get, &clk_data->clk_data); - if (ret) - goto unregister_gate; - - return clk_data; - -unregister_gate: - hisi_clk_unregister_gate(hi3516cv300_gate_clks, - ARRAY_SIZE(hi3516cv300_gate_clks), clk_data); -unregister_mux: - hisi_clk_unregister_mux(hi3516cv300_mux_clks, - ARRAY_SIZE(hi3516cv300_mux_clks), clk_data); -unregister_fixed_rate: - hisi_clk_unregister_fixed_rate(hi3516cv300_fixed_rate_clks, - ARRAY_SIZE(hi3516cv300_fixed_rate_clks), clk_data); - return ERR_PTR(ret); -} - -static void hi3516cv300_clk_unregister(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg = platform_get_drvdata(pdev); - - of_clk_del_provider(pdev->dev.of_node); - - hisi_clk_unregister_gate(hi3516cv300_gate_clks, - ARRAY_SIZE(hi3516cv300_gate_clks), crg->clk_data); - hisi_clk_unregister_mux(hi3516cv300_mux_clks, - ARRAY_SIZE(hi3516cv300_mux_clks), crg->clk_data); - hisi_clk_unregister_fixed_rate(hi3516cv300_fixed_rate_clks, - ARRAY_SIZE(hi3516cv300_fixed_rate_clks), crg->clk_data); -} - -static const struct hisi_crg_funcs hi3516cv300_crg_funcs = { - .register_clks = hi3516cv300_clk_register, - .unregister_clks = hi3516cv300_clk_unregister, +static const struct hisi_clocks hi3516cv300_crg_clks = { + .nr = HI3516CV300_CRG_NR_CLKS, + .fixed_rate_clks = hi3516cv300_fixed_rate_clks, + .fixed_rate_clks_num = ARRAY_SIZE(hi3516cv300_fixed_rate_clks), + .mux_clks = hi3516cv300_mux_clks, + .mux_clks_num = ARRAY_SIZE(hi3516cv300_mux_clks), + .gate_clks = hi3516cv300_gate_clks, + .gate_clks_num = ARRAY_SIZE(hi3516cv300_gate_clks), }; /* hi3516CV300 sysctrl CRG */ @@ -200,118 +146,35 @@ static const struct hisi_mux_clock hi3516cv300_sysctrl_mux_clks[] = { CLK_SET_RATE_PARENT, 0x0, 23, 1, 0, wdt_mux_table, }, }; -static struct hisi_clock_data *hi3516cv300_sysctrl_clk_register( - struct platform_device *pdev) -{ - struct hisi_clock_data *clk_data; - int ret; - - clk_data = hisi_clk_alloc(pdev, HI3516CV300_SYSCTRL_NR_CLKS); - if (!clk_data) - return ERR_PTR(-ENOMEM); - - ret = hisi_clk_register_mux(hi3516cv300_sysctrl_mux_clks, - ARRAY_SIZE(hi3516cv300_sysctrl_mux_clks), clk_data); - if (ret) - return ERR_PTR(ret); - - - ret = of_clk_add_provider(pdev->dev.of_node, - of_clk_src_onecell_get, &clk_data->clk_data); - if (ret) - goto unregister_mux; - - return clk_data; - -unregister_mux: - hisi_clk_unregister_mux(hi3516cv300_sysctrl_mux_clks, - ARRAY_SIZE(hi3516cv300_sysctrl_mux_clks), clk_data); - return ERR_PTR(ret); -} - -static void hi3516cv300_sysctrl_clk_unregister(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg = platform_get_drvdata(pdev); - - of_clk_del_provider(pdev->dev.of_node); - - hisi_clk_unregister_mux(hi3516cv300_sysctrl_mux_clks, - ARRAY_SIZE(hi3516cv300_sysctrl_mux_clks), - crg->clk_data); -} - -static const struct hisi_crg_funcs hi3516cv300_sysctrl_funcs = { - .register_clks = hi3516cv300_sysctrl_clk_register, - .unregister_clks = hi3516cv300_sysctrl_clk_unregister, +static const struct hisi_clocks hi3516cv300_sysctrl_clks = { + .nr = HI3516CV300_SYSCTRL_NR_CLKS, + .mux_clks = hi3516cv300_sysctrl_mux_clks, + .mux_clks_num = ARRAY_SIZE(hi3516cv300_sysctrl_mux_clks), }; static const struct of_device_id hi3516cv300_crg_match_table[] = { { .compatible = "hisilicon,hi3516cv300-crg", - .data = &hi3516cv300_crg_funcs + .data = &hi3516cv300_crg_clks, }, { .compatible = "hisilicon,hi3516cv300-sysctrl", - .data = &hi3516cv300_sysctrl_funcs + .data = &hi3516cv300_sysctrl_clks, }, { } }; MODULE_DEVICE_TABLE(of, hi3516cv300_crg_match_table); -static int hi3516cv300_crg_probe(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg; - - crg = devm_kmalloc(&pdev->dev, sizeof(*crg), GFP_KERNEL); - if (!crg) - return -ENOMEM; - - crg->funcs = of_device_get_match_data(&pdev->dev); - if (!crg->funcs) - return -ENOENT; - - crg->rstc = hisi_reset_init(pdev); - if (!crg->rstc) - return -ENOMEM; - - crg->clk_data = crg->funcs->register_clks(pdev); - if (IS_ERR(crg->clk_data)) { - hisi_reset_exit(crg->rstc); - return PTR_ERR(crg->clk_data); - } - - platform_set_drvdata(pdev, crg); - return 0; -} - -static void hi3516cv300_crg_remove(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg = platform_get_drvdata(pdev); - - hisi_reset_exit(crg->rstc); - crg->funcs->unregister_clks(pdev); -} - static struct platform_driver hi3516cv300_crg_driver = { - .probe = hi3516cv300_crg_probe, - .remove_new = hi3516cv300_crg_remove, + .probe = hisi_crg_probe, + .remove_new = hisi_crg_remove, .driver = { .name = "hi3516cv300-crg", .of_match_table = hi3516cv300_crg_match_table, }, }; -static int __init hi3516cv300_crg_init(void) -{ - return platform_driver_register(&hi3516cv300_crg_driver); -} -core_initcall(hi3516cv300_crg_init); - -static void __exit hi3516cv300_crg_exit(void) -{ - platform_driver_unregister(&hi3516cv300_crg_driver); -} -module_exit(hi3516cv300_crg_exit); +module_platform_driver(hi3516cv300_crg_driver); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("HiSilicon Hi3516CV300 CRG Driver"); From patchwork Sun Jul 23 16:22:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangfl X-Patchwork-Id: 124524 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1385484vqg; Sun, 23 Jul 2023 11:47:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlFpYt0H5NdQK6k1hK09kY6qPo7nP5CNnx/0QNGWUHCeWpEZ2mzISLL21/Wd99WN5tB+6oY1 X-Received: by 2002:a17:907:75d5:b0:982:1936:ad27 with SMTP id jl21-20020a17090775d500b009821936ad27mr7413158ejc.11.1690138030243; Sun, 23 Jul 2023 11:47:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690138030; cv=none; d=google.com; s=arc-20160816; b=oWc809KLomZSKDgsQAUBkE9Bdb9mMhasVHoGYro85Jp+E8WuCyCz9sefzbAk+bcg6+ Sklp6D2gSUx0y8BJ4iCixpCXe/ONbOF1QHcTHioZW0pUkIRrk1+MjN6OEtyHDjyFPEdl lvTBY6LE6ahWDEnhu+nuQvfMf+PgDubswObWGX3UpnIxczmVfJeMemI1m1/A8oiOnB+H 3nGVTdtBgi2JlWpBJ5Zp7x95ExY8coQbeundLGfpkPklReOaq+0GV9PUgfsX3zu4YCYZ 0TRkPdWgzZ2u4xymQcP6cuAYNB1Ux4SFd81YHkwdPZocffFU29VVklRiqz4c1KANGH2M t3rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JrFfLWtuEeyZX21Fz2US96pmiJe/UZVkhX3z1c8xfNU=; fh=jI3Q7yktBjtl2ksHX/9EGqaANb6lEblpacKg3RfzuA8=; b=LoG92Nsm7vvR6KqyJZNgLs9IzCY5/q0zUVCegUc/ko7bYPRY7y6FfSmbiWpn7bcC5N CQWJ5/DrEj4jamKUOCzCrfD+NYISL1IUpFF1U2NzQQPZz1eFf0DT0GJeAHYUlqf/fvwn azKsH61+HjSaZ5u7f2ujNbI5ztNwM2yA7cbO3AfHoiuwpy0N6lrmI7K4KURGNZgJbOq/ xnGgq8eNFzhLSrorsnN/CRWibseONuKPAKNA4tzzMT3+wKbi9b/+ddeV1cPlFYsW5Nij N5xAfXbgUSpP57hcpBG598d4KM7oh024kAGEmtBjXSnl/cO0SByaMIxNK2KaOkF539GX fM7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Z1OfuxuL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k10-20020a170906578a00b00982bd2c070fsi5226474ejq.469.2023.07.23.11.46.47; Sun, 23 Jul 2023 11:47:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Z1OfuxuL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229702AbjGWQYi (ORCPT + 99 others); Sun, 23 Jul 2023 12:24:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229537AbjGWQYh (ORCPT ); Sun, 23 Jul 2023 12:24:37 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D91C120; Sun, 23 Jul 2023 09:24:07 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-55b0e7efb1cso1862845a12.1; Sun, 23 Jul 2023 09:24:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690129445; x=1690734245; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JrFfLWtuEeyZX21Fz2US96pmiJe/UZVkhX3z1c8xfNU=; b=Z1OfuxuLPdQ9VJrdKZwX0n4i3ztQZtvR13hI592VBHLywQtUdC1sCe728jOkJY092z eRWRF9n1Ij0rQuVO/pqzl+b/o6GWucq4xqntJGZfKK+T/BJwbbAjyp9qLtSfOiOmJ+As Ls0SWNQF4tS26pDAHe4R9r0NLlpmkwa8HN5v5e7zDripX1lnOxMhbKGEoB7s79JvbH7Z ekZqJBOAQVkNteF4RJNo0IY33EAtHqETLfFJXZmirpSuRoxSyQj9KTqQRjepIKxsZwrU VgIPfW3kc0JR/+Upvrx/VeugcRJllOXDTlX8GylN2gatenP1qsiFguPX83t6UPF7pQdz ydeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690129445; x=1690734245; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JrFfLWtuEeyZX21Fz2US96pmiJe/UZVkhX3z1c8xfNU=; b=fsM/facodGmg+o/CJc+EwuXOqBp30nd/NbvHMdUWW7tQAsG1mES8zsAaWONx+dVPXZ knQ/eOM7f7mkaxrWMlSqKEfaGNqslD0rRY/tORi0VZue/kpwdqKwHKVc92WxGWt1ys43 65EtD+Jcbq27UZDLkedIFL6bZ4l2OhSjvtypUq8h1n1aCZd5KFNugQx7lrBiJd1IbCyP 2xn16cN8iuoaoyqw72Jey+5RIN2HtzGu0gUBI7xu0SdUjHrS0LJimgJ/snTq3Q35jdwr kqunueWfFVFgTOm7QkDAyo9SjYIxJTJ4v/SsZxqR4weHRNMQNGNc2xUz3qa06aGM0w8k uqrQ== X-Gm-Message-State: ABy/qLaD/raHBME1NOiTujgH7etSWpy7kSqHQK+RdZAr18CRih8LX9zf Q3o1Idm+7v2DtAzbCm6bMCc3zl2hOHB2EbOB X-Received: by 2002:a17:90a:d182:b0:262:f06a:13e0 with SMTP id fu2-20020a17090ad18200b00262f06a13e0mr6512882pjb.5.1690129445024; Sun, 23 Jul 2023 09:24:05 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.245.199]) by smtp.gmail.com with ESMTPSA id u3-20020a17090aae8300b00265a7145fe5sm6883787pjq.41.2023.07.23.09.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 09:24:04 -0700 (PDT) From: David Yang To: linux-clk@vger.kernel.org Cc: David Yang , Michael Turquette , Stephen Boyd , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , linux-kernel@vger.kernel.org Subject: [PATCH v5 03/13] clk: hisilicon: hi3798cv200: Use helper functions Date: Mon, 24 Jul 2023 00:22:28 +0800 Message-Id: <20230723162245.35033-4-mmyangfl@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230723162245.35033-1-mmyangfl@gmail.com> References: <20230723162245.35033-1-mmyangfl@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772238175301586719 X-GMAIL-MSGID: 1772238175301586719 Use common helper functions and register clks with a single of_device_id data. Signed-off-by: David Yang --- drivers/clk/hisilicon/crg-hi3798cv200.c | 196 +++--------------------- 1 file changed, 20 insertions(+), 176 deletions(-) diff --git a/drivers/clk/hisilicon/crg-hi3798cv200.c b/drivers/clk/hisilicon/crg-hi3798cv200.c index a0b16be1e25d..c2079bf293b2 100644 --- a/drivers/clk/hisilicon/crg-hi3798cv200.c +++ b/drivers/clk/hisilicon/crg-hi3798cv200.c @@ -12,7 +12,6 @@ #include #include "clk.h" #include "crg.h" -#include "reset.h" /* hi3798CV200 core CRG */ #define HI3798CV200_INNER_CLK_OFFSET 64 @@ -41,6 +40,7 @@ #define HI3798CV200_CRG_NR_CLKS 128 +#define HI3798CV200_SYSCTRL_NR_CLKS 16 static const struct hisi_fixed_rate_clock hi3798cv200_fixed_rate_clks[] = { { HISTB_OSC_CLK, "clk_osc", NULL, 0, 24000000, }, { HISTB_APB_CLK, "clk_apb", NULL, 0, 100000000, }, @@ -193,90 +193,18 @@ static const struct hisi_gate_clock hi3798cv200_gate_clks[] = { CLK_SET_RATE_PARENT, 0xb0, 18, 0 }, }; -static struct hisi_clock_data *hi3798cv200_clk_register( - struct platform_device *pdev) -{ - struct hisi_clock_data *clk_data; - int ret; - - clk_data = hisi_clk_alloc(pdev, HI3798CV200_CRG_NR_CLKS); - if (!clk_data) - return ERR_PTR(-ENOMEM); - - /* hisi_phase_clock is resource managed */ - ret = hisi_clk_register_phase(&pdev->dev, - hi3798cv200_phase_clks, - ARRAY_SIZE(hi3798cv200_phase_clks), - clk_data); - if (ret) - return ERR_PTR(ret); - - ret = hisi_clk_register_fixed_rate(hi3798cv200_fixed_rate_clks, - ARRAY_SIZE(hi3798cv200_fixed_rate_clks), - clk_data); - if (ret) - return ERR_PTR(ret); - - ret = hisi_clk_register_mux(hi3798cv200_mux_clks, - ARRAY_SIZE(hi3798cv200_mux_clks), - clk_data); - if (ret) - goto unregister_fixed_rate; - - ret = hisi_clk_register_gate(hi3798cv200_gate_clks, - ARRAY_SIZE(hi3798cv200_gate_clks), - clk_data); - if (ret) - goto unregister_mux; - - ret = of_clk_add_provider(pdev->dev.of_node, - of_clk_src_onecell_get, &clk_data->clk_data); - if (ret) - goto unregister_gate; - - return clk_data; - -unregister_gate: - hisi_clk_unregister_gate(hi3798cv200_gate_clks, - ARRAY_SIZE(hi3798cv200_gate_clks), - clk_data); -unregister_mux: - hisi_clk_unregister_mux(hi3798cv200_mux_clks, - ARRAY_SIZE(hi3798cv200_mux_clks), - clk_data); -unregister_fixed_rate: - hisi_clk_unregister_fixed_rate(hi3798cv200_fixed_rate_clks, - ARRAY_SIZE(hi3798cv200_fixed_rate_clks), - clk_data); - return ERR_PTR(ret); -} - -static void hi3798cv200_clk_unregister(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg = platform_get_drvdata(pdev); - - of_clk_del_provider(pdev->dev.of_node); - - hisi_clk_unregister_gate(hi3798cv200_gate_clks, - ARRAY_SIZE(hi3798cv200_gate_clks), - crg->clk_data); - hisi_clk_unregister_mux(hi3798cv200_mux_clks, - ARRAY_SIZE(hi3798cv200_mux_clks), - crg->clk_data); - hisi_clk_unregister_fixed_rate(hi3798cv200_fixed_rate_clks, - ARRAY_SIZE(hi3798cv200_fixed_rate_clks), - crg->clk_data); -} - -static const struct hisi_crg_funcs hi3798cv200_crg_funcs = { - .register_clks = hi3798cv200_clk_register, - .unregister_clks = hi3798cv200_clk_unregister, +static const struct hisi_clocks hi3798cv200_crg_clks = { + .nr = HI3798CV200_CRG_NR_CLKS, + .fixed_rate_clks = hi3798cv200_fixed_rate_clks, + .fixed_rate_clks_num = ARRAY_SIZE(hi3798cv200_fixed_rate_clks), + .mux_clks = hi3798cv200_mux_clks, + .mux_clks_num = ARRAY_SIZE(hi3798cv200_mux_clks), + .phase_clks = hi3798cv200_phase_clks, + .phase_clks_num = ARRAY_SIZE(hi3798cv200_phase_clks), + .gate_clks = hi3798cv200_gate_clks, + .gate_clks_num = ARRAY_SIZE(hi3798cv200_gate_clks), }; -/* hi3798CV200 sysctrl CRG */ - -#define HI3798CV200_SYSCTRL_NR_CLKS 16 - static const struct hisi_gate_clock hi3798cv200_sysctrl_gate_clks[] = { { HISTB_IR_CLK, "clk_ir", "24m", CLK_SET_RATE_PARENT, 0x48, 4, 0, }, @@ -286,115 +214,31 @@ static const struct hisi_gate_clock hi3798cv200_sysctrl_gate_clks[] = { CLK_SET_RATE_PARENT, 0x48, 10, 0, }, }; -static struct hisi_clock_data *hi3798cv200_sysctrl_clk_register( - struct platform_device *pdev) -{ - struct hisi_clock_data *clk_data; - int ret; - - clk_data = hisi_clk_alloc(pdev, HI3798CV200_SYSCTRL_NR_CLKS); - if (!clk_data) - return ERR_PTR(-ENOMEM); - - ret = hisi_clk_register_gate(hi3798cv200_sysctrl_gate_clks, - ARRAY_SIZE(hi3798cv200_sysctrl_gate_clks), - clk_data); - if (ret) - return ERR_PTR(ret); - - ret = of_clk_add_provider(pdev->dev.of_node, - of_clk_src_onecell_get, &clk_data->clk_data); - if (ret) - goto unregister_gate; - - return clk_data; - -unregister_gate: - hisi_clk_unregister_gate(hi3798cv200_sysctrl_gate_clks, - ARRAY_SIZE(hi3798cv200_sysctrl_gate_clks), - clk_data); - return ERR_PTR(ret); -} - -static void hi3798cv200_sysctrl_clk_unregister(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg = platform_get_drvdata(pdev); - - of_clk_del_provider(pdev->dev.of_node); - - hisi_clk_unregister_gate(hi3798cv200_sysctrl_gate_clks, - ARRAY_SIZE(hi3798cv200_sysctrl_gate_clks), - crg->clk_data); -} - -static const struct hisi_crg_funcs hi3798cv200_sysctrl_funcs = { - .register_clks = hi3798cv200_sysctrl_clk_register, - .unregister_clks = hi3798cv200_sysctrl_clk_unregister, +static const struct hisi_clocks hi3798cv200_sysctrl_clks = { + .nr = HI3798CV200_SYSCTRL_NR_CLKS, + .gate_clks = hi3798cv200_sysctrl_gate_clks, + .gate_clks_num = ARRAY_SIZE(hi3798cv200_sysctrl_gate_clks), }; static const struct of_device_id hi3798cv200_crg_match_table[] = { { .compatible = "hisilicon,hi3798cv200-crg", - .data = &hi3798cv200_crg_funcs }, + .data = &hi3798cv200_crg_clks }, { .compatible = "hisilicon,hi3798cv200-sysctrl", - .data = &hi3798cv200_sysctrl_funcs }, + .data = &hi3798cv200_sysctrl_clks }, { } }; MODULE_DEVICE_TABLE(of, hi3798cv200_crg_match_table); -static int hi3798cv200_crg_probe(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg; - - crg = devm_kmalloc(&pdev->dev, sizeof(*crg), GFP_KERNEL); - if (!crg) - return -ENOMEM; - - crg->funcs = of_device_get_match_data(&pdev->dev); - if (!crg->funcs) - return -ENOENT; - - crg->rstc = hisi_reset_init(pdev); - if (!crg->rstc) - return -ENOMEM; - - crg->clk_data = crg->funcs->register_clks(pdev); - if (IS_ERR(crg->clk_data)) { - hisi_reset_exit(crg->rstc); - return PTR_ERR(crg->clk_data); - } - - platform_set_drvdata(pdev, crg); - return 0; -} - -static void hi3798cv200_crg_remove(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg = platform_get_drvdata(pdev); - - hisi_reset_exit(crg->rstc); - crg->funcs->unregister_clks(pdev); -} - static struct platform_driver hi3798cv200_crg_driver = { - .probe = hi3798cv200_crg_probe, - .remove_new = hi3798cv200_crg_remove, + .probe = hisi_crg_probe, + .remove_new = hisi_crg_remove, .driver = { .name = "hi3798cv200-crg", .of_match_table = hi3798cv200_crg_match_table, }, }; -static int __init hi3798cv200_crg_init(void) -{ - return platform_driver_register(&hi3798cv200_crg_driver); -} -core_initcall(hi3798cv200_crg_init); - -static void __exit hi3798cv200_crg_exit(void) -{ - platform_driver_unregister(&hi3798cv200_crg_driver); -} -module_exit(hi3798cv200_crg_exit); +module_platform_driver(hi3798cv200_crg_driver); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("HiSilicon Hi3798CV200 CRG Driver"); From patchwork Sun Jul 23 16:22:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangfl X-Patchwork-Id: 124529 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1388773vqg; Sun, 23 Jul 2023 11:59:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlG42ATjgsX/vRaGVd036FsqtA8fvT48ZGgFRu94VqVcNZZa+U6wDOe2TqcZNT2TWJ9sO0gh X-Received: by 2002:a05:6402:2da:b0:51d:a488:3b3d with SMTP id b26-20020a05640202da00b0051da4883b3dmr6057296edx.35.1690138770986; Sun, 23 Jul 2023 11:59:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690138770; cv=none; d=google.com; s=arc-20160816; b=SnsJCjEeXgYKeSDHL0kLrWg6UgucOVnGNWo8HkIsx+JW20oDOiKPQrGPsO0Rf4+fNS EZzcnkVUQuZfHHIBQ+5J9AoLEyKLLvCeq+ETFcm56y3sXMxX3zJTF0RIGSHY95goDHn8 aeQmLnTAHEbe6KbZOawqb76qa8+blqx4ZhA8dfMabFj1wObRQ7sVI7fp9XMCDCO8qt41 WW+/LD8/FypRy0p3gSRWY74VG3QWP/RlawufUt448Icx6KzgiuW64IPB0fmZnwB7j6vY ZIiTxsBIHAT+nI1o/Ogn3EfHu5y1V0yQTT+D3lGRxKpGcYDWCfsL45rT6FJoEnyZXWzK A/pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wc6dwH/HvZi0vPM1tFTS6dfKlRz8fg7TW4Ttiul7pXo=; fh=6op8AbJPoSQyJcsI0L5qUJDM8pym4PtkpWqFZ6dkle0=; b=0LSHFBVLVMSgteFJLx2nWgL2/3WJaO2FV1pqhPzQD9P2qG8Mys4Vo/P99Yk624ySoN mjWgt+0vIWo7nRkuftfQ+5qQ2qVOF72y+DgGIdmDxIcR23tpi+mwfrZla9I84HyMYd7e EVQ5wo4iZAUqnlhWis5MHsYx8IQgePf3I8/FYcJWWTp9V+29XkKtP0pqNVFgQAiOCITG i3oqI/0JBS9LI78hASYTaOa9aolcESlzwDJdJ8E2i322Bd2vyob4AaYgXsQnljF45G5k /DABOF56AvwQU/Jhl7pLzV00zgYf1dSiGRKWgCHZr7eUawEtk+ROy3thORi02qhFWSNV Q10Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=XfrIQYeO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u3-20020a05640207c300b005222bc367e1si520643edy.98.2023.07.23.11.59.07; Sun, 23 Jul 2023 11:59:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=XfrIQYeO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230032AbjGWQYz (ORCPT + 99 others); Sun, 23 Jul 2023 12:24:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229537AbjGWQYv (ORCPT ); Sun, 23 Jul 2023 12:24:51 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60B461707; Sun, 23 Jul 2023 09:24:21 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-55b66ca1c80so1870721a12.0; Sun, 23 Jul 2023 09:24:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690129456; x=1690734256; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wc6dwH/HvZi0vPM1tFTS6dfKlRz8fg7TW4Ttiul7pXo=; b=XfrIQYeOXg8UEZ4jO37YBLFnyAes+NpBWG72OQ4GCw0uta+4pUDiVT4xVDPw6yiu5U mVva2dy+Tev/KQBEJ8DB6mNyulxASK8JUoYxMmPHEldPF/G98IWFT0WL5dlMYcSaZs2v z58DIGbEddod5XxS29RKnzrOJyFiTURq20CB4K4gohQo3ZWlVkb7Tt3z/mxbgA34VSIg AFW2mUu6dqs2MF9wme9sJOZWMgDLecAGEbnldYczxP8iRCwa1swHM3hmrS4V0kxoJ7yc eEXQC9XqYqhJV8jeCaM9LPoLNdHLMszYAjwWczfK/PhrGw0zWoaK395kMedHmSqPYLxf Jb+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690129456; x=1690734256; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wc6dwH/HvZi0vPM1tFTS6dfKlRz8fg7TW4Ttiul7pXo=; b=H0r9yX2aTnXTWxdq2t+GPsVtSjXu/aTI7NAVZg7XAEDgH/6eSv/ArGL+HYjX8+kd9s nP6M9E/d5lVpqyVgXEH4588hQ9ArQDSD5Z4rf1JYzmgUi5vbHmPwt9YhaIImiJVPdza8 tz24O4Hs4crtzkWJxT1MUyIaZgUnTWeSurFfSptfkWZeLmCLpVmBoludXylHLKkVPZf0 P+2LVDXrmZRHJocUONcXI6L8rOfyOD5s6F/ifCAsuON5NgoL5V/9o6lLWIJomcSg5f+G P+qw/4QHcb94FdkcTXk7Pinma95ytZv6NkD6OtDX0fFOsJ4/mrvq0H2b26YuZxg5cn52 lzmQ== X-Gm-Message-State: ABy/qLaSn9VfTCxJXYMfX3hoNV1Tynqo8Wd/C4jMpDcUMsFq8ftEslOt A3UjH22dSrH3iI2cdnb6Yq+hHoE0rgGb2Hth X-Received: by 2002:a17:90a:fd02:b0:268:1b60:5031 with SMTP id cv2-20020a17090afd0200b002681b605031mr559501pjb.12.1690129455746; Sun, 23 Jul 2023 09:24:15 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.245.199]) by smtp.gmail.com with ESMTPSA id u3-20020a17090aae8300b00265a7145fe5sm6883787pjq.41.2023.07.23.09.24.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 09:24:15 -0700 (PDT) From: David Yang To: linux-clk@vger.kernel.org Cc: David Yang , Michael Turquette , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH v5 04/13] clk: hisilicon: Remove hisi_crg_funcs Date: Mon, 24 Jul 2023 00:22:29 +0800 Message-Id: <20230723162245.35033-5-mmyangfl@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230723162245.35033-1-mmyangfl@gmail.com> References: <20230723162245.35033-1-mmyangfl@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772238951899035271 X-GMAIL-MSGID: 1772238951899035271 After refactor, no one use hisi_crg_funcs. Signed-off-by: David Yang --- drivers/clk/hisilicon/crg.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/clk/hisilicon/crg.h b/drivers/clk/hisilicon/crg.h index bd8e76b1f6d7..db2324309d41 100644 --- a/drivers/clk/hisilicon/crg.h +++ b/drivers/clk/hisilicon/crg.h @@ -11,15 +11,9 @@ struct hisi_clock_data; struct hisi_reset_controller; -struct hisi_crg_funcs { - struct hisi_clock_data* (*register_clks)(struct platform_device *pdev); - void (*unregister_clks)(struct platform_device *pdev); -}; - struct hisi_crg_dev { struct hisi_clock_data *clk_data; struct hisi_reset_controller *rstc; - const struct hisi_crg_funcs *funcs; }; /* helper functions for platform driver */ From patchwork Sun Jul 23 16:22:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangfl X-Patchwork-Id: 124523 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1385257vqg; Sun, 23 Jul 2023 11:46:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlFXyjyljsNyAjvv+C84JJsvOmDaZMFkdxRpvg51cy+EpM7/O4iXWMnT/Y9YBzhjloe5+pUU X-Received: by 2002:a17:906:10cf:b0:99b:4210:cc79 with SMTP id v15-20020a17090610cf00b0099b4210cc79mr8434373ejv.22.1690137983277; Sun, 23 Jul 2023 11:46:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690137983; cv=none; d=google.com; s=arc-20160816; b=lyITxQH/C184BF8DJwS+PP94rBGMu5eWdsJhqWovNQBMnslIZ+/9nPBWfqqtx0C0TQ KYOU7u/zEGROSjhUKJ780hd05Bk7RURrL7vkU2K7TS5G/DP8dJZIYiSVCg/LiBPSFNk0 K3P6vz4i9eG7gRwtI/Luvh7iGbUEJLiqQjv0eyApPQSpSmwcEkpUPQZj3DeBoO/d9JFz bfrKRORXlEiGQ1Ch+551WmX29/Q1XlyXYsOfdKxBA1VCX6UAVMN6UJBH35RWyYzpwb6n p7nFCtwShXtyRJ+Y18Koh2ctXOKpYLaoEEaUi882xAbSD9tANeGmwFDmKht+g5LJOafN l72w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0MuOuodU2lHTtwqoFZB85wA0J3lkhz0ajlvILK6N/z0=; fh=jI3Q7yktBjtl2ksHX/9EGqaANb6lEblpacKg3RfzuA8=; b=gxKfYI3Xy4ANjazkc+tP5fzoRiZOpmRGA6kCFA3eRwFKtogDRtseQQaa0M3hFs1Jzt Bz7f/wYyt/jaQyju2GwilYwuu52gbRs+ErofwCeaxlUdn5yDPwrNZ6InewcDEOiv3siD ytyRsIGsyJNQ2ieq30ssPkROBtnnRw8RhF/Hvz7sLL/vKqEdfNsFcIdadqbfiIfn4oo2 OXnRR324WyKzmTeDvGE5H1h0mHHOVd+zhn0gLiBvaAt3ggYGS4lkdAJVqOUbdqbFDisB F2dbcLrqNRBPxj0Lg4oWmo+PZz2XZpisAPwPiW6aC9ai41KbM4Oc/f2mPOTLiaUw+Nff Gwvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Mj9QrBt0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i10-20020a1709061cca00b00992f30b2983si4948006ejh.849.2023.07.23.11.45.59; Sun, 23 Jul 2023 11:46:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Mj9QrBt0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230027AbjGWQZL (ORCPT + 99 others); Sun, 23 Jul 2023 12:25:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230092AbjGWQZF (ORCPT ); Sun, 23 Jul 2023 12:25:05 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 728BD10CE; Sun, 23 Jul 2023 09:24:38 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-66f5faba829so2279865b3a.3; Sun, 23 Jul 2023 09:24:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690129469; x=1690734269; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0MuOuodU2lHTtwqoFZB85wA0J3lkhz0ajlvILK6N/z0=; b=Mj9QrBt0qWj/nc2LQ2BvIG+75xnYIQ6WMkQYJ9oW7LBVEGqml8ZQ3t80jf59Zp46Zp 02aCJ0Hj9KbRqL4YKbyQGiKk9yhpDL7ImRM2VWrhU8KQAfQkMnL06u2iZKbeEFAAvhjh Vo+dNDXntH10fm1YFY+3K1mXXW/GS4+f2VRFEJUBTClYJ4zirSAP0/74bjHilBvIWKOU wqanMWe1r0g3yMJUNa0A9qZfGloiSb5Z/jzlDMFJDLcMPj2fYakMIp4QxuhcX2/sqcvM r7wWH+YYTO+waGbBDoMrzN39o26CHK2GY7YergchcCm3ubefsB5S3z7PvjThOu8KO54T PFAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690129469; x=1690734269; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0MuOuodU2lHTtwqoFZB85wA0J3lkhz0ajlvILK6N/z0=; b=hMvECCvVF/Odxro+8k+7pzZ7fWLxIxICc22wR+5E4k7AqqWxtum4wry7LFGUyXDWEx PooehofQdfGrTA0StBTThYZhQ/dA/V1oNNjXKtJTVh2nBbzjuDTnYWL810quNYMmwK18 AcT5Uem3Qwmr4rHG1S2P6yNM/AI2f6WhYkzYcvxFF5fSn4KDxGUFpSqKMnAa5KS+4bPG XtX0QeLuFDNeZvayj1UyJ1mFUNFL8FtNiFVZjFyA/tKxjeyBLr2f+xvkL91zHeII8YGO 8RFbbMP2AwK5G7FaRnA7GER/JtNjrjXWLNp7t9JK1DoGj9Snj6czvGoQnRP/2lvefUfU VhsQ== X-Gm-Message-State: ABy/qLaYZG70BAaAm4+ocDuFB8ojxrm26S5Avd4chRyfsvN23/vJv5Xc lc0ItX1kSvTLmiuaPamJIfmX6Kgz0TJ7TRV7 X-Received: by 2002:a17:90a:d3c2:b0:267:f5d1:1dd3 with SMTP id d2-20020a17090ad3c200b00267f5d11dd3mr4564763pjw.11.1690129469017; Sun, 23 Jul 2023 09:24:29 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.245.199]) by smtp.gmail.com with ESMTPSA id u3-20020a17090aae8300b00265a7145fe5sm6883787pjq.41.2023.07.23.09.24.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 09:24:28 -0700 (PDT) From: David Yang To: linux-clk@vger.kernel.org Cc: David Yang , Michael Turquette , Stephen Boyd , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , linux-kernel@vger.kernel.org Subject: [PATCH v5 05/13] clk: hisilicon: hi3519: Use helper functions Date: Mon, 24 Jul 2023 00:22:30 +0800 Message-Id: <20230723162245.35033-6-mmyangfl@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230723162245.35033-1-mmyangfl@gmail.com> References: <20230723162245.35033-1-mmyangfl@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772238125970516442 X-GMAIL-MSGID: 1772238125970516442 Use common helper functions and register clks with a single of_device_id data. Signed-off-by: David Yang --- drivers/clk/hisilicon/clk-hi3519.c | 127 ++++------------------------- 1 file changed, 15 insertions(+), 112 deletions(-) diff --git a/drivers/clk/hisilicon/clk-hi3519.c b/drivers/clk/hisilicon/clk-hi3519.c index b871872d9960..cb541de752da 100644 --- a/drivers/clk/hisilicon/clk-hi3519.c +++ b/drivers/clk/hisilicon/clk-hi3519.c @@ -10,7 +10,7 @@ #include #include #include "clk.h" -#include "reset.h" +#include "crg.h" #define HI3519_INNER_CLK_OFFSET 64 #define HI3519_FIXED_24M 65 @@ -73,130 +73,33 @@ static const struct hisi_gate_clock hi3519_gate_clks[] = { CLK_SET_RATE_PARENT, 0xe4, 18, 0, }, }; -static struct hisi_clock_data *hi3519_clk_register(struct platform_device *pdev) -{ - struct hisi_clock_data *clk_data; - int ret; - - clk_data = hisi_clk_alloc(pdev, HI3519_NR_CLKS); - if (!clk_data) - return ERR_PTR(-ENOMEM); - - ret = hisi_clk_register_fixed_rate(hi3519_fixed_rate_clks, - ARRAY_SIZE(hi3519_fixed_rate_clks), - clk_data); - if (ret) - return ERR_PTR(ret); - - ret = hisi_clk_register_mux(hi3519_mux_clks, - ARRAY_SIZE(hi3519_mux_clks), - clk_data); - if (ret) - goto unregister_fixed_rate; - - ret = hisi_clk_register_gate(hi3519_gate_clks, - ARRAY_SIZE(hi3519_gate_clks), - clk_data); - if (ret) - goto unregister_mux; - - ret = of_clk_add_provider(pdev->dev.of_node, - of_clk_src_onecell_get, &clk_data->clk_data); - if (ret) - goto unregister_gate; - - return clk_data; - -unregister_fixed_rate: - hisi_clk_unregister_fixed_rate(hi3519_fixed_rate_clks, - ARRAY_SIZE(hi3519_fixed_rate_clks), - clk_data); - -unregister_mux: - hisi_clk_unregister_mux(hi3519_mux_clks, - ARRAY_SIZE(hi3519_mux_clks), - clk_data); -unregister_gate: - hisi_clk_unregister_gate(hi3519_gate_clks, - ARRAY_SIZE(hi3519_gate_clks), - clk_data); - return ERR_PTR(ret); -} - -static void hi3519_clk_unregister(struct platform_device *pdev) -{ - struct hi3519_crg_data *crg = platform_get_drvdata(pdev); - - of_clk_del_provider(pdev->dev.of_node); - - hisi_clk_unregister_gate(hi3519_gate_clks, - ARRAY_SIZE(hi3519_mux_clks), - crg->clk_data); - hisi_clk_unregister_mux(hi3519_mux_clks, - ARRAY_SIZE(hi3519_mux_clks), - crg->clk_data); - hisi_clk_unregister_fixed_rate(hi3519_fixed_rate_clks, - ARRAY_SIZE(hi3519_fixed_rate_clks), - crg->clk_data); -} - -static int hi3519_clk_probe(struct platform_device *pdev) -{ - struct hi3519_crg_data *crg; - - crg = devm_kmalloc(&pdev->dev, sizeof(*crg), GFP_KERNEL); - if (!crg) - return -ENOMEM; - - crg->rstc = hisi_reset_init(pdev); - if (!crg->rstc) - return -ENOMEM; - - crg->clk_data = hi3519_clk_register(pdev); - if (IS_ERR(crg->clk_data)) { - hisi_reset_exit(crg->rstc); - return PTR_ERR(crg->clk_data); - } - - platform_set_drvdata(pdev, crg); - return 0; -} - -static void hi3519_clk_remove(struct platform_device *pdev) -{ - struct hi3519_crg_data *crg = platform_get_drvdata(pdev); - - hisi_reset_exit(crg->rstc); - hi3519_clk_unregister(pdev); -} - +static const struct hisi_clocks hi3519_crg_clks = { + .nr = HI3519_NR_CLKS, + .fixed_rate_clks = hi3519_fixed_rate_clks, + .fixed_rate_clks_num = ARRAY_SIZE(hi3519_fixed_rate_clks), + .mux_clks = hi3519_mux_clks, + .mux_clks_num = ARRAY_SIZE(hi3519_mux_clks), + .gate_clks = hi3519_gate_clks, + .gate_clks_num = ARRAY_SIZE(hi3519_gate_clks), +}; static const struct of_device_id hi3519_clk_match_table[] = { - { .compatible = "hisilicon,hi3519-crg" }, + { .compatible = "hisilicon,hi3519-crg", + .data = &hi3519_crg_clks }, { } }; MODULE_DEVICE_TABLE(of, hi3519_clk_match_table); static struct platform_driver hi3519_clk_driver = { - .probe = hi3519_clk_probe, - .remove_new = hi3519_clk_remove, + .probe = hisi_crg_probe, + .remove_new = hisi_crg_remove, .driver = { .name = "hi3519-clk", .of_match_table = hi3519_clk_match_table, }, }; -static int __init hi3519_clk_init(void) -{ - return platform_driver_register(&hi3519_clk_driver); -} -core_initcall(hi3519_clk_init); - -static void __exit hi3519_clk_exit(void) -{ - platform_driver_unregister(&hi3519_clk_driver); -} -module_exit(hi3519_clk_exit); +module_platform_driver(hi3519_clk_driver); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("HiSilicon Hi3519 Clock Driver"); From patchwork Sun Jul 23 16:22:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangfl X-Patchwork-Id: 124510 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1344278vqg; Sun, 23 Jul 2023 09:49:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlELXkmRNnNCYbrP19TYVFzXchuzq177ckYh6qpWZsDuJMDgPlfUrFkQDWb4roxltRprzGuy X-Received: by 2002:a17:902:eccf:b0:1b8:1335:b775 with SMTP id a15-20020a170902eccf00b001b81335b775mr9858642plh.0.1690130983230; Sun, 23 Jul 2023 09:49:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690130983; cv=none; d=google.com; s=arc-20160816; b=AkGYGL+IWHjKp9VMEBvR9DnvCbhkPUkUFZCC5FpRFf/UqgUlkMpQ5rVeJ9NaLiVvw9 oADVyyUuk8BoSh0Iv5lvpbpeQG3/WgX6u5tybnT61Hi6JexCgOg0Gfj+UNWy4O+QaFcB kqKdcbew/Jt3geGx3WQDR6mTyDtcnTX10c3m73QtqEykqZ4qesyDUGnNZ6D5yCpSol8i gTaDBDWSz1CawnQT4IVnYsG1HMERnIT/AR6dS+5/+BEGwD1ejQZLVwnb/W9mkCBqhKaC lpa6nCAVGx4KcqqTdYFwU/++YQtjkl8KkbgTIPhIk2ehkadZLV3lquT0w9Wqlp7JCShA R9ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=o2BDluI1D7wuq0FUMxJuDfhF2VMI7cJr2HFkRAiaIng=; fh=0Ct5L75ES7kcLIXEE7WxKQVutRGLAzLsT+h9we2Bt4w=; b=zRhct0VwBPmcBpnlF0pDF8nxHkxyl5s2fLS4VpQUbEE8A4F2gKiogbzG208BE1txFU hQ2JB0WTCeSUORna2KkPz2OQijxOQ6jeDtpQRqMM2J+cazH/Ar5YGL65sU+/lzKXgpg1 Z0u4qVTifFgEZz64tKEvf7xJoo7/SsFGw5EA9uckvcLTLrDT5wCOJfrdPP+GuWfm3373 fs34+WXpBxC2Ly/L6bXRecVZ1dpsi+zCh7um6bV6Ml9eB+wlwyx+jaV39wCbFjgsoypJ v0jv79D8ViblYDkKhUrf7ioRUxX4ncHxzoHQwajAfhn+ZI45A3ULgtKmuNHd0SFWEwqr vJWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=lYjtjGYL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d15-20020a170902cecf00b001bb40ba3ab2si7746142plg.213.2023.07.23.09.49.30; Sun, 23 Jul 2023 09:49:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=lYjtjGYL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230039AbjGWQZc (ORCPT + 99 others); Sun, 23 Jul 2023 12:25:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230034AbjGWQZ3 (ORCPT ); Sun, 23 Jul 2023 12:25:29 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA18F1722; Sun, 23 Jul 2023 09:24:59 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-268128a0105so253326a91.3; Sun, 23 Jul 2023 09:24:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690129484; x=1690734284; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=o2BDluI1D7wuq0FUMxJuDfhF2VMI7cJr2HFkRAiaIng=; b=lYjtjGYL/Y3uCCVQCG8FRFsALqdAks9godqyDGyj43yej6LmZLjrSN/M0YFpBDy4E8 tmqdE7oLgn51ZStu8PMwPDIQT3l0L0jqnMbfYGCogHrfSKQpPI+4GsGms6pJ0bUP6JRD I81HdbVUpTSzLiZFNMvclJESLHSjy0EtUPn0wpOA+TGmVxRump5Kin3qjlrrukw09xd6 PGtRNCdDxxr+On2OlWuZLLjoNBFQWlqcUtCx7jAdLOT/sBQuGcERJX4zoevYqlvPRbKo TWoPSZeYALBnCvGJMZOauO392ffToeyxzKwy8nQ9u/5b5Q+rllFFtDvKbyXqR33jS5Ed POww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690129484; x=1690734284; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o2BDluI1D7wuq0FUMxJuDfhF2VMI7cJr2HFkRAiaIng=; b=MiyNkoaZkpIxOKY88ggdrUh3WHwkM1gqvAeKbyFzD07fC9OS3/caEM8grbt+LxNkX9 v8UyHeyJ39gz32Pd1j3wXBkRQFVy67Z5tQVzEd17bSU0+q5oxx6+/VsgYusxBHinUB4m Jy70DKlTBAI8SDh/EJraPeCHBZQKthvxKN07WDUlTj0dNPiGkpqQNWL38q/yMAafp9Jj UIcHR7Qfg64i6GD83pN+po7WGJGt6mYkINWNuFWrRtuKn4IxHi0xnuVCvmRWHgx9Ca3f vV1u/XnUBx4r0V8w1AKWeMzU2xOzY2aIZgSjClqfK0gCpApCRJ1vfy1nHrjp/IPd0myM +6Eg== X-Gm-Message-State: ABy/qLaikBCEHYu5rwsBlaAZg2ajNEe4QIzxVLhi2cgNumnLgSatMNMk S9q/DUxjBkljUOtIBX897srpwXjeoEDd0L77l60= X-Received: by 2002:a17:90a:9a8d:b0:262:ec13:d3a with SMTP id e13-20020a17090a9a8d00b00262ec130d3amr8472680pjp.28.1690129484337; Sun, 23 Jul 2023 09:24:44 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.245.199]) by smtp.gmail.com with ESMTPSA id u3-20020a17090aae8300b00265a7145fe5sm6883787pjq.41.2023.07.23.09.24.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 09:24:43 -0700 (PDT) From: David Yang To: linux-clk@vger.kernel.org Cc: David Yang , Michael Turquette , Stephen Boyd , Conor Dooley , Nick Alcock , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , linux-kernel@vger.kernel.org Subject: [PATCH v5 06/13] clk: hisilicon: hi3559a: Use helper functions Date: Mon, 24 Jul 2023 00:22:31 +0800 Message-Id: <20230723162245.35033-7-mmyangfl@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230723162245.35033-1-mmyangfl@gmail.com> References: <20230723162245.35033-1-mmyangfl@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772230785540704152 X-GMAIL-MSGID: 1772230785540704152 Use common helper functions and register clks with a single of_device_id data. Signed-off-by: David Yang --- drivers/clk/hisilicon/clk-hi3559a.c | 231 +++++----------------------- 1 file changed, 37 insertions(+), 194 deletions(-) diff --git a/drivers/clk/hisilicon/clk-hi3559a.c b/drivers/clk/hisilicon/clk-hi3559a.c index ce4028102bc2..092a5356e586 100644 --- a/drivers/clk/hisilicon/clk-hi3559a.c +++ b/drivers/clk/hisilicon/clk-hi3559a.c @@ -11,7 +11,6 @@ #include #include #include -#include #include @@ -452,21 +451,23 @@ static const struct clk_ops hisi_clk_pll_ops = { .recalc_rate = clk_pll_recalc_rate, }; -static void hisi_clk_register_pll(struct hi3559av100_pll_clock *clks, - int nums, struct hisi_clock_data *data, struct device *dev) +static int +hisi_clk_register_pll(struct device *dev, const void *clocks, + size_t num, struct hisi_clock_data *data) { + const struct hi3559av100_pll_clock *clks = clocks; void __iomem *base = data->base; struct hi3559av100_clk_pll *p_clk = NULL; struct clk *clk = NULL; struct clk_init_data init; int i; - p_clk = devm_kzalloc(dev, sizeof(*p_clk) * nums, GFP_KERNEL); + p_clk = devm_kzalloc(dev, sizeof(*p_clk) * num, GFP_KERNEL); if (!p_clk) - return; + return -ENOMEM; - for (i = 0; i < nums; i++) { + for (i = 0; i < num; i++) { init.name = clks[i].name; init.flags = 0; init.parent_names = @@ -494,78 +495,27 @@ static void hisi_clk_register_pll(struct hi3559av100_pll_clock *clks, devm_kfree(dev, p_clk); dev_err(dev, "%s: failed to register clock %s\n", __func__, clks[i].name); - continue; + return PTR_ERR(clk); } data->clk_data.clks[clks[i].id] = clk; p_clk++; } -} - -static struct hisi_clock_data *hi3559av100_clk_register( - struct platform_device *pdev) -{ - struct hisi_clock_data *clk_data; - int ret; - - clk_data = hisi_clk_alloc(pdev, HI3559AV100_CRG_NR_CLKS); - if (!clk_data) - return ERR_PTR(-ENOMEM); - - ret = hisi_clk_register_fixed_rate(hi3559av100_fixed_rate_clks_crg, - ARRAY_SIZE(hi3559av100_fixed_rate_clks_crg), clk_data); - if (ret) - return ERR_PTR(ret); - - hisi_clk_register_pll(hi3559av100_pll_clks, - ARRAY_SIZE(hi3559av100_pll_clks), clk_data, &pdev->dev); - - ret = hisi_clk_register_mux(hi3559av100_mux_clks_crg, - ARRAY_SIZE(hi3559av100_mux_clks_crg), clk_data); - if (ret) - goto unregister_fixed_rate; - - ret = hisi_clk_register_gate(hi3559av100_gate_clks, - ARRAY_SIZE(hi3559av100_gate_clks), clk_data); - if (ret) - goto unregister_mux; - - ret = of_clk_add_provider(pdev->dev.of_node, - of_clk_src_onecell_get, &clk_data->clk_data); - if (ret) - goto unregister_gate; - - return clk_data; - -unregister_gate: - hisi_clk_unregister_gate(hi3559av100_gate_clks, - ARRAY_SIZE(hi3559av100_gate_clks), clk_data); -unregister_mux: - hisi_clk_unregister_mux(hi3559av100_mux_clks_crg, - ARRAY_SIZE(hi3559av100_mux_clks_crg), clk_data); -unregister_fixed_rate: - hisi_clk_unregister_fixed_rate(hi3559av100_fixed_rate_clks_crg, - ARRAY_SIZE(hi3559av100_fixed_rate_clks_crg), clk_data); - return ERR_PTR(ret); -} -static void hi3559av100_clk_unregister(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg = platform_get_drvdata(pdev); - - of_clk_del_provider(pdev->dev.of_node); - - hisi_clk_unregister_gate(hi3559av100_gate_clks, - ARRAY_SIZE(hi3559av100_gate_clks), crg->clk_data); - hisi_clk_unregister_mux(hi3559av100_mux_clks_crg, - ARRAY_SIZE(hi3559av100_mux_clks_crg), crg->clk_data); - hisi_clk_unregister_fixed_rate(hi3559av100_fixed_rate_clks_crg, - ARRAY_SIZE(hi3559av100_fixed_rate_clks_crg), crg->clk_data); + return 0; } -static const struct hisi_crg_funcs hi3559av100_crg_funcs = { - .register_clks = hi3559av100_clk_register, - .unregister_clks = hi3559av100_clk_unregister, +static const struct hisi_clocks hi3559av100_clks = { + .nr = HI3559AV100_CRG_NR_CLKS, + .fixed_rate_clks = hi3559av100_fixed_rate_clks_crg, + .fixed_rate_clks_num = ARRAY_SIZE(hi3559av100_fixed_rate_clks_crg), + .mux_clks = hi3559av100_mux_clks_crg, + .mux_clks_num = ARRAY_SIZE(hi3559av100_mux_clks_crg), + .gate_clks = hi3559av100_gate_clks, + .gate_clks_num = ARRAY_SIZE(hi3559av100_gate_clks), + .customized_clks = hi3559av100_pll_clks, + .customized_clks_num = ARRAY_SIZE(hi3559av100_pll_clks), + .clk_register_customized = hisi_clk_register_pll, }; static struct hisi_fixed_rate_clock hi3559av100_shub_fixed_rate_clks[] = { @@ -673,7 +623,7 @@ static struct hisi_gate_clock hi3559av100_shub_gate_clks[] = { }, }; -static int hi3559av100_shub_default_clk_set(void) +static int hi3559av100_shub_default_clk_set(struct device *dev, struct hisi_clock_data *data) { void __iomem *crg_base; unsigned int val; @@ -696,148 +646,41 @@ static int hi3559av100_shub_default_clk_set(void) return 0; } -static struct hisi_clock_data *hi3559av100_shub_clk_register( - struct platform_device *pdev) -{ - struct hisi_clock_data *clk_data = NULL; - int ret; - - hi3559av100_shub_default_clk_set(); - - clk_data = hisi_clk_alloc(pdev, HI3559AV100_SHUB_NR_CLKS); - if (!clk_data) - return ERR_PTR(-ENOMEM); - - ret = hisi_clk_register_fixed_rate(hi3559av100_shub_fixed_rate_clks, - ARRAY_SIZE(hi3559av100_shub_fixed_rate_clks), clk_data); - if (ret) - return ERR_PTR(ret); - - ret = hisi_clk_register_mux(hi3559av100_shub_mux_clks, - ARRAY_SIZE(hi3559av100_shub_mux_clks), clk_data); - if (ret) - goto unregister_fixed_rate; - - ret = hisi_clk_register_divider(hi3559av100_shub_div_clks, - ARRAY_SIZE(hi3559av100_shub_div_clks), clk_data); - if (ret) - goto unregister_mux; - - ret = hisi_clk_register_gate(hi3559av100_shub_gate_clks, - ARRAY_SIZE(hi3559av100_shub_gate_clks), clk_data); - if (ret) - goto unregister_factor; - - ret = of_clk_add_provider(pdev->dev.of_node, - of_clk_src_onecell_get, &clk_data->clk_data); - if (ret) - goto unregister_gate; - - return clk_data; - -unregister_gate: - hisi_clk_unregister_gate(hi3559av100_shub_gate_clks, - ARRAY_SIZE(hi3559av100_shub_gate_clks), clk_data); -unregister_factor: - hisi_clk_unregister_divider(hi3559av100_shub_div_clks, - ARRAY_SIZE(hi3559av100_shub_div_clks), clk_data); -unregister_mux: - hisi_clk_unregister_mux(hi3559av100_shub_mux_clks, - ARRAY_SIZE(hi3559av100_shub_mux_clks), clk_data); -unregister_fixed_rate: - hisi_clk_unregister_fixed_rate(hi3559av100_shub_fixed_rate_clks, - ARRAY_SIZE(hi3559av100_shub_fixed_rate_clks), clk_data); - return ERR_PTR(ret); -} - -static void hi3559av100_shub_clk_unregister(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg = platform_get_drvdata(pdev); - - of_clk_del_provider(pdev->dev.of_node); - - hisi_clk_unregister_gate(hi3559av100_shub_gate_clks, - ARRAY_SIZE(hi3559av100_shub_gate_clks), crg->clk_data); - hisi_clk_unregister_divider(hi3559av100_shub_div_clks, - ARRAY_SIZE(hi3559av100_shub_div_clks), crg->clk_data); - hisi_clk_unregister_mux(hi3559av100_shub_mux_clks, - ARRAY_SIZE(hi3559av100_shub_mux_clks), crg->clk_data); - hisi_clk_unregister_fixed_rate(hi3559av100_shub_fixed_rate_clks, - ARRAY_SIZE(hi3559av100_shub_fixed_rate_clks), crg->clk_data); -} - -static const struct hisi_crg_funcs hi3559av100_shub_crg_funcs = { - .register_clks = hi3559av100_shub_clk_register, - .unregister_clks = hi3559av100_shub_clk_unregister, +static const struct hisi_clocks hi3559av100_shub_clks = { + .nr = HI3559AV100_SHUB_NR_CLKS, + .prologue = hi3559av100_shub_default_clk_set, + .fixed_rate_clks = hi3559av100_shub_fixed_rate_clks, + .fixed_rate_clks_num = ARRAY_SIZE(hi3559av100_shub_fixed_rate_clks), + .mux_clks = hi3559av100_shub_mux_clks, + .mux_clks_num = ARRAY_SIZE(hi3559av100_shub_mux_clks), + .divider_clks = hi3559av100_shub_div_clks, + .divider_clks_num = ARRAY_SIZE(hi3559av100_shub_div_clks), + .gate_clks = hi3559av100_shub_gate_clks, + .gate_clks_num = ARRAY_SIZE(hi3559av100_shub_gate_clks), }; static const struct of_device_id hi3559av100_crg_match_table[] = { { .compatible = "hisilicon,hi3559av100-clock", - .data = &hi3559av100_crg_funcs + .data = &hi3559av100_clks }, { .compatible = "hisilicon,hi3559av100-shub-clock", - .data = &hi3559av100_shub_crg_funcs + .data = &hi3559av100_shub_clks }, { } }; MODULE_DEVICE_TABLE(of, hi3559av100_crg_match_table); -static int hi3559av100_crg_probe(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg; - - crg = devm_kmalloc(&pdev->dev, sizeof(*crg), GFP_KERNEL); - if (!crg) - return -ENOMEM; - - crg->funcs = of_device_get_match_data(&pdev->dev); - if (!crg->funcs) - return -ENOENT; - - crg->rstc = hisi_reset_init(pdev); - if (!crg->rstc) - return -ENOMEM; - - crg->clk_data = crg->funcs->register_clks(pdev); - if (IS_ERR(crg->clk_data)) { - hisi_reset_exit(crg->rstc); - return PTR_ERR(crg->clk_data); - } - - platform_set_drvdata(pdev, crg); - return 0; -} - -static void hi3559av100_crg_remove(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg = platform_get_drvdata(pdev); - - hisi_reset_exit(crg->rstc); - crg->funcs->unregister_clks(pdev); -} - static struct platform_driver hi3559av100_crg_driver = { - .probe = hi3559av100_crg_probe, - .remove_new = hi3559av100_crg_remove, + .probe = hisi_crg_probe, + .remove_new = hisi_crg_remove, .driver = { .name = "hi3559av100-clock", .of_match_table = hi3559av100_crg_match_table, }, }; -static int __init hi3559av100_crg_init(void) -{ - return platform_driver_register(&hi3559av100_crg_driver); -} -core_initcall(hi3559av100_crg_init); - -static void __exit hi3559av100_crg_exit(void) -{ - platform_driver_unregister(&hi3559av100_crg_driver); -} -module_exit(hi3559av100_crg_exit); - +module_platform_driver(hi3559av100_crg_driver); MODULE_DESCRIPTION("HiSilicon Hi3559AV100 CRG Driver"); From patchwork Sun Jul 23 16:22:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangfl X-Patchwork-Id: 124505 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1336681vqg; Sun, 23 Jul 2023 09:28:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlEw/cmnLKFmGmwMuJ7naDK59ZhNAoalMcD/v8FzQkmlcS2UNj4Rk1PGW1BFzfmoaPi7lOq1 X-Received: by 2002:a05:6a20:7f93:b0:133:8229:196e with SMTP id d19-20020a056a207f9300b001338229196emr8028724pzj.35.1690129732968; Sun, 23 Jul 2023 09:28:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690129732; cv=none; d=google.com; s=arc-20160816; b=A8HXQrn9FdaRdBO/IRIokLvQvmXczhB6K2LoZm0NkwsWL7ctQ3xL2l4b6oQQ7j5Aw9 KQ5NXoUGl0kRhfr2bRCzi8B3t4Tv4xzGVmjPktEChze+DsAdwmBmYBhOwElYxRajwVAU +NoDhbc1AFsvCMwfbqaJ9vhsrlyD5AY46FLGlIT+CZ61ojtuftMplrVUv8o1ba5jkNGp LpNCRZuWT/GrIi+nIvxYUto2waoDaFjwmS7LhWN70JHuL6mSj81v2RG/Kn9bjk8Ll4Fb p36tXBILHIJw9EQwsNiSFyK6RtapoWzGViaSa/W4wvOHwNZZcP7plk+XOJ1ij31zBS4G GePg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=s4prFBDtTDxUhVTvO99EFoP9a0PGrs/5AlOq53YLHt8=; fh=6op8AbJPoSQyJcsI0L5qUJDM8pym4PtkpWqFZ6dkle0=; b=d3W4d9ZUnjbNfx1immZql/ECOTHbrytvwRJkSb5EQJk3BDJnHGvOaP6kbuKrvmfj7a WvriTu6Kx+PESoGfSA8GwCxuN71IiKQ7DutXYGdhU5k+3z544UkzjPMvID52ZmivCxg3 Ds58am7+hW1MfM5dmd6omP8tk55xc82/l+0IDIMjp9+/bvl+y6EXKjMUGvDReia0s7RD zyUCBswJ8XE2TQfl7Pn8kESuEgcEqUiSJwzLNk9sn2f0JkFrBLdhQauy2ML+bO6DaGri FOPATrSF5TojgriY9d4n+lWu57aNVJvcepzHGQWm5+6K4cxRYp7EMo6rlvaQWu5mQXnE +Hgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=YGKTlpNz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s203-20020a632cd4000000b0055b731aa9adsi6791259pgs.562.2023.07.23.09.28.39; Sun, 23 Jul 2023 09:28:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=YGKTlpNz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230153AbjGWQZ6 (ORCPT + 99 others); Sun, 23 Jul 2023 12:25:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230080AbjGWQZu (ORCPT ); Sun, 23 Jul 2023 12:25:50 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 894B619A6; Sun, 23 Jul 2023 09:25:16 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-668730696a4so1953268b3a.1; Sun, 23 Jul 2023 09:25:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690129497; x=1690734297; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=s4prFBDtTDxUhVTvO99EFoP9a0PGrs/5AlOq53YLHt8=; b=YGKTlpNzjPIn1Y9YvwjyQOKhwfSlEByAPdjPFB+1p3HrGOyoo6uCNSBh6dMnFQ9z+D 5yUgoCKGnZfVoV2qljCucR5ufjbE0zeOHfFyfq4xeOdWILzV8C4r0RJsr6nm16vkkWoU Flh6xapSmZwdWZKJtOUn9CEJUY27hUoHxSqXzhl1uvgKq8vv+nrVSliLEpp6YEMlNvSL Ph/a1FAamVn+EI3z7ojse1g/z1JoXlzu47dU8tAptYzQiKJyiAaeVe3pvfslSBmWo+1O +HwwkZgeWpUar6wBcjU+0QYEFPyIeKsNZzZPtVpNKXq8Ug84PZ5S0BtHwfRbYPA5Nt8M T5Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690129497; x=1690734297; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s4prFBDtTDxUhVTvO99EFoP9a0PGrs/5AlOq53YLHt8=; b=JueHvcK6QZ5bK1Svf1Pw8H0fcC582LCS5zXSN403ESzLI8TRs+r45s7mGnAQgfZYeK Mycu5xZN5uq9rOTCgsXd/C85jUHxjjZV/8wiGTA4sLPOCxKRSQ4e5AXaNAz2w8qgu3go v73JXedxpcU2GBOjTx+5NlKxseQu+Spxh/YX0NSqdt0LoCu2FYg5NIfzkOSknQU1TPW6 H3aTkhb7o2K6sVTnodM/J6q+5Dsa8v6Gz93wLg4FN6tyA0rZ8EN5OhwXeHjeh1SHcb/o pZWCN7BNfO8z+GjFfDWZ9fWZQQ/o0/K4fV/9zbyIkXFrFiR/C0wHdoTnCBIvFdV+fGil pcdA== X-Gm-Message-State: ABy/qLbXv7XD/N1Da7HbjD+FDKtP9BzW4J2qht/iNvTWAQ8pNI4ZI8j/ EbZOri5KwYZcwc9L6yL7JtPLMHrUxKlXMzys X-Received: by 2002:a17:90a:1b0f:b0:262:f0e8:a389 with SMTP id q15-20020a17090a1b0f00b00262f0e8a389mr5463163pjq.36.1690129496909; Sun, 23 Jul 2023 09:24:56 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.245.199]) by smtp.gmail.com with ESMTPSA id u3-20020a17090aae8300b00265a7145fe5sm6883787pjq.41.2023.07.23.09.24.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 09:24:56 -0700 (PDT) From: David Yang To: linux-clk@vger.kernel.org Cc: David Yang , Michael Turquette , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH v5 07/13] clk: hisilicon: hi3660: Convert into module Date: Mon, 24 Jul 2023 00:22:32 +0800 Message-Id: <20230723162245.35033-8-mmyangfl@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230723162245.35033-1-mmyangfl@gmail.com> References: <20230723162245.35033-1-mmyangfl@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772229474827605525 X-GMAIL-MSGID: 1772229474827605525 Use common helper functions and register clks with a single of_device_id data. Signed-off-by: David Yang --- drivers/clk/hisilicon/clk-hi3660.c | 192 ++++++++--------------------- 1 file changed, 53 insertions(+), 139 deletions(-) diff --git a/drivers/clk/hisilicon/clk-hi3660.c b/drivers/clk/hisilicon/clk-hi3660.c index 41f61726ab19..9ece1d57cbe6 100644 --- a/drivers/clk/hisilicon/clk-hi3660.c +++ b/drivers/clk/hisilicon/clk-hi3660.c @@ -5,9 +5,13 @@ */ #include + #include +#include +#include #include #include + #include "clk.h" static const struct hisi_fixed_rate_clock hi3660_fixed_rate_clks[] = { @@ -469,169 +473,79 @@ static const struct hisi_gate_clock hi3660_iomcu_gate_sep_clks[] = { CLK_SET_RATE_PARENT, 0x90, 0, 0, }, }; -static struct hisi_clock_data *clk_crgctrl_data; - -static void hi3660_clk_iomcu_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - int nr = ARRAY_SIZE(hi3660_iomcu_gate_sep_clks); - - clk_data = hisi_clk_init(np, nr); - if (!clk_data) - return; - - hisi_clk_register_gate_sep(hi3660_iomcu_gate_sep_clks, - ARRAY_SIZE(hi3660_iomcu_gate_sep_clks), - clk_data); -} - -static void hi3660_clk_pmuctrl_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - int nr = ARRAY_SIZE(hi3660_pmu_gate_clks); - - clk_data = hisi_clk_init(np, nr); - if (!clk_data) - return; - - hisi_clk_register_gate(hi3660_pmu_gate_clks, - ARRAY_SIZE(hi3660_pmu_gate_clks), clk_data); -} +static const struct hisi_clocks hi3660_clk_iomcu_clks = { + .gate_sep_clks = hi3660_iomcu_gate_sep_clks, + .gate_sep_clks_num = ARRAY_SIZE(hi3660_iomcu_gate_sep_clks), +}; -static void hi3660_clk_pctrl_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - int nr = ARRAY_SIZE(hi3660_pctrl_gate_clks); +static const struct hisi_clocks hi3660_clk_pmuctrl_clks = { + .gate_clks = hi3660_pmu_gate_clks, + .gate_clks_num = ARRAY_SIZE(hi3660_pmu_gate_clks), +}; - clk_data = hisi_clk_init(np, nr); - if (!clk_data) - return; - hisi_clk_register_gate(hi3660_pctrl_gate_clks, - ARRAY_SIZE(hi3660_pctrl_gate_clks), clk_data); -} +static const struct hisi_clocks hi3660_clk_pctrl_clks = { + .gate_clks = hi3660_pctrl_gate_clks, + .gate_clks_num = ARRAY_SIZE(hi3660_pctrl_gate_clks), +}; -static void hi3660_clk_sctrl_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - int nr = ARRAY_SIZE(hi3660_sctrl_gate_clks) + - ARRAY_SIZE(hi3660_sctrl_gate_sep_clks) + - ARRAY_SIZE(hi3660_sctrl_mux_clks) + - ARRAY_SIZE(hi3660_sctrl_divider_clks); +static const struct hisi_clocks hi3660_clk_sctrl_clks = { + .mux_clks = hi3660_sctrl_mux_clks, + .mux_clks_num = ARRAY_SIZE(hi3660_sctrl_mux_clks), + .divider_clks = hi3660_sctrl_divider_clks, + .divider_clks_num = ARRAY_SIZE(hi3660_sctrl_divider_clks), + .gate_clks = hi3660_sctrl_gate_clks, + .gate_clks_num = ARRAY_SIZE(hi3660_sctrl_gate_clks), + .gate_sep_clks = hi3660_sctrl_gate_sep_clks, + .gate_sep_clks_num = ARRAY_SIZE(hi3660_sctrl_gate_sep_clks), +}; - clk_data = hisi_clk_init(np, nr); - if (!clk_data) - return; - hisi_clk_register_gate(hi3660_sctrl_gate_clks, - ARRAY_SIZE(hi3660_sctrl_gate_clks), clk_data); - hisi_clk_register_gate_sep(hi3660_sctrl_gate_sep_clks, - ARRAY_SIZE(hi3660_sctrl_gate_sep_clks), - clk_data); - hisi_clk_register_mux(hi3660_sctrl_mux_clks, - ARRAY_SIZE(hi3660_sctrl_mux_clks), clk_data); - hisi_clk_register_divider(hi3660_sctrl_divider_clks, - ARRAY_SIZE(hi3660_sctrl_divider_clks), - clk_data); -} +static const struct hisi_clocks hi3660_clk_crgctrl_clks = { + .fixed_rate_clks = hi3660_fixed_rate_clks, + .fixed_rate_clks_num = ARRAY_SIZE(hi3660_fixed_rate_clks), + .fixed_factor_clks = hi3660_crg_fixed_factor_clks, + .fixed_factor_clks_num = ARRAY_SIZE(hi3660_crg_fixed_factor_clks), + .mux_clks = hi3660_crgctrl_mux_clks, + .mux_clks_num = ARRAY_SIZE(hi3660_crgctrl_mux_clks), + .divider_clks = hi3660_crgctrl_divider_clks, + .divider_clks_num = ARRAY_SIZE(hi3660_crgctrl_divider_clks), + .gate_clks = hi3660_crgctrl_gate_clks, + .gate_clks_num = ARRAY_SIZE(hi3660_crgctrl_gate_clks), + .gate_sep_clks = hi3660_crgctrl_gate_sep_clks, + .gate_sep_clks_num = ARRAY_SIZE(hi3660_crgctrl_gate_sep_clks), +}; static void hi3660_clk_crgctrl_early_init(struct device_node *np) { - int nr = ARRAY_SIZE(hi3660_fixed_rate_clks) + - ARRAY_SIZE(hi3660_crgctrl_gate_sep_clks) + - ARRAY_SIZE(hi3660_crgctrl_gate_clks) + - ARRAY_SIZE(hi3660_crgctrl_mux_clks) + - ARRAY_SIZE(hi3660_crg_fixed_factor_clks) + - ARRAY_SIZE(hi3660_crgctrl_divider_clks); - int i; - - clk_crgctrl_data = hisi_clk_init(np, nr); - if (!clk_crgctrl_data) - return; - - for (i = 0; i < nr; i++) - clk_crgctrl_data->clk_data.clks[i] = ERR_PTR(-EPROBE_DEFER); - - hisi_clk_register_fixed_rate(hi3660_fixed_rate_clks, - ARRAY_SIZE(hi3660_fixed_rate_clks), - clk_crgctrl_data); + hisi_clk_early_init(np, &hi3660_clk_crgctrl_clks); } CLK_OF_DECLARE_DRIVER(hi3660_clk_crgctrl, "hisilicon,hi3660-crgctrl", hi3660_clk_crgctrl_early_init); -static void hi3660_clk_crgctrl_init(struct device_node *np) -{ - struct clk **clks; - int i; - - if (!clk_crgctrl_data) - hi3660_clk_crgctrl_early_init(np); - - /* clk_crgctrl_data initialization failed */ - if (!clk_crgctrl_data) - return; - - hisi_clk_register_gate_sep(hi3660_crgctrl_gate_sep_clks, - ARRAY_SIZE(hi3660_crgctrl_gate_sep_clks), - clk_crgctrl_data); - hisi_clk_register_gate(hi3660_crgctrl_gate_clks, - ARRAY_SIZE(hi3660_crgctrl_gate_clks), - clk_crgctrl_data); - hisi_clk_register_mux(hi3660_crgctrl_mux_clks, - ARRAY_SIZE(hi3660_crgctrl_mux_clks), - clk_crgctrl_data); - hisi_clk_register_fixed_factor(hi3660_crg_fixed_factor_clks, - ARRAY_SIZE(hi3660_crg_fixed_factor_clks), - clk_crgctrl_data); - hisi_clk_register_divider(hi3660_crgctrl_divider_clks, - ARRAY_SIZE(hi3660_crgctrl_divider_clks), - clk_crgctrl_data); - - clks = clk_crgctrl_data->clk_data.clks; - for (i = 0; i < clk_crgctrl_data->clk_data.clk_num; i++) { - if (IS_ERR(clks[i]) && PTR_ERR(clks[i]) != -EPROBE_DEFER) - pr_err("Failed to register crgctrl clock[%d] err=%ld\n", - i, PTR_ERR(clks[i])); - } -} - static const struct of_device_id hi3660_clk_match_table[] = { { .compatible = "hisilicon,hi3660-crgctrl", - .data = hi3660_clk_crgctrl_init }, + .data = &hi3660_clk_crgctrl_clks }, { .compatible = "hisilicon,hi3660-pctrl", - .data = hi3660_clk_pctrl_init }, + .data = &hi3660_clk_pctrl_clks }, { .compatible = "hisilicon,hi3660-pmuctrl", - .data = hi3660_clk_pmuctrl_init }, + .data = &hi3660_clk_pmuctrl_clks }, { .compatible = "hisilicon,hi3660-sctrl", - .data = hi3660_clk_sctrl_init }, + .data = &hi3660_clk_sctrl_clks }, { .compatible = "hisilicon,hi3660-iomcu", - .data = hi3660_clk_iomcu_init }, + .data = &hi3660_clk_iomcu_clks }, { } }; - -static int hi3660_clk_probe(struct platform_device *pdev) -{ - struct device *dev = &pdev->dev; - struct device_node *np = pdev->dev.of_node; - void (*init_func)(struct device_node *np); - - init_func = of_device_get_match_data(dev); - if (!init_func) - return -ENODEV; - - init_func(np); - - return 0; -} +MODULE_DEVICE_TABLE(of, hi3660_clk_match_table); static struct platform_driver hi3660_clk_driver = { - .probe = hi3660_clk_probe, + .probe = hisi_clk_probe, + .remove_new = hisi_clk_remove, .driver = { .name = "hi3660-clk", .of_match_table = hi3660_clk_match_table, }, }; -static int __init hi3660_clk_init(void) -{ - return platform_driver_register(&hi3660_clk_driver); -} -core_initcall(hi3660_clk_init); +module_platform_driver(hi3660_clk_driver); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("HiSilicon Hi3660 Clock Driver"); From patchwork Sun Jul 23 16:22:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangfl X-Patchwork-Id: 124508 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1343309vqg; Sun, 23 Jul 2023 09:47:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlHD356mCVZd0TrjkaXB+eCd8+1OJnLAfFahshBMxhCSxhPkGRLRDXGkta14T05zP+aQ+wae X-Received: by 2002:a17:902:e843:b0:1b8:a569:f980 with SMTP id t3-20020a170902e84300b001b8a569f980mr6235357plg.65.1690130827313; Sun, 23 Jul 2023 09:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690130827; cv=none; d=google.com; s=arc-20160816; b=ZS64dpvpEXYRh7JWagaxZyTQQyywGrnsggziC24WOnp1tvmU2YvrsSKi6y7mtTaMwv 3YMyxmZspYQErSyZY2mZvN8f47Co3btELoL2OH5f0zCzChABPiFXHaB2AWUZbtPEP2sF +D94F5X4kO9o7D9Gdp6UAvjEZUT2TBDbJv6toml/cl7ic8lRJEcT9rP0kamP1wlmXgNB lOxdkEqza0kg9BVmA2OmwjtWs6dMfPslqSjCp7YrQIMVMD3F26LkV5qu+p9ZP5sQGRRV K4UylfGMhyK6OGnwfeOFfCJ3PgydQoAqjwWRE+EJP56s3rp1E/QltzaE067NPsrG067n f4Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0agPzZ2xJxAwSk+bG2vGTG3BIoZXujauSJdpUasqtKc=; fh=6op8AbJPoSQyJcsI0L5qUJDM8pym4PtkpWqFZ6dkle0=; b=s//CqosHsa3aLRr+xj3SCD68vLHQpr++Pgc56wrvtTxYBaOx3ii1muR/xQ8zU+4z/N iAVg5kJOMPIhCq8a+GebJbyESxdZyc/TOqHDiQ8E+CDPKi1LDE3F5PcqNs/M4dBAMuQu 48hqYviQ6gbmqgiC24EQ1v5x4XDfhrNhxlsoNW767VfsBUcnbRuJLCQD0LoGuEgfRJ0h VdZlmXwe1eM6SaQvFSMD0Fd+jZgrQrzyFldTFMrgHtR8Et5SZXIKFrGx+fD8kqLz1NML fMa2xZr6poiWKuH5QtdcrWxJ6DVXPoqihClWBs8xEjP4x6Uw9/oX+bQQBeHYeBMTBxK0 4cHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="P1HEJIJ/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jc6-20020a17090325c600b001bb21e1e6dbsi6727038plb.383.2023.07.23.09.46.52; Sun, 23 Jul 2023 09:47:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="P1HEJIJ/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230177AbjGWQ0K (ORCPT + 99 others); Sun, 23 Jul 2023 12:26:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230161AbjGWQ0C (ORCPT ); Sun, 23 Jul 2023 12:26:02 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83C2119B0; Sun, 23 Jul 2023 09:25:34 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1b8a462e0b0so19978935ad.3; Sun, 23 Jul 2023 09:25:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690129510; x=1690734310; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0agPzZ2xJxAwSk+bG2vGTG3BIoZXujauSJdpUasqtKc=; b=P1HEJIJ/HMg1oo+YnS2dREcgOMKMZtXRrZLD3yObSszowE4lPmuU0jHuZ6La3Lj838 pBmXzmalvAfXFmk00DFURXBxi6/kB19Nilmr8izP7t2g8FEJ4AgYXc7x6nJtSRlpDiU1 yRTvG5GAV38QmRGA+YDRNEyEpf9VJgEq1ISvE7lpnjIsQMn4sf5KZ6XYLFWxF9i9e3Fq jklC/La1fJmOhg4+sm9zxTGgB/GhrQsKVxVY1HJzL59ueZ3Ias9qs9G0WocZByWyWD1R BhPPx1mKq2vgl1uVCgsZxUg9uxmZc6LUEzj2c2rqQ8r9O98JFPDm1y2wu0ZBRXeo45kM cXdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690129510; x=1690734310; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0agPzZ2xJxAwSk+bG2vGTG3BIoZXujauSJdpUasqtKc=; b=cfwlP0pyj++eISL/a8FySFmGrHDCmTvLvZXjzLdkd3Wa4IOueDiVyi1zm+JGRANnbk /hwAaRvRN53jls5AYBecEBCmOw0u4SkYvwihtrrkqivAaj9CFNrwhLoVYwCGQbc9L7XS pq1ATLlwRsmrsn5TFW2Gt24x4m5if0yXiNc6nGtZKbJHR3NXtbl8C4L7esdQJr0wq75V /QnZPCxfkOoqyYo675hvEl68qL3ioIWUSE5el1oZ4+ULlxLE7U5IpzqBeRn1isfXWyVJ BjUQNXbSAYU1kGZCBDYFoCN5/KmD1GRxUMIUgUBCXyYTJfJJ9HCKnyIRPDcyO9yhZoCV fG/w== X-Gm-Message-State: ABy/qLYRZGiGPEdZY9y/stF08oYq26x6Gm4XToko9V8leAO4rFT/z3nW fR6v25gbABG8Fo+w9Q56ZSxAsyDEXc9N3hY7 X-Received: by 2002:a17:902:e5c8:b0:1b8:8ff5:2cee with SMTP id u8-20020a170902e5c800b001b88ff52ceemr7361956plf.64.1690129509859; Sun, 23 Jul 2023 09:25:09 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.245.199]) by smtp.gmail.com with ESMTPSA id u3-20020a17090aae8300b00265a7145fe5sm6883787pjq.41.2023.07.23.09.25.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 09:25:09 -0700 (PDT) From: David Yang To: linux-clk@vger.kernel.org Cc: David Yang , Michael Turquette , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH v5 08/13] clk: hisilicon: hi3670: Convert into module Date: Mon, 24 Jul 2023 00:22:33 +0800 Message-Id: <20230723162245.35033-9-mmyangfl@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230723162245.35033-1-mmyangfl@gmail.com> References: <20230723162245.35033-1-mmyangfl@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772230622343270581 X-GMAIL-MSGID: 1772230622343270581 Use common helper functions and register clks with a single of_device_id data. Signed-off-by: David Yang --- drivers/clk/hisilicon/clk-hi3670.c | 248 +++++++++-------------------- 1 file changed, 75 insertions(+), 173 deletions(-) diff --git a/drivers/clk/hisilicon/clk-hi3670.c b/drivers/clk/hisilicon/clk-hi3670.c index 4d05a71683a5..8e478832c26c 100644 --- a/drivers/clk/hisilicon/clk-hi3670.c +++ b/drivers/clk/hisilicon/clk-hi3670.c @@ -9,8 +9,11 @@ #include #include +#include +#include #include #include + #include "clk.h" static const struct hisi_fixed_rate_clock hi3670_fixed_rate_clks[] = { @@ -822,195 +825,94 @@ static const struct hisi_gate_clock hi3670_media2_gate_sep_clks[] = { CLK_SET_RATE_PARENT, 0x00, 2, 0, }, }; -static void hi3670_clk_crgctrl_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - - int nr = ARRAY_SIZE(hi3670_fixed_rate_clks) + - ARRAY_SIZE(hi3670_crgctrl_gate_sep_clks) + - ARRAY_SIZE(hi3670_crgctrl_gate_clks) + - ARRAY_SIZE(hi3670_crgctrl_mux_clks) + - ARRAY_SIZE(hi3670_crg_fixed_factor_clks) + - ARRAY_SIZE(hi3670_crgctrl_divider_clks); - - clk_data = hisi_clk_init(np, nr); - if (!clk_data) - return; - - hisi_clk_register_fixed_rate(hi3670_fixed_rate_clks, - ARRAY_SIZE(hi3670_fixed_rate_clks), - clk_data); - hisi_clk_register_gate_sep(hi3670_crgctrl_gate_sep_clks, - ARRAY_SIZE(hi3670_crgctrl_gate_sep_clks), - clk_data); - hisi_clk_register_gate(hi3670_crgctrl_gate_clks, - ARRAY_SIZE(hi3670_crgctrl_gate_clks), - clk_data); - hisi_clk_register_mux(hi3670_crgctrl_mux_clks, - ARRAY_SIZE(hi3670_crgctrl_mux_clks), - clk_data); - hisi_clk_register_fixed_factor(hi3670_crg_fixed_factor_clks, - ARRAY_SIZE(hi3670_crg_fixed_factor_clks), - clk_data); - hisi_clk_register_divider(hi3670_crgctrl_divider_clks, - ARRAY_SIZE(hi3670_crgctrl_divider_clks), - clk_data); -} - -static void hi3670_clk_pctrl_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - int nr = ARRAY_SIZE(hi3670_pctrl_gate_clks); - - clk_data = hisi_clk_init(np, nr); - if (!clk_data) - return; - hisi_clk_register_gate(hi3670_pctrl_gate_clks, - ARRAY_SIZE(hi3670_pctrl_gate_clks), clk_data); -} - -static void hi3670_clk_pmuctrl_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - int nr = ARRAY_SIZE(hi3670_pmu_gate_clks); - - clk_data = hisi_clk_init(np, nr); - if (!clk_data) - return; - - hisi_clk_register_gate(hi3670_pmu_gate_clks, - ARRAY_SIZE(hi3670_pmu_gate_clks), clk_data); -} - -static void hi3670_clk_sctrl_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - int nr = ARRAY_SIZE(hi3670_sctrl_gate_sep_clks) + - ARRAY_SIZE(hi3670_sctrl_gate_clks) + - ARRAY_SIZE(hi3670_sctrl_mux_clks) + - ARRAY_SIZE(hi3670_sctrl_divider_clks); - - clk_data = hisi_clk_init(np, nr); - if (!clk_data) - return; - - hisi_clk_register_gate_sep(hi3670_sctrl_gate_sep_clks, - ARRAY_SIZE(hi3670_sctrl_gate_sep_clks), - clk_data); - hisi_clk_register_gate(hi3670_sctrl_gate_clks, - ARRAY_SIZE(hi3670_sctrl_gate_clks), - clk_data); - hisi_clk_register_mux(hi3670_sctrl_mux_clks, - ARRAY_SIZE(hi3670_sctrl_mux_clks), - clk_data); - hisi_clk_register_divider(hi3670_sctrl_divider_clks, - ARRAY_SIZE(hi3670_sctrl_divider_clks), - clk_data); -} - -static void hi3670_clk_iomcu_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - int nr = ARRAY_SIZE(hi3670_iomcu_gate_sep_clks) + - ARRAY_SIZE(hi3670_iomcu_fixed_factor_clks); - - clk_data = hisi_clk_init(np, nr); - if (!clk_data) - return; - - hisi_clk_register_gate(hi3670_iomcu_gate_sep_clks, - ARRAY_SIZE(hi3670_iomcu_gate_sep_clks), clk_data); - - hisi_clk_register_fixed_factor(hi3670_iomcu_fixed_factor_clks, - ARRAY_SIZE(hi3670_iomcu_fixed_factor_clks), - clk_data); -} - -static void hi3670_clk_media1_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - - int nr = ARRAY_SIZE(hi3670_media1_gate_sep_clks) + - ARRAY_SIZE(hi3670_media1_gate_clks) + - ARRAY_SIZE(hi3670_media1_mux_clks) + - ARRAY_SIZE(hi3670_media1_divider_clks); - - clk_data = hisi_clk_init(np, nr); - if (!clk_data) - return; - - hisi_clk_register_gate_sep(hi3670_media1_gate_sep_clks, - ARRAY_SIZE(hi3670_media1_gate_sep_clks), - clk_data); - hisi_clk_register_gate(hi3670_media1_gate_clks, - ARRAY_SIZE(hi3670_media1_gate_clks), - clk_data); - hisi_clk_register_mux(hi3670_media1_mux_clks, - ARRAY_SIZE(hi3670_media1_mux_clks), - clk_data); - hisi_clk_register_divider(hi3670_media1_divider_clks, - ARRAY_SIZE(hi3670_media1_divider_clks), - clk_data); -} - -static void hi3670_clk_media2_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - - int nr = ARRAY_SIZE(hi3670_media2_gate_sep_clks); - - clk_data = hisi_clk_init(np, nr); - if (!clk_data) - return; - - hisi_clk_register_gate_sep(hi3670_media2_gate_sep_clks, - ARRAY_SIZE(hi3670_media2_gate_sep_clks), - clk_data); -} +static const struct hisi_clocks hi3670_clk_crgctrl_clks = { + .fixed_rate_clks = hi3670_fixed_rate_clks, + .fixed_rate_clks_num = ARRAY_SIZE(hi3670_fixed_rate_clks), + .fixed_factor_clks = hi3670_crg_fixed_factor_clks, + .fixed_factor_clks_num = ARRAY_SIZE(hi3670_crg_fixed_factor_clks), + .mux_clks = hi3670_crgctrl_mux_clks, + .mux_clks_num = ARRAY_SIZE(hi3670_crgctrl_mux_clks), + .divider_clks = hi3670_crgctrl_divider_clks, + .divider_clks_num = ARRAY_SIZE(hi3670_crgctrl_divider_clks), + .gate_clks = hi3670_crgctrl_gate_clks, + .gate_clks_num = ARRAY_SIZE(hi3670_crgctrl_gate_clks), + .gate_sep_clks = hi3670_crgctrl_gate_sep_clks, + .gate_sep_clks_num = ARRAY_SIZE(hi3670_crgctrl_gate_sep_clks), +}; + +static const struct hisi_clocks hi3670_clk_pctrl_clks = { + .gate_clks = hi3670_pctrl_gate_clks, + .gate_clks_num = ARRAY_SIZE(hi3670_pctrl_gate_clks), +}; + +static const struct hisi_clocks hi3670_clk_pmuctrl_clks = { + .gate_clks = hi3670_pmu_gate_clks, + .gate_clks_num = ARRAY_SIZE(hi3670_pmu_gate_clks), +}; + +static const struct hisi_clocks hi3670_clk_sctrl_clks = { + .mux_clks = hi3670_sctrl_mux_clks, + .mux_clks_num = ARRAY_SIZE(hi3670_sctrl_mux_clks), + .divider_clks = hi3670_sctrl_divider_clks, + .divider_clks_num = ARRAY_SIZE(hi3670_sctrl_divider_clks), + .gate_clks = hi3670_sctrl_gate_clks, + .gate_clks_num = ARRAY_SIZE(hi3670_sctrl_gate_clks), + .gate_sep_clks = hi3670_sctrl_gate_sep_clks, + .gate_sep_clks_num = ARRAY_SIZE(hi3670_sctrl_gate_sep_clks), +}; + +static const struct hisi_clocks hi3670_clk_iomcu_clks = { + .fixed_factor_clks = hi3670_iomcu_fixed_factor_clks, + .fixed_factor_clks_num = ARRAY_SIZE(hi3670_iomcu_fixed_factor_clks), + .gate_clks = hi3670_iomcu_gate_sep_clks, + .gate_clks_num = ARRAY_SIZE(hi3670_iomcu_gate_sep_clks), +}; + +static const struct hisi_clocks hi3670_clk_media1_clks = { + .mux_clks = hi3670_media1_mux_clks, + .mux_clks_num = ARRAY_SIZE(hi3670_media1_mux_clks), + .divider_clks = hi3670_media1_divider_clks, + .divider_clks_num = ARRAY_SIZE(hi3670_media1_divider_clks), + .gate_clks = hi3670_media1_gate_clks, + .gate_clks_num = ARRAY_SIZE(hi3670_media1_gate_clks), + .gate_sep_clks = hi3670_media1_gate_sep_clks, + .gate_sep_clks_num = ARRAY_SIZE(hi3670_media1_gate_sep_clks), +}; + +static const struct hisi_clocks hi3670_clk_media2_clks = { + .gate_sep_clks = hi3670_media2_gate_sep_clks, + .gate_sep_clks_num = ARRAY_SIZE(hi3670_media2_gate_sep_clks), +}; static const struct of_device_id hi3670_clk_match_table[] = { { .compatible = "hisilicon,hi3670-crgctrl", - .data = hi3670_clk_crgctrl_init }, + .data = &hi3670_clk_crgctrl_clks }, { .compatible = "hisilicon,hi3670-pctrl", - .data = hi3670_clk_pctrl_init }, + .data = &hi3670_clk_pctrl_clks }, { .compatible = "hisilicon,hi3670-pmuctrl", - .data = hi3670_clk_pmuctrl_init }, + .data = &hi3670_clk_pmuctrl_clks }, { .compatible = "hisilicon,hi3670-sctrl", - .data = hi3670_clk_sctrl_init }, + .data = &hi3670_clk_sctrl_clks }, { .compatible = "hisilicon,hi3670-iomcu", - .data = hi3670_clk_iomcu_init }, + .data = &hi3670_clk_iomcu_clks }, { .compatible = "hisilicon,hi3670-media1-crg", - .data = hi3670_clk_media1_init }, + .data = &hi3670_clk_media1_clks }, { .compatible = "hisilicon,hi3670-media2-crg", - .data = hi3670_clk_media2_init }, + .data = &hi3670_clk_media2_clks }, { } }; - -static int hi3670_clk_probe(struct platform_device *pdev) -{ - struct device *dev = &pdev->dev; - struct device_node *np = pdev->dev.of_node; - void (*init_func)(struct device_node *np); - - init_func = of_device_get_match_data(dev); - if (!init_func) - return -ENODEV; - - init_func(np); - - return 0; -} +MODULE_DEVICE_TABLE(of, hi3670_clk_match_table); static struct platform_driver hi3670_clk_driver = { - .probe = hi3670_clk_probe, + .probe = hisi_clk_probe, + .remove_new = hisi_clk_remove, .driver = { .name = "hi3670-clk", .of_match_table = hi3670_clk_match_table, }, }; -static int __init hi3670_clk_init(void) -{ - return platform_driver_register(&hi3670_clk_driver); -} -core_initcall(hi3670_clk_init); +module_platform_driver(hi3670_clk_driver); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("HiSilicon Hi3670 Clock Driver"); From patchwork Sun Jul 23 16:22:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangfl X-Patchwork-Id: 124515 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1356946vqg; Sun, 23 Jul 2023 10:21:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlEcEVlkloL8KwEh+JpAAH0q1A0KU98pfu2JbzIV8MQspnMq8EvtvsoAIHdyV5UoOwuIzhRw X-Received: by 2002:a17:902:b708:b0:1bb:a125:f831 with SMTP id d8-20020a170902b70800b001bba125f831mr1249537pls.58.1690132881917; Sun, 23 Jul 2023 10:21:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690132881; cv=none; d=google.com; s=arc-20160816; b=xQpGrG08kxArdRcevNWApLVUKWW8fWpFW4/AIQKKeTXR9Rand8XJBi2pXcJ7jmUFgI PIyz3jfarmeHkvPiFRYetJG93COmKdOtYkjFHKH20o2t7fyA57/5XWawC2AIiDhO7yMY VAsV51of1cO+oxsbfO/f8R7IrvEABDLrgl51JRgJT1kuc4jbgixRb3R2DhufD7YXRMij zvUCghHXPjpsWI5Suk000atntYIH+kPYJ9L9JnQ+vlqJv9ZGaZ0ijF/DgYrM3v+o1QND KyYzZnowINXbUNp8KqzLr7UdNmdJa0HplUOynI+tT0pwpz3bi3lbhG3rsjBp7whRvBzr 2EEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aSnN3BCJfqaTSOI9w7xIxc4ZZxFlhc3oORJ8up3814o=; fh=6op8AbJPoSQyJcsI0L5qUJDM8pym4PtkpWqFZ6dkle0=; b=kE+tbGCqeBiVBIQ/Ic0Ir56A4Z/FlkP/d6l7YKyXt5kXQsEdf8gqNjjuB/p+2HEvMN S0sLqxTBSI+V565+ZdqtwAfSROX9oN/MvFgg26FSI0wZ+QuLFS3s40cgzCgDdu6aG9lu Mv8IM7+inU8TcJIK63iGj3YxNhHqqW6Lbxsz2dG7gK2I7p6/CWC6eWIaU/Sd3ZMLlA7C W+HvM4ce4YQsFK+jBfKLiXrKVfN53Cm7W/zoZzGfCsdhCvR8QPUecj1cZpcrCmDvNvwZ RjxLL0Vtxk7O9zQPmvc/5JwTHIixvLVXoBBsXoeW4H+p7s3B67eeAvC6wbMaJOkjHm39 gKYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=UGj5Egv0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u9-20020a170903124900b001b231cb6f22si8067959plh.111.2023.07.23.10.21.08; Sun, 23 Jul 2023 10:21:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=UGj5Egv0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229842AbjGWQ0Q (ORCPT + 99 others); Sun, 23 Jul 2023 12:26:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229625AbjGWQ0L (ORCPT ); Sun, 23 Jul 2023 12:26:11 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35B8C1FE5; Sun, 23 Jul 2023 09:25:48 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-5577004e21bso1471105a12.2; Sun, 23 Jul 2023 09:25:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690129522; x=1690734322; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aSnN3BCJfqaTSOI9w7xIxc4ZZxFlhc3oORJ8up3814o=; b=UGj5Egv0azfGO2u52suXuipC6+M3n7mZgYTKAaMLuJquiba6T2TMh9SUjTAG+y4Nwh jVa5Lpi9H5sWhVD+iN2S1qyIoLyrC8Hdq3IFBjYOd0TV04qYFpw1V/Ljo15rchGvU+nr ab7zsDU3ZLg18TLAL+lRgF6UVGl2jVUb+V7jGlpDy2mGEsPapfCMD9sj1uaN7x6xNCEq v5Q+Z1h/LDrbKeV9/wnzIY95iRHcgLkVm15Obrnp+cT95woH8dvf+9RvS5tkkYFtBzKn 5dkgdSiYlPdg3t4eT3rvzKaErhAosiOwtfjx0xuxAu/C6qtqsvSrAEP77Kuo9p2Cj223 MKVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690129522; x=1690734322; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aSnN3BCJfqaTSOI9w7xIxc4ZZxFlhc3oORJ8up3814o=; b=M9jNiFJUqBcPRHF3jIx2JrN9cxtUO8WDAqwB7T3utk58vVYSToCCPDcmrWc7Bs7zOu goSCywrLh9MsidpEfx52T3Wxh17jDsbmIOE/SowgCP5F+yqwXtjOoZiqInyPYeZWglQn ICD+U8/xFemEy3YLOPPfIRDee8gzICugkvsA60aRDLSVvg0DJQdWjQhd0itgCJS1gR+O sJUrzkQwg/dWu8aadpibH1ehzrgH3NSUPubFlB3FPqAXv0doSdS1rNfAGXwLtvUtrisL rHuRLr4MLV3qILR8M2r8V05ut6cCUaJeOTAOGZZZOOHnj/+2gxPHtx+yOXrRr4jE5K11 q8HA== X-Gm-Message-State: ABy/qLYGycQHsQTM0rNCpYt1MyOj7MS6LbQF3TdwaXkMdZS0hhljpXc9 IFwUA5MFWAX9W4YYRx+BgQHc++2RBjfTSiww X-Received: by 2002:a17:90a:8b0e:b0:263:f590:f231 with SMTP id y14-20020a17090a8b0e00b00263f590f231mr6655751pjn.26.1690129522458; Sun, 23 Jul 2023 09:25:22 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.245.199]) by smtp.gmail.com with ESMTPSA id u3-20020a17090aae8300b00265a7145fe5sm6883787pjq.41.2023.07.23.09.25.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 09:25:22 -0700 (PDT) From: David Yang To: linux-clk@vger.kernel.org Cc: David Yang , Michael Turquette , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH v5 09/13] clk: hisilicon: hi3620: Convert into platform driver module Date: Mon, 24 Jul 2023 00:22:34 +0800 Message-Id: <20230723162245.35033-10-mmyangfl@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230723162245.35033-1-mmyangfl@gmail.com> References: <20230723162245.35033-1-mmyangfl@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772232776303003528 X-GMAIL-MSGID: 1772232776303003528 Use common helper functions and register clks with a single of_device_id data. Signed-off-by: David Yang --- drivers/clk/hisilicon/clk-hi3620.c | 189 +++++++++++++++-------------- 1 file changed, 96 insertions(+), 93 deletions(-) diff --git a/drivers/clk/hisilicon/clk-hi3620.c b/drivers/clk/hisilicon/clk-hi3620.c index a3d04c7c3da8..a08778de8dc2 100644 --- a/drivers/clk/hisilicon/clk-hi3620.c +++ b/drivers/clk/hisilicon/clk-hi3620.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -22,48 +23,48 @@ #include "clk.h" /* clock parent list */ -static const char *const timer0_mux_p[] __initconst = { "osc32k", "timerclk01", }; -static const char *const timer1_mux_p[] __initconst = { "osc32k", "timerclk01", }; -static const char *const timer2_mux_p[] __initconst = { "osc32k", "timerclk23", }; -static const char *const timer3_mux_p[] __initconst = { "osc32k", "timerclk23", }; -static const char *const timer4_mux_p[] __initconst = { "osc32k", "timerclk45", }; -static const char *const timer5_mux_p[] __initconst = { "osc32k", "timerclk45", }; -static const char *const timer6_mux_p[] __initconst = { "osc32k", "timerclk67", }; -static const char *const timer7_mux_p[] __initconst = { "osc32k", "timerclk67", }; -static const char *const timer8_mux_p[] __initconst = { "osc32k", "timerclk89", }; -static const char *const timer9_mux_p[] __initconst = { "osc32k", "timerclk89", }; -static const char *const uart0_mux_p[] __initconst = { "osc26m", "pclk", }; -static const char *const uart1_mux_p[] __initconst = { "osc26m", "pclk", }; -static const char *const uart2_mux_p[] __initconst = { "osc26m", "pclk", }; -static const char *const uart3_mux_p[] __initconst = { "osc26m", "pclk", }; -static const char *const uart4_mux_p[] __initconst = { "osc26m", "pclk", }; -static const char *const spi0_mux_p[] __initconst = { "osc26m", "rclk_cfgaxi", }; -static const char *const spi1_mux_p[] __initconst = { "osc26m", "rclk_cfgaxi", }; -static const char *const spi2_mux_p[] __initconst = { "osc26m", "rclk_cfgaxi", }; +static const char *const timer0_mux_p[] = { "osc32k", "timerclk01", }; +static const char *const timer1_mux_p[] = { "osc32k", "timerclk01", }; +static const char *const timer2_mux_p[] = { "osc32k", "timerclk23", }; +static const char *const timer3_mux_p[] = { "osc32k", "timerclk23", }; +static const char *const timer4_mux_p[] = { "osc32k", "timerclk45", }; +static const char *const timer5_mux_p[] = { "osc32k", "timerclk45", }; +static const char *const timer6_mux_p[] = { "osc32k", "timerclk67", }; +static const char *const timer7_mux_p[] = { "osc32k", "timerclk67", }; +static const char *const timer8_mux_p[] = { "osc32k", "timerclk89", }; +static const char *const timer9_mux_p[] = { "osc32k", "timerclk89", }; +static const char *const uart0_mux_p[] = { "osc26m", "pclk", }; +static const char *const uart1_mux_p[] = { "osc26m", "pclk", }; +static const char *const uart2_mux_p[] = { "osc26m", "pclk", }; +static const char *const uart3_mux_p[] = { "osc26m", "pclk", }; +static const char *const uart4_mux_p[] = { "osc26m", "pclk", }; +static const char *const spi0_mux_p[] = { "osc26m", "rclk_cfgaxi", }; +static const char *const spi1_mux_p[] = { "osc26m", "rclk_cfgaxi", }; +static const char *const spi2_mux_p[] = { "osc26m", "rclk_cfgaxi", }; /* share axi parent */ -static const char *const saxi_mux_p[] __initconst = { "armpll3", "armpll2", }; -static const char *const pwm0_mux_p[] __initconst = { "osc32k", "osc26m", }; -static const char *const pwm1_mux_p[] __initconst = { "osc32k", "osc26m", }; -static const char *const sd_mux_p[] __initconst = { "armpll2", "armpll3", }; -static const char *const mmc1_mux_p[] __initconst = { "armpll2", "armpll3", }; -static const char *const mmc1_mux2_p[] __initconst = { "osc26m", "mmc1_div", }; -static const char *const g2d_mux_p[] __initconst = { "armpll2", "armpll3", }; -static const char *const venc_mux_p[] __initconst = { "armpll2", "armpll3", }; -static const char *const vdec_mux_p[] __initconst = { "armpll2", "armpll3", }; -static const char *const vpp_mux_p[] __initconst = { "armpll2", "armpll3", }; -static const char *const edc0_mux_p[] __initconst = { "armpll2", "armpll3", }; -static const char *const ldi0_mux_p[] __initconst = { "armpll2", "armpll4", +static const char *const saxi_mux_p[] = { "armpll3", "armpll2", }; +static const char *const pwm0_mux_p[] = { "osc32k", "osc26m", }; +static const char *const pwm1_mux_p[] = { "osc32k", "osc26m", }; +static const char *const sd_mux_p[] = { "armpll2", "armpll3", }; +static const char *const mmc1_mux_p[] = { "armpll2", "armpll3", }; +static const char *const mmc1_mux2_p[] = { "osc26m", "mmc1_div", }; +static const char *const g2d_mux_p[] = { "armpll2", "armpll3", }; +static const char *const venc_mux_p[] = { "armpll2", "armpll3", }; +static const char *const vdec_mux_p[] = { "armpll2", "armpll3", }; +static const char *const vpp_mux_p[] = { "armpll2", "armpll3", }; +static const char *const edc0_mux_p[] = { "armpll2", "armpll3", }; +static const char *const ldi0_mux_p[] = { "armpll2", "armpll4", "armpll3", "armpll5", }; -static const char *const edc1_mux_p[] __initconst = { "armpll2", "armpll3", }; -static const char *const ldi1_mux_p[] __initconst = { "armpll2", "armpll4", +static const char *const edc1_mux_p[] = { "armpll2", "armpll3", }; +static const char *const ldi1_mux_p[] = { "armpll2", "armpll4", "armpll3", "armpll5", }; -static const char *const rclk_hsic_p[] __initconst = { "armpll3", "armpll2", }; -static const char *const mmc2_mux_p[] __initconst = { "armpll2", "armpll3", }; -static const char *const mmc3_mux_p[] __initconst = { "armpll2", "armpll3", }; +static const char *const rclk_hsic_p[] = { "armpll3", "armpll2", }; +static const char *const mmc2_mux_p[] = { "armpll2", "armpll3", }; +static const char *const mmc3_mux_p[] = { "armpll2", "armpll3", }; /* fixed rate clocks */ -static struct hisi_fixed_rate_clock hi3620_fixed_rate_clks[] __initdata = { +static struct hisi_fixed_rate_clock hi3620_fixed_rate_clks[] = { { HI3620_OSC32K, "osc32k", NULL, 0, 32768, }, { HI3620_OSC26M, "osc26m", NULL, 0, 26000000, }, { HI3620_PCLK, "pclk", NULL, 0, 26000000, }, @@ -76,13 +77,13 @@ static struct hisi_fixed_rate_clock hi3620_fixed_rate_clks[] __initdata = { }; /* fixed factor clocks */ -static struct hisi_fixed_factor_clock hi3620_fixed_factor_clks[] __initdata = { +static struct hisi_fixed_factor_clock hi3620_fixed_factor_clks[] = { { HI3620_RCLK_TCXO, "rclk_tcxo", "osc26m", 1, 4, 0, }, { HI3620_RCLK_CFGAXI, "rclk_cfgaxi", "armpll2", 1, 30, 0, }, { HI3620_RCLK_PICO, "rclk_pico", "hsic_div", 1, 40, 0, }, }; -static struct hisi_mux_clock hi3620_mux_clks[] __initdata = { +static struct hisi_mux_clock hi3620_mux_clks[] = { { HI3620_TIMER0_MUX, "timer0_mux", timer0_mux_p, ARRAY_SIZE(timer0_mux_p), CLK_SET_RATE_PARENT, 0, 15, 2, 0, }, { HI3620_TIMER1_MUX, "timer1_mux", timer1_mux_p, ARRAY_SIZE(timer1_mux_p), CLK_SET_RATE_PARENT, 0, 17, 2, 0, }, { HI3620_TIMER2_MUX, "timer2_mux", timer2_mux_p, ARRAY_SIZE(timer2_mux_p), CLK_SET_RATE_PARENT, 0, 19, 2, 0, }, @@ -120,7 +121,7 @@ static struct hisi_mux_clock hi3620_mux_clks[] __initdata = { { HI3620_MMC3_MUX, "mmc3_mux", mmc3_mux_p, ARRAY_SIZE(mmc3_mux_p), CLK_SET_RATE_PARENT, 0x140, 9, 1, CLK_MUX_HIWORD_MASK, }, }; -static struct hisi_divider_clock hi3620_div_clks[] __initdata = { +static struct hisi_divider_clock hi3620_div_clks[] = { { HI3620_SHAREAXI_DIV, "saxi_div", "saxi_mux", 0, 0x100, 0, 5, CLK_DIVIDER_HIWORD_MASK, NULL, }, { HI3620_CFGAXI_DIV, "cfgaxi_div", "saxi_div", 0, 0x100, 5, 2, CLK_DIVIDER_HIWORD_MASK, NULL, }, { HI3620_SD_DIV, "sd_div", "sd_mux", 0, 0x108, 0, 4, CLK_DIVIDER_HIWORD_MASK, NULL, }, @@ -130,7 +131,7 @@ static struct hisi_divider_clock hi3620_div_clks[] __initdata = { { HI3620_MMC3_DIV, "mmc3_div", "mmc3_mux", 0, 0x140, 5, 4, CLK_DIVIDER_HIWORD_MASK, NULL, }, }; -static struct hisi_gate_clock hi3620_separated_gate_clks[] __initdata = { +static struct hisi_gate_clock hi3620_separated_gate_clks[] = { { HI3620_TIMERCLK01, "timerclk01", "timer_rclk01", CLK_SET_RATE_PARENT, 0x20, 0, 0, }, { HI3620_TIMER_RCLK01, "timer_rclk01", "rclk_tcxo", CLK_SET_RATE_PARENT, 0x20, 1, 0, }, { HI3620_TIMERCLK23, "timerclk23", "timer_rclk23", CLK_SET_RATE_PARENT, 0x20, 2, 0, }, @@ -192,29 +193,19 @@ static struct hisi_gate_clock hi3620_separated_gate_clks[] __initdata = { { HI3620_MCU_CLK, "mcu_clk", "acp_clk", CLK_SET_RATE_PARENT, 0x50, 24, 0, }, }; -static void __init hi3620_clk_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - - clk_data = hisi_clk_init(np, HI3620_NR_CLKS); - if (!clk_data) - return; - - hisi_clk_register_fixed_rate(hi3620_fixed_rate_clks, - ARRAY_SIZE(hi3620_fixed_rate_clks), - clk_data); - hisi_clk_register_fixed_factor(hi3620_fixed_factor_clks, - ARRAY_SIZE(hi3620_fixed_factor_clks), - clk_data); - hisi_clk_register_mux(hi3620_mux_clks, ARRAY_SIZE(hi3620_mux_clks), - clk_data); - hisi_clk_register_divider(hi3620_div_clks, ARRAY_SIZE(hi3620_div_clks), - clk_data); - hisi_clk_register_gate_sep(hi3620_separated_gate_clks, - ARRAY_SIZE(hi3620_separated_gate_clks), - clk_data); -} -CLK_OF_DECLARE(hi3620_clk, "hisilicon,hi3620-clock", hi3620_clk_init); +static const struct hisi_clocks hi3620_clks = { + .nr = HI3620_NR_CLKS, + .fixed_rate_clks = hi3620_fixed_rate_clks, + .fixed_rate_clks_num = ARRAY_SIZE(hi3620_fixed_rate_clks), + .fixed_factor_clks = hi3620_fixed_factor_clks, + .fixed_factor_clks_num = ARRAY_SIZE(hi3620_fixed_factor_clks), + .mux_clks = hi3620_mux_clks, + .mux_clks_num = ARRAY_SIZE(hi3620_mux_clks), + .divider_clks = hi3620_div_clks, + .divider_clks_num = ARRAY_SIZE(hi3620_div_clks), + .gate_sep_clks = hi3620_separated_gate_clks, + .gate_sep_clks_num = ARRAY_SIZE(hi3620_separated_gate_clks), +}; struct hisi_mmc_clock { unsigned int id; @@ -252,7 +243,7 @@ struct clk_mmc { #define to_mmc(_hw) container_of(_hw, struct clk_mmc, hw) -static struct hisi_mmc_clock hi3620_mmc_clks[] __initdata = { +static struct hisi_mmc_clock hi3620_mmc_clks[] = { { HI3620_SD_CIUCLK, "sd_bclk1", "sd_clk", CLK_SET_RATE_PARENT, 0x1f8, 0, 0x1f8, 1, 3, 0x1f8, 4, 4, 0x1f8, 8, 4}, { HI3620_MMC_CIUCLK1, "mmc_bclk1", "mmc_clk1", CLK_SET_RATE_PARENT, 0x1f8, 12, 0x1f8, 13, 3, 0x1f8, 16, 4, 0x1f8, 20, 4}, { HI3620_MMC_CIUCLK2, "mmc_bclk2", "mmc_clk2", CLK_SET_RATE_PARENT, 0x1f8, 24, 0x1f8, 25, 3, 0x1f8, 28, 4, 0x1fc, 0, 4}, @@ -408,8 +399,9 @@ static const struct clk_ops clk_mmc_ops = { .recalc_rate = mmc_clk_recalc_rate, }; -static struct clk *hisi_register_clk_mmc(struct hisi_mmc_clock *mmc_clk, - void __iomem *base, struct device_node *np) +static struct clk * +clk_register_hisi_mmc(struct device *dev, const struct hisi_mmc_clock *mmc_clk, + void __iomem *base) { struct clk_mmc *mclk; struct clk *clk; @@ -445,39 +437,50 @@ static struct clk *hisi_register_clk_mmc(struct hisi_mmc_clock *mmc_clk, return clk; } -static void __init hi3620_mmc_clk_init(struct device_node *node) +static int hisi_register_clk_mmc(struct device *dev, const void *clocks, + size_t num, struct hisi_clock_data *data) { - void __iomem *base; - int i, num = ARRAY_SIZE(hi3620_mmc_clks); - struct clk_onecell_data *clk_data; + const struct hisi_mmc_clock *clks = clocks; - if (!node) { - pr_err("failed to find pctrl node in DTS\n"); - return; - } + for (int i = 0; i < num; i++) { + struct clk *clk = clk_register_hisi_mmc(dev, &clks[i], data->base); - base = of_iomap(node, 0); - if (!base) { - pr_err("failed to map pctrl\n"); - return; + if (IS_ERR(clk)) { + pr_err("%s: failed to register clock %s\n", + __func__, clks[i].name); + return PTR_ERR(clk); + } + data->clk_data.clks[clks[i].id] = clk; } - clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL); - if (WARN_ON(!clk_data)) - return; + return 0; +} - clk_data->clks = kcalloc(num, sizeof(*clk_data->clks), GFP_KERNEL); - if (!clk_data->clks) - return; +static const struct hisi_clocks hi3620_clks_mmc = { + .customized_clks = hi3620_mmc_clks, + .customized_clks_num = ARRAY_SIZE(hi3620_mmc_clks), + .clk_register_customized = hisi_register_clk_mmc, +}; - for (i = 0; i < num; i++) { - struct hisi_mmc_clock *mmc_clk = &hi3620_mmc_clks[i]; - clk_data->clks[mmc_clk->id] = - hisi_register_clk_mmc(mmc_clk, base, node); - } +static const struct of_device_id hi3620_clk_match_table[] = { + { .compatible = "hisilicon,hi3620-clock", + .data = &hi3620_clks }, + { .compatible = "hisilicon,hi3620-mmc-clock", + .data = &hi3620_clks_mmc }, + { } +}; +MODULE_DEVICE_TABLE(of, hi3620_clk_match_table); + +static struct platform_driver hi3620_clk_driver = { + .probe = hisi_clk_probe, + .remove_new = hisi_clk_remove, + .driver = { + .name = "hi3620-clock", + .of_match_table = hi3620_clk_match_table, + }, +}; - clk_data->clk_num = num; - of_clk_add_provider(node, of_clk_src_onecell_get, clk_data); -} +module_platform_driver(hi3620_clk_driver); -CLK_OF_DECLARE(hi3620_mmc_clk, "hisilicon,hi3620-mmc-clock", hi3620_mmc_clk_init); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("HiSilicon Hi3620 Clock Driver"); From patchwork Sun Jul 23 16:22:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangfl X-Patchwork-Id: 124512 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1345685vqg; Sun, 23 Jul 2023 09:54:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlGYpiUJLYt3I9gQE3QIGamoNW2Ictn3bNybNE1VeivCZ0clfkJnwJlLddJNPA+A8GlJ4K5O X-Received: by 2002:a05:6a20:b903:b0:136:e26b:6401 with SMTP id fe3-20020a056a20b90300b00136e26b6401mr8211843pzb.16.1690131245512; Sun, 23 Jul 2023 09:54:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690131245; cv=none; d=google.com; s=arc-20160816; b=uShe71vJxWXWD+fx5UP4BeEWufq6f2AZPz+3OEBp3FWmBzoTMTb5ZvvigBkODJJBAX zUCCn9c5R6VHIIFgBh+shJE7orxzIiMyJDa/ykn3IWeD9wY7mreRkihu0EzoaMRgm4fB z4iSuDKxOAIRa2T3trvRXlJkZXKF4oVj0Iv98OksPWmUydgnyrEmgKjwX1AiAP2i/8tu EOmxewtB4aptuOaA03JjwdPyWheha64D/NY4/TpsoMyG0U7H1bo7qTeB6KXLYDgToQ8t bdMzthyLZ25N+2uhP0Y2pjPkDJ6d0qyu3sZEgH8ERe5dqVtKO8WGYkHmsQaUS9w0OGag xDLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fXzfAG4N6TwCpk4DoqL7m8vRm6P+/nRHCvi921nmTkw=; fh=6op8AbJPoSQyJcsI0L5qUJDM8pym4PtkpWqFZ6dkle0=; b=wO/CnaSHm9Gj0RmGwhlA4kj1yJTcH8Tw+rn35J3sUQXjQ/16TwqAvtfZRSmaZvZsC3 BAXYVl5mw3u1wz2gyhJqYE/c+5J2iZPPVMjzTYBvYJr2ZGsNHNzG10cYkRG8y5o8u2vy rv40p0B9exvT8ygzTMTgOPwuFqxvUkAuOIPT3YmLS0ihXKjOlltSRHKwlAD0b/nGU2Wv yHrdZqZUCMQ/p9rKH7NZsETAFlo0HKHqwA1b4vgPJ9TeV0hTKv3DBF95AMeLi9CKT1Rf dLFb6YiSefVvJH1qqv39RhQ8JmFdZ8c9MfYWDrm/YzU02BKmfdL9X1sesM3cDMy9pv4h 8TMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=cE+D1oYK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k9-20020a63d849000000b0055ac8f8526dsi7211648pgj.530.2023.07.23.09.53.52; Sun, 23 Jul 2023 09:54:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=cE+D1oYK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229560AbjGWQ03 (ORCPT + 99 others); Sun, 23 Jul 2023 12:26:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229770AbjGWQ0U (ORCPT ); Sun, 23 Jul 2023 12:26:20 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B82A810C7; Sun, 23 Jul 2023 09:25:55 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1bb119be881so27372275ad.3; Sun, 23 Jul 2023 09:25:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690129536; x=1690734336; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fXzfAG4N6TwCpk4DoqL7m8vRm6P+/nRHCvi921nmTkw=; b=cE+D1oYKxKE1qKxW+APFJCOKI2lxb23htnRYmf9JZFXypNvIE17rMGwd80KDgbdyqh ev5G6oV39J571M2TYdrjD4y9MjQipq/JHrJ37+3QCoGOlDv6EkTimjqiaAJI3p0t5tIX ug5Zly7B9w0eA1rzQ0EWU+O/6Mal1gt+TaRyiyovzDHVixRmqYSoTcK1xho5DgWHIQz1 5I9DeNOV5Egs14Lcia/ZvZG+khRw58mYoZOVqVG8PICXC+sIcclNkUNLkuKNidwlVsMj QiPdS9MhqUbqLFDj+Tfj/YvpUtwh9U9LMdFocQxlMwD59jBvWAZEtc+ybMEW4cvcYDkh sBKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690129536; x=1690734336; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fXzfAG4N6TwCpk4DoqL7m8vRm6P+/nRHCvi921nmTkw=; b=d6UTrn1ygcqCXeH8ueG/aEncnCS/Kw5HkO1jlguiYd6/ovY68QhETa1fL3TFxA/WF5 084qAdm/an079+LsjFZt2LBZ0WPDVHK/ksCwjwfRUz3F+oM5Lw+Fac7bq94/nluT6ndt LfVv2m5UWQpLNuxdJTapQHWROUfdrl8ONzT5dyeHjrL1cwjwQwNHp9XEMFHmugaAxVih AzGgu+fzqG6N578trpsqreFbyMXbLcREoRcr1jQsRB9ecgMvtjkIwXD8HqG834mt3i9i lyYxZ3vK039t1138rT7j62Ky0jFg89qrKVZWwpHHNf9FaQKfdFWHEM4sEm9w1avaRqMf Pdlg== X-Gm-Message-State: ABy/qLaVNOOlenklNiJmGLsN4IZwh3qoB3b8dywYhQN/yylxWlk5+mH+ eJCOrFhSQsHSwv1fIUuO8eVCvHTNEmJThM8P X-Received: by 2002:a17:902:eccd:b0:1b9:e97f:3846 with SMTP id a13-20020a170902eccd00b001b9e97f3846mr11125224plh.15.1690129535750; Sun, 23 Jul 2023 09:25:35 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.245.199]) by smtp.gmail.com with ESMTPSA id u3-20020a17090aae8300b00265a7145fe5sm6883787pjq.41.2023.07.23.09.25.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 09:25:35 -0700 (PDT) From: David Yang To: linux-clk@vger.kernel.org Cc: David Yang , Michael Turquette , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH v5 10/13] clk: hisilicon: hi6220: Convert into platform driver module Date: Mon, 24 Jul 2023 00:22:35 +0800 Message-Id: <20230723162245.35033-11-mmyangfl@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230723162245.35033-1-mmyangfl@gmail.com> References: <20230723162245.35033-1-mmyangfl@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772231060485818101 X-GMAIL-MSGID: 1772231060485818101 Use common helper functions and register clks with a single of_device_id data. Signed-off-by: David Yang --- drivers/clk/hisilicon/clk-hi6220.c | 231 ++++++++++++++--------------- 1 file changed, 112 insertions(+), 119 deletions(-) diff --git a/drivers/clk/hisilicon/clk-hi6220.c b/drivers/clk/hisilicon/clk-hi6220.c index e7cdf72d4b06..6eac73408745 100644 --- a/drivers/clk/hisilicon/clk-hi6220.c +++ b/drivers/clk/hisilicon/clk-hi6220.c @@ -9,20 +9,24 @@ #include #include -#include -#include -#include -#include +#include #include -#include #include #include "clk.h" +static int +hi6220_clk_register_divider_stub(struct device *dev, const void *clks, + size_t num, struct hisi_clock_data *data) +{ + /* INCOMPLETE PATCH */ + hi6220_clk_register_divider(clks, num, data); + return 0; +} /* clocks in AO (always on) controller */ -static struct hisi_fixed_rate_clock hi6220_fixed_rate_clks[] __initdata = { +static struct hisi_fixed_rate_clock hi6220_fixed_rate_clks[] = { { HI6220_REF32K, "ref32k", NULL, 0, 32764, }, { HI6220_CLK_TCXO, "clk_tcxo", NULL, 0, 19200000, }, { HI6220_MMC1_PAD, "mmc1_pad", NULL, 0, 100000000, }, @@ -38,7 +42,7 @@ static struct hisi_fixed_rate_clock hi6220_fixed_rate_clks[] __initdata = { { HI6220_PLL_DDR, "ddrpll0", NULL, 0, 1600000000,}, }; -static struct hisi_fixed_factor_clock hi6220_fixed_factor_clks[] __initdata = { +static struct hisi_fixed_factor_clock hi6220_fixed_factor_clks[] = { { HI6220_300M, "clk_300m", "syspll", 1, 4, 0, }, { HI6220_150M, "clk_150m", "clk_300m", 1, 2, 0, }, { HI6220_PICOPHY_SRC, "picophy_src", "clk_150m", 1, 4, 0, }, @@ -51,7 +55,7 @@ static struct hisi_fixed_factor_clock hi6220_fixed_factor_clks[] __initdata = { { HI6220_MMC2_SMP, "mmc2_sample", "mmc2_sel", 1, 8, 0, }, }; -static struct hisi_gate_clock hi6220_separated_gate_clks_ao[] __initdata = { +static struct hisi_gate_clock hi6220_separated_gate_clks_ao[] = { { HI6220_WDT0_PCLK, "wdt0_pclk", "ref32k", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 12, 0, }, { HI6220_WDT1_PCLK, "wdt1_pclk", "ref32k", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 13, 0, }, { HI6220_WDT2_PCLK, "wdt2_pclk", "ref32k", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 14, 0, }, @@ -69,47 +73,43 @@ static struct hisi_gate_clock hi6220_separated_gate_clks_ao[] __initdata = { { HI6220_RTC1_PCLK, "rtc1_pclk", "clk_tcxo", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 26, 0, }, }; -static void __init hi6220_clk_ao_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data_ao; - - clk_data_ao = hisi_clk_init(np, HI6220_AO_NR_CLKS); - if (!clk_data_ao) - return; - - hisi_clk_register_fixed_rate(hi6220_fixed_rate_clks, - ARRAY_SIZE(hi6220_fixed_rate_clks), clk_data_ao); - - hisi_clk_register_fixed_factor(hi6220_fixed_factor_clks, - ARRAY_SIZE(hi6220_fixed_factor_clks), clk_data_ao); +static const struct hisi_clocks hi6220_ao_clks = { + .nr = HI6220_AO_NR_CLKS, + .fixed_rate_clks = hi6220_fixed_rate_clks, + .fixed_rate_clks_num = ARRAY_SIZE(hi6220_fixed_rate_clks), + .fixed_factor_clks = hi6220_fixed_factor_clks, + .fixed_factor_clks_num = ARRAY_SIZE(hi6220_fixed_factor_clks), + .gate_sep_clks = hi6220_separated_gate_clks_ao, + .gate_sep_clks_num = ARRAY_SIZE(hi6220_separated_gate_clks_ao), +}; - hisi_clk_register_gate_sep(hi6220_separated_gate_clks_ao, - ARRAY_SIZE(hi6220_separated_gate_clks_ao), clk_data_ao); +static void hi6220_clk_ao_early_init(struct device_node *np) +{ + hisi_clk_early_init(np, &hi6220_ao_clks); } /* Allow reset driver to probe as well */ -CLK_OF_DECLARE_DRIVER(hi6220_clk_ao, "hisilicon,hi6220-aoctrl", hi6220_clk_ao_init); - +CLK_OF_DECLARE_DRIVER(hi6220_clk_ao, "hisilicon,hi6220-aoctrl", hi6220_clk_ao_early_init); /* clocks in sysctrl */ -static const char *mmc0_mux0_p[] __initdata = { "pll_ddr_gate", "syspll", }; -static const char *mmc0_mux1_p[] __initdata = { "mmc0_mux0", "pll_media_gate", }; -static const char *mmc0_src_p[] __initdata = { "mmc0srcsel", "mmc0_div", }; -static const char *mmc1_mux0_p[] __initdata = { "pll_ddr_gate", "syspll", }; -static const char *mmc1_mux1_p[] __initdata = { "mmc1_mux0", "pll_media_gate", }; -static const char *mmc1_src_p[] __initdata = { "mmc1srcsel", "mmc1_div", }; -static const char *mmc2_mux0_p[] __initdata = { "pll_ddr_gate", "syspll", }; -static const char *mmc2_mux1_p[] __initdata = { "mmc2_mux0", "pll_media_gate", }; -static const char *mmc2_src_p[] __initdata = { "mmc2srcsel", "mmc2_div", }; -static const char *mmc0_sample_in[] __initdata = { "mmc0_sample", "mmc0_pad", }; -static const char *mmc1_sample_in[] __initdata = { "mmc1_sample", "mmc1_pad", }; -static const char *mmc2_sample_in[] __initdata = { "mmc2_sample", "mmc2_pad", }; -static const char *uart1_src[] __initdata = { "clk_tcxo", "clk_150m", }; -static const char *uart2_src[] __initdata = { "clk_tcxo", "clk_150m", }; -static const char *uart3_src[] __initdata = { "clk_tcxo", "clk_150m", }; -static const char *uart4_src[] __initdata = { "clk_tcxo", "clk_150m", }; -static const char *hifi_src[] __initdata = { "syspll", "pll_media_gate", }; - -static struct hisi_gate_clock hi6220_separated_gate_clks_sys[] __initdata = { +static const char *const mmc0_mux0_p[] = { "pll_ddr_gate", "syspll", }; +static const char *const mmc0_mux1_p[] = { "mmc0_mux0", "pll_media_gate", }; +static const char *const mmc0_src_p[] = { "mmc0srcsel", "mmc0_div", }; +static const char *const mmc1_mux0_p[] = { "pll_ddr_gate", "syspll", }; +static const char *const mmc1_mux1_p[] = { "mmc1_mux0", "pll_media_gate", }; +static const char *const mmc1_src_p[] = { "mmc1srcsel", "mmc1_div", }; +static const char *const mmc2_mux0_p[] = { "pll_ddr_gate", "syspll", }; +static const char *const mmc2_mux1_p[] = { "mmc2_mux0", "pll_media_gate", }; +static const char *const mmc2_src_p[] = { "mmc2srcsel", "mmc2_div", }; +static const char *const mmc0_sample_in[] = { "mmc0_sample", "mmc0_pad", }; +static const char *const mmc1_sample_in[] = { "mmc1_sample", "mmc1_pad", }; +static const char *const mmc2_sample_in[] = { "mmc2_sample", "mmc2_pad", }; +static const char *const uart1_src[] = { "clk_tcxo", "clk_150m", }; +static const char *const uart2_src[] = { "clk_tcxo", "clk_150m", }; +static const char *const uart3_src[] = { "clk_tcxo", "clk_150m", }; +static const char *const uart4_src[] = { "clk_tcxo", "clk_150m", }; +static const char *const hifi_src[] = { "syspll", "pll_media_gate", }; + +static struct hisi_gate_clock hi6220_separated_gate_clks_sys[] = { { HI6220_MMC0_CLK, "mmc0_clk", "mmc0_src", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x200, 0, 0, }, { HI6220_MMC0_CIUCLK, "mmc0_ciuclk", "mmc0_smp_in", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x200, 0, 0, }, { HI6220_MMC1_CLK, "mmc1_clk", "mmc1_src", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x200, 1, 0, }, @@ -146,7 +146,7 @@ static struct hisi_gate_clock hi6220_separated_gate_clks_sys[] __initdata = { { HI6220_CS_ATB_SYSPLL, "cs_atb_syspll", "syspll", CLK_SET_RATE_PARENT|CLK_IS_CRITICAL, 0x270, 12, 0, }, }; -static struct hisi_mux_clock hi6220_mux_clks_sys[] __initdata = { +static struct hisi_mux_clock hi6220_mux_clks_sys[] = { { HI6220_MMC0_SRC, "mmc0_src", mmc0_src_p, ARRAY_SIZE(mmc0_src_p), CLK_SET_RATE_PARENT, 0x4, 0, 1, 0, }, { HI6220_MMC0_SMP_IN, "mmc0_smp_in", mmc0_sample_in, ARRAY_SIZE(mmc0_sample_in), CLK_SET_RATE_PARENT, 0x4, 0, 1, 0, }, { HI6220_MMC1_SRC, "mmc1_src", mmc1_src_p, ARRAY_SIZE(mmc1_src_p), CLK_SET_RATE_PARENT, 0x4, 2, 1, 0, }, @@ -166,7 +166,7 @@ static struct hisi_mux_clock hi6220_mux_clks_sys[] __initdata = { { HI6220_MMC2_MUX1, "mmc2_mux1", mmc2_mux1_p, ARRAY_SIZE(mmc2_mux1_p), CLK_SET_RATE_PARENT, 0x400, 15, 1, CLK_MUX_HIWORD_MASK,}, }; -static struct hi6220_divider_clock hi6220_div_clks_sys[] __initdata = { +static struct hi6220_divider_clock hi6220_div_clks_sys[] = { { HI6220_CLK_BUS, "clk_bus", "clk_300m", CLK_SET_RATE_PARENT, 0x490, 0, 4, 7, }, { HI6220_MMC0_DIV, "mmc0_div", "mmc0_syspll", CLK_SET_RATE_PARENT, 0x494, 0, 6, 7, }, { HI6220_MMC1_DIV, "mmc1_div", "mmc1_syspll", CLK_SET_RATE_PARENT, 0x498, 0, 6, 7, }, @@ -177,32 +177,23 @@ static struct hi6220_divider_clock hi6220_div_clks_sys[] __initdata = { { HI6220_CS_ATB_DIV, "cs_atb_div", "cs_atb_syspll", CLK_SET_RATE_PARENT, 0x4a4, 0, 4, 7, }, }; -static void __init hi6220_clk_sys_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - - clk_data = hisi_clk_init(np, HI6220_SYS_NR_CLKS); - if (!clk_data) - return; - - hisi_clk_register_gate_sep(hi6220_separated_gate_clks_sys, - ARRAY_SIZE(hi6220_separated_gate_clks_sys), clk_data); - - hisi_clk_register_mux(hi6220_mux_clks_sys, - ARRAY_SIZE(hi6220_mux_clks_sys), clk_data); - - hi6220_clk_register_divider(hi6220_div_clks_sys, - ARRAY_SIZE(hi6220_div_clks_sys), clk_data); -} -CLK_OF_DECLARE_DRIVER(hi6220_clk_sys, "hisilicon,hi6220-sysctrl", hi6220_clk_sys_init); - +static const struct hisi_clocks hi6220_sys_clks = { + .nr = HI6220_SYS_NR_CLKS, + .mux_clks = hi6220_mux_clks_sys, + .mux_clks_num = ARRAY_SIZE(hi6220_mux_clks_sys), + .gate_sep_clks = hi6220_separated_gate_clks_sys, + .gate_sep_clks_num = ARRAY_SIZE(hi6220_separated_gate_clks_sys), + .customized_clks = hi6220_div_clks_sys, + .customized_clks_num = ARRAY_SIZE(hi6220_div_clks_sys), + .clk_register_customized = hi6220_clk_register_divider_stub, +}; /* clocks in media controller */ -static const char *clk_1000_1200_src[] __initdata = { "pll_gpu_gate", "media_syspll_src", }; -static const char *clk_1440_1200_src[] __initdata = { "media_syspll_src", "media_pll_src", }; -static const char *clk_1000_1440_src[] __initdata = { "pll_gpu_gate", "media_pll_src", }; +static const char *const clk_1000_1200_src[] = { "pll_gpu_gate", "media_syspll_src", }; +static const char *const clk_1440_1200_src[] = { "media_syspll_src", "media_pll_src", }; +static const char *const clk_1000_1440_src[] = { "pll_gpu_gate", "media_pll_src", }; -static struct hisi_gate_clock hi6220_separated_gate_clks_media[] __initdata = { +static struct hisi_gate_clock hi6220_separated_gate_clks_media[] = { { HI6220_DSI_PCLK, "dsi_pclk", "vpucodec", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x520, 0, 0, }, { HI6220_G3D_PCLK, "g3d_pclk", "vpucodec", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x520, 1, 0, }, { HI6220_ACLK_CODEC_VPU, "aclk_codec_vpu", "ade_core_src", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x520, 3, 0, }, @@ -218,13 +209,13 @@ static struct hisi_gate_clock hi6220_separated_gate_clks_media[] __initdata = { { HI6220_MED_SYSPLL, "media_syspll_src", "media_syspll", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x520, 17, 0, }, }; -static struct hisi_mux_clock hi6220_mux_clks_media[] __initdata = { +static struct hisi_mux_clock hi6220_mux_clks_media[] = { { HI6220_1440_1200, "clk_1440_1200", clk_1440_1200_src, ARRAY_SIZE(clk_1440_1200_src), CLK_SET_RATE_PARENT, 0x51c, 0, 1, 0, }, { HI6220_1000_1200, "clk_1000_1200", clk_1000_1200_src, ARRAY_SIZE(clk_1000_1200_src), CLK_SET_RATE_PARENT, 0x51c, 1, 1, 0, }, { HI6220_1000_1440, "clk_1000_1440", clk_1000_1440_src, ARRAY_SIZE(clk_1000_1440_src), CLK_SET_RATE_PARENT, 0x51c, 6, 1, 0, }, }; -static struct hi6220_divider_clock hi6220_div_clks_media[] __initdata = { +static struct hi6220_divider_clock hi6220_div_clks_media[] = { { HI6220_CODEC_JPEG, "codec_jpeg_aclk", "media_pll_src", CLK_SET_RATE_PARENT, 0xcbc, 0, 4, 23, }, { HI6220_ISP_SCLK_SRC, "isp_sclk_src", "isp_sclk_gate", CLK_SET_RATE_PARENT, 0xcbc, 8, 4, 15, }, { HI6220_ISP_SCLK1, "isp_sclk1", "isp_sclk_gate1", CLK_SET_RATE_PARENT, 0xcbc, 24, 4, 31, }, @@ -234,28 +225,19 @@ static struct hi6220_divider_clock hi6220_div_clks_media[] __initdata = { { HI6220_CODEC_VPU_SRC, "codec_vpu_src", "codec_vpu_gate", CLK_SET_RATE_PARENT, 0xcc4, 24, 6, 31, }, }; -static void __init hi6220_clk_media_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - - clk_data = hisi_clk_init(np, HI6220_MEDIA_NR_CLKS); - if (!clk_data) - return; - - hisi_clk_register_gate_sep(hi6220_separated_gate_clks_media, - ARRAY_SIZE(hi6220_separated_gate_clks_media), clk_data); - - hisi_clk_register_mux(hi6220_mux_clks_media, - ARRAY_SIZE(hi6220_mux_clks_media), clk_data); - - hi6220_clk_register_divider(hi6220_div_clks_media, - ARRAY_SIZE(hi6220_div_clks_media), clk_data); -} -CLK_OF_DECLARE_DRIVER(hi6220_clk_media, "hisilicon,hi6220-mediactrl", hi6220_clk_media_init); - +static const struct hisi_clocks hi6220_media_clks = { + .nr = HI6220_MEDIA_NR_CLKS, + .mux_clks = hi6220_mux_clks_media, + .mux_clks_num = ARRAY_SIZE(hi6220_mux_clks_media), + .gate_sep_clks = hi6220_separated_gate_clks_media, + .gate_sep_clks_num = ARRAY_SIZE(hi6220_separated_gate_clks_media), + .customized_clks = hi6220_div_clks_media, + .customized_clks_num = ARRAY_SIZE(hi6220_div_clks_media), + .clk_register_customized = hi6220_clk_register_divider_stub, +}; /* clocks in pmctrl */ -static struct hisi_gate_clock hi6220_gate_clks_power[] __initdata = { +static struct hisi_gate_clock hi6220_gate_clks_power[] = { { HI6220_PLL_GPU_GATE, "pll_gpu_gate", "gpupll", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x8, 0, 0, }, { HI6220_PLL1_DDR_GATE, "pll1_ddr_gate", "ddrpll1", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x10, 0, 0, }, { HI6220_PLL_DDR_GATE, "pll_ddr_gate", "ddrpll0", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x18, 0, 0, }, @@ -263,26 +245,19 @@ static struct hisi_gate_clock hi6220_gate_clks_power[] __initdata = { { HI6220_PLL0_BBP_GATE, "pll0_bbp_gate", "bbppll0", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x48, 0, 0, }, }; -static struct hi6220_divider_clock hi6220_div_clks_power[] __initdata = { +static struct hi6220_divider_clock hi6220_div_clks_power[] = { { HI6220_DDRC_SRC, "ddrc_src", "ddr_sel_src", CLK_SET_RATE_PARENT, 0x5a8, 0, 4, 0, }, { HI6220_DDRC_AXI1, "ddrc_axi1", "ddrc_src", CLK_SET_RATE_PARENT, 0x5a8, 8, 2, 0, }, }; -static void __init hi6220_clk_power_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - - clk_data = hisi_clk_init(np, HI6220_POWER_NR_CLKS); - if (!clk_data) - return; - - hisi_clk_register_gate(hi6220_gate_clks_power, - ARRAY_SIZE(hi6220_gate_clks_power), clk_data); - - hi6220_clk_register_divider(hi6220_div_clks_power, - ARRAY_SIZE(hi6220_div_clks_power), clk_data); -} -CLK_OF_DECLARE(hi6220_clk_power, "hisilicon,hi6220-pmctrl", hi6220_clk_power_init); +static const struct hisi_clocks hi6220_power_clks = { + .nr = HI6220_POWER_NR_CLKS, + .gate_clks = hi6220_gate_clks_power, + .gate_clks_num = ARRAY_SIZE(hi6220_gate_clks_power), + .customized_clks = hi6220_div_clks_power, + .customized_clks_num = ARRAY_SIZE(hi6220_div_clks_power), + .clk_register_customized = hi6220_clk_register_divider_stub, +}; /* clocks in acpu */ static const struct hisi_gate_clock hi6220_acpu_sc_gate_sep_clks[] = { @@ -290,18 +265,36 @@ static const struct hisi_gate_clock hi6220_acpu_sc_gate_sep_clks[] = { CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, 0xc, 11, 0, }, }; -static void __init hi6220_clk_acpu_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - int nr = ARRAY_SIZE(hi6220_acpu_sc_gate_sep_clks); +static const struct hisi_clocks hi6220_acpu_clks = { + .gate_sep_clks = hi6220_acpu_sc_gate_sep_clks, + .gate_sep_clks_num = ARRAY_SIZE(hi6220_acpu_sc_gate_sep_clks), +}; - clk_data = hisi_clk_init(np, nr); - if (!clk_data) - return; +static const struct of_device_id hi6220_clk_match_table[] = { + { .compatible = "hisilicon,hi6220-aoctrl", + .data = &hi6220_ao_clks }, + { .compatible = "hisilicon,hi6220-sysctrl", + .data = &hi6220_sys_clks }, + { .compatible = "hisilicon,hi6220-mediactrl", + .data = &hi6220_media_clks }, + { .compatible = "hisilicon,hi6220-pmctrl", + .data = &hi6220_power_clks }, + { .compatible = "hisilicon,hi6220-acpu-sctrl", + .data = &hi6220_acpu_clks }, + { } +}; +MODULE_DEVICE_TABLE(of, hi6220_clk_match_table); + +static struct platform_driver hi6220_clk_driver = { + .probe = hisi_clk_probe, + .remove_new = hisi_clk_remove, + .driver = { + .name = "hi6220-clock", + .of_match_table = hi6220_clk_match_table, + }, +}; - hisi_clk_register_gate_sep(hi6220_acpu_sc_gate_sep_clks, - ARRAY_SIZE(hi6220_acpu_sc_gate_sep_clks), - clk_data); -} +module_platform_driver(hi6220_clk_driver); -CLK_OF_DECLARE(hi6220_clk_acpu, "hisilicon,hi6220-acpu-sctrl", hi6220_clk_acpu_init); +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("HiSilicon Hi6220 Clock Driver"); From patchwork Sun Jul 23 16:22:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangfl X-Patchwork-Id: 124513 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1356706vqg; Sun, 23 Jul 2023 10:20:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlGx9zf0RMda5VPaCw4XvDe8EhE76SIQNPQu4s/P6SM0IoflCMlKegxzzuDK8nvTtqJZ4gR4 X-Received: by 2002:a05:6a20:cd:b0:137:7add:b7cd with SMTP id 13-20020a056a2000cd00b001377addb7cdmr8929958pzh.17.1690132839092; Sun, 23 Jul 2023 10:20:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690132839; cv=none; d=google.com; s=arc-20160816; b=NXN1JFCKHKQZ8U+Zkyvxdzcld0/njBUvbgieFMvSLgCiwZS8S+cNBN//XLe/xGm2eu DojAyExWF+t0pkjcQDS1iEc7on+X6gdv22sYtR0x/REal3q6qBEeZtPvGupQ+uQv8dIR QqlzdRmuQY7BkjSsB9jjuWSoY3cXmUaS69V+iFQZ4RjkGEj1j4gHwgOe1oBdcXuevuQk APEhVp4UjFnN8cX3X6djTtRqH1J9fEbuRucr6jbuL7TwByYhzNPrFJWownBOOLnLXcEQ gWfoupV07wIppD1E6TvvdmFlXfR2pPLTfW5Kod8U/mhOptDlW+O7z4d2T6LpCF2QABQu nlgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZNZDSYoGb3uZl1I3ymSzL6L6meDQzuQ8PM9FVmAR7qU=; fh=6op8AbJPoSQyJcsI0L5qUJDM8pym4PtkpWqFZ6dkle0=; b=eisXuA9n3xH8ZEIwkhG5UwVN0wChAk0nEZVi+FSDW4X7r0+B/W/WVIiZtSdYWrh6qd TyjGtcPSAmHtRKA8LwfsefzbjKmiH3WKy99Dum2nYB9Q3B/c7ksbxfKq4XIorpaUZF9A AwhQZhJx9CXDnzCEUpkVSRW8SRuNE7+D+2dhhwMeGA5mCEasOL8v85cqofh8fkw5dOju cQ6M8hQRVSN/Ay8q7voQE/rF1qXNt7Mm5Xi8XhURix9F+CNDpoaAN1nwWiecezdpEcqu qOj4TTJ8T1VEdi5M4jbxED5mVcVh86RMV2VRz2cy8EqOhj0lSmkMFhfxwGtxalF58lq0 Z1hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=PEfU5yjj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c15-20020a056a00248f00b006834175c797si7585130pfv.330.2023.07.23.10.20.15; Sun, 23 Jul 2023 10:20:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=PEfU5yjj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230246AbjGWQ0j (ORCPT + 99 others); Sun, 23 Jul 2023 12:26:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230034AbjGWQ02 (ORCPT ); Sun, 23 Jul 2023 12:26:28 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3BF01999; Sun, 23 Jul 2023 09:26:04 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-55adfa61199so2561412a12.2; Sun, 23 Jul 2023 09:26:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690129548; x=1690734348; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZNZDSYoGb3uZl1I3ymSzL6L6meDQzuQ8PM9FVmAR7qU=; b=PEfU5yjjNgEDTN/b3EIfG3zOydNiwp4jwFDp7XbfB9kgD7nbTsgXc74/g4N49AI68/ 8UuV1157/Ve4YkeLCEUk+cf442JFUvqtuwhirxZQWUJdPyU96L9Ng94Ejnz8Qq3r+dqw 1bSRdLpyGW2gf5qEqa95eJrDCh02NEwPgJonTsm7GuZizmobBFrgnBySgMbUZHETdLhk 3GKQcDjNsD8QsQNRvSDp4gmxNLFIxn4V2u1AYQL73e/VDrj4vBCJpFv5ajTEaKI26cfp CBNRSNsuMZzHNJUTBZF5hZxKRRMsk0uOME286IF8Xaiv1DiMFu97zSE81+5D8yToaauL o1vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690129548; x=1690734348; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZNZDSYoGb3uZl1I3ymSzL6L6meDQzuQ8PM9FVmAR7qU=; b=AeALi36blOio4YpzxVC3ZXy8Zd/iweGD9LbYYWNsQxGxMFnqZtsbIWUupuUSLtpwgS SrQKxxi+n87YR3WTJ+7NAg8HENu5RyN4QL5DFPE6O3eMZV6ztKMy5eihKP5Fv/O89vbx Fp46PXo1+FLpka3E5LVgRlXaDqi+JZCahzXA8PXvoAYMStlPf0pjkundl+1VQpp9NfL7 pw5uPFGaZBqaanIQbpF/gQVVn474/cccjgXGDx6F6L+CXeS+MvL/Eqrx+I1418Qznmqf u5jR7veNybs4+C4a6jglf/CTEHt17L/kTqd20EsmyYIBoOu9ne/KQQJxv1xbBjel1eTP S8nA== X-Gm-Message-State: ABy/qLb8jn9u49yKgH+6oBqkv9/BsBW20YY7G872GuZ3l8n4qXd/pOfr QGEdTuO3F1uGtbfKsnmBxyLGNcdw7nGkIP3V X-Received: by 2002:a17:90b:1b47:b0:263:6114:f0f9 with SMTP id nv7-20020a17090b1b4700b002636114f0f9mr7023160pjb.42.1690129548626; Sun, 23 Jul 2023 09:25:48 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.245.199]) by smtp.gmail.com with ESMTPSA id u3-20020a17090aae8300b00265a7145fe5sm6883787pjq.41.2023.07.23.09.25.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 09:25:48 -0700 (PDT) From: David Yang To: linux-clk@vger.kernel.org Cc: David Yang , Michael Turquette , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH v5 11/13] clk: hisilicon: hip04: Convert into platform driver module Date: Mon, 24 Jul 2023 00:22:36 +0800 Message-Id: <20230723162245.35033-12-mmyangfl@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230723162245.35033-1-mmyangfl@gmail.com> References: <20230723162245.35033-1-mmyangfl@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772232731851482460 X-GMAIL-MSGID: 1772232731851482460 Use common helper functions and register clks with a single of_device_id data. Signed-off-by: David Yang --- drivers/clk/hisilicon/clk-hip04.c | 39 +++++++++++++++++++------------ 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/drivers/clk/hisilicon/clk-hip04.c b/drivers/clk/hisilicon/clk-hip04.c index 785b9faf3ea5..9aa2481781cb 100644 --- a/drivers/clk/hisilicon/clk-hip04.c +++ b/drivers/clk/hisilicon/clk-hip04.c @@ -10,11 +10,8 @@ #include #include -#include -#include -#include +#include #include -#include #include @@ -27,16 +24,28 @@ static struct hisi_fixed_rate_clock hip04_fixed_rate_clks[] __initdata = { { HIP04_CLK_168M, "clk168m", NULL, 0, 168750000, }, }; -static void __init hip04_clk_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; +static const struct hisi_clocks hip04_clks = { + .fixed_rate_clks = hip04_fixed_rate_clks, + .fixed_factor_clks_num = ARRAY_SIZE(hip04_fixed_rate_clks), +}; + +static const struct of_device_id hip04_clk_match_table[] = { + { .compatible = "hisilicon,hip04-clock", + .data = &hip04_clks }, + { } +}; +MODULE_DEVICE_TABLE(of, hip04_clk_match_table); + +static struct platform_driver hip04_clk_driver = { + .probe = hisi_clk_probe, + .remove_new = hisi_clk_remove, + .driver = { + .name = "hip04-clock", + .of_match_table = hip04_clk_match_table, + }, +}; - clk_data = hisi_clk_init(np, HIP04_NR_CLKS); - if (!clk_data) - return; +module_platform_driver(hip04_clk_driver); - hisi_clk_register_fixed_rate(hip04_fixed_rate_clks, - ARRAY_SIZE(hip04_fixed_rate_clks), - clk_data); -} -CLK_OF_DECLARE(hip04_clk, "hisilicon,hip04-clock", hip04_clk_init); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("HiSilicon HiP04 Clock Driver"); From patchwork Sun Jul 23 16:22:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangfl X-Patchwork-Id: 124511 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1345264vqg; Sun, 23 Jul 2023 09:52:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlEpSmQ7pZZr8GK1w+j19MZtoZ00GiXiYOTceopAxUSj2YD7v5VyzVaHDD/xvtNt+18vtoTb X-Received: by 2002:a05:6a20:3248:b0:12c:cfbb:f7e9 with SMTP id hm8-20020a056a20324800b0012ccfbbf7e9mr6069634pzc.47.1690131164688; Sun, 23 Jul 2023 09:52:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690131164; cv=none; d=google.com; s=arc-20160816; b=g44CFIfTmnrjiXxux1PqxjUzm75Lz3fmJDWWRJEsKnFFUX4L6vnYZ6nphRktgDQWSz k/3bn/dEVmTkK4WTWiyaprIHqw8qxtQ1Xf9ETyKLLjzJEYLNx1UmrVZ4CclnDeWPNQVh strAjREu3WQJTMBNLFCeP4wt9eCREQex83O0fCLfIRbXAGEsV5PBiJ1+GU6aGTv7aKK/ BRz4HT6Wyb6eESlVjl0kC0kHs4l/gjA8U62hKk+/ePYx6NlY+04panA6DEgyHgOw8CJq LEcqnabvh4wC7mLjhW5lYS95W1wj6MzVv1OArJecg46kKA4aZ+MELOwCPUVcoK35uKHV 7zUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UO4VB8kjNhkNDNCG7UDzQ3uTczAZ82geNh1f0TcTnsg=; fh=6op8AbJPoSQyJcsI0L5qUJDM8pym4PtkpWqFZ6dkle0=; b=drqkXZ+W/TTEJS2rQZlSazPVW+0xETpAPe/uSk9vJzWhP712aMin+iYgahqWTKoX/Q 0JhHJgbh/a/E0Vmg7k15vnxtzqO0qb964V/jcnoPyoRCDp0KLkiMQ9kPICqd/0BkBNID hQsJQg4bpMEczv6bFDtcgTSMpRVT9Zw8X9LXFlhsvNVO9P7ZqMKkG/mFgb9hUyMUCSlV QQFoBnoqAlFpTgafhp9bZ1ywA5vnGJyv2YWNypgLUYCQC0RpUD3XV3AIbp+NYidxSLV+ 9Uv9uFNl3CkdFThzDnTCyqcqWqseGw8LhX+1ho9/2hGFrZINJqz7quWUPHlXB8hMXuFi ZANw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ZybVVVzn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q10-20020a63980a000000b0055be9526b7fsi7432416pgd.416.2023.07.23.09.52.31; Sun, 23 Jul 2023 09:52:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ZybVVVzn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230228AbjGWQ0s (ORCPT + 99 others); Sun, 23 Jul 2023 12:26:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230226AbjGWQ0f (ORCPT ); Sun, 23 Jul 2023 12:26:35 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94EEA1732; Sun, 23 Jul 2023 09:26:10 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-53482b44007so1707195a12.2; Sun, 23 Jul 2023 09:26:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690129561; x=1690734361; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UO4VB8kjNhkNDNCG7UDzQ3uTczAZ82geNh1f0TcTnsg=; b=ZybVVVzn5aEj5B/y12Bnf4PEIrj3sWeUmxRYSpbLXHWKuB4mdWeSAOEffGod/YskVh UuB2uV341Z+9tZgfPnm5xKr+sS/twFvKdrIoOEI3Pk4bDz47sjmUiSf0IyIisISQQBh4 F24s6yzbAOzoXPWVCevJHhILDMkPUvrtaJuY9/TR1wmR+pLJlSeRYN0328ReZ3UI6FEl MiljFbKfxiDleaI19WdylOlijflcK1LoI2urC4kI15FR1EHJ83EMudqhlZ/N9TaHMh8b PJgjqV2+Td2hTOggjCj1LYXSwbS7haVKhPLwBfkPHNcgNPbazXQXr2DYCD1MLYa55P9Z nn8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690129561; x=1690734361; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UO4VB8kjNhkNDNCG7UDzQ3uTczAZ82geNh1f0TcTnsg=; b=Chx6lPmdTfPobcrvEKoCjfw0Rq6foyKIxHwK3Cv0ZOx59YU4wDGeCX/dvfUItqjuet ZMjMaX93cf3YT6zj3hZCvVEkMLp+08PPbnkiE0knkKLYS0yrV8uFuQVNkaQHgSbM6WuY 45NByQS+fiHXAU0xF4ed/S5kp7xTVVvGJGT/fiL8RcONwd4nENrDVGJisVtWN0rAujri ZFyfYoP1/fsbepk7GSibljln0E6binmKH6wBMWdctJQaLR/QympXHUVz+6/9MzDD3a8Q 2mJU9gwUPH9Z5fDlXdYlu8/FdPejsbIKGOZOBOeACnDMFyoYy3G5X7QbCJ8lNVzDbA9K cOOw== X-Gm-Message-State: ABy/qLbhYHUBJjiwws4X2kUT/8T8uEklc+Pp6yQI8yOYOGX4s3UQdIUK GzZubPGamkjXTUuof4KR14XmHjw9y/f+ztIY X-Received: by 2002:a17:90a:34ce:b0:268:1b7f:257b with SMTP id m14-20020a17090a34ce00b002681b7f257bmr515029pjf.24.1690129561096; Sun, 23 Jul 2023 09:26:01 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.245.199]) by smtp.gmail.com with ESMTPSA id u3-20020a17090aae8300b00265a7145fe5sm6883787pjq.41.2023.07.23.09.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 09:26:00 -0700 (PDT) From: David Yang To: linux-clk@vger.kernel.org Cc: David Yang , Michael Turquette , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH v5 12/13] clk: hisilicon: hix5hd2: Convert into platform driver module Date: Mon, 24 Jul 2023 00:22:37 +0800 Message-Id: <20230723162245.35033-13-mmyangfl@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230723162245.35033-1-mmyangfl@gmail.com> References: <20230723162245.35033-1-mmyangfl@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772230975813660127 X-GMAIL-MSGID: 1772230975813660127 Use common helper functions and register clks with a single of_device_id data. Signed-off-by: David Yang --- drivers/clk/hisilicon/clk-hix5hd2.c | 85 ++++++++++++++++++----------- 1 file changed, 52 insertions(+), 33 deletions(-) diff --git a/drivers/clk/hisilicon/clk-hix5hd2.c b/drivers/clk/hisilicon/clk-hix5hd2.c index 64bdd3f05725..6f988a7574b4 100644 --- a/drivers/clk/hisilicon/clk-hix5hd2.c +++ b/drivers/clk/hisilicon/clk-hix5hd2.c @@ -4,13 +4,17 @@ * Copyright (c) 2014 Hisilicon Limited. */ -#include #include + #include #include +#include +#include +#include + #include "clk.h" -static struct hisi_fixed_rate_clock hix5hd2_fixed_rate_clks[] __initdata = { +static struct hisi_fixed_rate_clock hix5hd2_fixed_rate_clks[] = { { HIX5HD2_FIXED_1200M, "1200m", NULL, 0, 1200000000, }, { HIX5HD2_FIXED_400M, "400m", NULL, 0, 400000000, }, { HIX5HD2_FIXED_48M, "48m", NULL, 0, 48000000, }, @@ -43,19 +47,19 @@ static struct hisi_fixed_rate_clock hix5hd2_fixed_rate_clks[] __initdata = { { HIX5HD2_FIXED_83M, "83m", NULL, 0, 83333333, }, }; -static const char *const sfc_mux_p[] __initconst = { +static const char *const sfc_mux_p[] = { "24m", "150m", "200m", "100m", "75m", }; static u32 sfc_mux_table[] = {0, 4, 5, 6, 7}; -static const char *const sdio_mux_p[] __initconst = { +static const char *const sdio_mux_p[] = { "75m", "100m", "50m", "15m", }; static u32 sdio_mux_table[] = {0, 1, 2, 3}; -static const char *const fephy_mux_p[] __initconst = { "25m", "125m"}; +static const char *const fephy_mux_p[] = { "25m", "125m"}; static u32 fephy_mux_table[] = {0, 1}; -static struct hisi_mux_clock hix5hd2_mux_clks[] __initdata = { +static struct hisi_mux_clock hix5hd2_mux_clks[] = { { HIX5HD2_SFC_MUX, "sfc_mux", sfc_mux_p, ARRAY_SIZE(sfc_mux_p), CLK_SET_RATE_PARENT, 0x5c, 8, 3, 0, sfc_mux_table, }, { HIX5HD2_MMC_MUX, "mmc_mux", sdio_mux_p, ARRAY_SIZE(sdio_mux_p), @@ -67,7 +71,7 @@ static struct hisi_mux_clock hix5hd2_mux_clks[] __initdata = { CLK_SET_RATE_PARENT, 0x120, 8, 2, 0, fephy_mux_table, }, }; -static struct hisi_gate_clock hix5hd2_gate_clks[] __initdata = { +static struct hisi_gate_clock hix5hd2_gate_clks[] = { /* sfc */ { HIX5HD2_SFC_CLK, "clk_sfc", "sfc_mux", CLK_SET_RATE_PARENT, 0x5c, 0, 0, }, @@ -153,7 +157,7 @@ struct hix5hd2_clk_complex { u32 phy_rst_mask; }; -static struct hix5hd2_complex_clock hix5hd2_complex_clks[] __initdata = { +static struct hix5hd2_complex_clock hix5hd2_complex_clks[] = { {"clk_mac0", "clk_fephy", HIX5HD2_MAC0_CLK, 0xcc, 0xa, 0x500, 0x120, 0, 0x10, TYPE_ETHER}, {"clk_mac1", "clk_fwd_sys", HIX5HD2_MAC1_CLK, @@ -249,21 +253,22 @@ static const struct clk_ops clk_complex_ops = { .disable = clk_complex_disable, }; -static void __init -hix5hd2_clk_register_complex(struct hix5hd2_complex_clock *clks, int nums, +static int +hix5hd2_clk_register_complex(struct device *dev, const void *clocks, size_t num, struct hisi_clock_data *data) { + const struct hix5hd2_complex_clock *clks = clocks; void __iomem *base = data->base; int i; - for (i = 0; i < nums; i++) { + for (i = 0; i < num; i++) { struct hix5hd2_clk_complex *p_clk; struct clk *clk; struct clk_init_data init; p_clk = kzalloc(sizeof(*p_clk), GFP_KERNEL); if (!p_clk) - return; + return -ENOMEM; init.name = clks[i].name; if (clks[i].type == TYPE_ETHER) @@ -289,31 +294,45 @@ hix5hd2_clk_register_complex(struct hix5hd2_complex_clock *clks, int nums, kfree(p_clk); pr_err("%s: failed to register clock %s\n", __func__, clks[i].name); - continue; + return PTR_ERR(p_clk); } data->clk_data.clks[clks[i].id] = clk; } -} -static void __init hix5hd2_clk_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - - clk_data = hisi_clk_init(np, HIX5HD2_NR_CLKS); - if (!clk_data) - return; - - hisi_clk_register_fixed_rate(hix5hd2_fixed_rate_clks, - ARRAY_SIZE(hix5hd2_fixed_rate_clks), - clk_data); - hisi_clk_register_mux(hix5hd2_mux_clks, ARRAY_SIZE(hix5hd2_mux_clks), - clk_data); - hisi_clk_register_gate(hix5hd2_gate_clks, - ARRAY_SIZE(hix5hd2_gate_clks), clk_data); - hix5hd2_clk_register_complex(hix5hd2_complex_clks, - ARRAY_SIZE(hix5hd2_complex_clks), - clk_data); + return 0; } -CLK_OF_DECLARE(hix5hd2_clk, "hisilicon,hix5hd2-clock", hix5hd2_clk_init); +static const struct hisi_clocks hix5hd2_clks = { + .nr = HIX5HD2_NR_CLKS, + .fixed_rate_clks = hix5hd2_fixed_rate_clks, + .fixed_factor_clks_num = ARRAY_SIZE(hix5hd2_fixed_rate_clks), + .mux_clks = hix5hd2_mux_clks, + .mux_clks_num = ARRAY_SIZE(hix5hd2_mux_clks), + .gate_clks = hix5hd2_gate_clks, + .gate_clks_num = ARRAY_SIZE(hix5hd2_gate_clks), + .customized_clks = hix5hd2_complex_clks, + .customized_clks_num = ARRAY_SIZE(hix5hd2_complex_clks), + .clk_register_customized = hix5hd2_clk_register_complex, +}; + +static const struct of_device_id hix5hd2_clk_match_table[] = { + { .compatible = "hisilicon,hix5hd2-clock", + .data = &hix5hd2_clks }, + { } +}; +MODULE_DEVICE_TABLE(of, hix5hd2_clk_match_table); + +static struct platform_driver hix5hd2_clk_driver = { + .probe = hisi_clk_probe, + .remove_new = hisi_clk_remove, + .driver = { + .name = "hix5hd2-clock", + .of_match_table = hix5hd2_clk_match_table, + }, +}; + +module_platform_driver(hix5hd2_clk_driver); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("HiSilicon Hix5hd2 Clock Driver"); From patchwork Sun Jul 23 16:22:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangfl X-Patchwork-Id: 124518 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1381711vqg; Sun, 23 Jul 2023 11:33:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlEvR/cZka7zFkKAuud5Vz95ohdXFIUwvaeYhzqHgoC/YGa06TJMNrVW7PSALl41I6rspoIc X-Received: by 2002:a05:6a20:7d8f:b0:134:73f6:5832 with SMTP id v15-20020a056a207d8f00b0013473f65832mr11345299pzj.16.1690137193380; Sun, 23 Jul 2023 11:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690137193; cv=none; d=google.com; s=arc-20160816; b=oFiab5dNHEvjC8W50Xvt4iuBrGdXkEcuWa4NWM/hnFLRqAMWRzQQIrsfnYP7SJLwtZ RP2yr39NzhdW3GfLGmtrqWB/ZMk9YzaNwDZKtkeil2gtnshqD9M+6OE7kbOa/wt5oSnx 1/oEkwosfnE9wxhQeo+uehDVOEnHnnX+mAdhRg39WREzgnWBJSdT0SmEuey6dQeBuEBa 0UskNj+4s3niPvb5RY0UR3dBiWbh7elhY5ZCH6QL+p4N3xkTbOs33ovCtyisQrKeIfwU JWVEi68CVO4U2tHajWSeddCBVaaLxj+U23bNX8vsb6nETl1Z7Z19rGqZhWF1W8A/EKqe Kf8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9oovTwLEQPCWKcnGGfyUizOeQBNM5wHrp5154CH8CHI=; fh=0Ct5L75ES7kcLIXEE7WxKQVutRGLAzLsT+h9we2Bt4w=; b=uCxFrH10Kc3it4HudVoshxTJtugmZy+/PljD+gVIFNIxjMmPePK1M+nC4OVVb3l0Sv ix6TdJCUgqrZMojBZn8TzfYxmi/MzYfvjG5rCIRNtC+JrqKVV3au6/r4bd3w2K4+qozg OwqY7JsxN6II7T92NAwwpBf8a9aRkQYx00dyOwk59P4IJfBjNk82pRAy4OyGrJ35XvBk gGnSEegPwGdAsoMsYirMz/uTsLTwFDYczWz5ZV16YkgwYTeQds3no/W2p1y3toARjKNf lixa+R71bVMiiyG6o9vNlvSEzO4QSIx2/AVQeNI2DxfQZ5fNqcrV+il3uQFQJqRz9HiN kesg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Q6MC0sFE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w30-20020a63af1e000000b0055ad86f58fcsi6005488pge.553.2023.07.23.11.32.49; Sun, 23 Jul 2023 11:33:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Q6MC0sFE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230215AbjGWQ1N (ORCPT + 99 others); Sun, 23 Jul 2023 12:27:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230194AbjGWQ1F (ORCPT ); Sun, 23 Jul 2023 12:27:05 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2015F1706; Sun, 23 Jul 2023 09:26:38 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-262e5e71978so2262119a91.1; Sun, 23 Jul 2023 09:26:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690129587; x=1690734387; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9oovTwLEQPCWKcnGGfyUizOeQBNM5wHrp5154CH8CHI=; b=Q6MC0sFEif1L6dbiJ+y0OcJyjSF09Bvdo6pWqmkMm0+rNfgT6eHF9BQUXkm41G/HVn 7rIYTB0PCc8+qsueHhd5qpul7shJrfx5fIJfohiCSfeRLdZuFfpzUok4KaUx9avRCl5K k04y8bhQS1IPLN7RL4YJA65AcBo1HJYnwytHNYVVPnOocG6yX/EB9E8GR7wP+CRpvnCZ zx/M3DIPKxC2P1CtITI4OLdpI7yxzJDnIA44AwYGMjOZNt3P3zjIUt0uGH8PFxJiUIMr fPJK/HKHPNFKH/MfezBZvhd2tInfbw0PVl1azRS60/GCdbXWiKb6XaBEk81Ldd/GDWYm UK0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690129587; x=1690734387; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9oovTwLEQPCWKcnGGfyUizOeQBNM5wHrp5154CH8CHI=; b=K40fXsdXBxy1ANuBiDkM2Jh5I9d5yaLFt83d61LvYpajEgGk1n+XODZ2YJlYf9WVBe izEE4vLeyvwNTJF27U8O4IxSr+Rw4OzXTC/LLdilFTkXnPrbvHPcVE9Kfp0zxQn43vd5 vgXFx4oGSIyRVVTl0ZfCsYCDA6Oum8AIQlPn/JcYm7WSoFLp7nAytQSqNmo5zwCEgukd U7KzyzzPMs/gKQ0fFBvllhZTPHzROnbfy1zTl6zA3XMsx1MMRDfes8blrk0YXaLu0INT LzCGbVYDVdrNeZ3p4WOBpkKpOIFJj0RS5WADjIM3ShtH01fNtVmu6sgtvG6GSFFP2EHX NPQg== X-Gm-Message-State: ABy/qLatJ/QxG/npSgJugyPfUmwi5UmWH8i0lDYjOCp3ZnTS7iQ30hsR 5P4cG3rb/I4m4hXHMiX3gCNRLOFQ2tEZcyMDtq4= X-Received: by 2002:a17:90b:2301:b0:263:f73d:9f50 with SMTP id mt1-20020a17090b230100b00263f73d9f50mr11128440pjb.19.1690129587231; Sun, 23 Jul 2023 09:26:27 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.245.199]) by smtp.gmail.com with ESMTPSA id u3-20020a17090aae8300b00265a7145fe5sm6883787pjq.41.2023.07.23.09.26.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 09:26:27 -0700 (PDT) From: David Yang To: linux-clk@vger.kernel.org Cc: David Yang , Michael Turquette , Stephen Boyd , Conor Dooley , Nick Alcock , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , linux-kernel@vger.kernel.org Subject: [PATCH v5 13/13] clk: hisilicon: Migrate devm APIs Date: Mon, 24 Jul 2023 00:22:38 +0800 Message-Id: <20230723162245.35033-14-mmyangfl@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230723162245.35033-1-mmyangfl@gmail.com> References: <20230723162245.35033-1-mmyangfl@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772237297572051742 X-GMAIL-MSGID: 1772237297572051742 Migrates devm APIs for HiSilicon clock drivers. Signed-off-by: David Yang --- drivers/clk/hisilicon/clk-hi3559a.c | 29 +- drivers/clk/hisilicon/clk-hi3620.c | 29 +- drivers/clk/hisilicon/clk-hi6220-stub.c | 9 +- drivers/clk/hisilicon/clk-hi6220.c | 4 +- drivers/clk/hisilicon/clk-hisi-phase.c | 13 +- drivers/clk/hisilicon/clk-hix5hd2.c | 15 +- drivers/clk/hisilicon/clk.c | 430 +++++++--------------- drivers/clk/hisilicon/clk.h | 99 +++-- drivers/clk/hisilicon/clkdivider-hi6220.c | 24 +- drivers/clk/hisilicon/clkgate-separated.c | 26 +- 10 files changed, 266 insertions(+), 412 deletions(-) diff --git a/drivers/clk/hisilicon/clk-hi3559a.c b/drivers/clk/hisilicon/clk-hi3559a.c index 092a5356e586..2fd8340363e5 100644 --- a/drivers/clk/hisilicon/clk-hi3559a.c +++ b/drivers/clk/hisilicon/clk-hi3559a.c @@ -457,17 +457,16 @@ hisi_clk_register_pll(struct device *dev, const void *clocks, { const struct hi3559av100_pll_clock *clks = clocks; void __iomem *base = data->base; - struct hi3559av100_clk_pll *p_clk = NULL; - struct clk *clk = NULL; + struct hi3559av100_clk_pll *p_clk; struct clk_init_data init; int i; - - p_clk = devm_kzalloc(dev, sizeof(*p_clk) * num, GFP_KERNEL); - - if (!p_clk) - return -ENOMEM; + int ret; for (i = 0; i < num; i++) { + p_clk = devm_kzalloc(dev, sizeof(*p_clk), GFP_KERNEL); + if (!p_clk) + return -ENOMEM; + init.name = clks[i].name; init.flags = 0; init.parent_names = @@ -490,16 +489,14 @@ hisi_clk_register_pll(struct device *dev, const void *clocks, p_clk->refdiv_width = clks[i].refdiv_width; p_clk->hw.init = &init; - clk = clk_register(NULL, &p_clk->hw); - if (IS_ERR(clk)) { - devm_kfree(dev, p_clk); + ret = devm_clk_hw_register(dev, &p_clk->hw); + if (ret) { dev_err(dev, "%s: failed to register clock %s\n", - __func__, clks[i].name); - return PTR_ERR(clk); + __func__, clks[i].name); + return ret; } - data->clk_data.clks[clks[i].id] = clk; - p_clk++; + data->clk_data->hws[clks[i].id] = &p_clk->hw; } return 0; @@ -628,7 +625,7 @@ static int hi3559av100_shub_default_clk_set(struct device *dev, struct hisi_cloc void __iomem *crg_base; unsigned int val; - crg_base = ioremap(CRG_BASE_ADDR, SZ_4K); + crg_base = devm_ioremap(dev, CRG_BASE_ADDR, SZ_4K); /* SSP: 192M/2 */ val = readl_relaxed(crg_base + 0x20); @@ -640,7 +637,7 @@ static int hi3559av100_shub_default_clk_set(struct device *dev, struct hisi_cloc val |= (0x1 << 28); writel_relaxed(val, crg_base + 0x1C); - iounmap(crg_base); + devm_iounmap(dev, crg_base); crg_base = NULL; return 0; diff --git a/drivers/clk/hisilicon/clk-hi3620.c b/drivers/clk/hisilicon/clk-hi3620.c index a08778de8dc2..b831bb90a61a 100644 --- a/drivers/clk/hisilicon/clk-hi3620.c +++ b/drivers/clk/hisilicon/clk-hi3620.c @@ -11,12 +11,10 @@ #include #include +#include #include #include -#include -#include #include -#include #include @@ -399,15 +397,15 @@ static const struct clk_ops clk_mmc_ops = { .recalc_rate = mmc_clk_recalc_rate, }; -static struct clk * +static struct clk_hw * clk_register_hisi_mmc(struct device *dev, const struct hisi_mmc_clock *mmc_clk, void __iomem *base) { struct clk_mmc *mclk; - struct clk *clk; struct clk_init_data init; + int ret; - mclk = kzalloc(sizeof(*mclk), GFP_KERNEL); + mclk = devm_kzalloc(dev, sizeof(*mclk), GFP_KERNEL); if (!mclk) return ERR_PTR(-ENOMEM); @@ -431,26 +429,31 @@ clk_register_hisi_mmc(struct device *dev, const struct hisi_mmc_clock *mmc_clk, mclk->sam_off = mmc_clk->sam_off; mclk->sam_bits = mmc_clk->sam_bits; - clk = clk_register(NULL, &mclk->hw); - if (WARN_ON(IS_ERR(clk))) - kfree(mclk); - return clk; + ret = devm_clk_hw_register(dev, &mclk->hw); + if (ret) { + dev_err(dev, "%s: failed to register clock %s\n", + __func__, init.name); + return ERR_PTR(ret); + } + + return &mclk->hw; } static int hisi_register_clk_mmc(struct device *dev, const void *clocks, size_t num, struct hisi_clock_data *data) { const struct hisi_mmc_clock *clks = clocks; + int i; - for (int i = 0; i < num; i++) { - struct clk *clk = clk_register_hisi_mmc(dev, &clks[i], data->base); + for (i = 0; i < num; i++) { + struct clk_hw *clk = clk_register_hisi_mmc(dev, &clks[i], data->base); if (IS_ERR(clk)) { pr_err("%s: failed to register clock %s\n", __func__, clks[i].name); return PTR_ERR(clk); } - data->clk_data.clks[clks[i].id] = clk; + data->clk_data->hws[clks[i].id] = clk; } return 0; diff --git a/drivers/clk/hisilicon/clk-hi6220-stub.c b/drivers/clk/hisilicon/clk-hi6220-stub.c index 4fdee4424d82..dd996a43958e 100644 --- a/drivers/clk/hisilicon/clk-hi6220-stub.c +++ b/drivers/clk/hisilicon/clk-hi6220-stub.c @@ -195,7 +195,6 @@ static int hi6220_stub_clk_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct clk_init_data init; struct hi6220_stub_clk *stub_clk; - struct clk *clk; struct device_node *np = pdev->dev.of_node; int ret; @@ -233,11 +232,11 @@ static int hi6220_stub_clk_probe(struct platform_device *pdev) init.num_parents = 0; init.flags = 0; - clk = devm_clk_register(dev, &stub_clk->hw); - if (IS_ERR(clk)) - return PTR_ERR(clk); + ret = devm_clk_hw_register(dev, &stub_clk->hw); + if (ret) + return ret; - ret = of_clk_add_provider(np, of_clk_src_simple_get, clk); + ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, &stub_clk->hw); if (ret) { dev_err(dev, "failed to register OF clock provider\n"); return ret; diff --git a/drivers/clk/hisilicon/clk-hi6220.c b/drivers/clk/hisilicon/clk-hi6220.c index 6eac73408745..50ae5df4070b 100644 --- a/drivers/clk/hisilicon/clk-hi6220.c +++ b/drivers/clk/hisilicon/clk-hi6220.c @@ -20,9 +20,7 @@ static int hi6220_clk_register_divider_stub(struct device *dev, const void *clks, size_t num, struct hisi_clock_data *data) { - /* INCOMPLETE PATCH */ - hi6220_clk_register_divider(clks, num, data); - return 0; + return hi6220_clk_register_divider(dev, clks, num, data); } /* clocks in AO (always on) controller */ diff --git a/drivers/clk/hisilicon/clk-hisi-phase.c b/drivers/clk/hisilicon/clk-hisi-phase.c index ba6afad66a2b..15a23dd6edb1 100644 --- a/drivers/clk/hisilicon/clk-hisi-phase.c +++ b/drivers/clk/hisilicon/clk-hisi-phase.c @@ -5,11 +5,11 @@ * Simple HiSilicon phase clock implementation. */ +#include #include #include #include #include -#include #include "clk.h" @@ -90,12 +90,13 @@ static const struct clk_ops clk_phase_ops = { .set_phase = hisi_clk_set_phase, }; -struct clk *clk_register_hisi_phase(struct device *dev, +struct clk_hw *devm_clk_hw_register_hisi_phase(struct device *dev, const struct hisi_phase_clock *clks, void __iomem *base, spinlock_t *lock) { struct clk_hisi_phase *phase; struct clk_init_data init; + int ret; phase = devm_kzalloc(dev, sizeof(struct clk_hisi_phase), GFP_KERNEL); if (!phase) @@ -116,6 +117,10 @@ struct clk *clk_register_hisi_phase(struct device *dev, phase->phase_num = clks->phase_num; phase->hw.init = &init; - return devm_clk_register(dev, &phase->hw); + ret = devm_clk_hw_register(dev, &phase->hw); + if (ret) + return ERR_PTR(ret); + + return &phase->hw; } -EXPORT_SYMBOL_GPL(clk_register_hisi_phase); +EXPORT_SYMBOL_GPL(devm_clk_hw_register_hisi_phase); diff --git a/drivers/clk/hisilicon/clk-hix5hd2.c b/drivers/clk/hisilicon/clk-hix5hd2.c index 6f988a7574b4..8bf9692affce 100644 --- a/drivers/clk/hisilicon/clk-hix5hd2.c +++ b/drivers/clk/hisilicon/clk-hix5hd2.c @@ -6,7 +6,7 @@ #include -#include +#include #include #include #include @@ -260,13 +260,13 @@ hix5hd2_clk_register_complex(struct device *dev, const void *clocks, size_t num, const struct hix5hd2_complex_clock *clks = clocks; void __iomem *base = data->base; int i; + int ret; for (i = 0; i < num; i++) { struct hix5hd2_clk_complex *p_clk; - struct clk *clk; struct clk_init_data init; - p_clk = kzalloc(sizeof(*p_clk), GFP_KERNEL); + p_clk = devm_kzalloc(dev, sizeof(*p_clk), GFP_KERNEL); if (!p_clk) return -ENOMEM; @@ -289,15 +289,14 @@ hix5hd2_clk_register_complex(struct device *dev, const void *clocks, size_t num, p_clk->phy_rst_mask = clks[i].phy_rst_mask; p_clk->hw.init = &init; - clk = clk_register(NULL, &p_clk->hw); - if (IS_ERR(clk)) { - kfree(p_clk); + ret = devm_clk_hw_register(dev, &p_clk->hw); + if (ret) { pr_err("%s: failed to register clock %s\n", __func__, clks[i].name); - return PTR_ERR(p_clk); + return ret; } - data->clk_data.clks[clks[i].id] = clk; + data->clk_data->hws[clks[i].id] = &p_clk->hw; } return 0; diff --git a/drivers/clk/hisilicon/clk.c b/drivers/clk/hisilicon/clk.c index aa8908714cd0..9ff31dd7ec15 100644 --- a/drivers/clk/hisilicon/clk.c +++ b/drivers/clk/hisilicon/clk.c @@ -4,6 +4,7 @@ * * Copyright (c) 2012-2013 Hisilicon Limited. * Copyright (c) 2012-2013 Linaro Limited. + * Copyright (c) 2023 David Yang * * Author: Haojian Zhuang * Xin Li @@ -13,6 +14,8 @@ #include #include #include +#include +#include #include #include #include @@ -23,343 +26,214 @@ static DEFINE_SPINLOCK(hisi_clk_lock); -struct hisi_clock_data *hisi_clk_alloc(struct platform_device *pdev, - int nr_clks) +struct hisi_clock_data *hisi_clk_init(struct device_node *np, size_t nr) { - struct hisi_clock_data *clk_data; - struct resource *res; - struct clk **clk_table; - - clk_data = devm_kmalloc(&pdev->dev, sizeof(*clk_data), GFP_KERNEL); - if (!clk_data) - return NULL; - - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) - return NULL; - clk_data->base = devm_ioremap(&pdev->dev, - res->start, resource_size(res)); - if (!clk_data->base) - return NULL; - - clk_table = devm_kmalloc_array(&pdev->dev, nr_clks, - sizeof(*clk_table), - GFP_KERNEL); - if (!clk_table) - return NULL; - - clk_data->clk_data.clks = clk_table; - clk_data->clk_data.clk_num = nr_clks; - - return clk_data; -} -EXPORT_SYMBOL_GPL(hisi_clk_alloc); - -struct hisi_clock_data *hisi_clk_init(struct device_node *np, - int nr_clks) -{ - struct hisi_clock_data *clk_data; - struct clk **clk_table; void __iomem *base; + struct hisi_clock_data *data; + int ret; + int i; base = of_iomap(np, 0); if (!base) { pr_err("%s: failed to map clock registers\n", __func__); - goto err; + return NULL; } - clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL); - if (!clk_data) - goto err; + data = kmalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return NULL; - clk_data->base = base; - clk_table = kcalloc(nr_clks, sizeof(*clk_table), GFP_KERNEL); - if (!clk_table) + data->clk_data = kzalloc(sizeof(*data->clk_data) + nr * sizeof(data->clk_data->hws[0]), + GFP_KERNEL); + if (!data->clk_data) goto err_data; - clk_data->clk_data.clks = clk_table; - clk_data->clk_data.clk_num = nr_clks; - of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data->clk_data); - return clk_data; + ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, data->clk_data); + if (ret) + goto err_clk; + + data->base = base; + data->clks = NULL; + data->clk_data->num = nr; + for (i = 0; i < nr; i++) + data->clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER); + + return data; + +err_clk: + kfree(data->clk_data); err_data: - kfree(clk_data); -err: + kfree(data); return NULL; } EXPORT_SYMBOL_GPL(hisi_clk_init); +#define hisi_clk_unregister_fn(type) \ +static void hisi_clk_unregister_##type(struct hisi_clock_data *data) \ +{ \ + for (int i = 0; i < data->clks->type##_clks_num; i++) { \ + struct clk_hw *clk = data->clk_data->hws[data->clks->type##_clks[i].id]; \ +\ + if (clk && !IS_ERR(clk)) \ + clk_hw_unregister_##type(clk); \ + } \ +} + +hisi_clk_unregister_fn(fixed_rate) +hisi_clk_unregister_fn(fixed_factor) + void hisi_clk_free(struct device_node *np, struct hisi_clock_data *data) { if (data->clks) { if (data->clks->fixed_rate_clks_num) - hisi_clk_unregister_fixed_rate(data->clks->fixed_rate_clks, - data->clks->fixed_rate_clks_num, - data); + hisi_clk_unregister_fixed_rate(data); if (data->clks->fixed_factor_clks_num) - hisi_clk_unregister_fixed_factor(data->clks->fixed_factor_clks, - data->clks->fixed_factor_clks_num, - data); + hisi_clk_unregister_fixed_factor(data); } of_clk_del_provider(np); - kfree(data->clk_data.clks); + kfree(data->clk_data); kfree(data); } EXPORT_SYMBOL_GPL(hisi_clk_free); int hisi_clk_register_fixed_rate(const struct hisi_fixed_rate_clock *clks, - int nums, struct hisi_clock_data *data) + size_t num, struct hisi_clock_data *data) { - struct clk *clk; + struct clk_hw *clk; int i; - for (i = 0; i < nums; i++) { - clk = clk_register_fixed_rate(NULL, clks[i].name, - clks[i].parent_name, - clks[i].flags, - clks[i].fixed_rate); + for (i = 0; i < num; i++) { + const struct hisi_fixed_rate_clock *p_clk = &clks[i]; + + clk = clk_hw_register_fixed_rate(NULL, p_clk->name, p_clk->parent_name, + p_clk->flags, p_clk->fixed_rate); + if (IS_ERR(clk)) { pr_err("%s: failed to register clock %s\n", - __func__, clks[i].name); + __func__, p_clk->name); goto err; } - data->clk_data.clks[clks[i].id] = clk; + + data->clk_data->hws[p_clk->id] = clk; } return 0; err: while (i--) - clk_unregister_fixed_rate(data->clk_data.clks[clks[i].id]); - + clk_hw_unregister_fixed_rate(data->clk_data->hws[clks[i].id]); return PTR_ERR(clk); } EXPORT_SYMBOL_GPL(hisi_clk_register_fixed_rate); int hisi_clk_register_fixed_factor(const struct hisi_fixed_factor_clock *clks, - int nums, - struct hisi_clock_data *data) + size_t num, struct hisi_clock_data *data) { - struct clk *clk; + struct clk_hw *clk; int i; - for (i = 0; i < nums; i++) { - clk = clk_register_fixed_factor(NULL, clks[i].name, - clks[i].parent_name, - clks[i].flags, clks[i].mult, - clks[i].div); - if (IS_ERR(clk)) { - pr_err("%s: failed to register clock %s\n", - __func__, clks[i].name); - goto err; - } - data->clk_data.clks[clks[i].id] = clk; - } - - return 0; - -err: - while (i--) - clk_unregister_fixed_factor(data->clk_data.clks[clks[i].id]); - - return PTR_ERR(clk); -} -EXPORT_SYMBOL_GPL(hisi_clk_register_fixed_factor); + for (i = 0; i < num; i++) { + const struct hisi_fixed_factor_clock *p_clk = &clks[i]; -int hisi_clk_register_mux(const struct hisi_mux_clock *clks, - int nums, struct hisi_clock_data *data) -{ - struct clk *clk; - void __iomem *base = data->base; - int i; - - for (i = 0; i < nums; i++) { - u32 mask = BIT(clks[i].width) - 1; + clk = clk_hw_register_fixed_factor(NULL, p_clk->name, p_clk->parent_name, + p_clk->flags, p_clk->mult, p_clk->div); - clk = clk_register_mux_table(NULL, clks[i].name, - clks[i].parent_names, - clks[i].num_parents, clks[i].flags, - base + clks[i].offset, clks[i].shift, - mask, clks[i].mux_flags, - clks[i].table, &hisi_clk_lock); if (IS_ERR(clk)) { pr_err("%s: failed to register clock %s\n", - __func__, clks[i].name); + __func__, p_clk->name); goto err; } - if (clks[i].alias) - clk_register_clkdev(clk, clks[i].alias, NULL); - - data->clk_data.clks[clks[i].id] = clk; + data->clk_data->hws[p_clk->id] = clk; } return 0; err: while (i--) - clk_unregister_mux(data->clk_data.clks[clks[i].id]); - + clk_hw_unregister_fixed_rate(data->clk_data->hws[clks[i].id]); return PTR_ERR(clk); } -EXPORT_SYMBOL_GPL(hisi_clk_register_mux); +EXPORT_SYMBOL_GPL(hisi_clk_register_fixed_factor); + +/* + * We ARE function creater. Commit message from checkpatch: + * Avoid warning on macros that use argument concatenation as + * those macros commonly create another function + */ +#define hisi_clk_register_fn(fn, type, stmt) \ +int fn(struct device *dev, const struct type *clks, \ + size_t num, struct hisi_clock_data *data) \ +{ \ + void __iomem *base = data->base; \ +\ + for (int i = 0; i < num; i++) { \ + const struct type *p_clk = &clks[i]; \ + struct clk_hw *clk = stmt; \ +\ + if (IS_ERR(clk)) { \ + pr_err("%s: failed to register clock %s\n", \ + __func__, p_clk->name); \ + return PTR_ERR(clk); \ + } \ +\ + if (p_clk->alias) \ + clk_hw_register_clkdev(clk, p_clk->alias, NULL); \ +\ + data->clk_data->hws[p_clk->id] = clk; \ + } \ +\ + return 0; \ +} \ +EXPORT_SYMBOL_GPL(fn); + +hisi_clk_register_fn(hisi_clk_register_mux, hisi_mux_clock, + __devm_clk_hw_register_mux(dev, NULL, p_clk->name, + p_clk->num_parents, p_clk->parent_names, NULL, NULL, + p_clk->flags, base + p_clk->offset, p_clk->shift, BIT(p_clk->width) - 1, + p_clk->mux_flags, p_clk->table, &hisi_clk_lock)) int hisi_clk_register_phase(struct device *dev, const struct hisi_phase_clock *clks, - int nums, struct hisi_clock_data *data) + size_t num, struct hisi_clock_data *data) { void __iomem *base = data->base; - struct clk *clk; - int i; - for (i = 0; i < nums; i++) { - clk = clk_register_hisi_phase(dev, &clks[i], base, - &hisi_clk_lock); + for (int i = 0; i < num; i++) { + const struct hisi_phase_clock *p_clk = &clks[i]; + struct clk_hw *clk = devm_clk_hw_register_hisi_phase(dev, + p_clk, base, &hisi_clk_lock); + if (IS_ERR(clk)) { pr_err("%s: failed to register clock %s\n", __func__, - clks[i].name); + p_clk->name); return PTR_ERR(clk); } - data->clk_data.clks[clks[i].id] = clk; + data->clk_data->hws[p_clk->id] = clk; } return 0; } EXPORT_SYMBOL_GPL(hisi_clk_register_phase); -int hisi_clk_register_divider(const struct hisi_divider_clock *clks, - int nums, struct hisi_clock_data *data) -{ - struct clk *clk; - void __iomem *base = data->base; - int i; - - for (i = 0; i < nums; i++) { - clk = clk_register_divider_table(NULL, clks[i].name, - clks[i].parent_name, - clks[i].flags, - base + clks[i].offset, - clks[i].shift, clks[i].width, - clks[i].div_flags, - clks[i].table, - &hisi_clk_lock); - if (IS_ERR(clk)) { - pr_err("%s: failed to register clock %s\n", - __func__, clks[i].name); - goto err; - } - - if (clks[i].alias) - clk_register_clkdev(clk, clks[i].alias, NULL); - - data->clk_data.clks[clks[i].id] = clk; - } - - return 0; - -err: - while (i--) - clk_unregister_divider(data->clk_data.clks[clks[i].id]); - - return PTR_ERR(clk); -} -EXPORT_SYMBOL_GPL(hisi_clk_register_divider); - -int hisi_clk_register_gate(const struct hisi_gate_clock *clks, - int nums, struct hisi_clock_data *data) -{ - struct clk *clk; - void __iomem *base = data->base; - int i; - - for (i = 0; i < nums; i++) { - clk = clk_register_gate(NULL, clks[i].name, - clks[i].parent_name, - clks[i].flags, - base + clks[i].offset, - clks[i].bit_idx, - clks[i].gate_flags, - &hisi_clk_lock); - if (IS_ERR(clk)) { - pr_err("%s: failed to register clock %s\n", - __func__, clks[i].name); - goto err; - } - - if (clks[i].alias) - clk_register_clkdev(clk, clks[i].alias, NULL); - - data->clk_data.clks[clks[i].id] = clk; - } - - return 0; - -err: - while (i--) - clk_unregister_gate(data->clk_data.clks[clks[i].id]); - - return PTR_ERR(clk); -} -EXPORT_SYMBOL_GPL(hisi_clk_register_gate); - -void hisi_clk_register_gate_sep(const struct hisi_gate_clock *clks, - int nums, struct hisi_clock_data *data) -{ - struct clk *clk; - void __iomem *base = data->base; - int i; - - for (i = 0; i < nums; i++) { - clk = hisi_register_clkgate_sep(NULL, clks[i].name, - clks[i].parent_name, - clks[i].flags, - base + clks[i].offset, - clks[i].bit_idx, - clks[i].gate_flags, - &hisi_clk_lock); - if (IS_ERR(clk)) { - pr_err("%s: failed to register clock %s\n", - __func__, clks[i].name); - continue; - } - - if (clks[i].alias) - clk_register_clkdev(clk, clks[i].alias, NULL); - - data->clk_data.clks[clks[i].id] = clk; - } -} -EXPORT_SYMBOL_GPL(hisi_clk_register_gate_sep); - -void __init hi6220_clk_register_divider(const struct hi6220_divider_clock *clks, - int nums, struct hisi_clock_data *data) -{ - struct clk *clk; - void __iomem *base = data->base; - int i; - - for (i = 0; i < nums; i++) { - clk = hi6220_register_clkdiv(NULL, clks[i].name, - clks[i].parent_name, - clks[i].flags, - base + clks[i].offset, - clks[i].shift, - clks[i].width, - clks[i].mask_bit, - &hisi_clk_lock); - if (IS_ERR(clk)) { - pr_err("%s: failed to register clock %s\n", - __func__, clks[i].name); - continue; - } - - if (clks[i].alias) - clk_register_clkdev(clk, clks[i].alias, NULL); - - data->clk_data.clks[clks[i].id] = clk; - } -} +hisi_clk_register_fn(hisi_clk_register_divider, hisi_divider_clock, + devm_clk_hw_register_divider_table(dev, p_clk->name, p_clk->parent_name, + p_clk->flags, base + p_clk->offset, p_clk->shift, p_clk->width, + p_clk->div_flags, p_clk->table, &hisi_clk_lock)) +hisi_clk_register_fn(hisi_clk_register_gate, hisi_gate_clock, + devm_clk_hw_register_gate(dev, p_clk->name, p_clk->parent_name, + p_clk->flags, base + p_clk->offset, p_clk->bit_idx, + p_clk->gate_flags, &hisi_clk_lock)) +hisi_clk_register_fn(hisi_clk_register_gate_sep, hisi_gate_clock, + devm_clk_hw_register_hisi_gate_sep(dev, p_clk->name, p_clk->parent_name, + p_clk->flags, base + p_clk->offset, p_clk->bit_idx, + p_clk->gate_flags, &hisi_clk_lock)) +hisi_clk_register_fn(hi6220_clk_register_divider, hi6220_divider_clock, + devm_clk_hw_register_hi6220_divider(dev, p_clk->name, p_clk->parent_name, + p_clk->flags, base + p_clk->offset, p_clk->shift, p_clk->width, + p_clk->mask_bit, &hisi_clk_lock)) static size_t hisi_clocks_get_nr(const struct hisi_clocks *clks) { @@ -406,38 +280,20 @@ static int hisi_clk_register(struct device *dev, const struct hisi_clocks *clks, { int ret; - if (clks->mux_clks_num) { - ret = hisi_clk_register_mux(clks->mux_clks, - clks->mux_clks_num, data); - if (ret) - return ret; - } - - if (clks->phase_clks_num) { - ret = hisi_clk_register_phase(dev, clks->phase_clks, - clks->phase_clks_num, data); - if (ret) - return ret; - } - - if (clks->divider_clks_num) { - ret = hisi_clk_register_divider(clks->divider_clks, - clks->divider_clks_num, data); - if (ret) - return ret; - } - - if (clks->gate_clks_num) { - ret = hisi_clk_register_gate(clks->gate_clks, - clks->gate_clks_num, data); - if (ret) - return ret; - } - - if (clks->gate_sep_clks_num) { - hisi_clk_register_gate_sep(clks->gate_sep_clks, - clks->gate_sep_clks_num, data); - } +#define do_hisi_clk_register(type) do { \ + if (clks->type##_clks_num) { \ + ret = hisi_clk_register_##type(dev, clks->type##_clks, \ + clks->type##_clks_num, data); \ + if (ret) \ + return ret; \ + } \ +} while (0) + + do_hisi_clk_register(mux); + do_hisi_clk_register(phase); + do_hisi_clk_register(divider); + do_hisi_clk_register(gate); + do_hisi_clk_register(gate_sep); if (clks->clk_register_customized && clks->customized_clks_num) { ret = clks->clk_register_customized(dev, clks->customized_clks, diff --git a/drivers/clk/hisilicon/clk.h b/drivers/clk/hisilicon/clk.h index 87b17e9b79a3..911e1a45deb0 100644 --- a/drivers/clk/hisilicon/clk.h +++ b/drivers/clk/hisilicon/clk.h @@ -4,6 +4,7 @@ * * Copyright (c) 2012-2013 Hisilicon Limited. * Copyright (c) 2012-2013 Linaro Limited. + * Copyright (c) 2023 David Yang * * Author: Haojian Zhuang * Xin Li @@ -19,8 +20,18 @@ struct platform_device; struct hisi_clocks; +/* + * (Virtual) fixed clocks, often depended by crucial peripherals, require + * early initialization before device probing, thus cannot use devm APIs. + * Otherwise, kernel will defer those peripherals, causing boot failure. + * + * fixed_rate and fixed_factor clocks are driver-managed. They are freed by + * hisi_clk_free() altogether. + * + * Other clocks are devm-managed. + */ struct hisi_clock_data { - struct clk_onecell_data clk_data; + struct clk_hw_onecell_data *clk_data; void __iomem *base; const struct hisi_clocks *clks; }; @@ -138,57 +149,45 @@ struct hisi_clocks { size_t num, struct hisi_clock_data *data); }; -struct clk *hisi_register_clkgate_sep(struct device *, const char *, - const char *, unsigned long, - void __iomem *, u8, - u8, spinlock_t *); -struct clk *hi6220_register_clkdiv(struct device *dev, const char *name, - const char *parent_name, unsigned long flags, void __iomem *reg, - u8 shift, u8 width, u32 mask_bit, spinlock_t *lock); - -struct hisi_clock_data *hisi_clk_alloc(struct platform_device *, int); -struct hisi_clock_data *hisi_clk_init(struct device_node *, int); -void hisi_clk_free(struct device_node *np, struct hisi_clock_data *data); -int hisi_clk_register_fixed_rate(const struct hisi_fixed_rate_clock *, - int, struct hisi_clock_data *); -int hisi_clk_register_fixed_factor(const struct hisi_fixed_factor_clock *, - int, struct hisi_clock_data *); -int hisi_clk_register_mux(const struct hisi_mux_clock *, int, - struct hisi_clock_data *); -struct clk *clk_register_hisi_phase(struct device *dev, - const struct hisi_phase_clock *clks, +struct clk_hw * +devm_clk_hw_register_hisi_phase(struct device *dev, const struct hisi_phase_clock *clks, void __iomem *base, spinlock_t *lock); +struct clk_hw * +devm_clk_hw_register_hisi_gate_sep(struct device *dev, const char *name, + const char *parent_name, unsigned long flags, + void __iomem *reg, u8 bit_idx, + u8 clk_gate_flags, spinlock_t *lock); +struct clk_hw * +devm_clk_hw_register_hi6220_divider(struct device *dev, const char *name, + const char *parent_name, unsigned long flags, + void __iomem *reg, u8 shift, + u8 width, u32 mask_bit, spinlock_t *lock); + +struct hisi_clock_data *hisi_clk_init(struct device_node *np, size_t nr); +void hisi_clk_free(struct device_node *np, struct hisi_clock_data *data); + +int hisi_clk_register_fixed_rate(const struct hisi_fixed_rate_clock *clks, + size_t num, struct hisi_clock_data *data); +int hisi_clk_register_fixed_factor(const struct hisi_fixed_factor_clock *clks, + size_t num, struct hisi_clock_data *data); + +int hisi_clk_register_mux(struct device *dev, const struct hisi_mux_clock *clks, + size_t num, struct hisi_clock_data *data); int hisi_clk_register_phase(struct device *dev, - const struct hisi_phase_clock *clks, - int nums, struct hisi_clock_data *data); -int hisi_clk_register_divider(const struct hisi_divider_clock *, - int, struct hisi_clock_data *); -int hisi_clk_register_gate(const struct hisi_gate_clock *, - int, struct hisi_clock_data *); -void hisi_clk_register_gate_sep(const struct hisi_gate_clock *, - int, struct hisi_clock_data *); -void hi6220_clk_register_divider(const struct hi6220_divider_clock *, - int, struct hisi_clock_data *); - -#define hisi_clk_unregister(type) \ -static inline \ -void hisi_clk_unregister_##type(const struct hisi_##type##_clock *clks, \ - int nums, struct hisi_clock_data *data) \ -{ \ - struct clk **clocks = data->clk_data.clks; \ - int i; \ - for (i = 0; i < nums; i++) { \ - int id = clks[i].id; \ - if (clocks[id]) \ - clk_unregister_##type(clocks[id]); \ - } \ -} - -hisi_clk_unregister(fixed_rate) -hisi_clk_unregister(fixed_factor) -hisi_clk_unregister(mux) -hisi_clk_unregister(divider) -hisi_clk_unregister(gate) + const struct hisi_phase_clock *clks, + size_t num, struct hisi_clock_data *data); +int hisi_clk_register_divider(struct device *dev, + const struct hisi_divider_clock *clks, + size_t num, struct hisi_clock_data *data); +int hisi_clk_register_gate(struct device *dev, + const struct hisi_gate_clock *clks, + size_t num, struct hisi_clock_data *data); +int hisi_clk_register_gate_sep(struct device *dev, + const struct hisi_gate_clock *clks, + size_t num, struct hisi_clock_data *data); +int hi6220_clk_register_divider(struct device *dev, + const struct hi6220_divider_clock *clks, + size_t num, struct hisi_clock_data *data); /* helper functions for platform driver */ diff --git a/drivers/clk/hisilicon/clkdivider-hi6220.c b/drivers/clk/hisilicon/clkdivider-hi6220.c index 5348bafe694f..3c03b3e5b841 100644 --- a/drivers/clk/hisilicon/clkdivider-hi6220.c +++ b/drivers/clk/hisilicon/clkdivider-hi6220.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include #include @@ -97,19 +97,19 @@ static const struct clk_ops hi6220_clkdiv_ops = { .set_rate = hi6220_clkdiv_set_rate, }; -struct clk *hi6220_register_clkdiv(struct device *dev, const char *name, +struct clk_hw *devm_clk_hw_register_hi6220_divider(struct device *dev, const char *name, const char *parent_name, unsigned long flags, void __iomem *reg, u8 shift, u8 width, u32 mask_bit, spinlock_t *lock) { struct hi6220_clk_divider *div; - struct clk *clk; struct clk_init_data init; struct clk_div_table *table; u32 max_div, min_div; int i; + int ret; /* allocate the divider */ - div = kzalloc(sizeof(*div), GFP_KERNEL); + div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL); if (!div) return ERR_PTR(-ENOMEM); @@ -117,11 +117,9 @@ struct clk *hi6220_register_clkdiv(struct device *dev, const char *name, max_div = div_mask(width) + 1; min_div = 1; - table = kcalloc(max_div + 1, sizeof(*table), GFP_KERNEL); - if (!table) { - kfree(div); + table = devm_kcalloc(dev, max_div + 1, sizeof(*table), GFP_KERNEL); + if (!table) return ERR_PTR(-ENOMEM); - } for (i = 0; i < max_div; i++) { table[i].div = min_div + i; @@ -144,11 +142,9 @@ struct clk *hi6220_register_clkdiv(struct device *dev, const char *name, div->table = table; /* register the clock */ - clk = clk_register(dev, &div->hw); - if (IS_ERR(clk)) { - kfree(table); - kfree(div); - } + ret = devm_clk_hw_register(dev, &div->hw); + if (ret) + return ERR_PTR(ret); - return clk; + return &div->hw; } diff --git a/drivers/clk/hisilicon/clkgate-separated.c b/drivers/clk/hisilicon/clkgate-separated.c index 90d858522967..dc64a8a0ab58 100644 --- a/drivers/clk/hisilicon/clkgate-separated.c +++ b/drivers/clk/hisilicon/clkgate-separated.c @@ -11,8 +11,8 @@ #include #include +#include #include -#include #include "clk.h" @@ -80,17 +80,18 @@ static const struct clk_ops clkgate_separated_ops = { .is_enabled = clkgate_separated_is_enabled, }; -struct clk *hisi_register_clkgate_sep(struct device *dev, const char *name, - const char *parent_name, - unsigned long flags, - void __iomem *reg, u8 bit_idx, - u8 clk_gate_flags, spinlock_t *lock) +struct clk_hw * +devm_clk_hw_register_hisi_gate_sep(struct device *dev, const char *name, + const char *parent_name, + unsigned long flags, + void __iomem *reg, u8 bit_idx, + u8 clk_gate_flags, spinlock_t *lock) { struct clkgate_separated *sclk; - struct clk *clk; struct clk_init_data init; + int ret; - sclk = kzalloc(sizeof(*sclk), GFP_KERNEL); + sclk = devm_kzalloc(dev, sizeof(*sclk), GFP_KERNEL); if (!sclk) return ERR_PTR(-ENOMEM); @@ -106,8 +107,9 @@ struct clk *hisi_register_clkgate_sep(struct device *dev, const char *name, sclk->hw.init = &init; sclk->lock = lock; - clk = clk_register(dev, &sclk->hw); - if (IS_ERR(clk)) - kfree(sclk); - return clk; + ret = devm_clk_hw_register(dev, &sclk->hw); + if (ret) + return ERR_PTR(ret); + + return &sclk->hw; }