Skip to contentSkip to conversation

Add support of CEC wakeup on Amlogic G12 and SM1 SoCs

PATCH In review Guillaume La Roque 4 participants 10 messages Dec 13, 2019 – Jan 13, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover Add support of CEC wakeup on Amlogic G12 and SM1 SoCs

this patchset add support of CEC wakeup.
We need to set logical address and activate some options in registers before going in suspend. Registers address and options values come from amlogic driver.

Changes since v1:
- fix bad mask variable use to set logical address.
- use FIELD_PREP instead of shift value.

Guillaume La Roque (3):
media: dt-bindings: media: meson-ao-cec: Add support of ao-sysctrl
syscon
arm64: dts: meson-g12g12: add syscon phandle in cec node
media: platform: meson-ao-cec-g12a: add wakeup support

 .../media/amlogic,meson-gx-ao-cec.yaml        |  4 +++
 .../boot/dts/amlogic/meson-g12-common.dtsi    |  1 +
 drivers/media/platform/meson/ao-cec-g12a.c    | 33 +++++++++++++++++++
 3 files changed, 38 insertions(+)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/3 media: dt-bindings: media: meson-ao-cec: Add support of ao-sysctrl syscon

ao-sysctrl syscon phandle property is needed for CEC wakeup support. This property is optional.

---
 .../devicetree/bindings/media/amlogic,meson-gx-ao-cec.yaml    | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/media/amlogic,meson-gx-ao-cec.yaml +4 -0
index 41197578f19a..1f721498d249 100644
@@ -32,6 +32,10 @@ properties:
     allOf:
       - $ref: /schemas/types.yaml#/definitions/phandle
 
+  amlogic,ao-sysctrl:
+    description: phandle to the ao-sysctrl syscon
+    $ref: '/schemas/types.yaml#/definitions/phandle'
+
 allOf:
   - if:
       properties:
Signature · 1 line
2.17.1
maintainer Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] media: dt-bindings: media: meson-ao-cec: Add support of ao-sysctrl syscon

Quoted 9 lines · Guillaume La Roque

ao-sysctrl syscon phandle property is needed for CEC wakeup support. This property is optional.

---
 .../devicetree/bindings/media/amlogic,meson-gx-ao-cec.yaml    | 4 ++++
 1 file changed, 4 insertions(+)
#3 lore raw

PATCH v2 2/3 arm64: dts: meson-g12g12: add syscon phandle in cec node

In reply to Guillaume La Roque

add syscon phandle in cec node to activate wakeup support

---
 arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi +1 -0
index 7fabc8d9654a..98c6a1d1d035 100644
@@ -1899,6 +1899,7 @@
 				interrupts = <GIC_SPI 203 IRQ_TYPE_EDGE_RISING>;
 				clocks = <&clkc_AO CLKID_AO_CTS_OSCIN>;
 				clock-names = "oscin";
+				amlogic,ao-sysctrl = <&rti>;
 				status = "disabled";
 			};
 
Signature · 1 line
2.17.1
#4 lore raw

PATCH v2 3/3 media: platform: meson-ao-cec-g12a: add wakeup support

In reply to Guillaume La Roque

add register configuration to activate wakeup feature in bl301

---
 drivers/media/platform/meson/ao-cec-g12a.c | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/media/platform/meson/ao-cec-g12a.c +33 -0
index 891533060d49..85850b974126 100644
@@ -25,6 +25,7 @@
 #include <media/cec.h>
 #include <media/cec-notifier.h>
 #include <linux/clk-provider.h>
+#include <linux/mfd/syscon.h>
 
 /* CEC Registers */
 
@@ -168,6 +169,18 @@
 
 #define CECB_WAKEUPCTRL		0x31
 
+#define CECB_FUNC_CFG_REG		0xA0
+#define CECB_FUNC_CFG_MASK		GENMASK(6, 0)
+#define CECB_FUNC_CFG_CEC_ON		0x01
+#define CECB_FUNC_CFG_OTP_ON		0x02
+#define CECB_FUNC_CFG_AUTO_STANDBY	0x04
+#define CECB_FUNC_CFG_AUTO_POWER_ON	0x08
+#define CECB_FUNC_CFG_ALL		0x2f
+#define CECB_FUNC_CFG_NONE		0x0
+
+#define CECB_LOG_ADDR_REG	0xA4
+#define CECB_LOG_ADDR_MASK	GENMASK(22, 16)
+
 struct meson_ao_cec_g12a_data {
 	/* Setup the internal CECB_CTRL2 register */
 	bool				ctrl2_setup;
@@ -177,6 +190,7 @@ struct meson_ao_cec_g12a_device {
 	struct platform_device		*pdev;
 	struct regmap			*regmap;
 	struct regmap			*regmap_cec;
+	struct regmap			*regmap_ao_sysctrl;
 	spinlock_t			cec_reg_lock;
 	struct cec_notifier		*notify;
 	struct cec_adapter		*adap;
@@ -518,6 +532,13 @@ meson_ao_cec_g12a_set_log_addr(struct cec_adapter *adap, u8 logical_addr)
 					 BIT(logical_addr - 8));
 	}
 
+	if (ao_cec->regmap_ao_sysctrl)
+		ret |= regmap_update_bits(ao_cec->regmap_ao_sysctrl,
+					 CECB_LOG_ADDR_REG,
+					 CECB_LOG_ADDR_MASK,
+					 FIELD_PREP(CECB_LOG_ADDR_MASK,
+						    logical_addr));
+
 	/* Always set Broadcast/Unregistered 15 address */
 	ret |= regmap_update_bits(ao_cec->regmap_cec, CECB_LADD_HIGH,
 				  BIT(CEC_LOG_ADDR_UNREGISTERED - 8),
@@ -618,6 +639,13 @@ static int meson_ao_cec_g12a_adap_enable(struct cec_adapter *adap, bool enable)
 		regmap_write(ao_cec->regmap_cec, CECB_CTRL2,
 			     FIELD_PREP(CECB_CTRL2_RISE_DEL_MAX, 2));
 
+	if (ao_cec->regmap_ao_sysctrl) {
+		regmap_update_bits(ao_cec->regmap_ao_sysctrl,
+				   CECB_FUNC_CFG_REG,
+				   CECB_FUNC_CFG_MASK,
+				   CECB_FUNC_CFG_ALL);
+	}
+
 	meson_ao_cec_g12a_irq_setup(ao_cec, true);
 
 	return 0;
@@ -685,6 +713,11 @@ static int meson_ao_cec_g12a_probe(struct platform_device *pdev)
 		goto out_probe_adapter;
 	}
 
+	ao_cec->regmap_ao_sysctrl = syscon_regmap_lookup_by_phandle
+		(pdev->dev.of_node, "amlogic,ao-sysctrl");
+	if (IS_ERR(ao_cec->regmap_ao_sysctrl))
+		dev_warn(&pdev->dev, "ao-sysctrl syscon regmap lookup failed.\n");
+
 	irq = platform_get_irq(pdev, 0);
 	ret = devm_request_threaded_irq(&pdev->dev, irq,
 					meson_ao_cec_g12a_irq,
Signature · 1 line
2.17.1
Reviewed-by on v2 3/3
#5 lore raw

Re: [PATCH v2 3/3] media: platform: meson-ao-cec-g12a: add wakeup support

Quoted 78 lines · Guillaume La Roque

add register configuration to activate wakeup feature in bl301

---
 drivers/media/platform/meson/ao-cec-g12a.c | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/media/platform/meson/ao-cec-g12a.c +28 -0
index 891533060d49..85850b974126 100644
@@ -25,6 +25,7 @@
 #include <media/cec.h>
 #include <media/cec-notifier.h>
 #include <linux/clk-provider.h>
+#include <linux/mfd/syscon.h>
 
 /* CEC Registers */
 
@@ -168,6 +169,18 @@
 
 #define CECB_WAKEUPCTRL		0x31
 
+#define CECB_FUNC_CFG_REG		0xA0
+#define CECB_FUNC_CFG_MASK		GENMASK(6, 0)
+#define CECB_FUNC_CFG_CEC_ON		0x01
+#define CECB_FUNC_CFG_OTP_ON		0x02
+#define CECB_FUNC_CFG_AUTO_STANDBY	0x04
+#define CECB_FUNC_CFG_AUTO_POWER_ON	0x08
+#define CECB_FUNC_CFG_ALL		0x2f
+#define CECB_FUNC_CFG_NONE		0x0
+
+#define CECB_LOG_ADDR_REG	0xA4
+#define CECB_LOG_ADDR_MASK	GENMASK(22, 16)
+
 struct meson_ao_cec_g12a_data {
 	/* Setup the internal CECB_CTRL2 register */
 	bool				ctrl2_setup;
@@ -177,6 +190,7 @@ struct meson_ao_cec_g12a_device {
 	struct platform_device		*pdev;
 	struct regmap			*regmap;
 	struct regmap			*regmap_cec;
+	struct regmap			*regmap_ao_sysctrl;
 	spinlock_t			cec_reg_lock;
 	struct cec_notifier		*notify;
 	struct cec_adapter		*adap;
@@ -518,6 +532,13 @@ meson_ao_cec_g12a_set_log_addr(struct cec_adapter *adap, u8 logical_addr)
 					 BIT(logical_addr - 8));
 	}
 
+	if (ao_cec->regmap_ao_sysctrl)
+		ret |= regmap_update_bits(ao_cec->regmap_ao_sysctrl,
+					 CECB_LOG_ADDR_REG,
+					 CECB_LOG_ADDR_MASK,
+					 FIELD_PREP(CECB_LOG_ADDR_MASK,
+						    logical_addr));
+
 	/* Always set Broadcast/Unregistered 15 address */
 	ret |= regmap_update_bits(ao_cec->regmap_cec, CECB_LADD_HIGH,
 				  BIT(CEC_LOG_ADDR_UNREGISTERED - 8),
@@ -618,6 +639,13 @@ static int meson_ao_cec_g12a_adap_enable(struct cec_adapter *adap, bool enable)
 		regmap_write(ao_cec->regmap_cec, CECB_CTRL2,
 			     FIELD_PREP(CECB_CTRL2_RISE_DEL_MAX, 2));
 
+	if (ao_cec->regmap_ao_sysctrl) {
+		regmap_update_bits(ao_cec->regmap_ao_sysctrl,
+				   CECB_FUNC_CFG_REG,
+				   CECB_FUNC_CFG_MASK,
+				   CECB_FUNC_CFG_ALL);
+	}
+
 	meson_ao_cec_g12a_irq_setup(ao_cec, true);
 
 	return 0;
@@ -685,6 +713,11 @@ static int meson_ao_cec_g12a_probe(struct platform_device *pdev)
 		goto out_probe_adapter;

drivers/media/platform/meson/ao-cec-g12a.c static int meson_ao_cec_g12a_probe(struct platform_device *pdev) · line 723

Quoted 10 lines
drivers/media/platform/meson/ao-cec-g12a.c +5 -0
 	}
 
+	ao_cec->regmap_ao_sysctrl = syscon_regmap_lookup_by_phandle
+		(pdev->dev.of_node, "amlogic,ao-sysctrl");
+	if (IS_ERR(ao_cec->regmap_ao_sysctrl))
+		dev_warn(&pdev->dev, "ao-sysctrl syscon regmap lookup failed.\n");
+
 	irq = platform_get_irq(pdev, 0);
 	ret = devm_request_threaded_irq(&pdev->dev, irq,
 					meson_ao_cec_g12a_irq,
#6 lore raw

Re: [PATCH v2 3/3] media: platform: meson-ao-cec-g12a: add wakeup support

In reply to Guillaume La Roque

Hi Guillaume,

Quoted 62 lines · Guillaume La Roque

add register configuration to activate wakeup feature in bl301

---
 drivers/media/platform/meson/ao-cec-g12a.c | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/media/platform/meson/ao-cec-g12a.c +21 -0
index 891533060d49..85850b974126 100644
@@ -25,6 +25,7 @@
 #include <media/cec.h>
 #include <media/cec-notifier.h>
 #include <linux/clk-provider.h>
+#include <linux/mfd/syscon.h>
 
 /* CEC Registers */
 
@@ -168,6 +169,18 @@
 
 #define CECB_WAKEUPCTRL		0x31
 
+#define CECB_FUNC_CFG_REG		0xA0
+#define CECB_FUNC_CFG_MASK		GENMASK(6, 0)
+#define CECB_FUNC_CFG_CEC_ON		0x01
+#define CECB_FUNC_CFG_OTP_ON		0x02
+#define CECB_FUNC_CFG_AUTO_STANDBY	0x04
+#define CECB_FUNC_CFG_AUTO_POWER_ON	0x08
+#define CECB_FUNC_CFG_ALL		0x2f
+#define CECB_FUNC_CFG_NONE		0x0
+
+#define CECB_LOG_ADDR_REG	0xA4
+#define CECB_LOG_ADDR_MASK	GENMASK(22, 16)
+
 struct meson_ao_cec_g12a_data {
 	/* Setup the internal CECB_CTRL2 register */
 	bool				ctrl2_setup;
@@ -177,6 +190,7 @@ struct meson_ao_cec_g12a_device {
 	struct platform_device		*pdev;
 	struct regmap			*regmap;
 	struct regmap			*regmap_cec;
+	struct regmap			*regmap_ao_sysctrl;
 	spinlock_t			cec_reg_lock;
 	struct cec_notifier		*notify;
 	struct cec_adapter		*adap;
@@ -518,6 +532,13 @@ meson_ao_cec_g12a_set_log_addr(struct cec_adapter *adap, u8 logical_addr)
 					 BIT(logical_addr - 8));
 	}
 
+	if (ao_cec->regmap_ao_sysctrl)
+		ret |= regmap_update_bits(ao_cec->regmap_ao_sysctrl,
+					 CECB_LOG_ADDR_REG,
+					 CECB_LOG_ADDR_MASK,
+					 FIELD_PREP(CECB_LOG_ADDR_MASK,
+						    logical_addr));
+
 	/* Always set Broadcast/Unregistered 15 address */
 	ret |= regmap_update_bits(ao_cec->regmap_cec, CECB_LADD_HIGH,
 				  BIT(CEC_LOG_ADDR_UNREGISTERED - 8),

drivers/media/platform/meson/ao-cec-g12a.c static int meson_ao_cec_g12a_adap_enable(struct cec_adapter *adap, bool enable) · line 646

Quoted 8 lines
drivers/media/platform/meson/ao-cec-g12a.c +5 -0
@@ -618,6 +639,13 @@ static int meson_ao_cec_g12a_adap_enable(struct cec_adapter *adap, bool enable)
 		regmap_write(ao_cec->regmap_cec, CECB_CTRL2,
 			     FIELD_PREP(CECB_CTRL2_RISE_DEL_MAX, 2));
 
+	if (ao_cec->regmap_ao_sysctrl) {
+		regmap_update_bits(ao_cec->regmap_ao_sysctrl,
+				   CECB_FUNC_CFG_REG,
+				   CECB_FUNC_CFG_MASK,
+				   CECB_FUNC_CFG_ALL);

What exactly is enabled here? Looking at CECB_FUNC_CFG_ALL it seems to enable automatic standby (I presume when the STANDBY message is received?) and power on (I presume when SET_STREAM_PATH is received?).

Do you really want to automatically handle STANDBY that way? What does this do on the hardware level anyway? Isn't this something that should be controlled in userspace?

Similar questions for power on: you may not always want to enable this feature since it depends very much on the precise use-case.

And which messages it reacts to in order to do a power-on needs to be documented since this differs depending on whether the CEC adapter is used for a TV or for a playback device. This feature may be hardwired for a playback device only, in which case it should probably be disabled if the CEC adapter is configured as a TV.

In any case I would like to see some more details about how this works, especially since this is the first implementation of such a feature.

I suspect that some userspace API might be needed to get the right level of control of such a feature.

Regards,

Hans

Quoted 18 lines
drivers/media/platform/meson/ao-cec-g12a.c +7 -0
+	}
+
 	meson_ao_cec_g12a_irq_setup(ao_cec, true);
 
 	return 0;
@@ -685,6 +713,11 @@ static int meson_ao_cec_g12a_probe(struct platform_device *pdev)
 		goto out_probe_adapter;
 	}
 
+	ao_cec->regmap_ao_sysctrl = syscon_regmap_lookup_by_phandle
+		(pdev->dev.of_node, "amlogic,ao-sysctrl");
+	if (IS_ERR(ao_cec->regmap_ao_sysctrl))
+		dev_warn(&pdev->dev, "ao-sysctrl syscon regmap lookup failed.\n");
+
 	irq = platform_get_irq(pdev, 0);
 	ret = devm_request_threaded_irq(&pdev->dev, irq,
 					meson_ao_cec_g12a_irq,
#7 lore raw

Re: [PATCH v2 3/3] media: platform: meson-ao-cec-g12a: add wakeup support

Hi Hans,

Quoted 68 lines · Hans Verkuil

Hi Guillaume,

Quoted 65 lines · Guillaume La Roque

add register configuration to activate wakeup feature in bl301

---
 drivers/media/platform/meson/ao-cec-g12a.c | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/media/platform/meson/ao-cec-g12a.c +21 -0
index 891533060d49..85850b974126 100644
@@ -25,6 +25,7 @@
 #include <media/cec.h>
 #include <media/cec-notifier.h>
 #include <linux/clk-provider.h>
+#include <linux/mfd/syscon.h>
 
 /* CEC Registers */
 
@@ -168,6 +169,18 @@
 
 #define CECB_WAKEUPCTRL		0x31
 
+#define CECB_FUNC_CFG_REG		0xA0
+#define CECB_FUNC_CFG_MASK		GENMASK(6, 0)
+#define CECB_FUNC_CFG_CEC_ON		0x01
+#define CECB_FUNC_CFG_OTP_ON		0x02
+#define CECB_FUNC_CFG_AUTO_STANDBY	0x04
+#define CECB_FUNC_CFG_AUTO_POWER_ON	0x08
+#define CECB_FUNC_CFG_ALL		0x2f
+#define CECB_FUNC_CFG_NONE		0x0
+
+#define CECB_LOG_ADDR_REG	0xA4
+#define CECB_LOG_ADDR_MASK	GENMASK(22, 16)
+
 struct meson_ao_cec_g12a_data {
 	/* Setup the internal CECB_CTRL2 register */
 	bool				ctrl2_setup;
@@ -177,6 +190,7 @@ struct meson_ao_cec_g12a_device {
 	struct platform_device		*pdev;
 	struct regmap			*regmap;
 	struct regmap			*regmap_cec;
+	struct regmap			*regmap_ao_sysctrl;
 	spinlock_t			cec_reg_lock;
 	struct cec_notifier		*notify;
 	struct cec_adapter		*adap;
@@ -518,6 +532,13 @@ meson_ao_cec_g12a_set_log_addr(struct cec_adapter *adap, u8 logical_addr)
 					 BIT(logical_addr - 8));
 	}
 
+	if (ao_cec->regmap_ao_sysctrl)
+		ret |= regmap_update_bits(ao_cec->regmap_ao_sysctrl,
+					 CECB_LOG_ADDR_REG,
+					 CECB_LOG_ADDR_MASK,
+					 FIELD_PREP(CECB_LOG_ADDR_MASK,
+						    logical_addr));
+
 	/* Always set Broadcast/Unregistered 15 address */
 	ret |= regmap_update_bits(ao_cec->regmap_cec, CECB_LADD_HIGH,
 				  BIT(CEC_LOG_ADDR_UNREGISTERED - 8),
@@ -618,6 +639,13 @@ static int meson_ao_cec_g12a_adap_enable(struct cec_adapter *adap, bool enable)
 		regmap_write(ao_cec->regmap_cec, CECB_CTRL2,
 			     FIELD_PREP(CECB_CTRL2_RISE_DEL_MAX, 2));
 
Quoted 8 lines

drivers/media/platform/meson/ao-cec-g12a.c static int meson_ao_cec_g12a_adap_enable(struct cec_adapter *adap, bool enable) · line 646

Quoted 5 lines
drivers/media/platform/meson/ao-cec-g12a.c +5 -0
+	if (ao_cec->regmap_ao_sysctrl) {
+		regmap_update_bits(ao_cec->regmap_ao_sysctrl,
+				   CECB_FUNC_CFG_REG,
+				   CECB_FUNC_CFG_MASK,
+				   CECB_FUNC_CFG_ALL);

What exactly is enabled here? Looking at CECB_FUNC_CFG_ALL it seems to enable automatic standby (I presume when the STANDBY message is received?) and power on (I presume when SET_STREAM_PATH is received?).

this register and flags are used by bl301 part.

amlogic implemented a task to check cec event/message.

for power on in bl301 it's not only on SET_STREAM_PATH but also on :

USER_CONTROL_PRESSED
TEXT_VIEW_ON
ACTIVE_SOURCE
ROUTING_CHANGE

when in CECB_FUNC_CFG_REG register we put  CECB_FUNC_CFG_CEC_ON and  CECB_FUNC_CFG_AUTO_POWER_ON

it's not possible to change this

Quoted 4 lines

Do you really want to automatically handle STANDBY that way? What does this do on the hardware level anyway? Isn't this something that should be controlled in userspace?

in fact i do a new check in bl301 code amlogic do nothing on STANDBY so i will clean code

and activate real option supported by bl301

Quoted 10 lines

Similar questions for power on: you may not always want to enable this feature since it depends very much on the precise use-case.

And which messages it reacts to in order to do a power-on needs to be documented since this differs depending on whether the CEC adapter is used for a TV or for a playback device. This feature may be hardwired for a playback device only, in which case it should probably be disabled if the CEC adapter is configured as a TV.

Quoted 5 lines

In any case I would like to see some more details about how this works, especially since this is the first implementation of such a feature.

I suspect that some userspace API might be needed to get the right level of control of such a feature.

i will send v3 next week with some comments and fix ( disable are missing for example)

actual usercase is for android TV.

when cec was enable android TV want to be wakeup by cec event.

Quoted 4 lines

Regards,

Hans

thanks for your review

Regards

Guillaume

Quoted 18 lines
Quoted 18 lines
drivers/media/platform/meson/ao-cec-g12a.c +7 -0
+	}
+
 	meson_ao_cec_g12a_irq_setup(ao_cec, true);
 
 	return 0;
@@ -685,6 +713,11 @@ static int meson_ao_cec_g12a_probe(struct platform_device *pdev)
 		goto out_probe_adapter;
 	}
 
+	ao_cec->regmap_ao_sysctrl = syscon_regmap_lookup_by_phandle
+		(pdev->dev.of_node, "amlogic,ao-sysctrl");
+	if (IS_ERR(ao_cec->regmap_ao_sysctrl))
+		dev_warn(&pdev->dev, "ao-sysctrl syscon regmap lookup failed.\n");
+
 	irq = platform_get_irq(pdev, 0);
 	ret = devm_request_threaded_irq(&pdev->dev, irq,
 					meson_ao_cec_g12a_irq,
#8 lore raw

Re: [PATCH v2 3/3] media: platform: meson-ao-cec-g12a: add wakeup support

Quoted 79 lines · guillaume La Roque

Hi Hans,

Quoted 68 lines · Hans Verkuil

Hi Guillaume,

Quoted 65 lines · Guillaume La Roque

add register configuration to activate wakeup feature in bl301

---
 drivers/media/platform/meson/ao-cec-g12a.c | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/media/platform/meson/ao-cec-g12a.c +21 -0
index 891533060d49..85850b974126 100644
@@ -25,6 +25,7 @@
 #include <media/cec.h>
 #include <media/cec-notifier.h>
 #include <linux/clk-provider.h>
+#include <linux/mfd/syscon.h>
 
 /* CEC Registers */
 
@@ -168,6 +169,18 @@
 
 #define CECB_WAKEUPCTRL		0x31
 
+#define CECB_FUNC_CFG_REG		0xA0
+#define CECB_FUNC_CFG_MASK		GENMASK(6, 0)
+#define CECB_FUNC_CFG_CEC_ON		0x01
+#define CECB_FUNC_CFG_OTP_ON		0x02
+#define CECB_FUNC_CFG_AUTO_STANDBY	0x04
+#define CECB_FUNC_CFG_AUTO_POWER_ON	0x08
+#define CECB_FUNC_CFG_ALL		0x2f
+#define CECB_FUNC_CFG_NONE		0x0
+
+#define CECB_LOG_ADDR_REG	0xA4
+#define CECB_LOG_ADDR_MASK	GENMASK(22, 16)
+
 struct meson_ao_cec_g12a_data {
 	/* Setup the internal CECB_CTRL2 register */
 	bool				ctrl2_setup;
@@ -177,6 +190,7 @@ struct meson_ao_cec_g12a_device {
 	struct platform_device		*pdev;
 	struct regmap			*regmap;
 	struct regmap			*regmap_cec;
+	struct regmap			*regmap_ao_sysctrl;
 	spinlock_t			cec_reg_lock;
 	struct cec_notifier		*notify;
 	struct cec_adapter		*adap;
@@ -518,6 +532,13 @@ meson_ao_cec_g12a_set_log_addr(struct cec_adapter *adap, u8 logical_addr)
 					 BIT(logical_addr - 8));
 	}
 
+	if (ao_cec->regmap_ao_sysctrl)
+		ret |= regmap_update_bits(ao_cec->regmap_ao_sysctrl,
+					 CECB_LOG_ADDR_REG,
+					 CECB_LOG_ADDR_MASK,
+					 FIELD_PREP(CECB_LOG_ADDR_MASK,
+						    logical_addr));
+
 	/* Always set Broadcast/Unregistered 15 address */
 	ret |= regmap_update_bits(ao_cec->regmap_cec, CECB_LADD_HIGH,
 				  BIT(CEC_LOG_ADDR_UNREGISTERED - 8),
@@ -618,6 +639,13 @@ static int meson_ao_cec_g12a_adap_enable(struct cec_adapter *adap, bool enable)
 		regmap_write(ao_cec->regmap_cec, CECB_CTRL2,
 			     FIELD_PREP(CECB_CTRL2_RISE_DEL_MAX, 2));
 
Quoted 8 lines

drivers/media/platform/meson/ao-cec-g12a.c static int meson_ao_cec_g12a_adap_enable(struct cec_adapter *adap, bool enable) · line 646

Quoted 5 lines
drivers/media/platform/meson/ao-cec-g12a.c +5 -0
+	if (ao_cec->regmap_ao_sysctrl) {
+		regmap_update_bits(ao_cec->regmap_ao_sysctrl,
+				   CECB_FUNC_CFG_REG,
+				   CECB_FUNC_CFG_MASK,
+				   CECB_FUNC_CFG_ALL);

What exactly is enabled here? Looking at CECB_FUNC_CFG_ALL it seems to enable automatic standby (I presume when the STANDBY message is received?) and power on (I presume when SET_STREAM_PATH is received?).

Quoted 8 lines

this register and flags are used by bl301 part.

amlogic implemented a task to check cec event/message.

for power on in bl301 it's not only on SET_STREAM_PATH but also on :

USER_CONTROL_PRESSED
TEXT_VIEW_ON

Not IMAGE_VIEW_ON?

Quoted 6 lines

ACTIVE_SOURCE
ROUTING_CHANGE

when in CECB_FUNC_CFG_REG register we put  CECB_FUNC_CFG_CEC_ON and  CECB_FUNC_CFG_AUTO_POWER_ON

it's not possible to change this

Too bad since ACTIVE_SOURCE and ROUTING_CHANGE should not power on a CEC device.

See section 11.5.2 in the HDMI 2.0 Specification for more details, if you have that spec.

Quoted 33 lines
Quoted 5 lines

Do you really want to automatically handle STANDBY that way? What does this do on the hardware level anyway? Isn't this something that should be controlled in userspace?

in fact i do a new check in bl301 code amlogic do nothing on STANDBY so i will clean code

and activate real option supported by bl301

Quoted 10 lines

Similar questions for power on: you may not always want to enable this feature since it depends very much on the precise use-case.

And which messages it reacts to in order to do a power-on needs to be documented since this differs depending on whether the CEC adapter is used for a TV or for a playback device. This feature may be hardwired for a playback device only, in which case it should probably be disabled if the CEC adapter is configured as a TV.

Quoted 5 lines

In any case I would like to see some more details about how this works, especially since this is the first implementation of such a feature.

I suspect that some userspace API might be needed to get the right level of control of such a feature.

i will send v3 next week with some comments and fix ( disable are missing for example)

actual usercase is for android TV.

when cec was enable android TV want to be wakeup by cec event.

Quoted 6 lines
Quoted 4 lines

Regards,

Hans

thanks for your review

No problem!

Hans

Quoted 23 lines

Regards

Guillaume

Quoted 18 lines
Quoted 18 lines
drivers/media/platform/meson/ao-cec-g12a.c +7 -0
+	}
+
 	meson_ao_cec_g12a_irq_setup(ao_cec, true);
 
 	return 0;
@@ -685,6 +713,11 @@ static int meson_ao_cec_g12a_probe(struct platform_device *pdev)
 		goto out_probe_adapter;
 	}
 
+	ao_cec->regmap_ao_sysctrl = syscon_regmap_lookup_by_phandle
+		(pdev->dev.of_node, "amlogic,ao-sysctrl");
+	if (IS_ERR(ao_cec->regmap_ao_sysctrl))
+		dev_warn(&pdev->dev, "ao-sysctrl syscon regmap lookup failed.\n");
+
 	irq = platform_get_irq(pdev, 0);
 	ret = devm_request_threaded_irq(&pdev->dev, irq,
 					meson_ao_cec_g12a_irq,
#9 lore raw

Re: [PATCH v2 3/3] media: platform: meson-ao-cec-g12a: add wakeup support

Quoted 82 lines · Hans Verkuil
Quoted 81 lines · guillaume La Roque

Hi Hans,

Quoted 68 lines · Hans Verkuil

Hi Guillaume,

Quoted 65 lines · Guillaume La Roque

add register configuration to activate wakeup feature in bl301

---
 drivers/media/platform/meson/ao-cec-g12a.c | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/media/platform/meson/ao-cec-g12a.c +21 -0
index 891533060d49..85850b974126 100644
@@ -25,6 +25,7 @@
 #include <media/cec.h>
 #include <media/cec-notifier.h>
 #include <linux/clk-provider.h>
+#include <linux/mfd/syscon.h>
 
 /* CEC Registers */
 
@@ -168,6 +169,18 @@
 
 #define CECB_WAKEUPCTRL		0x31
 
+#define CECB_FUNC_CFG_REG		0xA0
+#define CECB_FUNC_CFG_MASK		GENMASK(6, 0)
+#define CECB_FUNC_CFG_CEC_ON		0x01
+#define CECB_FUNC_CFG_OTP_ON		0x02
+#define CECB_FUNC_CFG_AUTO_STANDBY	0x04
+#define CECB_FUNC_CFG_AUTO_POWER_ON	0x08
+#define CECB_FUNC_CFG_ALL		0x2f
+#define CECB_FUNC_CFG_NONE		0x0
+
+#define CECB_LOG_ADDR_REG	0xA4
+#define CECB_LOG_ADDR_MASK	GENMASK(22, 16)
+
 struct meson_ao_cec_g12a_data {
 	/* Setup the internal CECB_CTRL2 register */
 	bool				ctrl2_setup;
@@ -177,6 +190,7 @@ struct meson_ao_cec_g12a_device {
 	struct platform_device		*pdev;
 	struct regmap			*regmap;
 	struct regmap			*regmap_cec;
+	struct regmap			*regmap_ao_sysctrl;
 	spinlock_t			cec_reg_lock;
 	struct cec_notifier		*notify;
 	struct cec_adapter		*adap;
@@ -518,6 +532,13 @@ meson_ao_cec_g12a_set_log_addr(struct cec_adapter *adap, u8 logical_addr)
 					 BIT(logical_addr - 8));
 	}
 
+	if (ao_cec->regmap_ao_sysctrl)
+		ret |= regmap_update_bits(ao_cec->regmap_ao_sysctrl,
+					 CECB_LOG_ADDR_REG,
+					 CECB_LOG_ADDR_MASK,
+					 FIELD_PREP(CECB_LOG_ADDR_MASK,
+						    logical_addr));
+
 	/* Always set Broadcast/Unregistered 15 address */
 	ret |= regmap_update_bits(ao_cec->regmap_cec, CECB_LADD_HIGH,
 				  BIT(CEC_LOG_ADDR_UNREGISTERED - 8),
@@ -618,6 +639,13 @@ static int meson_ao_cec_g12a_adap_enable(struct cec_adapter *adap, bool enable)
 		regmap_write(ao_cec->regmap_cec, CECB_CTRL2,
 			     FIELD_PREP(CECB_CTRL2_RISE_DEL_MAX, 2));
 
Quoted 8 lines

drivers/media/platform/meson/ao-cec-g12a.c static int meson_ao_cec_g12a_adap_enable(struct cec_adapter *adap, bool enable) · line 646

Quoted 5 lines
drivers/media/platform/meson/ao-cec-g12a.c +5 -0
+	if (ao_cec->regmap_ao_sysctrl) {
+		regmap_update_bits(ao_cec->regmap_ao_sysctrl,
+				   CECB_FUNC_CFG_REG,
+				   CECB_FUNC_CFG_MASK,
+				   CECB_FUNC_CFG_ALL);

What exactly is enabled here? Looking at CECB_FUNC_CFG_ALL it seems to enable automatic standby (I presume when the STANDBY message is received?) and power on (I presume when SET_STREAM_PATH is received?).

this register and flags are used by bl301 part.

Quoted 7 lines
Quoted 6 lines

amlogic implemented a task to check cec event/message.

for power on in bl301 it's not only on SET_STREAM_PATH but also on :

USER_CONTROL_PRESSED
TEXT_VIEW_ON

Not IMAGE_VIEW_ON?

sorry i forgot it , yes on IMAGE_VIEW_ON too

Quoted 11 lines
Quoted 7 lines

ACTIVE_SOURCE
ROUTING_CHANGE

when in CECB_FUNC_CFG_REG register we put  CECB_FUNC_CFG_CEC_ON and  CECB_FUNC_CFG_AUTO_POWER_ON

it's not possible to change this

Too bad since ACTIVE_SOURCE and ROUTING_CHANGE should not power on a CEC device.

See section 11.5.2 in the HDMI 2.0 Specification for more details, if you have that spec.

i will return your comment to amlogic but not sure they do change in bl301.

Quoted 51 lines
Quoted 26 lines
Quoted 4 lines

Do you really want to automatically handle STANDBY that way? What does this do on the hardware level anyway? Isn't this something that should be controlled in userspace?

in fact i do a new check in bl301 code amlogic do nothing on STANDBY so i will clean code

and activate real option supported by bl301

Quoted 9 lines

Similar questions for power on: you may not always want to enable this feature since it depends very much on the precise use-case.

And which messages it reacts to in order to do a power-on needs to be documented since this differs depending on whether the CEC adapter is used for a TV or for a playback device. This feature may be hardwired for a playback device only, in which case it should probably be disabled if the CEC adapter is configured as a TV.

Quoted 5 lines

In any case I would like to see some more details about how this works, especially since this is the first implementation of such a feature.

I suspect that some userspace API might be needed to get the right level of control of such a feature.

i will send v3 next week with some comments and fix ( disable are missing for example)

actual usercase is for android TV.

Quoted 8 lines

when cec was enable android TV want to be wakeup by cec event.

Quoted 4 lines

Regards,

Hans

thanks for your review

No problem!

Hans

Quoted 13 lines

Regards

Guillaume

Quoted 9 lines
Quoted 9 lines
drivers/media/platform/meson/ao-cec-g12a.c +2 -0
+	}
+
 	meson_ao_cec_g12a_irq_setup(ao_cec, true);
 
 	return 0;
@@ -685,6 +713,11 @@ static int meson_ao_cec_g12a_probe(struct platform_device *pdev)
 		goto out_probe_adapter;
 	}
 
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/media/platform/meson/ao-cec-g12a.c static int meson_ao_cec_g12a_probe(struct platform_device *pdev) · line 723

Quoted 9 lines
drivers/media/platform/meson/ao-cec-g12a.c +5 -0
+	ao_cec->regmap_ao_sysctrl = syscon_regmap_lookup_by_phandle
+		(pdev->dev.of_node, "amlogic,ao-sysctrl");
+	if (IS_ERR(ao_cec->regmap_ao_sysctrl))
+		dev_warn(&pdev->dev, "ao-sysctrl syscon regmap lookup failed.\n");
+
 	irq = platform_get_irq(pdev, 0);
 	ret = devm_request_threaded_irq(&pdev->dev, irq,
 					meson_ao_cec_g12a_irq,

Regards

Guillaume