devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v7 0/3] pwm: Add pwm driver for Sophgo SG2042
@ 2025-02-05  6:59 Chen Wang
  2025-02-05  7:00 ` [PATCH v7 1/3] dt-bindings: pwm: sophgo: add PWM controller for SG2042 Chen Wang
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Chen Wang @ 2025-02-05  6:59 UTC (permalink / raw)
  To: ukleinek, robh, krzk+dt, conor+dt, unicorn_wang, inochiama,
	devicetree, linux-kernel, linux-pwm, linux-riscv, chao.wei,
	haijiao.liu, xiaoguang.xing, chunzhi.lin

From: Chen Wang <unicorn_wang@outlook.com>

Add driver for pwm controller of Sophgo SG2042 SoC.

Thanks,
Chen

---

Changes in v7:
  The patch series is based on v6.14-rc1.

  Fixed following issues as per comments from Uwe Kleine-König, thanks.

  - dt-bindings: change value of "#pwm-cells" from 2 to 3.
  - driver: rename variables period/hlperiod to period_ticks/hlperiod_ticks and
    improve coding of apply()/get_state(); use
    devm_reset_control_get_optional_shared_deasserted() instead of
    devm_reset_control_get_optional_shared() and reset_control_deassert();
    add more comments and other miscellaneous code improvements.

Changes in v6:
  Nothing major changes just rebased onto v6.13-rc1 and retested. You can
  simply review or test the patches at the link [6].

Changes in v5:
  The patch series is based on v6.12-rc1. You can simply review or test
  the patches at the link [5].

  Updated driver to add resets property for pwm controller node as per
  suggestion from Inochi.

Changes in v4:
  The patch series is based on v6.12-rc1. You can simply review or test
  the patches at the link [4].

  Updated driver to set property atomic of pwm_chip to true as per suggestion
  from Sean.

Changes in v3:
  The patch series is catched up with v6.12-rc1. You can simply review or test
  the patches at the link [3].

  Add patch #3 for dts part change.

Changes in v2:
  The patch series is based on v6.11-rc6. You can simply review or test the
  patches at the link [2].

  Fixed following issues as per comments from Yixun Lan, Krzysztof Kozlowski
  and Uwe Kleine-König, thanks.

  - Some minor issues in dt-bindings.
  - driver issues, use macros with name prefix for registers access; add
    limitations comments; fixed potential calculation overflow problem;
    add .get_state() callback and other miscellaneous code improvements.

Changes in v1:
  The patch series is based on v6.11-rc6. You can simply review or test the
  patches at the link [1].

Link: https://lore.kernel.org/linux-riscv/cover.1725536870.git.unicorn_wang@outlook.com/ [1]
Link: https://lore.kernel.org/linux-riscv/cover.1725931796.git.unicorn_wang@outlook.com/ [2]
Link: https://lore.kernel.org/linux-riscv/cover.1728355974.git.unicorn_wang@outlook.com/ [3]
Link: https://lore.kernel.org/linux-riscv/cover.1729037302.git.unicorn_wang@outlook.com/ [4]
Link: https://lore.kernel.org/linux-riscv/cover.1729843087.git.unicorn_wang@outlook.com/ [5]
Link: https://lore.kernel.org/linux-riscv/cover.1733281657.git.unicorn_wang@outlook.com/ [6]
---

Chen Wang (3):
  dt-bindings: pwm: sophgo: add PWM controller for SG2042
  pwm: sophgo: add driver for Sophgo SG2042 PWM
  riscv: sophgo: dts: add pwm controller for SG2042 SoC

 .../bindings/pwm/sophgo,sg2042-pwm.yaml       |  58 ++++++
 arch/riscv/boot/dts/sophgo/sg2042.dtsi        |   9 +
 drivers/pwm/Kconfig                           |  10 +
 drivers/pwm/Makefile                          |   1 +
 drivers/pwm/pwm-sophgo-sg2042.c               | 196 ++++++++++++++++++
 5 files changed, 274 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pwm/sophgo,sg2042-pwm.yaml
 create mode 100644 drivers/pwm/pwm-sophgo-sg2042.c


base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
-- 
2.34.1


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

* [PATCH v7 1/3] dt-bindings: pwm: sophgo: add PWM controller for SG2042
  2025-02-05  6:59 [PATCH v7 0/3] pwm: Add pwm driver for Sophgo SG2042 Chen Wang
@ 2025-02-05  7:00 ` Chen Wang
  2025-02-05  7:01 ` [PATCH v7 2/3] pwm: sophgo: add driver for Sophgo SG2042 PWM Chen Wang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Chen Wang @ 2025-02-05  7:00 UTC (permalink / raw)
  To: ukleinek, robh, krzk+dt, conor+dt, unicorn_wang, inochiama,
	devicetree, linux-kernel, linux-pwm, linux-riscv, chao.wei,
	haijiao.liu, xiaoguang.xing, chunzhi.lin
  Cc: Krzysztof Kozlowski

From: Chen Wang <unicorn_wang@outlook.com>

Sophgo SG2042 contains a PWM controller, which has 4 channels and
can generate PWM waveforms output.

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
---
 .../bindings/pwm/sophgo,sg2042-pwm.yaml       | 58 +++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pwm/sophgo,sg2042-pwm.yaml

diff --git a/Documentation/devicetree/bindings/pwm/sophgo,sg2042-pwm.yaml b/Documentation/devicetree/bindings/pwm/sophgo,sg2042-pwm.yaml
new file mode 100644
index 000000000000..bbb6326d47d7
--- /dev/null
+++ b/Documentation/devicetree/bindings/pwm/sophgo,sg2042-pwm.yaml
@@ -0,0 +1,58 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pwm/sophgo,sg2042-pwm.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sophgo SG2042 PWM controller
+
+maintainers:
+  - Chen Wang <unicorn_wang@outlook.com>
+
+description:
+  This controller contains 4 channels which can generate PWM waveforms.
+
+allOf:
+  - $ref: pwm.yaml#
+
+properties:
+  compatible:
+    const: sophgo,sg2042-pwm
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: apb
+
+  resets:
+    maxItems: 1
+
+  "#pwm-cells":
+    const: 3
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - resets
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/reset/sophgo,sg2042-reset.h>
+
+    pwm@7f006000 {
+        compatible = "sophgo,sg2042-pwm";
+        reg = <0x7f006000 0x1000>;
+        #pwm-cells = <3>;
+        clocks = <&clock 67>;
+        clock-names = "apb";
+        resets = <&rstgen RST_PWM>;
+    };
-- 
2.34.1


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

* [PATCH v7 2/3] pwm: sophgo: add driver for Sophgo SG2042 PWM
  2025-02-05  6:59 [PATCH v7 0/3] pwm: Add pwm driver for Sophgo SG2042 Chen Wang
  2025-02-05  7:00 ` [PATCH v7 1/3] dt-bindings: pwm: sophgo: add PWM controller for SG2042 Chen Wang
@ 2025-02-05  7:01 ` Chen Wang
  2025-02-05 10:06   ` Uwe Kleine-König
  2025-02-05  7:01 ` [PATCH v7 3/3] riscv: sophgo: dts: add pwm controller for SG2042 SoC Chen Wang
  2025-02-09  1:35 ` (subset) [PATCH v7 0/3] pwm: Add pwm driver for Sophgo SG2042 Inochi Amaoto
  3 siblings, 1 reply; 9+ messages in thread
From: Chen Wang @ 2025-02-05  7:01 UTC (permalink / raw)
  To: ukleinek, robh, krzk+dt, conor+dt, unicorn_wang, inochiama,
	devicetree, linux-kernel, linux-pwm, linux-riscv, chao.wei,
	haijiao.liu, xiaoguang.xing, chunzhi.lin
  Cc: Sean Young

From: Chen Wang <unicorn_wang@outlook.com>

Add a PWM driver for PWM controller in Sophgo SG2042 SoC.

Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
---
 drivers/pwm/Kconfig             |  10 ++
 drivers/pwm/Makefile            |   1 +
 drivers/pwm/pwm-sophgo-sg2042.c | 196 ++++++++++++++++++++++++++++++++
 3 files changed, 207 insertions(+)
 create mode 100644 drivers/pwm/pwm-sophgo-sg2042.c

diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index 0915c1e7df16..ec85f3895936 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -584,6 +584,16 @@ config PWM_SL28CPLD
 	  To compile this driver as a module, choose M here: the module
 	  will be called pwm-sl28cpld.
 
+config PWM_SOPHGO_SG2042
+	tristate "Sophgo SG2042 PWM support"
+	depends on ARCH_SOPHGO || COMPILE_TEST
+	help
+	  PWM driver for the PWM controller on Sophgo SG2042 SoC. The PWM
+	  controller supports outputing 4 channels of PWM waveforms.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called pwm_sophgo_sg2042.
+
 config PWM_SPEAR
 	tristate "STMicroelectronics SPEAr PWM support"
 	depends on PLAT_SPEAR || COMPILE_TEST
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile
index 9081e0c0e9e0..539e0def3f82 100644
--- a/drivers/pwm/Makefile
+++ b/drivers/pwm/Makefile
@@ -53,6 +53,7 @@ obj-$(CONFIG_PWM_RZ_MTU3)	+= pwm-rz-mtu3.o
 obj-$(CONFIG_PWM_SAMSUNG)	+= pwm-samsung.o
 obj-$(CONFIG_PWM_SIFIVE)	+= pwm-sifive.o
 obj-$(CONFIG_PWM_SL28CPLD)	+= pwm-sl28cpld.o
+obj-$(CONFIG_PWM_SOPHGO_SG2042)	+= pwm-sophgo-sg2042.o
 obj-$(CONFIG_PWM_SPEAR)		+= pwm-spear.o
 obj-$(CONFIG_PWM_SPRD)		+= pwm-sprd.o
 obj-$(CONFIG_PWM_STI)		+= pwm-sti.o
diff --git a/drivers/pwm/pwm-sophgo-sg2042.c b/drivers/pwm/pwm-sophgo-sg2042.c
new file mode 100644
index 000000000000..ce8cf8af3402
--- /dev/null
+++ b/drivers/pwm/pwm-sophgo-sg2042.c
@@ -0,0 +1,196 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Sophgo SG2042 PWM Controller Driver
+ *
+ * Copyright (C) 2024 Sophgo Technology Inc.
+ * Copyright (C) 2024 Chen Wang <unicorn_wang@outlook.com>
+ *
+ * Limitations:
+ * - After reset, the output of the PWM channel is always high.
+ *   The value of HLPERIOD/PERIOD is 0.
+ * - When HLPERIOD or PERIOD is reconfigured, PWM will start to
+ *   output waveforms with the new configuration after completing
+ *   the running period.
+ * - When PERIOD and HLPERIOD is set to 0, the PWM wave output will
+ *   be stopped and the output is pulled to high.
+ * See the datasheet [1] for more details.
+ * [1]:https://github.com/sophgo/sophgo-doc/tree/main/SG2042/TRM
+ */
+
+#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>
+#include <linux/reset.h>
+
+/*
+ * Offset RegisterName
+ * 0x0000 HLPERIOD0
+ * 0x0004 PERIOD0
+ * 0x0008 HLPERIOD1
+ * 0x000C PERIOD1
+ * 0x0010 HLPERIOD2
+ * 0x0014 PERIOD2
+ * 0x0018 HLPERIOD3
+ * 0x001C PERIOD3
+ * Four groups and every group is composed of HLPERIOD & PERIOD
+ */
+#define SG2042_PWM_HLPERIOD(chan) ((chan) * 8 + 0)
+#define SG2042_PWM_PERIOD(chan) ((chan) * 8 + 4)
+
+#define SG2042_PWM_CHANNELNUM	4
+
+/**
+ * struct sg2042_pwm_ddata - private driver data
+ * @base:		base address of mapped PWM registers
+ * @clk_rate_hz:	rate of base clock in HZ
+ */
+struct sg2042_pwm_ddata {
+	void __iomem *base;
+	unsigned long clk_rate_hz;
+};
+
+/*
+ * period_ticks: PERIOD
+ * hlperiod_ticks: HLPERIOD
+ */
+static void pwm_sg2042_config(struct sg2042_pwm_ddata *ddata, unsigned int chan,
+			      u32 period_ticks, u32 hlperiod_ticks)
+{
+	void __iomem *base = ddata->base;
+
+	writel(period_ticks, base + SG2042_PWM_PERIOD(chan));
+	writel(hlperiod_ticks, base + SG2042_PWM_HLPERIOD(chan));
+}
+
+static int pwm_sg2042_apply(struct pwm_chip *chip, struct pwm_device *pwm,
+			    const struct pwm_state *state)
+{
+	struct sg2042_pwm_ddata *ddata = pwmchip_get_drvdata(chip);
+	u32 hlperiod_ticks;
+	u32 period_ticks;
+
+	if (state->polarity == PWM_POLARITY_INVERSED)
+		return -EINVAL;
+
+	if (!state->enabled) {
+		pwm_sg2042_config(ddata, pwm->hwpwm, 0, 0);
+		return 0;
+	}
+
+	/*
+	 * Duration of High level (duty_cycle) = HLPERIOD x Period_of_input_clk
+	 * Duration of One Cycle (period) = PERIOD x Period_of_input_clk
+	 */
+	period_ticks = min(mul_u64_u64_div_u64(ddata->clk_rate_hz, state->period, NSEC_PER_SEC), U32_MAX);
+	hlperiod_ticks = min(mul_u64_u64_div_u64(ddata->clk_rate_hz, state->duty_cycle, NSEC_PER_SEC), U32_MAX);
+
+	dev_dbg(pwmchip_parent(chip), "chan[%u]: PERIOD=%u, HLPERIOD=%u\n",
+		pwm->hwpwm, period_ticks, hlperiod_ticks);
+
+	pwm_sg2042_config(ddata, pwm->hwpwm, period_ticks, hlperiod_ticks);
+
+	return 0;
+}
+
+static int pwm_sg2042_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
+				struct pwm_state *state)
+{
+	struct sg2042_pwm_ddata *ddata = pwmchip_get_drvdata(chip);
+	unsigned int chan = pwm->hwpwm;
+	u32 hlperiod_ticks;
+	u32 period_ticks;
+
+	period_ticks = readl(ddata->base + SG2042_PWM_PERIOD(chan));
+	hlperiod_ticks = readl(ddata->base + SG2042_PWM_HLPERIOD(chan));
+
+	if (!period_ticks) {
+		state->enabled = false;
+		return 0;
+	}
+
+	if (hlperiod_ticks > period_ticks)
+		hlperiod_ticks = period_ticks;
+
+	state->enabled = true;
+	state->period = DIV_ROUND_UP_ULL((u64)period_ticks * NSEC_PER_SEC, ddata->clk_rate_hz);
+	state->duty_cycle = DIV_ROUND_UP_ULL((u64)hlperiod_ticks * NSEC_PER_SEC, ddata->clk_rate_hz);
+	state->polarity = PWM_POLARITY_NORMAL;
+
+	return 0;
+}
+
+static const struct pwm_ops pwm_sg2042_ops = {
+	.apply = pwm_sg2042_apply,
+	.get_state = pwm_sg2042_get_state,
+};
+
+static const struct of_device_id sg2042_pwm_ids[] = {
+	{ .compatible = "sophgo,sg2042-pwm" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, sg2042_pwm_ids);
+
+static int pwm_sg2042_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct sg2042_pwm_ddata *ddata;
+	struct reset_control *rst;
+	struct pwm_chip *chip;
+	struct clk *clk;
+	int ret;
+
+	chip = devm_pwmchip_alloc(dev, SG2042_PWM_CHANNELNUM, sizeof(*ddata));
+	if (IS_ERR(chip))
+		return PTR_ERR(chip);
+	ddata = pwmchip_get_drvdata(chip);
+
+	ddata->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(ddata->base))
+		return PTR_ERR(ddata->base);
+
+	clk = devm_clk_get_enabled(dev, "apb");
+	if (IS_ERR(clk))
+		return dev_err_probe(dev, PTR_ERR(clk), "Failed to get base clk\n");
+
+	ret = devm_clk_rate_exclusive_get(dev, clk);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to get exclusive rate\n");
+
+	ddata->clk_rate_hz = clk_get_rate(clk);
+	/* period = PERIOD * NSEC_PER_SEC / clk_rate_hz */
+	if (!ddata->clk_rate_hz || ddata->clk_rate_hz > NSEC_PER_SEC)
+		return dev_err_probe(dev, -EINVAL,
+				     "Invalid clock rate: %lu\n", ddata->clk_rate_hz);
+
+	rst = devm_reset_control_get_optional_shared_deasserted(dev, NULL);
+	if (IS_ERR(rst))
+		return dev_err_probe(dev, PTR_ERR(rst), "Failed to get reset\n");
+
+	chip->ops = &pwm_sg2042_ops;
+	chip->atomic = true;
+
+	ret = devm_pwmchip_add(dev, chip);
+	if (ret < 0) {
+		reset_control_assert(rst);
+		return dev_err_probe(dev, ret, "Failed to register PWM chip\n");
+	}
+
+	return 0;
+}
+
+static struct platform_driver pwm_sg2042_driver = {
+	.driver	= {
+		.name = "sg2042-pwm",
+		.of_match_table = sg2042_pwm_ids,
+	},
+	.probe = pwm_sg2042_probe,
+};
+module_platform_driver(pwm_sg2042_driver);
+
+MODULE_AUTHOR("Chen Wang");
+MODULE_DESCRIPTION("Sophgo SG2042 PWM driver");
+MODULE_LICENSE("GPL");
-- 
2.34.1


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

* [PATCH v7 3/3] riscv: sophgo: dts: add pwm controller for SG2042 SoC
  2025-02-05  6:59 [PATCH v7 0/3] pwm: Add pwm driver for Sophgo SG2042 Chen Wang
  2025-02-05  7:00 ` [PATCH v7 1/3] dt-bindings: pwm: sophgo: add PWM controller for SG2042 Chen Wang
  2025-02-05  7:01 ` [PATCH v7 2/3] pwm: sophgo: add driver for Sophgo SG2042 PWM Chen Wang
@ 2025-02-05  7:01 ` Chen Wang
  2025-02-09  1:35 ` (subset) [PATCH v7 0/3] pwm: Add pwm driver for Sophgo SG2042 Inochi Amaoto
  3 siblings, 0 replies; 9+ messages in thread
From: Chen Wang @ 2025-02-05  7:01 UTC (permalink / raw)
  To: ukleinek, robh, krzk+dt, conor+dt, unicorn_wang, inochiama,
	devicetree, linux-kernel, linux-pwm, linux-riscv, chao.wei,
	haijiao.liu, xiaoguang.xing, chunzhi.lin

From: Chen Wang <unicorn_wang@outlook.com>

SG2042 has one PWM controller, which has 4 pwm output channels.

Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
---
 arch/riscv/boot/dts/sophgo/sg2042.dtsi | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/riscv/boot/dts/sophgo/sg2042.dtsi b/arch/riscv/boot/dts/sophgo/sg2042.dtsi
index e62ac51ac55a..4449c762d663 100644
--- a/arch/riscv/boot/dts/sophgo/sg2042.dtsi
+++ b/arch/riscv/boot/dts/sophgo/sg2042.dtsi
@@ -165,6 +165,15 @@ port2a: gpio-controller@0 {
 			};
 		};
 
+		pwm: pwm@703000c000 {
+			compatible = "sophgo,sg2042-pwm";
+			reg = <0x70 0x3000c000 0x0 0x20>;
+			#pwm-cells = <3>;
+			clocks = <&clkgen GATE_CLK_APB_PWM>;
+			clock-names = "apb";
+			resets = <&rstgen RST_PWM>;
+		};
+
 		pllclk: clock-controller@70300100c0 {
 			compatible = "sophgo,sg2042-pll";
 			reg = <0x70 0x300100c0 0x0 0x40>;
-- 
2.34.1


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

* Re: [PATCH v7 2/3] pwm: sophgo: add driver for Sophgo SG2042 PWM
  2025-02-05  7:01 ` [PATCH v7 2/3] pwm: sophgo: add driver for Sophgo SG2042 PWM Chen Wang
@ 2025-02-05 10:06   ` Uwe Kleine-König
  2025-02-05 12:57     ` Chen Wang
  0 siblings, 1 reply; 9+ messages in thread
From: Uwe Kleine-König @ 2025-02-05 10:06 UTC (permalink / raw)
  To: Chen Wang
  Cc: robh, krzk+dt, conor+dt, unicorn_wang, inochiama, devicetree,
	linux-kernel, linux-pwm, linux-riscv, chao.wei, haijiao.liu,
	xiaoguang.xing, chunzhi.lin, Sean Young

[-- Attachment #1: Type: text/plain, Size: 1421 bytes --]

Hello Chen,

I was tempted to apply this patch while reading throug it until nearly
the end ...

On Wed, Feb 05, 2025 at 03:01:13PM +0800, Chen Wang wrote:
> [...]
> +static int pwm_sg2042_probe(struct platform_device *pdev)
> +{
> [...]
> +	rst = devm_reset_control_get_optional_shared_deasserted(dev, NULL);
> +	if (IS_ERR(rst))
> +		return dev_err_probe(dev, PTR_ERR(rst), "Failed to get reset\n");
> +
> +	chip->ops = &pwm_sg2042_ops;
> +	chip->atomic = true;
> +
> +	ret = devm_pwmchip_add(dev, chip);
> +	if (ret < 0) {
> +		reset_control_assert(rst);

This is wrong (well, or unneeded). With
devm_reset_control_get_optional_shared_deasserted() the devm cleanup
cares for reasserting the reset.

> +		return dev_err_probe(dev, ret, "Failed to register PWM chip\n");
> +	}
> +
> +	return 0;
> +}

If you want I can apply and squash the following in:

diff --git a/drivers/pwm/pwm-sophgo-sg2042.c b/drivers/pwm/pwm-sophgo-sg2042.c
index ce8cf8af3402..ff4639d849ce 100644
--- a/drivers/pwm/pwm-sophgo-sg2042.c
+++ b/drivers/pwm/pwm-sophgo-sg2042.c
@@ -174,10 +174,8 @@ static int pwm_sg2042_probe(struct platform_device *pdev)
 	chip->atomic = true;
 
 	ret = devm_pwmchip_add(dev, chip);
-	if (ret < 0) {
-		reset_control_assert(rst);
+	if (ret < 0)
 		return dev_err_probe(dev, ret, "Failed to register PWM chip\n");
-	}
 
 	return 0;
 }

ack?

Best regards
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v7 2/3] pwm: sophgo: add driver for Sophgo SG2042 PWM
  2025-02-05 10:06   ` Uwe Kleine-König
@ 2025-02-05 12:57     ` Chen Wang
  2025-02-05 16:33       ` Uwe Kleine-König
  0 siblings, 1 reply; 9+ messages in thread
From: Chen Wang @ 2025-02-05 12:57 UTC (permalink / raw)
  To: Uwe Kleine-König, Chen Wang
  Cc: robh, krzk+dt, conor+dt, inochiama, devicetree, linux-kernel,
	linux-pwm, linux-riscv, chao.wei, haijiao.liu, xiaoguang.xing,
	chunzhi.lin, Sean Young


On 2025/2/5 18:06, Uwe Kleine-König wrote:
> Hello Chen,
>
> I was tempted to apply this patch while reading throug it until nearly
> the end ...
>
> On Wed, Feb 05, 2025 at 03:01:13PM +0800, Chen Wang wrote:
>> [...]
>> +static int pwm_sg2042_probe(struct platform_device *pdev)
>> +{
>> [...]
>> +	rst = devm_reset_control_get_optional_shared_deasserted(dev, NULL);
>> +	if (IS_ERR(rst))
>> +		return dev_err_probe(dev, PTR_ERR(rst), "Failed to get reset\n");
>> +
>> +	chip->ops = &pwm_sg2042_ops;
>> +	chip->atomic = true;
>> +
>> +	ret = devm_pwmchip_add(dev, chip);
>> +	if (ret < 0) {
>> +		reset_control_assert(rst);
> This is wrong (well, or unneeded). With
> devm_reset_control_get_optional_shared_deasserted() the devm cleanup
> cares for reasserting the reset.
>
>> +		return dev_err_probe(dev, ret, "Failed to register PWM chip\n");
>> +	}
>> +
>> +	return 0;
>> +}
> If you want I can apply and squash the following in:
>
> diff --git a/drivers/pwm/pwm-sophgo-sg2042.c b/drivers/pwm/pwm-sophgo-sg2042.c
> index ce8cf8af3402..ff4639d849ce 100644
> --- a/drivers/pwm/pwm-sophgo-sg2042.c
> +++ b/drivers/pwm/pwm-sophgo-sg2042.c
> @@ -174,10 +174,8 @@ static int pwm_sg2042_probe(struct platform_device *pdev)
>   	chip->atomic = true;
>   
>   	ret = devm_pwmchip_add(dev, chip);
> -	if (ret < 0) {
> -		reset_control_assert(rst);
> +	if (ret < 0)
>   		return dev_err_probe(dev, ret, "Failed to register PWM chip\n");
> -	}
>   
>   	return 0;
>   }
>
> ack?
>
> Best regards
> Uwe

Ack.

Thanks,

Chen



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

* Re: [PATCH v7 2/3] pwm: sophgo: add driver for Sophgo SG2042 PWM
  2025-02-05 12:57     ` Chen Wang
@ 2025-02-05 16:33       ` Uwe Kleine-König
  2025-02-06  1:10         ` Inochi Amaoto
  0 siblings, 1 reply; 9+ messages in thread
From: Uwe Kleine-König @ 2025-02-05 16:33 UTC (permalink / raw)
  To: Chen Wang
  Cc: Chen Wang, robh, krzk+dt, conor+dt, inochiama, devicetree,
	linux-kernel, linux-pwm, linux-riscv, chao.wei, haijiao.liu,
	xiaoguang.xing, chunzhi.lin, Sean Young

[-- Attachment #1: Type: text/plain, Size: 809 bytes --]

Hello,

On Wed, Feb 05, 2025 at 08:57:20PM +0800, Chen Wang wrote:
> On 2025/2/5 18:06, Uwe Kleine-König wrote:
> > I was tempted to apply this patch while reading throug it until nearly
> > the end ...
> > 
> > > +		reset_control_assert(rst);
> > 
> > This is wrong (well, or unneeded). With
> > devm_reset_control_get_optional_shared_deasserted() the devm cleanup
> > cares for reasserting the reset.
> > 
> > > +		return dev_err_probe(dev, ret, "Failed to register PWM chip\n");
> > > +	}
> > > +
> > > +	return 0;
> > > +}
> > 
> > If you want I can apply and squash the following in:
> > 
> > [...]
> > 
> > ack?
> 
> Ack.

Great. Pushed to 

	https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm/for-next

with the suggested fixup.

Best regards
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v7 2/3] pwm: sophgo: add driver for Sophgo SG2042 PWM
  2025-02-05 16:33       ` Uwe Kleine-König
@ 2025-02-06  1:10         ` Inochi Amaoto
  0 siblings, 0 replies; 9+ messages in thread
From: Inochi Amaoto @ 2025-02-06  1:10 UTC (permalink / raw)
  To: Uwe Kleine-König, Chen Wang
  Cc: Chen Wang, robh, krzk+dt, conor+dt, inochiama, devicetree,
	linux-kernel, linux-pwm, linux-riscv, chao.wei, haijiao.liu,
	xiaoguang.xing, chunzhi.lin, Sean Young

On Wed, Feb 05, 2025 at 05:33:38PM +0100, Uwe Kleine-König wrote:
> Hello,
> 
> On Wed, Feb 05, 2025 at 08:57:20PM +0800, Chen Wang wrote:
> > On 2025/2/5 18:06, Uwe Kleine-König wrote:
> > > I was tempted to apply this patch while reading throug it until nearly
> > > the end ...
> > > 
> > > > +		reset_control_assert(rst);
> > > 
> > > This is wrong (well, or unneeded). With
> > > devm_reset_control_get_optional_shared_deasserted() the devm cleanup
> > > cares for reasserting the reset.
> > > 
> > > > +		return dev_err_probe(dev, ret, "Failed to register PWM chip\n");
> > > > +	}
> > > > +
> > > > +	return 0;
> > > > +}
> > > 
> > > If you want I can apply and squash the following in:
> > > 
> > > [...]
> > > 
> > > ack?
> > 
> > Ack.
> 
> Great. Pushed to 
> 
> 	https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm/for-next
> 
> with the suggested fixup.
> 

Good, I will take the dts next Monday.

Regards,
Inochi

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

* Re: (subset) [PATCH v7 0/3] pwm: Add pwm driver for Sophgo SG2042
  2025-02-05  6:59 [PATCH v7 0/3] pwm: Add pwm driver for Sophgo SG2042 Chen Wang
                   ` (2 preceding siblings ...)
  2025-02-05  7:01 ` [PATCH v7 3/3] riscv: sophgo: dts: add pwm controller for SG2042 SoC Chen Wang
@ 2025-02-09  1:35 ` Inochi Amaoto
  3 siblings, 0 replies; 9+ messages in thread
From: Inochi Amaoto @ 2025-02-09  1:35 UTC (permalink / raw)
  To: ukleinek, robh, krzk+dt, conor+dt, unicorn_wang, inochiama,
	devicetree, linux-kernel, linux-pwm, linux-riscv, chao.wei,
	haijiao.liu, xiaoguang.xing, chunzhi.lin, Chen Wang
  Cc: Inochi Amaoto

On Wed, 5 Feb 2025 14:59:16 +0800, Chen Wang wrote:
> From: Chen Wang <unicorn_wang@outlook.com>
> 
> Add driver for pwm controller of Sophgo SG2042 SoC.
> 
> Thanks,
> Chen
> 
> [...]

Applied to for-next, thanks!

[3/3] riscv: sophgo: dts: add pwm controller for SG2042 SoC
      https://github.com/sophgo/linux/commit/255f83ba5c16b0f79ad0c46c69b2e907012bde83

Thanks,
Inochi


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

end of thread, other threads:[~2025-02-09  1:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-05  6:59 [PATCH v7 0/3] pwm: Add pwm driver for Sophgo SG2042 Chen Wang
2025-02-05  7:00 ` [PATCH v7 1/3] dt-bindings: pwm: sophgo: add PWM controller for SG2042 Chen Wang
2025-02-05  7:01 ` [PATCH v7 2/3] pwm: sophgo: add driver for Sophgo SG2042 PWM Chen Wang
2025-02-05 10:06   ` Uwe Kleine-König
2025-02-05 12:57     ` Chen Wang
2025-02-05 16:33       ` Uwe Kleine-König
2025-02-06  1:10         ` Inochi Amaoto
2025-02-05  7:01 ` [PATCH v7 3/3] riscv: sophgo: dts: add pwm controller for SG2042 SoC Chen Wang
2025-02-09  1:35 ` (subset) [PATCH v7 0/3] pwm: Add pwm driver for Sophgo SG2042 Inochi Amaoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).