Re: [PATCH v4 0/3] drm/bridge: tfp410: Add i2c support

2023-09-26 Thread Jonathan Cormier
How do I bump this patch submission?


[PATCH v4 3/3] drm/bridge: tfp410: If connected, use I2C for polled HPD status.

2023-04-04 Thread Jonathan Cormier
From: Michael Williamson 

If the I2C bus is connected on the TFP410, then use the register
status bit to determine connection state.  This is needed, in particular,
for polling the state when the Hot Plug detect is not connected to
a controlling CPU via GPIO/IRQ lane.

Signed-off-by: Michael Williamson 
Reviewed-by: Neil Armstrong 
Signed-off-by: Jonathan Cormier 
---
 drivers/gpu/drm/bridge/ti-tfp410.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/gpu/drm/bridge/ti-tfp410.c 
b/drivers/gpu/drm/bridge/ti-tfp410.c
index 41007d05d584..eeb7202452aa 100644
--- a/drivers/gpu/drm/bridge/ti-tfp410.c
+++ b/drivers/gpu/drm/bridge/ti-tfp410.c
@@ -28,6 +28,9 @@
 #define TFP410_BIT_BSEL BIT(2)
 #define TFP410_BIT_DSEL BIT(3)
 
+#define TFP410_REG_CTL_2_MODE  0x09
+#define TFP410_BIT_HTPLG BIT(1)
+
 static const struct regmap_config tfp410_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
@@ -105,6 +108,15 @@ static enum drm_connector_status
 tfp410_connector_detect(struct drm_connector *connector, bool force)
 {
struct tfp410 *dvi = drm_connector_to_tfp410(connector);
+   int ret;
+
+   if (dvi->i2c) {
+   ret = regmap_test_bits(dvi->regmap, TFP410_REG_CTL_2_MODE, 
TFP410_BIT_HTPLG);
+   if (ret < 0)
+   dev_err(dvi->dev, "%s failed to read HTPLG bit : %d\n", 
__func__, ret);
+   else
+   return ret ? connector_status_connected : 
connector_status_disconnected;
+   }
 
return drm_bridge_detect(dvi->next_bridge);
 }

-- 
2.25.1



[PATCH v4 2/3] drm/bridge: tfp410: Fix logic to configured polled HPD

2023-04-04 Thread Jonathan Cormier
From: Michael Williamson 

The logic to configure polling (vs async/irq notification) of hot-plug
events was not correct.  If the connected bridge requires polling,
then inform the upstream bridge we also require polling.

Fixes: 5cafa0f1853b ("drm/bridge: tfp410: Replace manual connector handling 
with bridge")

Signed-off-by: Michael Williamson 
Reviewed-by: Neil Armstrong 
Signed-off-by: Jonathan Cormier 
---
 drivers/gpu/drm/bridge/ti-tfp410.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/bridge/ti-tfp410.c 
b/drivers/gpu/drm/bridge/ti-tfp410.c
index bb3f8d0ff207..41007d05d584 100644
--- a/drivers/gpu/drm/bridge/ti-tfp410.c
+++ b/drivers/gpu/drm/bridge/ti-tfp410.c
@@ -155,7 +155,7 @@ static int tfp410_attach(struct drm_bridge *bridge,
return -ENODEV;
}
 
-   if (dvi->next_bridge->ops & DRM_BRIDGE_OP_DETECT)
+   if (dvi->next_bridge->ops & DRM_BRIDGE_OP_HPD)
dvi->connector.polled = DRM_CONNECTOR_POLL_HPD;
else
dvi->connector.polled = DRM_CONNECTOR_POLL_CONNECT | 
DRM_CONNECTOR_POLL_DISCONNECT;

-- 
2.25.1



[PATCH v4 1/3] drm/bridge: tfp410: Support basic I2C interface

2023-04-04 Thread Jonathan Cormier
From: Michael Williamson 

The TFP410 driver does not support I2C.  As such, the device remains in
Power Down if the I2C is enabled by the bootstrap pins.

Add basic support for the I2C interface, and provide support to take
the device out of power down when enabled.  Also read the bootstrap mode
pins via the CTL_1_MODE register when using the I2C bus.

Signed-off-by: Michael Williamson 
Reviewed-by: Neil Armstrong 
Signed-off-by: Jonathan Cormier 
---
 drivers/gpu/drm/bridge/ti-tfp410.c | 93 +++---
 1 file changed, 67 insertions(+), 26 deletions(-)

diff --git a/drivers/gpu/drm/bridge/ti-tfp410.c 
b/drivers/gpu/drm/bridge/ti-tfp410.c
index b9635abbad16..bb3f8d0ff207 100644
--- a/drivers/gpu/drm/bridge/ti-tfp410.c
+++ b/drivers/gpu/drm/bridge/ti-tfp410.c
@@ -6,6 +6,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -21,6 +22,20 @@
 
 #define HOTPLUG_DEBOUNCE_MS1100
 
+#define TFP410_REG_CTL_1_MODE  0x08
+#define TFP410_BIT_PD   BIT(0)
+#define TFP410_BIT_EDGE BIT(1)
+#define TFP410_BIT_BSEL BIT(2)
+#define TFP410_BIT_DSEL BIT(3)
+
+static const struct regmap_config tfp410_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+
+   .max_register = 0xff,
+   .cache_type = REGCACHE_NONE,
+};
+
 struct tfp410 {
struct drm_bridge   bridge;
struct drm_connectorconnector;
@@ -33,6 +48,8 @@ struct tfp410 {
struct drm_bridge   *next_bridge;
 
struct device *dev;
+   struct i2c_client *i2c;
+   struct regmap *regmap;
 };
 
 static inline struct tfp410 *
@@ -183,6 +200,9 @@ static void tfp410_enable(struct drm_bridge *bridge)
 {
struct tfp410 *dvi = drm_bridge_to_tfp410(bridge);
 
+   if (dvi->i2c)
+   regmap_set_bits(dvi->regmap, TFP410_REG_CTL_1_MODE, 
TFP410_BIT_PD);
+
gpiod_set_value_cansleep(dvi->powerdown, 0);
 }
 
@@ -190,6 +210,9 @@ static void tfp410_disable(struct drm_bridge *bridge)
 {
struct tfp410 *dvi = drm_bridge_to_tfp410(bridge);
 
+   if (dvi->i2c)
+   regmap_clear_bits(dvi->regmap, TFP410_REG_CTL_1_MODE, 
TFP410_BIT_PD);
+
gpiod_set_value_cansleep(dvi->powerdown, 1);
 }
 
@@ -221,38 +244,48 @@ static const struct drm_bridge_timings 
tfp410_default_timings = {
.hold_time_ps = 1300,
 };
 
-static int tfp410_parse_timings(struct tfp410 *dvi, bool i2c)
+static int tfp410_parse_timings(struct tfp410 *dvi)
 {
struct drm_bridge_timings *timings = &dvi->timings;
struct device_node *ep;
u32 pclk_sample = 0;
u32 bus_width = 24;
u32 deskew = 0;
+   unsigned int val = 0;
+   int ret = 0;
 
/* Start with defaults. */
*timings = tfp410_default_timings;
 
-   if (i2c)
+   if (dvi->i2c) {
/*
-* In I2C mode timings are configured through the I2C interface.
-* As the driver doesn't support I2C configuration yet, we just
-* go with the defaults (BSEL=1, DSEL=1, DKEN=0, EDGE=1).
+* For now, assume settings are latched from pins on reset / 
power up.
+* Should add options to optionally set them out of DT 
properties.
 */
-   return 0;
-
-   /*
-* In non-I2C mode, timings are configured through the BSEL, DSEL, DKEN
-* and EDGE pins. They are specified in DT through endpoint properties
-* and vendor-specific properties.
-*/
-   ep = of_graph_get_endpoint_by_regs(dvi->dev->of_node, 0, 0);
-   if (!ep)
-   return -EINVAL;
-
-   /* Get the sampling edge from the endpoint. */
-   of_property_read_u32(ep, "pclk-sample", &pclk_sample);
-   of_property_read_u32(ep, "bus-width", &bus_width);
-   of_node_put(ep);
+   ret = regmap_read(dvi->regmap, TFP410_REG_CTL_1_MODE, &val);
+   if (ret) {
+   dev_err(dvi->dev, "Read failed on CTL_1_MODE\n");
+   return ret;
+   }
+   pclk_sample = (val & TFP410_BIT_EDGE) ? 1 : 0;
+   bus_width = (val & TFP410_BIT_BSEL) ? 24 : 12;
+   dev_dbg(dvi->dev, "(0x%02X) : detected %d bus width, %s edge 
sampling\n",
+   val, bus_width, pclk_sample ? "positive" : "negative");
+   } else {
+   /*
+* In non-I2C mode, timings are configured through the BSEL, 
DSEL, DKEN
+* and EDGE pins. They are specified in DT through endpoint 
properties
+* and vendor-specific properties.
+*/
+   ep = of_graph_get_endpoint_by_regs(dvi->dev->of_node, 0, 0);
+   if (!ep)
+   return -EINVAL;
+
+   /* Get the sampling edge from the endpoint. */
+

[PATCH v4 0/3] drm/bridge: tfp410: Add i2c support

2023-04-04 Thread Jonathan Cormier
The TFP410 driver does not support I2C.  As such, the device remains in
Power Down if the I2C is enabled by the bootstrap pins.

Add basic support for the I2C interface, and provide support to take
the device out of power down when enabled.  Also read the bootstrap mode
pins via the CTL_1_MODE register when using the I2C bus.

Also allow polling device to support hdmi/dvi hotplug detection.

Signed-off-by: Jonathan Cormier 
---
Changes in v4:
- Add Reviewed-by: Neil Armstrong 
- Add Fixes: 5cafa0f1853b ("drm/bridge: tfp410: Replace manual connector 
handling with bridge")
- Link to v3: 
https://lore.kernel.org/r/20230125-tfp410_i2c-v3-0-a85d5f0f5...@criticallink.com

Changes in v3:
- Drop dt-bindings i2c example
- Link to v2: 
https://lore.kernel.org/r/20230125-tfp410_i2c-v2-0-bf22f4dcb...@criticallink.com

Changes in v2:
- Fix dt_binding_check errors
- Remove hdmi connector from binding example
- Fix compile warning. Unused variable and unsigned int instead of int for ret
- Fix commit titles
- Drop of_match_ptr change
- Link to v1: 
https://lore.kernel.org/r/20230125-tfp410_i2c-v1-0-66a4d4e39...@criticallink.com

---
Michael Williamson (3):
  drm/bridge: tfp410: Support basic I2C interface
  drm/bridge: tfp410: Fix logic to configured polled HPD
  drm/bridge: tfp410: If connected, use I2C for polled HPD status.

 drivers/gpu/drm/bridge/ti-tfp410.c | 107 +++--
 1 file changed, 80 insertions(+), 27 deletions(-)
---
base-commit: 93f875a8526a291005e7f38478079526c843cbec
change-id: 20230125-tfp410_i2c-3b270b0bf3e0

Best regards,
-- 
Jonathan Cormier 



[PATCH v3 3/3] drm/bridge: tfp410: If connected, use I2C for polled HPD status.

2023-02-20 Thread Jonathan Cormier
From: Michael Williamson 

If the I2C bus is connected on the TFP410, then use the register
status bit to determine connection state.  This is needed, in particular,
for polling the state when the Hot Plug detect is not connected to
a controlling CPU via GPIO/IRQ lane.

Signed-off-by: Michael Williamson 
Signed-off-by: Jonathan Cormier 
---
 drivers/gpu/drm/bridge/ti-tfp410.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/gpu/drm/bridge/ti-tfp410.c 
b/drivers/gpu/drm/bridge/ti-tfp410.c
index 41007d05d584..eeb7202452aa 100644
--- a/drivers/gpu/drm/bridge/ti-tfp410.c
+++ b/drivers/gpu/drm/bridge/ti-tfp410.c
@@ -28,6 +28,9 @@
 #define TFP410_BIT_BSEL BIT(2)
 #define TFP410_BIT_DSEL BIT(3)
 
+#define TFP410_REG_CTL_2_MODE  0x09
+#define TFP410_BIT_HTPLG BIT(1)
+
 static const struct regmap_config tfp410_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
@@ -105,6 +108,15 @@ static enum drm_connector_status
 tfp410_connector_detect(struct drm_connector *connector, bool force)
 {
struct tfp410 *dvi = drm_connector_to_tfp410(connector);
+   int ret;
+
+   if (dvi->i2c) {
+   ret = regmap_test_bits(dvi->regmap, TFP410_REG_CTL_2_MODE, 
TFP410_BIT_HTPLG);
+   if (ret < 0)
+   dev_err(dvi->dev, "%s failed to read HTPLG bit : %d\n", 
__func__, ret);
+   else
+   return ret ? connector_status_connected : 
connector_status_disconnected;
+   }
 
return drm_bridge_detect(dvi->next_bridge);
 }

-- 
2.25.1



[PATCH v3 2/3] drm/bridge: tfp410: Fix logic to configured polled HPD

2023-02-20 Thread Jonathan Cormier
From: Michael Williamson 

The logic to configure polling (vs async/irq notification) of hot-plug
events was not correct.  If the connected bridge requires polling,
then inform the upstream bridge we also require polling.

Signed-off-by: Michael Williamson 
Signed-off-by: Jonathan Cormier 
---
 drivers/gpu/drm/bridge/ti-tfp410.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/bridge/ti-tfp410.c 
b/drivers/gpu/drm/bridge/ti-tfp410.c
index bb3f8d0ff207..41007d05d584 100644
--- a/drivers/gpu/drm/bridge/ti-tfp410.c
+++ b/drivers/gpu/drm/bridge/ti-tfp410.c
@@ -155,7 +155,7 @@ static int tfp410_attach(struct drm_bridge *bridge,
return -ENODEV;
}
 
-   if (dvi->next_bridge->ops & DRM_BRIDGE_OP_DETECT)
+   if (dvi->next_bridge->ops & DRM_BRIDGE_OP_HPD)
dvi->connector.polled = DRM_CONNECTOR_POLL_HPD;
else
dvi->connector.polled = DRM_CONNECTOR_POLL_CONNECT | 
DRM_CONNECTOR_POLL_DISCONNECT;

-- 
2.25.1



[PATCH v3 1/3] drm/bridge: tfp410: Support basic I2C interface

2023-02-20 Thread Jonathan Cormier
From: Michael Williamson 

The TFP410 driver does not support I2C.  As such, the device remains in
Power Down if the I2C is enabled by the bootstrap pins.

Add basic support for the I2C interface, and provide support to take
the device out of power down when enabled.  Also read the bootstrap mode
pins via the CTL_1_MODE register when using the I2C bus.

Signed-off-by: Michael Williamson 
Signed-off-by: Jonathan Cormier 
---
 drivers/gpu/drm/bridge/ti-tfp410.c | 93 +++---
 1 file changed, 67 insertions(+), 26 deletions(-)

diff --git a/drivers/gpu/drm/bridge/ti-tfp410.c 
b/drivers/gpu/drm/bridge/ti-tfp410.c
index b9635abbad16..bb3f8d0ff207 100644
--- a/drivers/gpu/drm/bridge/ti-tfp410.c
+++ b/drivers/gpu/drm/bridge/ti-tfp410.c
@@ -6,6 +6,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -21,6 +22,20 @@
 
 #define HOTPLUG_DEBOUNCE_MS1100
 
+#define TFP410_REG_CTL_1_MODE  0x08
+#define TFP410_BIT_PD   BIT(0)
+#define TFP410_BIT_EDGE BIT(1)
+#define TFP410_BIT_BSEL BIT(2)
+#define TFP410_BIT_DSEL BIT(3)
+
+static const struct regmap_config tfp410_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+
+   .max_register = 0xff,
+   .cache_type = REGCACHE_NONE,
+};
+
 struct tfp410 {
struct drm_bridge   bridge;
struct drm_connectorconnector;
@@ -33,6 +48,8 @@ struct tfp410 {
struct drm_bridge   *next_bridge;
 
struct device *dev;
+   struct i2c_client *i2c;
+   struct regmap *regmap;
 };
 
 static inline struct tfp410 *
@@ -183,6 +200,9 @@ static void tfp410_enable(struct drm_bridge *bridge)
 {
struct tfp410 *dvi = drm_bridge_to_tfp410(bridge);
 
+   if (dvi->i2c)
+   regmap_set_bits(dvi->regmap, TFP410_REG_CTL_1_MODE, 
TFP410_BIT_PD);
+
gpiod_set_value_cansleep(dvi->powerdown, 0);
 }
 
@@ -190,6 +210,9 @@ static void tfp410_disable(struct drm_bridge *bridge)
 {
struct tfp410 *dvi = drm_bridge_to_tfp410(bridge);
 
+   if (dvi->i2c)
+   regmap_clear_bits(dvi->regmap, TFP410_REG_CTL_1_MODE, 
TFP410_BIT_PD);
+
gpiod_set_value_cansleep(dvi->powerdown, 1);
 }
 
@@ -221,38 +244,48 @@ static const struct drm_bridge_timings 
tfp410_default_timings = {
.hold_time_ps = 1300,
 };
 
-static int tfp410_parse_timings(struct tfp410 *dvi, bool i2c)
+static int tfp410_parse_timings(struct tfp410 *dvi)
 {
struct drm_bridge_timings *timings = &dvi->timings;
struct device_node *ep;
u32 pclk_sample = 0;
u32 bus_width = 24;
u32 deskew = 0;
+   unsigned int val = 0;
+   int ret = 0;
 
/* Start with defaults. */
*timings = tfp410_default_timings;
 
-   if (i2c)
+   if (dvi->i2c) {
/*
-* In I2C mode timings are configured through the I2C interface.
-* As the driver doesn't support I2C configuration yet, we just
-* go with the defaults (BSEL=1, DSEL=1, DKEN=0, EDGE=1).
+* For now, assume settings are latched from pins on reset / 
power up.
+* Should add options to optionally set them out of DT 
properties.
 */
-   return 0;
-
-   /*
-* In non-I2C mode, timings are configured through the BSEL, DSEL, DKEN
-* and EDGE pins. They are specified in DT through endpoint properties
-* and vendor-specific properties.
-*/
-   ep = of_graph_get_endpoint_by_regs(dvi->dev->of_node, 0, 0);
-   if (!ep)
-   return -EINVAL;
-
-   /* Get the sampling edge from the endpoint. */
-   of_property_read_u32(ep, "pclk-sample", &pclk_sample);
-   of_property_read_u32(ep, "bus-width", &bus_width);
-   of_node_put(ep);
+   ret = regmap_read(dvi->regmap, TFP410_REG_CTL_1_MODE, &val);
+   if (ret) {
+   dev_err(dvi->dev, "Read failed on CTL_1_MODE\n");
+   return ret;
+   }
+   pclk_sample = (val & TFP410_BIT_EDGE) ? 1 : 0;
+   bus_width = (val & TFP410_BIT_BSEL) ? 24 : 12;
+   dev_dbg(dvi->dev, "(0x%02X) : detected %d bus width, %s edge 
sampling\n",
+   val, bus_width, pclk_sample ? "positive" : "negative");
+   } else {
+   /*
+* In non-I2C mode, timings are configured through the BSEL, 
DSEL, DKEN
+* and EDGE pins. They are specified in DT through endpoint 
properties
+* and vendor-specific properties.
+*/
+   ep = of_graph_get_endpoint_by_regs(dvi->dev->of_node, 0, 0);
+   if (!ep)
+   return -EINVAL;
+
+   /* Get the sampling edge from the endpoint. */
+   of_property_read_u

[PATCH v3 0/3] drm/bridge: tfp410: Add i2c support

2023-02-20 Thread Jonathan Cormier
The TFP410 driver does not support I2C.  As such, the device remains in
Power Down if the I2C is enabled by the bootstrap pins.

Add basic support for the I2C interface, and provide support to take
the device out of power down when enabled.  Also read the bootstrap mode
pins via the CTL_1_MODE register when using the I2C bus.

Also allow polling device to support hdmi/dvi hotplug detection.

Signed-off-by: Jonathan Cormier 
---
Changes in v3:
- Drop dt-bindings i2c example
- Link to v2: 
https://lore.kernel.org/r/20230125-tfp410_i2c-v2-0-bf22f4dcb...@criticallink.com

Changes in v2:
- Fix dt_binding_check errors
- Remove hdmi connector from binding example
- Fix compile warning. Unused variable and unsigned int instead of int for ret
- Fix commit titles
- Drop of_match_ptr change
- Link to v1: 
https://lore.kernel.org/r/20230125-tfp410_i2c-v1-0-66a4d4e39...@criticallink.com

---
Michael Williamson (3):
  drm/bridge: tfp410: Support basic I2C interface
  drm/bridge: tfp410: Fix logic to configured polled HPD
  drm/bridge: tfp410: If connected, use I2C for polled HPD status.

 drivers/gpu/drm/bridge/ti-tfp410.c | 107 +++--
 1 file changed, 80 insertions(+), 27 deletions(-)
---
base-commit: 93f875a8526a291005e7f38478079526c843cbec
change-id: 20230125-tfp410_i2c-3b270b0bf3e0

Best regards,
-- 
Jonathan Cormier 



[PATCH v2 3/4] drm/bridge: tfp410: Fix logic to configured polled HPD

2023-01-26 Thread Jonathan Cormier
From: Michael Williamson 

The logic to configure polling (vs async/irq notification) of hot-plug
events was not correct.  If the connected bridge requires polling,
then inform the upstream bridge we also require polling.

Signed-off-by: Michael Williamson 
Signed-off-by: Jonathan Cormier 
---
 drivers/gpu/drm/bridge/ti-tfp410.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/bridge/ti-tfp410.c 
b/drivers/gpu/drm/bridge/ti-tfp410.c
index bb3f8d0ff207..41007d05d584 100644
--- a/drivers/gpu/drm/bridge/ti-tfp410.c
+++ b/drivers/gpu/drm/bridge/ti-tfp410.c
@@ -155,7 +155,7 @@ static int tfp410_attach(struct drm_bridge *bridge,
return -ENODEV;
}
 
-   if (dvi->next_bridge->ops & DRM_BRIDGE_OP_DETECT)
+   if (dvi->next_bridge->ops & DRM_BRIDGE_OP_HPD)
dvi->connector.polled = DRM_CONNECTOR_POLL_HPD;
else
dvi->connector.polled = DRM_CONNECTOR_POLL_CONNECT | 
DRM_CONNECTOR_POLL_DISCONNECT;

-- 
2.25.1



[PATCH v2 4/4] drm/bridge: tfp410: If connected, use I2C for polled HPD status.

2023-01-26 Thread Jonathan Cormier
From: Michael Williamson 

If the I2C bus is connected on the TFP410, then use the register
status bit to determine connection state.  This is needed, in particular,
for polling the state when the Hot Plug detect is not connected to
a controlling CPU via GPIO/IRQ lane.

Signed-off-by: Michael Williamson 
Signed-off-by: Jonathan Cormier 
---
 drivers/gpu/drm/bridge/ti-tfp410.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/gpu/drm/bridge/ti-tfp410.c 
b/drivers/gpu/drm/bridge/ti-tfp410.c
index 41007d05d584..eeb7202452aa 100644
--- a/drivers/gpu/drm/bridge/ti-tfp410.c
+++ b/drivers/gpu/drm/bridge/ti-tfp410.c
@@ -28,6 +28,9 @@
 #define TFP410_BIT_BSEL BIT(2)
 #define TFP410_BIT_DSEL BIT(3)
 
+#define TFP410_REG_CTL_2_MODE  0x09
+#define TFP410_BIT_HTPLG BIT(1)
+
 static const struct regmap_config tfp410_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
@@ -105,6 +108,15 @@ static enum drm_connector_status
 tfp410_connector_detect(struct drm_connector *connector, bool force)
 {
struct tfp410 *dvi = drm_connector_to_tfp410(connector);
+   int ret;
+
+   if (dvi->i2c) {
+   ret = regmap_test_bits(dvi->regmap, TFP410_REG_CTL_2_MODE, 
TFP410_BIT_HTPLG);
+   if (ret < 0)
+   dev_err(dvi->dev, "%s failed to read HTPLG bit : %d\n", 
__func__, ret);
+   else
+   return ret ? connector_status_connected : 
connector_status_disconnected;
+   }
 
return drm_bridge_detect(dvi->next_bridge);
 }

-- 
2.25.1



[PATCH v2 2/4] drm/bridge: tfp410: Support basic I2C interface

2023-01-26 Thread Jonathan Cormier
From: Michael Williamson 

The TFP410 driver does not support I2C.  As such, the device remains in
Power Down if the I2C is enabled by the bootstrap pins.

Add basic support for the I2C interface, and provide support to take
the device out of power down when enabled.  Also read the bootstrap mode
pins via the CTL_1_MODE register when using the I2C bus.

Signed-off-by: Michael Williamson 
Signed-off-by: Jonathan Cormier 
---
 drivers/gpu/drm/bridge/ti-tfp410.c | 93 +++---
 1 file changed, 67 insertions(+), 26 deletions(-)

diff --git a/drivers/gpu/drm/bridge/ti-tfp410.c 
b/drivers/gpu/drm/bridge/ti-tfp410.c
index b9635abbad16..bb3f8d0ff207 100644
--- a/drivers/gpu/drm/bridge/ti-tfp410.c
+++ b/drivers/gpu/drm/bridge/ti-tfp410.c
@@ -6,6 +6,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -21,6 +22,20 @@
 
 #define HOTPLUG_DEBOUNCE_MS1100
 
+#define TFP410_REG_CTL_1_MODE  0x08
+#define TFP410_BIT_PD   BIT(0)
+#define TFP410_BIT_EDGE BIT(1)
+#define TFP410_BIT_BSEL BIT(2)
+#define TFP410_BIT_DSEL BIT(3)
+
+static const struct regmap_config tfp410_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+
+   .max_register = 0xff,
+   .cache_type = REGCACHE_NONE,
+};
+
 struct tfp410 {
struct drm_bridge   bridge;
struct drm_connectorconnector;
@@ -33,6 +48,8 @@ struct tfp410 {
struct drm_bridge   *next_bridge;
 
struct device *dev;
+   struct i2c_client *i2c;
+   struct regmap *regmap;
 };
 
 static inline struct tfp410 *
@@ -183,6 +200,9 @@ static void tfp410_enable(struct drm_bridge *bridge)
 {
struct tfp410 *dvi = drm_bridge_to_tfp410(bridge);
 
+   if (dvi->i2c)
+   regmap_set_bits(dvi->regmap, TFP410_REG_CTL_1_MODE, 
TFP410_BIT_PD);
+
gpiod_set_value_cansleep(dvi->powerdown, 0);
 }
 
@@ -190,6 +210,9 @@ static void tfp410_disable(struct drm_bridge *bridge)
 {
struct tfp410 *dvi = drm_bridge_to_tfp410(bridge);
 
+   if (dvi->i2c)
+   regmap_clear_bits(dvi->regmap, TFP410_REG_CTL_1_MODE, 
TFP410_BIT_PD);
+
gpiod_set_value_cansleep(dvi->powerdown, 1);
 }
 
@@ -221,38 +244,48 @@ static const struct drm_bridge_timings 
tfp410_default_timings = {
.hold_time_ps = 1300,
 };
 
-static int tfp410_parse_timings(struct tfp410 *dvi, bool i2c)
+static int tfp410_parse_timings(struct tfp410 *dvi)
 {
struct drm_bridge_timings *timings = &dvi->timings;
struct device_node *ep;
u32 pclk_sample = 0;
u32 bus_width = 24;
u32 deskew = 0;
+   unsigned int val = 0;
+   int ret = 0;
 
/* Start with defaults. */
*timings = tfp410_default_timings;
 
-   if (i2c)
+   if (dvi->i2c) {
/*
-* In I2C mode timings are configured through the I2C interface.
-* As the driver doesn't support I2C configuration yet, we just
-* go with the defaults (BSEL=1, DSEL=1, DKEN=0, EDGE=1).
+* For now, assume settings are latched from pins on reset / 
power up.
+* Should add options to optionally set them out of DT 
properties.
 */
-   return 0;
-
-   /*
-* In non-I2C mode, timings are configured through the BSEL, DSEL, DKEN
-* and EDGE pins. They are specified in DT through endpoint properties
-* and vendor-specific properties.
-*/
-   ep = of_graph_get_endpoint_by_regs(dvi->dev->of_node, 0, 0);
-   if (!ep)
-   return -EINVAL;
-
-   /* Get the sampling edge from the endpoint. */
-   of_property_read_u32(ep, "pclk-sample", &pclk_sample);
-   of_property_read_u32(ep, "bus-width", &bus_width);
-   of_node_put(ep);
+   ret = regmap_read(dvi->regmap, TFP410_REG_CTL_1_MODE, &val);
+   if (ret) {
+   dev_err(dvi->dev, "Read failed on CTL_1_MODE\n");
+   return ret;
+   }
+   pclk_sample = (val & TFP410_BIT_EDGE) ? 1 : 0;
+   bus_width = (val & TFP410_BIT_BSEL) ? 24 : 12;
+   dev_dbg(dvi->dev, "(0x%02X) : detected %d bus width, %s edge 
sampling\n",
+   val, bus_width, pclk_sample ? "positive" : "negative");
+   } else {
+   /*
+* In non-I2C mode, timings are configured through the BSEL, 
DSEL, DKEN
+* and EDGE pins. They are specified in DT through endpoint 
properties
+* and vendor-specific properties.
+*/
+   ep = of_graph_get_endpoint_by_regs(dvi->dev->of_node, 0, 0);
+   if (!ep)
+   return -EINVAL;
+
+   /* Get the sampling edge from the endpoint. */
+   of_property_read_u

[PATCH v2 1/4] dt-bindings: display: bridge: tfp410: Add tfp410 i2c example

2023-01-26 Thread Jonathan Cormier
Add a i2c example with HDMI connector

Signed-off-by: Jonathan Cormier 
---
 .../bindings/display/bridge/ti,tfp410.yaml | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/Documentation/devicetree/bindings/display/bridge/ti,tfp410.yaml 
b/Documentation/devicetree/bindings/display/bridge/ti,tfp410.yaml
index 4c5dd8ec2951..1f3d29259f22 100644
--- a/Documentation/devicetree/bindings/display/bridge/ti,tfp410.yaml
+++ b/Documentation/devicetree/bindings/display/bridge/ti,tfp410.yaml
@@ -116,4 +116,34 @@ examples:
 };
 };
 
+  - |
+i2c {
+#address-cells = <1>;
+#size-cells = <0>;
+
+tfp410_i2c: encoder@38 {
+compatible = "ti,tfp410";
+reg = <0x38>;
+
+ports {
+#address-cells = <1>;
+#size-cells = <0>;
+
+port@0 {
+reg = <0>;
+tfp410_in_1: endpoint {
+remote-endpoint = <&dpi1_out>;
+};
+};
+
+port@1 {
+reg = <1>;
+tfp410_out_1: endpoint {
+remote-endpoint = <&hdmi_connector_in>;
+};
+};
+};
+};
+};
+
 ...

-- 
2.25.1



[PATCH v2 0/4] drm/bridge: tfp410: Add i2c support

2023-01-26 Thread Jonathan Cormier
The TFP410 driver does not support I2C.  As such, the device remains in
Power Down if the I2C is enabled by the bootstrap pins.

Add basic support for the I2C interface, and provide support to take
the device out of power down when enabled.  Also read the bootstrap mode
pins via the CTL_1_MODE register when using the I2C bus.

Also allow polling device to support hdmi/dvi hotplug detection.

Signed-off-by: Jonathan Cormier 
---
Changes in v2:
- Fix dt_binding_check errors
- Remove hdmi connector from binding example
- Fix compile warning. Unused variable and unsigned int instead of int for ret
- Fix commit titles
- Drop of_match_ptr change
- Link to v1: 
https://lore.kernel.org/r/20230125-tfp410_i2c-v1-0-66a4d4e39...@criticallink.com

---
Jonathan Cormier (1):
  dt-bindings: display: bridge: tfp410: Add tfp410 i2c example

Michael Williamson (3):
  drm/bridge: tfp410: Support basic I2C interface
  drm/bridge: tfp410: Fix logic to configured polled HPD
  drm/bridge: tfp410: If connected, use I2C for polled HPD status.

 .../bindings/display/bridge/ti,tfp410.yaml |  30 ++
 drivers/gpu/drm/bridge/ti-tfp410.c | 107 +++--
 2 files changed, 110 insertions(+), 27 deletions(-)
---
base-commit: 93f875a8526a291005e7f38478079526c843cbec
change-id: 20230125-tfp410_i2c-3b270b0bf3e0

Best regards,
-- 
Jonathan Cormier 



[PATCH 4/4] DRM: BRIDGE: TFP410: If connected, use I2C for polled HPD status.

2023-01-25 Thread Jonathan Cormier
From: Michael Williamson 

If the I2C bus is connected on the TFP410, then use the register
status bit to determine connection state.  This is needed, in particular,
for polling the state when the Hot Plug detect is not connected to
a controlling CPU via GPIO/IRQ lane.

Signed-off-by: Michael Williamson 
Signed-off-by: Jonathan Cormier 
---
 drivers/gpu/drm/bridge/ti-tfp410.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/drivers/gpu/drm/bridge/ti-tfp410.c 
b/drivers/gpu/drm/bridge/ti-tfp410.c
index 837e1f81a0ff..ac216eaec3c8 100644
--- a/drivers/gpu/drm/bridge/ti-tfp410.c
+++ b/drivers/gpu/drm/bridge/ti-tfp410.c
@@ -28,6 +28,9 @@
 #define TFP410_BIT_BSEL BIT(2)
 #define TFP410_BIT_DSEL BIT(3)
 
+#define TFP410_REG_CTL_2_MODE  0x09
+#define TFP410_BIT_HTPLG BIT(1)
+
 static const struct regmap_config tfp410_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
@@ -105,6 +108,16 @@ static enum drm_connector_status
 tfp410_connector_detect(struct drm_connector *connector, bool force)
 {
struct tfp410 *dvi = drm_connector_to_tfp410(connector);
+   u32 val;
+   unsigned int ret;
+
+   if (dvi->i2c) {
+   ret = regmap_test_bits(dvi->regmap, TFP410_REG_CTL_2_MODE, 
TFP410_BIT_HTPLG);
+   if (ret < 0)
+   dev_err(dvi->dev, "%s failed to read HTPLG bit : %d\n", 
__func__, ret);
+   else
+   return ret ? connector_status_connected : 
connector_status_disconnected;
+   }
 
return drm_bridge_detect(dvi->next_bridge);
 }

-- 
2.25.1


[PATCH 1/4] dt-bindings: display: bridge: tfp410: Add tfp410 i2c example

2023-01-25 Thread Jonathan Cormier
Add a i2c example with HDMI connector

Signed-off-by: Jonathan Cormier 
---
 .../bindings/display/bridge/ti,tfp410.yaml | 42 ++
 1 file changed, 42 insertions(+)

diff --git a/Documentation/devicetree/bindings/display/bridge/ti,tfp410.yaml 
b/Documentation/devicetree/bindings/display/bridge/ti,tfp410.yaml
index 4c5dd8ec2951..456214f14b47 100644
--- a/Documentation/devicetree/bindings/display/bridge/ti,tfp410.yaml
+++ b/Documentation/devicetree/bindings/display/bridge/ti,tfp410.yaml
@@ -116,4 +116,46 @@ examples:
 };
 };
 
+  - |
+i2c {
+  #address-cells = <1>;
+  #size-cells = <0>;
+
+  hdmi_encoder: tfp410@38 {
+compatible = "ti,tfp410";
+reg = <0x38>;
+
+ports {
+  address-cells = <1>;
+  size-cells = <0>;
+
+  port@0 {
+reg = <0>;
+tfp410_in: endpoint {
+  remote-endpoint = <&dpi1_out>;
+};
+  };
+
+  port@1 {
+reg = <1>;
+tfp410_out: endpoint {
+  remote-endpoint = <&hdmi_connector_in>;
+};
+  };
+};
+  };
+};
+
+hdmi: hdmi_connector {
+  compatible = "hdmi-connector";
+  label = "hdmi";
+  type = "a";
+  ddc-i2c-bus = <&i2c1>;
+  port {
+hdmi_connector_in: endpoint {
+  remote-endpoint = <&tfp410_out>;
+};
+  };
+};
+
 ...

-- 
2.25.1


[PATCH 0/4] DRM: BRIDGE: TFP410: Add i2c support

2023-01-25 Thread Jonathan Cormier
The TFP410 driver does not support I2C.  As such, the device remains in
Power Down if the I2C is enabled by the bootstrap pins.

Add basic support for the I2C interface, and provide support to take
the device out of power down when enabled.  Also read the bootstrap mode
pins via the CTL_1_MODE register when using the I2C bus.

Also allow polling device to support hdmi/dvi hotplug detection.

To: Andrzej Hajda 
To: Neil Armstrong 
To: Robert Foss 
To: Laurent Pinchart 
To: Jonas Karlman 
To: Jernej Skrabec 
To: David Airlie 
To: Daniel Vetter 
To: Rob Herring 
To: Krzysztof Kozlowski 
To: Tomi Valkeinen 
To: Jyri Sarha 
Cc: dri-devel@lists.freedesktop.org
Cc: devicet...@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
Cc: Michael Williamson 
Cc: Bob Duke 
Signed-off-by: Jonathan Cormier 

---
Jonathan Cormier (1):
  dt-bindings: display: bridge: tfp410: Add tfp410 i2c example

Michael Williamson (3):
  DRM: BRIDGE: TFP410: Support basic I2C interface
  DRM: BRIDGE: TFP410: Fix logic to configured polled HPD
  DRM: BRIDGE: TFP410: If connected, use I2C for polled HPD status.

 .../bindings/display/bridge/ti,tfp410.yaml |  42 
 drivers/gpu/drm/bridge/ti-tfp410.c | 110 +++--
 2 files changed, 124 insertions(+), 28 deletions(-)
---
base-commit: 93f875a8526a291005e7f38478079526c843cbec
change-id: 20230125-tfp410_i2c-3b270b0bf3e0

Best regards,
-- 
Jonathan Cormier 


[PATCH 2/4] DRM: BRIDGE: TFP410: Support basic I2C interface

2023-01-25 Thread Jonathan Cormier
From: Michael Williamson 

The TFP410 driver does not support I2C.  As such, the device remains in
Power Down if the I2C is enabled by the bootstrap pins.

Add basic support for the I2C interface, and provide support to take
the device out of power down when enabled.  Also read the bootstrap mode
pins via the CTL_1_MODE register when using the I2C bus.

Signed-off-by: Michael Williamson 
Signed-off-by: Jonathan Cormier 
---
 drivers/gpu/drm/bridge/ti-tfp410.c | 95 +++---
 1 file changed, 68 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/bridge/ti-tfp410.c 
b/drivers/gpu/drm/bridge/ti-tfp410.c
index b9635abbad16..323a6d9ed188 100644
--- a/drivers/gpu/drm/bridge/ti-tfp410.c
+++ b/drivers/gpu/drm/bridge/ti-tfp410.c
@@ -6,6 +6,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -21,6 +22,20 @@
 
 #define HOTPLUG_DEBOUNCE_MS1100
 
+#define TFP410_REG_CTL_1_MODE  0x08
+#define TFP410_BIT_PD   BIT(0)
+#define TFP410_BIT_EDGE BIT(1)
+#define TFP410_BIT_BSEL BIT(2)
+#define TFP410_BIT_DSEL BIT(3)
+
+static const struct regmap_config tfp410_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+
+   .max_register = 0xff,
+   .cache_type = REGCACHE_NONE,
+};
+
 struct tfp410 {
struct drm_bridge   bridge;
struct drm_connectorconnector;
@@ -33,6 +48,8 @@ struct tfp410 {
struct drm_bridge   *next_bridge;
 
struct device *dev;
+   struct i2c_client *i2c;
+   struct regmap *regmap;
 };
 
 static inline struct tfp410 *
@@ -183,6 +200,9 @@ static void tfp410_enable(struct drm_bridge *bridge)
 {
struct tfp410 *dvi = drm_bridge_to_tfp410(bridge);
 
+   if (dvi->i2c)
+   regmap_set_bits(dvi->regmap, TFP410_REG_CTL_1_MODE, 
TFP410_BIT_PD);
+
gpiod_set_value_cansleep(dvi->powerdown, 0);
 }
 
@@ -190,6 +210,9 @@ static void tfp410_disable(struct drm_bridge *bridge)
 {
struct tfp410 *dvi = drm_bridge_to_tfp410(bridge);
 
+   if (dvi->i2c)
+   regmap_clear_bits(dvi->regmap, TFP410_REG_CTL_1_MODE, 
TFP410_BIT_PD);
+
gpiod_set_value_cansleep(dvi->powerdown, 1);
 }
 
@@ -221,38 +244,48 @@ static const struct drm_bridge_timings 
tfp410_default_timings = {
.hold_time_ps = 1300,
 };
 
-static int tfp410_parse_timings(struct tfp410 *dvi, bool i2c)
+static int tfp410_parse_timings(struct tfp410 *dvi)
 {
struct drm_bridge_timings *timings = &dvi->timings;
struct device_node *ep;
u32 pclk_sample = 0;
u32 bus_width = 24;
u32 deskew = 0;
+   unsigned int val = 0;
+   int ret = 0;
 
/* Start with defaults. */
*timings = tfp410_default_timings;
 
-   if (i2c)
+   if (dvi->i2c) {
/*
-* In I2C mode timings are configured through the I2C interface.
-* As the driver doesn't support I2C configuration yet, we just
-* go with the defaults (BSEL=1, DSEL=1, DKEN=0, EDGE=1).
+* For now, assume settings are latched from pins on reset / 
power up.
+* Should add options to optionally set them out of DT 
properties.
 */
-   return 0;
-
-   /*
-* In non-I2C mode, timings are configured through the BSEL, DSEL, DKEN
-* and EDGE pins. They are specified in DT through endpoint properties
-* and vendor-specific properties.
-*/
-   ep = of_graph_get_endpoint_by_regs(dvi->dev->of_node, 0, 0);
-   if (!ep)
-   return -EINVAL;
-
-   /* Get the sampling edge from the endpoint. */
-   of_property_read_u32(ep, "pclk-sample", &pclk_sample);
-   of_property_read_u32(ep, "bus-width", &bus_width);
-   of_node_put(ep);
+   ret = regmap_read(dvi->regmap, TFP410_REG_CTL_1_MODE, &val);
+   if (ret) {
+   dev_err(dvi->dev, "Read failed on CTL_1_MODE\n");
+   return ret;
+   }
+   pclk_sample = (val & TFP410_BIT_EDGE) ? 1 : 0;
+   bus_width = (val & TFP410_BIT_BSEL) ? 24 : 12;
+   dev_dbg(dvi->dev, "(0x%02X) : detected %d bus width, %s edge 
sampling\n",
+   val, bus_width, pclk_sample ? "positive" : "negative");
+   } else {
+   /*
+* In non-I2C mode, timings are configured through the BSEL, 
DSEL, DKEN
+* and EDGE pins. They are specified in DT through endpoint 
properties
+* and vendor-specific properties.
+*/
+   ep = of_graph_get_endpoint_by_regs(dvi->dev->of_node, 0, 0);
+   if (!ep)
+   return -EINVAL;
+
+   /* Get the sampling edge from the endpoint. */
+   of_property_read_u

[PATCH 3/4] DRM: BRIDGE: TFP410: Fix logic to configured polled HPD

2023-01-25 Thread Jonathan Cormier
From: Michael Williamson 

The logic to configure polling (vs async/irq notification) of hot-plug
events was not correct.  If the connected bridge requires polling,
then inform the upstream bridge we also require polling.

Signed-off-by: Michael Williamson 
Signed-off-by: Jonathan Cormier 
---
 drivers/gpu/drm/bridge/ti-tfp410.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/bridge/ti-tfp410.c 
b/drivers/gpu/drm/bridge/ti-tfp410.c
index 323a6d9ed188..837e1f81a0ff 100644
--- a/drivers/gpu/drm/bridge/ti-tfp410.c
+++ b/drivers/gpu/drm/bridge/ti-tfp410.c
@@ -155,7 +155,7 @@ static int tfp410_attach(struct drm_bridge *bridge,
return -ENODEV;
}
 
-   if (dvi->next_bridge->ops & DRM_BRIDGE_OP_DETECT)
+   if (dvi->next_bridge->ops & DRM_BRIDGE_OP_HPD)
dvi->connector.polled = DRM_CONNECTOR_POLL_HPD;
else
dvi->connector.polled = DRM_CONNECTOR_POLL_CONNECT | 
DRM_CONNECTOR_POLL_DISCONNECT;

-- 
2.25.1