From nobody Sat Apr 27 21:51:01 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9EB2C74A5B for ; Sun, 26 Mar 2023 05:28:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231888AbjCZF21 (ORCPT ); Sun, 26 Mar 2023 01:28:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231893AbjCZF2X (ORCPT ); Sun, 26 Mar 2023 01:28:23 -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 3AB1330F2; Sat, 25 Mar 2023 22:28:21 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id gp15-20020a17090adf0f00b0023d1bbd9f9eso8940556pjb.0; Sat, 25 Mar 2023 22:28:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679808500; 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=AzqnlpaZQYiWvtgYVVVK+zVHzXORQeLQeNjwiqHCZDc=; b=fHhDQ3XPWZJSNlJoNx6L35AB4WPx7YjQgPEGEthRfxFOsS8HqTtbr79Yr7kDIFRcCH MneEmeUrdMkKuXAIXgVyIvaC9+OZWeZtL9d9Jmd2kQp4EabPLBore8QPoOo1bYHZ1Uk0 QVH40YQ9paqT194m+XDPcYIUEbla3zzv3cl4HSnol18L+yz3S8VROkFjvUDAv8pu7bCQ XUjN3+7/hjjzbXv+GTClyl+9fAuBg9kcHxmrJVE6n0ZwRHO16pGQrLuVP0/jyzcTIaHK Au1/7GsO1/YSQ1kB9dLr0JLwHjih3GLMP+n6c01mv5GHSnm/GESPPex+qSc9Ao7Nfil/ PCvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679808500; 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=AzqnlpaZQYiWvtgYVVVK+zVHzXORQeLQeNjwiqHCZDc=; b=MkTy/fYHSzgINcMqa6THQQK3aA1re1Tz5VNtdJ1aKqEeg3eK0H2epgf438OkKtFJ91 o48NHDHecwZdfHGHv7h2xgI19dmAJB+ykURwadP2bKDqznYXlC4Cv4URkmWsMORR3Fna XoVZYbNlzfSBGNkWXWpwPqrLGgAgXjkpZJP2hC5LgyyovEWtWAIgxwhC37z1lIYLAVXv 8K3bC5UCtn7ETY87E0R3gZBR/0Ei7jdL/KdvWR4melsOfbE8IsYLxGzvZN4moDeat9WC v6n6k2h6ruU4dRkj8fjlWPagMPeYlLjFocFtf9PZ7dZRxv5yhWJRppKxmeVYGsseYG9V Me1A== X-Gm-Message-State: AO0yUKXftHnA1fAdaUjg9Ai9USfGlYE6oRZ9PgyoGnF26Hu8zQAnbyaI py5mDFRcXuzEhV7poBZr3F2LRSfQmLts1BMO X-Google-Smtp-Source: AK7set9iEFTTnJpueWiQ1nQlzpGTSB4Rq3ajQ7O/kbYczaQUPm+joQFkIh4Zalm3zvWqqBq68jBFmw== X-Received: by 2002:a05:6a20:6695:b0:cc:6699:dd8a with SMTP id o21-20020a056a20669500b000cc6699dd8amr8122889pzh.45.1679808500304; Sat, 25 Mar 2023 22:28:20 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.213.201]) by smtp.gmail.com with ESMTPSA id b14-20020a63eb4e000000b004fb5f4bf585sm15966915pgk.78.2023.03.25.22.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 22:28:20 -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 1/4] clk: hisilicon: Add helper functions for platform driver Date: Sun, 26 Mar 2023 13:27:47 +0800 Message-Id: <20230326052757.297551-2-mmyangfl@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230326052757.297551-1-mmyangfl@gmail.com> References: <20230326052757.297551-1-mmyangfl@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 | 148 ++++++++++++++++++++++++++++++++++ drivers/clk/hisilicon/clk.h | 56 +++++++++++-- drivers/clk/hisilicon/crg.h | 5 ++ drivers/clk/hisilicon/reset.c | 65 ++++++++++++++- 4 files changed, 266 insertions(+), 8 deletions(-) diff --git a/drivers/clk/hisilicon/clk.c b/drivers/clk/hisilicon/clk.c index 54d9fdc93599..96bbc09e7d45 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); =20 +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,132 @@ void __init hi6220_clk_register_divider(const struct = hi6220_divider_clock *clks, data->clk_data.clks[clks[i].id] =3D clk; } } + +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 =3D hisi_clk_register_mux(clks->mux_clks, + clks->mux_clks_num, data); + if (ret) + return ret; + } + + if (clks->phase_clks_num) { + ret =3D hisi_clk_register_phase(dev, clks->phase_clks, + clks->phase_clks_num, data); + if (ret) + return ret; + } + + if (clks->divider_clks_num) { + ret =3D hisi_clk_register_divider(clks->divider_clks, + clks->divider_clks_num, data); + if (ret) + return ret; + } + + if (clks->gate_clks_num) { + ret =3D 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 =3D clks->clk_register_customized(dev, clks->customized_clks, + clks->customized_clks_num, data); + if (ret) + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(hisi_clk_register); + +int hisi_clk_early_init(struct device_node *np, const struct hisi_clocks *= clks) +{ + struct hisi_clock_data *data; + int ret; + + data =3D hisi_clk_init(np, clks->nr); + if (!data) + return -ENOMEM; + data->clks =3D clks; + + ret =3D hisi_clk_register_fixed_rate(clks->fixed_rate_clks, + clks->fixed_rate_clks_num, data); + if (ret) + goto err; + + ret =3D hisi_clk_register_fixed_factor(clks->fixed_factor_clks, + clks->fixed_factor_clks_num, data); + if (ret) + goto err; + + np->data =3D data; + return 0; + +err: + hisi_clk_free(np, data); + return ret; +} +EXPORT_SYMBOL_GPL(hisi_clk_early_init); + +int hisi_clk_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct device_node *np =3D dev->of_node; + const struct hisi_clocks *clks; + struct hisi_clock_data *data; + int ret; + + clks =3D of_device_get_match_data(dev); + if (!clks) + return -ENOENT; + + if (!np->data) { + ret =3D hisi_clk_early_init(np, clks); + if (ret) + return ret; + } + + data =3D np->data; + np->data =3D NULL; + + if (clks->prologue) { + ret =3D clks->prologue(dev, data); + if (ret) + goto err; + } + + ret =3D 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); + +int hisi_clk_remove(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct device_node *np =3D dev->of_node; + struct hisi_clock_data *data =3D platform_get_drvdata(pdev); + + hisi_clk_free(np, data); + return 0; +} +EXPORT_SYMBOL_GPL(hisi_clk_remove); diff --git a/drivers/clk/hisilicon/clk.h b/drivers/clk/hisilicon/clk.h index 7a9b42e1b027..def94498e14d 100644 --- a/drivers/clk/hisilicon/clk.h +++ b/drivers/clk/hisilicon/clk.h @@ -17,10 +17,12 @@ #include =20 struct platform_device; +struct hisi_clocks; =20 struct hisi_clock_data { struct clk_onecell_data clk_data; void __iomem *base; + const struct hisi_clocks *clks; }; =20 struct hisi_fixed_rate_clock { @@ -103,6 +105,38 @@ struct hisi_gate_clock { const char *alias; }; =20 +struct hisi_clocks { + int nr; + + int (*prologue)(struct device *dev, struct hisi_clock_data *data); + + const struct hisi_fixed_rate_clock *fixed_rate_clks; + int fixed_rate_clks_num; + + const struct hisi_fixed_factor_clock *fixed_factor_clks; + int fixed_factor_clks_num; + + const struct hisi_mux_clock *mux_clks; + int mux_clks_num; + + const struct hisi_phase_clock *phase_clks; + int phase_clks_num; + + const struct hisi_divider_clock *divider_clks; + int divider_clks_num; + + const struct hisi_gate_clock *gate_clks; + int gate_clks_num; + + const struct hisi_gate_clock *gate_sep_clks; + int gate_sep_clks_num; + + const void *customized_clks; + int customized_clks_num; + int (*clk_register_customized)(struct device *dev, const void *clks, + int 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 +147,7 @@ struct clk *hi6220_register_clkdiv(struct device *dev, = const char *name, =20 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 *, @@ -134,7 +169,16 @@ void hisi_clk_register_gate_sep(const struct hisi_gate= _clock *, void hi6220_clk_register_divider(const struct hi6220_divider_clock *, int, struct hisi_clock_data *); =20 -#define hisi_clk_unregister(type) \ +int hisi_clk_register(struct device *dev, const struct hisi_clocks *clks, + struct hisi_clock_data *data); + +/* 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); +int hisi_clk_remove(struct platform_device *pdev); + +#define hisi_clk_unregister_fn(type) \ static inline \ void hisi_clk_unregister_##type(const struct hisi_##type##_clock *clks, \ int nums, struct hisi_clock_data *data) \ @@ -148,10 +192,10 @@ void hisi_clk_unregister_##type(const struct hisi_##t= ype##_clock *clks, \ } \ } =20 -hisi_clk_unregister(fixed_rate) -hisi_clk_unregister(fixed_factor) -hisi_clk_unregister(mux) -hisi_clk_unregister(divider) -hisi_clk_unregister(gate) +hisi_clk_unregister_fn(fixed_rate) +hisi_clk_unregister_fn(fixed_factor) +hisi_clk_unregister_fn(mux) +hisi_clk_unregister_fn(divider) +hisi_clk_unregister_fn(gate) =20 #endif /* __HISI_CLK_H */ diff --git a/drivers/clk/hisilicon/crg.h b/drivers/clk/hisilicon/crg.h index 803f6ba6d7a2..d9544f1f2625 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; }; =20 +/* helper functions for platform driver */ + +int hisi_crg_probe(struct platform_device *pdev); +int 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..471b5670e4dc 100644 --- a/drivers/clk/hisilicon/reset.c +++ b/drivers/clk/hisilicon/reset.c @@ -5,12 +5,16 @@ * Copyright (c) 2015-2016 HiSilicon Technologies Co., Ltd. */ =20 +#include #include +#include #include -#include +#include #include -#include #include + +#include "clk.h" +#include "crg.h" #include "reset.h" =20 #define HISI_RESET_BIT_MASK 0x1f @@ -116,3 +120,60 @@ void hisi_reset_exit(struct hisi_reset_controller *rst= c) reset_controller_unregister(&rstc->rcdev); } EXPORT_SYMBOL_GPL(hisi_reset_exit); + +int hisi_crg_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct device_node *np =3D dev->of_node; + const struct hisi_clocks *clks; + struct hisi_crg_dev *crg; + int ret; + + clks =3D of_device_get_match_data(dev); + if (!clks) + return -ENOENT; + + crg =3D devm_kmalloc(dev, sizeof(*crg), GFP_KERNEL); + if (!crg) + return -ENOMEM; + + if (!np->data) { + ret =3D hisi_clk_early_init(np, clks); + if (ret) + return ret; + } + + crg->clk_data =3D np->data; + np->data =3D NULL; + + ret =3D hisi_clk_register(dev, clks, crg->clk_data); + if (ret) + goto err; + + crg->rstc =3D hisi_reset_init(pdev); + if (!crg->rstc) { + ret =3D -ENOMEM; + goto err; + } + + platform_set_drvdata(pdev, crg); + return 0; + +err: + hisi_clk_free(np, crg->clk_data); + return ret; +} +EXPORT_SYMBOL_GPL(hisi_crg_probe); + +int hisi_crg_remove(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct device_node *np =3D dev->of_node; + struct hisi_crg_dev *crg =3D platform_get_drvdata(pdev); + + hisi_reset_exit(crg->rstc); + crg->funcs->unregister_clks(pdev); + hisi_clk_free(np, crg->clk_data); + return 0; +} +EXPORT_SYMBOL_GPL(hisi_crg_remove); --=20 2.39.2 From nobody Sat Apr 27 21:51:01 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12A91C761AF for ; Sun, 26 Mar 2023 05:28:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231906AbjCZF25 (ORCPT ); Sun, 26 Mar 2023 01:28:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231330AbjCZF2z (ORCPT ); Sun, 26 Mar 2023 01:28:55 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC6551FD6; Sat, 25 Mar 2023 22:28:45 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id e15-20020a17090ac20f00b0023d1b009f52so8906129pjt.2; Sat, 25 Mar 2023 22:28:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679808525; 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=Lf6DPp/q1TX2YNzmlllkA7XUi5qRczt/JESYvuaVLJg=; b=dykNfZh9XGJWtgPABGuhwC3XDH8VdrC/Txx0KVFZczC7/518uVA7KIJ+fuY3ZZVSl7 1Cma17CNfjMFJ7x1czi/1uLdFAG+2n/wFtEc8mxZek/lW99h+CRyLGmrSB18ozVBc/Ay F2XtzA6hJGNpXs9XiTED3cdkjUOBXxCnA8HM43ZWqB4GiwbroygnRQaFzaXTVmZhmBl/ JOhkwYjz0bDGXIbV71ziRkNO3BAmsM/AtE+Qd9mkncDTAyvf3ciApio9V0Rl5tfCt5bc BjzyNTE13w3TPukW1vSo4Jv5GLjZLCTHltI3bQr96yRZutnW8WZ0SqzxgIdL8puYH+IL evog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679808525; 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=Lf6DPp/q1TX2YNzmlllkA7XUi5qRczt/JESYvuaVLJg=; b=rLQlK4D5AV056T5aZ4zPcdZQXBz1HUvggzphAsNyiuCXJ4mHWDuJt6OrRLqOsqUrMg lAQ8hnYhWIsGDnxV+z+PWsP9uTkzE8x85R/0fUOEnRE1hY3w5HTofddckGWh2lKXHwgZ MCgF5ISv1L2CUxTIFGLf5kuN1ATsb+ttal/ny9Go5XWbHSU4yzvosTgaILtamatdAwjp O8liL98ZeVRZHkw3+gkj+zFsJmqds5S3QDvifNnb5l4guoPxjaLrRpjRVyEH2ymltpCG 9DF0I9GveBwk9/6nPxrZwI5xdiP2WbChyY5RrOoY/CzPdf5Q9wISUdbi26tfNEbI9wUr ocuw== X-Gm-Message-State: AO0yUKXmml+Fzz2BzaUT/6iyq7VCtQ3HvNR5t105iXP5jHs5yp5pLJj4 u/UUMf4u42wOfdcDGggNiFUUFr2+N/gUjKzXm/8= X-Google-Smtp-Source: AK7set8vfTpBIBrwER3k4Go/hRvhWHyfcSVsUbolLUPqrY/Xf7QfmPc8zAsH3Cl76dLhDbp5J9gTcA== X-Received: by 2002:a05:6a20:6d04:b0:d7:5cf7:9019 with SMTP id fv4-20020a056a206d0400b000d75cf79019mr6391105pzb.25.1679808524554; Sat, 25 Mar 2023 22:28:44 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.213.201]) by smtp.gmail.com with ESMTPSA id b14-20020a63eb4e000000b004fb5f4bf585sm15966915pgk.78.2023.03.25.22.28.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 22:28:44 -0700 (PDT) From: David Yang To: linux-clk@vger.kernel.org Cc: David Yang , Michael Turquette , Stephen Boyd , linux-kernel@vger.kernel.org, Conor Dooley , Nick Alcock Subject: [PATCH 2/4] clk: hisilicon: Use helper functions Date: Sun, 26 Mar 2023 13:27:48 +0800 Message-Id: <20230326052757.297551-3-mmyangfl@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230326052757.297551-1-mmyangfl@gmail.com> References: <20230326052757.297551-1-mmyangfl@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Remove redundant codes. Signed-off-by: David Yang --- drivers/clk/hisilicon/clk-hi3519.c | 134 ++---------- drivers/clk/hisilicon/clk-hi3559a.c | 228 +++----------------- drivers/clk/hisilicon/clk-hi3660.c | 207 ++++++------------ drivers/clk/hisilicon/clk-hi3670.c | 270 +++++++++--------------- drivers/clk/hisilicon/crg-hi3516cv300.c | 177 ++-------------- drivers/clk/hisilicon/crg-hi3798cv200.c | 206 +++--------------- drivers/clk/hisilicon/crg.h | 6 - drivers/clk/hisilicon/reset.c | 1 - 8 files changed, 260 insertions(+), 969 deletions(-) diff --git a/drivers/clk/hisilicon/clk-hi3519.c b/drivers/clk/hisilicon/clk= -hi3519.c index ad0c7f350cf0..199d1b8c3140 100644 --- a/drivers/clk/hisilicon/clk-hi3519.c +++ b/drivers/clk/hisilicon/clk-hi3519.c @@ -6,11 +6,13 @@ */ =20 #include -#include + +#include #include -#include +#include + #include "clk.h" -#include "reset.h" +#include "crg.h" =20 #define HI3519_INNER_CLK_OFFSET 64 #define HI3519_FIXED_24M 65 @@ -73,131 +75,33 @@ static const struct hisi_gate_clock hi3519_gate_clks[]= =3D { CLK_SET_RATE_PARENT, 0xe4, 18, 0, }, }; =20 -static struct hisi_clock_data *hi3519_clk_register(struct platform_device = *pdev) -{ - struct hisi_clock_data *clk_data; - int ret; - - clk_data =3D hisi_clk_alloc(pdev, HI3519_NR_CLKS); - if (!clk_data) - return ERR_PTR(-ENOMEM); - - ret =3D hisi_clk_register_fixed_rate(hi3519_fixed_rate_clks, - ARRAY_SIZE(hi3519_fixed_rate_clks), - clk_data); - if (ret) - return ERR_PTR(ret); - - ret =3D hisi_clk_register_mux(hi3519_mux_clks, - ARRAY_SIZE(hi3519_mux_clks), - clk_data); - if (ret) - goto unregister_fixed_rate; - - ret =3D hisi_clk_register_gate(hi3519_gate_clks, - ARRAY_SIZE(hi3519_gate_clks), - clk_data); - if (ret) - goto unregister_mux; - - ret =3D 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 =3D 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 =3D devm_kmalloc(&pdev->dev, sizeof(*crg), GFP_KERNEL); - if (!crg) - return -ENOMEM; - - crg->rstc =3D hisi_reset_init(pdev); - if (!crg->rstc) - return -ENOMEM; - - crg->clk_data =3D 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 =3D platform_get_drvdata(pdev); - - hisi_reset_exit(crg->rstc); - hi3519_clk_unregister(pdev); - return 0; -} - +static const struct hisi_clocks hi3519_crg_clks =3D { + .nr =3D HI3519_NR_CLKS, + .fixed_rate_clks =3D hi3519_fixed_rate_clks, + .fixed_rate_clks_num =3D ARRAY_SIZE(hi3519_fixed_rate_clks), + .mux_clks =3D hi3519_mux_clks, + .mux_clks_num =3D ARRAY_SIZE(hi3519_mux_clks), + .gate_clks =3D hi3519_gate_clks, + .gate_clks_num =3D ARRAY_SIZE(hi3519_gate_clks), +}; =20 static const struct of_device_id hi3519_clk_match_table[] =3D { - { .compatible =3D "hisilicon,hi3519-crg" }, + { .compatible =3D "hisilicon,hi3519-crg", + .data =3D &hi3519_crg_clks }, { } }; MODULE_DEVICE_TABLE(of, hi3519_clk_match_table); =20 static struct platform_driver hi3519_clk_driver =3D { - .probe =3D hi3519_clk_probe, - .remove =3D hi3519_clk_remove, + .probe =3D hisi_crg_probe, + .remove =3D hisi_crg_remove, .driver =3D { .name =3D "hi3519-clk", .of_match_table =3D hi3519_clk_match_table, }, }; =20 -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); =20 MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("HiSilicon Hi3519 Clock Driver"); diff --git a/drivers/clk/hisilicon/clk-hi3559a.c b/drivers/clk/hisilicon/cl= k-hi3559a.c index 8036bd8cbb0a..d641b2a759dd 100644 --- a/drivers/clk/hisilicon/clk-hi3559a.c +++ b/drivers/clk/hisilicon/clk-hi3559a.c @@ -11,7 +11,6 @@ #include #include #include -#include =20 #include =20 @@ -452,9 +451,11 @@ static const struct clk_ops hisi_clk_pll_ops =3D { .recalc_rate =3D clk_pll_recalc_rate, }; =20 -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, + int nums, struct hisi_clock_data *data) { + const struct hi3559av100_pll_clock *clks =3D clocks; void __iomem *base =3D data->base; struct hi3559av100_clk_pll *p_clk =3D NULL; struct clk *clk =3D NULL; @@ -464,7 +465,7 @@ static void hisi_clk_register_pll(struct hi3559av100_pl= l_clock *clks, p_clk =3D devm_kzalloc(dev, sizeof(*p_clk) * nums, GFP_KERNEL); =20 if (!p_clk) - return; + return -ENOMEM; =20 for (i =3D 0; i < nums; i++) { init.name =3D clks[i].name; @@ -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); } =20 data->clk_data.clks[clks[i].id] =3D 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 =3D hisi_clk_alloc(pdev, HI3559AV100_CRG_NR_CLKS); - if (!clk_data) - return ERR_PTR(-ENOMEM); - - ret =3D 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 =3D hisi_clk_register_mux(hi3559av100_mux_clks_crg, - ARRAY_SIZE(hi3559av100_mux_clks_crg), clk_data); - if (ret) - goto unregister_fixed_rate; - - ret =3D hisi_clk_register_gate(hi3559av100_gate_clks, - ARRAY_SIZE(hi3559av100_gate_clks), clk_data); - if (ret) - goto unregister_mux; - - ret =3D 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); -} =20 -static void hi3559av100_clk_unregister(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg =3D 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; } =20 -static const struct hisi_crg_funcs hi3559av100_crg_funcs =3D { - .register_clks =3D hi3559av100_clk_register, - .unregister_clks =3D hi3559av100_clk_unregister, +static const struct hisi_clocks hi3559av100_clks =3D { + .nr =3D HI3559AV100_CRG_NR_CLKS, + .fixed_rate_clks =3D hi3559av100_fixed_rate_clks_crg, + .fixed_rate_clks_num =3D ARRAY_SIZE(hi3559av100_fixed_rate_clks_crg), + .mux_clks =3D hi3559av100_mux_clks_crg, + .mux_clks_num =3D ARRAY_SIZE(hi3559av100_mux_clks_crg), + .gate_clks =3D hi3559av100_gate_clks, + .gate_clks_num =3D ARRAY_SIZE(hi3559av100_gate_clks), + .customized_clks =3D hi3559av100_pll_clks, + .customized_clks_num =3D ARRAY_SIZE(hi3559av100_pll_clks), + .clk_register_customized =3D hisi_clk_register_pll, }; =20 static struct hisi_fixed_rate_clock hi3559av100_shub_fixed_rate_clks[] =3D= { @@ -673,7 +623,7 @@ static struct hisi_gate_clock hi3559av100_shub_gate_clk= s[] =3D { }, }; =20 -static int hi3559av100_shub_default_clk_set(void) +static int hi3559av100_shub_default_clk_set(struct device *dev, struct his= i_clock_data *data) { void __iomem *crg_base; unsigned int val; @@ -696,149 +646,41 @@ static int hi3559av100_shub_default_clk_set(void) return 0; } =20 -static struct hisi_clock_data *hi3559av100_shub_clk_register( - struct platform_device *pdev) -{ - struct hisi_clock_data *clk_data =3D NULL; - int ret; - - hi3559av100_shub_default_clk_set(); - - clk_data =3D hisi_clk_alloc(pdev, HI3559AV100_SHUB_NR_CLKS); - if (!clk_data) - return ERR_PTR(-ENOMEM); - - ret =3D 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 =3D hisi_clk_register_mux(hi3559av100_shub_mux_clks, - ARRAY_SIZE(hi3559av100_shub_mux_clks), clk_data); - if (ret) - goto unregister_fixed_rate; - - ret =3D hisi_clk_register_divider(hi3559av100_shub_div_clks, - ARRAY_SIZE(hi3559av100_shub_div_clks), clk_data); - if (ret) - goto unregister_mux; - - ret =3D hisi_clk_register_gate(hi3559av100_shub_gate_clks, - ARRAY_SIZE(hi3559av100_shub_gate_clks), clk_data); - if (ret) - goto unregister_factor; - - ret =3D 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 =3D 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 =3D { - .register_clks =3D hi3559av100_shub_clk_register, - .unregister_clks =3D hi3559av100_shub_clk_unregister, +static const struct hisi_clocks hi3559av100_shub_clks =3D { + .nr =3D HI3559AV100_SHUB_NR_CLKS, + .prologue =3D hi3559av100_shub_default_clk_set, + .fixed_rate_clks =3D hi3559av100_shub_fixed_rate_clks, + .fixed_rate_clks_num =3D ARRAY_SIZE(hi3559av100_shub_fixed_rate_clks), + .mux_clks =3D hi3559av100_shub_mux_clks, + .mux_clks_num =3D ARRAY_SIZE(hi3559av100_shub_mux_clks), + .divider_clks =3D hi3559av100_shub_div_clks, + .divider_clks_num =3D ARRAY_SIZE(hi3559av100_shub_div_clks), + .gate_clks =3D hi3559av100_shub_gate_clks, + .gate_clks_num =3D ARRAY_SIZE(hi3559av100_shub_gate_clks), }; =20 static const struct of_device_id hi3559av100_crg_match_table[] =3D { { .compatible =3D "hisilicon,hi3559av100-clock", - .data =3D &hi3559av100_crg_funcs + .data =3D &hi3559av100_clks }, { .compatible =3D "hisilicon,hi3559av100-shub-clock", - .data =3D &hi3559av100_shub_crg_funcs + .data =3D &hi3559av100_shub_clks }, { } }; MODULE_DEVICE_TABLE(of, hi3559av100_crg_match_table); =20 -static int hi3559av100_crg_probe(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg; - - crg =3D devm_kmalloc(&pdev->dev, sizeof(*crg), GFP_KERNEL); - if (!crg) - return -ENOMEM; - - crg->funcs =3D of_device_get_match_data(&pdev->dev); - if (!crg->funcs) - return -ENOENT; - - crg->rstc =3D hisi_reset_init(pdev); - if (!crg->rstc) - return -ENOMEM; - - crg->clk_data =3D 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 int hi3559av100_crg_remove(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg =3D platform_get_drvdata(pdev); - - hisi_reset_exit(crg->rstc); - crg->funcs->unregister_clks(pdev); - return 0; -} - static struct platform_driver hi3559av100_crg_driver =3D { - .probe =3D hi3559av100_crg_probe, - .remove =3D hi3559av100_crg_remove, + .probe =3D hisi_crg_probe, + .remove =3D hisi_crg_remove, .driver =3D { .name =3D "hi3559av100-clock", .of_match_table =3D hi3559av100_crg_match_table, }, }; =20 -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); =20 MODULE_DESCRIPTION("HiSilicon Hi3559AV100 CRG Driver"); diff --git a/drivers/clk/hisilicon/clk-hi3660.c b/drivers/clk/hisilicon/clk= -hi3660.c index 41f61726ab19..c41b84545960 100644 --- a/drivers/clk/hisilicon/clk-hi3660.c +++ b/drivers/clk/hisilicon/clk-hi3660.c @@ -5,9 +5,11 @@ */ =20 #include -#include + +#include +#include #include -#include + #include "clk.h" =20 static const struct hisi_fixed_rate_clock hi3660_fixed_rate_clks[] =3D { @@ -469,169 +471,92 @@ static const struct hisi_gate_clock hi3660_iomcu_gat= e_sep_clks[] =3D { CLK_SET_RATE_PARENT, 0x90, 0, 0, }, }; =20 -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 =3D ARRAY_SIZE(hi3660_iomcu_gate_sep_clks); - - clk_data =3D 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 =3D ARRAY_SIZE(hi3660_pmu_gate_clks); - - clk_data =3D 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 =3D { + .nr =3D ARRAY_SIZE(hi3660_iomcu_gate_sep_clks), + .gate_sep_clks =3D hi3660_iomcu_gate_sep_clks, + .gate_sep_clks_num =3D ARRAY_SIZE(hi3660_iomcu_gate_sep_clks), +}; =20 -static void hi3660_clk_pctrl_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - int nr =3D ARRAY_SIZE(hi3660_pctrl_gate_clks); +static const struct hisi_clocks hi3660_clk_pmuctrl_clks =3D { + .nr =3D ARRAY_SIZE(hi3660_pmu_gate_clks), + .gate_clks =3D hi3660_pmu_gate_clks, + .gate_clks_num =3D ARRAY_SIZE(hi3660_pmu_gate_clks), +}; =20 - clk_data =3D 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 =3D { + .nr =3D ARRAY_SIZE(hi3660_pctrl_gate_clks), + .gate_clks =3D hi3660_pctrl_gate_clks, + .gate_clks_num =3D ARRAY_SIZE(hi3660_pctrl_gate_clks), +}; =20 -static void hi3660_clk_sctrl_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - int nr =3D 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 =3D { + .nr =3D ARRAY_SIZE(hi3660_sctrl_mux_clks) + + ARRAY_SIZE(hi3660_sctrl_divider_clks) + + ARRAY_SIZE(hi3660_sctrl_gate_clks) + + ARRAY_SIZE(hi3660_sctrl_gate_sep_clks), + .mux_clks =3D hi3660_sctrl_mux_clks, + .mux_clks_num =3D ARRAY_SIZE(hi3660_sctrl_mux_clks), + .divider_clks =3D hi3660_sctrl_divider_clks, + .divider_clks_num =3D ARRAY_SIZE(hi3660_sctrl_divider_clks), + .gate_clks =3D hi3660_sctrl_gate_clks, + .gate_clks_num =3D ARRAY_SIZE(hi3660_sctrl_gate_clks), + .gate_sep_clks =3D hi3660_sctrl_gate_sep_clks, + .gate_sep_clks_num =3D ARRAY_SIZE(hi3660_sctrl_gate_sep_clks), +}; =20 - clk_data =3D 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 =3D { + .nr =3D ARRAY_SIZE(hi3660_fixed_rate_clks) + + ARRAY_SIZE(hi3660_crg_fixed_factor_clks) + + ARRAY_SIZE(hi3660_crgctrl_mux_clks) + + ARRAY_SIZE(hi3660_crgctrl_divider_clks) + + ARRAY_SIZE(hi3660_crgctrl_gate_clks) + + ARRAY_SIZE(hi3660_crgctrl_gate_sep_clks), + .fixed_rate_clks =3D hi3660_fixed_rate_clks, + .fixed_rate_clks_num =3D ARRAY_SIZE(hi3660_fixed_rate_clks), + .fixed_factor_clks =3D hi3660_crg_fixed_factor_clks, + .fixed_factor_clks_num =3D ARRAY_SIZE(hi3660_crg_fixed_factor_clks), + .mux_clks =3D hi3660_crgctrl_mux_clks, + .mux_clks_num =3D ARRAY_SIZE(hi3660_crgctrl_mux_clks), + .divider_clks =3D hi3660_crgctrl_divider_clks, + .divider_clks_num =3D ARRAY_SIZE(hi3660_crgctrl_divider_clks), + .gate_clks =3D hi3660_crgctrl_gate_clks, + .gate_clks_num =3D ARRAY_SIZE(hi3660_crgctrl_gate_clks), + .gate_sep_clks =3D hi3660_crgctrl_gate_sep_clks, + .gate_sep_clks_num =3D ARRAY_SIZE(hi3660_crgctrl_gate_sep_clks), +}; =20 static void hi3660_clk_crgctrl_early_init(struct device_node *np) { - int nr =3D 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 =3D hisi_clk_init(np, nr); - if (!clk_crgctrl_data) - return; - - for (i =3D 0; i < nr; i++) - clk_crgctrl_data->clk_data.clks[i] =3D 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); =20 -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 =3D clk_crgctrl_data->clk_data.clks; - for (i =3D 0; i < clk_crgctrl_data->clk_data.clk_num; i++) { - if (IS_ERR(clks[i]) && PTR_ERR(clks[i]) !=3D -EPROBE_DEFER) - pr_err("Failed to register crgctrl clock[%d] err=3D%ld\n", - i, PTR_ERR(clks[i])); - } -} - static const struct of_device_id hi3660_clk_match_table[] =3D { { .compatible =3D "hisilicon,hi3660-crgctrl", - .data =3D hi3660_clk_crgctrl_init }, + .data =3D &hi3660_clk_crgctrl_clks }, { .compatible =3D "hisilicon,hi3660-pctrl", - .data =3D hi3660_clk_pctrl_init }, + .data =3D &hi3660_clk_pctrl_clks }, { .compatible =3D "hisilicon,hi3660-pmuctrl", - .data =3D hi3660_clk_pmuctrl_init }, + .data =3D &hi3660_clk_pmuctrl_clks }, { .compatible =3D "hisilicon,hi3660-sctrl", - .data =3D hi3660_clk_sctrl_init }, + .data =3D &hi3660_clk_sctrl_clks }, { .compatible =3D "hisilicon,hi3660-iomcu", - .data =3D hi3660_clk_iomcu_init }, + .data =3D &hi3660_clk_iomcu_clks }, { } }; - -static int hi3660_clk_probe(struct platform_device *pdev) -{ - struct device *dev =3D &pdev->dev; - struct device_node *np =3D pdev->dev.of_node; - void (*init_func)(struct device_node *np); - - init_func =3D of_device_get_match_data(dev); - if (!init_func) - return -ENODEV; - - init_func(np); - - return 0; -} +MODULE_DEVICE_TABLE(of, hi3660_clk_match_table); =20 static struct platform_driver hi3660_clk_driver =3D { - .probe =3D hi3660_clk_probe, + .probe =3D hisi_clk_probe, + .remove =3D hisi_clk_remove, .driver =3D { .name =3D "hi3660-clk", .of_match_table =3D hi3660_clk_match_table, }, }; =20 -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"); +MODULE_DESCRIPTION("HiSilicon Hi3660 Clock Driver"); diff --git a/drivers/clk/hisilicon/clk-hi3670.c b/drivers/clk/hisilicon/clk= -hi3670.c index 4d05a71683a5..8853a61ab808 100644 --- a/drivers/clk/hisilicon/clk-hi3670.c +++ b/drivers/clk/hisilicon/clk-hi3670.c @@ -8,9 +8,11 @@ */ =20 #include -#include + +#include +#include #include -#include + #include "clk.h" =20 static const struct hisi_fixed_rate_clock hi3670_fixed_rate_clks[] =3D { @@ -822,195 +824,113 @@ static const struct hisi_gate_clock hi3670_media2_g= ate_sep_clks[] =3D { CLK_SET_RATE_PARENT, 0x00, 2, 0, }, }; =20 -static void hi3670_clk_crgctrl_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - - int nr =3D 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 =3D 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 =3D ARRAY_SIZE(hi3670_pctrl_gate_clks); - - clk_data =3D 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 =3D ARRAY_SIZE(hi3670_pmu_gate_clks); - - clk_data =3D 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 =3D 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 =3D 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 =3D ARRAY_SIZE(hi3670_iomcu_gate_sep_clks) + - ARRAY_SIZE(hi3670_iomcu_fixed_factor_clks); - - clk_data =3D 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 =3D 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 =3D 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 =3D ARRAY_SIZE(hi3670_media2_gate_sep_clks); - - clk_data =3D 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 =3D { + .nr =3D ARRAY_SIZE(hi3670_fixed_rate_clks) + + ARRAY_SIZE(hi3670_crg_fixed_factor_clks) + + ARRAY_SIZE(hi3670_crgctrl_mux_clks) + + ARRAY_SIZE(hi3670_crgctrl_divider_clks) + + ARRAY_SIZE(hi3670_crgctrl_gate_clks) + + ARRAY_SIZE(hi3670_crgctrl_gate_sep_clks), + .fixed_rate_clks =3D hi3670_fixed_rate_clks, + .fixed_rate_clks_num =3D ARRAY_SIZE(hi3670_fixed_rate_clks), + .fixed_factor_clks =3D hi3670_crg_fixed_factor_clks, + .fixed_factor_clks_num =3D ARRAY_SIZE(hi3670_crg_fixed_factor_clks), + .mux_clks =3D hi3670_crgctrl_mux_clks, + .mux_clks_num =3D ARRAY_SIZE(hi3670_crgctrl_mux_clks), + .divider_clks =3D hi3670_crgctrl_divider_clks, + .divider_clks_num =3D ARRAY_SIZE(hi3670_crgctrl_divider_clks), + .gate_clks =3D hi3670_crgctrl_gate_clks, + .gate_clks_num =3D ARRAY_SIZE(hi3670_crgctrl_gate_clks), + .gate_sep_clks =3D hi3670_crgctrl_gate_sep_clks, + .gate_sep_clks_num =3D ARRAY_SIZE(hi3670_crgctrl_gate_sep_clks), +}; + +static const struct hisi_clocks hi3670_clk_pctrl_clks =3D { + .nr =3D ARRAY_SIZE(hi3670_pctrl_gate_clks), + .gate_clks =3D hi3670_pctrl_gate_clks, + .gate_clks_num =3D ARRAY_SIZE(hi3670_pctrl_gate_clks), +}; + +static const struct hisi_clocks hi3670_clk_pmuctrl_clks =3D { + .nr =3D ARRAY_SIZE(hi3670_pmu_gate_clks), + .gate_clks =3D hi3670_pmu_gate_clks, + .gate_clks_num =3D ARRAY_SIZE(hi3670_pmu_gate_clks), +}; + +static const struct hisi_clocks hi3670_clk_sctrl_clks =3D { + .nr =3D ARRAY_SIZE(hi3670_sctrl_mux_clks) + + ARRAY_SIZE(hi3670_sctrl_divider_clks) + + ARRAY_SIZE(hi3670_sctrl_gate_clks) + + ARRAY_SIZE(hi3670_sctrl_gate_sep_clks), + .mux_clks =3D hi3670_sctrl_mux_clks, + .mux_clks_num =3D ARRAY_SIZE(hi3670_sctrl_mux_clks), + .divider_clks =3D hi3670_sctrl_divider_clks, + .divider_clks_num =3D ARRAY_SIZE(hi3670_sctrl_divider_clks), + .gate_clks =3D hi3670_sctrl_gate_clks, + .gate_clks_num =3D ARRAY_SIZE(hi3670_sctrl_gate_clks), + .gate_sep_clks =3D hi3670_sctrl_gate_sep_clks, + .gate_sep_clks_num =3D ARRAY_SIZE(hi3670_sctrl_gate_sep_clks), +}; + +static const struct hisi_clocks hi3670_clk_iomcu_clks =3D { + .nr =3D ARRAY_SIZE(hi3670_iomcu_fixed_factor_clks) + + ARRAY_SIZE(hi3670_iomcu_gate_sep_clks), + .fixed_factor_clks =3D hi3670_iomcu_fixed_factor_clks, + .fixed_factor_clks_num =3D ARRAY_SIZE(hi3670_iomcu_fixed_factor_clks), + .gate_clks =3D hi3670_iomcu_gate_sep_clks, + .gate_clks_num =3D ARRAY_SIZE(hi3670_iomcu_gate_sep_clks), +}; + +static const struct hisi_clocks hi3670_clk_media1_clks =3D { + .nr =3D ARRAY_SIZE(hi3670_media1_mux_clks) + + ARRAY_SIZE(hi3670_media1_divider_clks) + + ARRAY_SIZE(hi3670_media1_gate_clks) + + ARRAY_SIZE(hi3670_media1_gate_sep_clks), + .mux_clks =3D hi3670_media1_mux_clks, + .mux_clks_num =3D ARRAY_SIZE(hi3670_media1_mux_clks), + .divider_clks =3D hi3670_media1_divider_clks, + .divider_clks_num =3D ARRAY_SIZE(hi3670_media1_divider_clks), + .gate_clks =3D hi3670_media1_gate_clks, + .gate_clks_num =3D ARRAY_SIZE(hi3670_media1_gate_clks), + .gate_sep_clks =3D hi3670_media1_gate_sep_clks, + .gate_sep_clks_num =3D ARRAY_SIZE(hi3670_media1_gate_sep_clks), +}; + +static const struct hisi_clocks hi3670_clk_media2_clks =3D { + .nr =3D ARRAY_SIZE(hi3670_media2_gate_sep_clks), + .gate_sep_clks =3D hi3670_media2_gate_sep_clks, + .gate_sep_clks_num =3D ARRAY_SIZE(hi3670_media2_gate_sep_clks), +}; =20 static const struct of_device_id hi3670_clk_match_table[] =3D { { .compatible =3D "hisilicon,hi3670-crgctrl", - .data =3D hi3670_clk_crgctrl_init }, + .data =3D &hi3670_clk_crgctrl_clks }, { .compatible =3D "hisilicon,hi3670-pctrl", - .data =3D hi3670_clk_pctrl_init }, + .data =3D &hi3670_clk_pctrl_clks }, { .compatible =3D "hisilicon,hi3670-pmuctrl", - .data =3D hi3670_clk_pmuctrl_init }, + .data =3D &hi3670_clk_pmuctrl_clks }, { .compatible =3D "hisilicon,hi3670-sctrl", - .data =3D hi3670_clk_sctrl_init }, + .data =3D &hi3670_clk_sctrl_clks }, { .compatible =3D "hisilicon,hi3670-iomcu", - .data =3D hi3670_clk_iomcu_init }, + .data =3D &hi3670_clk_iomcu_clks }, { .compatible =3D "hisilicon,hi3670-media1-crg", - .data =3D hi3670_clk_media1_init }, + .data =3D &hi3670_clk_media1_clks }, { .compatible =3D "hisilicon,hi3670-media2-crg", - .data =3D hi3670_clk_media2_init }, + .data =3D &hi3670_clk_media2_clks }, { } }; - -static int hi3670_clk_probe(struct platform_device *pdev) -{ - struct device *dev =3D &pdev->dev; - struct device_node *np =3D pdev->dev.of_node; - void (*init_func)(struct device_node *np); - - init_func =3D of_device_get_match_data(dev); - if (!init_func) - return -ENODEV; - - init_func(np); - - return 0; -} +MODULE_DEVICE_TABLE(of, hi3670_clk_match_table); =20 static struct platform_driver hi3670_clk_driver =3D { - .probe =3D hi3670_clk_probe, + .probe =3D hisi_clk_probe, + .remove =3D hisi_clk_remove, .driver =3D { .name =3D "hi3670-clk", .of_match_table =3D hi3670_clk_match_table, }, }; =20 -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"); diff --git a/drivers/clk/hisilicon/crg-hi3516cv300.c b/drivers/clk/hisilico= n/crg-hi3516cv300.c index 5d4e61c7a429..0805852ecc87 100644 --- a/drivers/clk/hisilicon/crg-hi3516cv300.c +++ b/drivers/clk/hisilicon/crg-hi3516cv300.c @@ -6,13 +6,13 @@ */ =20 #include -#include + +#include #include #include -#include + #include "clk.h" #include "crg.h" -#include "reset.h" =20 /* hi3516CV300 core CRG */ #define HI3516CV300_INNER_CLK_OFFSET 64 @@ -126,67 +126,14 @@ static const struct hisi_gate_clock hi3516cv300_gate_= clks[] =3D { { HI3516CV300_USB2_PHY_CLK, "clk_usb2_phy", NULL, 0, 0xb8, 7, 0, }, }; =20 -static struct hisi_clock_data *hi3516cv300_clk_register( - struct platform_device *pdev) -{ - struct hisi_clock_data *clk_data; - int ret; - - clk_data =3D hisi_clk_alloc(pdev, HI3516CV300_CRG_NR_CLKS); - if (!clk_data) - return ERR_PTR(-ENOMEM); - - ret =3D hisi_clk_register_fixed_rate(hi3516cv300_fixed_rate_clks, - ARRAY_SIZE(hi3516cv300_fixed_rate_clks), clk_data); - if (ret) - return ERR_PTR(ret); - - ret =3D hisi_clk_register_mux(hi3516cv300_mux_clks, - ARRAY_SIZE(hi3516cv300_mux_clks), clk_data); - if (ret) - goto unregister_fixed_rate; - - ret =3D hisi_clk_register_gate(hi3516cv300_gate_clks, - ARRAY_SIZE(hi3516cv300_gate_clks), clk_data); - if (ret) - goto unregister_mux; - - ret =3D 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 =3D 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 =3D { - .register_clks =3D hi3516cv300_clk_register, - .unregister_clks =3D hi3516cv300_clk_unregister, +static const struct hisi_clocks hi3516cv300_crg_clks =3D { + .nr =3D HI3516CV300_CRG_NR_CLKS, + .fixed_rate_clks =3D hi3516cv300_fixed_rate_clks, + .fixed_rate_clks_num =3D ARRAY_SIZE(hi3516cv300_fixed_rate_clks), + .mux_clks =3D hi3516cv300_mux_clks, + .mux_clks_num =3D ARRAY_SIZE(hi3516cv300_mux_clks), + .gate_clks =3D hi3516cv300_gate_clks, + .gate_clks_num =3D ARRAY_SIZE(hi3516cv300_gate_clks), }; =20 /* hi3516CV300 sysctrl CRG */ @@ -200,119 +147,35 @@ static const struct hisi_mux_clock hi3516cv300_sysct= rl_mux_clks[] =3D { CLK_SET_RATE_PARENT, 0x0, 23, 1, 0, wdt_mux_table, }, }; =20 -static struct hisi_clock_data *hi3516cv300_sysctrl_clk_register( - struct platform_device *pdev) -{ - struct hisi_clock_data *clk_data; - int ret; - - clk_data =3D hisi_clk_alloc(pdev, HI3516CV300_SYSCTRL_NR_CLKS); - if (!clk_data) - return ERR_PTR(-ENOMEM); - - ret =3D hisi_clk_register_mux(hi3516cv300_sysctrl_mux_clks, - ARRAY_SIZE(hi3516cv300_sysctrl_mux_clks), clk_data); - if (ret) - return ERR_PTR(ret); - - - ret =3D 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 *pde= v) -{ - struct hisi_crg_dev *crg =3D 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 =3D { - .register_clks =3D hi3516cv300_sysctrl_clk_register, - .unregister_clks =3D hi3516cv300_sysctrl_clk_unregister, +static const struct hisi_clocks hi3516cv300_sysctrl_clks =3D { + .nr =3D HI3516CV300_SYSCTRL_NR_CLKS, + .mux_clks =3D hi3516cv300_sysctrl_mux_clks, + .mux_clks_num =3D ARRAY_SIZE(hi3516cv300_sysctrl_mux_clks), }; =20 static const struct of_device_id hi3516cv300_crg_match_table[] =3D { { .compatible =3D "hisilicon,hi3516cv300-crg", - .data =3D &hi3516cv300_crg_funcs + .data =3D &hi3516cv300_crg_clks, }, { .compatible =3D "hisilicon,hi3516cv300-sysctrl", - .data =3D &hi3516cv300_sysctrl_funcs + .data =3D &hi3516cv300_sysctrl_clks, }, { } }; MODULE_DEVICE_TABLE(of, hi3516cv300_crg_match_table); =20 -static int hi3516cv300_crg_probe(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg; - - crg =3D devm_kmalloc(&pdev->dev, sizeof(*crg), GFP_KERNEL); - if (!crg) - return -ENOMEM; - - crg->funcs =3D of_device_get_match_data(&pdev->dev); - if (!crg->funcs) - return -ENOENT; - - crg->rstc =3D hisi_reset_init(pdev); - if (!crg->rstc) - return -ENOMEM; - - crg->clk_data =3D 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 int hi3516cv300_crg_remove(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg =3D platform_get_drvdata(pdev); - - hisi_reset_exit(crg->rstc); - crg->funcs->unregister_clks(pdev); - return 0; -} - static struct platform_driver hi3516cv300_crg_driver =3D { - .probe =3D hi3516cv300_crg_probe, - .remove =3D hi3516cv300_crg_remove, + .probe =3D hisi_crg_probe, + .remove =3D hisi_crg_remove, .driver =3D { .name =3D "hi3516cv300-crg", .of_match_table =3D hi3516cv300_crg_match_table, }, }; =20 -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); =20 MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("HiSilicon Hi3516CV300 CRG Driver"); diff --git a/drivers/clk/hisilicon/crg-hi3798cv200.c b/drivers/clk/hisilico= n/crg-hi3798cv200.c index 08a19ba776e6..967e72099820 100644 --- a/drivers/clk/hisilicon/crg-hi3798cv200.c +++ b/drivers/clk/hisilicon/crg-hi3798cv200.c @@ -6,13 +6,13 @@ */ =20 #include -#include + +#include #include #include -#include + #include "clk.h" #include "crg.h" -#include "reset.h" =20 /* hi3798CV200 core CRG */ #define HI3798CV200_INNER_CLK_OFFSET 64 @@ -41,6 +41,7 @@ =20 #define HI3798CV200_CRG_NR_CLKS 128 =20 +#define HI3798CV200_SYSCTRL_NR_CLKS 16 static const struct hisi_fixed_rate_clock hi3798cv200_fixed_rate_clks[] = =3D { { HISTB_OSC_CLK, "clk_osc", NULL, 0, 24000000, }, { HISTB_APB_CLK, "clk_apb", NULL, 0, 100000000, }, @@ -193,90 +194,18 @@ static const struct hisi_gate_clock hi3798cv200_gate_= clks[] =3D { CLK_SET_RATE_PARENT, 0xb0, 18, 0 }, }; =20 -static struct hisi_clock_data *hi3798cv200_clk_register( - struct platform_device *pdev) -{ - struct hisi_clock_data *clk_data; - int ret; - - clk_data =3D hisi_clk_alloc(pdev, HI3798CV200_CRG_NR_CLKS); - if (!clk_data) - return ERR_PTR(-ENOMEM); - - /* hisi_phase_clock is resource managed */ - ret =3D hisi_clk_register_phase(&pdev->dev, - hi3798cv200_phase_clks, - ARRAY_SIZE(hi3798cv200_phase_clks), - clk_data); - if (ret) - return ERR_PTR(ret); - - ret =3D hisi_clk_register_fixed_rate(hi3798cv200_fixed_rate_clks, - ARRAY_SIZE(hi3798cv200_fixed_rate_clks), - clk_data); - if (ret) - return ERR_PTR(ret); - - ret =3D hisi_clk_register_mux(hi3798cv200_mux_clks, - ARRAY_SIZE(hi3798cv200_mux_clks), - clk_data); - if (ret) - goto unregister_fixed_rate; - - ret =3D hisi_clk_register_gate(hi3798cv200_gate_clks, - ARRAY_SIZE(hi3798cv200_gate_clks), - clk_data); - if (ret) - goto unregister_mux; - - ret =3D 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 =3D 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 =3D { - .register_clks =3D hi3798cv200_clk_register, - .unregister_clks =3D hi3798cv200_clk_unregister, +static const struct hisi_clocks hi3798cv200_crg_clks =3D { + .nr =3D HI3798CV200_CRG_NR_CLKS, + .fixed_rate_clks =3D hi3798cv200_fixed_rate_clks, + .fixed_rate_clks_num =3D ARRAY_SIZE(hi3798cv200_fixed_rate_clks), + .mux_clks =3D hi3798cv200_mux_clks, + .mux_clks_num =3D ARRAY_SIZE(hi3798cv200_mux_clks), + .phase_clks =3D hi3798cv200_phase_clks, + .phase_clks_num =3D ARRAY_SIZE(hi3798cv200_phase_clks), + .gate_clks =3D hi3798cv200_gate_clks, + .gate_clks_num =3D ARRAY_SIZE(hi3798cv200_gate_clks), }; =20 -/* hi3798CV200 sysctrl CRG */ - -#define HI3798CV200_SYSCTRL_NR_CLKS 16 - static const struct hisi_gate_clock hi3798cv200_sysctrl_gate_clks[] =3D { { HISTB_IR_CLK, "clk_ir", "24m", CLK_SET_RATE_PARENT, 0x48, 4, 0, }, @@ -286,116 +215,31 @@ static const struct hisi_gate_clock hi3798cv200_sysc= trl_gate_clks[] =3D { CLK_SET_RATE_PARENT, 0x48, 10, 0, }, }; =20 -static struct hisi_clock_data *hi3798cv200_sysctrl_clk_register( - struct platform_device *pdev) -{ - struct hisi_clock_data *clk_data; - int ret; - - clk_data =3D hisi_clk_alloc(pdev, HI3798CV200_SYSCTRL_NR_CLKS); - if (!clk_data) - return ERR_PTR(-ENOMEM); - - ret =3D hisi_clk_register_gate(hi3798cv200_sysctrl_gate_clks, - ARRAY_SIZE(hi3798cv200_sysctrl_gate_clks), - clk_data); - if (ret) - return ERR_PTR(ret); - - ret =3D 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 *pde= v) -{ - struct hisi_crg_dev *crg =3D 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 =3D { - .register_clks =3D hi3798cv200_sysctrl_clk_register, - .unregister_clks =3D hi3798cv200_sysctrl_clk_unregister, +static const struct hisi_clocks hi3798cv200_sysctrl_clks =3D { + .nr =3D HI3798CV200_SYSCTRL_NR_CLKS, + .gate_clks =3D hi3798cv200_sysctrl_gate_clks, + .gate_clks_num =3D ARRAY_SIZE(hi3798cv200_sysctrl_gate_clks), }; =20 static const struct of_device_id hi3798cv200_crg_match_table[] =3D { { .compatible =3D "hisilicon,hi3798cv200-crg", - .data =3D &hi3798cv200_crg_funcs }, + .data =3D &hi3798cv200_crg_clks }, { .compatible =3D "hisilicon,hi3798cv200-sysctrl", - .data =3D &hi3798cv200_sysctrl_funcs }, + .data =3D &hi3798cv200_sysctrl_clks }, { } }; MODULE_DEVICE_TABLE(of, hi3798cv200_crg_match_table); =20 -static int hi3798cv200_crg_probe(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg; - - crg =3D devm_kmalloc(&pdev->dev, sizeof(*crg), GFP_KERNEL); - if (!crg) - return -ENOMEM; - - crg->funcs =3D of_device_get_match_data(&pdev->dev); - if (!crg->funcs) - return -ENOENT; - - crg->rstc =3D hisi_reset_init(pdev); - if (!crg->rstc) - return -ENOMEM; - - crg->clk_data =3D 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 int hi3798cv200_crg_remove(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg =3D platform_get_drvdata(pdev); - - hisi_reset_exit(crg->rstc); - crg->funcs->unregister_clks(pdev); - return 0; -} - static struct platform_driver hi3798cv200_crg_driver =3D { - .probe =3D hi3798cv200_crg_probe, - .remove =3D hi3798cv200_crg_remove, - .driver =3D { - .name =3D "hi3798cv200-crg", + .probe =3D hisi_crg_probe, + .remove =3D hisi_crg_remove, + .driver =3D { + .name =3D "hi3798cv200-crg", .of_match_table =3D hi3798cv200_crg_match_table, }, }; =20 -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); =20 MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("HiSilicon Hi3798CV200 CRG Driver"); diff --git a/drivers/clk/hisilicon/crg.h b/drivers/clk/hisilicon/crg.h index d9544f1f2625..49142759d63b 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; =20 -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; }; =20 /* helper functions for platform driver */ diff --git a/drivers/clk/hisilicon/reset.c b/drivers/clk/hisilicon/reset.c index 471b5670e4dc..843e7b2c9f0e 100644 --- a/drivers/clk/hisilicon/reset.c +++ b/drivers/clk/hisilicon/reset.c @@ -172,7 +172,6 @@ int hisi_crg_remove(struct platform_device *pdev) struct hisi_crg_dev *crg =3D platform_get_drvdata(pdev); =20 hisi_reset_exit(crg->rstc); - crg->funcs->unregister_clks(pdev); hisi_clk_free(np, crg->clk_data); return 0; } --=20 2.39.2 From nobody Sat Apr 27 21:51:01 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 427F5C6FD1C for ; Sun, 26 Mar 2023 05:29:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231921AbjCZF3L (ORCPT ); Sun, 26 Mar 2023 01:29:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231330AbjCZF3J (ORCPT ); Sun, 26 Mar 2023 01:29:09 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DA8993CA; Sat, 25 Mar 2023 22:29:05 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id u38so3620908pfg.10; Sat, 25 Mar 2023 22:29:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679808544; 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=YKhnMooh27ljfK1QnQ9/evwUgskAV4ZMTmZuvKU5mBY=; b=DPKd59Ctd/pEFdgcPXZjdaMzbrRkF3dNGVY2Nhb0Xmcs1Hwtfw1MJ+3GDzF8hB8xl5 Gl/QglRYLmo6POOBEXkLSnFX0fkuPe1Y85bUg+ZVi92qveYyTJGpRT4UmbhOLO4Vm8jj caJzhXnI7U1PmCAeQizsVX4htEMux7W7ihZm8G19qkxOenh6fhIEUML6dz97k6W4ojIs c7wm6mlqrGtJUYbOGRtb1SbZNJQqgzTGhpVECwReAGXb79kvHIdGlu008GsYBEVik94g zW4doY3FFOwpbC+LhOODY6OI5ECugkDunoGxMco5xgJw2qVGO6UeZRRjjNXjhX4t9kfH H8fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679808544; 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=YKhnMooh27ljfK1QnQ9/evwUgskAV4ZMTmZuvKU5mBY=; b=zoftecA2KbseSwc3Jpqmm9FPuQoEDvxF1tYadtzjmFl7AFUp4w+C/jWP/KTOUCpVfN b0o21FZeXqdrkKDt/uK3vVDzqqFRKYd9zyfIbL3cMjo9/CmtK8NsuCCrx7VlEXqZ5pCF teH0PU6xhOVxDrRKKBxICKLlAAncKIdadawlYrM/2yzqfi31hdWPoqBuYXe4QoYj4Fmk mHqTcBtAbZvtmpzLVydvKw/qhgVyvMTDnqMwR+F+88h9kKhHMWDpRmNXmfrzk6XWA08G LqL83WSR9288MT6lwAybm0vIGPXpyOk7gUrFN+sbvExU12YdeJfcLrT5RYQOa1Cw3mir IF5g== X-Gm-Message-State: AO0yUKWqOFGwBGCWMiFjEGyJWhkvuRjKxRDRQFOXbKD8bsXDbNsDjnb6 vcZa/HR0UC8WoKT5qlf98nE+PniUB2dskuRYMAE= X-Google-Smtp-Source: AK7set/F4BQ9+srfoAOmQ0Gg2GTfqse507oBYtsMAsj+Jbl44BCUJ+e9rY6vB2iF/qS57xf+qDf5xQ== X-Received: by 2002:a05:6a00:2914:b0:627:de16:889c with SMTP id cg20-20020a056a00291400b00627de16889cmr13722391pfb.4.1679808543955; Sat, 25 Mar 2023 22:29:03 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.213.201]) by smtp.gmail.com with ESMTPSA id b14-20020a63eb4e000000b004fb5f4bf585sm15966915pgk.78.2023.03.25.22.29.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 22:29:03 -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 3/4] clk: hisilicon: Convert to platform driver Date: Sun, 26 Mar 2023 13:27:49 +0800 Message-Id: <20230326052757.297551-4-mmyangfl@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230326052757.297551-1-mmyangfl@gmail.com> References: <20230326052757.297551-1-mmyangfl@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" And use common helper functions. This patch is part of devm APIs migration. Signed-off-by: David Yang --- drivers/clk/hisilicon/clk-hi3620.c | 195 ++++++++++++------------ drivers/clk/hisilicon/clk-hi6220.c | 225 +++++++++++++--------------- drivers/clk/hisilicon/clk-hip04.c | 41 +++-- drivers/clk/hisilicon/clk-hix5hd2.c | 83 ++++++---- 4 files changed, 281 insertions(+), 263 deletions(-) diff --git a/drivers/clk/hisilicon/clk-hi3620.c b/drivers/clk/hisilicon/clk= -hi3620.c index a3d04c7c3da8..1eacf77b0d8c 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" =20 /* clock parent list */ -static const char *const timer0_mux_p[] __initconst =3D { "osc32k", "timer= clk01", }; -static const char *const timer1_mux_p[] __initconst =3D { "osc32k", "timer= clk01", }; -static const char *const timer2_mux_p[] __initconst =3D { "osc32k", "timer= clk23", }; -static const char *const timer3_mux_p[] __initconst =3D { "osc32k", "timer= clk23", }; -static const char *const timer4_mux_p[] __initconst =3D { "osc32k", "timer= clk45", }; -static const char *const timer5_mux_p[] __initconst =3D { "osc32k", "timer= clk45", }; -static const char *const timer6_mux_p[] __initconst =3D { "osc32k", "timer= clk67", }; -static const char *const timer7_mux_p[] __initconst =3D { "osc32k", "timer= clk67", }; -static const char *const timer8_mux_p[] __initconst =3D { "osc32k", "timer= clk89", }; -static const char *const timer9_mux_p[] __initconst =3D { "osc32k", "timer= clk89", }; -static const char *const uart0_mux_p[] __initconst =3D { "osc26m", "pclk",= }; -static const char *const uart1_mux_p[] __initconst =3D { "osc26m", "pclk",= }; -static const char *const uart2_mux_p[] __initconst =3D { "osc26m", "pclk",= }; -static const char *const uart3_mux_p[] __initconst =3D { "osc26m", "pclk",= }; -static const char *const uart4_mux_p[] __initconst =3D { "osc26m", "pclk",= }; -static const char *const spi0_mux_p[] __initconst =3D { "osc26m", "rclk_cf= gaxi", }; -static const char *const spi1_mux_p[] __initconst =3D { "osc26m", "rclk_cf= gaxi", }; -static const char *const spi2_mux_p[] __initconst =3D { "osc26m", "rclk_cf= gaxi", }; +static const char *const timer0_mux_p[] =3D { "osc32k", "timerclk01", }; +static const char *const timer1_mux_p[] =3D { "osc32k", "timerclk01", }; +static const char *const timer2_mux_p[] =3D { "osc32k", "timerclk23", }; +static const char *const timer3_mux_p[] =3D { "osc32k", "timerclk23", }; +static const char *const timer4_mux_p[] =3D { "osc32k", "timerclk45", }; +static const char *const timer5_mux_p[] =3D { "osc32k", "timerclk45", }; +static const char *const timer6_mux_p[] =3D { "osc32k", "timerclk67", }; +static const char *const timer7_mux_p[] =3D { "osc32k", "timerclk67", }; +static const char *const timer8_mux_p[] =3D { "osc32k", "timerclk89", }; +static const char *const timer9_mux_p[] =3D { "osc32k", "timerclk89", }; +static const char *const uart0_mux_p[] =3D { "osc26m", "pclk", }; +static const char *const uart1_mux_p[] =3D { "osc26m", "pclk", }; +static const char *const uart2_mux_p[] =3D { "osc26m", "pclk", }; +static const char *const uart3_mux_p[] =3D { "osc26m", "pclk", }; +static const char *const uart4_mux_p[] =3D { "osc26m", "pclk", }; +static const char *const spi0_mux_p[] =3D { "osc26m", "rclk_cfgaxi", }; +static const char *const spi1_mux_p[] =3D { "osc26m", "rclk_cfgaxi", }; +static const char *const spi2_mux_p[] =3D { "osc26m", "rclk_cfgaxi", }; /* share axi parent */ -static const char *const saxi_mux_p[] __initconst =3D { "armpll3", "armpll= 2", }; -static const char *const pwm0_mux_p[] __initconst =3D { "osc32k", "osc26m"= , }; -static const char *const pwm1_mux_p[] __initconst =3D { "osc32k", "osc26m"= , }; -static const char *const sd_mux_p[] __initconst =3D { "armpll2", "armpll3"= , }; -static const char *const mmc1_mux_p[] __initconst =3D { "armpll2", "armpll= 3", }; -static const char *const mmc1_mux2_p[] __initconst =3D { "osc26m", "mmc1_d= iv", }; -static const char *const g2d_mux_p[] __initconst =3D { "armpll2", "armpll3= ", }; -static const char *const venc_mux_p[] __initconst =3D { "armpll2", "armpll= 3", }; -static const char *const vdec_mux_p[] __initconst =3D { "armpll2", "armpll= 3", }; -static const char *const vpp_mux_p[] __initconst =3D { "armpll2", "armpll3= ", }; -static const char *const edc0_mux_p[] __initconst =3D { "armpll2", "armpll= 3", }; -static const char *const ldi0_mux_p[] __initconst =3D { "armpll2", "armpll= 4", +static const char *const saxi_mux_p[] =3D { "armpll3", "armpll2", }; +static const char *const pwm0_mux_p[] =3D { "osc32k", "osc26m", }; +static const char *const pwm1_mux_p[] =3D { "osc32k", "osc26m", }; +static const char *const sd_mux_p[] =3D { "armpll2", "armpll3", }; +static const char *const mmc1_mux_p[] =3D { "armpll2", "armpll3", }; +static const char *const mmc1_mux2_p[] =3D { "osc26m", "mmc1_div", }; +static const char *const g2d_mux_p[] =3D { "armpll2", "armpll3", }; +static const char *const venc_mux_p[] =3D { "armpll2", "armpll3", }; +static const char *const vdec_mux_p[] =3D { "armpll2", "armpll3", }; +static const char *const vpp_mux_p[] =3D { "armpll2", "armpll3", }; +static const char *const edc0_mux_p[] =3D { "armpll2", "armpll3", }; +static const char *const ldi0_mux_p[] =3D { "armpll2", "armpll4", "armpll3", "armpll5", }; -static const char *const edc1_mux_p[] __initconst =3D { "armpll2", "armpll= 3", }; -static const char *const ldi1_mux_p[] __initconst =3D { "armpll2", "armpll= 4", +static const char *const edc1_mux_p[] =3D { "armpll2", "armpll3", }; +static const char *const ldi1_mux_p[] =3D { "armpll2", "armpll4", "armpll3", "armpll5", }; -static const char *const rclk_hsic_p[] __initconst =3D { "armpll3", "armpl= l2", }; -static const char *const mmc2_mux_p[] __initconst =3D { "armpll2", "armpll= 3", }; -static const char *const mmc3_mux_p[] __initconst =3D { "armpll2", "armpll= 3", }; +static const char *const rclk_hsic_p[] =3D { "armpll3", "armpll2", }; +static const char *const mmc2_mux_p[] =3D { "armpll2", "armpll3", }; +static const char *const mmc3_mux_p[] =3D { "armpll2", "armpll3", }; =20 =20 /* fixed rate clocks */ -static struct hisi_fixed_rate_clock hi3620_fixed_rate_clks[] __initdata = =3D { +static struct hisi_fixed_rate_clock hi3620_fixed_rate_clks[] =3D { { 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_c= lks[] __initdata =3D { }; =20 /* fixed factor clocks */ -static struct hisi_fixed_factor_clock hi3620_fixed_factor_clks[] __initdat= a =3D { +static struct hisi_fixed_factor_clock hi3620_fixed_factor_clks[] =3D { { 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, }, }; =20 -static struct hisi_mux_clock hi3620_mux_clks[] __initdata =3D { +static struct hisi_mux_clock hi3620_mux_clks[] =3D { { 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[] __initda= ta =3D { { HI3620_MMC3_MUX, "mmc3_mux", mmc3_mux_p, ARRAY_SIZE(mmc3_mux_p), = CLK_SET_RATE_PARENT, 0x140, 9, 1, CLK_MUX_HIWORD_MASK, }, }; =20 -static struct hisi_divider_clock hi3620_div_clks[] __initdata =3D { +static struct hisi_divider_clock hi3620_div_clks[] =3D { { HI3620_SHAREAXI_DIV, "saxi_div", "saxi_mux", 0, 0x100, 0, 5, CLK_DIV= IDER_HIWORD_MASK, NULL, }, { HI3620_CFGAXI_DIV, "cfgaxi_div", "saxi_div", 0, 0x100, 5, 2, CLK_DIV= IDER_HIWORD_MASK, NULL, }, { HI3620_SD_DIV, "sd_div", "sd_mux", 0, 0x108, 0, 4, CLK_DIVI= DER_HIWORD_MASK, NULL, }, @@ -130,7 +131,7 @@ static struct hisi_divider_clock hi3620_div_clks[] __in= itdata =3D { { HI3620_MMC3_DIV, "mmc3_div", "mmc3_mux", 0, 0x140, 5, 4, CLK_DIV= IDER_HIWORD_MASK, NULL, }, }; =20 -static struct hisi_gate_clock hi3620_separated_gate_clks[] __initdata =3D { +static struct hisi_gate_clock hi3620_separated_gate_clks[] =3D { { HI3620_TIMERCLK01, "timerclk01", "timer_rclk01", CLK_SET_RATE_PAREN= T, 0x20, 0, 0, }, { HI3620_TIMER_RCLK01, "timer_rclk01", "rclk_tcxo", CLK_SET_RATE_PAREN= T, 0x20, 1, 0, }, { HI3620_TIMERCLK23, "timerclk23", "timer_rclk23", CLK_SET_RATE_PAREN= T, 0x20, 2, 0, }, @@ -192,29 +193,19 @@ static struct hisi_gate_clock hi3620_separated_gate_c= lks[] __initdata =3D { { HI3620_MCU_CLK, "mcu_clk", "acp_clk", CLK_SET_RATE_PAREN= T, 0x50, 24, 0, }, }; =20 -static void __init hi3620_clk_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - - clk_data =3D 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 =3D { + .nr =3D HI3620_NR_CLKS, + .fixed_rate_clks =3D hi3620_fixed_rate_clks, + .fixed_rate_clks_num =3D ARRAY_SIZE(hi3620_fixed_rate_clks), + .fixed_factor_clks =3D hi3620_fixed_factor_clks, + .fixed_factor_clks_num =3D ARRAY_SIZE(hi3620_fixed_factor_clks), + .mux_clks =3D hi3620_mux_clks, + .mux_clks_num =3D ARRAY_SIZE(hi3620_mux_clks), + .divider_clks =3D hi3620_div_clks, + .divider_clks_num =3D ARRAY_SIZE(hi3620_div_clks), + .gate_sep_clks =3D hi3620_separated_gate_clks, + .gate_sep_clks_num =3D ARRAY_SIZE(hi3620_separated_gate_clks), +}; =20 struct hisi_mmc_clock { unsigned int id; @@ -252,7 +243,7 @@ struct clk_mmc { =20 #define to_mmc(_hw) container_of(_hw, struct clk_mmc, hw) =20 -static struct hisi_mmc_clock hi3620_mmc_clks[] __initdata =3D { +static struct hisi_mmc_clock hi3620_mmc_clks[] =3D { { 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, 0x1= f8, 12, 0x1f8, 13, 3, 0x1f8, 16, 4, 0x1f8, 20, 4}, { HI3620_MMC_CIUCLK2, "mmc_bclk2", "mmc_clk2", CLK_SET_RATE_PARENT, 0x1= f8, 24, 0x1f8, 25, 3, 0x1f8, 28, 4, 0x1fc, 0, 4}, @@ -408,8 +399,9 @@ static const struct clk_ops clk_mmc_ops =3D { .recalc_rate =3D mmc_clk_recalc_rate, }; =20 -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,52 @@ static struct clk *hisi_register_clk_mmc(struct hisi_= mmc_clock *mmc_clk, return clk; } =20 -static void __init hi3620_mmc_clk_init(struct device_node *node) +static int hisi_register_clk_mmc(struct device *dev, const void *clocks, + int nums, struct hisi_clock_data *data) { - void __iomem *base; - int i, num =3D ARRAY_SIZE(hi3620_mmc_clks); - struct clk_onecell_data *clk_data; - - if (!node) { - pr_err("failed to find pctrl node in DTS\n"); - return; - } - - base =3D of_iomap(node, 0); - if (!base) { - pr_err("failed to map pctrl\n"); - return; + const struct hisi_mmc_clock *clks =3D clocks; + struct clk *clk; + int i; + + for (i =3D 0; i < nums; i++) { + clk =3D 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] =3D clk; } =20 - clk_data =3D kzalloc(sizeof(*clk_data), GFP_KERNEL); - if (WARN_ON(!clk_data)) - return; + return 0; +} =20 - clk_data->clks =3D kcalloc(num, sizeof(*clk_data->clks), GFP_KERNEL); - if (!clk_data->clks) - return; +static const struct hisi_clocks hi3620_clks_mmc =3D { + .nr =3D ARRAY_SIZE(hi3620_mmc_clks), + .customized_clks =3D hi3620_mmc_clks, + .customized_clks_num =3D ARRAY_SIZE(hi3620_mmc_clks), + .clk_register_customized =3D hisi_register_clk_mmc, +}; =20 - for (i =3D 0; i < num; i++) { - struct hisi_mmc_clock *mmc_clk =3D &hi3620_mmc_clks[i]; - clk_data->clks[mmc_clk->id] =3D - hisi_register_clk_mmc(mmc_clk, base, node); - } +static const struct of_device_id hi3620_clk_match_table[] =3D { + { .compatible =3D "hisilicon,hi3620-clock", + .data =3D &hi3620_clks }, + { .compatible =3D "hisilicon,hi3620-mmc-clock", + .data =3D &hi3620_clks_mmc }, + { } +}; +MODULE_DEVICE_TABLE(of, hi3620_clk_match_table); + +static struct platform_driver hi3620_clk_driver =3D { + .probe =3D hisi_clk_probe, + .remove =3D hisi_clk_remove, + .driver =3D { + .name =3D "hi3620-clock", + .of_match_table =3D hi3620_clk_match_table, + }, +}; =20 - clk_data->clk_num =3D num; - of_clk_add_provider(node, of_clk_src_onecell_get, clk_data); -} +module_platform_driver(hi3620_clk_driver); =20 -CLK_OF_DECLARE(hi3620_mmc_clk, "hisilicon,hi3620-mmc-clock", hi3620_mmc_cl= k_init); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("HiSilicon Hi3620 Clock Driver"); diff --git a/drivers/clk/hisilicon/clk-hi6220.c b/drivers/clk/hisilicon/clk= -hi6220.c index e7cdf72d4b06..cdc17f82ce2d 100644 --- a/drivers/clk/hisilicon/clk-hi6220.c +++ b/drivers/clk/hisilicon/clk-hi6220.c @@ -9,20 +9,15 @@ =20 #include #include -#include -#include -#include -#include +#include #include -#include =20 #include =20 #include "clk.h" =20 - /* clocks in AO (always on) controller */ -static struct hisi_fixed_rate_clock hi6220_fixed_rate_clks[] __initdata = =3D { +static struct hisi_fixed_rate_clock hi6220_fixed_rate_clks[] =3D { { HI6220_REF32K, "ref32k", NULL, 0, 32764, }, { HI6220_CLK_TCXO, "clk_tcxo", NULL, 0, 19200000, }, { HI6220_MMC1_PAD, "mmc1_pad", NULL, 0, 100000000, }, @@ -38,7 +33,7 @@ static struct hisi_fixed_rate_clock hi6220_fixed_rate_clk= s[] __initdata =3D { { HI6220_PLL_DDR, "ddrpll0", NULL, 0, 1600000000,}, }; =20 -static struct hisi_fixed_factor_clock hi6220_fixed_factor_clks[] __initdat= a =3D { +static struct hisi_fixed_factor_clock hi6220_fixed_factor_clks[] =3D { { 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 +46,7 @@ static struct hisi_fixed_factor_clock hi6220_fixed_factor= _clks[] __initdata =3D { { HI6220_MMC2_SMP, "mmc2_sample", "mmc2_sel", 1, 8, 0, }, }; =20 -static struct hisi_gate_clock hi6220_separated_gate_clks_ao[] __initdata = =3D { +static struct hisi_gate_clock hi6220_separated_gate_clks_ao[] =3D { { 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 +64,43 @@ static struct hisi_gate_clock hi6220_separated_gate_clk= s_ao[] __initdata =3D { { HI6220_RTC1_PCLK, "rtc1_pclk", "clk_tcxo", CLK_SET_RATE_PARENT|CLK_= IGNORE_UNUSED, 0x630, 26, 0, }, }; =20 -static void __init hi6220_clk_ao_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data_ao; - - clk_data_ao =3D 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 =3D { + .nr =3D HI6220_AO_NR_CLKS, + .fixed_rate_clks =3D hi6220_fixed_rate_clks, + .fixed_rate_clks_num =3D ARRAY_SIZE(hi6220_fixed_rate_clks), + .fixed_factor_clks =3D hi6220_fixed_factor_clks, + .fixed_factor_clks_num =3D ARRAY_SIZE(hi6220_fixed_factor_clks), + .gate_sep_clks =3D hi6220_separated_gate_clks_ao, + .gate_sep_clks_num =3D ARRAY_SIZE(hi6220_separated_gate_clks_ao), +}; =20 - 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); =20 /* clocks in sysctrl */ -static const char *mmc0_mux0_p[] __initdata =3D { "pll_ddr_gate", "syspll"= , }; -static const char *mmc0_mux1_p[] __initdata =3D { "mmc0_mux0", "pll_media_= gate", }; -static const char *mmc0_src_p[] __initdata =3D { "mmc0srcsel", "mmc0_div",= }; -static const char *mmc1_mux0_p[] __initdata =3D { "pll_ddr_gate", "syspll"= , }; -static const char *mmc1_mux1_p[] __initdata =3D { "mmc1_mux0", "pll_media_= gate", }; -static const char *mmc1_src_p[] __initdata =3D { "mmc1srcsel", "mmc1_div"= , }; -static const char *mmc2_mux0_p[] __initdata =3D { "pll_ddr_gate", "syspll"= , }; -static const char *mmc2_mux1_p[] __initdata =3D { "mmc2_mux0", "pll_media_= gate", }; -static const char *mmc2_src_p[] __initdata =3D { "mmc2srcsel", "mmc2_div"= , }; -static const char *mmc0_sample_in[] __initdata =3D { "mmc0_sample", "mmc0_= pad", }; -static const char *mmc1_sample_in[] __initdata =3D { "mmc1_sample", "mmc1_= pad", }; -static const char *mmc2_sample_in[] __initdata =3D { "mmc2_sample", "mmc2_= pad", }; -static const char *uart1_src[] __initdata =3D { "clk_tcxo", "clk_150m", }; -static const char *uart2_src[] __initdata =3D { "clk_tcxo", "clk_150m", }; -static const char *uart3_src[] __initdata =3D { "clk_tcxo", "clk_150m", }; -static const char *uart4_src[] __initdata =3D { "clk_tcxo", "clk_150m", }; -static const char *hifi_src[] __initdata =3D { "syspll", "pll_media_gate",= }; - -static struct hisi_gate_clock hi6220_separated_gate_clks_sys[] __initdata = =3D { +static const char * const mmc0_mux0_p[] =3D { "pll_ddr_gate", "syspll", }; +static const char * const mmc0_mux1_p[] =3D { "mmc0_mux0", "pll_media_gate= ", }; +static const char * const mmc0_src_p[] =3D { "mmc0srcsel", "mmc0_div", }; +static const char * const mmc1_mux0_p[] =3D { "pll_ddr_gate", "syspll", }; +static const char * const mmc1_mux1_p[] =3D { "mmc1_mux0", "pll_media_gate= ", }; +static const char * const mmc1_src_p[] =3D { "mmc1srcsel", "mmc1_div", }; +static const char * const mmc2_mux0_p[] =3D { "pll_ddr_gate", "syspll", }; +static const char * const mmc2_mux1_p[] =3D { "mmc2_mux0", "pll_media_gate= ", }; +static const char * const mmc2_src_p[] =3D { "mmc2srcsel", "mmc2_div", }; +static const char * const mmc0_sample_in[] =3D { "mmc0_sample", "mmc0_pad"= , }; +static const char * const mmc1_sample_in[] =3D { "mmc1_sample", "mmc1_pad"= , }; +static const char * const mmc2_sample_in[] =3D { "mmc2_sample", "mmc2_pad"= , }; +static const char * const uart1_src[] =3D { "clk_tcxo", "clk_150m", }; +static const char * const uart2_src[] =3D { "clk_tcxo", "clk_150m", }; +static const char * const uart3_src[] =3D { "clk_tcxo", "clk_150m", }; +static const char * const uart4_src[] =3D { "clk_tcxo", "clk_150m", }; +static const char * const hifi_src[] =3D { "syspll", "pll_media_gate", }; + +static struct hisi_gate_clock hi6220_separated_gate_clks_sys[] =3D { { HI6220_MMC0_CLK, "mmc0_clk", "mmc0_src", CLK_SET_RATE_P= ARENT|CLK_IGNORE_UNUSED, 0x200, 0, 0, }, { HI6220_MMC0_CIUCLK, "mmc0_ciuclk", "mmc0_smp_in", CLK_SET_RATE_P= ARENT|CLK_IGNORE_UNUSED, 0x200, 0, 0, }, { HI6220_MMC1_CLK, "mmc1_clk", "mmc1_src", CLK_SET_RATE_P= ARENT|CLK_IGNORE_UNUSED, 0x200, 1, 0, }, @@ -146,7 +137,7 @@ static struct hisi_gate_clock hi6220_separated_gate_clk= s_sys[] __initdata =3D { { HI6220_CS_ATB_SYSPLL, "cs_atb_syspll", "syspll", CLK_SET_RATE_P= ARENT|CLK_IS_CRITICAL, 0x270, 12, 0, }, }; =20 -static struct hisi_mux_clock hi6220_mux_clks_sys[] __initdata =3D { +static struct hisi_mux_clock hi6220_mux_clks_sys[] =3D { { 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_samp= le_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 +157,7 @@ static struct hisi_mux_clock hi6220_mux_clks_sys[] __in= itdata =3D { { HI6220_MMC2_MUX1, "mmc2_mux1", mmc2_mux1_p, ARRAY_SIZE(mmc2_mux1= _p), CLK_SET_RATE_PARENT, 0x400, 15, 1, CLK_MUX_HIWORD_MASK,}, }; =20 -static struct hi6220_divider_clock hi6220_div_clks_sys[] __initdata =3D { +static struct hi6220_divider_clock hi6220_div_clks_sys[] =3D { { 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 +168,23 @@ static struct hi6220_divider_clock hi6220_div_clks_sy= s[] __initdata =3D { { HI6220_CS_ATB_DIV, "cs_atb_div", "cs_atb_syspll", CLK_SET_RATE_PARENT= , 0x4a4, 0, 4, 7, }, }; =20 -static void __init hi6220_clk_sys_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - - clk_data =3D 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_c= lk_sys_init); - +static const struct hisi_clocks hi6220_sys_clks =3D { + .nr =3D HI6220_SYS_NR_CLKS, + .mux_clks =3D hi6220_mux_clks_sys, + .mux_clks_num =3D ARRAY_SIZE(hi6220_mux_clks_sys), + .gate_sep_clks =3D hi6220_separated_gate_clks_sys, + .gate_sep_clks_num =3D ARRAY_SIZE(hi6220_separated_gate_clks_sys), + .customized_clks =3D hi6220_div_clks_sys, + .customized_clks_num =3D ARRAY_SIZE(hi6220_div_clks_sys), + /* .clk_register_customized =3D hi6220_clk_register_divider, */ +}; =20 /* clocks in media controller */ -static const char *clk_1000_1200_src[] __initdata =3D { "pll_gpu_gate", "m= edia_syspll_src", }; -static const char *clk_1440_1200_src[] __initdata =3D { "media_syspll_src"= , "media_pll_src", }; -static const char *clk_1000_1440_src[] __initdata =3D { "pll_gpu_gate", "m= edia_pll_src", }; +static const char * const clk_1000_1200_src[] =3D { "pll_gpu_gate", "media= _syspll_src", }; +static const char * const clk_1440_1200_src[] =3D { "media_syspll_src", "m= edia_pll_src", }; +static const char * const clk_1000_1440_src[] =3D { "pll_gpu_gate", "media= _pll_src", }; =20 -static struct hisi_gate_clock hi6220_separated_gate_clks_media[] __initdat= a =3D { +static struct hisi_gate_clock hi6220_separated_gate_clks_media[] =3D { { HI6220_DSI_PCLK, "dsi_pclk", "vpucodec", CLK_SET_RAT= E_PARENT|CLK_IGNORE_UNUSED, 0x520, 0, 0, }, { HI6220_G3D_PCLK, "g3d_pclk", "vpucodec", CLK_SET_RAT= E_PARENT|CLK_IGNORE_UNUSED, 0x520, 1, 0, }, { HI6220_ACLK_CODEC_VPU, "aclk_codec_vpu", "ade_core_src", CLK_SET_RAT= E_PARENT|CLK_IGNORE_UNUSED, 0x520, 3, 0, }, @@ -218,13 +200,13 @@ static struct hisi_gate_clock hi6220_separated_gate_c= lks_media[] __initdata =3D { { HI6220_MED_SYSPLL, "media_syspll_src", "media_syspll", CLK_SET_RAT= E_PARENT|CLK_IGNORE_UNUSED, 0x520, 17, 0, }, }; =20 -static struct hisi_mux_clock hi6220_mux_clks_media[] __initdata =3D { +static struct hisi_mux_clock hi6220_mux_clks_media[] =3D { { HI6220_1440_1200, "clk_1440_1200", clk_1440_1200_src, ARRAY_SIZE(clk_14= 40_1200_src), CLK_SET_RATE_PARENT, 0x51c, 0, 1, 0, }, { HI6220_1000_1200, "clk_1000_1200", clk_1000_1200_src, ARRAY_SIZE(clk_10= 00_1200_src), CLK_SET_RATE_PARENT, 0x51c, 1, 1, 0, }, { HI6220_1000_1440, "clk_1000_1440", clk_1000_1440_src, ARRAY_SIZE(clk_10= 00_1440_src), CLK_SET_RATE_PARENT, 0x51c, 6, 1, 0, }, }; =20 -static struct hi6220_divider_clock hi6220_div_clks_media[] __initdata =3D { +static struct hi6220_divider_clock hi6220_div_clks_media[] =3D { { 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 +216,19 @@ static struct hi6220_divider_clock hi6220_div_clks_me= dia[] __initdata =3D { { HI6220_CODEC_VPU_SRC, "codec_vpu_src", "codec_vpu_gate", CLK_SET_RATE= _PARENT, 0xcc4, 24, 6, 31, }, }; =20 -static void __init hi6220_clk_media_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - - clk_data =3D 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", hi62= 20_clk_media_init); - +static const struct hisi_clocks hi6220_media_clks =3D { + .nr =3D HI6220_MEDIA_NR_CLKS, + .mux_clks =3D hi6220_mux_clks_media, + .mux_clks_num =3D ARRAY_SIZE(hi6220_mux_clks_media), + .gate_sep_clks =3D hi6220_separated_gate_clks_media, + .gate_sep_clks_num =3D ARRAY_SIZE(hi6220_separated_gate_clks_media), + .customized_clks =3D hi6220_div_clks_media, + .customized_clks_num =3D ARRAY_SIZE(hi6220_div_clks_media), + /* .clk_register_customized =3D hi6220_clk_register_divider, */ +}; =20 /* clocks in pmctrl */ -static struct hisi_gate_clock hi6220_gate_clks_power[] __initdata =3D { +static struct hisi_gate_clock hi6220_gate_clks_power[] =3D { { HI6220_PLL_GPU_GATE, "pll_gpu_gate", "gpupll", CLK_SET_RATE_PARE= NT|CLK_IGNORE_UNUSED, 0x8, 0, 0, }, { HI6220_PLL1_DDR_GATE, "pll1_ddr_gate", "ddrpll1", CLK_SET_RATE_PARE= NT|CLK_IGNORE_UNUSED, 0x10, 0, 0, }, { HI6220_PLL_DDR_GATE, "pll_ddr_gate", "ddrpll0", CLK_SET_RATE_PARE= NT|CLK_IGNORE_UNUSED, 0x18, 0, 0, }, @@ -263,26 +236,19 @@ static struct hisi_gate_clock hi6220_gate_clks_power[= ] __initdata =3D { { HI6220_PLL0_BBP_GATE, "pll0_bbp_gate", "bbppll0", CLK_SET_RATE_PARE= NT|CLK_IGNORE_UNUSED, 0x48, 0, 0, }, }; =20 -static struct hi6220_divider_clock hi6220_div_clks_power[] __initdata =3D { +static struct hi6220_divider_clock hi6220_div_clks_power[] =3D { { HI6220_DDRC_SRC, "ddrc_src", "ddr_sel_src", CLK_SET_RATE_PARENT, 0x5a= 8, 0, 4, 0, }, { HI6220_DDRC_AXI1, "ddrc_axi1", "ddrc_src", CLK_SET_RATE_PARENT, 0x5a= 8, 8, 2, 0, }, }; =20 -static void __init hi6220_clk_power_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - - clk_data =3D 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_pow= er_init); +static const struct hisi_clocks hi6220_power_clks =3D { + .nr =3D HI6220_POWER_NR_CLKS, + .gate_clks =3D hi6220_gate_clks_power, + .gate_clks_num =3D ARRAY_SIZE(hi6220_gate_clks_power), + .customized_clks =3D hi6220_div_clks_power, + .customized_clks_num =3D ARRAY_SIZE(hi6220_div_clks_power), + /* .clk_register_customized =3D hi6220_clk_register_divider, */ +}; =20 /* clocks in acpu */ static const struct hisi_gate_clock hi6220_acpu_sc_gate_sep_clks[] =3D { @@ -290,18 +256,37 @@ static const struct hisi_gate_clock hi6220_acpu_sc_ga= te_sep_clks[] =3D { CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, 0xc, 11, 0, }, }; =20 -static void __init hi6220_clk_acpu_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - int nr =3D ARRAY_SIZE(hi6220_acpu_sc_gate_sep_clks); +static const struct hisi_clocks hi6220_acpu_clks =3D { + .nr =3D ARRAY_SIZE(hi6220_acpu_sc_gate_sep_clks), + .gate_sep_clks =3D hi6220_acpu_sc_gate_sep_clks, + .gate_sep_clks_num =3D ARRAY_SIZE(hi6220_acpu_sc_gate_sep_clks), +}; =20 - clk_data =3D hisi_clk_init(np, nr); - if (!clk_data) - return; +static const struct of_device_id hi6220_clk_match_table[] =3D { + { .compatible =3D "hisilicon,hi6220-aoctrl", + .data =3D &hi6220_ao_clks }, + { .compatible =3D "hisilicon,hi6220-sysctrl", + .data =3D &hi6220_sys_clks }, + { .compatible =3D "hisilicon,hi6220-mediactrl", + .data =3D &hi6220_media_clks }, + { .compatible =3D "hisilicon,hi6220-pmctrl", + .data =3D &hi6220_power_clks }, + { .compatible =3D "hisilicon,hi6220-acpu-sctrl", + .data =3D &hi6220_acpu_clks }, + { } +}; +MODULE_DEVICE_TABLE(of, hi6220_clk_match_table); + +static struct platform_driver hi6220_clk_driver =3D { + .probe =3D hisi_clk_probe, + .remove =3D hisi_clk_remove, + .driver =3D { + .name =3D "hi6220-clock", + .of_match_table =3D hi6220_clk_match_table, + }, +}; =20 - 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); =20 -CLK_OF_DECLARE(hi6220_clk_acpu, "hisilicon,hi6220-acpu-sctrl", hi6220_clk_= acpu_init); +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("HiSilicon Hi6220 Clock Driver"); diff --git a/drivers/clk/hisilicon/clk-hip04.c b/drivers/clk/hisilicon/clk-= hip04.c index 785b9faf3ea5..e7d9582acc14 100644 --- a/drivers/clk/hisilicon/clk-hip04.c +++ b/drivers/clk/hisilicon/clk-hip04.c @@ -9,12 +9,8 @@ */ =20 #include -#include -#include -#include -#include +#include #include -#include =20 #include =20 @@ -27,16 +23,29 @@ static struct hisi_fixed_rate_clock hip04_fixed_rate_cl= ks[] __initdata =3D { { HIP04_CLK_168M, "clk168m", NULL, 0, 168750000, }, }; =20 -static void __init hip04_clk_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; +static const struct hisi_clocks hip04_clks =3D { + .nr =3D ARRAY_SIZE(hip04_fixed_rate_clks), + .fixed_rate_clks =3D hip04_fixed_rate_clks, + .fixed_factor_clks_num =3D ARRAY_SIZE(hip04_fixed_rate_clks), +}; + +static const struct of_device_id hip04_clk_match_table[] =3D { + { .compatible =3D "hisilicon,hip04-clock", + .data =3D &hip04_clks }, + { } +}; +MODULE_DEVICE_TABLE(of, hip04_clk_match_table); + +static struct platform_driver hip04_clk_driver =3D { + .probe =3D hisi_clk_probe, + .remove =3D hisi_clk_remove, + .driver =3D { + .name =3D "hip04-clock", + .of_match_table =3D hip04_clk_match_table, + }, +}; =20 - clk_data =3D hisi_clk_init(np, HIP04_NR_CLKS); - if (!clk_data) - return; +module_platform_driver(hip04_clk_driver); =20 - 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"); diff --git a/drivers/clk/hisilicon/clk-hix5hd2.c b/drivers/clk/hisilicon/cl= k-hix5hd2.c index 64bdd3f05725..f37a17649d26 100644 --- a/drivers/clk/hisilicon/clk-hix5hd2.c +++ b/drivers/clk/hisilicon/clk-hix5hd2.c @@ -4,13 +4,17 @@ * Copyright (c) 2014 Hisilicon Limited. */ =20 -#include #include + #include #include +#include +#include +#include + #include "clk.h" =20 -static struct hisi_fixed_rate_clock hix5hd2_fixed_rate_clks[] __initdata = =3D { +static struct hisi_fixed_rate_clock hix5hd2_fixed_rate_clks[] =3D { { 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 =3D { { HIX5HD2_FIXED_83M, "83m", NULL, 0, 83333333, }, }; =20 -static const char *const sfc_mux_p[] __initconst =3D { +static const char *const sfc_mux_p[] =3D { "24m", "150m", "200m", "100m", "75m", }; static u32 sfc_mux_table[] =3D {0, 4, 5, 6, 7}; =20 -static const char *const sdio_mux_p[] __initconst =3D { +static const char *const sdio_mux_p[] =3D { "75m", "100m", "50m", "15m", }; static u32 sdio_mux_table[] =3D {0, 1, 2, 3}; =20 -static const char *const fephy_mux_p[] __initconst =3D { "25m", "125m"}; +static const char *const fephy_mux_p[] =3D { "25m", "125m"}; static u32 fephy_mux_table[] =3D {0, 1}; =20 =20 -static struct hisi_mux_clock hix5hd2_mux_clks[] __initdata =3D { +static struct hisi_mux_clock hix5hd2_mux_clks[] =3D { { 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[] __initdat= a =3D { CLK_SET_RATE_PARENT, 0x120, 8, 2, 0, fephy_mux_table, }, }; =20 -static struct hisi_gate_clock hix5hd2_gate_clks[] __initdata =3D { +static struct hisi_gate_clock hix5hd2_gate_clks[] =3D { /* 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; }; =20 -static struct hix5hd2_complex_clock hix5hd2_complex_clks[] __initdata =3D { +static struct hix5hd2_complex_clock hix5hd2_complex_clks[] =3D { {"clk_mac0", "clk_fephy", HIX5HD2_MAC0_CLK, 0xcc, 0xa, 0x500, 0x120, 0, 0x10, TYPE_ETHER}, {"clk_mac1", "clk_fwd_sys", HIX5HD2_MAC1_CLK, @@ -249,10 +253,11 @@ static const struct clk_ops clk_complex_ops =3D { .disable =3D clk_complex_disable, }; =20 -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, int n= ums, struct hisi_clock_data *data) { + const struct hix5hd2_complex_clock *clks =3D clocks; void __iomem *base =3D data->base; int i; =20 @@ -263,7 +268,7 @@ hix5hd2_clk_register_complex(struct hix5hd2_complex_clo= ck *clks, int nums, =20 p_clk =3D kzalloc(sizeof(*p_clk), GFP_KERNEL); if (!p_clk) - return; + return -ENOMEM; =20 init.name =3D clks[i].name; if (clks[i].type =3D=3D TYPE_ETHER) @@ -289,31 +294,45 @@ hix5hd2_clk_register_complex(struct hix5hd2_complex_c= lock *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); } =20 data->clk_data.clks[clks[i].id] =3D clk; } -} =20 -static void __init hix5hd2_clk_init(struct device_node *np) -{ - struct hisi_clock_data *clk_data; - - clk_data =3D 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; } =20 -CLK_OF_DECLARE(hix5hd2_clk, "hisilicon,hix5hd2-clock", hix5hd2_clk_init); +static const struct hisi_clocks hix5hd2_clks =3D { + .nr =3D HIX5HD2_NR_CLKS, + .fixed_rate_clks =3D hix5hd2_fixed_rate_clks, + .fixed_factor_clks_num =3D ARRAY_SIZE(hix5hd2_fixed_rate_clks), + .mux_clks =3D hix5hd2_mux_clks, + .mux_clks_num =3D ARRAY_SIZE(hix5hd2_mux_clks), + .gate_clks =3D hix5hd2_gate_clks, + .gate_clks_num =3D ARRAY_SIZE(hix5hd2_gate_clks), + .customized_clks =3D hix5hd2_complex_clks, + .customized_clks_num =3D ARRAY_SIZE(hix5hd2_complex_clks), + .clk_register_customized =3D hix5hd2_clk_register_complex, +}; + +static const struct of_device_id hix5hd2_clk_match_table[] =3D { + { .compatible =3D "hisilicon,hix5hd2-clock", + .data =3D &hix5hd2_clks }, + { } +}; +MODULE_DEVICE_TABLE(of, hix5hd2_clk_match_table); + +static struct platform_driver hix5hd2_clk_driver =3D { + .probe =3D hisi_clk_probe, + .remove =3D hisi_clk_remove, + .driver =3D { + .name =3D "hix5hd2-clock", + .of_match_table =3D hix5hd2_clk_match_table, + }, +}; + +module_platform_driver(hix5hd2_clk_driver); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("HiSilicon Hix5hd2 Clock Driver"); --=20 2.39.2 From nobody Sat Apr 27 21:51:01 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79DEAC761AF for ; Sun, 26 Mar 2023 05:29:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231922AbjCZF34 (ORCPT ); Sun, 26 Mar 2023 01:29:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231330AbjCZF3y (ORCPT ); Sun, 26 Mar 2023 01:29:54 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECB831FD6; Sat, 25 Mar 2023 22:29:31 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id e15-20020a17090ac20f00b0023d1b009f52so8906740pjt.2; Sat, 25 Mar 2023 22:29:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679808571; 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=gQdxggrvOBdOzYAM+XEY+ITiNdb5smrybeGz1srgktI=; b=MTnFNwgSpPuTbk8QPRmyE9hcMzYwaOud2n9pG094UAGP+9OsANjagntB3tXtMxueBg 0NC9O61HUPj8LWsvNK1c6vW0moqKoER3Jk6EdGEQmXSVQ/onEeEYiDGX6WzFr4WaFIXG YQRf+JGvU2w+FJ+3cI82a4KOqCrbf5HDB6bEJU4MPdFDSvAsJ306f2pq1JGqffxa8WnL vZ/AL1QxdQrxsp63/020+E64v42ACUuF5GxAFh1kwXkBnMrpiJX74Lp+6CUcPTnAAFFL O3Ttj7NzFADrkyeHPJmLdffytF4zRIMFJ/klcGmmNL0co3FAYkg3Ud5YO06J4WhwC2D2 3+5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679808571; 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=gQdxggrvOBdOzYAM+XEY+ITiNdb5smrybeGz1srgktI=; b=azc4syzH5SvSfzl7csv6M6IZ/5pbxJSvL7P6AYbM09+BTEbgYiVV00M6wbHEE9gIfg G38M6mxkhvqcJZG9pZ/i1oIfnsyx35eK0cEY06jUCfY2MXzAri1UwTjIHU8oEBwnIzDn Yu8CPUm5/S7r2c0/UuwIq0wsviWh3mWMEoeeXUNaFgpbWBs8fQC1SlMfd2tLMnx8okmc np3hbygUFz0S4oizDLOjMki+jp8KIkWkA6HGqhfM1/AsU3tdun9tdXzBOAxJyt+Yw5XY lUH//xwQwcuuun8UJNgNg1D50S/EKuQaTTxvSIZwmf336por2C+NAKPYwaLtapAjiXO4 wmNg== X-Gm-Message-State: AO0yUKVNaN8htkwiOa22Fc+o6uMh43BDnNWmfzfvacPslkUWUq7ZNNhy UOlejmJDJrqxe33OehfKYSbiZo66WKwtlx8kBlM= X-Google-Smtp-Source: AK7set8kcgeI7p6SPOohnsf8UIArLriGRQVOn9rrmM+kikHPHoj/ZS+TZaYXKOcBL8IB9+0jUU6WeQ== X-Received: by 2002:a05:6a20:92a0:b0:d9:f41c:33b0 with SMTP id q32-20020a056a2092a000b000d9f41c33b0mr7592878pzg.36.1679808571032; Sat, 25 Mar 2023 22:29:31 -0700 (PDT) Received: from d.home.yangfl.dn42 ([104.28.213.201]) by smtp.gmail.com with ESMTPSA id b14-20020a63eb4e000000b004fb5f4bf585sm15966915pgk.78.2023.03.25.22.29.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 22:29:30 -0700 (PDT) From: David Yang To: linux-clk@vger.kernel.org Cc: David Yang , Michael Turquette , Stephen Boyd , linux-kernel@vger.kernel.org, Conor Dooley , Nick Alcock Subject: [PATCH 4/4] clk: hisilicon: Migrate devm APIs Date: Sun, 26 Mar 2023 13:27:50 +0800 Message-Id: <20230326052757.297551-5-mmyangfl@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230326052757.297551-1-mmyangfl@gmail.com> References: <20230326052757.297551-1-mmyangfl@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 | 28 +- drivers/clk/hisilicon/clk-hi6220-stub.c | 9 +- drivers/clk/hisilicon/clk-hi6220.c | 13 +- drivers/clk/hisilicon/clk-hisi-phase.c | 13 +- drivers/clk/hisilicon/clk-hix5hd2.c | 12 +- drivers/clk/hisilicon/clk.c | 411 +++++++--------------- drivers/clk/hisilicon/clk.h | 97 ++--- drivers/clk/hisilicon/clkdivider-hi6220.c | 24 +- drivers/clk/hisilicon/clkgate-separated.c | 26 +- 10 files changed, 262 insertions(+), 400 deletions(-) diff --git a/drivers/clk/hisilicon/clk-hi3559a.c b/drivers/clk/hisilicon/cl= k-hi3559a.c index d641b2a759dd..926a7c211978 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 =3D clocks; void __iomem *base =3D data->base; - struct hi3559av100_clk_pll *p_clk =3D NULL; - struct clk *clk =3D NULL; + struct hi3559av100_clk_pll *p_clk; struct clk_init_data init; int i; - - p_clk =3D devm_kzalloc(dev, sizeof(*p_clk) * nums, GFP_KERNEL); - - if (!p_clk) - return -ENOMEM; + int ret; =20 for (i =3D 0; i < nums; i++) { + p_clk =3D devm_kzalloc(dev, sizeof(*p_clk), GFP_KERNEL); + if (!p_clk) + return -ENOMEM; + init.name =3D clks[i].name; init.flags =3D 0; init.parent_names =3D @@ -490,16 +489,14 @@ hisi_clk_register_pll(struct device *dev, const void = *clocks, p_clk->refdiv_width =3D clks[i].refdiv_width; p_clk->hw.init =3D &init; =20 - clk =3D clk_register(NULL, &p_clk->hw); - if (IS_ERR(clk)) { - devm_kfree(dev, p_clk); + ret =3D 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; } =20 - data->clk_data.clks[clks[i].id] =3D clk; - p_clk++; + data->clk_data->hws[clks[i].id] =3D &p_clk->hw; } =20 return 0; @@ -628,7 +625,7 @@ static int hi3559av100_shub_default_clk_set(struct devi= ce *dev, struct hisi_cloc void __iomem *crg_base; unsigned int val; =20 - crg_base =3D ioremap(CRG_BASE_ADDR, SZ_4K); + crg_base =3D devm_ioremap(dev, CRG_BASE_ADDR, SZ_4K); =20 /* SSP: 192M/2 */ val =3D readl_relaxed(crg_base + 0x20); @@ -640,7 +637,7 @@ static int hi3559av100_shub_default_clk_set(struct devi= ce *dev, struct hisi_cloc val |=3D (0x1 << 28); writel_relaxed(val, crg_base + 0x1C); =20 - iounmap(crg_base); + devm_iounmap(dev, crg_base); crg_base =3D NULL; =20 return 0; diff --git a/drivers/clk/hisilicon/clk-hi3620.c b/drivers/clk/hisilicon/clk= -hi3620.c index 1eacf77b0d8c..6a6c482c87c6 100644 --- a/drivers/clk/hisilicon/clk-hi3620.c +++ b/drivers/clk/hisilicon/clk-hi3620.c @@ -11,12 +11,10 @@ =20 #include #include +#include #include #include -#include -#include #include -#include =20 #include =20 @@ -399,15 +397,15 @@ static const struct clk_ops clk_mmc_ops =3D { .recalc_rate =3D mmc_clk_recalc_rate, }; =20 -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; =20 - mclk =3D kzalloc(sizeof(*mclk), GFP_KERNEL); + mclk =3D devm_kzalloc(dev, sizeof(*mclk), GFP_KERNEL); if (!mclk) return ERR_PTR(-ENOMEM); =20 @@ -431,27 +429,31 @@ clk_register_hisi_mmc(struct device *dev, const struc= t hisi_mmc_clock *mmc_clk, mclk->sam_off =3D mmc_clk->sam_off; mclk->sam_bits =3D mmc_clk->sam_bits; =20 - clk =3D clk_register(NULL, &mclk->hw); - if (WARN_ON(IS_ERR(clk))) - kfree(mclk); - return clk; + ret =3D devm_clk_hw_register(dev, &mclk->hw); + if (ret) { + dev_err(dev, "%s: failed to register clock %s\n", + __func__, clks[i].name); + return ret; + } + + return &mclk->hw; } =20 static int hisi_register_clk_mmc(struct device *dev, const void *clocks, int nums, struct hisi_clock_data *data) { const struct hisi_mmc_clock *clks =3D clocks; - struct clk *clk; int i; =20 for (i =3D 0; i < nums; i++) { - clk =3D clk_register_hisi_mmc(dev, &clks[i], data->base); + struct clk_hw *clk =3D 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] =3D clk; + data->clk_data->hws[clks[i].id] =3D clk; } =20 return 0; diff --git a/drivers/clk/hisilicon/clk-hi6220-stub.c b/drivers/clk/hisilico= n/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 =3D &pdev->dev; struct clk_init_data init; struct hi6220_stub_clk *stub_clk; - struct clk *clk; struct device_node *np =3D pdev->dev.of_node; int ret; =20 @@ -233,11 +232,11 @@ static int hi6220_stub_clk_probe(struct platform_devi= ce *pdev) init.num_parents =3D 0; init.flags =3D 0; =20 - clk =3D devm_clk_register(dev, &stub_clk->hw); - if (IS_ERR(clk)) - return PTR_ERR(clk); + ret =3D devm_clk_hw_register(dev, &stub_clk->hw); + if (ret) + return ret; =20 - ret =3D of_clk_add_provider(np, of_clk_src_simple_get, clk); + ret =3D 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 cdc17f82ce2d..d37a3633f8ae 100644 --- a/drivers/clk/hisilicon/clk-hi6220.c +++ b/drivers/clk/hisilicon/clk-hi6220.c @@ -16,6 +16,13 @@ =20 #include "clk.h" =20 +static int +hi6220_clk_register_divider_stub(struct device *dev, const void *clks, + int num, struct hisi_clock_data *data) +{ + return hi6220_clk_register_divider(dev, clks, num, data); +} + /* clocks in AO (always on) controller */ static struct hisi_fixed_rate_clock hi6220_fixed_rate_clks[] =3D { { HI6220_REF32K, "ref32k", NULL, 0, 32764, }, @@ -176,7 +183,7 @@ static const struct hisi_clocks hi6220_sys_clks =3D { .gate_sep_clks_num =3D ARRAY_SIZE(hi6220_separated_gate_clks_sys), .customized_clks =3D hi6220_div_clks_sys, .customized_clks_num =3D ARRAY_SIZE(hi6220_div_clks_sys), - /* .clk_register_customized =3D hi6220_clk_register_divider, */ + .clk_register_customized =3D hi6220_clk_register_divider_stub, }; =20 /* clocks in media controller */ @@ -224,7 +231,7 @@ static const struct hisi_clocks hi6220_media_clks =3D { .gate_sep_clks_num =3D ARRAY_SIZE(hi6220_separated_gate_clks_media), .customized_clks =3D hi6220_div_clks_media, .customized_clks_num =3D ARRAY_SIZE(hi6220_div_clks_media), - /* .clk_register_customized =3D hi6220_clk_register_divider, */ + .clk_register_customized =3D hi6220_clk_register_divider_stub, }; =20 /* clocks in pmctrl */ @@ -247,7 +254,7 @@ static const struct hisi_clocks hi6220_power_clks =3D { .gate_clks_num =3D ARRAY_SIZE(hi6220_gate_clks_power), .customized_clks =3D hi6220_div_clks_power, .customized_clks_num =3D ARRAY_SIZE(hi6220_div_clks_power), - /* .clk_register_customized =3D hi6220_clk_register_divider, */ + .clk_register_customized =3D hi6220_clk_register_divider_stub, }; =20 /* clocks in acpu */ 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. */ =20 +#include #include #include #include #include -#include =20 #include "clk.h" =20 @@ -90,12 +90,13 @@ static const struct clk_ops clk_phase_ops =3D { .set_phase =3D hisi_clk_set_phase, }; =20 -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; =20 phase =3D 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 =3D clks->phase_num; phase->hw.init =3D &init; =20 - return devm_clk_register(dev, &phase->hw); + ret =3D 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/cl= k-hix5hd2.c index f37a17649d26..d838fbae39fd 100644 --- a/drivers/clk/hisilicon/clk-hix5hd2.c +++ b/drivers/clk/hisilicon/clk-hix5hd2.c @@ -6,7 +6,7 @@ =20 #include =20 -#include +#include #include #include #include @@ -260,13 +260,14 @@ hix5hd2_clk_register_complex(struct device *dev, cons= t void *clocks, int nums, const struct hix5hd2_complex_clock *clks =3D clocks; void __iomem *base =3D data->base; int i; + int ret; =20 for (i =3D 0; i < nums; i++) { struct hix5hd2_clk_complex *p_clk; struct clk *clk; struct clk_init_data init; =20 - p_clk =3D kzalloc(sizeof(*p_clk), GFP_KERNEL); + p_clk =3D devm_kzalloc(dev, sizeof(*p_clk), GFP_KERNEL); if (!p_clk) return -ENOMEM; =20 @@ -289,12 +290,11 @@ hix5hd2_clk_register_complex(struct device *dev, cons= t void *clocks, int nums, p_clk->phy_rst_mask =3D clks[i].phy_rst_mask; p_clk->hw.init =3D &init; =20 - clk =3D clk_register(NULL, &p_clk->hw); - if (IS_ERR(clk)) { - kfree(p_clk); + ret =3D 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; } =20 data->clk_data.clks[clks[i].id] =3D clk; diff --git a/drivers/clk/hisilicon/clk.c b/drivers/clk/hisilicon/clk.c index 96bbc09e7d45..9a5d530c772b 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,67 +26,44 @@ =20 static DEFINE_SPINLOCK(hisi_clk_lock); =20 -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, int nr) { - struct hisi_clock_data *clk_data; - struct resource *res; - struct clk **clk_table; - - clk_data =3D devm_kmalloc(&pdev->dev, sizeof(*clk_data), GFP_KERNEL); - if (!clk_data) - return NULL; - - res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) - return NULL; - clk_data->base =3D devm_ioremap(&pdev->dev, - res->start, resource_size(res)); - if (!clk_data->base) - return NULL; - - clk_table =3D devm_kmalloc_array(&pdev->dev, nr_clks, - sizeof(*clk_table), - GFP_KERNEL); - if (!clk_table) - return NULL; - - clk_data->clk_data.clks =3D clk_table; - clk_data->clk_data.clk_num =3D 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; =20 base =3D of_iomap(np, 0); if (!base) { pr_err("%s: failed to map clock registers\n", __func__); - goto err; + return NULL; } =20 - clk_data =3D kzalloc(sizeof(*clk_data), GFP_KERNEL); - if (!clk_data) - goto err; + data =3D kmalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return NULL; =20 - clk_data->base =3D base; - clk_table =3D kcalloc(nr_clks, sizeof(*clk_table), GFP_KERNEL); - if (!clk_table) + data->clk_data =3D kzalloc(sizeof(*data->clk_data) + nr * sizeof(data->cl= k_data->hws[0]), + GFP_KERNEL); + if (!data->clk_data) goto err_data; =20 - clk_data->clk_data.clks =3D clk_table; - clk_data->clk_data.clk_num =3D nr_clks; - of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data->clk_data); - return clk_data; + ret =3D of_clk_add_hw_provider(np, of_clk_hw_onecell_get, data->clk_data); + if (ret) + goto err_clk; + + data->base =3D base; + data->clks =3D NULL; + data->clk_data->num =3D nr; + for (i =3D 0; i < nr; i++) + data->clk_data->hws[i] =3D 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); @@ -92,312 +72,171 @@ void hisi_clk_free(struct device_node *np, struct his= i_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); } =20 of_clk_del_provider(np); - kfree(data->clk_data.clks); + kfree(data->clk_data); kfree(data); } EXPORT_SYMBOL_GPL(hisi_clk_free); =20 int hisi_clk_register_fixed_rate(const struct hisi_fixed_rate_clock *clks, - int nums, struct hisi_clock_data *data) + int num, struct hisi_clock_data *data) { - struct clk *clk; + struct clk_hw *clk; int i; =20 - for (i =3D 0; i < nums; i++) { - clk =3D clk_register_fixed_rate(NULL, clks[i].name, - clks[i].parent_name, - clks[i].flags, - clks[i].fixed_rate); + for (i =3D 0; i < num; i++) { + const struct hisi_fixed_rate_clock *p_clk =3D &clks[i]; + + clk =3D 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] =3D clk; + + data->clk_data->hws[p_clk->id] =3D clk; } =20 return 0; =20 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); =20 int hisi_clk_register_fixed_factor(const struct hisi_fixed_factor_clock *c= lks, - int nums, - struct hisi_clock_data *data) + int num, struct hisi_clock_data *data) { - struct clk *clk; + struct clk_hw *clk; int i; =20 - for (i =3D 0; i < nums; i++) { - clk =3D 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] =3D clk; - } - - return 0; + for (i =3D 0; i < num; i++) { + const struct hisi_fixed_factor_clock *p_clk =3D &clks[i]; =20 -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); + clk =3D clk_hw_register_fixed_factor(NULL, p_clk->name, p_clk->parent_na= me, + p_clk->flags, p_clk->mult, p_clk->div); =20 -int hisi_clk_register_mux(const struct hisi_mux_clock *clks, - int nums, struct hisi_clock_data *data) -{ - struct clk *clk; - void __iomem *base =3D data->base; - int i; - - for (i =3D 0; i < nums; i++) { - u32 mask =3D BIT(clks[i].width) - 1; - - clk =3D 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; } =20 - if (clks[i].alias) - clk_register_clkdev(clk, clks[i].alias, NULL); - - data->clk_data.clks[clks[i].id] =3D clk; + data->clk_data->hws[p_clk->id] =3D clk; } =20 return 0; =20 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); + +#define hisi_clk_register_fn(fn, type, stmt) \ +int fn(struct device *dev, const struct type *clks, \ + int num, struct hisi_clock_data *data) \ +{ \ + void __iomem *base =3D data->base; \ + int i; \ +\ + for (i =3D 0; i < num; i++) { \ + const struct type *p_clk =3D &clks[i]; \ + struct clk_hw *clk =3D 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] =3D 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)) =20 int hisi_clk_register_phase(struct device *dev, const struct hisi_phase_clock *clks, - int nums, struct hisi_clock_data *data) + int num, struct hisi_clock_data *data) { void __iomem *base =3D data->base; - struct clk *clk; int i; =20 - for (i =3D 0; i < nums; i++) { - clk =3D clk_register_hisi_phase(dev, &clks[i], base, - &hisi_clk_lock); + for (i =3D 0; i < num; i++) { + const struct hisi_phase_clock *p_clk =3D &clks[i]; + struct clk_hw *clk =3D 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); } =20 - data->clk_data.clks[clks[i].id] =3D clk; + data->clk_data->hws[p_clk->id] =3D clk; } =20 return 0; } EXPORT_SYMBOL_GPL(hisi_clk_register_phase); =20 -int hisi_clk_register_divider(const struct hisi_divider_clock *clks, - int nums, struct hisi_clock_data *data) -{ - struct clk *clk; - void __iomem *base =3D data->base; - int i; - - for (i =3D 0; i < nums; i++) { - clk =3D 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] =3D 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 =3D data->base; - int i; - - for (i =3D 0; i < nums; i++) { - clk =3D 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] =3D 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 =3D data->base; - int i; - - for (i =3D 0; i < nums; i++) { - clk =3D 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] =3D 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 =3D data->base; - int i; - - for (i =3D 0; i < nums; i++) { - clk =3D 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] =3D 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)) =20 int hisi_clk_register(struct device *dev, const struct hisi_clocks *clks, struct hisi_clock_data *data) { int ret; =20 - if (clks->mux_clks_num) { - ret =3D hisi_clk_register_mux(clks->mux_clks, - clks->mux_clks_num, data); - if (ret) - return ret; - } - - if (clks->phase_clks_num) { - ret =3D hisi_clk_register_phase(dev, clks->phase_clks, - clks->phase_clks_num, data); - if (ret) - return ret; - } - - if (clks->divider_clks_num) { - ret =3D hisi_clk_register_divider(clks->divider_clks, - clks->divider_clks_num, data); - if (ret) - return ret; - } - - if (clks->gate_clks_num) { - ret =3D 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 =3D 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); =20 if (clks->clk_register_customized && clks->customized_clks_num) { ret =3D clks->clk_register_customized(dev, clks->customized_clks, diff --git a/drivers/clk/hisilicon/clk.h b/drivers/clk/hisilicon/clk.h index def94498e14d..44fafab996bf 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,9 +20,19 @@ struct platform_device; struct hisi_clocks; =20 +/* + * (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; - void __iomem *base; + struct clk_hw_onecell_data *clk_data; + void __iomem *base; const struct hisi_clocks *clks; }; =20 @@ -137,37 +148,46 @@ struct hisi_clocks { int num, struct hisi_clock_data *data); }; =20 -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_phas= e_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, int 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, + int num, struct hisi_clock_data *data); +int hisi_clk_register_fixed_factor(const struct hisi_fixed_factor_clock *c= lks, + int num, struct hisi_clock_data *data); + +int hisi_clk_register_mux(struct device *dev, + const struct hisi_mux_clock *clks, int 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 *); + const struct hisi_phase_clock *clks, + int num, struct hisi_clock_data *data); +int hisi_clk_register_divider(struct device *dev, + const struct hisi_divider_clock *clks, + int num, struct hisi_clock_data *data); +int hisi_clk_register_gate(struct device *dev, + const struct hisi_gate_clock *clks, + int num, struct hisi_clock_data *data); +int hisi_clk_register_gate_sep(struct device *dev, + const struct hisi_gate_clock *clks, + int num, struct hisi_clock_data *data); +int hi6220_clk_register_divider(struct device *dev, + const struct hi6220_divider_clock *clks, + int num, struct hisi_clock_data *data); =20 int hisi_clk_register(struct device *dev, const struct hisi_clocks *clks, struct hisi_clock_data *data); @@ -180,22 +200,17 @@ int hisi_clk_remove(struct platform_device *pdev); =20 #define hisi_clk_unregister_fn(type) \ static inline \ -void hisi_clk_unregister_##type(const struct hisi_##type##_clock *clks, \ - int nums, struct hisi_clock_data *data) \ +void hisi_clk_unregister_##type(struct hisi_clock_data *data) \ { \ - struct clk **clocks =3D data->clk_data.clks; \ int i; \ - for (i =3D 0; i < nums; i++) { \ - int id =3D clks[i].id; \ - if (clocks[id]) \ - clk_unregister_##type(clocks[id]); \ + for (i =3D 0; i < data->clks->type##_clks_num; i++) { \ + struct clk_hw *clk =3D data->clk_data->hws[data->clks->type##_clks[i].id= ]; \ + if (clk && !IS_ERR(clk)) \ + clk_hw_unregister_##type(clk); \ } \ } =20 hisi_clk_unregister_fn(fixed_rate) hisi_clk_unregister_fn(fixed_factor) -hisi_clk_unregister_fn(mux) -hisi_clk_unregister_fn(divider) -hisi_clk_unregister_fn(gate) =20 #endif /* __HISI_CLK_H */ diff --git a/drivers/clk/hisilicon/clkdivider-hi6220.c b/drivers/clk/hisili= con/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 @@ =20 #include #include -#include +#include #include #include #include @@ -97,19 +97,19 @@ static const struct clk_ops hi6220_clkdiv_ops =3D { .set_rate =3D hi6220_clkdiv_set_rate, }; =20 -struct clk *hi6220_register_clkdiv(struct device *dev, const char *name, +struct clk_hw *devm_clk_hw_register_hi6220_divider(struct device *dev, con= st 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; =20 /* allocate the divider */ - div =3D kzalloc(sizeof(*div), GFP_KERNEL); + div =3D devm_kzalloc(dev, sizeof(*div), GFP_KERNEL); if (!div) return ERR_PTR(-ENOMEM); =20 @@ -117,11 +117,9 @@ struct clk *hi6220_register_clkdiv(struct device *dev,= const char *name, max_div =3D div_mask(width) + 1; min_div =3D 1; =20 - table =3D kcalloc(max_div + 1, sizeof(*table), GFP_KERNEL); - if (!table) { - kfree(div); + table =3D devm_kcalloc(dev, max_div + 1, sizeof(*table), GFP_KERNEL); + if (!table) return ERR_PTR(-ENOMEM); - } =20 for (i =3D 0; i < max_div; i++) { table[i].div =3D min_div + i; @@ -144,11 +142,9 @@ struct clk *hi6220_register_clkdiv(struct device *dev,= const char *name, div->table =3D table; =20 /* register the clock */ - clk =3D clk_register(dev, &div->hw); - if (IS_ERR(clk)) { - kfree(table); - kfree(div); - } + ret =3D devm_clk_hw_register(dev, &div->hw); + if (ret) + return ERR_PTR(ret); =20 - return clk; + return &div->hw; } diff --git a/drivers/clk/hisilicon/clkgate-separated.c b/drivers/clk/hisili= con/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 @@ =20 #include #include +#include #include -#include =20 #include "clk.h" =20 @@ -80,17 +80,18 @@ static const struct clk_ops clkgate_separated_ops =3D { .is_enabled =3D clkgate_separated_is_enabled, }; =20 -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; =20 - sclk =3D kzalloc(sizeof(*sclk), GFP_KERNEL); + sclk =3D devm_kzalloc(dev, sizeof(*sclk), GFP_KERNEL); if (!sclk) return ERR_PTR(-ENOMEM); =20 @@ -106,8 +107,9 @@ struct clk *hisi_register_clkgate_sep(struct device *de= v, const char *name, sclk->hw.init =3D &init; sclk->lock =3D lock; =20 - clk =3D clk_register(dev, &sclk->hw); - if (IS_ERR(clk)) - kfree(sclk); - return clk; + ret =3D devm_clk_hw_register(dev, &sclk->hw); + if (ret) + return ERR_PTR(ret); + + return &sclk->hw; } --=20 2.39.2