From patchwork Mon Apr 10 11:07:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangfl X-Patchwork-Id: 81473 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1826368vqo; Mon, 10 Apr 2023 04:26:22 -0700 (PDT) X-Google-Smtp-Source: AKy350YJQpf/+YgifWp2NXHgU4QZGsVidsIIDLQZlJdW07N4iOgBRLY/gLE1lnU8wutLN1m267Ki X-Received: by 2002:a62:1d12:0:b0:626:2ce1:263c with SMTP id d18-20020a621d12000000b006262ce1263cmr10641602pfd.5.1681125982046; Mon, 10 Apr 2023 04:26:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681125982; cv=none; d=google.com; s=arc-20160816; b=GA3QzJ/N2B+Abt8/jny81mmX3rU+qNRNVIx4YX+9/dxz/EbNN8IWGTja0ycckaD1lr 2wzczH6i43yFCJALqoeWW040Fzg0Iq16KFddV8T/RFAZJ0Zg9CiA/VbWrTzc0ZWnoXDq Oq2qfjv7/wHyXnLOS/v+gFuB5Y42c+EGvlx+OeKhpvUqSwNtgig71Tr2Hf7ECQ9rYpGJ eKlAIdJEG1KUvE1EFcwiNowfN695wmMssQmh/q3BnnE4r3gVMhWJornOBLCW4g+d2JUU 9MI9LDyqEPvUAPuOvixaCTGXCj7rC/kPaz2OrFv/3iHTFB+Y1qJX6O/yzsghe2gFT7LB Fg2Q== 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=eAEODm1kNNhfhQehFrRwXlq3FhwRoxU54wQDsxuZLBY=; b=E5Fb6gOAPg4ZELeKbWCBImVuaZ+xeYRuLBTrXqIF+czCT0if/s+WrCNIT1gwuNxRdH Tuz2TU0BQ3igeR41yyoz4M+KrOCq8ht1Sj75UquSJDHMNTHH3IkZ2YSl9WTxn4eHgyxQ KGMZxGK4WjAmuAxzSmHbOw1sYc/zjjEfDma5D1zipXxn/6tT8/uSKeZz4cDZgpaqiNhr t8qO8KzCdZyEGjfmbjIqrHLImEoZudRPV+HxMpnWTakl694QV2vDS5wfNklp57I/riGx T4qe5yrzfSUkZTDtQb/i35OlUSIhEkD75d32mfOvZ5udX6mo7tuB5Ag3TioQ9KkT4LNI MlOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="mneeEP5/"; 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 f2-20020a6547c2000000b00503a2ab160esi9878963pgs.553.2023.04.10.04.26.07; Mon, 10 Apr 2023 04:26:22 -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="mneeEP5/"; 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 S229894AbjDJLLD (ORCPT + 99 others); Mon, 10 Apr 2023 07:11:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229902AbjDJLLB (ORCPT ); Mon, 10 Apr 2023 07:11:01 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DE395252; Mon, 10 Apr 2023 04:10:37 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id c3so4792813pjg.1; Mon, 10 Apr 2023 04:10:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1681125036; 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=eAEODm1kNNhfhQehFrRwXlq3FhwRoxU54wQDsxuZLBY=; b=mneeEP5/S/ifs7vAoq84uXh0uh/1PHr3A6Rlsz4YpVabICVyO58KO8z0pkVTYOO6Vv YPFwZ1G7z6SaeeqYhGd0hI7mt3kfv2bwUxsIIJE1s+ikd4033gOl7n/UNJT7E2IJDSAq kFsOO/c4lU5pwZhOxVaUzM4/50eMvrIu3CXobF75qL8c4N8NJiK+hkqRX1x+uP/ghZeO tIxZVoxZJeDDgzcQ9LeCCG30TjJh9GfT+gaVfJyZlI42UX6iuF6r6I9AihEQTdvUf0F7 Rv5QrwlWnmoWllJ1aeJkyMK0VyY+FgSQpGQB5R8oIjeziyMxWinB2VLknPXe0/Z0wNWw rtyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681125036; 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=eAEODm1kNNhfhQehFrRwXlq3FhwRoxU54wQDsxuZLBY=; b=q4+S11hYOpML72rA1ehDQKNE+J3pDPTKpPyGO3E60NfhQKLVKhRpGmYo3Q/4qW94td VbnVloQ9cVDOu0/XzpFV/jwZijgNtGHolG0noSUGGIUnU63wmn1UYgxN2uBNE8BjFNBG NvYopAFb6AyxivEnMyYa1BMZT1Vm0Jej9uhlKjQOGW9O+QTXg/cFlHUTl4X2uAlDVXtI x90oJA2dF11Ym5qprJ/DLZ20xJ2wmv4/KMb2ESAq4l45nvAxmlH56hrIv5XRdjxbIIQr kmDs8xORffT+Hcop8BaS7vWSyxmRxcK6IO1jDhMVX4Fc+pV85+dnb7Ym/DuvQ1ZJFmDB 63CA== X-Gm-Message-State: AAQBX9dQDQzdztmZHaMKpErH5Glq/n7aj1OoTDYIMojXWjcpgRjM1Y3y JNchRYtLxQ5wpn6NtOwUbnVvVP9D/s9OOURsm7Q= X-Received: by 2002:a17:902:e749:b0:1a1:e93c:8937 with SMTP id p9-20020a170902e74900b001a1e93c8937mr14101810plf.35.1681125036086; Mon, 10 Apr 2023 04:10:36 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.213.201]) by smtp.gmail.com with ESMTPSA id r5-20020a170902be0500b001a076568da9sm7464728pls.216.2023.04.10.04.10.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 04:10: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 v3 13/14] clk: hisilicon: hix5hd2: Convert into platform driver module Date: Mon, 10 Apr 2023 19:07:25 +0800 Message-Id: <20230410110733.192151-14-mmyangfl@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230410110733.192151-1-mmyangfl@gmail.com> References: <20230410110733.192151-1-mmyangfl@gmail.com> MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762788357417684952?= X-GMAIL-MSGID: =?utf-8?q?1762788357417684952?= 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..fb0f5d2745b2 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 = 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");