Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH 0/3] Add power sequence for Amlogic WCN chips
@ 2024-07-05 11:13 Yang Li via B4 Relay
  2024-07-05 11:13 ` [PATCH 1/3] dt-bindings: power: Add power sequence for Amloigc " Yang Li via B4 Relay
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Yang Li via B4 Relay @ 2024-07-05 11:13 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Bartosz Golaszewski
  Cc: devicetree, linux-kernel, linux-pm, Yang Li

Add Amlogic WCN power sequence, including dt-binding, power sequence
provider with Amlogic, and enable POWER_SEQUENCING_AML_WCN in defconfig.

Signed-off-by: Yang Li <yang.li@amlogic.com>
---
Yang Li (3):
      dt-bindings: power: Add power sequence for Amloigc WCN chips
      power: sequenceing: Add power sequence for Amlogic WCN chips
      MAINTAINERS: Add an entry for Amlogic WCN power sequence

 .../bindings/power/amlogic,w155s2-pwrseq.yaml      |  62 ++++++
 MAINTAINERS                                        |   8 +
 drivers/power/sequencing/Kconfig                   |   7 +
 drivers/power/sequencing/Makefile                  |   1 +
 drivers/power/sequencing/pwrseq-aml-wcn.c          | 209 +++++++++++++++++++++
 5 files changed, 287 insertions(+)
---
base-commit: 0b58e108042b0ed28a71cd7edf5175999955b233
change-id: 20240701-pwrseq-2c7db60f7ad1

Best regards,
-- 
Yang Li <yang.li@amlogic.com>



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

* [PATCH 1/3] dt-bindings: power: Add power sequence for Amloigc WCN chips
  2024-07-05 11:13 [PATCH 0/3] Add power sequence for Amlogic WCN chips Yang Li via B4 Relay
@ 2024-07-05 11:13 ` Yang Li via B4 Relay
  2024-07-05 13:34   ` Bartosz Golaszewski
  2024-07-07 12:59   ` Krzysztof Kozlowski
  2024-07-05 11:13 ` [PATCH 2/3] power: sequenceing: Add power sequence for Amlogic " Yang Li via B4 Relay
  2024-07-05 11:13 ` [PATCH 3/3] MAINTAINERS: Add an entry for Amlogic WCN power sequence Yang Li via B4 Relay
  2 siblings, 2 replies; 20+ messages in thread
From: Yang Li via B4 Relay @ 2024-07-05 11:13 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Bartosz Golaszewski
  Cc: devicetree, linux-kernel, linux-pm, Yang Li

From: Yang Li <yang.li@amlogic.com>

Add binding document to introduce power sequence of
Amlogic WCN chips.

Signed-off-by: Yang Li <yang.li@amlogic.com>
---
 .../bindings/power/amlogic,w155s2-pwrseq.yaml      | 62 ++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/Documentation/devicetree/bindings/power/amlogic,w155s2-pwrseq.yaml b/Documentation/devicetree/bindings/power/amlogic,w155s2-pwrseq.yaml
new file mode 100644
index 000000000000..f99a775fcf9b
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/amlogic,w155s2-pwrseq.yaml
@@ -0,0 +1,62 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/power/amlogic,w155s2-pwrseq.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Amlogic power sequence for WCN chips
+
+maintainers:
+  - Yang Li <yang.li@amlogic.com>
+
+description:
+  The Amlogic WCN chip contains discrete modules for WLAN and Bluetooth. Power on
+  Bluetooth and Wi-Fi respectively, including chip_en pull-up and bt_en pull-up,
+  and generation of the 32.768KHz clock.
+
+properties:
+  compatible:
+    oneOf:
+      - const: amlogic,w155s2-pwrseq
+      - items:
+          - enum:
+              - amlogic,w265s1-pwrseq
+              - amlogic,w265p1-pwrseq
+              - amlogic,w265s2-pwrseq
+          - const: amlogic,w155s2-pwrseq
+
+  clocks:
+    maxItems: 1
+    description: clock provided to the controller (32.768KHz)
+
+  clock-names:
+    items:
+      - const: ext_clock
+
+  amlogic,chip-enable-gpios:
+    maxItems: 1
+    description: gpio specifier used to enable chipset
+
+  amlogic,bt-enable-gpios:
+    maxItems: 1
+    description: gpio specifier used to enable BT
+
+required:
+  - compatible
+  - clocks
+  - clock-names
+  - amlogic,chip-enable-gpios
+  - amlogic,bt-enable-gpios
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    wcn_pwrseq {
+        compatible = "amlogic,w155s2-pwrseq";
+        clocks = <&extclk>;
+        clock-names = "ext_clock";
+        amlogic,chip-enable-gpios = <&gpio 7 GPIO_ACTIVE_HIGH>;
+        amlogic,bt-enable-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>;
+    };

-- 
2.42.0



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

* [PATCH 2/3] power: sequenceing: Add power sequence for Amlogic WCN chips
  2024-07-05 11:13 [PATCH 0/3] Add power sequence for Amlogic WCN chips Yang Li via B4 Relay
  2024-07-05 11:13 ` [PATCH 1/3] dt-bindings: power: Add power sequence for Amloigc " Yang Li via B4 Relay
@ 2024-07-05 11:13 ` Yang Li via B4 Relay
  2024-07-05 13:46   ` Bartosz Golaszewski
  2024-07-07 13:02   ` Krzysztof Kozlowski
  2024-07-05 11:13 ` [PATCH 3/3] MAINTAINERS: Add an entry for Amlogic WCN power sequence Yang Li via B4 Relay
  2 siblings, 2 replies; 20+ messages in thread
From: Yang Li via B4 Relay @ 2024-07-05 11:13 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Bartosz Golaszewski
  Cc: devicetree, linux-kernel, linux-pm, Yang Li

From: Yang Li <yang.li@amlogic.com>

Add power sequence for Bluetooth and Wi-Fi respectively, including chip_en
pull-up and bt_en pull-up, and generation of the 32.768 clock.

Signed-off-by: Yang Li <yang.li@amlogic.com>
---
 drivers/power/sequencing/Kconfig          |   7 +
 drivers/power/sequencing/Makefile         |   1 +
 drivers/power/sequencing/pwrseq-aml-wcn.c | 209 ++++++++++++++++++++++++++++++
 3 files changed, 217 insertions(+)

diff --git a/drivers/power/sequencing/Kconfig b/drivers/power/sequencing/Kconfig
index c9f1cdb66524..65d3b2c20bfb 100644
--- a/drivers/power/sequencing/Kconfig
+++ b/drivers/power/sequencing/Kconfig
@@ -26,4 +26,11 @@ config POWER_SEQUENCING_QCOM_WCN
 	  this driver is needed for correct power control or else we'd risk not
 	  respecting the required delays between enabling Bluetooth and WLAN.
 
+config POWER_SEQUENCING_AML_WCN
+	tristate "Amlogic WCN family PMU driver"
+	default m if ARCH_MESON
+	help
+	  Say Y here to enable the power sequencing driver for Amlogic
+	  WCN Bluetooth/WLAN chipsets.
+
 endif
diff --git a/drivers/power/sequencing/Makefile b/drivers/power/sequencing/Makefile
index 2eec2df7912d..32706daf8f0f 100644
--- a/drivers/power/sequencing/Makefile
+++ b/drivers/power/sequencing/Makefile
@@ -4,3 +4,4 @@ obj-$(CONFIG_POWER_SEQUENCING)		+= pwrseq-core.o
 pwrseq-core-y				:= core.o
 
 obj-$(CONFIG_POWER_SEQUENCING_QCOM_WCN)	+= pwrseq-qcom-wcn.o
+obj-$(CONFIG_POWER_SEQUENCING_AML_WCN)	+= pwrseq-aml-wcn.o
diff --git a/drivers/power/sequencing/pwrseq-aml-wcn.c b/drivers/power/sequencing/pwrseq-aml-wcn.c
new file mode 100644
index 000000000000..6f5bfcf60b9c
--- /dev/null
+++ b/drivers/power/sequencing/pwrseq-aml-wcn.c
@@ -0,0 +1,209 @@
+// SPDX-License-Identifier: (GPL-2.0-only OR MIT)
+/*
+ * Copyright (C) 2024 Amlogic, Inc. All rights reserved
+ */
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/gpio.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_device.h>
+#include <linux/pwrseq/provider.h>
+#include <linux/string.h>
+#include <linux/types.h>
+
+struct pwrseq_aml_wcn_ctx {
+	struct pwrseq_device *pwrseq;
+	int bt_enable_gpio;
+	int chip_enable_gpio;
+	struct clk *lpo_clk;
+	unsigned int pwr_count;
+};
+
+static DEFINE_MUTEX(pwrseq_lock);
+
+static int pwrseq_aml_wcn_chip_enable(struct pwrseq_device *pwrseq)
+{
+	struct pwrseq_aml_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
+	int err;
+
+	mutex_lock(&pwrseq_lock);
+	if (ctx->pwr_count == 0) {
+		gpio_request(ctx->chip_enable_gpio, "chip-enable-gpios");
+		gpio_direction_output(ctx->chip_enable_gpio, 1);
+		gpio_free(ctx->chip_enable_gpio);
+
+		if (!IS_ERR(ctx->lpo_clk)) {
+			err = clk_prepare_enable(ctx->lpo_clk);
+			if (err) {
+				mutex_unlock(&pwrseq_lock);
+				return err;
+			}
+		}
+	}
+
+	ctx->pwr_count++;
+	mutex_unlock(&pwrseq_lock);
+	return 0;
+}
+
+static int pwrseq_aml_wcn_chip_disable(struct pwrseq_device *pwrseq)
+{
+	struct pwrseq_aml_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
+
+	mutex_lock(&pwrseq_lock);
+	if (--ctx->pwr_count == 0) {
+		gpio_request(ctx->chip_enable_gpio, "chip-enable-gpios");
+		gpio_direction_output(ctx->chip_enable_gpio, 0);
+		gpio_free(ctx->chip_enable_gpio);
+
+		if (!IS_ERR(ctx->lpo_clk))
+			clk_disable_unprepare(ctx->lpo_clk);
+	}
+
+	mutex_unlock(&pwrseq_lock);
+	return 0;
+}
+
+static const struct pwrseq_unit_data pwrseq_aml_wcn_chip_power_unit_data = {
+	.name = "chip-enable",
+	.enable = pwrseq_aml_wcn_chip_enable,
+	.disable = pwrseq_aml_wcn_chip_disable,
+};
+
+static const struct pwrseq_unit_data *pwrseq_aml_wcn_unit_deps[] = {
+	&pwrseq_aml_wcn_chip_power_unit_data,
+	NULL
+};
+
+static int pwrseq_aml_wcn_bt_enable(struct pwrseq_device *pwrseq)
+{
+	struct pwrseq_aml_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
+
+	gpio_request(ctx->bt_enable_gpio, "bt-enable-gpios");
+	gpio_direction_output(ctx->bt_enable_gpio, 1);
+	gpio_free(ctx->bt_enable_gpio);
+
+	/* wait 100ms for bluetooth controller power on  */
+	msleep(100);
+
+	return 0;
+}
+
+static int pwrseq_aml_wcn_bt_disable(struct pwrseq_device *pwrseq)
+{
+	struct pwrseq_aml_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
+
+	gpio_request(ctx->bt_enable_gpio, "bt-enable-gpios");
+	gpio_direction_output(ctx->bt_enable_gpio, 0);
+	gpio_free(ctx->bt_enable_gpio);
+
+	return 0;
+}
+
+static const struct pwrseq_unit_data pwrseq_aml_wcn_bt_unit_data = {
+	.name = "bluetooth-enable",
+	.deps = pwrseq_aml_wcn_unit_deps,
+	.enable = pwrseq_aml_wcn_bt_enable,
+	.disable = pwrseq_aml_wcn_bt_disable,
+};
+
+static const struct pwrseq_unit_data pwrseq_aml_wcn_wlan_unit_data = {
+	.name = "wlan-enable",
+	.deps = pwrseq_aml_wcn_unit_deps,
+};
+
+static const struct pwrseq_target_data pwrseq_aml_wcn_bt_target_data = {
+	.name = "bluetooth",
+	.unit = &pwrseq_aml_wcn_bt_unit_data,
+};
+
+static const struct pwrseq_target_data pwrseq_aml_wcn_wlan_target_data = {
+	.name = "wlan",
+	.unit = &pwrseq_aml_wcn_wlan_unit_data,
+};
+
+static const struct pwrseq_target_data *pwrseq_aml_wcn_targets[] = {
+	&pwrseq_aml_wcn_bt_target_data,
+	&pwrseq_aml_wcn_wlan_target_data,
+	NULL
+};
+
+static int pwrseq_aml_wcn_match(struct pwrseq_device *pwrseq,
+				 struct device *dev)
+{
+	struct device_node *dev_node = dev->of_node;
+
+	if (!of_property_present(dev_node, "amlogic,wcn-pwrseq"))
+		return 0;
+
+	return 1;
+}
+
+static int pwrseq_aml_wcn_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct pwrseq_aml_wcn_ctx *ctx;
+	struct pwrseq_config config;
+
+	ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+	if (!ctx)
+		return -ENOMEM;
+
+	ctx->bt_enable_gpio = of_get_named_gpio(dev->of_node,
+					       "amlogic,bt-enable-gpios", 0);
+	if (!gpio_is_valid(ctx->bt_enable_gpio))
+		return dev_err_probe(dev, ctx->bt_enable_gpio,
+				"Failed to get the bt enable GPIO");
+
+	ctx->chip_enable_gpio = of_get_named_gpio(dev->of_node,
+					       "amlogic,chip-enable-gpios", 0);
+	if (!gpio_is_valid(ctx->chip_enable_gpio))
+		return dev_err_probe(dev, ctx->bt_enable_gpio,
+					"Failed to get the chip enable GPIO");
+
+	ctx->lpo_clk = devm_clk_get_optional(dev, NULL);
+	if (IS_ERR(ctx->lpo_clk))
+		return dev_err_probe(dev, PTR_ERR(ctx->lpo_clk),
+				"Failed to get the clock source");
+
+	memset(&config, 0, sizeof(config));
+
+	config.parent = dev;
+	config.owner = THIS_MODULE;
+	config.drvdata = ctx;
+	config.match = pwrseq_aml_wcn_match;
+	config.targets = pwrseq_aml_wcn_targets;
+
+	ctx->pwr_count = 0;
+	ctx->pwrseq = devm_pwrseq_device_register(dev, &config);
+	if (IS_ERR(ctx->pwrseq))
+		return dev_err_probe(dev, PTR_ERR(ctx->pwrseq),
+				     "Failed to register the power sequencer\n");
+
+	return 0;
+}
+
+static const struct of_device_id pwrseq_aml_wcn_of_match[] = {
+	{ .compatible = "amlogic,w155s2-pwrseq" },
+	{ /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, pwrseq_aml_wcn_of_match);
+
+static struct platform_driver pwrseq_aml_wcn_driver = {
+	.driver = {
+		.name = "pwrseq-aml_wcn",
+		.of_match_table = pwrseq_aml_wcn_of_match,
+	},
+	.probe = pwrseq_aml_wcn_probe,
+};
+module_platform_driver(pwrseq_aml_wcn_driver);
+
+MODULE_AUTHOR("Yang Li <yang.li@amlogic.com>");
+MODULE_DESCRIPTION("Amlogic WCN PMU power sequencing driver");
+MODULE_LICENSE("GPL");

-- 
2.42.0



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

* [PATCH 3/3] MAINTAINERS: Add an entry for Amlogic WCN power sequence
  2024-07-05 11:13 [PATCH 0/3] Add power sequence for Amlogic WCN chips Yang Li via B4 Relay
  2024-07-05 11:13 ` [PATCH 1/3] dt-bindings: power: Add power sequence for Amloigc " Yang Li via B4 Relay
  2024-07-05 11:13 ` [PATCH 2/3] power: sequenceing: Add power sequence for Amlogic " Yang Li via B4 Relay
@ 2024-07-05 11:13 ` Yang Li via B4 Relay
  2024-07-07 13:04   ` Krzysztof Kozlowski
  2 siblings, 1 reply; 20+ messages in thread
From: Yang Li via B4 Relay @ 2024-07-05 11:13 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Bartosz Golaszewski
  Cc: devicetree, linux-kernel, linux-pm, Yang Li

From: Yang Li <yang.li@amlogic.com>

Add an entry for Amlogic WCN power sequence.

Signed-off-by: Yang Li <yang.li@amlogic.com>
---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index dcb37b635f2c..0773f7040341 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1174,6 +1174,14 @@ F:	Documentation/devicetree/bindings/perf/amlogic,g12-ddr-pmu.yaml
 F:	drivers/perf/amlogic/
 F:	include/soc/amlogic/
 
+AMLOGIC WCN POWER SEQUENCING
+M:	Yang Li <yang.li@amlogic.com>
+L:	linux-pm@vger.kernel.org
+S:	Maintained
+W:	http://www.amlogic.com
+F:	Documentation/devicetree/bindings/power/amlogic,w1552-pwrseq.yaml
+F:	drivers/power/sequencing/pwrseq-aml-wcn.c
+
 AMPHENOL CHIPCAP 2 HUMIDITY-TEMPERATURE IIO DRIVER
 M:	Javier Carrasco <javier.carrasco.cruz@gmail.com>
 L:	linux-hwmon@vger.kernel.org

-- 
2.42.0



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

* Re: [PATCH 1/3] dt-bindings: power: Add power sequence for Amloigc WCN chips
  2024-07-05 11:13 ` [PATCH 1/3] dt-bindings: power: Add power sequence for Amloigc " Yang Li via B4 Relay
@ 2024-07-05 13:34   ` Bartosz Golaszewski
  2024-07-08  6:12     ` Yang Li
  2024-07-07 12:59   ` Krzysztof Kozlowski
  1 sibling, 1 reply; 20+ messages in thread
From: Bartosz Golaszewski @ 2024-07-05 13:34 UTC (permalink / raw)
  To: yang.li
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
	linux-kernel, linux-pm

On Fri, Jul 5, 2024 at 1:13 PM Yang Li via B4 Relay
<devnull+yang.li.amlogic.com@kernel.org> wrote:
>
> From: Yang Li <yang.li@amlogic.com>
>
> Add binding document to introduce power sequence of
> Amlogic WCN chips.
>

Hi! Thanks for the interest in this new subsystem.

> Signed-off-by: Yang Li <yang.li@amlogic.com>
> ---
>  .../bindings/power/amlogic,w155s2-pwrseq.yaml      | 62 ++++++++++++++++++++++
>  1 file changed, 62 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/power/amlogic,w155s2-pwrseq.yaml b/Documentation/devicetree/bindings/power/amlogic,w155s2-pwrseq.yaml
> new file mode 100644
> index 000000000000..f99a775fcf9b
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/power/amlogic,w155s2-pwrseq.yaml
> @@ -0,0 +1,62 @@
> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/power/amlogic,w155s2-pwrseq.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Amlogic power sequence for WCN chips
> +
> +maintainers:
> +  - Yang Li <yang.li@amlogic.com>
> +
> +description:
> +  The Amlogic WCN chip contains discrete modules for WLAN and Bluetooth. Power on
> +  Bluetooth and Wi-Fi respectively, including chip_en pull-up and bt_en pull-up,
> +  and generation of the 32.768KHz clock.
> +
> +properties:
> +  compatible:
> +    oneOf:
> +      - const: amlogic,w155s2-pwrseq
> +      - items:
> +          - enum:
> +              - amlogic,w265s1-pwrseq
> +              - amlogic,w265p1-pwrseq
> +              - amlogic,w265s2-pwrseq
> +          - const: amlogic,w155s2-pwrseq

The name is wrong. There's no such device as 'pwrseq'. There's most
likely some kind of a Power Management Unit and the compatible string
must reflect this.

> +
> +  clocks:
> +    maxItems: 1
> +    description: clock provided to the controller (32.768KHz)
> +
> +  clock-names:
> +    items:
> +      - const: ext_clock
> +
> +  amlogic,chip-enable-gpios:
> +    maxItems: 1
> +    description: gpio specifier used to enable chipset

Why not simply: chip-enable-gpios or even enable-gpios?

> +
> +  amlogic,bt-enable-gpios:
> +    maxItems: 1
> +    description: gpio specifier used to enable BT
> +

Same here: should be simply bt-enable-gpios.

Bart

> +required:
> +  - compatible
> +  - clocks
> +  - clock-names
> +  - amlogic,chip-enable-gpios
> +  - amlogic,bt-enable-gpios
> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +    #include <dt-bindings/gpio/gpio.h>
> +    wcn_pwrseq {
> +        compatible = "amlogic,w155s2-pwrseq";
> +        clocks = <&extclk>;
> +        clock-names = "ext_clock";
> +        amlogic,chip-enable-gpios = <&gpio 7 GPIO_ACTIVE_HIGH>;
> +        amlogic,bt-enable-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>;
> +    };
>
> --
> 2.42.0
>
>

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

* Re: [PATCH 2/3] power: sequenceing: Add power sequence for Amlogic WCN chips
  2024-07-05 11:13 ` [PATCH 2/3] power: sequenceing: Add power sequence for Amlogic " Yang Li via B4 Relay
@ 2024-07-05 13:46   ` Bartosz Golaszewski
  2024-07-10  3:00     ` Yang Li
  2024-07-07 13:02   ` Krzysztof Kozlowski
  1 sibling, 1 reply; 20+ messages in thread
From: Bartosz Golaszewski @ 2024-07-05 13:46 UTC (permalink / raw)
  To: yang.li
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
	linux-kernel, linux-pm

On Fri, Jul 5, 2024 at 1:13 PM Yang Li via B4 Relay
<devnull+yang.li.amlogic.com@kernel.org> wrote:
>
> From: Yang Li <yang.li@amlogic.com>
>
> Add power sequence for Bluetooth and Wi-Fi respectively, including chip_en
> pull-up and bt_en pull-up, and generation of the 32.768 clock.
>
> Signed-off-by: Yang Li <yang.li@amlogic.com>
> ---
>  drivers/power/sequencing/Kconfig          |   7 +
>  drivers/power/sequencing/Makefile         |   1 +
>  drivers/power/sequencing/pwrseq-aml-wcn.c | 209 ++++++++++++++++++++++++++++++
>  3 files changed, 217 insertions(+)
>
> diff --git a/drivers/power/sequencing/Kconfig b/drivers/power/sequencing/Kconfig
> index c9f1cdb66524..65d3b2c20bfb 100644
> --- a/drivers/power/sequencing/Kconfig
> +++ b/drivers/power/sequencing/Kconfig
> @@ -26,4 +26,11 @@ config POWER_SEQUENCING_QCOM_WCN
>           this driver is needed for correct power control or else we'd risk not
>           respecting the required delays between enabling Bluetooth and WLAN.
>
> +config POWER_SEQUENCING_AML_WCN
> +       tristate "Amlogic WCN family PMU driver"
> +       default m if ARCH_MESON
> +       help
> +         Say Y here to enable the power sequencing driver for Amlogic
> +         WCN Bluetooth/WLAN chipsets.
> +
>  endif
> diff --git a/drivers/power/sequencing/Makefile b/drivers/power/sequencing/Makefile
> index 2eec2df7912d..32706daf8f0f 100644
> --- a/drivers/power/sequencing/Makefile
> +++ b/drivers/power/sequencing/Makefile
> @@ -4,3 +4,4 @@ obj-$(CONFIG_POWER_SEQUENCING)          += pwrseq-core.o
>  pwrseq-core-y                          := core.o
>
>  obj-$(CONFIG_POWER_SEQUENCING_QCOM_WCN)        += pwrseq-qcom-wcn.o
> +obj-$(CONFIG_POWER_SEQUENCING_AML_WCN) += pwrseq-aml-wcn.o
> diff --git a/drivers/power/sequencing/pwrseq-aml-wcn.c b/drivers/power/sequencing/pwrseq-aml-wcn.c
> new file mode 100644
> index 000000000000..6f5bfcf60b9c
> --- /dev/null
> +++ b/drivers/power/sequencing/pwrseq-aml-wcn.c
> @@ -0,0 +1,209 @@
> +// SPDX-License-Identifier: (GPL-2.0-only OR MIT)
> +/*
> + * Copyright (C) 2024 Amlogic, Inc. All rights reserved
> + */
> +
> +#include <linux/clk.h>
> +#include <linux/delay.h>
> +#include <linux/device.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/of.h>
> +#include <linux/gpio.h>

Please see line 5 in this file.

> +#include <linux/of_gpio.h>

You don't need this either.

> +#include <linux/platform_device.h>
> +#include <linux/pwrseq/provider.h>
> +#include <linux/string.h>
> +#include <linux/types.h>
> +
> +struct pwrseq_aml_wcn_ctx {
> +       struct pwrseq_device *pwrseq;
> +       int bt_enable_gpio;
> +       int chip_enable_gpio;
> +       struct clk *lpo_clk;
> +       unsigned int pwr_count;
> +};
> +
> +static DEFINE_MUTEX(pwrseq_lock);
> +

Why is this global?

> +static int pwrseq_aml_wcn_chip_enable(struct pwrseq_device *pwrseq)
> +{
> +       struct pwrseq_aml_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
> +       int err;
> +
> +       mutex_lock(&pwrseq_lock);

Please use guard() from linux/cleanup.h.

> +       if (ctx->pwr_count == 0) {
> +               gpio_request(ctx->chip_enable_gpio, "chip-enable-gpios");
> +               gpio_direction_output(ctx->chip_enable_gpio, 1);
> +               gpio_free(ctx->chip_enable_gpio);

Not only are these legacy APIs but they are also used wrong. You
almost never want to release the GPIO after setting the direction as
someone else may grab it and use it.

> +
> +               if (!IS_ERR(ctx->lpo_clk)) {
> +                       err = clk_prepare_enable(ctx->lpo_clk);
> +                       if (err) {
> +                               mutex_unlock(&pwrseq_lock);
> +                               return err;
> +                       }
> +               }
> +       }
> +
> +       ctx->pwr_count++;
> +       mutex_unlock(&pwrseq_lock);
> +       return 0;
> +}
> +
> +static int pwrseq_aml_wcn_chip_disable(struct pwrseq_device *pwrseq)
> +{
> +       struct pwrseq_aml_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
> +
> +       mutex_lock(&pwrseq_lock);
> +       if (--ctx->pwr_count == 0) {
> +               gpio_request(ctx->chip_enable_gpio, "chip-enable-gpios");
> +               gpio_direction_output(ctx->chip_enable_gpio, 0);
> +               gpio_free(ctx->chip_enable_gpio);
> +
> +               if (!IS_ERR(ctx->lpo_clk))
> +                       clk_disable_unprepare(ctx->lpo_clk);
> +       }
> +
> +       mutex_unlock(&pwrseq_lock);
> +       return 0;
> +}
> +
> +static const struct pwrseq_unit_data pwrseq_aml_wcn_chip_power_unit_data = {
> +       .name = "chip-enable",
> +       .enable = pwrseq_aml_wcn_chip_enable,
> +       .disable = pwrseq_aml_wcn_chip_disable,
> +};
> +
> +static const struct pwrseq_unit_data *pwrseq_aml_wcn_unit_deps[] = {
> +       &pwrseq_aml_wcn_chip_power_unit_data,
> +       NULL
> +};
> +
> +static int pwrseq_aml_wcn_bt_enable(struct pwrseq_device *pwrseq)
> +{
> +       struct pwrseq_aml_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
> +
> +       gpio_request(ctx->bt_enable_gpio, "bt-enable-gpios");
> +       gpio_direction_output(ctx->bt_enable_gpio, 1);
> +       gpio_free(ctx->bt_enable_gpio);
> +
> +       /* wait 100ms for bluetooth controller power on  */
> +       msleep(100);
> +
> +       return 0;
> +}
> +
> +static int pwrseq_aml_wcn_bt_disable(struct pwrseq_device *pwrseq)
> +{
> +       struct pwrseq_aml_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
> +
> +       gpio_request(ctx->bt_enable_gpio, "bt-enable-gpios");
> +       gpio_direction_output(ctx->bt_enable_gpio, 0);
> +       gpio_free(ctx->bt_enable_gpio);
> +
> +       return 0;
> +}
> +
> +static const struct pwrseq_unit_data pwrseq_aml_wcn_bt_unit_data = {
> +       .name = "bluetooth-enable",
> +       .deps = pwrseq_aml_wcn_unit_deps,
> +       .enable = pwrseq_aml_wcn_bt_enable,
> +       .disable = pwrseq_aml_wcn_bt_disable,
> +};
> +
> +static const struct pwrseq_unit_data pwrseq_aml_wcn_wlan_unit_data = {
> +       .name = "wlan-enable",
> +       .deps = pwrseq_aml_wcn_unit_deps,
> +};
> +
> +static const struct pwrseq_target_data pwrseq_aml_wcn_bt_target_data = {
> +       .name = "bluetooth",
> +       .unit = &pwrseq_aml_wcn_bt_unit_data,
> +};
> +
> +static const struct pwrseq_target_data pwrseq_aml_wcn_wlan_target_data = {
> +       .name = "wlan",
> +       .unit = &pwrseq_aml_wcn_wlan_unit_data,
> +};
> +
> +static const struct pwrseq_target_data *pwrseq_aml_wcn_targets[] = {
> +       &pwrseq_aml_wcn_bt_target_data,
> +       &pwrseq_aml_wcn_wlan_target_data,
> +       NULL
> +};
> +
> +static int pwrseq_aml_wcn_match(struct pwrseq_device *pwrseq,
> +                                struct device *dev)
> +{
> +       struct device_node *dev_node = dev->of_node;
> +
> +       if (!of_property_present(dev_node, "amlogic,wcn-pwrseq"))
> +               return 0;
> +

You must never reference the notion of power sequencing in the DT.
Please take a look at the pwrseq-qcom-wcn driver where we model the
PMU with its regulators and then parse them in match() to figure out
if we have the right thing or not.

> +       return 1;
> +}
> +
> +static int pwrseq_aml_wcn_probe(struct platform_device *pdev)
> +{
> +       struct device *dev = &pdev->dev;
> +       struct pwrseq_aml_wcn_ctx *ctx;
> +       struct pwrseq_config config;
> +
> +       ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
> +       if (!ctx)
> +               return -ENOMEM;
> +
> +       ctx->bt_enable_gpio = of_get_named_gpio(dev->of_node,
> +                                              "amlogic,bt-enable-gpios", 0);
> +       if (!gpio_is_valid(ctx->bt_enable_gpio))
> +               return dev_err_probe(dev, ctx->bt_enable_gpio,
> +                               "Failed to get the bt enable GPIO");
> +
> +       ctx->chip_enable_gpio = of_get_named_gpio(dev->of_node,
> +                                              "amlogic,chip-enable-gpios", 0);

You don't need the OF variant. Use the regular devm_gpiod_get(). You
also forgot to release it but the devres variant will take care of it.

> +       if (!gpio_is_valid(ctx->chip_enable_gpio))
> +               return dev_err_probe(dev, ctx->bt_enable_gpio,
> +                                       "Failed to get the chip enable GPIO");

Wat

> +
> +       ctx->lpo_clk = devm_clk_get_optional(dev, NULL);
> +       if (IS_ERR(ctx->lpo_clk))
> +               return dev_err_probe(dev, PTR_ERR(ctx->lpo_clk),
> +                               "Failed to get the clock source");
> +
> +       memset(&config, 0, sizeof(config));
> +
> +       config.parent = dev;
> +       config.owner = THIS_MODULE;
> +       config.drvdata = ctx;
> +       config.match = pwrseq_aml_wcn_match;
> +       config.targets = pwrseq_aml_wcn_targets;
> +
> +       ctx->pwr_count = 0;
> +       ctx->pwrseq = devm_pwrseq_device_register(dev, &config);
> +       if (IS_ERR(ctx->pwrseq))
> +               return dev_err_probe(dev, PTR_ERR(ctx->pwrseq),
> +                                    "Failed to register the power sequencer\n");
> +
> +       return 0;
> +}
> +
> +static const struct of_device_id pwrseq_aml_wcn_of_match[] = {
> +       { .compatible = "amlogic,w155s2-pwrseq" },
> +       { /* sentinel */ },
> +};
> +MODULE_DEVICE_TABLE(of, pwrseq_aml_wcn_of_match);
> +
> +static struct platform_driver pwrseq_aml_wcn_driver = {
> +       .driver = {
> +               .name = "pwrseq-aml_wcn",
> +               .of_match_table = pwrseq_aml_wcn_of_match,
> +       },
> +       .probe = pwrseq_aml_wcn_probe,
> +};
> +module_platform_driver(pwrseq_aml_wcn_driver);
> +
> +MODULE_AUTHOR("Yang Li <yang.li@amlogic.com>");
> +MODULE_DESCRIPTION("Amlogic WCN PMU power sequencing driver");
> +MODULE_LICENSE("GPL");
>
> --
> 2.42.0
>
>

Bart

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

* Re: [PATCH 1/3] dt-bindings: power: Add power sequence for Amloigc WCN chips
  2024-07-05 11:13 ` [PATCH 1/3] dt-bindings: power: Add power sequence for Amloigc " Yang Li via B4 Relay
  2024-07-05 13:34   ` Bartosz Golaszewski
@ 2024-07-07 12:59   ` Krzysztof Kozlowski
  2024-07-08  6:04     ` Yang Li
  1 sibling, 1 reply; 20+ messages in thread
From: Krzysztof Kozlowski @ 2024-07-07 12:59 UTC (permalink / raw)
  To: yang.li, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Bartosz Golaszewski
  Cc: devicetree, linux-kernel, linux-pm

On 05/07/2024 13:13, Yang Li via B4 Relay wrote:
> From: Yang Li <yang.li@amlogic.com>
> 
> Add binding document to introduce power sequence of
> Amlogic WCN chips.
> 
> Signed-off-by: Yang Li <yang.li@amlogic.com>
> ---
>  .../bindings/power/amlogic,w155s2-pwrseq.yaml      | 62 ++++++++++++++++++++++
>  1 file changed, 62 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/power/amlogic,w155s2-pwrseq.yaml b/Documentation/devicetree/bindings/power/amlogic,w155s2-pwrseq.yaml
> new file mode 100644
> index 000000000000..f99a775fcf9b
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/power/amlogic,w155s2-pwrseq.yaml
> @@ -0,0 +1,62 @@
> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/power/amlogic,w155s2-pwrseq.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Amlogic power sequence for WCN chips
> +
> +maintainers:
> +  - Yang Li <yang.li@amlogic.com>
> +
> +description:
> +  The Amlogic WCN chip contains discrete modules for WLAN and Bluetooth. Power on
> +  Bluetooth and Wi-Fi respectively, including chip_en pull-up and bt_en pull-up,
> +  and generation of the 32.768KHz clock.
> +
> +properties:
> +  compatible:
> +    oneOf:
> +      - const: amlogic,w155s2-pwrseq
> +      - items:
> +          - enum:
> +              - amlogic,w265s1-pwrseq
> +              - amlogic,w265p1-pwrseq
> +              - amlogic,w265s2-pwrseq
> +          - const: amlogic,w155s2-pwrseq
> +
> +  clocks:
> +    maxItems: 1
> +    description: clock provided to the controller (32.768KHz)
> +
> +  clock-names:
> +    items:
> +      - const: ext_clock

Drop _clock... or actually drop entire clock-names, not much helpful.

> +
> +  amlogic,chip-enable-gpios:
> +    maxItems: 1
> +    description: gpio specifier used to enable chipset

For entire chipset? Then enable-gpios

> +
> +  amlogic,bt-enable-gpios:
> +    maxItems: 1
> +    description: gpio specifier used to enable BT

Follow existing bindings for Qualcomm as example.

> +
> +required:
> +  - compatible
> +  - clocks
> +  - clock-names
> +  - amlogic,chip-enable-gpios
> +  - amlogic,bt-enable-gpios
> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +    #include <dt-bindings/gpio/gpio.h>
> +    wcn_pwrseq {

No underscores in node names, generic node names.

There is no device as "pwrseq". I also do not get what "wcn" means here.



Best regards,
Krzysztof


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

* Re: [PATCH 2/3] power: sequenceing: Add power sequence for Amlogic WCN chips
  2024-07-05 11:13 ` [PATCH 2/3] power: sequenceing: Add power sequence for Amlogic " Yang Li via B4 Relay
  2024-07-05 13:46   ` Bartosz Golaszewski
@ 2024-07-07 13:02   ` Krzysztof Kozlowski
  2024-07-08  7:41     ` Yang Li
  1 sibling, 1 reply; 20+ messages in thread
From: Krzysztof Kozlowski @ 2024-07-07 13:02 UTC (permalink / raw)
  To: yang.li, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Bartosz Golaszewski
  Cc: devicetree, linux-kernel, linux-pm

On 05/07/2024 13:13, Yang Li via B4 Relay wrote:
> From: Yang Li <yang.li@amlogic.com>
> 
> Add power sequence for Bluetooth and Wi-Fi respectively, including chip_en
> pull-up and bt_en pull-up, and generation of the 32.768 clock.
> 
> Signed-off-by: Yang Li <yang.li@amlogic.com>

> +#include <linux/clk.h>
> +#include <linux/delay.h>
> +#include <linux/device.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/of.h>
> +#include <linux/gpio.h>
> +#include <linux/of_gpio.h>
> +#include <linux/platform_device.h>
> +#include <linux/pwrseq/provider.h>
> +#include <linux/string.h>
> +#include <linux/types.h>
> +
> +struct pwrseq_aml_wcn_ctx {
> +	struct pwrseq_device *pwrseq;
> +	int bt_enable_gpio;

Why? It's never used... or you use wrong API. Confusing code.

> +	int chip_enable_gpio;
> +	struct clk *lpo_clk;
> +	unsigned int pwr_count;
> +};
> +
> +static DEFINE_MUTEX(pwrseq_lock);

Why this is not part of structure above?

> +


...

> +
> +static int pwrseq_aml_wcn_match(struct pwrseq_device *pwrseq,
> +				 struct device *dev)
> +{
> +	struct device_node *dev_node = dev->of_node;
> +
> +	if (!of_property_present(dev_node, "amlogic,wcn-pwrseq"))

You cannot have undocumented properties, sorry, that's a NAK.

> +		return 0;
> +
> +	return 1;
> +}
> +
> +static int pwrseq_aml_wcn_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct pwrseq_aml_wcn_ctx *ctx;
> +	struct pwrseq_config config;
> +
> +	ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
> +	if (!ctx)
> +		return -ENOMEM;
> +
> +	ctx->bt_enable_gpio = of_get_named_gpio(dev->of_node,
> +					       "amlogic,bt-enable-gpios", 0);
> +	if (!gpio_is_valid(ctx->bt_enable_gpio))
> +		return dev_err_probe(dev, ctx->bt_enable_gpio,
> +				"Failed to get the bt enable GPIO");
> +
> +	ctx->chip_enable_gpio = of_get_named_gpio(dev->of_node,
> +					       "amlogic,chip-enable-gpios", 0);
> +	if (!gpio_is_valid(ctx->chip_enable_gpio))
> +		return dev_err_probe(dev, ctx->bt_enable_gpio,
> +					"Failed to get the chip enable GPIO");
> +
> +	ctx->lpo_clk = devm_clk_get_optional(dev, NULL);

Clock is not optional, according to you binding.

> +	if (IS_ERR(ctx->lpo_clk))
> +		return dev_err_probe(dev, PTR_ERR(ctx->lpo_clk),
> +				"Failed to get the clock source");
> +
> +	memset(&config, 0, sizeof(config));

Just initialize it on the stack with 0.



Best regards,
Krzysztof


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

* Re: [PATCH 3/3] MAINTAINERS: Add an entry for Amlogic WCN power sequence
  2024-07-05 11:13 ` [PATCH 3/3] MAINTAINERS: Add an entry for Amlogic WCN power sequence Yang Li via B4 Relay
@ 2024-07-07 13:04   ` Krzysztof Kozlowski
  2024-07-08  6:34     ` Yang Li
  0 siblings, 1 reply; 20+ messages in thread
From: Krzysztof Kozlowski @ 2024-07-07 13:04 UTC (permalink / raw)
  To: yang.li, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Bartosz Golaszewski
  Cc: devicetree, linux-kernel, linux-pm

On 05/07/2024 13:13, Yang Li via B4 Relay wrote:
> From: Yang Li <yang.li@amlogic.com>
> 
> Add an entry for Amlogic WCN power sequence.
> 
> Signed-off-by: Yang Li <yang.li@amlogic.com>
> ---
>  MAINTAINERS | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index dcb37b635f2c..0773f7040341 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -1174,6 +1174,14 @@ F:	Documentation/devicetree/bindings/perf/amlogic,g12-ddr-pmu.yaml
>  F:	drivers/perf/amlogic/
>  F:	include/soc/amlogic/
>  
> +AMLOGIC WCN POWER SEQUENCING
> +M:	Yang Li <yang.li@amlogic.com>
> +L:	linux-pm@vger.kernel.org
> +S:	Maintained
> +W:	http://www.amlogic.com

Drop. It's not helpful at all. Don't throw at us your company marketing.

Best regards,
Krzysztof


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

* Re: [PATCH 1/3] dt-bindings: power: Add power sequence for Amloigc WCN chips
  2024-07-07 12:59   ` Krzysztof Kozlowski
@ 2024-07-08  6:04     ` Yang Li
  2024-07-08  6:11       ` Krzysztof Kozlowski
  0 siblings, 1 reply; 20+ messages in thread
From: Yang Li @ 2024-07-08  6:04 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Bartosz Golaszewski
  Cc: devicetree, linux-kernel, linux-pm

Dear Krzysztof

Thanks for your immediate recovery and careful guidance.

> On 05/07/2024 13:13, Yang Li via B4 Relay wrote:
>> From: Yang Li <yang.li@amlogic.com>
>>
>> Add binding document to introduce power sequence of
>> Amlogic WCN chips.
>>
>> Signed-off-by: Yang Li <yang.li@amlogic.com>
>> ---
>>   .../bindings/power/amlogic,w155s2-pwrseq.yaml      | 62 ++++++++++++++++++++++
>>   1 file changed, 62 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/power/amlogic,w155s2-pwrseq.yaml b/Documentation/devicetree/bindings/power/amlogic,w155s2-pwrseq.yaml
>> new file mode 100644
>> index 000000000000..f99a775fcf9b
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/power/amlogic,w155s2-pwrseq.yaml
>> @@ -0,0 +1,62 @@
>> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
>> +%YAML 1.2
>> +---
>> +$id: http://devicetree.org/schemas/power/amlogic,w155s2-pwrseq.yaml#
>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>> +
>> +title: Amlogic power sequence for WCN chips
>> +
>> +maintainers:
>> +  - Yang Li <yang.li@amlogic.com>
>> +
>> +description:
>> +  The Amlogic WCN chip contains discrete modules for WLAN and Bluetooth. Power on
>> +  Bluetooth and Wi-Fi respectively, including chip_en pull-up and bt_en pull-up,
>> +  and generation of the 32.768KHz clock.
>> +
>> +properties:
>> +  compatible:
>> +    oneOf:
>> +      - const: amlogic,w155s2-pwrseq
>> +      - items:
>> +          - enum:
>> +              - amlogic,w265s1-pwrseq
>> +              - amlogic,w265p1-pwrseq
>> +              - amlogic,w265s2-pwrseq
>> +          - const: amlogic,w155s2-pwrseq
>> +
>> +  clocks:
>> +    maxItems: 1
>> +    description: clock provided to the controller (32.768KHz)
>> +
>> +  clock-names:
>> +    items:
>> +      - const: ext_clock
> Drop _clock... or actually drop entire clock-names, not much helpful.
Got it~ will do.
>
>> +
>> +  amlogic,chip-enable-gpios:
>> +    maxItems: 1
>> +    description: gpio specifier used to enable chipset
> For entire chipset? Then enable-gpios
Yes, I will change "amlogic,chip-enable-gpios" to "enable-gpio"
>> +
>> +  amlogic,bt-enable-gpios:
>> +    maxItems: 1
>> +    description: gpio specifier used to enable BT
> Follow existing bindings for Qualcomm as example.

Okay, I will change "amlogic,bt-enable-gpios"to "bt-enable-gpios" follow

Qualcomm's example.

>> +
>> +required:
>> +  - compatible
>> +  - clocks
>> +  - clock-names
>> +  - amlogic,chip-enable-gpios
>> +  - amlogic,bt-enable-gpios
>> +
>> +additionalProperties: false
>> +
>> +examples:
>> +  - |
>> +    #include <dt-bindings/gpio/gpio.h>
>> +    wcn_pwrseq {
> No underscores in node names, generic node names.
>
> There is no device as "pwrseq". I also do not get what "wcn" means here.

Yes, I understand.

Can I change "wcn_pwrseq" to "pmu", and do I need to change the binding 
file name to "amlogic,w155s2-pmu"

> Best regards,
> Krzysztof
>

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

* Re: [PATCH 1/3] dt-bindings: power: Add power sequence for Amloigc WCN chips
  2024-07-08  6:04     ` Yang Li
@ 2024-07-08  6:11       ` Krzysztof Kozlowski
  2024-07-08  6:32         ` Yang Li
  0 siblings, 1 reply; 20+ messages in thread
From: Krzysztof Kozlowski @ 2024-07-08  6:11 UTC (permalink / raw)
  To: Yang Li, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Bartosz Golaszewski
  Cc: devicetree, linux-kernel, linux-pm

On 08/07/2024 08:04, Yang Li wrote:
>>> +
>>> +required:
>>> +  - compatible
>>> +  - clocks
>>> +  - clock-names
>>> +  - amlogic,chip-enable-gpios
>>> +  - amlogic,bt-enable-gpios
>>> +
>>> +additionalProperties: false
>>> +
>>> +examples:
>>> +  - |
>>> +    #include <dt-bindings/gpio/gpio.h>
>>> +    wcn_pwrseq {
>> No underscores in node names, generic node names.
>>
>> There is no device as "pwrseq". I also do not get what "wcn" means here.
> 
> Yes, I understand.
> 
> Can I change "wcn_pwrseq" to "pmu", and do I need to change the binding 

What is pmu for your device? What is this device in the first place you
are documenting? Where is the datasheet?

> file name to "amlogic,w155s2-pmu"

Yes, compatible should also match proper device.


Best regards,
Krzysztof


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

* Re: [PATCH 1/3] dt-bindings: power: Add power sequence for Amloigc WCN chips
  2024-07-05 13:34   ` Bartosz Golaszewski
@ 2024-07-08  6:12     ` Yang Li
  0 siblings, 0 replies; 20+ messages in thread
From: Yang Li @ 2024-07-08  6:12 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
	linux-kernel, linux-pm

Dear Bartosz

Thanks for your careful guidance and suggestions.

> On Fri, Jul 5, 2024 at 1:13 PM Yang Li via B4 Relay
> <devnull+yang.li.amlogic.com@kernel.org> wrote:
>> From: Yang Li <yang.li@amlogic.com>
>>
>> Add binding document to introduce power sequence of
>> Amlogic WCN chips.
>>
> Hi! Thanks for the interest in this new subsystem.
>
>> Signed-off-by: Yang Li <yang.li@amlogic.com>
>> ---
>>   .../bindings/power/amlogic,w155s2-pwrseq.yaml      | 62 ++++++++++++++++++++++
>>   1 file changed, 62 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/power/amlogic,w155s2-pwrseq.yaml b/Documentation/devicetree/bindings/power/amlogic,w155s2-pwrseq.yaml
>> new file mode 100644
>> index 000000000000..f99a775fcf9b
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/power/amlogic,w155s2-pwrseq.yaml
>> @@ -0,0 +1,62 @@
>> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
>> +%YAML 1.2
>> +---
>> +$id: http://devicetree.org/schemas/power/amlogic,w155s2-pwrseq.yaml#
>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>> +
>> +title: Amlogic power sequence for WCN chips
>> +
>> +maintainers:
>> +  - Yang Li <yang.li@amlogic.com>
>> +
>> +description:
>> +  The Amlogic WCN chip contains discrete modules for WLAN and Bluetooth. Power on
>> +  Bluetooth and Wi-Fi respectively, including chip_en pull-up and bt_en pull-up,
>> +  and generation of the 32.768KHz clock.
>> +
>> +properties:
>> +  compatible:
>> +    oneOf:
>> +      - const: amlogic,w155s2-pwrseq
>> +      - items:
>> +          - enum:
>> +              - amlogic,w265s1-pwrseq
>> +              - amlogic,w265p1-pwrseq
>> +              - amlogic,w265s2-pwrseq
>> +          - const: amlogic,w155s2-pwrseq
> The name is wrong. There's no such device as 'pwrseq'. There's most
> likely some kind of a Power Management Unit and the compatible string
> must reflect this.

Yes, I got it!

I will change "pwrseq" to "pmu".

>> +
>> +  clocks:
>> +    maxItems: 1
>> +    description: clock provided to the controller (32.768KHz)
>> +
>> +  clock-names:
>> +    items:
>> +      - const: ext_clock
>> +
>> +  amlogic,chip-enable-gpios:
>> +    maxItems: 1
>> +    description: gpio specifier used to enable chipset
> Why not simply: chip-enable-gpios or even enable-gpios?
Well, I will do. "amlogic,chip-enable-gpios" => "enable-gpios"
>
>> +
>> +  amlogic,bt-enable-gpios:
>> +    maxItems: 1
>> +    description: gpio specifier used to enable BT
>> +
> Same here: should be simply bt-enable-gpios.
>
> Bart
Well, I well change "amlogic,bt-enable-gpios" to "bt-enable-gpios".
>> +required:
>> +  - compatible
>> +  - clocks
>> +  - clock-names
>> +  - amlogic,chip-enable-gpios
>> +  - amlogic,bt-enable-gpios
>> +
>> +additionalProperties: false
>> +
>> +examples:
>> +  - |
>> +    #include <dt-bindings/gpio/gpio.h>
>> +    wcn_pwrseq {
>> +        compatible = "amlogic,w155s2-pwrseq";
>> +        clocks = <&extclk>;
>> +        clock-names = "ext_clock";
>> +        amlogic,chip-enable-gpios = <&gpio 7 GPIO_ACTIVE_HIGH>;
>> +        amlogic,bt-enable-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>;
>> +    };
>>
>> --
>> 2.42.0
>>
>>

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

* Re: [PATCH 1/3] dt-bindings: power: Add power sequence for Amloigc WCN chips
  2024-07-08  6:11       ` Krzysztof Kozlowski
@ 2024-07-08  6:32         ` Yang Li
  2024-07-08  7:32           ` Krzysztof Kozlowski
  0 siblings, 1 reply; 20+ messages in thread
From: Yang Li @ 2024-07-08  6:32 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Bartosz Golaszewski
  Cc: devicetree, linux-kernel, linux-pm


在 2024/7/8 14:11, Krzysztof Kozlowski 写道:
> [ EXTERNAL EMAIL ]
>
> On 08/07/2024 08:04, Yang Li wrote:
>>>> +
>>>> +required:
>>>> +  - compatible
>>>> +  - clocks
>>>> +  - clock-names
>>>> +  - amlogic,chip-enable-gpios
>>>> +  - amlogic,bt-enable-gpios
>>>> +
>>>> +additionalProperties: false
>>>> +
>>>> +examples:
>>>> +  - |
>>>> +    #include <dt-bindings/gpio/gpio.h>
>>>> +    wcn_pwrseq {
>>> No underscores in node names, generic node names.
>>>
>>> There is no device as "pwrseq". I also do not get what "wcn" means here.
>> Yes, I understand.
>>
>> Can I change "wcn_pwrseq" to "pmu", and do I need to change the binding
> What is pmu for your device? What is this device in the first place you
> are documenting? Where is the datasheet?

^_^ Well, You are right, the "pmu" wasn't really fit in here.

I'd like to explain the current usage first, and could you please give 
me a suggestion?

This module(pwrseq) used to power on Bluetooth & Wi-Fi combo chip, both 
Bluetooth and

Wi-Fi driver need to control "chip-en-gpios" pins, so we introduced the 
power sequence module.

What should we call it in this case?

>> file name to "amlogic,w155s2-pmu"
> Yes, compatible should also match proper device.
>
>
> Best regards,
> Krzysztof
>

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

* Re: [PATCH 3/3] MAINTAINERS: Add an entry for Amlogic WCN power sequence
  2024-07-07 13:04   ` Krzysztof Kozlowski
@ 2024-07-08  6:34     ` Yang Li
  0 siblings, 0 replies; 20+ messages in thread
From: Yang Li @ 2024-07-08  6:34 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Bartosz Golaszewski
  Cc: devicetree, linux-kernel, linux-pm


> On 05/07/2024 13:13, Yang Li via B4 Relay wrote:
>> From: Yang Li <yang.li@amlogic.com>
>>
>> Add an entry for Amlogic WCN power sequence.
>>
>> Signed-off-by: Yang Li <yang.li@amlogic.com>
>> ---
>>   MAINTAINERS | 8 ++++++++
>>   1 file changed, 8 insertions(+)
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index dcb37b635f2c..0773f7040341 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -1174,6 +1174,14 @@ F:     Documentation/devicetree/bindings/perf/amlogic,g12-ddr-pmu.yaml
>>   F:   drivers/perf/amlogic/
>>   F:   include/soc/amlogic/
>>
>> +AMLOGIC WCN POWER SEQUENCING
>> +M:   Yang Li <yang.li@amlogic.com>
>> +L:   linux-pm@vger.kernel.org
>> +S:   Maintained
>> +W:   http://www.amlogic.com
> Drop. It's not helpful at all. Don't throw at us your company marketing.

Well, I got it.

I will delete this line.

Thanks!

>
> Best regards,
> Krzysztof
>

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

* Re: [PATCH 1/3] dt-bindings: power: Add power sequence for Amloigc WCN chips
  2024-07-08  6:32         ` Yang Li
@ 2024-07-08  7:32           ` Krzysztof Kozlowski
  2024-07-08  8:21             ` Yang Li
  0 siblings, 1 reply; 20+ messages in thread
From: Krzysztof Kozlowski @ 2024-07-08  7:32 UTC (permalink / raw)
  To: Yang Li, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Bartosz Golaszewski
  Cc: devicetree, linux-kernel, linux-pm

On 08/07/2024 08:32, Yang Li wrote:
> 
> 在 2024/7/8 14:11, Krzysztof Kozlowski 写道:
>> [ EXTERNAL EMAIL ]
>>
>> On 08/07/2024 08:04, Yang Li wrote:
>>>>> +
>>>>> +required:
>>>>> +  - compatible
>>>>> +  - clocks
>>>>> +  - clock-names
>>>>> +  - amlogic,chip-enable-gpios
>>>>> +  - amlogic,bt-enable-gpios
>>>>> +
>>>>> +additionalProperties: false
>>>>> +
>>>>> +examples:
>>>>> +  - |
>>>>> +    #include <dt-bindings/gpio/gpio.h>
>>>>> +    wcn_pwrseq {
>>>> No underscores in node names, generic node names.
>>>>
>>>> There is no device as "pwrseq". I also do not get what "wcn" means here.
>>> Yes, I understand.
>>>
>>> Can I change "wcn_pwrseq" to "pmu", and do I need to change the binding
>> What is pmu for your device? What is this device in the first place you
>> are documenting? Where is the datasheet?
> 
> ^_^ Well, You are right, the "pmu" wasn't really fit in here.
> 
> I'd like to explain the current usage first, and could you please give 
> me a suggestion?
> 
> This module(pwrseq) used to power on Bluetooth & Wi-Fi combo chip, both 
> Bluetooth and
> 
> Wi-Fi driver need to control "chip-en-gpios" pins, so we introduced the 
> power sequence module.
> 
> What should we call it in this case?

Sorry, you describe driver, not a device.

That would be a no-go for entire binding. Please describe the hardware,
not what you want to achieve in Linux drivers.


Best regards,
Krzysztof


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

* Re: [PATCH 2/3] power: sequenceing: Add power sequence for Amlogic WCN chips
  2024-07-07 13:02   ` Krzysztof Kozlowski
@ 2024-07-08  7:41     ` Yang Li
  0 siblings, 0 replies; 20+ messages in thread
From: Yang Li @ 2024-07-08  7:41 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Bartosz Golaszewski
  Cc: devicetree, linux-kernel, linux-pm

Dear Krzysztof

Thanks for your comments.
> On 05/07/2024 13:13, Yang Li via B4 Relay wrote:
>> From: Yang Li <yang.li@amlogic.com>
>>
>> Add power sequence for Bluetooth and Wi-Fi respectively, including chip_en
>> pull-up and bt_en pull-up, and generation of the 32.768 clock.
>>
>> Signed-off-by: Yang Li <yang.li@amlogic.com>
>> +#include <linux/clk.h>
>> +#include <linux/delay.h>
>> +#include <linux/device.h>
>> +#include <linux/mod_devicetable.h>
>> +#include <linux/module.h>
>> +#include <linux/mutex.h>
>> +#include <linux/of.h>
>> +#include <linux/gpio.h>
>> +#include <linux/of_gpio.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/pwrseq/provider.h>
>> +#include <linux/string.h>
>> +#include <linux/types.h>
>> +
>> +struct pwrseq_aml_wcn_ctx {
>> +     struct pwrseq_device *pwrseq;
>> +     int bt_enable_gpio;
> Why? It's never used... or you use wrong API. Confusing code.
Well, I will used the "struct gpio_desc" replace current method.
>
>> +     int chip_enable_gpio;
>> +     struct clk *lpo_clk;
>> +     unsigned int pwr_count;
>> +};
>> +
>> +static DEFINE_MUTEX(pwrseq_lock);
> Why this is not part of structure above?

Sorry, I referenced some outdated examples.

And I will put it in structure of pwrseq_aml_wcn_ctx.

>> +
>
> ...
>
>> +
>> +static int pwrseq_aml_wcn_match(struct pwrseq_device *pwrseq,
>> +                              struct device *dev)
>> +{
>> +     struct device_node *dev_node = dev->of_node;
>> +
>> +     if (!of_property_present(dev_node, "amlogic,wcn-pwrseq"))
> You cannot have undocumented properties, sorry, that's a NAK.

About the match () function I also have some doubts, the 
drivers/power/sequence/core.c requirements need to be defined match () 
function is used to determine whether a potential consumers actually 
related to the sequencer. So, I need to add a meaningless node 
"amlogic,wcn-pwrseq" to both the consumer dt-binding and the provider 
dt-binding.

Right now, I add "amlogic,wcn-pwrseq" in binding file of 
"amlogic,w155s2-bt.yaml" only, may I need to add this properties 
("amlogic,wcn-pwrseq") in the binding file of "amlogic,w155s2-pwrseq.yaml"?

>> +             return 0;
>> +
>> +     return 1;
>> +}
>> +
>> +static int pwrseq_aml_wcn_probe(struct platform_device *pdev)
>> +{
>> +     struct device *dev = &pdev->dev;
>> +     struct pwrseq_aml_wcn_ctx *ctx;
>> +     struct pwrseq_config config;
>> +
>> +     ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
>> +     if (!ctx)
>> +             return -ENOMEM;
>> +
>> +     ctx->bt_enable_gpio = of_get_named_gpio(dev->of_node,
>> +                                            "amlogic,bt-enable-gpios", 0);
>> +     if (!gpio_is_valid(ctx->bt_enable_gpio))
>> +             return dev_err_probe(dev, ctx->bt_enable_gpio,
>> +                             "Failed to get the bt enable GPIO");
>> +
>> +     ctx->chip_enable_gpio = of_get_named_gpio(dev->of_node,
>> +                                            "amlogic,chip-enable-gpios", 0);
>> +     if (!gpio_is_valid(ctx->chip_enable_gpio))
>> +             return dev_err_probe(dev, ctx->bt_enable_gpio,
>> +                                     "Failed to get the chip enable GPIO");
>> +
>> +     ctx->lpo_clk = devm_clk_get_optional(dev, NULL);
> Clock is not optional, according to you binding.
Yes, I will used API of devm_clk_get(dev, "extclk") to relace it.
>
>> +     if (IS_ERR(ctx->lpo_clk))
>> +             return dev_err_probe(dev, PTR_ERR(ctx->lpo_clk),
>> +                             "Failed to get the clock source");
>> +
>> +     memset(&config, 0, sizeof(config));
> Just initialize it on the stack with 0.
Okay, I will delete this line and set config to zero when initializing.
>
>
>
> Best regards,
> Krzysztof
>

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

* Re: [PATCH 1/3] dt-bindings: power: Add power sequence for Amloigc WCN chips
  2024-07-08  7:32           ` Krzysztof Kozlowski
@ 2024-07-08  8:21             ` Yang Li
  2024-07-08  9:10               ` Krzysztof Kozlowski
  0 siblings, 1 reply; 20+ messages in thread
From: Yang Li @ 2024-07-08  8:21 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Bartosz Golaszewski
  Cc: devicetree, linux-kernel, linux-pm


On 2024/7/8 15:32, Krzysztof Kozlowski wrote:
> On 08/07/2024 08:32, Yang Li wrote:
>> 在 2024/7/8 14:11, Krzysztof Kozlowski wrote:
>>> On 08/07/2024 08:04, Yang Li wrote:
>>>>>> +
>>>>>> +required:
>>>>>> +  - compatible
>>>>>> +  - clocks
>>>>>> +  - clock-names
>>>>>> +  - amlogic,chip-enable-gpios
>>>>>> +  - amlogic,bt-enable-gpios
>>>>>> +
>>>>>> +additionalProperties: false
>>>>>> +
>>>>>> +examples:
>>>>>> +  - |
>>>>>> +    #include <dt-bindings/gpio/gpio.h>
>>>>>> +    wcn_pwrseq {
>>>>> No underscores in node names, generic node names.
>>>>>
>>>>> There is no device as "pwrseq". I also do not get what "wcn" means here.
>>>> Yes, I understand.
>>>>
>>>> Can I change "wcn_pwrseq" to "pmu", and do I need to change the binding
>>> What is pmu for your device? What is this device in the first place you
>>> are documenting? Where is the datasheet?
>> ^_^ Well, You are right, the "pmu" wasn't really fit in here.
>>
>> I'd like to explain the current usage first, and could you please give
>> me a suggestion?
>>
>> This module(pwrseq) used to power on Bluetooth & Wi-Fi combo chip, both
>> Bluetooth and
>>
>> Wi-Fi driver need to control "chip-en-gpios" pins, so we introduced the
>> power sequence module.
>>
>> What should we call it in this case?
> Sorry, you describe driver, not a device.
>
> That would be a no-go for entire binding. Please describe the hardware,
> not what you want to achieve in Linux drivers.
W155s2 is a Bluetooth and WiFi combination chip. Bluetooth requires the 
bt-en pin to be pulled up, the chip-en pin to be pulled up, and the 
32.768KHz clock. WiFi requires the chip-en pin to be pulled up, and the 
32.768KHz clock. It can be seen that Bluetooth and WiFi are coupled to 
the chip-en pin and the 32.768KHz clock. When Bluetooth and WiFi are 
working at the same time, no matter which one is turned off, it will 
affect the other device. Therefore, a pwrseq device is now abstracted to 
manage the chip-en pin, bt-en pin, and the 32.768KHz clock.

There is currently no matching device name for the pwrseq composite device.

Could you please give me some advice?

>
> Best regards,
> Krzysztof
>

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

* Re: [PATCH 1/3] dt-bindings: power: Add power sequence for Amloigc WCN chips
  2024-07-08  8:21             ` Yang Li
@ 2024-07-08  9:10               ` Krzysztof Kozlowski
  2024-07-08  9:36                 ` Bartosz Golaszewski
  0 siblings, 1 reply; 20+ messages in thread
From: Krzysztof Kozlowski @ 2024-07-08  9:10 UTC (permalink / raw)
  To: Yang Li, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Bartosz Golaszewski
  Cc: devicetree, linux-kernel, linux-pm

On 08/07/2024 10:21, Yang Li wrote:
> 
> On 2024/7/8 15:32, Krzysztof Kozlowski wrote:
>> On 08/07/2024 08:32, Yang Li wrote:
>>> 在 2024/7/8 14:11, Krzysztof Kozlowski wrote:
>>>> On 08/07/2024 08:04, Yang Li wrote:
>>>>>>> +
>>>>>>> +required:
>>>>>>> +  - compatible
>>>>>>> +  - clocks
>>>>>>> +  - clock-names
>>>>>>> +  - amlogic,chip-enable-gpios
>>>>>>> +  - amlogic,bt-enable-gpios
>>>>>>> +
>>>>>>> +additionalProperties: false
>>>>>>> +
>>>>>>> +examples:
>>>>>>> +  - |
>>>>>>> +    #include <dt-bindings/gpio/gpio.h>
>>>>>>> +    wcn_pwrseq {
>>>>>> No underscores in node names, generic node names.
>>>>>>
>>>>>> There is no device as "pwrseq". I also do not get what "wcn" means here.
>>>>> Yes, I understand.
>>>>>
>>>>> Can I change "wcn_pwrseq" to "pmu", and do I need to change the binding
>>>> What is pmu for your device? What is this device in the first place you
>>>> are documenting? Where is the datasheet?
>>> ^_^ Well, You are right, the "pmu" wasn't really fit in here.

So no datasheet? Then you are on your own.

>>>
>>> I'd like to explain the current usage first, and could you please give
>>> me a suggestion?
>>>
>>> This module(pwrseq) used to power on Bluetooth & Wi-Fi combo chip, both
>>> Bluetooth and
>>>
>>> Wi-Fi driver need to control "chip-en-gpios" pins, so we introduced the
>>> power sequence module.
>>>
>>> What should we call it in this case?
>> Sorry, you describe driver, not a device.
>>
>> That would be a no-go for entire binding. Please describe the hardware,
>> not what you want to achieve in Linux drivers.
> W155s2 is a Bluetooth and WiFi combination chip. Bluetooth requires the 

I asked about this device here.

You speak now about W155s2 but everywhere else you were using "WCN".
What is that WCN?

> bt-en pin to be pulled up, the chip-en pin to be pulled up, and the 
> 32.768KHz clock. WiFi requires the chip-en pin to be pulled up, and the 
> 32.768KHz clock. It can be seen that Bluetooth and WiFi are coupled to 
> the chip-en pin and the 32.768KHz clock. When Bluetooth and WiFi are 
> working at the same time, no matter which one is turned off, it will 
> affect the other device. Therefore, a pwrseq device is now abstracted to 

It is the first time you mention pwrseq device from above paragraph.
Nothing above describes pwrseq.

Stop describing your problem, we all know it exactly if you follow the
discussions about power sequencing. Instead describe this particular
device you add binding for. What is this pwrseq in hardware? How does it
look? Where is it located? What are its pins? What are its supplies?

> manage the chip-en pin, bt-en pin, and the 32.768KHz clock.

> 
> There is currently no matching device name for the pwrseq composite device.

? No clue what does this mean.
> 
> Could you please give me some advice?

Again, you do not describe the device for the binding but something
else. Something for your drivers, sorry. No.

If you disagree, respond accurately to all questions above, not to only
some of them...

Best regards,
Krzysztof


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

* Re: [PATCH 1/3] dt-bindings: power: Add power sequence for Amloigc WCN chips
  2024-07-08  9:10               ` Krzysztof Kozlowski
@ 2024-07-08  9:36                 ` Bartosz Golaszewski
  0 siblings, 0 replies; 20+ messages in thread
From: Bartosz Golaszewski @ 2024-07-08  9:36 UTC (permalink / raw)
  To: Yang Li
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
	linux-kernel, linux-pm, Krzysztof Kozlowski

On Mon, Jul 8, 2024 at 11:10 AM Krzysztof Kozlowski <krzk@kernel.org> wrote:
>
> On 08/07/2024 10:21, Yang Li wrote:
> >
> > On 2024/7/8 15:32, Krzysztof Kozlowski wrote:
> >> On 08/07/2024 08:32, Yang Li wrote:
> >>> 在 2024/7/8 14:11, Krzysztof Kozlowski wrote:
> >>>> On 08/07/2024 08:04, Yang Li wrote:
> >>>>>>> +
> >>>>>>> +required:
> >>>>>>> +  - compatible
> >>>>>>> +  - clocks
> >>>>>>> +  - clock-names
> >>>>>>> +  - amlogic,chip-enable-gpios
> >>>>>>> +  - amlogic,bt-enable-gpios
> >>>>>>> +
> >>>>>>> +additionalProperties: false
> >>>>>>> +
> >>>>>>> +examples:
> >>>>>>> +  - |
> >>>>>>> +    #include <dt-bindings/gpio/gpio.h>
> >>>>>>> +    wcn_pwrseq {
> >>>>>> No underscores in node names, generic node names.
> >>>>>>
> >>>>>> There is no device as "pwrseq". I also do not get what "wcn" means here.
> >>>>> Yes, I understand.
> >>>>>
> >>>>> Can I change "wcn_pwrseq" to "pmu", and do I need to change the binding
> >>>> What is pmu for your device? What is this device in the first place you
> >>>> are documenting? Where is the datasheet?
> >>> ^_^ Well, You are right, the "pmu" wasn't really fit in here.
>
> So no datasheet? Then you are on your own.
>
> >>>
> >>> I'd like to explain the current usage first, and could you please give
> >>> me a suggestion?
> >>>
> >>> This module(pwrseq) used to power on Bluetooth & Wi-Fi combo chip, both
> >>> Bluetooth and
> >>>
> >>> Wi-Fi driver need to control "chip-en-gpios" pins, so we introduced the
> >>> power sequence module.
> >>>
> >>> What should we call it in this case?
> >> Sorry, you describe driver, not a device.
> >>
> >> That would be a no-go for entire binding. Please describe the hardware,
> >> not what you want to achieve in Linux drivers.
> > W155s2 is a Bluetooth and WiFi combination chip. Bluetooth requires the
>
> I asked about this device here.
>
> You speak now about W155s2 but everywhere else you were using "WCN".
> What is that WCN?
>
> > bt-en pin to be pulled up, the chip-en pin to be pulled up, and the
> > 32.768KHz clock. WiFi requires the chip-en pin to be pulled up, and the
> > 32.768KHz clock. It can be seen that Bluetooth and WiFi are coupled to
> > the chip-en pin and the 32.768KHz clock. When Bluetooth and WiFi are
> > working at the same time, no matter which one is turned off, it will
> > affect the other device. Therefore, a pwrseq device is now abstracted to
>
> It is the first time you mention pwrseq device from above paragraph.
> Nothing above describes pwrseq.
>
> Stop describing your problem, we all know it exactly if you follow the
> discussions about power sequencing. Instead describe this particular
> device you add binding for. What is this pwrseq in hardware? How does it
> look? Where is it located? What are its pins? What are its supplies?
>
> > manage the chip-en pin, bt-en pin, and the 32.768KHz clock.
>
> >
> > There is currently no matching device name for the pwrseq composite device.
>
> ? No clue what does this mean.
> >
> > Could you please give me some advice?
>
> Again, you do not describe the device for the binding but something
> else. Something for your drivers, sorry. No.
>
> If you disagree, respond accurately to all questions above, not to only
> some of them...
>
> Best regards,
> Krzysztof
>

Yang, please look at the existing pwrseq-qcom-wcn.c driver and its
bindings. They do exactly what you most likely want to do here. They
describe the power management unit of the chipset, its inputs from
host and outputs consumed by the WLAN and BT modules. Please try to
follow it for your device.

Bart

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

* Re: [PATCH 2/3] power: sequenceing: Add power sequence for Amlogic WCN chips
  2024-07-05 13:46   ` Bartosz Golaszewski
@ 2024-07-10  3:00     ` Yang Li
  0 siblings, 0 replies; 20+ messages in thread
From: Yang Li @ 2024-07-10  3:00 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, devicetree,
	linux-kernel, linux-pm


On 2024/7/5 21:46, Bartosz Golaszewski wrote:
> On Fri, Jul 5, 2024 at 1:13 PM Yang Li via B4 Relay
> <devnull+yang.li.amlogic.com@kernel.org>  wrote:
>> From: Yang Li<yang.li@amlogic.com>
>>
>> Add power sequence for Bluetooth and Wi-Fi respectively, including chip_en
>> pull-up and bt_en pull-up, and generation of the 32.768 clock.
>>
>> Signed-off-by: Yang Li<yang.li@amlogic.com>
>> ---
>>   drivers/power/sequencing/Kconfig          |   7 +
>>   drivers/power/sequencing/Makefile         |   1 +
>>   drivers/power/sequencing/pwrseq-aml-wcn.c | 209 ++++++++++++++++++++++++++++++
>>   3 files changed, 217 insertions(+)
>>
>> diff --git a/drivers/power/sequencing/Kconfig b/drivers/power/sequencing/Kconfig
>> index c9f1cdb66524..65d3b2c20bfb 100644
>> --- a/drivers/power/sequencing/Kconfig
>> +++ b/drivers/power/sequencing/Kconfig
>> @@ -26,4 +26,11 @@ config POWER_SEQUENCING_QCOM_WCN
>>            this driver is needed for correct power control or else we'd risk not
>>            respecting the required delays between enabling Bluetooth and WLAN.
>>
>> +config POWER_SEQUENCING_AML_WCN
>> +       tristate "Amlogic WCN family PMU driver"
>> +       default m if ARCH_MESON
>> +       help
>> +         Say Y here to enable the power sequencing driver for Amlogic
>> +         WCN Bluetooth/WLAN chipsets.
>> +
>>   endif
>> diff --git a/drivers/power/sequencing/Makefile b/drivers/power/sequencing/Makefile
>> index 2eec2df7912d..32706daf8f0f 100644
>> --- a/drivers/power/sequencing/Makefile
>> +++ b/drivers/power/sequencing/Makefile
>> @@ -4,3 +4,4 @@ obj-$(CONFIG_POWER_SEQUENCING)          += pwrseq-core.o
>>   pwrseq-core-y                          := core.o
>>
>>   obj-$(CONFIG_POWER_SEQUENCING_QCOM_WCN)        += pwrseq-qcom-wcn.o
>> +obj-$(CONFIG_POWER_SEQUENCING_AML_WCN) += pwrseq-aml-wcn.o
>> diff --git a/drivers/power/sequencing/pwrseq-aml-wcn.c b/drivers/power/sequencing/pwrseq-aml-wcn.c
>> new file mode 100644
>> index 000000000000..6f5bfcf60b9c
>> --- /dev/null
>> +++ b/drivers/power/sequencing/pwrseq-aml-wcn.c
>> @@ -0,0 +1,209 @@
>> +// SPDX-License-Identifier: (GPL-2.0-only OR MIT)
>> +/*
>> + * Copyright (C) 2024 Amlogic, Inc. All rights reserved
>> + */
>> +
>> +#include <linux/clk.h>
>> +#include <linux/delay.h>
>> +#include <linux/device.h>
>> +#include <linux/mod_devicetable.h>
>> +#include <linux/module.h>
>> +#include <linux/mutex.h>
>> +#include <linux/of.h>
>> +#include <linux/gpio.h>
> Please see line 5 in this file.
I got it, I will remove this line, and include linux/gpio/consumer.h.
>> +#include <linux/of_gpio.h>
> You don't need this either.
Yes, I will remove it.
>> +#include <linux/platform_device.h>
>> +#include <linux/pwrseq/provider.h>
>> +#include <linux/string.h>
>> +#include <linux/types.h>
>> +
>> +struct pwrseq_aml_wcn_ctx {
>> +       struct pwrseq_device *pwrseq;
>> +       int bt_enable_gpio;
>> +       int chip_enable_gpio;
>> +       struct clk *lpo_clk;
>> +       unsigned int pwr_count;
>> +};
>> +
>> +static DEFINE_MUTEX(pwrseq_lock);
>> +
> Why is this global?
Okay, I will add it to structure of pwrseq_aml_wcn_ctx .
>> +static int pwrseq_aml_wcn_chip_enable(struct pwrseq_device *pwrseq)
>> +{
>> +       struct pwrseq_aml_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
>> +       int err;
>> +
>> +       mutex_lock(&pwrseq_lock);
> Please use guard() from linux/cleanup.h.
Well, I will use guard(mutex)(&pwrse_lock) to replace 
mutex_lock(&pwrseq_lock).
>> +       if (ctx->pwr_count == 0) {
>> +               gpio_request(ctx->chip_enable_gpio, "chip-enable-gpios");
>> +               gpio_direction_output(ctx->chip_enable_gpio, 1);
>> +               gpio_free(ctx->chip_enable_gpio);
> Not only are these legacy APIs but they are also used wrong. You
> almost never want to release the GPIO after setting the direction as
> someone else may grab it and use it.
Okay, I will use consumer API of devm_gpiod_get() to replace them.
>> +
>> +               if (!IS_ERR(ctx->lpo_clk)) {
>> +                       err = clk_prepare_enable(ctx->lpo_clk);
>> +                       if (err) {
>> +                               mutex_unlock(&pwrseq_lock);
>> +                               return err;
>> +                       }
>> +               }
>> +       }
>> +
>> +       ctx->pwr_count++;
>> +       mutex_unlock(&pwrseq_lock);
>> +       return 0;
>> +}
>> +
>> +static int pwrseq_aml_wcn_chip_disable(struct pwrseq_device *pwrseq)
>> +{
>> +       struct pwrseq_aml_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
>> +
>> +       mutex_lock(&pwrseq_lock);
>> +       if (--ctx->pwr_count == 0) {
>> +               gpio_request(ctx->chip_enable_gpio, "chip-enable-gpios");
>> +               gpio_direction_output(ctx->chip_enable_gpio, 0);
>> +               gpio_free(ctx->chip_enable_gpio);
>> +
>> +               if (!IS_ERR(ctx->lpo_clk))
>> +                       clk_disable_unprepare(ctx->lpo_clk);
>> +       }
>> +
>> +       mutex_unlock(&pwrseq_lock);
>> +       return 0;
>> +}
>> +
>> +static const struct pwrseq_unit_data pwrseq_aml_wcn_chip_power_unit_data = {
>> +       .name = "chip-enable",
>> +       .enable = pwrseq_aml_wcn_chip_enable,
>> +       .disable = pwrseq_aml_wcn_chip_disable,
>> +};
>> +
>> +static const struct pwrseq_unit_data *pwrseq_aml_wcn_unit_deps[] = {
>> +       &pwrseq_aml_wcn_chip_power_unit_data,
>> +       NULL
>> +};
>> +
>> +static int pwrseq_aml_wcn_bt_enable(struct pwrseq_device *pwrseq)
>> +{
>> +       struct pwrseq_aml_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
>> +
>> +       gpio_request(ctx->bt_enable_gpio, "bt-enable-gpios");
>> +       gpio_direction_output(ctx->bt_enable_gpio, 1);
>> +       gpio_free(ctx->bt_enable_gpio);
>> +
>> +       /* wait 100ms for bluetooth controller power on  */
>> +       msleep(100);
>> +
>> +       return 0;
>> +}
>> +
>> +static int pwrseq_aml_wcn_bt_disable(struct pwrseq_device *pwrseq)
>> +{
>> +       struct pwrseq_aml_wcn_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
>> +
>> +       gpio_request(ctx->bt_enable_gpio, "bt-enable-gpios");
>> +       gpio_direction_output(ctx->bt_enable_gpio, 0);
>> +       gpio_free(ctx->bt_enable_gpio);
>> +
>> +       return 0;
>> +}
>> +
>> +static const struct pwrseq_unit_data pwrseq_aml_wcn_bt_unit_data = {
>> +       .name = "bluetooth-enable",
>> +       .deps = pwrseq_aml_wcn_unit_deps,
>> +       .enable = pwrseq_aml_wcn_bt_enable,
>> +       .disable = pwrseq_aml_wcn_bt_disable,
>> +};
>> +
>> +static const struct pwrseq_unit_data pwrseq_aml_wcn_wlan_unit_data = {
>> +       .name = "wlan-enable",
>> +       .deps = pwrseq_aml_wcn_unit_deps,
>> +};
>> +
>> +static const struct pwrseq_target_data pwrseq_aml_wcn_bt_target_data = {
>> +       .name = "bluetooth",
>> +       .unit = &pwrseq_aml_wcn_bt_unit_data,
>> +};
>> +
>> +static const struct pwrseq_target_data pwrseq_aml_wcn_wlan_target_data = {
>> +       .name = "wlan",
>> +       .unit = &pwrseq_aml_wcn_wlan_unit_data,
>> +};
>> +
>> +static const struct pwrseq_target_data *pwrseq_aml_wcn_targets[] = {
>> +       &pwrseq_aml_wcn_bt_target_data,
>> +       &pwrseq_aml_wcn_wlan_target_data,
>> +       NULL
>> +};
>> +
>> +static int pwrseq_aml_wcn_match(struct pwrseq_device *pwrseq,
>> +                                struct device *dev)
>> +{
>> +       struct device_node *dev_node = dev->of_node;
>> +
>> +       if (!of_property_present(dev_node, "amlogic,wcn-pwrseq"))
>> +               return 0;
>> +
> You must never reference the notion of power sequencing in the DT.
> Please take a look at the pwrseq-qcom-wcn driver where we model the
> PMU with its regulators and then parse them in match() to figure out
> if we have the right thing or not.

There is some different between pwrseq-aml-wcn and pwrseq-qcom-wcn, 
pwrseq-aml-wcn device is abstracted to manage the chip-en pin, bt-en 
pin, and 32.768KHz clock. The drivers/power/sequence/core.c requirements 
need to be defined match () function is used to determine whether a 
potential consumers actually related to the sequencer. So, I need to add 
a meaningless node "amlogic,wcn-pwrseq" to both the consumer dt-binding 
and the provider dt-binding.

Right now, I add "amlogic,wcn-pwrseq" in binding file of 
"amlogic,w155s2-bt.yaml" only, may I need to add this properties 
("amlogic,wcn-pwrseq") in the binding file of "amlogic,w155s2-pwrseq.yaml"?

Or there are any others way to fixed this issue please let me know.

>> +       return 1;
>> +}
>> +
>> +static int pwrseq_aml_wcn_probe(struct platform_device *pdev)
>> +{
>> +       struct device *dev = &pdev->dev;
>> +       struct pwrseq_aml_wcn_ctx *ctx;
>> +       struct pwrseq_config config;
>> +
>> +       ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
>> +       if (!ctx)
>> +               return -ENOMEM;
>> +
>> +       ctx->bt_enable_gpio = of_get_named_gpio(dev->of_node,
>> +                                              "amlogic,bt-enable-gpios", 0);
>> +       if (!gpio_is_valid(ctx->bt_enable_gpio))
>> +               return dev_err_probe(dev, ctx->bt_enable_gpio,
>> +                               "Failed to get the bt enable GPIO");
>> +
>> +       ctx->chip_enable_gpio = of_get_named_gpio(dev->of_node,
>> +                                              "amlogic,chip-enable-gpios", 0);
> You don't need the OF variant. Use the regular devm_gpiod_get(). You
> also forgot to release it but the devres variant will take care of it.
Well, I will do it.
>
>> +       if (!gpio_is_valid(ctx->chip_enable_gpio))
>> +               return dev_err_probe(dev, ctx->bt_enable_gpio,
>> +                                       "Failed to get the chip enable GPIO");
> Wat
I got it, and I will fix it.
>
>> +
>> +       ctx->lpo_clk = devm_clk_get_optional(dev, NULL);
>> +       if (IS_ERR(ctx->lpo_clk))
>> +               return dev_err_probe(dev, PTR_ERR(ctx->lpo_clk),
>> +                               "Failed to get the clock source");
>> +
>> +       memset(&config, 0, sizeof(config));
>> +
>> +       config.parent = dev;
>> +       config.owner = THIS_MODULE;
>> +       config.drvdata = ctx;
>> +       config.match = pwrseq_aml_wcn_match;
>> +       config.targets = pwrseq_aml_wcn_targets;
>> +
>> +       ctx->pwr_count = 0;
>> +       ctx->pwrseq = devm_pwrseq_device_register(dev, &config);
>> +       if (IS_ERR(ctx->pwrseq))
>> +               return dev_err_probe(dev, PTR_ERR(ctx->pwrseq),
>> +                                    "Failed to register the power sequencer\n");
>> +
>> +       return 0;
>> +}
>> +
>> +static const struct of_device_id pwrseq_aml_wcn_of_match[] = {
>> +       { .compatible = "amlogic,w155s2-pwrseq" },
>> +       { /* sentinel */ },
>> +};
>> +MODULE_DEVICE_TABLE(of, pwrseq_aml_wcn_of_match);
>> +
>> +static struct platform_driver pwrseq_aml_wcn_driver = {
>> +       .driver = {
>> +               .name = "pwrseq-aml_wcn",
>> +               .of_match_table = pwrseq_aml_wcn_of_match,
>> +       },
>> +       .probe = pwrseq_aml_wcn_probe,
>> +};
>> +module_platform_driver(pwrseq_aml_wcn_driver);
>> +
>> +MODULE_AUTHOR("Yang Li<yang.li@amlogic.com>");
>> +MODULE_DESCRIPTION("Amlogic WCN PMU power sequencing driver");
>> +MODULE_LICENSE("GPL");
>>
>> --
>> 2.42.0
>>
>>
> Bart

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

end of thread, other threads:[~2024-07-10  3:00 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-05 11:13 [PATCH 0/3] Add power sequence for Amlogic WCN chips Yang Li via B4 Relay
2024-07-05 11:13 ` [PATCH 1/3] dt-bindings: power: Add power sequence for Amloigc " Yang Li via B4 Relay
2024-07-05 13:34   ` Bartosz Golaszewski
2024-07-08  6:12     ` Yang Li
2024-07-07 12:59   ` Krzysztof Kozlowski
2024-07-08  6:04     ` Yang Li
2024-07-08  6:11       ` Krzysztof Kozlowski
2024-07-08  6:32         ` Yang Li
2024-07-08  7:32           ` Krzysztof Kozlowski
2024-07-08  8:21             ` Yang Li
2024-07-08  9:10               ` Krzysztof Kozlowski
2024-07-08  9:36                 ` Bartosz Golaszewski
2024-07-05 11:13 ` [PATCH 2/3] power: sequenceing: Add power sequence for Amlogic " Yang Li via B4 Relay
2024-07-05 13:46   ` Bartosz Golaszewski
2024-07-10  3:00     ` Yang Li
2024-07-07 13:02   ` Krzysztof Kozlowski
2024-07-08  7:41     ` Yang Li
2024-07-05 11:13 ` [PATCH 3/3] MAINTAINERS: Add an entry for Amlogic WCN power sequence Yang Li via B4 Relay
2024-07-07 13:04   ` Krzysztof Kozlowski
2024-07-08  6:34     ` Yang Li

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