From patchwork Sun Jan 1 17:57:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 37970 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3857547wrt; Sun, 1 Jan 2023 09:59:34 -0800 (PST) X-Google-Smtp-Source: AMrXdXvYOFqGqEmqdYgRuydyJssgCYgG4Jo4GqbPve3XrYht9W66ju7NhKq67fljbJ/CLQNM5wBv X-Received: by 2002:a05:6402:5407:b0:47e:d7ea:d980 with SMTP id ev7-20020a056402540700b0047ed7ead980mr30345157edb.14.1672595974443; Sun, 01 Jan 2023 09:59:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672595974; cv=none; d=google.com; s=arc-20160816; b=hgX4LunfBiOpH1bf8CP67pyS3ycoHBJ+sygUfa97EK5JcvmrUnO/Yz9HsURd+Z36jX /BsXQcdNDEn5ZMeAtQ9Zbxa5cy4y5s9q3mE9mXMoALUWnHkDWeMYFfIVFQVZGCuX48yP h2nixKcympciXFQ3hZnAikUk03Jw5lSWbZnahcl0ytwmpsHB8dOoDq3If7g0mtXseG+0 phIOd1kCC0yzdW5G6L+ImmacdVQdHt+RjiTPev/jsDwcIxXI8VUu7ioeL12FJ8j5mlIp 94j3KUJ0RvHluRm1uxsEoJsjyJuRT694PHJMlO9obFs7Yoc7dWaHYlOPkz5XxwLuiWGb KZFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=S9smT0T74p/RoQNiIeBlvZXMl6kYsCsXSfs8qRvMbs0=; b=FHBME7+VkhAPJpjmq8uIDUb+BTEj1JdMqUVQAPc0gdCL+bbX9UyZT54TsyF2cy2EFt 1I1ugFqSVOaCN2YU6WibLjWSPdLafK4df8o7GNxJQVMf7GU7QlXIhru2JVw9yEGw3Jlo +5qlZi/yhgeZevUSheGgmoeFDBim1b/CgAWXiLo1M3P10oQATv20CiVI9O6JIj84CTHE PdNvG6TTqaU+J//WDkx32riapqbbsPf7cW2ULbix2nHDUorR2nwEmzuso7DaLrlF/4jx fe+BkisOzU1XxJ8yVyFB2Y7XB7jtcSRvM09adA7cK41hO4BUCjtxbvlk+JmspanLaA27 Idvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=OYKuiBkO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y14-20020a056402358e00b00484c1d97aa5si18497346edc.278.2023.01.01.09.59.10; Sun, 01 Jan 2023 09:59:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=OYKuiBkO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231679AbjAAR6S (ORCPT + 99 others); Sun, 1 Jan 2023 12:58:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbjAAR6C (ORCPT ); Sun, 1 Jan 2023 12:58:02 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4EAF2DDC for ; Sun, 1 Jan 2023 09:57:58 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id jo4so62253194ejb.7 for ; Sun, 01 Jan 2023 09:57:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; 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=S9smT0T74p/RoQNiIeBlvZXMl6kYsCsXSfs8qRvMbs0=; b=OYKuiBkOOwjN29tPh1/cWMs8cLG1wN2gp0u2wLLC0QTtDK5gbTk2HFLUf7vAZNygrn MzNeRUIkv5H3GMEoY2GSnne2ri+CNzGqq+W7e2d+T/6j+hrxmefHXrVCtdQIDCzgMN9l iwrDTX42EVaqJ+VwQgXF6NcoaEHCF78TMprDI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=S9smT0T74p/RoQNiIeBlvZXMl6kYsCsXSfs8qRvMbs0=; b=T7vBEA4oUT9IB3xmQp07R36/ff44PWIdZ9xXv6801IqoMAlW7+h1FVR9EcwdvINO3h NdDOoud60KZI35lIVquJsiX8kwtkIXfXOWoOlt5DaINGwirpgau7K+or2dhMW0ppLj06 lyhlLer6ggthXM4KKEL3gxY+tNvEjUg/8dGBW1k8oEG0vCApBsM9RpK34GtCXkX8t8aM U4MIKlILDeyZzos1S1ClcaIiQJxExIIS/prAF61Q/OEfiRCkpJwlhAniTwoxZmcXRx5H fkZ9cGA8PgDMvNdr0sXwRATnkU46EOZUtEkyb9i1jRrV/SvkiPO57d/pnUGkYQXxnHw/ TSqA== X-Gm-Message-State: AFqh2kok8vFSFk3cbFiF+/Gf+d9TzlR8D0JsUxOO0n+x5JpvTPUjgmZo DRB7mvco8tesVtsTETOMdckVE7C+KTXbT62Llps= X-Received: by 2002:a17:906:910:b0:7c0:f71b:8b3 with SMTP id i16-20020a170906091000b007c0f71b08b3mr32097158ejd.57.1672595876863; Sun, 01 Jan 2023 09:57:56 -0800 (PST) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-80-180-23-57.retail.telecomitalia.it. [80.180.23.57]) by smtp.gmail.com with ESMTPSA id q2-20020a1709063d4200b0082ddfb47d06sm12273018ejf.148.2023.01.01.09.57.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Jan 2023 09:57:56 -0800 (PST) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: angelo@amarulasolutions.com, michael@amarulasolutions.com, tommaso.merciai@amarulasolutions.com, Chen-Yu Tsai , linux-amarula@amarulasolutions.com, anthony@amarulasolutions.com, jagan@amarulasolutions.com, Dario Binacchi , kernel test robot , Abel Vesa , Fabio Estevam , Michael Turquette , NXP Linux Team , Pengutronix Kernel Team , Sascha Hauer , Shawn Guo , Stephen Boyd , linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org Subject: [RFC PATCH v2 07/11] clk: imx: composite-8m: add device tree support Date: Sun, 1 Jan 2023 18:57:36 +0100 Message-Id: <20230101175740.1010258-8-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230101175740.1010258-1-dario.binacchi@amarulasolutions.com> References: <20230101175740.1010258-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753843996707701145?= X-GMAIL-MSGID: =?utf-8?q?1753843996707701145?= The patch, backwards compatible, extends the driver to initialize the clock directly from the device tree. Signed-off-by: Dario Binacchi Reported-by: kernel test robot --- Changes in v2: - Fix compiler warnings reported by kernel test robot. drivers/clk/imx/clk-composite-8m.c | 84 ++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/drivers/clk/imx/clk-composite-8m.c b/drivers/clk/imx/clk-composite-8m.c index cbf0d7955a00..fa5fdfff0b2d 100644 --- a/drivers/clk/imx/clk-composite-8m.c +++ b/drivers/clk/imx/clk-composite-8m.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include "clk.h" @@ -25,6 +27,9 @@ #define PCG_CGC_SHIFT 28 +#undef pr_fmt +#define pr_fmt(fmt) "%s: " fmt, __func__ + static unsigned long imx8m_clk_composite_divider_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { @@ -250,3 +255,82 @@ struct clk_hw *__imx8m_clk_hw_composite(const char *name, return ERR_CAST(hw); } EXPORT_SYMBOL_GPL(__imx8m_clk_hw_composite); + +static void __init _of_imx_composite_clk_setup(struct device_node *node, + u32 type) +{ + void __iomem *reg; + struct clk_hw *hw; + const char *name = node->name; + unsigned int num_parents; + const char **parent_names; + unsigned long flags = IMX_COMPOSITE_CLK_FLAGS_DEFAULT; + + reg = of_iomap(node, 0); + if (IS_ERR(reg)) { + pr_err("failed to get reg address for %pOFn\n", node); + return; + } + + num_parents = of_clk_get_parent_count(node); + if (num_parents < 2) { + pr_err("%pOFn must have parents\n", node); + return; + } + + parent_names = kzalloc((sizeof(char *) * num_parents), GFP_KERNEL); + if (!parent_names) + return; + + of_clk_parent_fill(node, parent_names, num_parents); + of_property_read_string(node, "clock-output-names", &name); + + if (of_property_read_bool(node, "fsl,get-rate-nocache")) + flags |= CLK_GET_RATE_NOCACHE; + + if (of_property_read_bool(node, "fsl,is-critical")) + flags |= CLK_IS_CRITICAL; + + hw = __imx8m_clk_hw_composite(name, parent_names, num_parents, reg, + type, flags); + if (!IS_ERR(hw)) + of_clk_add_hw_provider(node, of_clk_hw_simple_get, hw); + + kfree(parent_names); +} + +/** + * of_imx_composite_clk_setup() - Setup function for imx composite clock + * @node: device node for the clock + */ +static void __init of_imx_composite_clk_setup(struct device_node *node) +{ + _of_imx_composite_clk_setup(node, IMX_COMPOSITE_CORE); +} +CLK_OF_DECLARE(fsl_composite_8m_clk, "fsl,imx8m-composite-clock", + of_imx_composite_clk_setup); + +/** + * of_imx_composite_bus_clk_setup() - Setup function for imx composite clock + * @node: device node for the clock + */ +static void __init of_imx_composite_bus_clk_setup(struct device_node *node) +{ + _of_imx_composite_clk_setup(node, IMX_COMPOSITE_BUS); +} +CLK_OF_DECLARE(fsl_composite_bus_8m_clk, "fsl,imx8m-composite-bus-clock", + of_imx_composite_bus_clk_setup); + +/** + * of_imx_composite_fw_managed_clk_setup() - Setup function for imx + * composite fw managed clock + * @node: device node for the clock + */ +static void __init +of_imx_composite_fw_managed_clk_setup(struct device_node *node) +{ + _of_imx_composite_clk_setup(node, IMX_COMPOSITE_FW_MANAGED); +} +CLK_OF_DECLARE(fsl_composite_fw_managed_8m_clk, + "fsl,imx8m-composite-fw-managed-clock", + of_imx_composite_fw_managed_clk_setup);