Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4370101rwb; Mon, 31 Jul 2023 06:04:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlFnIuY93xCv5nfGHSyt75KB0YWfqRDpqTvdjqTMM2Uoe3ZSvZs63kHhKEX0gM/oMSSJgMfy X-Received: by 2002:a2e:8003:0:b0:2b6:b6c4:6e79 with SMTP id j3-20020a2e8003000000b002b6b6c46e79mr5917255ljg.1.1690808668693; Mon, 31 Jul 2023 06:04:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690808668; cv=none; d=google.com; s=arc-20160816; b=IXXsX7YYltM2K2+cvZ9VPbp9JcK4ccFb4oUljbuwWy2JC5TYji0x1D3mj8SDsKbavs MgQD+zkVKU3tZ7fUS9bROfMCV/q6Y0Rm8tBp2bYCI7NU1MMevwV2Zw6W1lp4h1Ge9R1W han+Ja/Hz5dP6LPCi8CosAj8Trun5AIm6SAziPF90mCUiCACIBXAb9pVk3RTjK2p43mH LzYMS20kg9ZQW5M1bR/4LOOm4NKBf9Tx/i/fcmZmOcnMe1rpvjrEKxbtnMTVCL4iwAD0 YEOFB2Nklki47il2g8cQRqRob2WisBv3OB9HFx49MRUiA3mGMx7zofrvguaZSBxVquJa Ziyw== 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=KKy/j/MhNE72j2O0XcmE26uLn+SJHVCshEgT65m/knJcKwGqG9c2dV1gMhjnyscfOR 7eR1+rUOdQPPxaQ5m8N8p5iDEWsBi0k7UWPsqbqainR9zz71oP3/lG/z+BHFjlbT1lGg LWf9SVCKL15VP0aehMcmHHI/RB2OFQAr0d2dbzvokVFLSViZX0lpUIeDutQYyavHbJzi 4ATDloIm00rjjv+ErEqlq38ZI/NNAqZ9CzixOwt9FkqHp9gITHKPXvZp1yZqMhTX42QG PCD7sY21ExsCypdwk2VVmBKh613PxS8dL61uyIH05Rr9X1CoUwSr0tE4rSpPMZvdcccU y7cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=T43latip; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kj27-20020a170907765b00b00994b9c51cafsi2884136ejc.717.2023.07.31.06.04.02; Mon, 31 Jul 2023 06:04:28 -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=T43latip; 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 S232589AbjGaMVM (ORCPT + 99 others); Mon, 31 Jul 2023 08:21:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232516AbjGaMU5 (ORCPT ); Mon, 31 Jul 2023 08:20:57 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BF3A19B7; Mon, 31 Jul 2023 05:20:44 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-686ea67195dso3102015b3a.2; Mon, 31 Jul 2023 05:20:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690806043; x=1691410843; 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=T43latipwf94hNdA1OWOFkZdX+hSvZUKnEZAfWAP09DbiklwluJTIReHjB9SIGIgJC JaNB/apsa+4NKVKC3al5IJe7YRtuIof4R7lEQm4kF0nVhIVMwmSNlaUXhQo8Ks4WXsBc C57mm2GlmWZuDmV+D2pxDr1wLloS0Q5msRgjb5XdgMpmP/XySli+o6TkG/UjrtEjWuGl ZNK05Ke1eANaodr3kkhBBYzVTfrmlq0uDXSvxPebUcw+vTAYTTUGpWj/zUyrHMA6AEM3 M+jRDCqZ7/3sU0o1efa1/KvL50z/9k8BAmm5n1sTrvwo2dSAWZTABuZUj08PNbrmaWbX bntQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690806043; x=1691410843; 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=C5O47rEPgFnom/s+OaKjAl98k8eLvBbgl8ZW2FPo/JdANC9YlBFFB0Ll2vqxKKHoik XFlq54t9O0Vs7cG+lyWIOIHfE4HKrTQfiwn+mmiRlL9FcoOY72+hIdKluSUJVWuVZK7Q XegI8/iQ+izYW7AanfpU9ho6Dt2BD+qRlf+c5rqRQ6C3KvuBVwUEBEGd9DeAa/033IBc 83F/E4Z1OVQRC0LoDB9kLfSl5HRV8T7YaVdgLppJVbBXg106zDjFtvOxyiwMJdhC6Lu5 840xR1/rDjHV3iZcMHyA4tASiFzCbKexCx6Ca/GC34gpfMHIxKk3eC4qxQ/dcRk/Brf8 7cQA== X-Gm-Message-State: ABy/qLb91B64KlWgRR2q51Nt8KEhEYT0XNa8DVF4R0avO6FMpE1EafZC 8XahZa9Djv79oZljJwbFhW2hose8mBWSSsZl X-Received: by 2002:a05:6a00:1410:b0:67d:22a6:2f54 with SMTP id l16-20020a056a00141000b0067d22a62f54mr10757976pfu.31.1690806043525; Mon, 31 Jul 2023 05:20:43 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.245.199]) by smtp.gmail.com with ESMTPSA id y23-20020aa78557000000b00687227dd8f1sm3529559pfn.122.2023.07.31.05.20.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 05:20:43 -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 v6 07/13] clk: hisilicon: hi3660: Convert into module Date: Mon, 31 Jul 2023 20:18:07 +0800 Message-Id: <20230731121821.22242-8-mmyangfl@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230731121821.22242-1-mmyangfl@gmail.com> References: <20230731121821.22242-1-mmyangfl@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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_BLOCKED,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 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"); -- 2.40.1