* [PATCH 0/3] pwm: qcom: add Shikra PWM controller
@ 2026-11-16 6:59 Taniya Das
2026-11-16 6:59 ` [PATCH 1/3] dt-bindings: " Taniya Das
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Taniya Das @ 2026-11-16 6:59 UTC (permalink / raw)
To: Uwe Kleine-König, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Taniya Das, Bjorn Andersson, Konrad Dybcio,
Abel Vesa
Cc: Ajit Pandey, Imran Shaik, Jagadeesh Kona, linux-arm-msm,
linux-pwm, devicetree, linux-kernel
Add support for the Pulse Width Modulation (PWM) controller found on
Qualcomm Shikra SoCs.
The controller exposes a shared output-enable register and up to ten
independently addressed PWM frame blocks, each modelled from its own
device-tree child node. The driver retains the shared AHB and PWM core
clocks while any output is active.
The series contains the device-tree binding, the driver, and the Shikra
SoC DTSI node describing the controller and its ten PWM frames.
This series depends on the GCC PWM XO512 source clock, which provides the
GCC_PWM0_XO512_CLK_SRC divider feeding the PWM core clock referenced by
the controller node:
https://lore.kernel.org/r/20261116-pwm_clocks_shikra-v1-0-55fc11501821@oss.qualcomm.com
---
Taniya Das (3):
dt-bindings: pwm: qcom: add Shikra PWM controller
pwm: qcom: add Shikra PWM controller support
arm64: dts: qcom: add Shikra PWM controller
.../devicetree/bindings/pwm/qcom,shikra-pwm.yaml | 127 ++++
arch/arm64/boot/dts/qcom/shikra.dtsi | 63 ++
drivers/pwm/Kconfig | 13 +
drivers/pwm/Makefile | 1 +
drivers/pwm/pwm-qcom.c | 685 +++++++++++++++++++++
5 files changed, 889 insertions(+)
---
base-commit: 84abb955b1015477aa11a96e2f3ac1b938b77f48
change-id: 20261116-pwm_qcom_shikra-a63526bfad29
prerequisite-message-id: <20261116-pwm_clocks_shikra-v1-0-55fc11501821@oss.qualcomm.com>
prerequisite-patch-id: 25c90a2ea712aecae7404104dcc83e1c79227b6c
prerequisite-patch-id: e4b3500eec0cf6bc98edc43780b2828c28445b5c
Best regards,
--
Taniya Das <taniya.das@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/3] dt-bindings: pwm: qcom: add Shikra PWM controller
2026-11-16 6:59 [PATCH 0/3] pwm: qcom: add Shikra PWM controller Taniya Das
@ 2026-11-16 6:59 ` Taniya Das
2026-11-16 7:22 ` sashiko-bot
2026-11-16 6:59 ` [PATCH 2/3] pwm: qcom: add Shikra PWM controller support Taniya Das
2026-11-16 6:59 ` [PATCH 3/3] arm64: dts: qcom: add Shikra PWM controller Taniya Das
2 siblings, 1 reply; 7+ messages in thread
From: Taniya Das @ 2026-11-16 6:59 UTC (permalink / raw)
To: Uwe Kleine-König, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Taniya Das, Bjorn Andersson, Konrad Dybcio,
Abel Vesa
Cc: Ajit Pandey, Imran Shaik, Jagadeesh Kona, linux-arm-msm,
linux-pwm, devicetree, linux-kernel
Document the Pulse Width Modulation (PWM) controller on Qualcomm Shikra
SoCs. The controller has a shared enable register, ten independently
addressed frame blocks, and shared AHB and PWM core clocks.
Describe the frame child-node address mapping and the consumer PWM
specifier needed to select each hardware frame.
Signed-off-by: Taniya Das <taniya.das@oss.qualcomm.com>
---
.../devicetree/bindings/pwm/qcom,shikra-pwm.yaml | 127 +++++++++++++++++++++
1 file changed, 127 insertions(+)
diff --git a/Documentation/devicetree/bindings/pwm/qcom,shikra-pwm.yaml b/Documentation/devicetree/bindings/pwm/qcom,shikra-pwm.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..d7f2bdab68f68b822fc93ecabd628ab53d408249
--- /dev/null
+++ b/Documentation/devicetree/bindings/pwm/qcom,shikra-pwm.yaml
@@ -0,0 +1,127 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pwm/qcom,shikra-pwm.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Shikra PWM controller
+
+maintainers:
+ - Taniya Das <taniya.das@oss.qualcomm.com>
+
+description: |
+ The Qualcomm PWM (Pulse Width Modulation) block on Shikra contains
+ up to 10 independent PWM frame channels. Each frame is a child node of
+ the PWM controller node and owns its own register range. All frames
+ share a single PWM core clock owned by the parent node. Child frame reg
+ properties use the parent SoC address space through an empty identity
+ ranges mapping.
+
+ The PWM source input clock, pwm_core, is given by:
+
+ F_PWM_CLK = 19.2 MHz / N
+
+ where N is an integer from 1 through 512. The output frequency range
+ for a given PWM source clock is:
+
+ f_out(max) = F_PWM_CLK / 2
+ f_out(min) = F_PWM_CLK / 65536
+
+allOf:
+ - $ref: pwm.yaml#
+
+properties:
+ compatible:
+ const: qcom,shikra-pwm
+
+ reg:
+ maxItems: 1
+
+ clocks:
+ items:
+ - description: AHB bus clock for the PWM block.
+ - description: Gate clock shared by every frame (pwm_core).
+
+ clock-names:
+ items:
+ - const: ahb
+ - const: core
+
+ "#pwm-cells":
+ const: 3
+
+ "#address-cells":
+ const: 2
+
+ "#size-cells":
+ const: 2
+
+ ranges: true
+
+patternProperties:
+ "^pwm@[0-9a-f]+$":
+ type: object
+ description: Per-frame PWM channel sub-node.
+
+ properties:
+ reg:
+ maxItems: 1
+ description: This frame's own absolute register range.
+
+ qcom,frame-index:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ description:
+ Hardware frame index within the PWM block. It is the PWM index
+ used in the first cell of a consumer PWM specifier and selects
+ the corresponding enable bit in PWM_TOPCTL0.
+ maximum: 9
+
+ required:
+ - reg
+ - qcom,frame-index
+
+ additionalProperties: false
+
+required:
+ - compatible
+ - reg
+ - clocks
+ - clock-names
+ - "#pwm-cells"
+ - "#address-cells"
+ - "#size-cells"
+ - ranges
+
+unevaluatedProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/clock/qcom,shikra-gcc.h>
+
+ / {
+ #address-cells = <2>;
+ #size-cells = <2>;
+
+ pwm: pwm@4700000 {
+ compatible = "qcom,shikra-pwm";
+ reg = <0x0 0x04700000 0x0 0x10>;
+ clocks = <&gcc GCC_PDM_AHB_CLK>, <&gcc GCC_PWM0_XO512_CLK>;
+ clock-names = "ahb", "core";
+ assigned-clocks = <&gcc GCC_PWM0_XO512_CLK>;
+ assigned-clock-rates = <9600000>;
+ #pwm-cells = <3>;
+ #address-cells = <2>;
+ #size-cells = <2>;
+ ranges;
+
+ pwm@4701000 {
+ reg = <0x0 0x04701000 0x0 0x1c>;
+ qcom,frame-index = <0>;
+ };
+
+ pwm@4702000 {
+ reg = <0x0 0x04702000 0x0 0x1c>;
+ qcom,frame-index = <1>;
+ };
+ };
+ };
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] pwm: qcom: add Shikra PWM controller support
2026-11-16 6:59 [PATCH 0/3] pwm: qcom: add Shikra PWM controller Taniya Das
2026-11-16 6:59 ` [PATCH 1/3] dt-bindings: " Taniya Das
@ 2026-11-16 6:59 ` Taniya Das
2026-11-16 7:29 ` sashiko-bot
2026-11-16 6:59 ` [PATCH 3/3] arm64: dts: qcom: add Shikra PWM controller Taniya Das
2 siblings, 1 reply; 7+ messages in thread
From: Taniya Das @ 2026-11-16 6:59 UTC (permalink / raw)
To: Uwe Kleine-König, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Taniya Das, Bjorn Andersson, Konrad Dybcio,
Abel Vesa
Cc: Ajit Pandey, Imran Shaik, Jagadeesh Kona, linux-arm-msm,
linux-pwm, devicetree, linux-kernel
Add support for the Pulse Width Modulation (PWM) controller on Qualcomm
Shikra SoCs.
The controller has a shared output-enable register and up to ten frame
blocks with independent configuration registers. Model each available
frame from its DT child node, and retain the shared AHB and PWM core
clocks while an output is active.
Signed-off-by: Taniya Das <taniya.das@oss.qualcomm.com>
---
drivers/pwm/Kconfig | 13 +
drivers/pwm/Makefile | 1 +
drivers/pwm/pwm-qcom.c | 685 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 699 insertions(+)
diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index aacd800687e7c98b2272ddb01447356349425032..ae229e922521e97d88610887da5ccb0f7433fbd3 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -566,6 +566,19 @@ config PWM_PXA
To compile this driver as a module, choose M here: the module
will be called pwm-pxa.
+config PWM_QCOM
+ tristate "Qualcomm PWM support"
+ depends on ARCH_QCOM || COMPILE_TEST
+ depends on COMMON_CLK && HAS_IOMEM && OF
+ select REGMAP_MMIO
+ help
+ PWM framework driver for the PWM block found on Qualcomm SoCs,
+ which supports multiple PWM frames. Each frame can be
+ configured independently of the others.
+
+ To compile this driver as a module, choose M here: the module will
+ be called pwm-qcom.
+
config PWM_RASPBERRYPI_POE
tristate "Raspberry Pi Firmware PoE Hat PWM support"
# Make sure not 'y' when RASPBERRYPI_FIRMWARE is 'm'. This can only
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile
index 7e2c34cc4f6a955b04edcdd08721264d0d477f2e..a7e0095b573448cb643b19f4da2e6f02ada4bc39 100644
--- a/drivers/pwm/Makefile
+++ b/drivers/pwm/Makefile
@@ -50,6 +50,7 @@ obj-$(CONFIG_PWM_NTXEC) += pwm-ntxec.o
obj-$(CONFIG_PWM_OMAP_DMTIMER) += pwm-omap-dmtimer.o
obj-$(CONFIG_PWM_PCA9685) += pwm-pca9685.o
obj-$(CONFIG_PWM_PXA) += pwm-pxa.o
+obj-$(CONFIG_PWM_QCOM) += pwm-qcom.o
obj-$(CONFIG_PWM_RASPBERRYPI_POE) += pwm-raspberrypi-poe.o
obj-$(CONFIG_PWM_RENESAS_RCAR) += pwm-rcar.o
obj-$(CONFIG_PWM_RENESAS_RZG2L_GPT) += pwm-rzg2l-gpt.o
diff --git a/drivers/pwm/pwm-qcom.c b/drivers/pwm/pwm-qcom.c
new file mode 100644
index 0000000000000000000000000000000000000000..9b15cdcaa5c76a3f2a9d7871b4e12d52cf89610a
--- /dev/null
+++ b/drivers/pwm/pwm-qcom.c
@@ -0,0 +1,685 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ */
+
+#include <linux/bitops.h>
+#include <linux/clk.h>
+#include <linux/math64.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/pwm.h>
+#include <linux/regmap.h>
+
+/* Offsets */
+#define PWM_TOPCTL0 0x0
+
+/* offsets per frame */
+#define PWM_CTL0 0x0
+#define PWM_CTL1 0x4
+#define PWM_CTL2 0x8
+#define PWM_CYC_CFG 0xc
+#define PWM_UPDATE 0x10
+#define PWM_RESET 0x18
+
+#define PWM_FRAME_POLARITY_BIT BIT(0)
+#define PWM_FRAME_ROLLOVER_CNT_BIT BIT(4)
+#define PWM_FRAME_RESET_BIT BIT(0)
+
+/* All per-frame 16-bit value fields (CYC_CFG, CTL1, CTL2). */
+#define PWM_FRAME_VAL_MASK GENMASK(15, 0)
+
+/*
+ * struct qcom_pwm_priv_data - per-compatible hardware description
+ * @max_channels: number of frames supported by this hardware variant.
+ * @pwm_reset_support: whether PWM_RESET is implemented, allowing the period
+ * to be changed after it has already been set once.
+ * @pwm_cnt_rollover: whether PWM_FRAME_ROLLOVER_CNT_BIT is implemented,
+ * needed so period changes don't get stuck waiting on the counter.
+ */
+struct qcom_pwm_priv_data {
+ unsigned int max_channels;
+ bool pwm_reset_support;
+ bool pwm_cnt_rollover;
+};
+
+/*
+ * struct qcom_pwm_frames - Information regarding per PWM frame
+ * @frame_id: Id number associated with each frame.
+ * @polarity: Current polarity of the particular frame.
+ * @regmap: regmap covering this frame's own register block. Each frame now
+ * owns its own "reg" range in DT, so registers are accessed at their
+ * plain offsets within this regmap instead of as an offset into a
+ * shared parent regmap.
+ * @current_period_ns: Current period of the particular frame.
+ * @current_duty_ns: Current duty cycle of the particular frame.
+ * @current_freq: Current frequency of frame.
+ * @freq_set: This bool flag is responsible for setting period once per frame.
+ * @frame_lock: mutex lock per frame.
+ * @cnt_rollover_en: This bool flag is used to set rollover bit per frame.
+ */
+struct qcom_pwm_frames {
+ u32 frame_id;
+ u32 polarity;
+ struct regmap *regmap;
+ u64 current_period_ns;
+ u64 current_duty_ns;
+ unsigned long current_freq;
+ bool is_enabled;
+ bool freq_set;
+ struct mutex frame_lock; /* PWM per frame lock */
+ bool cnt_rollover_en;
+};
+
+/*
+ * struct qcom_pwm_chip - Information regarding per PWM block
+ * @regmap: regmap of the shared PWM_TOPCTL0 enable register.
+ * @frames: structure for all frames of each PWM block.
+ * @priv_data: per-compatible hardware description.
+ * @ahb: AHB clock providing access to the PWM block.
+ * @core: shared clock providing the PWM frame rate.
+ * @lock: mutex lock per chip (enable/disable path).
+ * @num_frames: number of frames in each PWM block.
+ */
+struct qcom_pwm_chip {
+ struct regmap *regmap;
+ struct qcom_pwm_frames *frames;
+ const struct qcom_pwm_priv_data *priv_data;
+ struct clk *ahb;
+ struct clk *core;
+ /* This lock to be used for Enable/Disable as it is per PWM channel */
+ struct mutex lock;
+ u32 num_frames;
+};
+
+static inline struct qcom_pwm_chip *to_qcom_pwm_chip(struct pwm_chip *chip)
+{
+ return pwmchip_get_drvdata(chip);
+}
+
+static int qcom_pwm_clks_enable(struct qcom_pwm_chip *chip)
+{
+ int ret;
+
+ ret = clk_prepare_enable(chip->ahb);
+ if (ret)
+ return ret;
+
+ ret = clk_prepare_enable(chip->core);
+ if (ret)
+ clk_disable_unprepare(chip->ahb);
+
+ return ret;
+}
+
+static void qcom_pwm_clks_disable(struct qcom_pwm_chip *chip)
+{
+ clk_disable_unprepare(chip->core);
+ clk_disable_unprepare(chip->ahb);
+}
+
+static int qcom_pwm_calc_frequency(struct qcom_pwm_chip *chip,
+ u64 period_ns, unsigned long rate, u32 hw_idx)
+{
+ struct regmap *frame_regmap = chip->frames[hw_idx].regmap;
+ u64 cycles;
+ int ret;
+
+ /*
+ * PWM client can set the period only once if the HW version does
+ * not support reset functionality.
+ */
+ if (chip->frames[hw_idx].freq_set && !chip->priv_data->pwm_reset_support)
+ return 0;
+
+ /*
+ * Number of core-clock cycles in one PWM period. Round down so the
+ * implemented period never exceeds the requested one, as the PWM API
+ * requires. PWM_CYC_CFG holds (cycles - 1) in its low 16 bits, so
+ * cycles is bounded to [2, 65536], i.e. an output frequency from
+ * rate / 2 down to rate / 65536.
+ */
+ cycles = mul_u64_u64_div_u64(period_ns, rate, NSEC_PER_SEC);
+ if (cycles < 2 || cycles > 65536) {
+ dev_dbg(regmap_get_device(frame_regmap),
+ "period %llu ns out of range for rate %lu Hz\n",
+ period_ns, rate);
+ return -ERANGE;
+ }
+
+ ret = regmap_update_bits(frame_regmap, PWM_CYC_CFG,
+ PWM_FRAME_VAL_MASK, cycles - 1);
+ if (ret)
+ return ret;
+
+ chip->frames[hw_idx].current_freq = div64_ul(rate, cycles);
+ chip->frames[hw_idx].freq_set = true;
+ chip->frames[hw_idx].current_period_ns = period_ns;
+
+ return 0;
+}
+
+static int qcom_pwm_get_state(struct pwm_chip *pwm_chip, struct pwm_device *pwm,
+ struct pwm_state *state)
+{
+ struct qcom_pwm_chip *chip = to_qcom_pwm_chip(pwm_chip);
+ struct qcom_pwm_frames *frame = &chip->frames[pwm->hwpwm];
+ unsigned long rate;
+ u32 topctl, ctl0, ctl1, cyc_cfg, cycles;
+ int ret;
+
+ if (!frame->regmap)
+ return -ENODEV;
+
+ /* Both clocks are needed for register access. */
+ ret = qcom_pwm_clks_enable(chip);
+ if (ret)
+ return ret;
+
+ rate = clk_get_rate(chip->core);
+ if (!rate) {
+ ret = -EINVAL;
+ goto err_clks;
+ }
+
+ mutex_lock(&frame->frame_lock);
+
+ ret = regmap_read(chip->regmap, PWM_TOPCTL0, &topctl);
+ if (ret)
+ goto out;
+
+ ret = regmap_read(frame->regmap, PWM_CTL0, &ctl0);
+ if (ret)
+ goto out;
+
+ ret = regmap_read(frame->regmap, PWM_CTL1, &ctl1);
+ if (ret)
+ goto out;
+
+ ret = regmap_read(frame->regmap, PWM_CYC_CFG, &cyc_cfg);
+ if (ret)
+ goto out;
+
+ cycles = (cyc_cfg & PWM_FRAME_VAL_MASK) + 1;
+ state->enabled = !!(topctl & BIT(frame->frame_id));
+ state->polarity = (ctl0 & PWM_FRAME_POLARITY_BIT) ?
+ PWM_POLARITY_INVERSED : PWM_POLARITY_NORMAL;
+ /*
+ * Round up so re-applying the returned state reproduces the same
+ * register values, since qcom_pwm_config() rounds the period and duty
+ * cycle down.
+ */
+ state->period = DIV_ROUND_UP_ULL((u64)cycles * NSEC_PER_SEC, rate);
+ state->duty_cycle = DIV_ROUND_UP_ULL((u64)(ctl1 & PWM_FRAME_VAL_MASK) *
+ NSEC_PER_SEC, rate);
+out:
+ mutex_unlock(&frame->frame_lock);
+err_clks:
+ qcom_pwm_clks_disable(chip);
+
+ return ret;
+}
+
+static int qcom_pwm_config(struct qcom_pwm_chip *chip,
+ u32 hw_idx, u64 duty_ns, u64 period_ns, int polarity)
+{
+ struct regmap *frame_regmap = chip->frames[hw_idx].regmap;
+ u64 ctl1, duty_percent;
+ unsigned long rate;
+ u64 current_period = period_ns;
+ bool clks_enabled = false;
+ int ret;
+ u32 cyc_cfg;
+
+ mutex_lock(&chip->frames[hw_idx].frame_lock);
+
+ if (!chip->frames[hw_idx].is_enabled) {
+ ret = qcom_pwm_clks_enable(chip);
+ if (ret)
+ goto err_unlock;
+ clks_enabled = true;
+ }
+
+ rate = clk_get_rate(chip->core);
+ if (!rate) {
+ ret = -EINVAL;
+ goto out;
+ }
+
+ /*
+ * Set the counter rollover enable bit, so that counter doesn't get stuck
+ * in period change configuration.
+ */
+ if (chip->priv_data->pwm_cnt_rollover && !chip->frames[hw_idx].cnt_rollover_en) {
+ ret = regmap_update_bits(frame_regmap, PWM_CTL0,
+ PWM_FRAME_ROLLOVER_CNT_BIT,
+ PWM_FRAME_ROLLOVER_CNT_BIT);
+ if (ret)
+ goto out;
+
+ chip->frames[hw_idx].cnt_rollover_en = true;
+ }
+
+ if (chip->frames[hw_idx].freq_set &&
+ chip->frames[hw_idx].current_period_ns != period_ns) {
+ if (chip->priv_data->pwm_reset_support) {
+ ret = regmap_update_bits(frame_regmap, PWM_RESET,
+ PWM_FRAME_RESET_BIT,
+ PWM_FRAME_RESET_BIT);
+ if (ret)
+ goto out;
+ } else {
+ ret = -EINVAL;
+ goto out;
+ }
+ }
+
+ ret = qcom_pwm_calc_frequency(chip, current_period, rate, hw_idx);
+ if (ret)
+ goto out;
+
+ if (chip->frames[hw_idx].polarity != polarity) {
+ ret = regmap_update_bits(frame_regmap, PWM_CTL0,
+ PWM_FRAME_POLARITY_BIT, polarity);
+ if (ret)
+ goto out;
+
+ chip->frames[hw_idx].polarity = polarity;
+ }
+
+ ctl1 = DIV_ROUND_CLOSEST(rate, chip->frames[hw_idx].current_freq);
+ duty_percent = mul_u64_add_u64_div_u64(duty_ns, 100, current_period / 2, current_period);
+ ctl1 = mul_u64_add_u64_div_u64(ctl1, duty_percent, 50, 100);
+
+ ret = regmap_read(frame_regmap, PWM_CYC_CFG, &cyc_cfg);
+ if (ret)
+ goto out;
+
+ if ((ctl1 > cyc_cfg || ctl1 == 0) && duty_ns != 0) {
+ dev_err(regmap_get_device(frame_regmap),
+ "duty cycle out of valid range\n");
+ ret = -ERANGE;
+ goto out;
+ }
+
+ ret = regmap_update_bits(frame_regmap, PWM_CTL2, PWM_FRAME_VAL_MASK, 0);
+ if (ret)
+ goto out;
+
+ ret = regmap_update_bits(frame_regmap, PWM_CTL1, PWM_FRAME_VAL_MASK, ctl1);
+ if (ret)
+ goto out;
+
+ ret = regmap_update_bits(frame_regmap, PWM_UPDATE, BIT(0), 1);
+ if (ret)
+ goto out;
+
+ chip->frames[hw_idx].current_duty_ns = duty_ns;
+out:
+ if (clks_enabled)
+ qcom_pwm_clks_disable(chip);
+err_unlock:
+ mutex_unlock(&chip->frames[hw_idx].frame_lock);
+
+ return ret;
+}
+
+static int qcom_pwm_enable(struct qcom_pwm_chip *chip,
+ struct pwm_device *pwm)
+{
+ struct device *dev = regmap_get_device(chip->regmap);
+ int ret;
+ u32 val, hw_idx = pwm->hwpwm;
+
+ ret = qcom_pwm_clks_enable(chip);
+ if (ret)
+ return ret;
+
+ mutex_lock(&chip->lock);
+
+ dev_dbg(dev, "enable: hw_idx=%u frame_id=%u\n",
+ hw_idx, chip->frames[hw_idx].frame_id);
+
+ val = BIT(chip->frames[hw_idx].frame_id);
+ ret = regmap_update_bits(chip->regmap, PWM_TOPCTL0, val, val);
+ if (!ret)
+ chip->frames[hw_idx].is_enabled = true;
+
+ mutex_unlock(&chip->lock);
+
+ if (ret)
+ goto err_clks;
+
+ return 0;
+
+err_clks:
+ qcom_pwm_clks_disable(chip);
+ return ret;
+}
+
+static int qcom_pwm_disable(struct qcom_pwm_chip *chip,
+ struct pwm_device *pwm)
+{
+ struct device *dev = regmap_get_device(chip->regmap);
+ u32 val, hw_idx = pwm->hwpwm;
+ int ret;
+
+ mutex_lock(&chip->lock);
+
+ dev_dbg(dev, "disable: hw_idx=%u\n", hw_idx);
+
+ val = BIT(chip->frames[hw_idx].frame_id);
+ ret = regmap_update_bits(chip->regmap, PWM_TOPCTL0, val, 0);
+ if (!ret)
+ chip->frames[hw_idx].is_enabled = false;
+
+ mutex_unlock(&chip->lock);
+
+ if (ret)
+ return ret;
+
+ qcom_pwm_clks_disable(chip);
+
+ return 0;
+}
+
+static int qcom_pwm_apply(struct pwm_chip *pwm_chip, struct pwm_device *pwm,
+ const struct pwm_state *state)
+{
+ struct qcom_pwm_chip *chip = to_qcom_pwm_chip(pwm_chip);
+ struct pwm_state curr_state;
+ u32 hw_idx = pwm->hwpwm;
+ int ret;
+
+ pwm_get_state(pwm, &curr_state);
+
+ if (state->period &&
+ (state->period != curr_state.period ||
+ state->duty_cycle != curr_state.duty_cycle ||
+ state->polarity != curr_state.polarity)) {
+ ret = qcom_pwm_config(chip, hw_idx, state->duty_cycle,
+ state->period, state->polarity);
+ if (ret) {
+ dev_err(pwmchip_parent(pwm_chip),
+ "failed to update PWM configuration\n");
+ return ret;
+ }
+ }
+
+ if (state->enabled != curr_state.enabled) {
+ if (state->enabled)
+ return qcom_pwm_enable(chip, pwm);
+
+ ret = qcom_pwm_disable(chip, pwm);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int qcom_pwm_request(struct pwm_chip *pwm_chip, struct pwm_device *pwm)
+{
+ struct qcom_pwm_chip *chip = to_qcom_pwm_chip(pwm_chip);
+
+ if (!chip->frames[pwm->hwpwm].regmap)
+ return -ENODEV;
+
+ return 0;
+}
+
+/*
+ * Reset the software state and the frame's own registers (the same
+ * PWM_CTL0/PWM_CTL1/PWM_CYC_CFG registers qcom_pwm_get_state() reads back)
+ * to their power-on defaults, and disable an active PWM frame.
+ */
+static void qcom_pwm_free(struct pwm_chip *pwm_chip, struct pwm_device *pwm)
+{
+ struct qcom_pwm_chip *chip = to_qcom_pwm_chip(pwm_chip);
+ struct qcom_pwm_frames *frame = &chip->frames[pwm->hwpwm];
+ bool enabled;
+ int ret;
+
+ mutex_lock(&chip->lock);
+ enabled = frame->is_enabled;
+ mutex_unlock(&chip->lock);
+
+ if (enabled) {
+ ret = qcom_pwm_disable(chip, pwm);
+ if (ret) {
+ dev_err(pwmchip_parent(pwm_chip),
+ "failed to disable PWM on free\n");
+ return;
+ }
+ }
+
+ ret = qcom_pwm_clks_enable(chip);
+ if (ret) {
+ dev_err(pwmchip_parent(pwm_chip),
+ "failed to enable clocks on free\n");
+ return;
+ }
+
+ mutex_lock(&frame->frame_lock);
+
+ ret = regmap_update_bits(frame->regmap, PWM_CTL0,
+ PWM_FRAME_POLARITY_BIT | PWM_FRAME_ROLLOVER_CNT_BIT, 0);
+ if (ret)
+ goto out;
+
+ ret = regmap_update_bits(frame->regmap, PWM_CTL1, PWM_FRAME_VAL_MASK, 0);
+ if (ret)
+ goto out;
+
+ ret = regmap_update_bits(frame->regmap, PWM_CTL2, PWM_FRAME_VAL_MASK, 0);
+ if (ret)
+ goto out;
+
+ ret = regmap_update_bits(frame->regmap, PWM_CYC_CFG, PWM_FRAME_VAL_MASK, 0);
+ if (ret)
+ goto out;
+
+ ret = regmap_update_bits(frame->regmap, PWM_UPDATE, BIT(0), 1);
+ if (ret)
+ goto out;
+
+ if (chip->priv_data->pwm_reset_support) {
+ ret = regmap_update_bits(frame->regmap, PWM_RESET,
+ PWM_FRAME_RESET_BIT, PWM_FRAME_RESET_BIT);
+ if (ret)
+ goto out;
+ }
+
+ frame->freq_set = false;
+ frame->current_period_ns = 0;
+ frame->current_duty_ns = 0;
+ frame->current_freq = 0;
+ frame->polarity = 0;
+ frame->cnt_rollover_en = false;
+out:
+ mutex_unlock(&frame->frame_lock);
+ qcom_pwm_clks_disable(chip);
+
+ if (ret)
+ dev_err(pwmchip_parent(pwm_chip),
+ "failed to reset PWM registers on free\n");
+}
+
+static const struct pwm_ops qcom_pwm_ops = {
+ .request = qcom_pwm_request,
+ .apply = qcom_pwm_apply,
+ .free = qcom_pwm_free,
+ .get_state = qcom_pwm_get_state,
+};
+
+static const struct regmap_config pwm_regmap_config = {
+ .reg_bits = 32,
+ .reg_stride = 4,
+ .val_bits = 32,
+ .fast_io = true,
+};
+
+static int qcom_pwm_parse_dt(struct platform_device *pdev,
+ struct pwm_chip *pwm_chip,
+ struct qcom_pwm_chip *chip)
+{
+ struct device *dev = pwmchip_parent(pwm_chip);
+ struct device_node *np = pdev->dev.of_node;
+ struct device_node *frame_node;
+ void __iomem *base;
+ unsigned long frame_ids = 0;
+ int ret;
+
+ base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(base))
+ return PTR_ERR(base);
+
+ chip->regmap = devm_regmap_init_mmio(dev, base, &pwm_regmap_config);
+ if (IS_ERR(chip->regmap))
+ return dev_err_probe(dev, PTR_ERR(chip->regmap),
+ "failed to initialise regmap\n");
+
+ chip->ahb = devm_clk_get(dev, "ahb");
+ if (IS_ERR(chip->ahb))
+ return dev_err_probe(dev, PTR_ERR(chip->ahb),
+ "failed to get ahb clock\n");
+
+ chip->core = devm_clk_get(dev, "core");
+ if (IS_ERR(chip->core))
+ return dev_err_probe(dev, PTR_ERR(chip->core),
+ "failed to get core clock\n");
+
+ chip->frames = devm_kcalloc(dev, chip->num_frames,
+ sizeof(*chip->frames), GFP_KERNEL);
+ if (!chip->frames)
+ return -ENOMEM;
+
+ for_each_available_child_of_node(np, frame_node) {
+ u32 n;
+ struct resource res;
+
+ if (of_property_read_u32(frame_node, "qcom,frame-index", &n)) {
+ of_node_put(frame_node);
+ return dev_err_probe(dev, -EINVAL,
+ "missing qcom,frame-index property in DT node\n");
+ }
+
+ if (n >= chip->priv_data->max_channels) {
+ of_node_put(frame_node);
+ return dev_err_probe(dev, -EINVAL,
+ "invalid qcom,frame-index %u\n", n);
+ }
+
+ if (test_and_set_bit(n, &frame_ids)) {
+ of_node_put(frame_node);
+ return dev_err_probe(dev, -EINVAL,
+ "duplicate qcom,frame-index %u\n", n);
+ }
+
+ chip->frames[n].frame_id = n;
+
+ ret = of_address_to_resource(frame_node, 0, &res);
+ if (ret) {
+ of_node_put(frame_node);
+ return dev_err_probe(dev, ret,
+ "failed to get frame-%u resource\n", n);
+ }
+
+ base = devm_ioremap_resource(dev, &res);
+ if (IS_ERR(base)) {
+ of_node_put(frame_node);
+ return PTR_ERR(base);
+ }
+
+ chip->frames[n].regmap =
+ devm_regmap_init_mmio(dev, base, &pwm_regmap_config);
+ if (IS_ERR(chip->frames[n].regmap)) {
+ of_node_put(frame_node);
+ return dev_err_probe(dev, PTR_ERR(chip->frames[n].regmap),
+ "failed to initialise frame regmap\n");
+ }
+
+ mutex_init(&chip->frames[n].frame_lock);
+ }
+
+ /* The hardware requires all PWM outputs to be disabled at probe. */
+ ret = qcom_pwm_clks_enable(chip);
+ if (ret)
+ return ret;
+
+ ret = regmap_update_bits(chip->regmap, PWM_TOPCTL0,
+ GENMASK(chip->priv_data->max_channels - 1, 0), 0);
+
+ qcom_pwm_clks_disable(chip);
+
+ return ret;
+}
+
+static const struct qcom_pwm_priv_data shikra_pwm_data = {
+ .max_channels = 10,
+};
+
+static const struct of_device_id qcom_pwm_of_match[] = {
+ { .compatible = "qcom,shikra-pwm", .data = &shikra_pwm_data },
+ { },
+};
+MODULE_DEVICE_TABLE(of, qcom_pwm_of_match);
+
+static int qcom_pwm_probe(struct platform_device *pdev)
+{
+ struct pwm_chip *pwm_chip;
+ struct qcom_pwm_chip *chip;
+ const struct qcom_pwm_priv_data *priv;
+ struct device_node *np = pdev->dev.of_node;
+ u32 child_count;
+ int rc;
+
+ priv = of_device_get_match_data(&pdev->dev);
+ if (!priv)
+ return -EINVAL;
+
+ /* At least one available frame resource must be described. */
+ child_count = of_get_available_child_count(np);
+ if (!child_count)
+ return dev_err_probe(&pdev->dev, -EINVAL,
+ "at least one PWM frame must be described\n");
+
+ pwm_chip = devm_pwmchip_alloc(&pdev->dev, priv->max_channels, sizeof(*chip));
+ if (IS_ERR(pwm_chip))
+ return PTR_ERR(pwm_chip);
+
+ chip = to_qcom_pwm_chip(pwm_chip);
+ chip->priv_data = priv;
+ chip->num_frames = priv->max_channels;
+ mutex_init(&chip->lock);
+
+ pwm_chip->ops = &qcom_pwm_ops;
+
+ rc = qcom_pwm_parse_dt(pdev, pwm_chip, chip);
+ if (rc)
+ return rc;
+
+ rc = devm_pwmchip_add(&pdev->dev, pwm_chip);
+ if (rc)
+ return rc;
+
+ return 0;
+}
+
+static struct platform_driver qcom_pwm_driver = {
+ .driver = {
+ .name = "qcom-pwm",
+ .of_match_table = qcom_pwm_of_match,
+ },
+ .probe = qcom_pwm_probe,
+};
+
+module_platform_driver(qcom_pwm_driver);
+
+MODULE_DESCRIPTION("Qualcomm PWM driver");
+MODULE_LICENSE("GPL");
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] arm64: dts: qcom: add Shikra PWM controller
2026-11-16 6:59 [PATCH 0/3] pwm: qcom: add Shikra PWM controller Taniya Das
2026-11-16 6:59 ` [PATCH 1/3] dt-bindings: " Taniya Das
2026-11-16 6:59 ` [PATCH 2/3] pwm: qcom: add Shikra PWM controller support Taniya Das
@ 2026-11-16 6:59 ` Taniya Das
2026-11-16 7:32 ` sashiko-bot
2 siblings, 1 reply; 7+ messages in thread
From: Taniya Das @ 2026-11-16 6:59 UTC (permalink / raw)
To: Uwe Kleine-König, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Taniya Das, Bjorn Andersson, Konrad Dybcio,
Abel Vesa
Cc: Ajit Pandey, Imran Shaik, Jagadeesh Kona, linux-arm-msm,
linux-pwm, devicetree, linux-kernel
Add the PWM controller node with its AHB and core clocks and the ten
PWM frame child nodes to the Shikra SoC DTSI. Assign the shared PWM
core clock a rate of 9.6MHz.
Signed-off-by: Taniya Das <taniya.das@oss.qualcomm.com>
---
arch/arm64/boot/dts/qcom/shikra.dtsi | 63 ++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/arch/arm64/boot/dts/qcom/shikra.dtsi b/arch/arm64/boot/dts/qcom/shikra.dtsi
index 0a95ad5a5582c643f97e2b0725eb88a9f262d83c..d8a3de38382bdb00684acd709f4d34136792771c 100644
--- a/arch/arm64/boot/dts/qcom/shikra.dtsi
+++ b/arch/arm64/boot/dts/qcom/shikra.dtsi
@@ -1303,6 +1303,69 @@ sram@4690000 {
reg = <0x0 0x04690000 0x0 0x14000>;
};
+ pwm: pwm@4700000 {
+ compatible = "qcom,shikra-pwm";
+ reg = <0x0 0x04700000 0x0 0x10>;
+ clocks = <&gcc GCC_PDM_AHB_CLK>, <&gcc GCC_PWM0_XO512_CLK>;
+ clock-names = "ahb", "core";
+ assigned-clocks = <&gcc GCC_PWM0_XO512_CLK>;
+ assigned-clock-rates = <9600000>;
+ #pwm-cells = <3>;
+ #address-cells = <2>;
+ #size-cells = <2>;
+ ranges;
+
+ pwm@4701000 {
+ reg = <0x0 0x04701000 0x0 0x1c>;
+ qcom,frame-index = <0>;
+ };
+
+ pwm@4702000 {
+ reg = <0x0 0x04702000 0x0 0x1c>;
+ qcom,frame-index = <1>;
+ };
+
+ pwm@4703000 {
+ reg = <0x0 0x04703000 0x0 0x1c>;
+ qcom,frame-index = <2>;
+ };
+
+ pwm@4704000 {
+ reg = <0x0 0x04704000 0x0 0x1c>;
+ qcom,frame-index = <3>;
+ };
+
+ pwm@4705000 {
+ reg = <0x0 0x04705000 0x0 0x1c>;
+ qcom,frame-index = <4>;
+ };
+
+ pwm@4706000 {
+ reg = <0x0 0x04706000 0x0 0x1c>;
+ qcom,frame-index = <5>;
+ };
+
+ pwm@4707000 {
+ reg = <0x0 0x04707000 0x0 0x1c>;
+ qcom,frame-index = <6>;
+ };
+
+ pwm@4708000 {
+ reg = <0x0 0x04708000 0x0 0x1c>;
+ qcom,frame-index = <7>;
+ };
+
+ pwm@4709000 {
+ reg = <0x0 0x04709000 0x0 0x1c>;
+ qcom,frame-index = <8>;
+ };
+
+ pwm@470a000 {
+ reg = <0x0 0x0470a000 0x0 0x1c>;
+ qcom,frame-index = <9>;
+ };
+ };
+
sdhc_1: mmc@4744000 {
compatible = "qcom,shikra-sdhci", "qcom,sdhci-msm-v5";
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] dt-bindings: pwm: qcom: add Shikra PWM controller
2026-11-16 6:59 ` [PATCH 1/3] dt-bindings: " Taniya Das
@ 2026-11-16 7:22 ` sashiko-bot
0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-16 7:22 UTC (permalink / raw)
To: Taniya Das; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] dt-bindings: pwm: qcom: ranges property out of canonical order
- [Low] dt-bindings: pwm: qcom: unused pwm node label in binding example
--
commit e6638c1381c339afe2578e824d79ad21eb5519c9
Author: Taniya Das <taniya.das@oss.qualcomm.com>
dt-bindings: pwm: qcom: add Shikra PWM controller
This commit adds the Device Tree binding schema for the Qualcomm Shikra
PWM controller and its per-frame channel child nodes.
> diff --git a/Documentation/devicetree/bindings/pwm/qcom,shikra-pwm.yaml b/Documentation/devicetree/bindings/pwm/qcom,shikra-pwm.yaml
> new file mode 100644
> index 0000000000000..d7f2bdab68f68
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/pwm/qcom,shikra-pwm.yaml
[ ... ]
> +properties:
> + compatible:
> + const: qcom,shikra-pwm
> +
> + reg:
> + maxItems: 1
> +
> + clocks:
> + items:
> + - description: AHB bus clock for the PWM block.
> + - description: Gate clock shared by every frame (pwm_core).
> +
> + clock-names:
> + items:
> + - const: ahb
> + - const: core
> +
> + "#pwm-cells":
> + const: 3
> +
> + "#address-cells":
> + const: 2
> +
> + "#size-cells":
> + const: 2
> +
> + ranges: true
[ ... ]
> +required:
> + - compatible
> + - reg
> + - clocks
> + - clock-names
> + - "#pwm-cells"
> + - "#address-cells"
> + - "#size-cells"
> + - ranges
> +
> +unevaluatedProperties: false
> +
> +examples:
> + - |
> + #include <dt-bindings/clock/qcom,shikra-gcc.h>
> +
> + / {
> + #address-cells = <2>;
> + #size-cells = <2>;
> +
> + pwm: pwm@4700000 {
[Severity: Low]
Should the unused pwm label on pwm@4700000 be dropped? Because &pwm is
never referenced in the example, scripts/dtc/dt-check-style --mode=strict
reports an [unused-labels] warning.
> + compatible = "qcom,shikra-pwm";
> + reg = <0x0 0x04700000 0x0 0x10>;
> + clocks = <&gcc GCC_PDM_AHB_CLK>, <&gcc GCC_PWM0_XO512_CLK>;
> + clock-names = "ahb", "core";
> + assigned-clocks = <&gcc GCC_PWM0_XO512_CLK>;
> + assigned-clock-rates = <9600000>;
> + #pwm-cells = <3>;
> + #address-cells = <2>;
> + #size-cells = <2>;
> + ranges;
[Severity: Low]
Should ranges be placed immediately after reg in the pwm@4700000 example
node, properties, and required? Putting ranges after #size-cells
deviates from the canonical DT property ordering and causes
scripts/dtc/dt-check-style --mode=strict to report a [property-order]
warning.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-pwm_qcom_shikra-v1-0-67ee4553adc5@oss.qualcomm.com?part=1
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] pwm: qcom: add Shikra PWM controller support
2026-11-16 6:59 ` [PATCH 2/3] pwm: qcom: add Shikra PWM controller support Taniya Das
@ 2026-11-16 7:29 ` sashiko-bot
0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-16 7:29 UTC (permalink / raw)
To: Taniya Das; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] pwm: qcom: division by zero in qcom_pwm_config() when cycles >
rate
- [High] pwm: qcom: broken duty-cycle math and -ERANGE check in
qcom_pwm_config()
- [High] pwm: qcom: qcom_pwm_apply() runs qcom_pwm_config() when
!state->enabled
- [Medium] pwm: qcom: unrounded current_period_ns check in
qcom_pwm_config() fails
- [Medium] pwm: qcom: desynchronized software state in qcom_pwm_apply()
and config
- [Medium] pwm: qcom: partial state mutation before validation in
qcom_pwm_config()
- [Low] pwm: qcom: unnamed regmap_config collision in
qcom_pwm_parse_dt()
--
commit 06e62578a3838a59f7adc59ac3054518eb4e4082
Author: Taniya Das <taniya.das@oss.qualcomm.com>
pwm: qcom: add Shikra PWM controller support
This commit adds a PWM controller driver for Qualcomm Shikra SoCs, modeling
up to ten independent PWM frames from DT child nodes with a shared
output-enable register and shared AHB and core clocks.
> diff --git a/drivers/pwm/pwm-qcom.c b/drivers/pwm/pwm-qcom.c
> new file mode 100644
> index 0000000000000..9b15cdcaa5c76
> --- /dev/null
> +++ b/drivers/pwm/pwm-qcom.c
[ ... ]
> +static int qcom_pwm_calc_frequency(struct qcom_pwm_chip *chip,
> + u64 period_ns, unsigned long rate, u32 hw_idx)
> +{
> + struct regmap *frame_regmap = chip->frames[hw_idx].regmap;
> + u64 cycles;
> + int ret;
> +
> + /*
> + * PWM client can set the period only once if the HW version does
> + * not support reset functionality.
> + */
> + if (chip->frames[hw_idx].freq_set && !chip->priv_data->pwm_reset_support)
> + return 0;
> +
> + /*
> + * Number of core-clock cycles in one PWM period. Round down so the
> + * implemented period never exceeds the requested one, as the PWM API
> + * requires. PWM_CYC_CFG holds (cycles - 1) in its low 16 bits, so
> + * cycles is bounded to [2, 65536], i.e. an output frequency from
> + * rate / 2 down to rate / 65536.
> + */
> + cycles = mul_u64_u64_div_u64(period_ns, rate, NSEC_PER_SEC);
> + if (cycles < 2 || cycles > 65536) {
> + dev_dbg(regmap_get_device(frame_regmap),
> + "period %llu ns out of range for rate %lu Hz\n",
> + period_ns, rate);
> + return -ERANGE;
> + }
> +
> + ret = regmap_update_bits(frame_regmap, PWM_CYC_CFG,
> + PWM_FRAME_VAL_MASK, cycles - 1);
> + if (ret)
> + return ret;
> +
> + chip->frames[hw_idx].current_freq = div64_ul(rate, cycles);
> + chip->frames[hw_idx].freq_set = true;
> + chip->frames[hw_idx].current_period_ns = period_ns;
> +
> + return 0;
> +}
[ ... ]
> +static int qcom_pwm_config(struct qcom_pwm_chip *chip,
> + u32 hw_idx, u64 duty_ns, u64 period_ns, int polarity)
> +{
[ ... ]
> + if (chip->frames[hw_idx].freq_set &&
> + chip->frames[hw_idx].current_period_ns != period_ns) {
> + if (chip->priv_data->pwm_reset_support) {
> + ret = regmap_update_bits(frame_regmap, PWM_RESET,
> + PWM_FRAME_RESET_BIT,
> + PWM_FRAME_RESET_BIT);
> + if (ret)
> + goto out;
> + } else {
> + ret = -EINVAL;
> + goto out;
> + }
> + }
[Severity: Medium]
Does comparing against the unrounded current_period_ns cause re-applying the
state returned by qcom_pwm_get_state() to fail with -EINVAL on
qcom,shikra-pwm?
qcom_pwm_calc_frequency() rounds cycles down and stores the caller's
unrounded period_ns in current_period_ns, whereas qcom_pwm_get_state()
returns the hardware period rounded up from cycles. Because shikra_pwm_data
leaves pwm_reset_support false, re-applying the state read back from
qcom_pwm_get_state() (for example in pwm_apply_debug() or a consumer
read-modify-write update) sees period_ns != current_period_ns and returns
-EINVAL even though both periods map to the same cycle count.
> +
> + ret = qcom_pwm_calc_frequency(chip, current_period, rate, hw_idx);
> + if (ret)
> + goto out;
> +
> + if (chip->frames[hw_idx].polarity != polarity) {
> + ret = regmap_update_bits(frame_regmap, PWM_CTL0,
> + PWM_FRAME_POLARITY_BIT, polarity);
> + if (ret)
> + goto out;
> +
> + chip->frames[hw_idx].polarity = polarity;
> + }
> +
> + ctl1 = DIV_ROUND_CLOSEST(rate, chip->frames[hw_idx].current_freq);
[Severity: High]
Can this divide by zero when cycles > rate?
When the core clock is divided below 65536 Hz (down to 37.5 kHz on Shikra)
and a valid period longer than one second is requested (rate < cycles <=
65536), div64_ul(rate, cycles) in qcom_pwm_calc_frequency() truncates
current_freq to 0, and DIV_ROUND_CLOSEST(rate, current_freq) divides by zero.
Even when cycles <= rate, round-tripping through an integer current_freq
loses cycle-count precision compared to using cycles directly.
> + duty_percent = mul_u64_add_u64_div_u64(duty_ns, 100, current_period / 2, current_period);
> + ctl1 = mul_u64_add_u64_div_u64(ctl1, duty_percent, 50, 100);
> +
> + ret = regmap_read(frame_regmap, PWM_CYC_CFG, &cyc_cfg);
> + if (ret)
> + goto out;
> +
> + if ((ctl1 > cyc_cfg || ctl1 == 0) && duty_ns != 0) {
> + dev_err(regmap_get_device(frame_regmap),
> + "duty cycle out of valid range\n");
> + ret = -ERANGE;
> + goto out;
> + }
[Severity: High]
Does this calculation reject valid 100% and < 0.5% duty cycles with -ERANGE
and quantize PWM_CTL1 to integer percentages?
PWM_CYC_CFG stores cycles - 1, so when duty_ns == period_ns (or >= 99.5% of
period_ns), duty_percent rounds to 100 and ctl1 becomes cycles (cyc_cfg + 1),
tripping ctl1 > cyc_cfg. When 0 < duty_ns < 0.5% of period_ns, duty_percent
rounds to 0 and ctl1 == 0 with duty_ns != 0 also returns -ERANGE instead of
programming the cycle count or rounding down to 0. Quantizing through a
rounded 0..100 percentage also discards the 16-bit counter resolution of
PWM_CTL1 and rounds duty_cycle up, contrary to the PWM framework contract and
the comment in qcom_pwm_get_state().
[Severity: Medium]
If the ctl1 range check above fails, does qcom_pwm_config() leave hardware
registers and per-frame state partially updated?
qcom_pwm_calc_frequency() has already written PWM_CYC_CFG and set
freq_set = true and current_period_ns, and the polarity block has already
updated PWM_CTL0 and frame->polarity, while __pwm_apply() leaves pwm->state
unchanged on error. On qcom,shikra-pwm (!pwm_reset_support), an initial
apply that fails the ctl1 check leaves freq_set true for the failed period,
causing subsequent apply calls with any other period to fail with -EINVAL.
[ ... ]
> +static int qcom_pwm_apply(struct pwm_chip *pwm_chip, struct pwm_device *pwm,
> + const struct pwm_state *state)
> +{
> + struct qcom_pwm_chip *chip = to_qcom_pwm_chip(pwm_chip);
> + struct pwm_state curr_state;
> + u32 hw_idx = pwm->hwpwm;
> + int ret;
> +
> + pwm_get_state(pwm, &curr_state);
> +
> + if (state->period &&
> + (state->period != curr_state.period ||
> + state->duty_cycle != curr_state.duty_cycle ||
> + state->polarity != curr_state.polarity)) {
> + ret = qcom_pwm_config(chip, hw_idx, state->duty_cycle,
> + state->period, state->polarity);
> + if (ret) {
> + dev_err(pwmchip_parent(pwm_chip),
> + "failed to update PWM configuration\n");
> + return ret;
> + }
> + }
[Severity: High]
Should qcom_pwm_apply() skip qcom_pwm_config() when !state->enabled?
When disabling an active PWM, running qcom_pwm_config() first can fail (for
example with -EINVAL if state->period changed on Shikra, or -ERANGE) and
return before qcom_pwm_disable() is reached, leaving the output active and
its ahb and core clocks enabled. When a channel is exported via sysfs while
disabled, qcom_pwm_get_state() initializes pwm->state.period from the reset
default PWM_CYC_CFG == 0 (1 clock cycle), so writing duty_cycle or polarity
before period calls qcom_pwm_config() with a 1-cycle period and fails with
-ERANGE, while writing period while disabled sets freq_set = true and locks
the period before the channel is ever enabled.
> +
> + if (state->enabled != curr_state.enabled) {
> + if (state->enabled)
> + return qcom_pwm_enable(chip, pwm);
> +
> + ret = qcom_pwm_disable(chip, pwm);
> + if (ret)
> + return ret;
> + }
> +
> + return 0;
> +}
[Severity: Medium]
Can comparing against curr_state (pwm->state) and frame->polarity skip
necessary hardware updates or disable clocks twice?
When a channel is first requested, pwm_device_request() populates pwm->state
from qcom_pwm_get_state() while frame->freq_set remains false; if a consumer
then enables the channel with those same period, duty_cycle, and polarity
values, qcom_pwm_apply() sees no change from curr_state, skips
qcom_pwm_config(), and enables an unconfigured frame. Similarly,
frame->polarity is initialized to 0 rather than read from PWM_CTL0, so
qcom_pwm_config() will not clear PWM_FRAME_POLARITY_BIT if it was set prior
to probe and PWM_POLARITY_NORMAL is requested.
[ ... ]
> +static const struct regmap_config pwm_regmap_config = {
> + .reg_bits = 32,
> + .reg_stride = 4,
> + .val_bits = 32,
> + .fast_io = true,
> +};
> +
> +static int qcom_pwm_parse_dt(struct platform_device *pdev,
> + struct pwm_chip *pwm_chip,
> + struct qcom_pwm_chip *chip)
> +{
> + struct device *dev = pwmchip_parent(pwm_chip);
> + struct device_node *np = pdev->dev.of_node;
> + struct device_node *frame_node;
> + void __iomem *base;
> + unsigned long frame_ids = 0;
> + int ret;
> +
> + base = devm_platform_ioremap_resource(pdev, 0);
> + if (IS_ERR(base))
> + return PTR_ERR(base);
> +
> + chip->regmap = devm_regmap_init_mmio(dev, base, &pwm_regmap_config);
[ ... ]
> + chip->frames[n].regmap =
> + devm_regmap_init_mmio(dev, base, &pwm_regmap_config);
[Severity: Low]
Does registering chip->regmap and every chip->frames[n].regmap on the same
device with an unnamed pwm_regmap_config collide in regmap debugfs?
Because pwm_regmap_config.name is NULL, regmap_debugfs_init() uses
dev_name(dev) for all of them under /sys/kernel/debug/regmap/, causing every
per-frame regmap to fail debugfs directory creation with -EEXIST during
probe.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-pwm_qcom_shikra-v1-0-67ee4553adc5@oss.qualcomm.com?part=2
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] arm64: dts: qcom: add Shikra PWM controller
2026-11-16 6:59 ` [PATCH 3/3] arm64: dts: qcom: add Shikra PWM controller Taniya Das
@ 2026-11-16 7:32 ` sashiko-bot
0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-16 7:32 UTC (permalink / raw)
To: Taniya Das; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] arm64: dts: qcom: shikra: pwm@4700000 left enabled by default in
SoC dtsi
--
commit eea458c9d44a72e60937665a306393bd7a4b77fd
Author: Taniya Das <taniya.das@oss.qualcomm.com>
arm64: dts: qcom: add Shikra PWM controller
This commit adds the PWM controller node and its ten frame child nodes
to the Shikra SoC DTSI.
> diff --git a/arch/arm64/boot/dts/qcom/shikra.dtsi b/arch/arm64/boot/dts/qcom/shikra.dtsi
> index 0a95ad5a5582c..d8a3de38382bd 100644
> --- a/arch/arm64/boot/dts/qcom/shikra.dtsi
> +++ b/arch/arm64/boot/dts/qcom/shikra.dtsi
> @@ -1303,6 +1303,69 @@ sram@4690000 {
> reg = <0x0 0x04690000 0x0 0x14000>;
> };
>
> + pwm: pwm@4700000 {
> + compatible = "qcom,shikra-pwm";
> + reg = <0x0 0x04700000 0x0 0x10>;
> + clocks = <&gcc GCC_PDM_AHB_CLK>, <&gcc GCC_PWM0_XO512_CLK>;
> + clock-names = "ahb", "core";
> + assigned-clocks = <&gcc GCC_PWM0_XO512_CLK>;
> + assigned-clock-rates = <9600000>;
> + #pwm-cells = <3>;
> + #address-cells = <2>;
> + #size-cells = <2>;
> + ranges;
> +
> + pwm@4701000 {
> + reg = <0x0 0x04701000 0x0 0x1c>;
> + qcom,frame-index = <0>;
> + };
[Severity: Low]
Should pwm@4700000 and its frame child nodes default to status = "disabled"
(with labels on the child nodes)?
Leaving them enabled in the SoC DTSI causes qcom_pwm_probe() to run on
every Shikra board, mapping all ten frames, enabling the PWM clocks, and
clearing all ten channel enable bits in PWM_TOPCTL0 even on boards that do
not wire up PWM. Without labels and status = "disabled" on the frame child
nodes, board files also cannot selectively enable only the frames they use,
which qcom_pwm_parse_dt() checks via for_each_available_child_of_node().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-pwm_qcom_shikra-v1-0-67ee4553adc5@oss.qualcomm.com?part=3
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-16 7:32 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 6:59 [PATCH 0/3] pwm: qcom: add Shikra PWM controller Taniya Das
2026-11-16 6:59 ` [PATCH 1/3] dt-bindings: " Taniya Das
2026-11-16 7:22 ` sashiko-bot
2026-11-16 6:59 ` [PATCH 2/3] pwm: qcom: add Shikra PWM controller support Taniya Das
2026-11-16 7:29 ` sashiko-bot
2026-11-16 6:59 ` [PATCH 3/3] arm64: dts: qcom: add Shikra PWM controller Taniya Das
2026-11-16 7:32 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox