mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Konrad Dybcio <konradybcio@kernel.org>
To: Bjorn Andersson <andersson@kernel.org>,
	 Michael Turquette <mturquette@baylibre.com>,
	 Stephen Boyd <sboyd@kernel.org>, Rob Herring <robh@kernel.org>,
	 Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>, Lee Jones <lee@kernel.org>,
	 Taniya Das <taniya.das@oss.qualcomm.com>,
	Linus Walleij <linusw@kernel.org>,
	 Melody Olvera <quic_molvera@quicinc.com>,
	 Konrad Dybcio <konradybcio@kernel.org>,
	Taniya Das <quic_tdas@quicinc.com>,
	 Raviteja Laggyshetty <quic_rlaggysh@quicinc.com>,
	 Jishnu Prakash <quic_jprakash@quicinc.com>
Cc: linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org,
	 devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-gpio@vger.kernel.org,
	Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>,
	 Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Subject: [PATCH RFC 3/8] pinctrl: qcom: Allow exposing reference clocks living in TLMM reg space
Date: Mon, 02 Feb 2026 15:57:35 +0100	[thread overview]
Message-ID: <20260202-topic-8750_tcsr-v1-3-cd7e6648c64f@oss.qualcomm.com> (raw)
In-Reply-To: <20260202-topic-8750_tcsr-v1-0-cd7e6648c64f@oss.qualcomm.com>

From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>

Certain platforms (at least SM8750) had a number of registers
(responsible for gating refclk output to various consumers) moved to
TLMM. They're simple on/off toggles.

Expose them from the msm-pinctrl driver to allow for a reasonable DT
representation.

Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 drivers/pinctrl/qcom/pinctrl-msm.c | 92 ++++++++++++++++++++++++++++++++++++++
 drivers/pinctrl/qcom/pinctrl-msm.h | 14 ++++++
 2 files changed, 106 insertions(+)

diff --git a/drivers/pinctrl/qcom/pinctrl-msm.c b/drivers/pinctrl/qcom/pinctrl-msm.c
index e99871b90ab9..1a52431a8605 100644
--- a/drivers/pinctrl/qcom/pinctrl-msm.c
+++ b/drivers/pinctrl/qcom/pinctrl-msm.c
@@ -4,6 +4,7 @@
  * Copyright (c) 2013, The Linux Foundation. All rights reserved.
  */
 
+#include <linux/clk-provider.h>
 #include <linux/delay.h>
 #include <linux/err.h>
 #include <linux/gpio/driver.h>
@@ -16,6 +17,7 @@
 #include <linux/pm.h>
 #include <linux/firmware/qcom/qcom_scm.h>
 #include <linux/reboot.h>
+#include <linux/regmap.h>
 #include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
@@ -80,6 +82,7 @@ struct msm_pinctrl {
 	const struct msm_pinctrl_soc_data *soc;
 	void __iomem *regs[MAX_NR_TILES];
 	u32 phys_base[MAX_NR_TILES];
+	struct ref_clk ref_clks[];
 };
 
 #define MSM_ACCESSOR(name) \
@@ -1525,9 +1528,69 @@ SIMPLE_DEV_PM_OPS(msm_pinctrl_dev_pm_ops, msm_pinctrl_suspend,
 
 EXPORT_SYMBOL(msm_pinctrl_dev_pm_ops);
 
+static int clkref_enable(struct clk_hw *hw)
+{
+	struct ref_clk *rclk = container_of(hw, struct ref_clk, hw);
+	u32 val;
+
+	regmap_write(rclk->regmap, rclk->init.offset, BIT(0));
+	udelay(10);
+
+	regmap_read(rclk->regmap, rclk->init.offset, &val);
+
+	return (val & BIT(0)) ? 0 : -EINVAL;
+}
+
+static void clkref_disable(struct clk_hw *hw)
+{
+	struct ref_clk *rclk = container_of(hw, struct ref_clk, hw);
+
+	regmap_write(rclk->regmap, rclk->init.offset, 0);
+
+	udelay(10);
+}
+
+static int clkref_is_enabled(struct clk_hw *hw)
+{
+	struct ref_clk *rclk = container_of(hw, struct ref_clk, hw);
+	u32 val;
+
+	regmap_read(rclk->regmap, rclk->init.offset, &val);
+
+	return !!val;
+}
+
+static const struct clk_ops clkref_ops = {
+	.enable = clkref_enable,
+	.disable = clkref_disable,
+	.is_enabled = clkref_is_enabled,
+};
+
+static struct clk_hw *msm_pinctrl_clk_get(struct of_phandle_args *clkspec, void *data)
+{
+	struct msm_pinctrl *pctrl = data;
+	u32 idx = clkspec->args[0];
+
+	if (idx >= pctrl->soc->num_ref_clks)
+		return ERR_PTR(-EINVAL);
+
+	return &pctrl->ref_clks[idx].hw;
+}
+
+static const struct clk_parent_data clkref_parent_data = {
+	.index = 0, /* RPM(h) XO clock */
+};
+
+static const struct regmap_config clkref_regmap_config = {
+	.reg_bits = 32,
+	.reg_stride = 4,
+	.val_bits = 32,
+};
+
 int msm_pinctrl_probe(struct platform_device *pdev,
 		      const struct msm_pinctrl_soc_data *soc_data)
 {
+	struct device *dev = &pdev->dev;
 	const struct pinfunction *func;
 	struct msm_pinctrl *pctrl;
 	struct resource *res;
@@ -1595,6 +1658,35 @@ int msm_pinctrl_probe(struct platform_device *pdev,
 	if (ret)
 		return ret;
 
+	if (soc_data->num_ref_clks) {
+		struct regmap *regmap = devm_regmap_init_mmio(dev, pctrl->regs[0],
+							      &clkref_regmap_config);
+		if (IS_ERR(regmap))
+			return PTR_ERR(regmap);
+
+		for (int i = 0; i < soc_data->num_ref_clks; i++) {
+			struct clk_hw *hw = &pctrl->ref_clks[i].hw;
+			struct clk_init_data init = { };
+
+			init.name = pctrl->soc->ref_clks[i]->name;
+			init.parent_data = &clkref_parent_data;
+			init.num_parents = 1;
+			init.ops = &clkref_ops;
+			hw->init = &init;
+
+			ret = devm_clk_hw_register(dev, hw);
+			if (ret)
+				return dev_err_probe(dev, ret, "Couldn't register clock %s\n",
+						     init.name);
+
+			pctrl->ref_clks[i].regmap = regmap;
+		}
+
+		ret = devm_of_clk_add_hw_provider(dev, msm_pinctrl_clk_get, pctrl);
+		if (ret)
+			return dev_err_probe(dev, ret, "Couldn't register clk provider\n");
+	}
+
 	platform_set_drvdata(pdev, pctrl);
 
 	dev_dbg(&pdev->dev, "Probed Qualcomm pinctrl driver\n");
diff --git a/drivers/pinctrl/qcom/pinctrl-msm.h b/drivers/pinctrl/qcom/pinctrl-msm.h
index 4625fa5320a9..213cc789711d 100644
--- a/drivers/pinctrl/qcom/pinctrl-msm.h
+++ b/drivers/pinctrl/qcom/pinctrl-msm.h
@@ -5,6 +5,7 @@
 #ifndef __PINCTRL_MSM_H__
 #define __PINCTRL_MSM_H__
 
+#include <linux/clk-provider.h>
 #include <linux/pm.h>
 #include <linux/types.h>
 
@@ -129,6 +130,17 @@ struct msm_gpio_wakeirq_map {
 	unsigned int wakeirq;
 };
 
+struct ref_clk_init_data {
+	const char * const name;
+	u32 offset;
+};
+
+struct ref_clk {
+	struct clk_hw hw;
+	struct regmap *regmap;
+	struct ref_clk_init_data init;
+};
+
 /**
  * struct msm_pinctrl_soc_data - Qualcomm pin controller driver configuration
  * @pins:	    An array describing all pins the pin controller affects.
@@ -170,6 +182,8 @@ struct msm_pinctrl_soc_data {
 	bool wakeirq_dual_edge_errata;
 	unsigned int gpio_func;
 	unsigned int egpio_func;
+	const struct ref_clk_init_data **ref_clks;
+	unsigned int num_ref_clks;
 };
 
 extern const struct dev_pm_ops msm_pinctrl_dev_pm_ops;

-- 
2.52.0


  parent reply	other threads:[~2026-02-02 14:58 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-02 14:57 [RFC PATCH 0/8] Fix TCSR representation on SM8750 Konrad Dybcio
2026-02-02 14:57 ` [PATCH RFC 1/8] dt-bindings: Move qcom,sm8750-tcsr from clock/tcsr to mfd/tcsr Konrad Dybcio
2026-02-02 14:57 ` [PATCH RFC 2/8] dt-bindings: pinctrl: qcom,sm8750-tlmm: Allow clocks/clock-cells Konrad Dybcio
2026-02-02 14:57 ` Konrad Dybcio [this message]
2026-02-02 19:39   ` [PATCH RFC 3/8] pinctrl: qcom: Allow exposing reference clocks living in TLMM reg space Dmitry Baryshkov
2026-02-02 14:57 ` [PATCH RFC 4/8] pinctrl: qcom: sm8750: Expose reference clocks Konrad Dybcio
2026-02-17 11:51   ` Abel Vesa
2026-02-02 14:57 ` [PATCH RFC 5/8] arm64: dts: qcom: Remove inexistent TCSR_CC Konrad Dybcio
2026-02-17 11:52   ` Abel Vesa
2026-02-17 12:39   ` Krzysztof Kozlowski
2026-02-17 12:43     ` Konrad Dybcio
2026-02-17 12:44       ` Krzysztof Kozlowski
2026-02-02 14:57 ` [PATCH RFC 6/8] clk: qcom: Remove tcsrcc-sm8750 Konrad Dybcio
2026-02-17 11:48   ` Abel Vesa
2026-02-17 11:50     ` Konrad Dybcio
2026-02-17 12:04       ` Abel Vesa
2026-02-02 14:57 ` [PATCH RFC 7/8] arm64: dts: qcom: sm8750: Describe TCSR Konrad Dybcio
2026-02-02 14:57 ` [PATCH RFC 8/8] arm64: defconfig: Remove CONFIG_SM_TCSRCC_8750 Konrad Dybcio
2026-02-17 11:52   ` Abel Vesa
2026-02-02 18:19 ` [RFC PATCH 0/8] Fix TCSR representation on SM8750 Mukesh Ojha
2026-02-03 12:09   ` Konrad Dybcio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260202-topic-8750_tcsr-v1-3-cd7e6648c64f@oss.qualcomm.com \
    --to=konradybcio@kernel.org \
    --cc=andersson@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=konrad.dybcio@oss.qualcomm.com \
    --cc=krzk+dt@kernel.org \
    --cc=lee@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=mukesh.ojha@oss.qualcomm.com \
    --cc=quic_jprakash@quicinc.com \
    --cc=quic_molvera@quicinc.com \
    --cc=quic_rlaggysh@quicinc.com \
    --cc=quic_tdas@quicinc.com \
    --cc=robh@kernel.org \
    --cc=sboyd@kernel.org \
    --cc=taniya.das@oss.qualcomm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®