Devicetree
 help / color / mirror / Atom feed
* [PATCH v7 0/2] pwm: add Axiado AX3000 PWM support
@ 2026-11-18 12:42 Petar Stepanovic
  2026-11-18 12:42 ` [PATCH v7 1/2] dt-bindings: pwm: add Axiado AX3000 PWM Petar Stepanovic
  2026-11-18 12:42 ` [PATCH v7 2/2] pwm: add Axiado AX3000 PWM driver Petar Stepanovic
  0 siblings, 2 replies; 4+ messages in thread
From: Petar Stepanovic @ 2026-11-18 12:42 UTC (permalink / raw)
  To: Akhila Kavi, Prasad Bolisetty, Uwe Kleine-König, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Harshit Shah, Tzu-Hao Wei,
	Karthikeyan Mitran
  Cc: linux-pwm, devicetree, linux-arm-kernel, linux-kernel, openbmc,
	Petar Stepanovic, Conor Dooley

This series adds support for the PWM controller found on Axiado
AX3000 and AX3005 SoCs.

A new driver is needed because this PWM controller is a SoC-specific
hardware block used on Axiado SoCs. It has its own register layout,
enable control, period configuration, duty-cycle configuration, and
does not match any existing upstream PWM driver.

The controller provides configurable PWM output signals. The driver
exposes the controller through the Linux PWM framework and supports
period and duty-cycle configuration.

The driver converts the requested period and duty cycle from nanoseconds
to hardware clock cycles based on the input clock rate.

The datasheet is not publicly available. Public high-level product
information is available at:

https://axiado.com/products/#AX3080

The register definitions and programming sequence used by this driver
are based on Axiado internal SoC documentation.

Signed-off-by: Petar Stepanovic <pstepanovic@axiado.com>
---
Changes in v7:
- Rebased onto Linux v7.4 and resolved a conflict in MAINTAINERS.
- Link to v6: https://patch.msgid.link/20261005-axiado-ax3000-pwm-v6-0-7feecd0087e4@axiado.com

Changes in v6:
- Use 3 PWM cells and add the flags cell to PWM consumers.
- Fix readback of the constant-high hardware state when the high-time
  register is zero.
- Link to v5: https://patch.msgid.link/20260921-axiado-ax3000-pwm-v5-0-202aad28e129@axiado.com

Changes in v5:
- Use the hardware disable state directly instead of emulating a
  disabled
  PWM with the constant-low representation.
- Remove driver-side cached period and logically-disabled state.
- Handle 0% duty cycle using the hardware constant-low representation
  during waveform rounding.
- Decode the constant-low representation as 0% duty with a
  one-clock-cycle
  period on readback.
- Simplify waveform read/write handling and remove redundant validation.
- Update the driver limitations documentation.
- Link to v4: https://patch.msgid.link/20260908-axiado-ax3000-pwm-v4-0-19a03671cd5b@axiado.com

Changes in v4:
- Corrected the AX3005 compatible ordering to list
  axiado,ax3005-pwm before its axiado,ax3000-pwm fallback.
- Changed the disabled-state handling to program a constant-low
  waveform,
  because disabling the hardware controller drives the output high.
- Added software state tracking so readback reports this constant-low
  hardware representation as a logically disabled PWM.
- Link to v3: https://patch.msgid.link/20260811-axiado-ax3000-pwm-v3-0-6ceaccd812cf@axiado.com

Changes in v3:
- Express AX3005 compatibility with AX3000 using a fallback compatible.
- Update the Devicetree binding example accordingly.
- Add 0% duty-cycle support using the hardware constant-low encoding.
- Cache the rounded period for 0% duty-cycle waveform readback.
- Allow sub-cycle duty requests to round down to 0% instead of rounding
  up to one clock cycle.
- Normalize high-time values greater than the period to 100% duty.
- Drop the redundant AX3005 OF match entry and use the AX3000 fallback.
- Clarify comments and PWM hardware limitations.
- Link to v2: https://lore.kernel.org/r/20260723-axiado-ax3000-pwm-v2-0-22002f0b281d@axiado.com

Changes in v2:
- Migrated the driver from the legacy apply/get_state API to the new
  waveform ops API (round_waveform_tohw/fromhw, read/write_waveform).
- Cache the clock rate at probe and lock it with
  devm_clk_rate_exclusive_get() instead of reading it on every op.
- Improved rounding: clamp period/duty to hardware limits, reject
  non-zero duty offset, preserve exact 100% duty, round sub-cycle duty
  up to the minimum.
- Added a "Limitations" comment block documenting hardware constraints.
- Renamed macros from AX_PWM_* to AXIADO_PWM_* and dropped unused ones.
- DT binding: dropped clock-names, made #pwm-cells required, and
  updated the description and compatible list to cover both the AX3000
  and AX3005 SoCs.
- Added axiado,ax3005-pwm to the driver's OF device match table.
- Link to v1: https://lore.kernel.org/r/20260618-axiado-ax3000-pwm-v1-0-c9797a909414@axiado.com

To: Petar Stepanovic <pstepanovic@axiado.com>
To: Akhila Kavi <akavi@axiado.com>
To: Prasad Bolisetty <pbolisetty@axiado.com>
To: Uwe Kleine-König <ukleinek@kernel.org>
To: Rob Herring <robh@kernel.org>
To: Krzysztof Kozlowski <krzk+dt@kernel.org>
To: Conor Dooley <conor+dt@kernel.org>
To: Harshit Shah <hshah@axiado.com>
To: Tzu-Hao Wei <twei@axiado.com>
To: Karthikeyan Mitran <kmitran@axiado.com>
Cc: linux-pwm@vger.kernel.org
Cc: devicetree@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org

---
Petar Stepanovic (2):
      dt-bindings: pwm: add Axiado AX3000 PWM
      pwm: add Axiado AX3000 PWM driver

 .../devicetree/bindings/pwm/axiado,ax3000-pwm.yaml |  53 ++++
 MAINTAINERS                                        |   9 +
 drivers/pwm/Kconfig                                |  11 +
 drivers/pwm/Makefile                               |   1 +
 drivers/pwm/pwm-axiado.c                           | 282 +++++++++++++++++++++
 5 files changed, 356 insertions(+)
---
base-commit: b3dfbde62cf1981c4638939c159dfd087b7a72e9
change-id: 20260518-axiado-ax3000-pwm-cd7c346849f1

Best regards,
--  
Petar Stepanovic <pstepanovic@axiado.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v7 1/2] dt-bindings: pwm: add Axiado AX3000 PWM
  2026-11-18 12:42 [PATCH v7 0/2] pwm: add Axiado AX3000 PWM support Petar Stepanovic
@ 2026-11-18 12:42 ` Petar Stepanovic
  2026-11-18 12:42 ` [PATCH v7 2/2] pwm: add Axiado AX3000 PWM driver Petar Stepanovic
  1 sibling, 0 replies; 4+ messages in thread
From: Petar Stepanovic @ 2026-11-18 12:42 UTC (permalink / raw)
  To: Akhila Kavi, Prasad Bolisetty, Uwe Kleine-König, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Harshit Shah, Tzu-Hao Wei,
	Karthikeyan Mitran
  Cc: linux-pwm, devicetree, linux-arm-kernel, linux-kernel, openbmc,
	Petar Stepanovic, Conor Dooley

The Axiado AX3000 and AX3005 SoCs include PWM controllers that can be
used to generate configurable PWM output signals.

Acked-by: Conor Dooley <conor.dooley@microchip.com>
Signed-off-by: Petar Stepanovic <pstepanovic@axiado.com>
---
 .../devicetree/bindings/pwm/axiado,ax3000-pwm.yaml | 53 ++++++++++++++++++++++
 MAINTAINERS                                        |  8 ++++
 2 files changed, 61 insertions(+)

diff --git a/Documentation/devicetree/bindings/pwm/axiado,ax3000-pwm.yaml b/Documentation/devicetree/bindings/pwm/axiado,ax3000-pwm.yaml
new file mode 100644
index 000000000000..f0d5a3dd70e1
--- /dev/null
+++ b/Documentation/devicetree/bindings/pwm/axiado,ax3000-pwm.yaml
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pwm/axiado,ax3000-pwm.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Axiado AX3000 PWM controller
+
+maintainers:
+  - Petar Stepanovic <pstepanovic@axiado.com>
+  - Akhila Kavi <akavi@axiado.com>
+  - Prasad Bolisetty <pbolisetty@axiado.com>
+
+description:
+  The Axiado PWM controller found on the AX3000 and AX3005 SoCs.
+
+allOf:
+  - $ref: pwm.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - const: axiado,ax3000-pwm
+      - items:
+          - const: axiado,ax3005-pwm
+          - const: axiado,ax3000-pwm
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  "#pwm-cells":
+    const: 3
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - "#pwm-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    pwm@80801c00 {
+      compatible = "axiado,ax3000-pwm";
+      reg = <0x80801c00 0x1000>;
+      #pwm-cells = <3>;
+      clocks = <&clk>;
+    };
+
diff --git a/MAINTAINERS b/MAINTAINERS
index 222b7fc2c3aa..fe85aaa5a7eb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4555,6 +4555,14 @@ S:	Orphan
 F:	Documentation/devicetree/bindings/sound/axentia,*
 F:	sound/soc/atmel/tse850-pcm5142.c
 
+AXIADO AX3000 PWM DRIVER
+M:	Petar Stepanovic <pstepanovic@axiado.com>
+M:	Akhila Kavi <akavi@axiado.com>
+M:	Prasad Bolisetty <pbolisetty@axiado.com>
+L:	linux-pwm@vger.kernel.org
+S:	Supported
+F:	Documentation/devicetree/bindings/pwm/axiado,ax3000-pwm.yaml
+
 AXIADO SARADC DRIVER
 M:	Petar Stepanovic <pstepanovic@axiado.com>
 M:	Akhila Kavi <akavi@axiado.com>

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v7 2/2] pwm: add Axiado AX3000 PWM driver
  2026-11-18 12:42 [PATCH v7 0/2] pwm: add Axiado AX3000 PWM support Petar Stepanovic
  2026-11-18 12:42 ` [PATCH v7 1/2] dt-bindings: pwm: add Axiado AX3000 PWM Petar Stepanovic
@ 2026-11-18 12:42 ` Petar Stepanovic
  2026-11-18 13:00   ` sashiko-bot
  1 sibling, 1 reply; 4+ messages in thread
From: Petar Stepanovic @ 2026-11-18 12:42 UTC (permalink / raw)
  To: Akhila Kavi, Prasad Bolisetty, Uwe Kleine-König, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Harshit Shah, Tzu-Hao Wei,
	Karthikeyan Mitran
  Cc: linux-pwm, devicetree, linux-arm-kernel, linux-kernel, openbmc,
	Petar Stepanovic

The Axiado AX3000 and AX3005 SoCs include a single-channel PWM
controller.

Add a driver supporting period, duty-cycle, and enable-state
configuration through the Linux PWM framework.

Disabling the hardware controller drives its output high. A 0% duty
cycle is implemented using the controller's constant-low encoding,
because a zero high time is interpreted by the hardware as a
constant-high output. The constant-low state is reported as a 0% duty
cycle with a one-clock-cycle period on readback.

AX3005 uses the same programming model as AX3000 and is supported
through the axiado,ax3000-pwm fallback compatible.

Signed-off-by: Petar Stepanovic <pstepanovic@axiado.com>
---
 MAINTAINERS              |   1 +
 drivers/pwm/Kconfig      |  11 ++
 drivers/pwm/Makefile     |   1 +
 drivers/pwm/pwm-axiado.c | 282 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 295 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index fe85aaa5a7eb..c148c9099045 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4562,6 +4562,7 @@ M:	Prasad Bolisetty <pbolisetty@axiado.com>
 L:	linux-pwm@vger.kernel.org
 S:	Supported
 F:	Documentation/devicetree/bindings/pwm/axiado,ax3000-pwm.yaml
+F:	drivers/pwm/pwm-axiado.c
 
 AXIADO SARADC DRIVER
 M:	Petar Stepanovic <pstepanovic@axiado.com>
diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index 729776086879..3ea749d83272 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -129,6 +129,17 @@ config PWM_ATMEL_TCB
 	  To compile this driver as a module, choose M here: the module
 	  will be called pwm-atmel-tcb.
 
+config PWM_AXIADO
+	tristate "Axiado PWM support"
+	depends on ARCH_AXIADO || COMPILE_TEST
+	depends on HAS_IOMEM
+	help
+	  PWM framework driver for the PWM controller found on Axiado
+	  AX3000 and AX3005 SoCs.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called pwm-axiado.
+
 config PWM_AXI_PWMGEN
 	tristate "Analog Devices AXI PWM generator"
 	depends on MICROBLAZE || NIOS2 || ARCH_ZYNQ || ARCH_ZYNQMP || ARCH_INTEL_SOCFPGA || COMPILE_TEST
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile
index 5630a521a7cf..434d913cfc79 100644
--- a/drivers/pwm/Makefile
+++ b/drivers/pwm/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_PWM_ARGON_FAN_HAT)	+= pwm-argon-fan-hat.o
 obj-$(CONFIG_PWM_ATMEL)		+= pwm-atmel.o
 obj-$(CONFIG_PWM_ATMEL_HLCDC_PWM)	+= pwm-atmel-hlcdc.o
 obj-$(CONFIG_PWM_ATMEL_TCB)	+= pwm-atmel-tcb.o
+obj-$(CONFIG_PWM_AXIADO)	+= pwm-axiado.o
 obj-$(CONFIG_PWM_AXI_PWMGEN)	+= pwm-axi-pwmgen.o
 obj-$(CONFIG_PWM_BCM2835)	+= pwm-bcm2835.o
 obj-$(CONFIG_PWM_BCM_IPROC)	+= pwm-bcm-iproc.o
diff --git a/drivers/pwm/pwm-axiado.c b/drivers/pwm/pwm-axiado.c
new file mode 100644
index 000000000000..08ae3d8ed4bb
--- /dev/null
+++ b/drivers/pwm/pwm-axiado.c
@@ -0,0 +1,282 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * SPDX-FileCopyrightText: 2021-2026 Axiado Corporation.
+ */
+
+/*
+ * Limitations:
+ * - Only normal polarity is supported.
+ * - The hardware has no shadow registers, so configuration changes take
+ *   effect immediately without waiting for the current period to complete.
+ * - The output is driven high while the hardware is disabled.
+ * - Supported period range: 2 through 0xfffffffe PWM input clock cycles;
+ *   0xffffffff is reserved by the hardware for a constant low output.
+ *   Longer periods are clamped to the maximum.
+ * - A 0% duty cycle is emitted using the constant low encoding because the
+ *   hardware interprets a zero high time as a constant high output. The
+ *   requested period is lost in that case and is reported as a single clock
+ *   cycle.
+ * - A 100% duty cycle is supported and emits a constant high output.
+ */
+
+#include <linux/bits.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/math64.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/pwm.h>
+
+/* Register offsets */
+#define AXIADO_PWM_CTRL_REG	0x0000
+#define AXIADO_PWM_PERIOD_REG	0x0004
+#define AXIADO_PWM_HIGH_REG	0x0008
+
+/* Period and duty cycle limits */
+#define AXIADO_PWM_PERIOD_MIN	2
+#define AXIADO_PWM_PERIOD_MAX	0xfffffffe
+#define AXIADO_PWM_PERIOD_CONST_LOW	0xffffffff
+#define AXIADO_PWM_DUTY_MIN	1
+
+/* Control register bits */
+#define AXIADO_PWM_CTRL_ENABLE	BIT(0)
+
+struct axiado_pwm_chip {
+	void __iomem *base;
+	unsigned long rate;
+};
+
+struct axiado_pwm_waveform {
+	u32 period;
+	u32 duty;
+	bool enabled;
+};
+
+static int
+axiado_pwm_round_waveform_tohw(struct pwm_chip *chip,
+			       struct pwm_device *pwm,
+			       const struct pwm_waveform *wf,
+			       void *_wfhw)
+{
+	struct axiado_pwm_chip *axpwm = pwmchip_get_drvdata(chip);
+	struct axiado_pwm_waveform *wfhw = _wfhw;
+	u64 period;
+	u64 duty;
+	int ret = 0;
+
+	/* Encode a disabled request as a zeroed hardware waveform. */
+	if (!wf->period_length_ns) {
+		*wfhw = (struct axiado_pwm_waveform) { };
+
+		return 0;
+	}
+
+	period = mul_u64_u64_div_u64(wf->period_length_ns, axpwm->rate,
+				     NSEC_PER_SEC);
+	duty = mul_u64_u64_div_u64(wf->duty_length_ns, axpwm->rate,
+				   NSEC_PER_SEC);
+
+	if (!duty) {
+		/*
+		 * A zero high time makes the hardware emit a constant high
+		 * output, so use the constant low period encoding for a 0%
+		 * duty cycle. The high time must stay non-zero because it
+		 * takes precedence over that encoding. The requested period
+		 * is lost, .round_waveform_fromhw() reports a single clock
+		 * cycle instead.
+		 */
+		*wfhw = (struct axiado_pwm_waveform) {
+			.period = AXIADO_PWM_PERIOD_CONST_LOW,
+			.duty = AXIADO_PWM_DUTY_MIN,
+			.enabled = true,
+		};
+
+		/* That single cycle is longer than a sub-cycle request. */
+		return period ? 0 : 1;
+	}
+
+	if (period < AXIADO_PWM_PERIOD_MIN) {
+		period = AXIADO_PWM_PERIOD_MIN;
+		ret = 1;
+	} else if (period > AXIADO_PWM_PERIOD_MAX) {
+		period = AXIADO_PWM_PERIOD_MAX;
+	}
+
+	/*
+	 * Period clamping can leave the converted duty greater than the
+	 * final hardware period. In that case, clamp it to 100% duty.
+	 */
+	if (duty > period)
+		duty = period;
+
+	*wfhw = (struct axiado_pwm_waveform) {
+		.period = period,
+		.duty = duty,
+		.enabled = true,
+	};
+
+	return ret;
+}
+
+static int
+axiado_pwm_round_waveform_fromhw(struct pwm_chip *chip,
+				 struct pwm_device *pwm,
+				 const void *_wfhw,
+				 struct pwm_waveform *wf)
+{
+	struct axiado_pwm_chip *axpwm = pwmchip_get_drvdata(chip);
+	const struct axiado_pwm_waveform *wfhw = _wfhw;
+	u32 period = wfhw->period;
+	u32 duty = wfhw->duty;
+
+	if (!wfhw->enabled) {
+		*wf = (struct pwm_waveform) {
+			.period_length_ns = 0,
+		};
+
+		return 0;
+	}
+
+	/*
+	 * The constant low encoding doesn't hold a period. Report the
+	 * shortest one, the output is low for all of it either way.
+	 */
+	if (!duty) {
+		if (period == AXIADO_PWM_PERIOD_CONST_LOW)
+			period = AXIADO_PWM_PERIOD_MAX;
+
+		duty = period;
+	} else if (period == AXIADO_PWM_PERIOD_CONST_LOW) {
+		period = 1;
+		duty = 0;
+	} else if (duty > period) {
+		duty = period;
+	}
+
+	*wf = (struct pwm_waveform) {
+		.period_length_ns =
+			mul_u64_u64_div_u64_roundup(period, NSEC_PER_SEC,
+						    axpwm->rate),
+		.duty_length_ns =
+			mul_u64_u64_div_u64_roundup(duty, NSEC_PER_SEC,
+						    axpwm->rate),
+		.duty_offset_ns = 0,
+	};
+
+	return 0;
+}
+
+static int axiado_pwm_read_waveform(struct pwm_chip *chip,
+				    struct pwm_device *pwm,
+				    void *_wfhw)
+{
+	struct axiado_pwm_chip *axpwm = pwmchip_get_drvdata(chip);
+	struct axiado_pwm_waveform *wfhw = _wfhw;
+	u32 ctrl;
+
+	ctrl = readl(axpwm->base + AXIADO_PWM_CTRL_REG);
+
+	*wfhw = (struct axiado_pwm_waveform) {
+		.period = readl(axpwm->base + AXIADO_PWM_PERIOD_REG),
+		.duty = readl(axpwm->base + AXIADO_PWM_HIGH_REG),
+		.enabled = !!(ctrl & AXIADO_PWM_CTRL_ENABLE),
+	};
+
+	return 0;
+}
+
+static int axiado_pwm_write_waveform(struct pwm_chip *chip,
+				     struct pwm_device *pwm,
+				     const void *_wfhw)
+{
+	struct axiado_pwm_chip *axpwm = pwmchip_get_drvdata(chip);
+	const struct axiado_pwm_waveform *wfhw = _wfhw;
+
+	if (!wfhw->enabled) {
+		writel(0, axpwm->base + AXIADO_PWM_CTRL_REG);
+
+		return 0;
+	}
+
+	/*
+	 * The hardware has no shadow registers. These writes may alter the
+	 * active waveform before the current period has completed.
+	 */
+	writel(wfhw->period, axpwm->base + AXIADO_PWM_PERIOD_REG);
+	writel(wfhw->duty, axpwm->base + AXIADO_PWM_HIGH_REG);
+	writel(AXIADO_PWM_CTRL_ENABLE, axpwm->base + AXIADO_PWM_CTRL_REG);
+
+	return 0;
+}
+
+static const struct pwm_ops axiado_pwm_ops = {
+	.sizeof_wfhw = sizeof(struct axiado_pwm_waveform),
+	.round_waveform_tohw = axiado_pwm_round_waveform_tohw,
+	.round_waveform_fromhw = axiado_pwm_round_waveform_fromhw,
+	.read_waveform = axiado_pwm_read_waveform,
+	.write_waveform = axiado_pwm_write_waveform,
+};
+
+static int axiado_pwm_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct axiado_pwm_chip *axpwm;
+	struct pwm_chip *chip;
+	struct clk *clk;
+	int ret;
+
+	chip = devm_pwmchip_alloc(dev, 1, sizeof(*axpwm));
+	if (IS_ERR(chip))
+		return PTR_ERR(chip);
+
+	axpwm = pwmchip_get_drvdata(chip);
+
+	axpwm->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(axpwm->base))
+		return dev_err_probe(dev, PTR_ERR(axpwm->base),
+				     "Failed to map registers\n");
+
+	clk = devm_clk_get_enabled(dev, NULL);
+	if (IS_ERR(clk))
+		return dev_err_probe(dev, PTR_ERR(clk),
+				     "Failed to get/enable clock\n");
+
+	ret = devm_clk_rate_exclusive_get(dev, clk);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "Failed to lock clock rate\n");
+
+	axpwm->rate = clk_get_rate(clk);
+	if (!axpwm->rate)
+		return dev_err_probe(dev, -EINVAL,
+				     "Failed to get clock rate\n");
+
+	chip->ops = &axiado_pwm_ops;
+	chip->atomic = true;
+
+	ret = devm_pwmchip_add(dev, chip);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to add PWM chip\n");
+
+	return 0;
+}
+
+static const struct of_device_id axiado_pwm_match[] = {
+	{ .compatible = "axiado,ax3000-pwm" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, axiado_pwm_match);
+
+static struct platform_driver axiado_pwm_driver = {
+	.driver = {
+		.name = "axiado-pwm",
+		.of_match_table = axiado_pwm_match,
+	},
+	.probe = axiado_pwm_probe,
+};
+module_platform_driver(axiado_pwm_driver);
+
+MODULE_AUTHOR("Axiado Corporation");
+MODULE_DESCRIPTION("Axiado PWM driver");
+MODULE_LICENSE("GPL");

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v7 2/2] pwm: add Axiado AX3000 PWM driver
  2026-11-18 12:42 ` [PATCH v7 2/2] pwm: add Axiado AX3000 PWM driver Petar Stepanovic
@ 2026-11-18 13:00   ` sashiko-bot
  0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-18 13:00 UTC (permalink / raw)
  To: Petar Stepanovic; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] pwm: axiado: report AXIADO_PWM_PERIOD_MIN for constant-low
  waveform
- [Low] pwm: axiado: missing clock rate upper bound check in
  axiado_pwm_probe()
- [Low] pwm: axiado: enabled state with zero period misreported as
  disabled
--

commit 7728e28931a7e60a27c5a0287f72bca3566ff745
Author: Petar Stepanovic <pstepanovic@axiado.com>

pwm: add Axiado AX3000 PWM driver

This commit adds a PWM driver for the single-channel PWM controller on
Axiado AX3000 and AX3005 SoCs using the waveform callbacks.

> diff --git a/drivers/pwm/pwm-axiado.c b/drivers/pwm/pwm-axiado.c
> new file mode 100644
> index 0000000000000..08ae3d8ed4bb1
> --- /dev/null
> +++ b/drivers/pwm/pwm-axiado.c
[ ... ]
> +static int
> +axiado_pwm_round_waveform_tohw(struct pwm_chip *chip,
> +			       struct pwm_device *pwm,
> +			       const struct pwm_waveform *wf,
> +			       void *_wfhw)
> +{
[ ... ]
> +	if (!duty) {
> +		/*
> +		 * A zero high time makes the hardware emit a constant high
> +		 * output, so use the constant low period encoding for a 0%
> +		 * duty cycle. The high time must stay non-zero because it
> +		 * takes precedence over that encoding. The requested period
> +		 * is lost, .round_waveform_fromhw() reports a single clock
> +		 * cycle instead.
> +		 */
> +		*wfhw = (struct axiado_pwm_waveform) {
> +			.period = AXIADO_PWM_PERIOD_CONST_LOW,
> +			.duty = AXIADO_PWM_DUTY_MIN,
> +			.enabled = true,
> +		};
> +
> +		/* That single cycle is longer than a sub-cycle request. */
> +		return period ? 0 : 1;
> +	}
> +
> +	if (period < AXIADO_PWM_PERIOD_MIN) {
> +		period = AXIADO_PWM_PERIOD_MIN;
> +		ret = 1;

[Severity: Medium]
Should the constant-low encoding use AXIADO_PWM_PERIOD_MIN (2 clock cycles)
instead of 1 clock cycle as its minimum and reported period?

When duty is 0, axiado_pwm_round_waveform_tohw() accepts a 1-cycle period
with return value 0 and axiado_pwm_round_waveform_fromhw() reports
AXIADO_PWM_PERIOD_CONST_LOW as period = 1, whereas any non-zero duty cycle
requires period >= AXIADO_PWM_PERIOD_MIN (2) and rounds a 1-cycle period up
with return value 1.

When CONFIG_PWM_PROVIDE_GPIO is enabled, pwm_gpio_set() probes the minimum
period with period_length_ns = 1 and duty_length_ns = 0, which rounds to 1
clock cycle.  Driving the GPIO high then sets duty_length_ns =
period_length_ns (1 clock cycle) and calls pwm_set_waveform_might_sleep()
with exact = true, which rounds the period up to 2 clock cycles and fails
with -EDOM:

drivers/pwm/core.c:pwm_gpio_set() {
	struct pwm_waveform wf = {
		.period_length_ns = 1,
	};
    ...
	ret = pwm_round_waveform_might_sleep(pwm, &wf);
	if (ret < 0)
		return ret;

	if (value)
		wf.duty_length_ns = wf.period_length_ns;
	else
		wf.duty_length_ns = 0;

	return pwm_set_waveform_might_sleep(pwm, &wf, true);
}

Reporting AXIADO_PWM_PERIOD_MIN for AXIADO_PWM_PERIOD_CONST_LOW in
axiado_pwm_round_waveform_fromhw() and returning period <
AXIADO_PWM_PERIOD_MIN ? 1 : 0 when !duty in
axiado_pwm_round_waveform_tohw() keeps the minimum period consistent across
all duty cycles.

[ ... ]
> +static int
> +axiado_pwm_round_waveform_fromhw(struct pwm_chip *chip,
> +				 struct pwm_device *pwm,
> +				 const void *_wfhw,
> +				 struct pwm_waveform *wf)
> +{
[ ... ]
> +	/*
> +	 * The constant low encoding doesn't hold a period. Report the
> +	 * shortest one, the output is low for all of it either way.
> +	 */
> +	if (!duty) {
> +		if (period == AXIADO_PWM_PERIOD_CONST_LOW)
> +			period = AXIADO_PWM_PERIOD_MAX;
> +
> +		duty = period;
> +	} else if (period == AXIADO_PWM_PERIOD_CONST_LOW) {
> +		period = 1;
> +		duty = 0;
> +	} else if (duty > period) {
> +		duty = period;
> +	}
> +
> +	*wf = (struct pwm_waveform) {
> +		.period_length_ns =
> +			mul_u64_u64_div_u64_roundup(period, NSEC_PER_SEC,
> +						    axpwm->rate),
> +		.duty_length_ns =
> +			mul_u64_u64_div_u64_roundup(duty, NSEC_PER_SEC,
> +						    axpwm->rate),
> +		.duty_offset_ns = 0,
> +	};

[Severity: Low]
Can axiado_pwm_round_waveform_fromhw() report a disabled waveform when the
hardware is enabled with AXIADO_PWM_PERIOD_REG == 0?

If pre-kernel firmware leaves the controller enabled with period == 0 (for
instance with duty == 0, where a zero high time still drives the output
constant high), period and duty both remain 0 and wf->period_length_ns is
computed as 0.  Because period_length_ns == 0 encodes a disabled waveform,
pwm_get_state_hw() records pwm->state.enabled = false, and a subsequent
pwm_apply_might_sleep() call to disable the channel returns early in
__pwm_apply() without clearing AXIADO_PWM_CTRL_ENABLE.

[ ... ]
> +static int axiado_pwm_probe(struct platform_device *pdev)
> +{
[ ... ]
> +	axpwm->rate = clk_get_rate(clk);
> +	if (!axpwm->rate)
> +		return dev_err_probe(dev, -EINVAL,
> +				     "Failed to get clock rate\n");

[Severity: Low]
Should axiado_pwm_probe() also reject axpwm->rate > NSEC_PER_SEC?

If clk_get_rate() exceeds NSEC_PER_SEC, a single clock cycle is shorter
than 1 ns, breaking nanosecond-to-cycle rounding idempotency and sub-cycle
detection in axiado_pwm_round_waveform_tohw(), and allowing
mul_u64_u64_div_u64() to overflow a 64-bit quotient for large
wf->period_length_ns values.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-axiado-ax3000-pwm-v7-0-bbd21a8cf861@axiado.com?part=2

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-18 13:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 12:42 [PATCH v7 0/2] pwm: add Axiado AX3000 PWM support Petar Stepanovic
2026-11-18 12:42 ` [PATCH v7 1/2] dt-bindings: pwm: add Axiado AX3000 PWM Petar Stepanovic
2026-11-18 12:42 ` [PATCH v7 2/2] pwm: add Axiado AX3000 PWM driver Petar Stepanovic
2026-11-18 13:00   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox