Re: [PATCH v3 03/10] clk: qcom: Add a driver for PDM GP_MN fractional clock divider

From: Abel Vesa

Date: Tue Nov 24 2026 - 00:54:54 EST


On 26-11-24 01:21:34, Taniya Das wrote:
> The PDM (Pulse Density Modulation) hardware block on Qualcomm SoCs
> contains a GP_MN clock divider that produces a fractional output
> frequency from a fixed input clock (typically TCXO4):
>
> Fout = Fin * (M / N)
>
> The hardware encodes the period in the NDIV register as the 1's
> complement of (N - M), and controls the duty cycle via a separate
> DUTY register that counts the number of low-phase native clock
> cycles over the period N.
>
> Add a standalone platform driver for this block that uses
> rational_best_approximation() to find the closest M/N pair within
> the 9-bit M and 13-bit N hardware limits. Reject ratios which cannot
> support a valid duty cycle, and program the MDIV, NDIV, and DUTY
> registers via regmap. Implement determine_rate, set_rate,
> recalc_rate, get_duty_cycle, and set_duty_cycle operations. The PDM
> AHB bus clock is gated around every register access.
>
> Signed-off-by: Taniya Das <taniya.das@xxxxxxxxxxxxxxxx>
> ---
> drivers/clk/qcom/Kconfig | 15 ++
> drivers/clk/qcom/Makefile | 1 +
> drivers/clk/qcom/clk-gp-mnd.c | 342 ++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 358 insertions(+)
>
> diff --git a/drivers/clk/qcom/Kconfig b/drivers/clk/qcom/Kconfig
> index e6c58e8b184963fa3d885a7661ad982aaa5bcbc0..ccab70a11cfcaa3ea2217101ade50ab255631837 100644
> --- a/drivers/clk/qcom/Kconfig
> +++ b/drivers/clk/qcom/Kconfig
> @@ -2170,4 +2170,19 @@ config SM_VIDEOCC_8450
> SM8450 or SM8475 devices.
> Say Y if you want to support video devices and functionality such as
> video encode/decode.
> +
> +config QCOM_CLK_GP_MND
> + tristate "Qualcomm PDM GP_MN clock divider"
> + depends on ARM64 || COMPILE_TEST
> + help
> + Support for the Qualcomm PDM GP_MN clock divider found in PDM
> + (Pulse Density Modulation) hardware blocks.
> + Given an input clock of frequency Fin (TCXO4), the output
> + frequency is Fout = Fin * (M / N). For every N input cycles
> + the divider produces M output cycles. D controls the duty
> + cycle: it is the number of native clock cycles in which the
> + GP_MN output is low, counted over 8192 native clock cycles.
> +
> + Say Y or M if you want to support GP_MN-based frequency and
> + duty-cycle configuration on Qualcomm SoCs.
> endif
> diff --git a/drivers/clk/qcom/Makefile b/drivers/clk/qcom/Makefile
> index f84d7343a3a475dd9ef1fa77bf0de25fab0d9e75..bc487b25ef5d9a235162fad95a3e0ef2984564f3 100644
> --- a/drivers/clk/qcom/Makefile
> +++ b/drivers/clk/qcom/Makefile
> @@ -229,6 +229,7 @@ obj-$(CONFIG_SM_VIDEOCC_8550) += videocc-sm8550.o
> obj-$(CONFIG_SM_VIDEOCC_8750) += videocc-sm8750.o
> obj-$(CONFIG_SM_VIDEOCC_MILOS) += videocc-milos.o
> obj-$(CONFIG_SPMI_PMIC_CLKDIV) += clk-spmi-pmic-div.o
> +obj-$(CONFIG_QCOM_CLK_GP_MND) += clk-gp-mnd.o
> obj-$(CONFIG_KPSS_XCC) += kpss-xcc.o
> obj-$(CONFIG_QCOM_HFPLL) += hfpll.o
> obj-$(CONFIG_KRAITCC) += krait-cc.o
> diff --git a/drivers/clk/qcom/clk-gp-mnd.c b/drivers/clk/qcom/clk-gp-mnd.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..75d620166e8dc044afb08d014f9707e9b53e8e31
> --- /dev/null
> +++ b/drivers/clk/qcom/clk-gp-mnd.c
> @@ -0,0 +1,342 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
> + */
> +
> +#include <linux/clk.h>
> +#include <linux/clk-provider.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/pm_clock.h>
> +#include <linux/pm_runtime.h>
> +#include <linux/rational.h>
> +#include <linux/regmap.h>
> +

[...]

> + ret = pm_clk_add(dev, "ahb");
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to get ahb clock\n");
> +
> + clk = devm_clk_get(dev, "pdm");
> + if (IS_ERR(clk))
> + return PTR_ERR(clk);
> +
> + /* Set default rate if not already configured */
> + if (!clk_get_rate(clk)) {
> + ret = clk_set_rate(clk, 19200000);
> + if (ret)
> + dev_warn(dev, "failed to set default pdm clock rate\n");
> + }

Why are we setting the parent clock rate from here ?

And then we just don't do anything with it.

I think this bypasses CCF clock tree and that's not good.

> +
> + base = devm_platform_ioremap_resource(pdev, 0);
> + if (IS_ERR(base))
> + return dev_err_probe(dev, PTR_ERR(base),
> + "failed to map PDM registers\n");
> +
> + gp->regmap = devm_regmap_init_mmio(dev, base, &gp_mnd_regmap_config);
> + if (IS_ERR(gp->regmap))
> + return dev_err_probe(dev, PTR_ERR(gp->regmap),
> + "failed to init regmap\n");
> +
> + gp->hw.init = &init;
> +
> + ret = devm_clk_hw_register(dev, &gp->hw);
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "failed to register gp_mnd clock\n");
> +
> + return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, &gp->hw);
> +}
> +

[...]