From patchwork Tue Apr 16 10:03:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Yang X-Patchwork-Id: 13631597 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1482912A16D; Tue, 16 Apr 2024 10:05:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713261940; cv=none; b=iiEs9PJZ/2+khCPMUz3WY5iBKK/1Go9arQzgWhJc3RUtPa2jqC2vl3Peim2lWPc1ToxQKMDIHzz4kR1XDIgbzgyPRd9f82+8H4MnelkzvJborR2ELP1X/RgLW/0NW48uK0z+vp7emqGF/gZ+qLmOsQ35syLDVudhilWwV/+QKx0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713261940; c=relaxed/simple; bh=lfD9o2pHG/+QPMe0OdB6aCGlOA449bGcTbqMaJfjB7A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mlf5RPumGI3NEYEDaLU490sBvY7kNly0IIxQ3m5tFmZ5Tfk3o7cx8iao6M48Y4hxV4QMmv0alPKCFIVGo/kvVcFyBQk5PJkpYz+NP6uEMemVKVxW/x3e4eskfhov+qSj/4dfNlJ6Ajo1RHf73NSUaPQc+alCaGxBqh4UCnf0J1w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Z84T5Wrv; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Z84T5Wrv" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1e36b7e7dd2so33320555ad.1; Tue, 16 Apr 2024 03:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713261938; x=1713866738; darn=vger.kernel.org; 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=EckRc5LNsseY5WZLgeXlQQDLpph0OA/kZDaAAhnVxro=; b=Z84T5WrvCUrj3FO6RUl/q2aoAZ53UwfJhynv9Kye6nMmwrz7oVK8NIU+Od6oaunB9O 2vjV9qmlXEfUdkrKsKwTJyz6HfjVv3vcSAkefVuX4uiQfmSSvXVu4ruSbgh1Ch0DuROM VyuWKs7EjcBBvRppLLJub+OAyq1H507Hnh9Q4sD8ve47cnYvknYHFNcH7jGMsqaoyzxF 8fn3lzYhpFEAI3uTvp03Agp2J9OoJyTUd5TvRMwLY7oaJKxjhCCWKW00+TJJtsjFe7Zu +IJSfsAT//beDIQq7+9BmcuWxLgGHQu3hVOai4oJbD9dA2KBsZH6CRrf947WhPgsHTOo G2tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713261938; x=1713866738; 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=EckRc5LNsseY5WZLgeXlQQDLpph0OA/kZDaAAhnVxro=; b=OhyHfMQkrimJVf7FZG8sOJ6OAKBs6G2cvNOvC7xQ8MaLw9zsY2++t5vOKXe+w2CoCz qQhcIPaOzHpnRbebtr9ajUVbGnoHecVvNWWVAzBz3E9CVbf+VS9AVzXz2NoD7dWIKeK2 v0HP5sJ7RaQJs+1o39ZyhIJUwyuAuOkh8fCbgXlY80NSBHUJpAh2KDvP9wl7T7RTyhAp Ofk3fEo3u9ykoaf12NMKTrMbPCRGjsYnr8qZsxbOwYj6QGnUetPhekvZdysPeR7JIdhN 09Jb6kTArszC24qS5VmONreH1M/uO4lZ9pgPsD2kqgY1WcrnAWm3bzraHwK5P4gtOavV +D0A== X-Forwarded-Encrypted: i=1; AJvYcCWScsoTgSRTm8KfHI3gXvbhCdmPsGx4F6l1fKJ2XxnZT8ZJ+VFVA2F70BUvmf5y/hSITLE6wniNRB1/6g14UZreQ7neAcWrqS/uVZDg X-Gm-Message-State: AOJu0YxZPKei+s1RULuv308Hddm9ja4+nR0s73svtkcVimiYzhw5HBXW sgRW97/ZHw3bI3r9zyDbRaxwSwzOxHbkDvc7CYDiNoZTtm6AH1NpSNJG5zpz X-Google-Smtp-Source: AGHT+IHakB1Gd+kGa7xOI15AfIFBJl+O+5g9uDXz9Kz7fC5pJvwHNaHSf+poYnknawlLG6HJLxxdTQ== X-Received: by 2002:a17:902:d5d6:b0:1e4:a667:550e with SMTP id g22-20020a170902d5d600b001e4a667550emr9445252plh.20.1713261937981; Tue, 16 Apr 2024 03:05:37 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.245.199]) by smtp.gmail.com with ESMTPSA id y4-20020a17090322c400b001e0b287c1d2sm9353651plg.215.2024.04.16.03.05.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 03:05:37 -0700 (PDT) From: David Yang To: linux-clk@vger.kernel.org Cc: Michael Turquette , Stephen Boyd , linux-kernel@vger.kernel.org, David Yang Subject: [PATCH v10 12/13] clk: hisilicon: hix5hd2: Convert into platform driver module Date: Tue, 16 Apr 2024 18:03:46 +0800 Message-ID: <20240416100347.395295-13-mmyangfl@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240416100347.395295-1-mmyangfl@gmail.com> References: <20240416100347.395295-1-mmyangfl@gmail.com> Precedence: bulk X-Mailing-List: linux-clk@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 86 ++++++++++++++++++----------- 1 file changed, 53 insertions(+), 33 deletions(-) diff --git a/drivers/clk/hisilicon/clk-hix5hd2.c b/drivers/clk/hisilicon/clk-hix5hd2.c index 64bdd3f05725..e46a516cd0eb 100644 --- a/drivers/clk/hisilicon/clk-hix5hd2.c +++ b/drivers/clk/hisilicon/clk-hix5hd2.c @@ -4,13 +4,18 @@ * Copyright (c) 2014 Hisilicon Limited. */ -#include #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 +48,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 +72,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 +158,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 +254,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 +295,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");