Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp702742rbb; Sat, 24 Feb 2024 22:54:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWxcfuMOhPyMo2lkki5ibAvr+MEB0KcrY8xFoYd/k/lJ6AdOCuhAj+UFDJys1qu5DWhyj07daxFUNOZqpNyoDc4Gux8RYrW5cZtAqAAxA== X-Google-Smtp-Source: AGHT+IEqDVXFVK3M5DeoqF3ZlOUjSthCyj3UyYNdf+juEOpgQy2hF0K5QZpKbxgBJ0KquRiUvhe5 X-Received: by 2002:a0c:f38c:0:b0:68f:477e:5e64 with SMTP id i12-20020a0cf38c000000b0068f477e5e64mr4525417qvk.45.1708844044816; Sat, 24 Feb 2024 22:54:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708844044; cv=pass; d=google.com; s=arc-20160816; b=irlOCCmNmSGoTSrBDU1uZonh+99s2un9Jp3m6ogEF5vUlvj1gEAvMa9YV2BFv4bShD iwwJpF/7KrmtMSDw8YSXMVoOJYTG1LRXR4dFLz5yHZ/sJ5nS61hYPU9FcwNLu8+OICBs gHse5zGsOyxl89zobFNrT6Aaa5u+3iuCBKQgldIZcCExFR2osLOBj5ihlAYorXu4PCAl 5VemrZbl6eobCaKvutjdQJAuMHLTYKug1LQK4hMmtopk91hJC+yKZKOcO/SH+PfrPrIT 5LyV2aF5LSjYiNd8CZIQfHWZVV+Bm6oR69S2BxdSVGYvSAB5WMwQ8/IKqcxLZSyENkD6 Cy1A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=tC6rG1fD3ItI1XoGthXm2AMsyO+JK9+EA6lFFhllInI=; fh=I168ufnu7xH6AQWacAe+I+kQjRQRezg9bUfKdjsAA9c=; b=f0DNvLKXB2ywDRqyY1GSR7vDLQuVRf1ETjfPOxU5Bwy3P1fljtJKl6y0UF7pQW7kAW gAimvdlOnWVUgyLHaH54hEPA/F28j/ygI3ETPFXw1r3pxMp4a3wUSmmDpLVVVUR38LRo 2AmUng9h16VuQXtvBYAFn0I7PTa0YGBfRmM4VlKzDISxnPZ2jAXvNc39vhteLcC2mDrw S0IH/cA1p5wLx/nF/Dp0WJdrPwVwhm9QHS008g398CpsYjnkC/OTnlka8fK5J7yHh8KG RblrpFXhczNxFUdrFYjbtM0Cjn5dYPNlf9LoVSVVKfT0WqGb20mkU/EfZuLQrHVN+V1x xDnA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=RTvYJ3uz; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-79999-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79999-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ed5-20020ad44ea5000000b0068cb4c6ecdbsi2585436qvb.317.2024.02.24.22.54.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 22:54:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79999-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=RTvYJ3uz; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-79999-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79999-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8401A1C20ACF for ; Sun, 25 Feb 2024 06:54:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9CB28DDAD; Sun, 25 Feb 2024 06:53:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RTvYJ3uz" Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2621F9EF; Sun, 25 Feb 2024 06:53:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708844008; cv=none; b=q61BzMeIUJM6M5knKs8ny9CKhZ/FkGXcM+BMOS5dEQJkJPVrNaQQjpQEEx9h8mV/whk5xmFspawxc7nXBd/vGrW42DgJd9eMHD4GtHvUzFVSFAr9dtfztZAe/biZF0FqQ+GjJEc7WJ/tLXBeKGK7rzPmuMEbiqq4i7ObWh1Njz0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708844008; c=relaxed/simple; bh=jqDNrGAyxsYzMLYgVvkvn3DsQMoDqzG2Abl6HqZwq3U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UzX8qMLL7gc3mcukRUY7+omPM4V75VWrBSEE19eP2F2ooFcUdkHiobHj9Ia8u9plceX76QcDgeYDQdoss8q2Ky75IrpvTAn80EeO9CiQxw3jRNwPdrj95KYFzgEpKdH4RQ0+9e/ao8IJp44njTrnVqsQhwlTh+alXD4T0czExGI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RTvYJ3uz; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-6e4560664b5so1712843b3a.1; Sat, 24 Feb 2024 22:53:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708844006; x=1709448806; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tC6rG1fD3ItI1XoGthXm2AMsyO+JK9+EA6lFFhllInI=; b=RTvYJ3uzOdeYw491jBGjwbT0fkuZuj1Ob5CcDqWa8oTMyCo7sautN9QrKioh7ESt/t 0wGzfi5UuNPWkTNWTPRRL7bnwkReUPfJcFXNoRt6qxMaL30as25ASsY8kCOK2AoksvgC iqko1c5aq+fe6e/CWtwfaGMvxR9KdCLvfL5eSIi8x0wuNRcv++dczIYgpTk5AIPxJzAr OsyNe8Hkriaj8XAy+G/oaTkgsH15PLUd97cMQb1gSQixjOcDHP4sZksFgrqchOhcFubT 29Nc9fGVBViaxTQIjnP2Uc5OZrHlljNOhEMpTgX/xYHtfkiEYy6VIAtMlItu4D6xEAAZ o27w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708844006; x=1709448806; 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=tC6rG1fD3ItI1XoGthXm2AMsyO+JK9+EA6lFFhllInI=; b=DwZ8ALXwJx7YRca0WVURetyrKDTwC78IseqQkx8XHfgzSbuf/rt3UDQRdyDsOGfzL7 r9mRg4ZG8/IlDiK64DwHv7yjpSUSAUEeKctyBbdPcRdwEGvtI6gP4lBIiop1vujf8OjA 6+OqpU9kp7ybOQ7AWyWGWp0AAk+ScF6anH2Ks5zfZmfiJ7riEvZl5SINK4fvoqbl9fY+ qWFI34sAv0BiW/Htfu/aNEzNYEudOI9fAGRETpvcNKOtcQHtLKHJxAbsq7iVPEBraoar 7bJJj5c6N27ZtbWeOWLBysUIRlUMcHcxpI34RAeRFoTh028LP+t3uyVl8AvPkBDzDB7e T2sw== X-Forwarded-Encrypted: i=1; AJvYcCVzsMJlCTStFgot+Fvrvk+yFIvepUOApQ0Uo7F/d0BZPdx7R2l4oEyDq/+9KgwrN/fH3w+C26D9H3CfO8fIowjuPr579wr5hwlHpdsl X-Gm-Message-State: AOJu0YzhNl+Hafruwyzezbmh1uX1+T6SiNEObZbsOXgHANwuKfPLNQD3 rfWzaCjBnfCtP6ZaTJPC1rSl80UhefukFiPJQCEg490OlW/+mzVCfZ1vd8jn6014gQ== X-Received: by 2002:a62:cf04:0:b0:6e4:625a:f03 with SMTP id b4-20020a62cf04000000b006e4625a0f03mr4201315pfg.15.1708844005820; Sat, 24 Feb 2024 22:53:25 -0800 (PST) Received: from localhost.localdomain ([171.218.176.26]) by smtp.gmail.com with ESMTPSA id p18-20020a056a0026d200b006e45b910a98sm1930313pfw.6.2024.02.24.22.53.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 22:53:25 -0800 (PST) From: David Yang To: linux-clk@vger.kernel.org Cc: Yang Xiwen , David Yang , Michael Turquette , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH v7 03/13] clk: hisilicon: hi3798cv200: Use helper functions Date: Sun, 25 Feb 2024 14:52:18 +0800 Message-ID: <20240225065234.413687-4-mmyangfl@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240225065234.413687-1-mmyangfl@gmail.com> References: <20240225065234.413687-1-mmyangfl@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Use common helper functions and register clks with a single of_device_id data. Signed-off-by: David Yang --- drivers/clk/hisilicon/crg-hi3798cv200.c | 200 +++--------------------- 1 file changed, 22 insertions(+), 178 deletions(-) diff --git a/drivers/clk/hisilicon/crg-hi3798cv200.c b/drivers/clk/hisilicon/crg-hi3798cv200.c index f651b197e45a..9ce590cc4142 100644 --- a/drivers/clk/hisilicon/crg-hi3798cv200.c +++ b/drivers/clk/hisilicon/crg-hi3798cv200.c @@ -12,7 +12,6 @@ #include #include "clk.h" #include "crg.h" -#include "reset.h" /* hi3798CV200 core CRG */ #define HI3798CV200_INNER_CLK_OFFSET 64 @@ -41,6 +40,7 @@ #define HI3798CV200_CRG_NR_CLKS 128 +#define HI3798CV200_SYSCTRL_NR_CLKS 16 static const struct hisi_fixed_rate_clock hi3798cv200_fixed_rate_clks[] = { { HISTB_OSC_CLK, "clk_osc", NULL, 0, 24000000, }, { HISTB_APB_CLK, "clk_apb", NULL, 0, 100000000, }, @@ -193,90 +193,18 @@ static const struct hisi_gate_clock hi3798cv200_gate_clks[] = { CLK_SET_RATE_PARENT, 0xb0, 18, 0 }, }; -static struct hisi_clock_data *hi3798cv200_clk_register( - struct platform_device *pdev) -{ - struct hisi_clock_data *clk_data; - int ret; - - clk_data = hisi_clk_alloc(pdev, HI3798CV200_CRG_NR_CLKS); - if (!clk_data) - return ERR_PTR(-ENOMEM); - - /* hisi_phase_clock is resource managed */ - ret = hisi_clk_register_phase(&pdev->dev, - hi3798cv200_phase_clks, - ARRAY_SIZE(hi3798cv200_phase_clks), - clk_data); - if (ret) - return ERR_PTR(ret); - - ret = hisi_clk_register_fixed_rate(hi3798cv200_fixed_rate_clks, - ARRAY_SIZE(hi3798cv200_fixed_rate_clks), - clk_data); - if (ret) - return ERR_PTR(ret); - - ret = hisi_clk_register_mux(hi3798cv200_mux_clks, - ARRAY_SIZE(hi3798cv200_mux_clks), - clk_data); - if (ret) - goto unregister_fixed_rate; - - ret = hisi_clk_register_gate(hi3798cv200_gate_clks, - ARRAY_SIZE(hi3798cv200_gate_clks), - clk_data); - if (ret) - goto unregister_mux; - - ret = of_clk_add_provider(pdev->dev.of_node, - of_clk_src_onecell_get, &clk_data->clk_data); - if (ret) - goto unregister_gate; - - return clk_data; - -unregister_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 = 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 = { - .register_clks = hi3798cv200_clk_register, - .unregister_clks = hi3798cv200_clk_unregister, +static const struct hisi_clocks hi3798cv200_crg_clks = { + .nr = HI3798CV200_CRG_NR_CLKS, + .fixed_rate_clks = hi3798cv200_fixed_rate_clks, + .fixed_rate_clks_num = ARRAY_SIZE(hi3798cv200_fixed_rate_clks), + .mux_clks = hi3798cv200_mux_clks, + .mux_clks_num = ARRAY_SIZE(hi3798cv200_mux_clks), + .phase_clks = hi3798cv200_phase_clks, + .phase_clks_num = ARRAY_SIZE(hi3798cv200_phase_clks), + .gate_clks = hi3798cv200_gate_clks, + .gate_clks_num = ARRAY_SIZE(hi3798cv200_gate_clks), }; -/* hi3798CV200 sysctrl CRG */ - -#define HI3798CV200_SYSCTRL_NR_CLKS 16 - static const struct hisi_gate_clock hi3798cv200_sysctrl_gate_clks[] = { { HISTB_IR_CLK, "clk_ir", "24m", CLK_SET_RATE_PARENT, 0x48, 4, 0, }, @@ -286,115 +214,31 @@ static const struct hisi_gate_clock hi3798cv200_sysctrl_gate_clks[] = { CLK_SET_RATE_PARENT, 0x48, 10, 0, }, }; -static struct hisi_clock_data *hi3798cv200_sysctrl_clk_register( - struct platform_device *pdev) -{ - struct hisi_clock_data *clk_data; - int ret; - - clk_data = hisi_clk_alloc(pdev, HI3798CV200_SYSCTRL_NR_CLKS); - if (!clk_data) - return ERR_PTR(-ENOMEM); - - ret = hisi_clk_register_gate(hi3798cv200_sysctrl_gate_clks, - ARRAY_SIZE(hi3798cv200_sysctrl_gate_clks), - clk_data); - if (ret) - return ERR_PTR(ret); - - ret = of_clk_add_provider(pdev->dev.of_node, - of_clk_src_onecell_get, &clk_data->clk_data); - if (ret) - goto unregister_gate; - - return clk_data; - -unregister_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 *pdev) -{ - struct hisi_crg_dev *crg = 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 = { - .register_clks = hi3798cv200_sysctrl_clk_register, - .unregister_clks = hi3798cv200_sysctrl_clk_unregister, +static const struct hisi_clocks hi3798cv200_sysctrl_clks = { + .nr = HI3798CV200_SYSCTRL_NR_CLKS, + .gate_clks = hi3798cv200_sysctrl_gate_clks, + .gate_clks_num = ARRAY_SIZE(hi3798cv200_sysctrl_gate_clks), }; static const struct of_device_id hi3798cv200_crg_match_table[] = { { .compatible = "hisilicon,hi3798cv200-crg", - .data = &hi3798cv200_crg_funcs }, + .data = &hi3798cv200_crg_clks }, { .compatible = "hisilicon,hi3798cv200-sysctrl", - .data = &hi3798cv200_sysctrl_funcs }, + .data = &hi3798cv200_sysctrl_clks }, { } }; MODULE_DEVICE_TABLE(of, hi3798cv200_crg_match_table); -static int hi3798cv200_crg_probe(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg; - - crg = devm_kmalloc(&pdev->dev, sizeof(*crg), GFP_KERNEL); - if (!crg) - return -ENOMEM; - - crg->funcs = of_device_get_match_data(&pdev->dev); - if (!crg->funcs) - return -ENOENT; - - crg->rstc = hisi_reset_init(pdev); - if (!crg->rstc) - return -ENOMEM; - - crg->clk_data = 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 void hi3798cv200_crg_remove(struct platform_device *pdev) -{ - struct hisi_crg_dev *crg = platform_get_drvdata(pdev); - - hisi_reset_exit(crg->rstc); - crg->funcs->unregister_clks(pdev); -} - static struct platform_driver hi3798cv200_crg_driver = { - .probe = hi3798cv200_crg_probe, - .remove_new = hi3798cv200_crg_remove, - .driver = { - .name = "hi3798cv200-crg", + .probe = hisi_crg_probe, + .remove_new = hisi_crg_remove, + .driver = { + .name = "hi3798cv200-crg", .of_match_table = hi3798cv200_crg_match_table, }, }; -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); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("HiSilicon Hi3798CV200 CRG Driver"); -- 2.43.0