Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5846924rwl; Tue, 11 Apr 2023 10:45:37 -0700 (PDT) X-Google-Smtp-Source: AKy350Y7gXEDM+8zhy17WlA3uZBpwFnlpDt3MRsa47IYdJiXbk61oP6JelJ7iCYoIHzsJT5lKMM/ X-Received: by 2002:a05:6a20:8ba7:b0:d9:3683:bc15 with SMTP id m39-20020a056a208ba700b000d93683bc15mr13423097pzh.19.1681235137468; Tue, 11 Apr 2023 10:45:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681235137; cv=none; d=google.com; s=arc-20160816; b=YfP2rf8csUH4l7cP3vEObMqMriH+erV3GQTPvtTGd4Q+wvJ9kFTZuuT4vX3/z4XPvb 6YYqlw6/yrlOzLObIrVWhfxHp3Q2nDT5Yn93M3ciy4jVwiNf1Z8zo4KaUBDX8bSjeHuc tZbBVRSXBwhH7b6Cil+qHEOX5XyO9krzdde33aH3qbaRcLM+tKlT5CCfHoxRtrWAKqbU rujVNx/KN4HsvCwHI7uGuPUBCACVDSl4lEaWxmi8RCuauLsMSOf8W6FZIPD8AbwnfGp4 myz9hcrElH78a/o7LdPYmmtpsCpvV5WcNPqYLlsHPb+vnFQKAsU9HDNJeZ5WtMU1DZWg JsLw== 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=hOql+bAuTzb4sNeAYIK71k2lMY+HYwNHUIwpssNISEY=; b=07cHnZ/Qr1ML08CCC8QeENy4XGCFX1Xkbqjlkc54v9hXAOmRwRb7rml/8/wQq8BrcE ONApkhx3fU58SC5WqOvtuB3pMTQUVDrMrK0E88BWLxdtyYI24RNFscqUukjIIvD0vHNF n8LTcnaX4FOXqZC93PmRdB3P8GMAsnb6Tpqvcka3+yofHuuZH8HXeXFHD310IyXTcGuq r7PgKeaJY6gErJ2OPNDJfCJpPX2RuZB8d2Kmc0S4FXPxQFUz5ZjPap0NmxV0WswBbdc0 Ck3I4ffCX9tnhtTC1Etlthm95LlZeCP+mk1lFL3vyibkLbkRZp3CDILZKGgh90FWf4TG ySKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="Bom/Wn8J"; 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 h191-20020a636cc8000000b0051453dfd147si13230023pgc.387.2023.04.11.10.45.25; Tue, 11 Apr 2023 10:45:37 -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=20210112 header.b="Bom/Wn8J"; 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 S230172AbjDKRpF (ORCPT + 99 others); Tue, 11 Apr 2023 13:45:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230241AbjDKRo5 (ORCPT ); Tue, 11 Apr 2023 13:44:57 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97CA25276; Tue, 11 Apr 2023 10:44:49 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id pm7-20020a17090b3c4700b00246f00dace2so838625pjb.2; Tue, 11 Apr 2023 10:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1681235089; 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=hOql+bAuTzb4sNeAYIK71k2lMY+HYwNHUIwpssNISEY=; b=Bom/Wn8JatzU3tzR4sD0zSM3L9IG4vjiBVYejPZ90T4L4r8D8PPusN00RhiVChGnWi FlzRqtwGrmV+wNdYrHExM70gGyaljUiwxpoi66gBlCNo2JqmDuVpKnODXnjqUNjotWaD DTp38AU70bQHGVHXdX9FeCDWQ+NNpl4L6UNm5b4UeUrMZKLiY1DBwniYlt5mEFHfBSbQ 0PKpXQZ5NRFJDOpxnmwezdUTmAmorMAVLSQkueiFCNuGnFIa0s/rpZ+O+x3hQRpt7cOW EPKNXPgTmlR9UiaJP/8bJ0AUlsR1v0pe4kF3Ar3ONF2dl1w3KVA7nfQc8MCsNWx5THmm dFjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681235089; 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=hOql+bAuTzb4sNeAYIK71k2lMY+HYwNHUIwpssNISEY=; b=fxHkVm/o5JN7n98Xhx9tkSLYP0VOyIhV8LnEILDGWGIuoqiz+m74Vj4+cMeyfUT2jZ vxYgG4SUmAeSGM5BwOhSSOPfD5faU4UDhr9gW3KPzWQrUc0zWxCy/LZfBQiv8GYqrqma JI2zBd7vDCT/zPC1TU70U/FqDoDmRQa1UDaDj1QeSSAaDJuhZNC0L8OmeV6IjBGCUgDt hv7tI+aiGM7h0sn1MxX6oAp2+9HwFEsX7UPezZ+fJHpCyUJ2x3hBD+i3budYnmhvbIQu zRztcYlniViR6xBsvcuCFrf/B1P8snwCbZXycBTGIikGHCdaUpuLq/4ST1I5ANUGokjq Ob5A== X-Gm-Message-State: AAQBX9cRF+/TeEleKkGHPWCcTHqU6Vl/0jx87QrPFcxGQM7RPy6hX1EW Dn5xuEVqTYqiPZ70MM9nJocuNnLlLeAIORI+ X-Received: by 2002:a17:903:2111:b0:1a6:467c:fc0c with SMTP id o17-20020a170903211100b001a6467cfc0cmr5977813ple.3.1681235088809; Tue, 11 Apr 2023 10:44:48 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.213.202]) by smtp.gmail.com with ESMTPSA id w23-20020a1709027b9700b001a655738a42sm1900805pll.172.2023.04.11.10.44.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 10:44: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 v4 05/13] clk: hisilicon: hi3519: Use helper functions Date: Wed, 12 Apr 2023 01:43:14 +0800 Message-Id: <20230411174329.424763-6-mmyangfl@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411174329.424763-1-mmyangfl@gmail.com> References: <20230411174329.424763-1-mmyangfl@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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-hi3519.c | 128 ++++------------------------- 1 file changed, 15 insertions(+), 113 deletions(-) diff --git a/drivers/clk/hisilicon/clk-hi3519.c b/drivers/clk/hisilicon/clk-hi3519.c index ad0c7f350cf0..eac66bde1361 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,131 +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 int 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); - return 0; -} - +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 = hi3519_clk_remove, + .probe = hisi_crg_probe, + .remove = 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"); -- 2.39.2