Skip to contentSkip to conversation

pwm: meson: add pwm support for S4

PATCH RESEND In review JunYi Zhao 4 participants 7 messages Oct 16, 2023 – Oct 27, 2023

Subsystems (2)
lore
Share & tools
lore

JunYi Zhao

author
#0 lore raw

PATCH RESEND v3 1/1 pwm: meson: add pwm support for S4

From: "junyi.zhao" <[email protected]>

Support PWM for S4 soc.
Now the PWM clock input is done in independent CLKCTRL registers. And no more in the PWM registers.
PWM needs to obtain an external clock source.

---
V2 -> V3:
Rebase and Review the latest upstream code again.
After reconstruction, stick to the previous code as much as possible.

 drivers/pwm/pwm-meson.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/pwm/pwm-meson.c +19 -0
index 25519cddc2a9..fe9fd75747c4 100644
@@ -99,6 +99,7 @@ struct meson_pwm_channel {
 struct meson_pwm_data {
 	const char * const *parent_names;
 	unsigned int num_parents;
+	unsigned int extern_clk;
 };
 
 struct meson_pwm {
@@ -396,6 +397,10 @@ static const struct meson_pwm_data pwm_g12a_ao_cd_data = {
 	.num_parents = ARRAY_SIZE(pwm_g12a_ao_cd_parent_names),
 };
 
+static const struct meson_pwm_data pwm_s4_data = {
+	.extern_clk = true,
+};
+
 static const struct of_device_id meson_pwm_matches[] = {
 	{
 		.compatible = "amlogic,meson8b-pwm",
@@ -429,6 +434,10 @@ static const struct of_device_id meson_pwm_matches[] = {
 		.compatible = "amlogic,meson-g12a-ao-pwm-cd",
 		.data = &pwm_g12a_ao_cd_data
 	},
+	{
+		.compatible = "amlogic,s4-pwm",
+		.data = &pwm_s4_data,
+	},
 	{},
 };
 MODULE_DEVICE_TABLE(of, meson_pwm_matches);
@@ -451,6 +460,16 @@ static int meson_pwm_init_channels(struct meson_pwm *meson)
 		struct clk_parent_data div_parent = {}, gate_parent = {};
 		struct clk_init_data init = {};
 
+		if (meson->data->extern_clk) {
+			snprintf(name, sizeof(name), "clkin%u", i);
+			channel->clk = devm_clk_get(dev, name);
+			if (IS_ERR(channel->clk)) {
+				dev_err(meson->chip.dev, "can't get device clock\n");
+				return PTR_ERR(channel->clk);
+			}
+			continue;
+		}
+
 		snprintf(name, sizeof(name), "%s#mux%u", dev_name(dev), i);
 
 		init.name = name;

base-commit: 4d2c646ac07cf4a35ef1c4a935a1a4fd6c6b1a36

Signature · 7 lines
2.41.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#1 lore raw

Hi JunYi

Quoted 50 lines · JunYi Zhao

From: "junyi.zhao" <[email protected]>

Support PWM for S4 soc.
Now the PWM clock input is done in independent CLKCTRL registers. And no more in the PWM registers.
PWM needs to obtain an external clock source.

---
V2 -> V3:
Rebase and Review the latest upstream code again.
After reconstruction, stick to the previous code as much as possible.

 drivers/pwm/pwm-meson.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/pwm/pwm-meson.c +9 -0
index 25519cddc2a9..fe9fd75747c4 100644
@@ -99,6 +99,7 @@ struct meson_pwm_channel {
 struct meson_pwm_data {
 	const char * const *parent_names;
 	unsigned int num_parents;
+	unsigned int extern_clk;
 };
 
 struct meson_pwm {
@@ -396,6 +397,10 @@ static const struct meson_pwm_data pwm_g12a_ao_cd_data = {
 	.num_parents = ARRAY_SIZE(pwm_g12a_ao_cd_parent_names),
 };
 
+static const struct meson_pwm_data pwm_s4_data = {
+	.extern_clk = true,
+};
+
 static const struct of_device_id meson_pwm_matches[] = {
 	{
 		.compatible = "amlogic,meson8b-pwm",
@@ -429,6 +434,10 @@ static const struct of_device_id meson_pwm_matches[] = {
 		.compatible = "amlogic,meson-g12a-ao-pwm-cd",
 		.data = &pwm_g12a_ao_cd_data
 	},
+	{
+		.compatible = "amlogic,s4-pwm",
+		.data = &pwm_s4_data,
+	},
 	{},
 };
 MODULE_DEVICE_TABLE(of, meson_pwm_matches);

drivers/pwm/pwm-meson.c static int meson_pwm_init_channels(struct meson_pwm *meson) · line 465

Quoted 6 lines
drivers/pwm/pwm-meson.c +3 -0
@@ -451,6 +460,16 @@ static int meson_pwm_init_channels(struct meson_pwm *meson)
 		struct clk_parent_data div_parent = {}, gate_parent = {};
 		struct clk_init_data init = {};
 
+		if (meson->data->extern_clk) {
+			snprintf(name, sizeof(name), "clkin%u", i);
+			channel->clk = devm_clk_get(dev, name);

use devm_clk_get_optional() which would save you from introducing the 'extern_clk' variable

Quoted 20 lines
drivers/pwm/pwm-meson.c +7 -0
+			if (IS_ERR(channel->clk)) {
+				dev_err(meson->chip.dev, "can't get device clock\n");
+				return PTR_ERR(channel->clk);
+			}
+			continue;
+		}
+
 		snprintf(name, sizeof(name), "%s#mux%u", dev_name(dev), i);
 
 		init.name = name;

base-commit: 4d2c646ac07cf4a35ef1c4a935a1a4fd6c6b1a36

Signature · 7 lines
2.41.0


_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
Signature · 3 lines
Yixun Lan (dlan)
Gentoo Linux Developer
GPG Key ID AABEFD55
#2 lore raw

Hello Yixun Lan

Quoted 56 lines · Yixun Lan

Hi JunYi

Quoted 53 lines · JunYi Zhao

From: "junyi.zhao" <[email protected]>

Support PWM for S4 soc.
Now the PWM clock input is done in independent CLKCTRL registers. And no more in the PWM registers.
PWM needs to obtain an external clock source.

---
V2 -> V3:
Rebase and Review the latest upstream code again.
After reconstruction, stick to the previous code as much as possible.

  drivers/pwm/pwm-meson.c | 19 +++++++++++++++++++
  1 file changed, 19 insertions(+)
drivers/pwm/pwm-meson.c +9 -0
index 25519cddc2a9..fe9fd75747c4 100644
@@ -99,6 +99,7 @@ struct meson_pwm_channel {
  struct meson_pwm_data {
  	const char * const *parent_names;
  	unsigned int num_parents;
+	unsigned int extern_clk;
  };
 
  struct meson_pwm {
@@ -396,6 +397,10 @@ static const struct meson_pwm_data pwm_g12a_ao_cd_data = {
  	.num_parents = ARRAY_SIZE(pwm_g12a_ao_cd_parent_names),
  };
 
+static const struct meson_pwm_data pwm_s4_data = {
+	.extern_clk = true,
+};
+
  static const struct of_device_id meson_pwm_matches[] = {
  	{
  		.compatible = "amlogic,meson8b-pwm",
@@ -429,6 +434,10 @@ static const struct of_device_id meson_pwm_matches[] = {
  		.compatible = "amlogic,meson-g12a-ao-pwm-cd",
  		.data = &pwm_g12a_ao_cd_data
  	},
+	{
+		.compatible = "amlogic,s4-pwm",
+		.data = &pwm_s4_data,
+	},
  	{},
  };
  MODULE_DEVICE_TABLE(of, meson_pwm_matches);
@@ -451,6 +460,16 @@ static int meson_pwm_init_channels(struct meson_pwm *meson)
  		struct clk_parent_data div_parent = {}, gate_parent = {};
  		struct clk_init_data init = {};
 
Quoted 5 lines

drivers/pwm/pwm-meson.c static int meson_pwm_init_channels(struct meson_pwm *meson) · line 465

Quoted 3 lines
drivers/pwm/pwm-meson.c +3 -0
+		if (meson->data->extern_clk) {
+			snprintf(name, sizeof(name), "clkin%u", i);
+			channel->clk = devm_clk_get(dev, name);

use devm_clk_get_optional() which would save you from introducing the 'extern_clk' variable

On S4 and other recent chips PWM clock resides in separate IP and it must be provided to driver in order to control PWM frequency. So this clock is not optional.

Quoted 22 lines
Quoted 21 lines
drivers/pwm/pwm-meson.c +7 -0
+			if (IS_ERR(channel->clk)) {
+				dev_err(meson->chip.dev, "can't get device clock\n");
+				return PTR_ERR(channel->clk);
+			}
+			continue;
+		}
+
  		snprintf(name, sizeof(name), "%s#mux%u", dev_name(dev), i);
 
  		init.name = name;

base-commit: 4d2c646ac07cf4a35ef1c4a935a1a4fd6c6b1a36

Signature · 7 lines
2.41.0


_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
Signature · 2 lines
Best regards
George
author
#3 lore raw

Hello YiXun,
CLK config has been separated on HW. No more in pwmchip.
And s4 datasheet about clk updated already.

Quoted 103 lines · George Stark

[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]

[ EXTERNAL EMAIL ]

Hello Yixun Lan

Quoted 59 lines · Yixun Lan

Hi JunYi

Quoted 56 lines · JunYi Zhao

From: "junyi.zhao" <[email protected]>

Support PWM for S4 soc.
Now the PWM clock input is done in independent CLKCTRL registers. And no more in the PWM registers.
PWM needs to obtain an external clock source.

---
V2 -> V3:
Rebase and Review the latest upstream code again.
After reconstruction, stick to the previous code as much as possible. drivers/pwm/pwm-meson.c | 19 +++++++++++++++++++

  1 file changed, 19 insertions(+)
drivers/pwm/pwm-meson.c +5 -0
index 25519cddc2a9..fe9fd75747c4 100644
@@ -99,6 +99,7 @@ struct meson_pwm_channel {
   struct meson_pwm_data {
      const char * const *parent_names;
      unsigned int num_parents;
+    unsigned int extern_clk;
   };
 
   struct meson_pwm {
@@ -396,6 +397,10 @@ static const struct meson_pwm_data 
 pwm_g12a_ao_cd_data = {
      .num_parents = ARRAY_SIZE(pwm_g12a_ao_cd_parent_names),
   };
 
+static const struct meson_pwm_data pwm_s4_data = {
+    .extern_clk = true,
+};
+
   static const struct of_device_id meson_pwm_matches[] = {
      {

             .compatible = "amlogic,meson8b-pwm",

drivers/pwm/pwm-meson.c +0 -0
@@ -429,6 +434,10 @@ static const struct of_device_id 
 meson_pwm_matches[] = {
              .compatible = "amlogic,meson-g12a-ao-pwm-cd",

             .data = &pwm_g12a_ao_cd_data
     },
+    {
+            .compatible = "amlogic,s4-pwm",
+            .data = &pwm_s4_data,
+    },
     {},
  };
  MODULE_DEVICE_TABLE(of, meson_pwm_matches);

drivers/pwm/pwm-meson.c +0 -0
@@ -451,6 +460,16 @@ static int meson_pwm_init_channels(struct 
 meson_pwm *meson)
              struct clk_parent_data div_parent = {}, gate_parent = {};
              struct clk_init_data init = {};
 
Quoted 5 lines

drivers/pwm/pwm-meson.c static int meson_pwm_init_channels(struct meson_pwm *meson) · line 465

Quoted 3 lines
drivers/pwm/pwm-meson.c +3 -0
+            if (meson->data->extern_clk) {
+                    snprintf(name, sizeof(name), "clkin%u", i);
+                    channel->clk = devm_clk_get(dev, name);

use devm_clk_get_optional() which would save you from introducing the 'extern_clk' variable

On S4 and other recent chips PWM clock resides in separate IP and it must be provided to driver in order to control PWM frequency. So this clock is not optional.

Quoted 23 lines
Quoted 22 lines
drivers/pwm/pwm-meson.c +7 -0
+                    if (IS_ERR(channel->clk)) {
+                            dev_err(meson->chip.dev, "can't get 
 device clock\n");
+                            return PTR_ERR(channel->clk);
+                    }
+                    continue;
+            }
+
              snprintf(name, sizeof(name), "%s#mux%u", dev_name(dev), i);

             init.name = name;

base-commit: 4d2c646ac07cf4a35ef1c4a935a1a4fd6c6b1a36

Signature · 7 lines
2.41.0


_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
Signature · 2 lines
Best regards
George
#4 lore raw
In reply to JunYi Zhao

Hello JunYi Zhao

Quoted 20 lines · JunYi Zhao

From: "junyi.zhao" <[email protected]>

Support PWM for S4 soc.
Now the PWM clock input is done in independent CLKCTRL registers. And no more in the PWM registers.
PWM needs to obtain an external clock source.

---
V2 -> V3:
Rebase and Review the latest upstream code again.
After reconstruction, stick to the previous code as much as possible.

  drivers/pwm/pwm-meson.c | 19 +++++++++++++++++++
  1 file changed, 19 insertions(+)
drivers/pwm/pwm-meson.c +0 -0
index 25519cddc2a9..fe9fd75747c4 100644

drivers/pwm/pwm-meson.c struct meson_pwm_channel { · line 102

Quoted 4 lines
drivers/pwm/pwm-meson.c +1 -0
@@ -99,6 +99,7 @@ struct meson_pwm_channel {
  struct meson_pwm_data {
  	const char * const *parent_names;
  	unsigned int num_parents;
+	unsigned int extern_clk;

may be bool extern_clk;

Quoted 44 lines
drivers/pwm/pwm-meson.c +18 -0
  };
 
  struct meson_pwm {
@@ -396,6 +397,10 @@ static const struct meson_pwm_data pwm_g12a_ao_cd_data = {
  	.num_parents = ARRAY_SIZE(pwm_g12a_ao_cd_parent_names),
  };
 
+static const struct meson_pwm_data pwm_s4_data = {
+	.extern_clk = true,
+};
+
  static const struct of_device_id meson_pwm_matches[] = {
  	{
  		.compatible = "amlogic,meson8b-pwm",
@@ -429,6 +434,10 @@ static const struct of_device_id meson_pwm_matches[] = {
  		.compatible = "amlogic,meson-g12a-ao-pwm-cd",
  		.data = &pwm_g12a_ao_cd_data
  	},
+	{
+		.compatible = "amlogic,s4-pwm",
+		.data = &pwm_s4_data,
+	},
  	{},
  };
  MODULE_DEVICE_TABLE(of, meson_pwm_matches);
@@ -451,6 +460,16 @@ static int meson_pwm_init_channels(struct meson_pwm *meson)
  		struct clk_parent_data div_parent = {}, gate_parent = {};
  		struct clk_init_data init = {};
 
+		if (meson->data->extern_clk) {
+			snprintf(name, sizeof(name), "clkin%u", i);
+			channel->clk = devm_clk_get(dev, name);
+			if (IS_ERR(channel->clk)) {
+				dev_err(meson->chip.dev, "can't get device clock\n");
+				return PTR_ERR(channel->clk);
+			}
+			continue;
+		}
+
  		snprintf(name, sizeof(name), "%s#mux%u", dev_name(dev), i);
 
  		init.name = name;

base-commit: 4d2c646ac07cf4a35ef1c4a935a1a4fd6c6b1a36

Signature · 2 lines
Best regards
George
author
#5 lore raw

Hi George, thank u for your review.
I will change it.

Quoted 77 lines · George Stark

[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]

[ EXTERNAL EMAIL ]

Hello JunYi Zhao

Quoted 20 lines · JunYi Zhao

From: "junyi.zhao" <[email protected]>

Support PWM for S4 soc.
Now the PWM clock input is done in independent CLKCTRL registers. And no more in the PWM registers.
PWM needs to obtain an external clock source.

---
V2 -> V3:
Rebase and Review the latest upstream code again.
After reconstruction, stick to the previous code as much as possible. drivers/pwm/pwm-meson.c | 19 +++++++++++++++++++

  1 file changed, 19 insertions(+)
drivers/pwm/pwm-meson.c +0 -0
index 25519cddc2a9..fe9fd75747c4 100644

drivers/pwm/pwm-meson.c struct meson_pwm_channel { · line 102

Quoted 4 lines
drivers/pwm/pwm-meson.c +1 -0
@@ -99,6 +99,7 @@ struct meson_pwm_channel {
   struct meson_pwm_data {
       const char * const *parent_names;
       unsigned int num_parents;
+     unsigned int extern_clk;

may be bool extern_clk;

Quoted 45 lines
drivers/pwm/pwm-meson.c +4 -0
   };
 
   struct meson_pwm {
@@ -396,6 +397,10 @@ static const struct meson_pwm_data 
 pwm_g12a_ao_cd_data = {
       .num_parents = ARRAY_SIZE(pwm_g12a_ao_cd_parent_names),
   };
 
+static const struct meson_pwm_data pwm_s4_data = {
+     .extern_clk = true,
+};
+
   static const struct of_device_id meson_pwm_matches[] = {
       {

              .compatible = "amlogic,meson8b-pwm",

drivers/pwm/pwm-meson.c +0 -0
@@ -429,6 +434,10 @@ static const struct of_device_id 
 meson_pwm_matches[] = {
               .compatible = "amlogic,meson-g12a-ao-pwm-cd",

              .data = &pwm_g12a_ao_cd_data
      },
+     {
+             .compatible = "amlogic,s4-pwm",
+             .data = &pwm_s4_data,
+     },
      {},
  };
  MODULE_DEVICE_TABLE(of, meson_pwm_matches);

drivers/pwm/pwm-meson.c +10 -0
@@ -451,6 +460,16 @@ static int meson_pwm_init_channels(struct 
 meson_pwm *meson)
               struct clk_parent_data div_parent = {}, gate_parent = {};
               struct clk_init_data init = {};
 
+             if (meson->data->extern_clk) {
+                     snprintf(name, sizeof(name), "clkin%u", i);
+                     channel->clk = devm_clk_get(dev, name);
+                     if (IS_ERR(channel->clk)) {
+                             dev_err(meson->chip.dev, "can't get 
 device clock\n");
+                             return PTR_ERR(channel->clk);
+                     }
+                     continue;
+             }
+
               snprintf(name, sizeof(name), "%s#mux%u", dev_name(dev), i);
Quoted 7 lines
Quoted 3 lines

              init.name = name;

base-commit: 4d2c646ac07cf4a35ef1c4a935a1a4fd6c6b1a36

Signature · 2 lines
Best regards
George

_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic

reviewer
#6 lore raw
In reply to George Stark
Quoted 44 lines · George Stark

Hello JunYi Zhao

Quoted 17 lines · JunYi Zhao

From: "junyi.zhao" <[email protected]>
Support PWM for S4 soc.
Now the PWM clock input is done in independent CLKCTRL registers. And no more in the PWM registers.
PWM needs to obtain an external clock source.

---
V2 -> V3:
Rebase and Review the latest upstream code again.
After reconstruction, stick to the previous code as much as possible.

  drivers/pwm/pwm-meson.c | 19 +++++++++++++++++++
  1 file changed, 19 insertions(+)
drivers/pwm/pwm-meson.c +0 -0
index 25519cddc2a9..fe9fd75747c4 100644

drivers/pwm/pwm-meson.c struct meson_pwm_channel { · line 102

Quoted 4 lines
drivers/pwm/pwm-meson.c +1 -0
@@ -99,6 +99,7 @@ struct meson_pwm_channel {
  struct meson_pwm_data {
  	const char * const *parent_names;
  	unsigned int num_parents;
+	unsigned int extern_clk;

may be bool extern_clk;

Quoted 19 lines
drivers/pwm/pwm-meson.c +6 -0
  };
    struct meson_pwm {
@@ -396,6 +397,10 @@ static const struct meson_pwm_data pwm_g12a_ao_cd_data = {
  	.num_parents = ARRAY_SIZE(pwm_g12a_ao_cd_parent_names),
  };
  +static const struct meson_pwm_data pwm_s4_data = {
+	.extern_clk = true,
+};
+
  static const struct of_device_id meson_pwm_matches[] = {
  	{
  		.compatible = "amlogic,meson8b-pwm",
@@ -429,6 +434,10 @@ static const struct of_device_id meson_pwm_matches[] = {
  		.compatible = "amlogic,meson-g12a-ao-pwm-cd",
  		.data = &pwm_g12a_ao_cd_data
  	},
+	{
+		.compatible = "amlogic,s4-pwm",
+		.data = &pwm_s4_data,
Quoted 8 lines

drivers/pwm/pwm-meson.c static int meson_pwm_init_channels(struct meson_pwm *meson) · line 462

Quoted 8 lines
drivers/pwm/pwm-meson.c +1 -0
+	},
  	{},
  };
  MODULE_DEVICE_TABLE(of, meson_pwm_matches);
@@ -451,6 +460,16 @@ static int meson_pwm_init_channels(struct meson_pwm *meson)
  		struct clk_parent_data div_parent = {}, gate_parent = {};
  		struct clk_init_data init = {};
  +		if (meson->data->extern_clk) {

Instead of hacking through the existing registration function, it be much better to provide the clock registration function as on ops in dt data.

Also, as Neil pointed out on the v2 [1], the meaning of clkin0/1 is changed on this SoC.
* On previous SoC, it was a reference to clock input the PWM block should select from the hard-coded list it has (should fix that someday)
* Now it is directly the input the PWM block must claim.

You need to update the bindings accordingly for the S4

[1]: https://lore.kernel.org/linux-amlogic/[email protected]

Quoted 12 lines
Quoted 12 lines
drivers/pwm/pwm-meson.c +9 -0
+			snprintf(name, sizeof(name), "clkin%u", i);
+			channel->clk = devm_clk_get(dev, name);
+			if (IS_ERR(channel->clk)) {
+				dev_err(meson->chip.dev, "can't get device clock\n");
+				return PTR_ERR(channel->clk);
+			}
+			continue;
+		}
+
  		snprintf(name, sizeof(name), "%s#mux%u", dev_name(dev), i);
    		init.name = name;

base-commit: 4d2c646ac07cf4a35ef1c4a935a1a4fd6c6b1a36