linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V5 0/5] can: flexcan: add stop mode support for i.MX8QM
@ 2020-11-06 10:56 Joakim Zhang
  2020-11-06 10:56 ` [PATCH V5 1/5] dt-bindings: can: flexcan: fix fsl,clk-source property Joakim Zhang
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Joakim Zhang @ 2020-11-06 10:56 UTC (permalink / raw)
  To: mkl, robh+dt, shawnguo, s.hauer
  Cc: kernel, linux-imx, linux-can, netdev, linux-kernel

Add stop mode support for i.MX8QM.

ChangeLogs:
V4->V5:
	* remove patch:firmware: imx: always export SCU symbols, since
	it done by commit: 95de5094f5ac firmware: imx: add dummy functions
	* rebase to fsl,flexcan.yaml

V3->V4:
	* can_idx->scu_idx.
	* return imx_scu_get_handle(&priv->sc_ipc_handle);
	* failed_canregister->failed_setup_stop_mode.

V2->V3:
	* define IMX_SC_R_CAN(x) in rsrc.h
	* remove error message on -EPROBE_DEFER.
	* split disable wakeup patch into separate one.

V1->V2:
	* split ECC fix patches into separate patches.
	* free can dev if failed to setup stop mode.
	* disable wakeup on flexcan_remove.
	* add FLEXCAN_IMX_SC_R_CAN macro helper.
	* fsl,can-index->fsl,scu-index.
	* move fsl,scu-index and priv->can_idx into
	* flexcan_setup_stop_mode_scfw()
	* prove failed if failed to setup stop mode.

Joakim Zhang (5):
  dt-bindings: can: flexcan: fix fsl,clk-source property
  dt-bindings: can: flexcan: add fsl,scu-index property to indicate a
    resource
  can: flexcan: rename macro FLEXCAN_QUIRK_SETUP_STOP_MODE ->
    FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR
  dt-bindings: firmware: add IMX_SC_R_CAN(x) macro for CAN
  can: flexcan: add CAN wakeup function for i.MX8QM

 .../bindings/net/can/fsl,flexcan.yaml         |  15 +-
 drivers/net/can/flexcan.c                     | 131 +++++++++++++++---
 include/dt-bindings/firmware/imx/rsrc.h       |   1 +
 3 files changed, 124 insertions(+), 23 deletions(-)

-- 
2.17.1


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

* [PATCH V5 1/5] dt-bindings: can: flexcan: fix fsl,clk-source property
  2020-11-06 10:56 [PATCH V5 0/5] can: flexcan: add stop mode support for i.MX8QM Joakim Zhang
@ 2020-11-06 10:56 ` Joakim Zhang
  2020-11-06 10:56 ` [PATCH V5 2/5] dt-bindings: can: flexcan: add fsl,scu-index property to indicate a resource Joakim Zhang
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Joakim Zhang @ 2020-11-06 10:56 UTC (permalink / raw)
  To: mkl, robh+dt, shawnguo, s.hauer
  Cc: kernel, linux-imx, linux-can, netdev, linux-kernel

Correct fsl,clk-source example since flexcan driver uses "of_property_read_u8"
to get this property.

Fixes: 9d733992772d ("dt-bindings: can: flexcan: add PE clock source property to device tree")
Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
---
 Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml b/Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml
index 43df15ba8fa4..8f4db883e16b 100644
--- a/Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml
+++ b/Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml
@@ -95,7 +95,7 @@ properties:
       by default.
       0: clock source 0 (oscillator clock)
       1: clock source 1 (peripheral clock)
-    $ref: /schemas/types.yaml#/definitions/uint32
+    $ref: /schemas/types.yaml#/definitions/uint8
     default: 1
     minimum: 0
     maximum: 1
@@ -120,7 +120,7 @@ examples:
         interrupts = <48 0x2>;
         interrupt-parent = <&mpic>;
         clock-frequency = <200000000>;
-        fsl,clk-source = <0>;
+        fsl,clk-source = /bits/ 8 <0>;
     };
   - |
     #include <dt-bindings/interrupt-controller/irq.h>
-- 
2.17.1


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

* [PATCH V5 2/5] dt-bindings: can: flexcan: add fsl,scu-index property to indicate a resource
  2020-11-06 10:56 [PATCH V5 0/5] can: flexcan: add stop mode support for i.MX8QM Joakim Zhang
  2020-11-06 10:56 ` [PATCH V5 1/5] dt-bindings: can: flexcan: fix fsl,clk-source property Joakim Zhang
@ 2020-11-06 10:56 ` Joakim Zhang
  2020-11-06 10:56 ` [PATCH V5 3/5] can: flexcan: rename macro FLEXCAN_QUIRK_SETUP_STOP_MODE -> FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR Joakim Zhang
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Joakim Zhang @ 2020-11-06 10:56 UTC (permalink / raw)
  To: mkl, robh+dt, shawnguo, s.hauer
  Cc: kernel, linux-imx, linux-can, netdev, linux-kernel

For SoCs with SCU support, need setup stop mode via SCU firmware,
so this property can help indicate a resource in SCU firmware.

Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
---
 .../devicetree/bindings/net/can/fsl,flexcan.yaml      | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml b/Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml
index 8f4db883e16b..2631dad8f85f 100644
--- a/Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml
+++ b/Documentation/devicetree/bindings/net/can/fsl,flexcan.yaml
@@ -105,6 +105,16 @@ properties:
     description:
       Enable CAN remote wakeup.
 
+  fsl,scu-index:
+    description: |
+      The scu index of CAN instance.
+      For SoCs with SCU support, need setup stop mode via SCU firmware, so this
+      property can help indicate a resource. It supports up to 3 CAN instances
+      now.
+    $ref: /schemas/types.yaml#/definitions/uint8
+    minimum: 0
+    maximum: 2
+
 required:
   - compatible
   - reg
@@ -132,4 +142,5 @@ examples:
         clocks = <&clks 1>, <&clks 2>;
         clock-names = "ipg", "per";
         fsl,stop-mode = <&gpr 0x34 28>;
+        fsl,scu-index = /bits/ 8 <1>;
     };
-- 
2.17.1


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

* [PATCH V5 3/5] can: flexcan: rename macro FLEXCAN_QUIRK_SETUP_STOP_MODE -> FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR
  2020-11-06 10:56 [PATCH V5 0/5] can: flexcan: add stop mode support for i.MX8QM Joakim Zhang
  2020-11-06 10:56 ` [PATCH V5 1/5] dt-bindings: can: flexcan: fix fsl,clk-source property Joakim Zhang
  2020-11-06 10:56 ` [PATCH V5 2/5] dt-bindings: can: flexcan: add fsl,scu-index property to indicate a resource Joakim Zhang
@ 2020-11-06 10:56 ` Joakim Zhang
  2020-11-06 10:56 ` [PATCH V5 4/5] dt-bindings: firmware: add IMX_SC_R_CAN(x) macro for CAN Joakim Zhang
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Joakim Zhang @ 2020-11-06 10:56 UTC (permalink / raw)
  To: mkl, robh+dt, shawnguo, s.hauer
  Cc: kernel, linux-imx, linux-can, netdev, linux-kernel

This patch intends to rename FLEXCAN_QUIRK_SETUP_STOP_MODE quirk
to FLEXCAN_QUIRK_SETUP_STOP_MODE_GRP for non-scu SoCs, coming patch will
add quirk for scu SoCs.

For non-scu SoCs, setup stop mode with GPR register.
For scu SoCs, setup stop mode with SCU firmware.

Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
---
 drivers/net/can/flexcan.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 881799bd9c5e..8f578c867493 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -236,8 +236,8 @@
 #define FLEXCAN_QUIRK_BROKEN_PERR_STATE BIT(6)
 /* default to BE register access */
 #define FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN BIT(7)
-/* Setup stop mode to support wakeup */
-#define FLEXCAN_QUIRK_SETUP_STOP_MODE BIT(8)
+/* Setup stop mode with GPR to support wakeup */
+#define FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR BIT(8)
 /* Support CAN-FD mode */
 #define FLEXCAN_QUIRK_SUPPORT_FD BIT(9)
 /* support memory detection and correction */
@@ -381,7 +381,7 @@ static const struct flexcan_devtype_data fsl_imx28_devtype_data = {
 static const struct flexcan_devtype_data fsl_imx6q_devtype_data = {
 	.quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS |
 		FLEXCAN_QUIRK_USE_OFF_TIMESTAMP | FLEXCAN_QUIRK_BROKEN_PERR_STATE |
-		FLEXCAN_QUIRK_SETUP_STOP_MODE,
+		FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR,
 };
 
 static const struct flexcan_devtype_data fsl_imx8qm_devtype_data = {
@@ -393,7 +393,7 @@ static const struct flexcan_devtype_data fsl_imx8qm_devtype_data = {
 static struct flexcan_devtype_data fsl_imx8mp_devtype_data = {
 	.quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS |
 		FLEXCAN_QUIRK_DISABLE_MECR | FLEXCAN_QUIRK_USE_OFF_TIMESTAMP |
-		FLEXCAN_QUIRK_BROKEN_PERR_STATE | FLEXCAN_QUIRK_SETUP_STOP_MODE |
+		FLEXCAN_QUIRK_BROKEN_PERR_STATE | FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR |
 		FLEXCAN_QUIRK_SUPPORT_FD | FLEXCAN_QUIRK_SUPPORT_ECC,
 };
 
@@ -2043,7 +2043,7 @@ static int flexcan_probe(struct platform_device *pdev)
 	of_can_transceiver(dev);
 	devm_can_led_init(dev);
 
-	if (priv->devtype_data->quirks & FLEXCAN_QUIRK_SETUP_STOP_MODE) {
+	if (priv->devtype_data->quirks & FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR) {
 		err = flexcan_setup_stop_mode(pdev);
 		if (err)
 			dev_dbg(&pdev->dev, "failed to setup stop-mode\n");
-- 
2.17.1


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

* [PATCH V5 4/5] dt-bindings: firmware: add IMX_SC_R_CAN(x) macro for CAN
  2020-11-06 10:56 [PATCH V5 0/5] can: flexcan: add stop mode support for i.MX8QM Joakim Zhang
                   ` (2 preceding siblings ...)
  2020-11-06 10:56 ` [PATCH V5 3/5] can: flexcan: rename macro FLEXCAN_QUIRK_SETUP_STOP_MODE -> FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR Joakim Zhang
@ 2020-11-06 10:56 ` Joakim Zhang
  2020-11-06 10:56 ` [PATCH V5 5/5] can: flexcan: add CAN wakeup function for i.MX8QM Joakim Zhang
  2020-11-06 11:32 ` [PATCH V5 0/5] can: flexcan: add stop mode support " Marc Kleine-Budde
  5 siblings, 0 replies; 10+ messages in thread
From: Joakim Zhang @ 2020-11-06 10:56 UTC (permalink / raw)
  To: mkl, robh+dt, shawnguo, s.hauer
  Cc: kernel, linux-imx, linux-can, netdev, linux-kernel

Add IMX_SC_R_CAN(x) macro for CAN.

Suggested-by: Marc Kleine-Budde <mkl@pengutronix.de>
Acked-by: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
---
 include/dt-bindings/firmware/imx/rsrc.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/dt-bindings/firmware/imx/rsrc.h b/include/dt-bindings/firmware/imx/rsrc.h
index 54278d5c1856..43885056557c 100644
--- a/include/dt-bindings/firmware/imx/rsrc.h
+++ b/include/dt-bindings/firmware/imx/rsrc.h
@@ -111,6 +111,7 @@
 #define IMX_SC_R_CAN_0			105
 #define IMX_SC_R_CAN_1			106
 #define IMX_SC_R_CAN_2			107
+#define IMX_SC_R_CAN(x)			(IMX_SC_R_CAN_0 + (x))
 #define IMX_SC_R_DMA_1_CH0		108
 #define IMX_SC_R_DMA_1_CH1		109
 #define IMX_SC_R_DMA_1_CH2		110
-- 
2.17.1


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

* [PATCH V5 5/5] can: flexcan: add CAN wakeup function for i.MX8QM
  2020-11-06 10:56 [PATCH V5 0/5] can: flexcan: add stop mode support for i.MX8QM Joakim Zhang
                   ` (3 preceding siblings ...)
  2020-11-06 10:56 ` [PATCH V5 4/5] dt-bindings: firmware: add IMX_SC_R_CAN(x) macro for CAN Joakim Zhang
@ 2020-11-06 10:56 ` Joakim Zhang
  2020-11-20 12:24   ` Marc Kleine-Budde
  2020-11-06 11:32 ` [PATCH V5 0/5] can: flexcan: add stop mode support " Marc Kleine-Budde
  5 siblings, 1 reply; 10+ messages in thread
From: Joakim Zhang @ 2020-11-06 10:56 UTC (permalink / raw)
  To: mkl, robh+dt, shawnguo, s.hauer
  Cc: kernel, linux-imx, linux-can, netdev, linux-kernel

The System Controller Firmware (SCFW) is a low-level system function
which runs on a dedicated Cortex-M core to provide power, clock, and
resource management. It exists on some i.MX8 processors. e.g. i.MX8QM
(QM, QP), and i.MX8QX (QXP, DX). SCU driver manages the IPC interface
between host CPU and the SCU firmware running on M4.

For i.MX8QM, stop mode request is controlled by System Controller Unit(SCU)
firmware, this patch introduces FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW quirk
for this function.

Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
---
 drivers/net/can/flexcan.c | 123 ++++++++++++++++++++++++++++++++------
 1 file changed, 106 insertions(+), 17 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 8f578c867493..1f2adbc606f5 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -9,6 +9,7 @@
 //
 // Based on code originally by Andrey Volkov <avolkov@varma-el.com>
 
+#include <dt-bindings/firmware/imx/rsrc.h>
 #include <linux/bitfield.h>
 #include <linux/can.h>
 #include <linux/can/dev.h>
@@ -17,6 +18,7 @@
 #include <linux/can/rx-offload.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
+#include <linux/firmware/imx/sci.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/mfd/syscon.h>
@@ -242,6 +244,8 @@
 #define FLEXCAN_QUIRK_SUPPORT_FD BIT(9)
 /* support memory detection and correction */
 #define FLEXCAN_QUIRK_SUPPORT_ECC BIT(10)
+/* Setup stop mode with SCU firmware to support wakeup */
+#define FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW BIT(11)
 
 /* Structure of the message buffer */
 struct flexcan_mb {
@@ -347,6 +351,7 @@ struct flexcan_priv {
 	u8 mb_count;
 	u8 mb_size;
 	u8 clk_src;	/* clock source of CAN Protocol Engine */
+	u8 scu_idx;
 
 	u64 rx_mask;
 	u64 tx_mask;
@@ -358,6 +363,9 @@ struct flexcan_priv {
 	struct regulator *reg_xceiver;
 	struct flexcan_stop_mode stm;
 
+	/* IPC handle when setup stop mode by System Controller firmware(scfw) */
+	struct imx_sc_ipc *sc_ipc_handle;
+
 	/* Read and Write APIs */
 	u32 (*read)(void __iomem *addr);
 	void (*write)(u32 val, void __iomem *addr);
@@ -387,7 +395,7 @@ static const struct flexcan_devtype_data fsl_imx6q_devtype_data = {
 static const struct flexcan_devtype_data fsl_imx8qm_devtype_data = {
 	.quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS |
 		FLEXCAN_QUIRK_USE_OFF_TIMESTAMP | FLEXCAN_QUIRK_BROKEN_PERR_STATE |
-		FLEXCAN_QUIRK_SUPPORT_FD,
+		FLEXCAN_QUIRK_SUPPORT_FD | FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW,
 };
 
 static struct flexcan_devtype_data fsl_imx8mp_devtype_data = {
@@ -546,18 +554,42 @@ static void flexcan_enable_wakeup_irq(struct flexcan_priv *priv, bool enable)
 	priv->write(reg_mcr, &regs->mcr);
 }
 
+static int flexcan_stop_mode_enable_scfw(struct flexcan_priv *priv, bool enabled)
+{
+	u8 idx = priv->scu_idx;
+	u32 rsrc_id, val;
+
+	rsrc_id = IMX_SC_R_CAN(idx);
+
+	if (enabled)
+		val = 1;
+	else
+		val = 0;
+
+	/* stop mode request via scu firmware */
+	return imx_sc_misc_set_control(priv->sc_ipc_handle, rsrc_id,
+				       IMX_SC_C_IPG_STOP, val);
+}
+
 static inline int flexcan_enter_stop_mode(struct flexcan_priv *priv)
 {
 	struct flexcan_regs __iomem *regs = priv->regs;
 	u32 reg_mcr;
+	int ret;
 
 	reg_mcr = priv->read(&regs->mcr);
 	reg_mcr |= FLEXCAN_MCR_SLF_WAK;
 	priv->write(reg_mcr, &regs->mcr);
 
 	/* enable stop request */
-	regmap_update_bits(priv->stm.gpr, priv->stm.req_gpr,
-			   1 << priv->stm.req_bit, 1 << priv->stm.req_bit);
+	if (priv->devtype_data->quirks & FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW) {
+		ret = flexcan_stop_mode_enable_scfw(priv, true);
+		if (ret < 0)
+			return ret;
+	} else {
+		regmap_update_bits(priv->stm.gpr, priv->stm.req_gpr,
+				   1 << priv->stm.req_bit, 1 << priv->stm.req_bit);
+	}
 
 	return flexcan_low_power_enter_ack(priv);
 }
@@ -566,10 +598,17 @@ static inline int flexcan_exit_stop_mode(struct flexcan_priv *priv)
 {
 	struct flexcan_regs __iomem *regs = priv->regs;
 	u32 reg_mcr;
+	int ret;
 
 	/* remove stop request */
-	regmap_update_bits(priv->stm.gpr, priv->stm.req_gpr,
-			   1 << priv->stm.req_bit, 0);
+	if (priv->devtype_data->quirks & FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW) {
+		ret = flexcan_stop_mode_enable_scfw(priv, false);
+		if (ret < 0)
+			return ret;
+	} else {
+		regmap_update_bits(priv->stm.gpr, priv->stm.req_gpr,
+				   1 << priv->stm.req_bit, 0);
+	}
 
 	reg_mcr = priv->read(&regs->mcr);
 	reg_mcr &= ~FLEXCAN_MCR_SLF_WAK;
@@ -1838,7 +1877,7 @@ static void unregister_flexcandev(struct net_device *dev)
 	unregister_candev(dev);
 }
 
-static int flexcan_setup_stop_mode(struct platform_device *pdev)
+static int flexcan_setup_stop_mode_gpr(struct platform_device *pdev)
 {
 	struct net_device *dev = platform_get_drvdata(pdev);
 	struct device_node *np = pdev->dev.of_node;
@@ -1883,11 +1922,6 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev)
 		"gpr %s req_gpr=0x02%x req_bit=%u\n",
 		gpr_np->full_name, priv->stm.req_gpr, priv->stm.req_bit);
 
-	device_set_wakeup_capable(&pdev->dev, true);
-
-	if (of_property_read_bool(np, "wakeup-source"))
-		device_set_wakeup_enable(&pdev->dev, true);
-
 	return 0;
 
 out_put_node:
@@ -1895,6 +1929,58 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev)
 	return ret;
 }
 
+static int flexcan_setup_stop_mode_scfw(struct platform_device *pdev)
+{
+	struct net_device *dev = platform_get_drvdata(pdev);
+	struct flexcan_priv *priv;
+	u8 scu_idx;
+	int ret;
+
+	ret = of_property_read_u8(pdev->dev.of_node, "fsl,scu-index", &scu_idx);
+	if (ret < 0) {
+		dev_dbg(&pdev->dev, "failed to get scu index\n");
+		return ret;
+	}
+
+	priv = netdev_priv(dev);
+	priv->scu_idx = scu_idx;
+
+	/* this function could be defered probe, return -EPROBE_DEFER */
+	return imx_scu_get_handle(&priv->sc_ipc_handle);
+}
+
+/* flexcan_setup_stop_mode - Setup stop mode for wakeup
+ *
+ * Return: = 0 setup stop mode successfully or doesn't support this feature
+ *         < 0 fail to setup stop mode (could be defered probe)
+ */
+static int flexcan_setup_stop_mode(struct platform_device *pdev)
+{
+	struct net_device *dev = platform_get_drvdata(pdev);
+	struct flexcan_priv *priv;
+	int ret;
+
+	priv = netdev_priv(dev);
+
+	if (priv->devtype_data->quirks & FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW)
+		ret = flexcan_setup_stop_mode_scfw(pdev);
+	else if (priv->devtype_data->quirks & FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR)
+		ret = flexcan_setup_stop_mode_gpr(pdev);
+	else
+		/* return 0 directly if doesn't support stop mode feature */
+		return 0;
+
+	if (ret)
+		return ret;
+
+	device_set_wakeup_capable(&pdev->dev, true);
+
+	if (of_property_read_bool(pdev->dev.of_node, "wakeup-source"))
+		device_set_wakeup_enable(&pdev->dev, true);
+
+	return 0;
+}
+
 static const struct of_device_id flexcan_of_match[] = {
 	{ .compatible = "fsl,imx8qm-flexcan", .data = &fsl_imx8qm_devtype_data, },
 	{ .compatible = "fsl,imx8mp-flexcan", .data = &fsl_imx8mp_devtype_data, },
@@ -2040,17 +2126,20 @@ static int flexcan_probe(struct platform_device *pdev)
 		goto failed_register;
 	}
 
+	err = flexcan_setup_stop_mode(pdev);
+	if (err < 0) {
+		if (err != -EPROBE_DEFER)
+			dev_err(&pdev->dev, "setup stop mode failed\n");
+		goto failed_setup_stop_mode;
+	}
+
 	of_can_transceiver(dev);
 	devm_can_led_init(dev);
 
-	if (priv->devtype_data->quirks & FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR) {
-		err = flexcan_setup_stop_mode(pdev);
-		if (err)
-			dev_dbg(&pdev->dev, "failed to setup stop-mode\n");
-	}
-
 	return 0;
 
+ failed_setup_stop_mode:
+	unregister_flexcandev(dev);
  failed_register:
 	pm_runtime_put_noidle(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
-- 
2.17.1


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

* Re: [PATCH V5 0/5] can: flexcan: add stop mode support for i.MX8QM
  2020-11-06 10:56 [PATCH V5 0/5] can: flexcan: add stop mode support for i.MX8QM Joakim Zhang
                   ` (4 preceding siblings ...)
  2020-11-06 10:56 ` [PATCH V5 5/5] can: flexcan: add CAN wakeup function for i.MX8QM Joakim Zhang
@ 2020-11-06 11:32 ` Marc Kleine-Budde
  2020-12-22 11:37   ` Joakim Zhang
  5 siblings, 1 reply; 10+ messages in thread
From: Marc Kleine-Budde @ 2020-11-06 11:32 UTC (permalink / raw)
  To: Joakim Zhang, robh+dt, shawnguo, s.hauer
  Cc: kernel, linux-imx, linux-can, netdev, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 2029 bytes --]

On 11/6/20 11:56 AM, Joakim Zhang wrote:
> Add stop mode support for i.MX8QM.
> 
> ChangeLogs:
> V4->V5:
> 	* remove patch:firmware: imx: always export SCU symbols, since
> 	it done by commit: 95de5094f5ac firmware: imx: add dummy functions
> 	* rebase to fsl,flexcan.yaml
> 
> V3->V4:
> 	* can_idx->scu_idx.
> 	* return imx_scu_get_handle(&priv->sc_ipc_handle);
> 	* failed_canregister->failed_setup_stop_mode.
> 
> V2->V3:
> 	* define IMX_SC_R_CAN(x) in rsrc.h
> 	* remove error message on -EPROBE_DEFER.
> 	* split disable wakeup patch into separate one.
> 
> V1->V2:
> 	* split ECC fix patches into separate patches.
> 	* free can dev if failed to setup stop mode.
> 	* disable wakeup on flexcan_remove.
> 	* add FLEXCAN_IMX_SC_R_CAN macro helper.
> 	* fsl,can-index->fsl,scu-index.
> 	* move fsl,scu-index and priv->can_idx into
> 	* flexcan_setup_stop_mode_scfw()
> 	* prove failed if failed to setup stop mode.
> 
> Joakim Zhang (5):
>   dt-bindings: can: flexcan: fix fsl,clk-source property

added to linux-can/testing

>   dt-bindings: can: flexcan: add fsl,scu-index property to indicate a
>     resource
>   can: flexcan: rename macro FLEXCAN_QUIRK_SETUP_STOP_MODE ->
>     FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR
>   dt-bindings: firmware: add IMX_SC_R_CAN(x) macro for CAN
>   can: flexcan: add CAN wakeup function for i.MX8QM

The others go via linux-can-next/testing, once net/master is merged back to
net-next/master to have the yaml bindings.

>  .../bindings/net/can/fsl,flexcan.yaml         |  15 +-
>  drivers/net/can/flexcan.c                     | 131 +++++++++++++++---
>  include/dt-bindings/firmware/imx/rsrc.h       |   1 +
>  3 files changed, 124 insertions(+), 23 deletions(-)

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


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

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

* Re: [PATCH V5 5/5] can: flexcan: add CAN wakeup function for i.MX8QM
  2020-11-06 10:56 ` [PATCH V5 5/5] can: flexcan: add CAN wakeup function for i.MX8QM Joakim Zhang
@ 2020-11-20 12:24   ` Marc Kleine-Budde
  0 siblings, 0 replies; 10+ messages in thread
From: Marc Kleine-Budde @ 2020-11-20 12:24 UTC (permalink / raw)
  To: Joakim Zhang, robh+dt, shawnguo, s.hauer
  Cc: kernel, linux-imx, linux-can, netdev, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 939 bytes --]

On 11/6/20 11:56 AM, Joakim Zhang wrote:
> The System Controller Firmware (SCFW) is a low-level system function
> which runs on a dedicated Cortex-M core to provide power, clock, and
> resource management. It exists on some i.MX8 processors. e.g. i.MX8QM
> (QM, QP), and i.MX8QX (QXP, DX). SCU driver manages the IPC interface
> between host CPU and the SCU firmware running on M4.
> 
> For i.MX8QM, stop mode request is controlled by System Controller Unit(SCU)
> firmware, this patch introduces FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW quirk
> for this function.
> 
> Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>

Who is upstreaming this?

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


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

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

* RE: [PATCH V5 0/5] can: flexcan: add stop mode support for i.MX8QM
  2020-11-06 11:32 ` [PATCH V5 0/5] can: flexcan: add stop mode support " Marc Kleine-Budde
@ 2020-12-22 11:37   ` Joakim Zhang
  2020-12-22 12:33     ` Marc Kleine-Budde
  0 siblings, 1 reply; 10+ messages in thread
From: Joakim Zhang @ 2020-12-22 11:37 UTC (permalink / raw)
  To: Marc Kleine-Budde, robh+dt, shawnguo, s.hauer
  Cc: kernel, dl-linux-imx, linux-can, netdev, linux-kernel


> -----Original Message-----
> From: Marc Kleine-Budde <mkl@pengutronix.de>
> Sent: 2020年11月6日 19:33
> To: Joakim Zhang <qiangqing.zhang@nxp.com>; robh+dt@kernel.org;
> shawnguo@kernel.org; s.hauer@pengutronix.de
> Cc: kernel@pengutronix.de; dl-linux-imx <linux-imx@nxp.com>;
> linux-can@vger.kernel.org; netdev@vger.kernel.org;
> linux-kernel@vger.kernel.org
> Subject: Re: [PATCH V5 0/5] can: flexcan: add stop mode support for i.MX8QM
> 
> On 11/6/20 11:56 AM, Joakim Zhang wrote:
> > Add stop mode support for i.MX8QM.
> >
> > ChangeLogs:
> > V4->V5:
> > 	* remove patch:firmware: imx: always export SCU symbols, since
> > 	it done by commit: 95de5094f5ac firmware: imx: add dummy functions
> > 	* rebase to fsl,flexcan.yaml
> >
> > V3->V4:
> > 	* can_idx->scu_idx.
> > 	* return imx_scu_get_handle(&priv->sc_ipc_handle);
> > 	* failed_canregister->failed_setup_stop_mode.
> >
> > V2->V3:
> > 	* define IMX_SC_R_CAN(x) in rsrc.h
> > 	* remove error message on -EPROBE_DEFER.
> > 	* split disable wakeup patch into separate one.
> >
> > V1->V2:
> > 	* split ECC fix patches into separate patches.
> > 	* free can dev if failed to setup stop mode.
> > 	* disable wakeup on flexcan_remove.
> > 	* add FLEXCAN_IMX_SC_R_CAN macro helper.
> > 	* fsl,can-index->fsl,scu-index.
> > 	* move fsl,scu-index and priv->can_idx into
> > 	* flexcan_setup_stop_mode_scfw()
> > 	* prove failed if failed to setup stop mode.
> >
> > Joakim Zhang (5):
> >   dt-bindings: can: flexcan: fix fsl,clk-source property
> 
> added to linux-can/testing
> 
> >   dt-bindings: can: flexcan: add fsl,scu-index property to indicate a
> >     resource
> >   can: flexcan: rename macro FLEXCAN_QUIRK_SETUP_STOP_MODE ->
> >     FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR
> >   dt-bindings: firmware: add IMX_SC_R_CAN(x) macro for CAN
> >   can: flexcan: add CAN wakeup function for i.MX8QM
> 
> The others go via linux-can-next/testing, once net/master is merged back to
> net-next/master to have the yaml bindings.

Hi Marc,

How about below patches? I even can't see it in your linux-can-next/testing branch. Are these missed?
	dt-bindings: can: flexcan: add fsl,scu-index property to indicate a resource
	can: flexcan: add CAN wakeup function for i.MX8QM

Best Regards,
Joakim Zhang

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

* Re: [PATCH V5 0/5] can: flexcan: add stop mode support for i.MX8QM
  2020-12-22 11:37   ` Joakim Zhang
@ 2020-12-22 12:33     ` Marc Kleine-Budde
  0 siblings, 0 replies; 10+ messages in thread
From: Marc Kleine-Budde @ 2020-12-22 12:33 UTC (permalink / raw)
  To: Joakim Zhang, robh+dt, shawnguo, s.hauer
  Cc: kernel, dl-linux-imx, linux-can, netdev, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 722 bytes --]

On 12/22/20 12:37 PM, Joakim Zhang wrote:
> How about below patches? I even can't see it in your linux-can-next/testing branch. Are these missed?
> 	dt-bindings: can: flexcan: add fsl,scu-index property to indicate a resource
> 	can: flexcan: add CAN wakeup function for i.MX8QM

The patch "firmware: imx: always export SCU symbols" is not yet in
net-next/master, so the flexcan patch will not compile where the SCU is switched
off.

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


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

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

end of thread, other threads:[~2020-12-22 12:33 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-06 10:56 [PATCH V5 0/5] can: flexcan: add stop mode support for i.MX8QM Joakim Zhang
2020-11-06 10:56 ` [PATCH V5 1/5] dt-bindings: can: flexcan: fix fsl,clk-source property Joakim Zhang
2020-11-06 10:56 ` [PATCH V5 2/5] dt-bindings: can: flexcan: add fsl,scu-index property to indicate a resource Joakim Zhang
2020-11-06 10:56 ` [PATCH V5 3/5] can: flexcan: rename macro FLEXCAN_QUIRK_SETUP_STOP_MODE -> FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR Joakim Zhang
2020-11-06 10:56 ` [PATCH V5 4/5] dt-bindings: firmware: add IMX_SC_R_CAN(x) macro for CAN Joakim Zhang
2020-11-06 10:56 ` [PATCH V5 5/5] can: flexcan: add CAN wakeup function for i.MX8QM Joakim Zhang
2020-11-20 12:24   ` Marc Kleine-Budde
2020-11-06 11:32 ` [PATCH V5 0/5] can: flexcan: add stop mode support " Marc Kleine-Budde
2020-12-22 11:37   ` Joakim Zhang
2020-12-22 12:33     ` Marc Kleine-Budde

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