[PATCH 2/2] drm/bridge: anx7625: Fix Set HPD irq detect window to 2ms

2023-11-20 Thread Xin Ji
Polling firmware HPD GPIO status, set HPD irq detect window to 2ms
after firmware HPD GPIO initial done

Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 51 ---
 drivers/gpu/drm/bridge/analogix/anx7625.h |  4 ++
 2 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 51abe42c639e..ef31033439bc 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1298,10 +1298,32 @@ static void anx7625_config(struct anx7625_data *ctx)
  XTAL_FRQ_SEL, XTAL_FRQ_27M);
 }
 
+static int anx7625_hpd_timer_config(struct anx7625_data *ctx)
+{
+   int ret;
+
+   /* Set irq detect window to 2ms */
+   ret = anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
+   HPD_DET_TIMER_BIT0_7, HPD_TIME & 0xFF);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
+HPD_DET_TIMER_BIT8_15,
+(HPD_TIME >> 8) & 0xFF);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
+HPD_DET_TIMER_BIT16_23,
+(HPD_TIME >> 16) & 0xFF);
+
+   return ret;
+}
+
+static int anx7625_read_hpd_gpio_config_status(struct anx7625_data *ctx)
+{
+   return anx7625_reg_read(ctx, ctx->i2c.rx_p0_client, GPIO_CTRL_2);
+}
+
 static void anx7625_disable_pd_protocol(struct anx7625_data *ctx)
 {
struct device *dev = ctx->dev;
-   int ret;
+   int ret, val;
 
/* Reset main ocm */
ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client, 0x88, 0x40);
@@ -1315,6 +1337,19 @@ static void anx7625_disable_pd_protocol(struct 
anx7625_data *ctx)
DRM_DEV_DEBUG_DRIVER(dev, "disable PD feature fail.\n");
else
DRM_DEV_DEBUG_DRIVER(dev, "disable PD feature succeeded.\n");
+
+   /*
+* Make sure the HPD GPIO already be configured after OCM release before
+* setting HPD detect window register. Here we poll the status register
+* at maximum 40ms, then config HPD irq detect window register
+*/
+   readx_poll_timeout(anx7625_read_hpd_gpio_config_status,
+  ctx, val,
+  ((val & HPD_SOURCE) || (val < 0)),
+  2000, 2000 * 20);
+
+   /* Set HPD irq detect window to 2ms */
+   anx7625_hpd_timer_config(ctx);
 }
 
 static int anx7625_ocm_loading_check(struct anx7625_data *ctx)
@@ -1437,20 +1472,6 @@ static void anx7625_start_dp_work(struct anx7625_data 
*ctx)
 
 static int anx7625_read_hpd_status_p0(struct anx7625_data *ctx)
 {
-   int ret;
-
-   /* Set irq detect window to 2ms */
-   ret = anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
-   HPD_DET_TIMER_BIT0_7, HPD_TIME & 0xFF);
-   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
-HPD_DET_TIMER_BIT8_15,
-(HPD_TIME >> 8) & 0xFF);
-   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
-HPD_DET_TIMER_BIT16_23,
-(HPD_TIME >> 16) & 0xFF);
-   if (ret < 0)
-   return ret;
-
return anx7625_reg_read(ctx, ctx->i2c.rx_p0_client, SYSTEM_STSTUS);
 }
 
diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h 
b/drivers/gpu/drm/bridge/analogix/anx7625.h
index 5af819611ebc..66ebee7f3d83 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.h
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
@@ -259,6 +259,10 @@
 #define AP_MIPI_RX_EN BIT(5) /* 1: MIPI RX input in  0: no RX in */
 #define AP_DISABLE_PD BIT(6)
 #define AP_DISABLE_DISPLAY BIT(7)
+
+#define GPIO_CTRL_2   0x49
+#define HPD_SOURCEBIT(6)
+
 /***/
 /* Register definition of device address 0x84 */
 #define  MIPI_PHY_CONTROL_30x03
-- 
2.25.1



[PATCH 1/2] Revert "drm/bridge: Add 200ms delay to wait FW HPD status stable"

2023-11-20 Thread Xin Ji
This reverts commit 330140d7319fcc4ec68bd924ea212e476bf12275

200ms delay will cause panel display image later than backlight
turn on, revert this patch.

Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 8f740154707d..51abe42c639e 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1464,9 +1464,6 @@ static int _anx7625_hpd_polling(struct anx7625_data *ctx,
if (ctx->pdata.intp_irq)
return 0;
 
-   /* Delay 200ms for FW HPD de-bounce */
-   msleep(200);
-
ret = readx_poll_timeout(anx7625_read_hpd_status_p0,
 ctx, val,
 ((val & HPD_STATUS) || (val < 0)),
-- 
2.25.1



[PATCH v2] drm/bridge: Add 200ms delay to wait FW HPD status stable

2023-09-22 Thread Xin Ji
For the no-interrupt design (sink device is panel, polling HPD
status when chip power on), anx7625 FW has more than 200ms HPD
de-bounce time in FW, for the safety to get HPD status, driver
better to wait 200ms before HPD detection after OS resume back.

Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 51abe42c639e..8f740154707d 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1464,6 +1464,9 @@ static int _anx7625_hpd_polling(struct anx7625_data *ctx,
if (ctx->pdata.intp_irq)
return 0;
 
+   /* Delay 200ms for FW HPD de-bounce */
+   msleep(200);
+
ret = readx_poll_timeout(anx7625_read_hpd_status_p0,
 ctx, val,
 ((val & HPD_STATUS) || (val < 0)),
-- 
2.25.1



RE: [PATCH] drm/bridge: Add 200ms delay to wait FW HPD status stable

2023-09-22 Thread Xin Ji
Hi Jani Nikula, thanks for reviewing, I'll use msleep instead,  thanks!
Xin

> -Original Message-
> From: Jani Nikula 
> Sent: Thursday, September 21, 2023 8:09 PM
> To: Xin Ji ; Andrzej Hajda ;
> Neil Armstrong ; Robert Foss ;
> Laurent Pinchart ; Jonas Karlman
> ; Jernej Skrabec ; David Airlie
> ; Daniel Vetter 
> Cc: Qilin Wen ; linux-ker...@vger.kernel.org; dri-
> de...@lists.freedesktop.org; hsi...@chromium.org; Bernie Liang
> ; Xin Ji 
> Subject: Re: [PATCH] drm/bridge: Add 200ms delay to wait FW HPD status stable
> 
> On Thu, 21 Sep 2023, Xin Ji  wrote:
> > For the none-interrupt design(sink device is panel, polling HPD status
> > when chip power on), anx7625 FW has more than 200ms HPD de-bounce time
> > in FW, for the safety to get HPD status, driver better to wait 200ms
> > before HPD detection after OS resume back.
> >
> > Signed-off-by: Xin Ji 
> > ---
> >  drivers/gpu/drm/bridge/analogix/anx7625.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > index 51abe42c639e..833d6d50a03d 100644
> > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > @@ -1464,6 +1464,9 @@ static int _anx7625_hpd_polling(struct
> anx7625_data *ctx,
> > if (ctx->pdata.intp_irq)
> > return 0;
> >
> > +   /* Delay 200ms for FW HPD de-bounce */
> > +   usleep_range(20, 201000);
> 
> If you need to sleep for 200 ms, maybe use msleep instead?
OK
> 
> BR,
> Jani.
> 
> > +
> > ret = readx_poll_timeout(anx7625_read_hpd_status_p0,
> >  ctx, val,
> >  ((val & HPD_STATUS) || (val < 0)),
> 
> --
> Jani Nikula, Intel


RE: [PATCH] drm/bridge: Add 200ms delay to wait FW HPD status stable

2023-09-22 Thread Xin Ji
Hi Laurent Pinchart, thanks for reviewing, I'll update the new patch, thanks!
Xin

> -Original Message-
> From: Laurent Pinchart 
> Sent: Thursday, September 21, 2023 8:13 PM
> To: Jani Nikula 
> Cc: Xin Ji ; Andrzej Hajda ;
> Neil Armstrong ; Robert Foss ;
> Jonas Karlman ; Jernej Skrabec ;
> David Airlie ; Daniel Vetter ; Qilin Wen
> ; linux-ker...@vger.kernel.org; dri-
> de...@lists.freedesktop.org; hsi...@chromium.org; Bernie Liang
> 
> Subject: Re: [PATCH] drm/bridge: Add 200ms delay to wait FW HPD status stable
> 
> CAUTION: This email originated from outside of the organization. Please do not
> click links or open attachments unless you recognize the sender, and know the
> content is safe.
> 
> 
> The subject line is missing the driver name.
> 
> On Thu, Sep 21, 2023 at 03:09:10PM +0300, Jani Nikula wrote:
> > On Thu, 21 Sep 2023, Xin Ji  wrote:
> > > For the none-interrupt design(sink device is panel, polling HPD
> 
> s/none-interrupt/no-interrupt/ ?
OK
> 
> s/design/design /
OK
> 
> > > status when chip power on), anx7625 FW has more than 200ms HPD
> > > de-bounce time in FW, for the safety to get HPD status, driver
> > > better to wait 200ms before HPD detection after OS resume back.
> > >
> > > Signed-off-by: Xin Ji 
> > > ---
> > >  drivers/gpu/drm/bridge/analogix/anx7625.c | 3 +++
> > >  1 file changed, 3 insertions(+)
> > >
> > > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > index 51abe42c639e..833d6d50a03d 100644
> > > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > @@ -1464,6 +1464,9 @@ static int _anx7625_hpd_polling(struct
> anx7625_data *ctx,
> > > if (ctx->pdata.intp_irq)
> > > return 0;
> > >
> > > +   /* Delay 200ms for FW HPD de-bounce */
> > > +   usleep_range(20, 201000);
> >
> > If you need to sleep for 200 ms, maybe use msleep instead?
> 
> fsleep() could be a nice replacement.
OK
> 
> > > +
> > > ret = readx_poll_timeout(anx7625_read_hpd_status_p0,
> > >  ctx, val,
> > >  ((val & HPD_STATUS) || (val < 0)),
> 
> --
> Regards,
> 
> Laurent Pinchart


[PATCH] drm/bridge: Add 200ms delay to wait FW HPD status stable

2023-09-21 Thread Xin Ji
For the none-interrupt design(sink device is panel, polling HPD
status when chip power on), anx7625 FW has more than 200ms HPD
de-bounce time in FW, for the safety to get HPD status, driver
better to wait 200ms before HPD detection after OS resume back.

Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 51abe42c639e..833d6d50a03d 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1464,6 +1464,9 @@ static int _anx7625_hpd_polling(struct anx7625_data *ctx,
if (ctx->pdata.intp_irq)
return 0;
 
+   /* Delay 200ms for FW HPD de-bounce */
+   usleep_range(20, 201000);
+
ret = readx_poll_timeout(anx7625_read_hpd_status_p0,
 ctx, val,
 ((val & HPD_STATUS) || (val < 0)),
-- 
2.25.1



[PATCH] drm/bridge: anx7625: keep last configure timing

2022-12-08 Thread Xin Ji
Sometimes kernel may resume back quickly after suspend,
and DRM not call .mode_set() to re-config
display timing before calling .atomic_enable(), bridge
driver with this patch to keep last configure timing.

Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index b0ff1ecb80a5..eb9116503b63 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1403,7 +1403,6 @@ static void anx7625_stop_dp_work(struct anx7625_data *ctx)
 {
ctx->hpd_status = 0;
ctx->hpd_high_cnt = 0;
-   ctx->display_timing_valid = 0;
 }
 
 static void anx7625_start_dp_work(struct anx7625_data *ctx)
-- 
2.25.1



Re: [PATCH] drm/bridge: anx7625: Set HPD irq detect window to 2ms

2022-09-05 Thread Xin Ji
On Mon, Sep 05, 2022 at 06:48:06PM +0200, Robert Foss wrote:
> Hi Xin,
> 
> On Sat, 3 Sept 2022 at 15:09, Xin Ji  wrote:
> >
> > Some panels trigger HPD irq due to noise, the HPD debounce
> > may be 1.8ms, exceeding the default irq detect window, ~1.4ms.
> > This patch set HPD irq detection window to 2ms to
> > tolerate the HPD noise.
> >
> > Signed-off-by: Xin Ji 
> > ---
> >  drivers/gpu/drm/bridge/analogix/anx7625.c | 14 ++
> >  drivers/gpu/drm/bridge/analogix/anx7625.h |  6 ++
> >  2 files changed, 20 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > index c74b5df4cade..0c323b5a1c99 100644
> > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > @@ -1440,6 +1440,20 @@ static void anx7625_start_dp_work(struct 
> > anx7625_data *ctx)
> >
> >  static int anx7625_read_hpd_status_p0(struct anx7625_data *ctx)
> >  {
> > +   int ret;
> > +
> > +   /* Set irq detect window to 2ms */
> > +   ret = anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
> > +   HPD_DET_TIMER_BIT0_7, HPD_TIME & 0xFF);
> > +   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
> > +HPD_DET_TIMER_BIT8_15,
> > +(HPD_TIME >> 8) & 0xFF);
> > +   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
> > +HPD_DET_TIMER_BIT16_23,
> > +(HPD_TIME >> 16) & 0xFF);
> 
> Does the HPD debounce timer register need to be written for every HPD
> status read?
Hi Robert Foss, yes, it is better to set it in every HPD status check, because 
the
HPD may be affected by noise, once the chip detect HPD is low, the timer
register will be automatically set to 1.4ms, so the driver better set it
in each check loop.

Thanks,
Xin
> 
> > +   if (ret < 0)
> > +   return ret;
> > +
> > return anx7625_reg_read(ctx, ctx->i2c.rx_p0_client, SYSTEM_STSTUS);
> >  }
> >
> > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h 
> > b/drivers/gpu/drm/bridge/analogix/anx7625.h
> > index e257a84db962..14f33d6be289 100644
> > --- a/drivers/gpu/drm/bridge/analogix/anx7625.h
> > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
> > @@ -132,6 +132,12 @@
> >  #define I2S_SLAVE_MODE 0x08
> >  #define AUDIO_LAYOUT   0x01
> >
> > +#define HPD_DET_TIMER_BIT0_7   0xea
> > +#define HPD_DET_TIMER_BIT8_15  0xeb
> > +#define HPD_DET_TIMER_BIT16_23 0xec
> > +/* HPD debounce time 2ms for 27M clock */
> > +#define HPD_TIME   54000
> > +
> >  #define AUDIO_CONTROL_REGISTER 0xe6
> >  #define TDM_TIMING_MODE 0x08
> >
> > --
> > 2.25.1
> >


[PATCH] drm/bridge: anx7625: Set HPD irq detect window to 2ms

2022-09-03 Thread Xin Ji
Some panels trigger HPD irq due to noise, the HPD debounce
may be 1.8ms, exceeding the default irq detect window, ~1.4ms.
This patch set HPD irq detection window to 2ms to
tolerate the HPD noise.

Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 14 ++
 drivers/gpu/drm/bridge/analogix/anx7625.h |  6 ++
 2 files changed, 20 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index c74b5df4cade..0c323b5a1c99 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1440,6 +1440,20 @@ static void anx7625_start_dp_work(struct anx7625_data 
*ctx)
 
 static int anx7625_read_hpd_status_p0(struct anx7625_data *ctx)
 {
+   int ret;
+
+   /* Set irq detect window to 2ms */
+   ret = anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
+   HPD_DET_TIMER_BIT0_7, HPD_TIME & 0xFF);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
+HPD_DET_TIMER_BIT8_15,
+(HPD_TIME >> 8) & 0xFF);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
+HPD_DET_TIMER_BIT16_23,
+(HPD_TIME >> 16) & 0xFF);
+   if (ret < 0)
+   return ret;
+
return anx7625_reg_read(ctx, ctx->i2c.rx_p0_client, SYSTEM_STSTUS);
 }
 
diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h 
b/drivers/gpu/drm/bridge/analogix/anx7625.h
index e257a84db962..14f33d6be289 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.h
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
@@ -132,6 +132,12 @@
 #define I2S_SLAVE_MODE 0x08
 #define AUDIO_LAYOUT   0x01
 
+#define HPD_DET_TIMER_BIT0_7   0xea
+#define HPD_DET_TIMER_BIT8_15  0xeb
+#define HPD_DET_TIMER_BIT16_23 0xec
+/* HPD debounce time 2ms for 27M clock */
+#define HPD_TIME   54000
+
 #define AUDIO_CONTROL_REGISTER 0xe6
 #define TDM_TIMING_MODE 0x08
 
-- 
2.25.1



[PATCH] drm/bridge: anx7625: Support HDMI_I2S audio format

2022-07-25 Thread Xin Ji
1. Support HDMI_I2S audio format.
2. Return 0 if there is no sink connection in .hw_param callback.

Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 23 +--
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 79fc7a50b497..c74b5df4cade 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1797,8 +1797,13 @@ static int anx7625_audio_hw_params(struct device *dev, 
void *data,
int wl, ch, rate;
int ret = 0;
 
-   if (fmt->fmt != HDMI_DSP_A) {
-   DRM_DEV_ERROR(dev, "only supports DSP_A\n");
+   if (anx7625_sink_detect(ctx) == connector_status_disconnected) {
+   DRM_DEV_DEBUG_DRIVER(dev, "DP not connected\n");
+   return 0;
+   }
+
+   if (fmt->fmt != HDMI_DSP_A && fmt->fmt != HDMI_I2S) {
+   DRM_DEV_ERROR(dev, "only supports DSP_A & I2S\n");
return -EINVAL;
}
 
@@ -1806,10 +1811,16 @@ static int anx7625_audio_hw_params(struct device *dev, 
void *data,
 params->sample_rate, params->sample_width,
 params->cea.channels);
 
-   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_6,
-   ~I2S_SLAVE_MODE,
-   TDM_SLAVE_MODE);
+   if (fmt->fmt == HDMI_DSP_A)
+   ret = anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+  AUDIO_CHANNEL_STATUS_6,
+  ~I2S_SLAVE_MODE,
+  TDM_SLAVE_MODE);
+   else
+   ret = anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+  AUDIO_CHANNEL_STATUS_6,
+  ~TDM_SLAVE_MODE,
+  I2S_SLAVE_MODE);
 
/* Word length */
switch (params->sample_width) {
-- 
2.25.1



Re: [PATCH 4/4] drm/bridge: anx7625: Add wait_hpd_asserted() callback

2022-07-05 Thread Xin Ji
Hi Hsin-Yi, thanks for your patch, it looks good to me.

Reviewed-by: Xin Ji 

Thanks,
Xin

On Thu, Jun 30, 2022 at 12:05:50AM +0800, Hsin-Yi Wang wrote:
> Move hpd polling check into wait_hpd_asserted() callback. For the cases
> that aux transfer function wasn't used, do hpd polling check after pm
> runtime resume, which will power on the bridge.
> 
> Signed-off-by: Hsin-Yi Wang 
> ---
>  drivers/gpu/drm/bridge/analogix/anx7625.c | 33 ++-
>  1 file changed, 27 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> b/drivers/gpu/drm/bridge/analogix/anx7625.c
> index 59ddeba33652b..ea5a0b86fe52a 100644
> --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> @@ -1443,23 +1443,24 @@ static int anx7625_read_hpd_status_p0(struct 
> anx7625_data *ctx)
>   return anx7625_reg_read(ctx, ctx->i2c.rx_p0_client, SYSTEM_STSTUS);
>  }
>  
> -static void anx7625_hpd_polling(struct anx7625_data *ctx)
> +static int _anx7625_hpd_polling(struct anx7625_data *ctx,
> +  unsigned long wait_us)
>  {
>   int ret, val;
>   struct device *dev = >client->dev;
>  
>   /* Interrupt mode, no need poll HPD status, just return */
>   if (ctx->pdata.intp_irq)
> - return;
> + return 0;
>  
>   ret = readx_poll_timeout(anx7625_read_hpd_status_p0,
>ctx, val,
>((val & HPD_STATUS) || (val < 0)),
> -  5000,
> -  5000 * 100);
> +  wait_us / 100,
> +  wait_us);
>   if (ret) {
>   DRM_DEV_ERROR(dev, "no hpd.\n");
> - return;
> + return ret;
>   }
>  
>   DRM_DEV_DEBUG_DRIVER(dev, "system status: 0x%x. HPD raise up.\n", val);
> @@ -1472,6 +1473,23 @@ static void anx7625_hpd_polling(struct anx7625_data 
> *ctx)
>  
>   if (!ctx->pdata.panel_bridge && ctx->bridge_attached)
>   drm_helper_hpd_irq_event(ctx->bridge.dev);
> +
> + return 0;
> +}
> +
> +static int anx7625_wait_hpd_asserted(struct drm_dp_aux *aux,
> +  unsigned long wait_us)
> +{
> + struct anx7625_data *ctx = container_of(aux, struct anx7625_data, aux);
> + struct device *dev = >client->dev;
> + int ret;
> +
> + pm_runtime_get_sync(dev);
> + ret = _anx7625_hpd_polling(ctx, wait_us);
> + pm_runtime_mark_last_busy(dev);
> + pm_runtime_put_autosuspend(dev);
> +
> + return ret;
>  }
>  
>  static void anx7625_remove_edid(struct anx7625_data *ctx)
> @@ -1741,6 +1759,7 @@ static struct edid *anx7625_get_edid(struct 
> anx7625_data *ctx)
>   }
>  
>   pm_runtime_get_sync(dev);
> + _anx7625_hpd_polling(ctx, 5000 * 100);
>   edid_num = sp_tx_edid_read(ctx, p_edid->edid_raw_data);
>   pm_runtime_put_sync(dev);
>  
> @@ -2378,6 +2397,7 @@ static void anx7625_bridge_atomic_enable(struct 
> drm_bridge *bridge,
>   ctx->connector = connector;
>  
>   pm_runtime_get_sync(dev);
> + _anx7625_hpd_polling(ctx, 5000 * 100);
>  
>   anx7625_dp_start(ctx);
>  }
> @@ -2497,7 +2517,6 @@ static int __maybe_unused 
> anx7625_runtime_pm_resume(struct device *dev)
>   mutex_lock(>lock);
>  
>   anx7625_power_on_init(ctx);
> - anx7625_hpd_polling(ctx);
>  
>   mutex_unlock(>lock);
>  
> @@ -2589,6 +2608,7 @@ static int anx7625_i2c_probe(struct i2c_client *client,
>   platform->aux.name = "anx7625-aux";
>   platform->aux.dev = dev;
>   platform->aux.transfer = anx7625_aux_transfer;
> + platform->aux.wait_hpd_asserted = anx7625_wait_hpd_asserted;
>   drm_dp_aux_init(>aux);
>  
>   if (anx7625_register_i2c_dummy_clients(platform, client) != 0) {
> @@ -2617,6 +2637,7 @@ static int anx7625_i2c_probe(struct i2c_client *client,
>   if (!platform->pdata.low_power_mode) {
>   anx7625_disable_pd_protocol(platform);
>   pm_runtime_get_sync(dev);
> + _anx7625_hpd_polling(platform, 5000 * 100);
>   }
>  
>   /* Add work function */
> -- 
> 2.37.0.rc0.161.g10f37bed90-goog


Re: [PATCH 3/4] drm/bridge: anx7625: Fix NULL pointer crash when using edp-panel

2022-07-05 Thread Xin Ji
Hi Hsin-Yi, thanks for your patch, it looks good to me.

Reviewed-by: Xin Ji 

Thanks,
Xin

On Thu, Jun 30, 2022 at 12:05:49AM +0800, Hsin-Yi Wang wrote:
> Move devm_of_dp_aux_populate_ep_devices() after pm runtime and i2c setup
> to avoid NULL pointer crash.
> 
> edp-panel probe (generic_edp_panel_probe) calls pm_runtime_get_sync() to
> read EDID. At this time, bridge should have pm runtime enabled and i2c
> clients ready.
> 
> Fixes: adca62ec370c ("drm/bridge: anx7625: Support reading edid through aux 
> channel")
> Signed-off-by: Hsin-Yi Wang 
> ---
>  drivers/gpu/drm/bridge/analogix/anx7625.c | 17 +
>  1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> b/drivers/gpu/drm/bridge/analogix/anx7625.c
> index 478f5af381c7d..59ddeba33652b 100644
> --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> @@ -2590,14 +2590,6 @@ static int anx7625_i2c_probe(struct i2c_client *client,
>   platform->aux.dev = dev;
>   platform->aux.transfer = anx7625_aux_transfer;
>   drm_dp_aux_init(>aux);
> - devm_of_dp_aux_populate_ep_devices(>aux);
> -
> - ret = anx7625_parse_dt(dev, pdata);
> - if (ret) {
> - if (ret != -EPROBE_DEFER)
> - DRM_DEV_ERROR(dev, "fail to parse DT : %d\n", ret);
> - goto free_wq;
> - }
>  
>   if (anx7625_register_i2c_dummy_clients(platform, client) != 0) {
>   ret = -ENOMEM;
> @@ -2613,6 +2605,15 @@ static int anx7625_i2c_probe(struct i2c_client *client,
>   if (ret)
>   goto free_wq;
>  
> + devm_of_dp_aux_populate_ep_devices(>aux);
> +
> + ret = anx7625_parse_dt(dev, pdata);
> + if (ret) {
> + if (ret != -EPROBE_DEFER)
> + DRM_DEV_ERROR(dev, "fail to parse DT : %d\n", ret);
> + goto free_wq;
> + }
> +
>   if (!platform->pdata.low_power_mode) {
>   anx7625_disable_pd_protocol(platform);
>   pm_runtime_get_sync(dev);
> -- 
> 2.37.0.rc0.161.g10f37bed90-goog


Re: [PATCH 2/4] drm/bridge: anx7625: Use pm_runtime_force_suspend(resume)

2022-07-05 Thread Xin Ji
Hi Hsin-Yi, thanks for your patch, looks good to me.

Reviewed-by: Xin Ji 

Thanks,
Xin
On Thu, Jun 30, 2022 at 12:05:48AM +0800, Hsin-Yi Wang wrote:
> There's no need to check for IRQ or disable it in suspend.
> 
> Use pm_runtime_force_suspend(resume) to make sure anx7625 is powered off
> correctly. Make the system suspend/resume and pm runtime suspend/resume
> more consistant.
> 
> Signed-off-by: Hsin-Yi Wang 
> ---
>  drivers/gpu/drm/bridge/analogix/anx7625.c | 33 ++-
>  1 file changed, 2 insertions(+), 31 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> b/drivers/gpu/drm/bridge/analogix/anx7625.c
> index f89e8151475f7..478f5af381c7d 100644
> --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> @@ -2504,38 +2504,9 @@ static int __maybe_unused 
> anx7625_runtime_pm_resume(struct device *dev)
>   return 0;
>  }
>  
> -static int __maybe_unused anx7625_resume(struct device *dev)
> -{
> - struct anx7625_data *ctx = dev_get_drvdata(dev);
> -
> - if (!ctx->pdata.intp_irq)
> - return 0;
> -
> - if (!pm_runtime_enabled(dev) || !pm_runtime_suspended(dev)) {
> - enable_irq(ctx->pdata.intp_irq);
> - anx7625_runtime_pm_resume(dev);
> - }
> -
> - return 0;
> -}
> -
> -static int __maybe_unused anx7625_suspend(struct device *dev)
> -{
> - struct anx7625_data *ctx = dev_get_drvdata(dev);
> -
> - if (!ctx->pdata.intp_irq)
> - return 0;
> -
> - if (!pm_runtime_enabled(dev) || !pm_runtime_suspended(dev)) {
> - anx7625_runtime_pm_suspend(dev);
> - disable_irq(ctx->pdata.intp_irq);
> - }
> -
> - return 0;
> -}
> -
>  static const struct dev_pm_ops anx7625_pm_ops = {
> - SET_SYSTEM_SLEEP_PM_OPS(anx7625_suspend, anx7625_resume)
> + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
> + pm_runtime_force_resume)
>   SET_RUNTIME_PM_OPS(anx7625_runtime_pm_suspend,
>  anx7625_runtime_pm_resume, NULL)
>  };
> -- 
> 2.37.0.rc0.161.g10f37bed90-goog


Re: [PATCH 1/4] drm/bridge: anx7625: Convert to devm_i2c_new_dummy_device()

2022-07-05 Thread Xin Ji
Hi Hsin-Yi, thanks for your patch, looks good to me.

Reviewed-by: Xin Ji 

On Thu, Jun 30, 2022 at 12:05:47AM +0800, Hsin-Yi Wang wrote:
> Simplify the resource management.
> 
> Signed-off-by: Hsin-Yi Wang 
> ---
>  drivers/gpu/drm/bridge/analogix/anx7625.c | 96 +++
>  1 file changed, 27 insertions(+), 69 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> b/drivers/gpu/drm/bridge/analogix/anx7625.c
> index 3710fa9ee0acd..f89e8151475f7 100644
> --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> @@ -2436,82 +2436,44 @@ static const struct drm_bridge_funcs 
> anx7625_bridge_funcs = {
>  static int anx7625_register_i2c_dummy_clients(struct anx7625_data *ctx,
> struct i2c_client *client)
>  {
> - int err = 0;
> + struct device *dev = >client->dev;
>  
> - ctx->i2c.tx_p0_client = i2c_new_dummy_device(client->adapter,
> -  TX_P0_ADDR >> 1);
> + ctx->i2c.tx_p0_client = devm_i2c_new_dummy_device(dev, client->adapter,
> + TX_P0_ADDR >> 1);
>   if (IS_ERR(ctx->i2c.tx_p0_client))
>   return PTR_ERR(ctx->i2c.tx_p0_client);
>  
> - ctx->i2c.tx_p1_client = i2c_new_dummy_device(client->adapter,
> -  TX_P1_ADDR >> 1);
> - if (IS_ERR(ctx->i2c.tx_p1_client)) {
> - err = PTR_ERR(ctx->i2c.tx_p1_client);
> - goto free_tx_p0;
> - }
> + ctx->i2c.tx_p1_client = devm_i2c_new_dummy_device(dev, client->adapter,
> + TX_P1_ADDR >> 1);
> + if (IS_ERR(ctx->i2c.tx_p1_client))
> + return PTR_ERR(ctx->i2c.tx_p1_client);
>  
> - ctx->i2c.tx_p2_client = i2c_new_dummy_device(client->adapter,
> -  TX_P2_ADDR >> 1);
> - if (IS_ERR(ctx->i2c.tx_p2_client)) {
> - err = PTR_ERR(ctx->i2c.tx_p2_client);
> - goto free_tx_p1;
> - }
> + ctx->i2c.tx_p2_client = devm_i2c_new_dummy_device(dev, client->adapter,
> + TX_P2_ADDR >> 1);
> + if (IS_ERR(ctx->i2c.tx_p2_client))
> + return PTR_ERR(ctx->i2c.tx_p2_client);
>  
> - ctx->i2c.rx_p0_client = i2c_new_dummy_device(client->adapter,
> -  RX_P0_ADDR >> 1);
> - if (IS_ERR(ctx->i2c.rx_p0_client)) {
> - err = PTR_ERR(ctx->i2c.rx_p0_client);
> - goto free_tx_p2;
> - }
> + ctx->i2c.rx_p0_client = devm_i2c_new_dummy_device(dev, client->adapter,
> + RX_P0_ADDR >> 1);
> + if (IS_ERR(ctx->i2c.rx_p0_client))
> + return PTR_ERR(ctx->i2c.rx_p0_client);
>  
> - ctx->i2c.rx_p1_client = i2c_new_dummy_device(client->adapter,
> -  RX_P1_ADDR >> 1);
> - if (IS_ERR(ctx->i2c.rx_p1_client)) {
> - err = PTR_ERR(ctx->i2c.rx_p1_client);
> - goto free_rx_p0;
> - }
> + ctx->i2c.rx_p1_client = devm_i2c_new_dummy_device(dev, client->adapter,
> + RX_P1_ADDR >> 1);
> + if (IS_ERR(ctx->i2c.rx_p1_client))
> + return PTR_ERR(ctx->i2c.rx_p1_client);
>  
> - ctx->i2c.rx_p2_client = i2c_new_dummy_device(client->adapter,
> -  RX_P2_ADDR >> 1);
> - if (IS_ERR(ctx->i2c.rx_p2_client)) {
> - err = PTR_ERR(ctx->i2c.rx_p2_client);
> - goto free_rx_p1;
> - }
> + ctx->i2c.rx_p2_client = devm_i2c_new_dummy_device(dev, client->adapter,
> + RX_P2_ADDR >> 1);
> + if (IS_ERR(ctx->i2c.rx_p2_client))
> + return PTR_ERR(ctx->i2c.rx_p2_client);
>  
> - ctx->i2c.tcpc_client = i2c_new_dummy_device(client->adapter,
> - TCPC_INTERFACE_ADDR >> 1);
> - if (IS_ERR(ctx->i2c.tcpc_client)) {
> - err = PTR_ERR(ctx->i2c.tcpc_client);
> - goto free_rx_p2;
> - }
> + ctx->i2c.tcpc_client = devm_i2c_new_dummy_device(dev, client->adapter,
> + TCPC_INTERFACE_ADDR >> 1);
> + if (IS_ERR(ctx->i2c.tcpc_client))
> + 

Re: [PATCH v2 4/4] drm/bridge: anx7625: Use DPI bus type

2022-05-22 Thread Xin Ji
On Sat, May 21, 2022 at 06:28:42PM +0200, Daniel Vetter wrote:
> On Sat, 21 May 2022 at 18:07, Daniel Vetter  wrote:
> >
> > On Tue, 17 May 2022 at 18:09, Robert Foss  wrote:
> > >
> > > On Mon, 25 Apr 2022 at 11:14, Xin Ji  wrote:
> > > >
> > > > On Mon, Apr 25, 2022 at 04:24:50PM +0800, Chen-Yu Tsai wrote:
> > > > > On Fri, Apr 22, 2022 at 10:13 PM Robert Foss  
> > > > > wrote:
> > > > > >
> > > > > > On Fri, 22 Apr 2022 at 16:01, Robert Foss  
> > > > > > wrote:
> > > > > > >
> > > > > > > On Fri, 22 Apr 2022 at 10:49, Xin Ji  
> > > > > > > wrote:
> > > > > > > >
> > > > > > > > As V4L2_FWNODE_BUS_TYPE_PARALLEL not properly descript for DPI
> > > > > > > > interface, this patch use new defined V4L2_FWNODE_BUS_TYPE_DPI 
> > > > > > > > for it.
> > > > > > > >
> > > > > > > > Fixes: fd0310b6fe7d ("drm/bridge: anx7625: add MIPI DPI input 
> > > > > > > > feature")
> > > > > > > > Signed-off-by: Xin Ji 
> > > > > > > > ---
> > > > > > > >  drivers/gpu/drm/bridge/analogix/anx7625.c | 8 
> > > > > > > >  1 file changed, 4 insertions(+), 4 deletions(-)
> > > > > > > >
> > > > > > > > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> > > > > > > > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > > > > > index 376da01243a3..71df977e8f53 100644
> > > > > > > > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > > > > > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > > > > > @@ -1623,14 +1623,14 @@ static int anx7625_parse_dt(struct 
> > > > > > > > device *dev,
> > > > > > > >
> > > > > > > > anx7625_get_swing_setting(dev, pdata);
> > > > > > > >
> > > > > > > > -   pdata->is_dpi = 1; /* default dpi mode */
> > > > > > > > +   pdata->is_dpi = 0; /* default dsi mode */
> > > > > > > > pdata->mipi_host_node = of_graph_get_remote_node(np, 0, 
> > > > > > > > 0);
> > > > > > > > if (!pdata->mipi_host_node) {
> > > > > > > > DRM_DEV_ERROR(dev, "fail to get internal 
> > > > > > > > panel.\n");
> > > > > > > > return -ENODEV;
> > > > > > > > }
> > > > > > > >
> > > > > > > > -   bus_type = V4L2_FWNODE_BUS_TYPE_PARALLEL;
> > > > > > > > +   bus_type = 0;
> > > > > > > > mipi_lanes = MAX_LANES_SUPPORT;
> > > > > > > > ep0 = of_graph_get_endpoint_by_regs(np, 0, 0);
> > > > > > > > if (ep0) {
> > > > > > > > @@ -1640,8 +1640,8 @@ static int anx7625_parse_dt(struct device 
> > > > > > > > *dev,
> > > > > > > > mipi_lanes = of_property_count_u32_elems(ep0, 
> > > > > > > > "data-lanes");
> > > > > > > > }
> > > > > > > >
> > > > > > > > -   if (bus_type == V4L2_FWNODE_BUS_TYPE_PARALLEL) /* bus 
> > > > > > > > type is Parallel(DSI) */
> > > > > > > > -   pdata->is_dpi = 0;
> > > > > > > > +   if (bus_type == V4L2_FWNODE_BUS_TYPE_DPI) /* bus type 
> > > > > > > > is DPI */
> > > > > > > > +   pdata->is_dpi = 1;
> > > > > > > >
> > > > > > > > pdata->mipi_lanes = mipi_lanes;
> > > > > > > > if (pdata->mipi_lanes > MAX_LANES_SUPPORT || 
> > > > > > > > pdata->mipi_lanes <= 0)
> > > > > > >
> > > > > > > Reviewed-by: Robert Foss 
> > > > > >
> > > > > > Acked-by: Robert Foss 
> > > > >
> > > > > Tested-by: Chen-Yu Tsai 
> > > > >
> > > > > Confirmed this fixes the display on

Re: [PATCH v2 4/4] drm/bridge: anx7625: Use DPI bus type

2022-04-25 Thread Xin Ji
On Mon, Apr 25, 2022 at 04:24:50PM +0800, Chen-Yu Tsai wrote:
> On Fri, Apr 22, 2022 at 10:13 PM Robert Foss  wrote:
> >
> > On Fri, 22 Apr 2022 at 16:01, Robert Foss  wrote:
> > >
> > > On Fri, 22 Apr 2022 at 10:49, Xin Ji  wrote:
> > > >
> > > > As V4L2_FWNODE_BUS_TYPE_PARALLEL not properly descript for DPI
> > > > interface, this patch use new defined V4L2_FWNODE_BUS_TYPE_DPI for it.
> > > >
> > > > Fixes: fd0310b6fe7d ("drm/bridge: anx7625: add MIPI DPI input feature")
> > > > Signed-off-by: Xin Ji 
> > > > ---
> > > >  drivers/gpu/drm/bridge/analogix/anx7625.c | 8 
> > > >  1 file changed, 4 insertions(+), 4 deletions(-)
> > > >
> > > > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> > > > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > index 376da01243a3..71df977e8f53 100644
> > > > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > @@ -1623,14 +1623,14 @@ static int anx7625_parse_dt(struct device *dev,
> > > >
> > > > anx7625_get_swing_setting(dev, pdata);
> > > >
> > > > -   pdata->is_dpi = 1; /* default dpi mode */
> > > > +   pdata->is_dpi = 0; /* default dsi mode */
> > > > pdata->mipi_host_node = of_graph_get_remote_node(np, 0, 0);
> > > > if (!pdata->mipi_host_node) {
> > > > DRM_DEV_ERROR(dev, "fail to get internal panel.\n");
> > > > return -ENODEV;
> > > > }
> > > >
> > > > -   bus_type = V4L2_FWNODE_BUS_TYPE_PARALLEL;
> > > > +   bus_type = 0;
> > > > mipi_lanes = MAX_LANES_SUPPORT;
> > > > ep0 = of_graph_get_endpoint_by_regs(np, 0, 0);
> > > > if (ep0) {
> > > > @@ -1640,8 +1640,8 @@ static int anx7625_parse_dt(struct device *dev,
> > > > mipi_lanes = of_property_count_u32_elems(ep0, 
> > > > "data-lanes");
> > > > }
> > > >
> > > > -   if (bus_type == V4L2_FWNODE_BUS_TYPE_PARALLEL) /* bus type is 
> > > > Parallel(DSI) */
> > > > -   pdata->is_dpi = 0;
> > > > +   if (bus_type == V4L2_FWNODE_BUS_TYPE_DPI) /* bus type is DPI */
> > > > +   pdata->is_dpi = 1;
> > > >
> > > > pdata->mipi_lanes = mipi_lanes;
> > > > if (pdata->mipi_lanes > MAX_LANES_SUPPORT || pdata->mipi_lanes 
> > > > <= 0)
> > >
> > > Reviewed-by: Robert Foss 
> >
> > Acked-by: Robert Foss 
> 
> Tested-by: Chen-Yu Tsai 
> 
> Confirmed this fixes the display on Juniper (Acer Chromebook Spin 311) on
> mainline (next-20220422).
> 
> Xin, in the future, please send the whole series to all recipients of
> all patches listed by get_maintainers.pl, not just the recipients of
> each patch. In the case of this series, they should have been sent
> to all of the mailing lists (media, devicetree, dri-devel) so that
> everyone has the same, full view of the patches.
Hi ChenYu, OK, I'll send to all media, devicetree, dri-devel next time.
Thanks,
Xin
> 
> ChenYu


[PATCH v2 4/4] drm/bridge: anx7625: Use DPI bus type

2022-04-22 Thread Xin Ji
As V4L2_FWNODE_BUS_TYPE_PARALLEL not properly descript for DPI
interface, this patch use new defined V4L2_FWNODE_BUS_TYPE_DPI for it.

Fixes: fd0310b6fe7d ("drm/bridge: anx7625: add MIPI DPI input feature")
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 376da01243a3..71df977e8f53 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1623,14 +1623,14 @@ static int anx7625_parse_dt(struct device *dev,
 
anx7625_get_swing_setting(dev, pdata);
 
-   pdata->is_dpi = 1; /* default dpi mode */
+   pdata->is_dpi = 0; /* default dsi mode */
pdata->mipi_host_node = of_graph_get_remote_node(np, 0, 0);
if (!pdata->mipi_host_node) {
DRM_DEV_ERROR(dev, "fail to get internal panel.\n");
return -ENODEV;
}
 
-   bus_type = V4L2_FWNODE_BUS_TYPE_PARALLEL;
+   bus_type = 0;
mipi_lanes = MAX_LANES_SUPPORT;
ep0 = of_graph_get_endpoint_by_regs(np, 0, 0);
if (ep0) {
@@ -1640,8 +1640,8 @@ static int anx7625_parse_dt(struct device *dev,
mipi_lanes = of_property_count_u32_elems(ep0, "data-lanes");
}
 
-   if (bus_type == V4L2_FWNODE_BUS_TYPE_PARALLEL) /* bus type is 
Parallel(DSI) */
-   pdata->is_dpi = 0;
+   if (bus_type == V4L2_FWNODE_BUS_TYPE_DPI) /* bus type is DPI */
+   pdata->is_dpi = 1;
 
pdata->mipi_lanes = mipi_lanes;
if (pdata->mipi_lanes > MAX_LANES_SUPPORT || pdata->mipi_lanes <= 0)
-- 
2.25.1



[PATCH v2 3/4] dt-bindings:drm/bridge:anx7625: add port@0 property

2022-04-22 Thread Xin Ji
Add 'bus-type' and 'data-lanes' define, bus-type 7 for MIPI DPI
input, others for DSI input.

Signed-off-by: Xin Ji 

---
V1 -> V2: rebase on the latest code.
---
 .../display/bridge/analogix,anx7625.yaml  | 19 ++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git 
a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml 
b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
index 35a48515836e..4590186c4a0b 100644
--- a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
+++ b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
@@ -94,7 +94,22 @@ properties:
 $ref: /schemas/graph.yaml#/$defs/port-base
 unevaluatedProperties: false
 description:
-  Video port for MIPI DSI input.
+  MIPI DSI/DPI input.
+
+properties:
+  endpoint:
+$ref: /schemas/media/video-interfaces.yaml#
+type: object
+additionalProperties: false
+
+properties:
+  remote-endpoint: true
+
+  bus-type:
+enum: [7]
+default: 1
+
+  data-lanes: true
 
   port@1:
 $ref: /schemas/graph.yaml#/properties/port
@@ -143,6 +158,8 @@ examples:
 reg = <0>;
 anx7625_in: endpoint {
 remote-endpoint = <_dsi>;
+bus-type = <7>;
+data-lanes = <0 1 2 3>;
 };
 };
 
-- 
2.25.1



Re: [PATCH 3/4] dt-bindings: drm/bridge: anx7625: Change bus-type to 7 (DPI)

2022-04-22 Thread Xin Ji
On Mon, Apr 18, 2022 at 02:31:38PM +0800, Chen-Yu Tsai wrote:
> Hi,
> 
> On Thu, Apr 14, 2022 at 10:27 AM Xin Ji  wrote:
> >
> > On Wed, Apr 13, 2022 at 04:28:51PM +0200, Robert Foss wrote:
> > > On Sat, 9 Apr 2022 at 06:47, Xin Ji  wrote:
> > > >
> > > > On Mon, Apr 04, 2022 at 12:52:14PM -0500, Rob Herring wrote:
> > > > > On Mon, Mar 28, 2022 at 08:09:54PM +0800, Xin Ji wrote:
> > > > > > Change bus-type define for DPI.
> > > > > >
> > > > > > Fixes: a43661e7e819 ("dt-bindings:drm/bridge:anx7625:add vendor 
> > > > > > define")
> > > > > >
> > > > > > Signed-off-by: Xin Ji 
> > > > > > ---
> > > > > >  .../devicetree/bindings/display/bridge/analogix,anx7625.yaml  | 4 
> > > > > > ++--
> > > > > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > > > > >
> > > > > > diff --git 
> > > > > > a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> > > > > >  
> > > > > > b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> > > > > > index 0d38d6fe3983..4590186c4a0b 100644
> > > > > > --- 
> > > > > > a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> > > > > > +++ 
> > > > > > b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> > > > > > @@ -106,7 +106,7 @@ properties:
> > > > > >remote-endpoint: true
> > > > > >
> > > > > >bus-type:
> > > > > > -enum: [1, 5]
> > > > > > +enum: [7]
> > > > >
> > > > > Changing is an ABI break, but didn't we revert adding this?
> > > > Hi Rob, sorry, what do you mean about ABI break? Do I need remove this
> > > > patch in this serial? Or do I need revert patch
> > > > https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.freedesktop.org%2Fpatch%2F462331%2Fdata=04%7C01%7Cxji%40analogixsemi.com%7C7d3089c9ec10458a4ea208da21051e7b%7Cb099b0b4f26c4cf59a0fd5be9acab205%7C0%7C0%7C637858603556318586%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000sdata=YMjW9RnMbbIiUA7dVCitqo9P2Axr2MxPCxxUK3W6pII%3Dreserved=0,
> > > >  I don't know how to do
> > > > it.
> > > >
> > >
> > > I contributed to the confusion about this, let's see if we can clear it 
> > > up.
> > >
> > > An issue was found related to which enum values were used to represent
> > > what late in the last release cycle. As a result a revert[1] patch for
> > > everything touching bus-type in anx7625 was merged.
> > >
> > > This patch, does not apply to drm-misc-next due to the revert, and if
> > > Xin Ji rebases his work on the drm-misc-next there should be no
> > > ABI-change as this patch when fixed up will introduce bus-type to the
> > > nax7625 ABI.
> > >
> > > Xin: Does this make sense to you?
> > Hi Robert Foss, yes, my work is based on drm-misc-next, all I can do,
> > just make a fix up patch(this patch) to change the bus-type define.
> 
> The revert was applied to the soc tree and merged into Linus's tree
> in v5.17-rc8. It was not present in drm-misc-next until April 5 with
> commit 9cbbd694a58b ("Merge drm/drm-next into drm-misc-next").
> 
> So please fetch the latest drm-misc-next, rebase your patches on top, and
> resend.
Hi ChenYu, OK, I'll resend this patch serial.
Thanks,
Xin
> 
> 
> Thanks
> ChenYu


Re: [PATCH] drm/bridge: anx7625: Fill in empty ELD when no connector

2022-04-18 Thread Xin Ji
On Thu, Apr 14, 2022 at 05:00:04PM +0800, Hsin-Yi Wang wrote:
> Speaker may share I2S with DP and .get_eld callback will be called when
> speaker is playing. When HDMI wans't connected, the connector will be
> null. Instead of return an error, fill in empty ELD.
> 
> Signed-off-by: Hsin-Yi Wang 
> ---
>  drivers/gpu/drm/bridge/analogix/anx7625.c | 12 ++--
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> b/drivers/gpu/drm/bridge/analogix/anx7625.c
> index 6516f9570b86..f2bc30c98c77 100644
> --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> @@ -1932,14 +1932,14 @@ static int anx7625_audio_get_eld(struct device *dev, 
> void *data,
>   struct anx7625_data *ctx = dev_get_drvdata(dev);
>  
>   if (!ctx->connector) {
> - dev_err(dev, "connector not initial\n");
> - return -EINVAL;
> + /* Pass en empty ELD if connector not available */
> + memset(buf, 0, len);
> + } else {
> + dev_dbg(dev, "audio copy eld\n");
> + memcpy(buf, ctx->connector->eld,
> +min(sizeof(ctx->connector->eld), len));
>   }
>  
> - dev_dbg(dev, "audio copy eld\n");
> - memcpy(buf, ctx->connector->eld,
> -min(sizeof(ctx->connector->eld), len));
> -
>   return 0;
Hi Hsin-Yi, it's OK for me.
Reviewed-by: Xin Ji 

Thanks,
Xin
>  }
>  
> -- 
> 2.35.1.1178.g4f1659d476-goog


Re: [PATCH 3/4] dt-bindings: drm/bridge: anx7625: Change bus-type to 7 (DPI)

2022-04-13 Thread Xin Ji
On Wed, Apr 13, 2022 at 04:28:51PM +0200, Robert Foss wrote:
> On Sat, 9 Apr 2022 at 06:47, Xin Ji  wrote:
> >
> > On Mon, Apr 04, 2022 at 12:52:14PM -0500, Rob Herring wrote:
> > > On Mon, Mar 28, 2022 at 08:09:54PM +0800, Xin Ji wrote:
> > > > Change bus-type define for DPI.
> > > >
> > > > Fixes: a43661e7e819 ("dt-bindings:drm/bridge:anx7625:add vendor define")
> > > >
> > > > Signed-off-by: Xin Ji 
> > > > ---
> > > >  .../devicetree/bindings/display/bridge/analogix,anx7625.yaml  | 4 ++--
> > > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git 
> > > > a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> > > >  
> > > > b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> > > > index 0d38d6fe3983..4590186c4a0b 100644
> > > > --- 
> > > > a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> > > > +++ 
> > > > b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> > > > @@ -106,7 +106,7 @@ properties:
> > > >remote-endpoint: true
> > > >
> > > >bus-type:
> > > > -enum: [1, 5]
> > > > +enum: [7]
> > >
> > > Changing is an ABI break, but didn't we revert adding this?
> > Hi Rob, sorry, what do you mean about ABI break? Do I need remove this
> > patch in this serial? Or do I need revert patch
> > https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.freedesktop.org%2Fpatch%2F462331%2Fdata=04%7C01%7Cxji%40analogixsemi.com%7C10f5b0213f434592936008da1d59f566%7Cb099b0b4f26c4cf59a0fd5be9acab205%7C0%7C0%7C637854569490105386%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000sdata=vK0Vmb9S425kHZc1WurfnNhnoXDMbUGkkdY1PVnfS9g%3Dreserved=0,
> >  I don't know how to do
> > it.
> >
> 
> I contributed to the confusion about this, let's see if we can clear it up.
> 
> An issue was found related to which enum values were used to represent
> what late in the last release cycle. As a result a revert[1] patch for
> everything touching bus-type in anx7625 was merged.
> 
> This patch, does not apply to drm-misc-next due to the revert, and if
> Xin Ji rebases his work on the drm-misc-next there should be no
> ABI-change as this patch when fixed up will introduce bus-type to the
> nax7625 ABI.
> 
> Xin: Does this make sense to you?
Hi Robert Foss, yes, my work is based on drm-misc-next, all I can do,
just make a fix up patch(this patch) to change the bus-type define.

Thanks,
Xin
> 
> [1] 
> https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcgit.freedesktop.org%2Fdrm%2Fdrm-misc%2Fcommit%2F%3Fid%3D979452fbc43028675b5a5da156f91928b739dea8data=04%7C01%7Cxji%40analogixsemi.com%7C10f5b0213f434592936008da1d59f566%7Cb099b0b4f26c4cf59a0fd5be9acab205%7C0%7C0%7C637854569490105386%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000sdata=onmKAoEEP1XDbl%2FaeAIfVYJ4cSbiTfTBYCd%2BHCA9fzw%3Dreserved=0


Re: [PATCH 3/4] dt-bindings: drm/bridge: anx7625: Change bus-type to 7 (DPI)

2022-04-08 Thread Xin Ji
On Mon, Apr 04, 2022 at 12:52:14PM -0500, Rob Herring wrote:
> On Mon, Mar 28, 2022 at 08:09:54PM +0800, Xin Ji wrote:
> > Change bus-type define for DPI.
> > 
> > Fixes: a43661e7e819 ("dt-bindings:drm/bridge:anx7625:add vendor define")
> > 
> > Signed-off-by: Xin Ji 
> > ---
> >  .../devicetree/bindings/display/bridge/analogix,anx7625.yaml  | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git 
> > a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml 
> > b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> > index 0d38d6fe3983..4590186c4a0b 100644
> > --- a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> > +++ b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> > @@ -106,7 +106,7 @@ properties:
> >remote-endpoint: true
> >  
> >bus-type:
> > -enum: [1, 5]
> > +enum: [7]
> 
> Changing is an ABI break, but didn't we revert adding this?
Hi Rob, sorry, what do you mean about ABI break? Do I need remove this
patch in this serial? Or do I need revert patch
https://patchwork.freedesktop.org/patch/462331/, I don't know how to do
it.

Thanks,
Xin
> 
> >  default: 1
> >  
> >data-lanes: true
> > @@ -158,7 +158,7 @@ examples:
> >  reg = <0>;
> >  anx7625_in: endpoint {
> >  remote-endpoint = <_dsi>;
> > -bus-type = <5>;
> > +bus-type = <7>;
> >  data-lanes = <0 1 2 3>;
> >  };
> >  };
> > -- 
> > 2.25.1
> > 
> > 


[PATCH 4/4] drm/bridge: anx7625: Use DPI bus type

2022-03-28 Thread Xin Ji
As V4L2_FWNODE_BUS_TYPE_PARALLEL not properly descript for DPI
interface, this patch use new defined V4L2_FWNODE_BUS_TYPE_DPI for it.

Fixes: fd0310b6fe7d ("drm/bridge: anx7625: add MIPI DPI input feature")
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 9a2a19ad4202..c528fa2c9533 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1615,14 +1615,14 @@ static int anx7625_parse_dt(struct device *dev,
 
anx7625_get_swing_setting(dev, pdata);
 
-   pdata->is_dpi = 1; /* default dpi mode */
+   pdata->is_dpi = 0; /* default dsi mode */
pdata->mipi_host_node = of_graph_get_remote_node(np, 0, 0);
if (!pdata->mipi_host_node) {
DRM_DEV_ERROR(dev, "fail to get internal panel.\n");
return -ENODEV;
}
 
-   bus_type = V4L2_FWNODE_BUS_TYPE_PARALLEL;
+   bus_type = 0;
mipi_lanes = MAX_LANES_SUPPORT;
ep0 = of_graph_get_endpoint_by_regs(np, 0, 0);
if (ep0) {
@@ -1632,8 +1632,8 @@ static int anx7625_parse_dt(struct device *dev,
mipi_lanes = of_property_count_u32_elems(ep0, "data-lanes");
}
 
-   if (bus_type == V4L2_FWNODE_BUS_TYPE_PARALLEL) /* bus type is 
Parallel(DSI) */
-   pdata->is_dpi = 0;
+   if (bus_type == V4L2_FWNODE_BUS_TYPE_DPI) /* bus type is DPI */
+   pdata->is_dpi = 1;
 
pdata->mipi_lanes = mipi_lanes;
if (pdata->mipi_lanes > MAX_LANES_SUPPORT || pdata->mipi_lanes <= 0)
-- 
2.25.1



[PATCH 3/4] dt-bindings: drm/bridge: anx7625: Change bus-type to 7 (DPI)

2022-03-28 Thread Xin Ji
Change bus-type define for DPI.

Fixes: a43661e7e819 ("dt-bindings:drm/bridge:anx7625:add vendor define")

Signed-off-by: Xin Ji 
---
 .../devicetree/bindings/display/bridge/analogix,anx7625.yaml  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml 
b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
index 0d38d6fe3983..4590186c4a0b 100644
--- a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
+++ b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
@@ -106,7 +106,7 @@ properties:
   remote-endpoint: true
 
   bus-type:
-enum: [1, 5]
+enum: [7]
 default: 1
 
   data-lanes: true
@@ -158,7 +158,7 @@ examples:
 reg = <0>;
 anx7625_in: endpoint {
 remote-endpoint = <_dsi>;
-bus-type = <5>;
+bus-type = <7>;
 data-lanes = <0 1 2 3>;
 };
 };
-- 
2.25.1



Re: [PATCH v12 3/4] drm/bridge: anx7625: add MIPI DPI input feature

2022-03-28 Thread Xin Ji
On Mon, Mar 28, 2022 at 11:54:12AM +0200, Robert Foss wrote:
> > > > > > > -   DRM_DEV_DEBUG_DRIVER(dev, "found dsi host node.\n");
> > > > > > > +   bus_type = V4L2_FWNODE_BUS_TYPE_PARALLEL;
> > > > > > > +   mipi_lanes = MAX_LANES_SUPPORT;
> > > > > > > +   ep0 = of_graph_get_endpoint_by_regs(np, 0, 0);
> > > > > > > +   if (ep0) {
> > > > > > > +   if (of_property_read_u32(ep0, "bus-type", _type))
> > > > > > > +   bus_type = 0;
> > > > > > > +
> > > > > > > +   mipi_lanes = of_property_count_u32_elems(ep0, 
> > > > > > > "data-lanes");
> > > > > > > +   }
> > > > > > > +
> > > > > > > +   if (bus_type == V4L2_FWNODE_BUS_TYPE_PARALLEL) /* bus type is 
> > > > > > > Parallel(DSI) */
> > > > > >
> > > > > > This is not correct *at all*. V4L2_FWNODE_BUS_TYPE_PARALLEL has 
> > > > > > nothing
> > > > > > to do with DSI. DSI stands for Digital *Serial* Interface. If 
> > > > > > anything,
> > > > > > the V4L2_FWNODE_BUS_TYPE_PARALLEL type would map better to DPI, 
> > > > > > even if
> > > > > > it's not an exact match.
> > > > > >
> > > > > > This patch has landed in v5.17-rc1, along with the corresponding
> > > > > > bindings. As DT bindings are an ABI, we should really fix this 
> > > > > > before
> > > > > > v5.17 is released. There is no DSI bus types defined in DT, and 
> > > > > > adding
> > > > > > one as a fix so late in the v5.17-rc cycle seems a bit of a stretch 
> > > > > > to
> > > > > > me (unless Rob disagrees).
> > > > > >
> > > > > > It would seem best to revert this series and the corresponding 
> > > > > > bindings,
> > > > > > and retry in v5.18.
> > > > >
> > > > > There is a DT patch using this property that is already queued up for 
> > > > > 5.17
> > > > > in the soc tree:
> > > > >
> > > > > https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2F20220214200507.2500693-1-nfraprado%40collabora.com%2Fdata=04%7C01%7Cxji%40analogixsemi.com%7C450c5609d8c24e9a34fa08da10a0f126%7Cb099b0b4f26c4cf59a0fd5be9acab205%7C0%7C0%7C637840580680816692%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000sdata=bARYbwXq6IJGxn3UBp%2F75lZhoTpzmZkTQsN0yvs7Cgg%3Dreserved=0
> > > > >
> > > > > merged here:
> > > > >
> > > > > https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fgit.kernel.org%2Fsoc%2Fsoc%2Fc%2F32568ae37596b529628ac09b875f4874e614f63fdata=04%7C01%7Cxji%40analogixsemi.com%7C450c5609d8c24e9a34fa08da10a0f126%7Cb099b0b4f26c4cf59a0fd5be9acab205%7C0%7C0%7C637840580680816692%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000sdata=lt3Tp8DveE1RJ%2F1MqDzYdKtHDxIyqhBbur%2Fm4N432AI%3Dreserved=0
> > > > >
> > > > > We will need to revert that one as well.
> > > >
> > > > I just submitted a series reverting the dt-binding change + the
> > > > related commit to "mt8183: jacuzzi".
> > > > Can I get a quick r-b/a-b in order to get this into v5.17.
> > > >
> > > > https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2F20220307154558.2505734-3-robert.foss%40linaro.org%2Fdata=04%7C01%7Cxji%40analogixsemi.com%7C450c5609d8c24e9a34fa08da10a0f126%7Cb099b0b4f26c4cf59a0fd5be9acab205%7C0%7C0%7C637840580680816692%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000sdata=dgA%2BrQ3KBMPLoR5bwL5Wt2Vs6EuNy%2Fh9yfOftxeUXjM%3Dreserved=0
> > > >
> > >
> > > v2 of revert submitted.
> > >
> > > https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2F20220308094911.2680291-1-robert.foss%40linaro.org%2Fdata=04%7C01%7Cxji%40analogixsemi.com%7C450c5609d8c24e9a34fa08da10a0f126%7Cb099b0b4f26c4cf59a0fd5be9acab205%7C0%7C0%7C637840580680816692%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000sdata=vIcCvXrwZs8XhXuoQ8On7vB9%2Bwrsov1DD5UBX%2B1G93Q%3Dreserved=0
> > >
> > > Xin: Will you spin a series that adds DPI support and re-enables DPI
> > > for anx7625? Additionally, "mt8183: jacuzzi" will have to have DPI
> > > re-enabled.
> > Hi Robert Foss, I'm little confused, do I need resend this serial or
> > send a patch based on currently define(V4L2_FWNODE_BUS_TYPE_PARALLEL)?
> >
> > And use V4L2_FWNODE_BUS_TYPE_PARALLEL for DPI, other value for DSI
> > setup?
> 
> V4L2_FWNODE_BUS_TYPE_PARALLEL is not meant to be used for DPI, but
> rather is used to represtent CPI. So another enum (something along the
> lines of V4L2_FWNODE_BUS_TYPE_DPI) needs to be defined, and then this
> series needs to use this new enum.
> 
> I'd like to see the following:
>  - Introduction of V4L2_FWNODE_BUS_TYPE_DPI
>  - Reworking this series to use V4L2_FWNODE_BUS_TYPE_DPI
>  - Reworking "mt8183: jacuzzi" to use V4L2_FWNODE_BUS_TYPE_DPI
> 
> Does that make sense?
Hi Rob, OK, I'll prepare the patch for review.
Thanks,
Xin
> 
> 
> Rob.


Re: [PATCH v2] drm/bridge: anx7625: Set downstream sink into normal status

2022-03-25 Thread Xin Ji
On Thu, Mar 24, 2022 at 01:07:56PM +0100, Robert Foss wrote:
> > > > > The driver uses DRM_DEV_* for logs. Can we use this?
> > > > Hi Hsin-Yi, as comment in drm/drm_print.h:
> > > > "NOTE: this is deprecated in favor of drm_dbg". DRM bridge driver not
> > > > use DRM_DEV_* any more. I'll send a patch to replace all of DRM_DEV_*
> > > > later.
> > >
> > > drm_dbg is better than dev_dbg though. With the former, you still get the
> > > option to control it with the drm.debug module parameter, unlike the 
> > > latter
> > > which normally gets compiled out.
> > >
> > > Please use drm_dbg*.
> > >
> > > ChenYu
> >
> > Hi ChenYu, the parameter of drm_dbg is "drm", if use drm_dbg, it will
> > change more code, I'll consider to upstream new patch to replace all of
> > them later.
> >
> 
> Alright, since the driver already uses these logging functions, let's
> apply this patch and fix the logging function this driver uses in a
> separate series.
> 
> Xin: Can you submit a patch/series that converts this driver to use
> drm_dbg* functions instead?
Hi Robert Foss, OK, I'll submit patch after this patch get merged.
Thanks,
Xin


Re: [PATCH v2] drm/bridge: anx7625: Set downstream sink into normal status

2022-03-22 Thread Xin Ji
On Tue, Mar 22, 2022 at 05:16:43PM +0800, Chen-Yu Tsai wrote:
> On Tue, Mar 22, 2022 at 4:52 PM Xin Ji  wrote:
> >
> > On Tue, Mar 22, 2022 at 04:43:20PM +0800, Hsin-Yi Wang wrote:
> > > On Tue, Mar 22, 2022 at 4:02 PM Xin Ji  wrote:
> > > >
> > > > As downstream sink was set into standby mode while bridge disabled,
> > > > this patch used for setting downstream sink into normal status
> > > > while enable bridge.
> > > >
> > > > Signed-off-by: Xin Ji 
> > > > Reviewed-by: Pin-Yen Lin 
> > > >
> > > > ---
> > > > V1 -> V2: use dev_dbg replace of dev_info
> > > > ---
> > > >  drivers/gpu/drm/bridge/analogix/anx7625.c | 8 
> > > >  1 file changed, 8 insertions(+)
> > > >
> > > > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> > > > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > index 9a2a19ad4202..dcf3275a00fe 100644
> > > > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > @@ -924,12 +924,20 @@ static void anx7625_dp_start(struct anx7625_data 
> > > > *ctx)
> > > >  {
> > > > int ret;
> > > > struct device *dev = >client->dev;
> > > > +   u8 data;
> > > >
> > > > if (!ctx->display_timing_valid) {
> > > > DRM_DEV_ERROR(dev, "mipi not set display timing 
> > > > yet.\n");
> > > > return;
> > > > }
> > > >
> > > > +   dev_dbg(dev, "set downstream sink into normal\n");
> > > > +   /* Downstream sink enter into normal mode */
> > > > +   data = 1;
> > > > +   ret = anx7625_aux_trans(ctx, DP_AUX_NATIVE_WRITE, 0x000600, 1, 
> > > > );
> > > > +   if (ret < 0)
> > > > +   dev_err(dev, "IO error : set sink into normal mode 
> > > > fail\n");
> > > > +
> > >
> > > The driver uses DRM_DEV_* for logs. Can we use this?
> > Hi Hsin-Yi, as comment in drm/drm_print.h:
> > "NOTE: this is deprecated in favor of drm_dbg". DRM bridge driver not
> > use DRM_DEV_* any more. I'll send a patch to replace all of DRM_DEV_*
> > later.
> 
> drm_dbg is better than dev_dbg though. With the former, you still get the
> option to control it with the drm.debug module parameter, unlike the latter
> which normally gets compiled out.
> 
> Please use drm_dbg*.
> 
> ChenYu

Hi ChenYu, the parameter of drm_dbg is "drm", if use drm_dbg, it will
change more code, I'll consider to upstream new patch to replace all of
them later.

Thanks,
Xin
> 
> > Thanks,
> > Xin
> > >
> > > > /* Disable HDCP */
> > > > anx7625_write_and(ctx, ctx->i2c.rx_p1_client, 0xee, 0x9f);
> > > >
> > > > --
> > > > 2.25.1
> > > >


Re: [PATCH v2] drm/bridge: anx7625: Set downstream sink into normal status

2022-03-22 Thread Xin Ji
On Tue, Mar 22, 2022 at 04:43:20PM +0800, Hsin-Yi Wang wrote:
> On Tue, Mar 22, 2022 at 4:02 PM Xin Ji  wrote:
> >
> > As downstream sink was set into standby mode while bridge disabled,
> > this patch used for setting downstream sink into normal status
> > while enable bridge.
> >
> > Signed-off-by: Xin Ji 
> > Reviewed-by: Pin-Yen Lin 
> >
> > ---
> > V1 -> V2: use dev_dbg replace of dev_info
> > ---
> >  drivers/gpu/drm/bridge/analogix/anx7625.c | 8 
> >  1 file changed, 8 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > index 9a2a19ad4202..dcf3275a00fe 100644
> > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > @@ -924,12 +924,20 @@ static void anx7625_dp_start(struct anx7625_data *ctx)
> >  {
> > int ret;
> > struct device *dev = >client->dev;
> > +   u8 data;
> >
> > if (!ctx->display_timing_valid) {
> > DRM_DEV_ERROR(dev, "mipi not set display timing yet.\n");
> > return;
> > }
> >
> > +   dev_dbg(dev, "set downstream sink into normal\n");
> > +   /* Downstream sink enter into normal mode */
> > +   data = 1;
> > +   ret = anx7625_aux_trans(ctx, DP_AUX_NATIVE_WRITE, 0x000600, 1, 
> > );
> > +   if (ret < 0)
> > +   dev_err(dev, "IO error : set sink into normal mode fail\n");
> > +
> 
> The driver uses DRM_DEV_* for logs. Can we use this?
Hi Hsin-Yi, as comment in drm/drm_print.h:
"NOTE: this is deprecated in favor of drm_dbg". DRM bridge driver not
use DRM_DEV_* any more. I'll send a patch to replace all of DRM_DEV_*
later.

Thanks,
Xin
> 
> > /* Disable HDCP */
> > anx7625_write_and(ctx, ctx->i2c.rx_p1_client, 0xee, 0x9f);
> >
> > --
> > 2.25.1
> >


[PATCH v2] drm/bridge: anx7625: Set downstream sink into normal status

2022-03-22 Thread Xin Ji
As downstream sink was set into standby mode while bridge disabled,
this patch used for setting downstream sink into normal status
while enable bridge.

Signed-off-by: Xin Ji 
Reviewed-by: Pin-Yen Lin 

---
V1 -> V2: use dev_dbg replace of dev_info
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 9a2a19ad4202..dcf3275a00fe 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -924,12 +924,20 @@ static void anx7625_dp_start(struct anx7625_data *ctx)
 {
int ret;
struct device *dev = >client->dev;
+   u8 data;
 
if (!ctx->display_timing_valid) {
DRM_DEV_ERROR(dev, "mipi not set display timing yet.\n");
return;
}
 
+   dev_dbg(dev, "set downstream sink into normal\n");
+   /* Downstream sink enter into normal mode */
+   data = 1;
+   ret = anx7625_aux_trans(ctx, DP_AUX_NATIVE_WRITE, 0x000600, 1, );
+   if (ret < 0)
+   dev_err(dev, "IO error : set sink into normal mode fail\n");
+
/* Disable HDCP */
anx7625_write_and(ctx, ctx->i2c.rx_p1_client, 0xee, 0x9f);
 
-- 
2.25.1



Re: drm/bridge: anx7625: Set downstream sink into normal status

2022-03-22 Thread Xin Ji
On Tue, Mar 22, 2022 at 03:33:17PM +0800, Pin-yen Lin wrote:
> Hi Xin,
> 
> Can we use dev_dbg instead of dev_info for the logging?
> 
> The log here is more like a debugging message, and using dev_dbg makes
> it consistent with anx7625_dp_stop.
> 
> Sorry for not catching this earlier.
> 
> Best regards,
> Pin-yen
Hi Pin-yen, OK, I'll change it in next version.
Thanks,
Xin
> 
> On Thu, Mar 3, 2022 at 3:52 PM Pin-yen Lin  wrote:
> >
> > Reviewed-by: Pin-Yen Lin 
> >
> >
> > On Wed, Mar 2, 2022 at 8:09 PM Xin Ji  wrote:
> > >
> > > As downstream sink was set into standby mode while bridge disabled,
> > > this patch used for setting downstream sink into normal status
> > > while enable bridge.
> > >
> > > Signed-off-by: Xin Ji 
> > > ---
> > >  drivers/gpu/drm/bridge/analogix/anx7625.c | 8 
> > >  1 file changed, 8 insertions(+)
> > >
> > > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> > > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > index 9aab879a8851..963eaf73ecab 100644
> > > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > @@ -919,12 +919,20 @@ static void anx7625_dp_start(struct anx7625_data 
> > > *ctx)
> > >  {
> > > int ret;
> > > struct device *dev = >client->dev;
> > > +   u8 data;
> > >
> > > if (!ctx->display_timing_valid) {
> > > DRM_DEV_ERROR(dev, "mipi not set display timing yet.\n");
> > > return;
> > > }
> > >
> > > +   dev_info(dev, "set downstream sink into normal\n");
> > > +   /* Downstream sink enter into normal mode */
> > > +   data = 1;
> > > +   ret = anx7625_aux_trans(ctx, DP_AUX_NATIVE_WRITE, 0x000600, 1, 
> > > );
> > > +   if (ret < 0)
> > > +   dev_err(dev, "IO error : set sink into normal mode 
> > > fail\n");
> > > +
> > > /* Disable HDCP */
> > > anx7625_write_and(ctx, ctx->i2c.rx_p1_client, 0xee, 0x9f);
> > >


Re: [PATCH v12 3/4] drm/bridge: anx7625: add MIPI DPI input feature

2022-03-21 Thread Xin Ji
On Tue, Mar 08, 2022 at 11:00:20AM +0100, Robert Foss wrote:
> On Mon, 7 Mar 2022 at 16:49, Robert Foss  wrote:
> >
> > On Mon, 7 Mar 2022 at 07:12, Chen-Yu Tsai  wrote:
> > >
> > > On Sun, Mar 06, 2022 at 07:13:30PM +0200, Laurent Pinchart wrote:
> > > > Hello Xin,
> > > >
> > > > (Question for Rob below, and I'm afraid this is urgent as we need to
> > > > merge a fix in v5.17).
> > > >
> > > > On Fri, Nov 05, 2021 at 11:19:03AM +0800, Xin Ji wrote:
> > > > > The basic anx7625 driver only support MIPI DSI rx signal input.
> > > > > This patch add MIPI DPI rx input configuration support, after apply
> > > > > this patch, the driver can support DSI rx or DPI rx by adding
> > > > > 'bus-type' in DT.
> > > > >
> > > > > Reviewed-by: Robert Foss 
> > > > > Signed-off-by: Xin Ji 
> > > > > ---
> > > > >  drivers/gpu/drm/bridge/analogix/anx7625.c | 247 
> > > > > --
> > > > >  drivers/gpu/drm/bridge/analogix/anx7625.h |  18 +-
> > > > >  2 files changed, 205 insertions(+), 60 deletions(-)
> > > > >
> > > > > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> > > > > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > > index f48e91134c20..f7c3386c8929 100644
> > > > > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > >
> > > [...]
> > >
> > > > >  static int anx7625_parse_dt(struct device *dev,
> > > > > struct anx7625_platform_data *pdata)
> > > > >  {
> > > > > -   struct device_node *np = dev->of_node;
> > > > > +   struct device_node *np = dev->of_node, *ep0;
> > > > > struct drm_panel *panel;
> > > > > int ret;
> > > > > +   int bus_type, mipi_lanes;
> > > > > +
> > > > > +   anx7625_get_swing_setting(dev, pdata);
> > > > >
> > > > > +   pdata->is_dpi = 1; /* default dpi mode */
> > > > > pdata->mipi_host_node = of_graph_get_remote_node(np, 0, 0);
> > > > > if (!pdata->mipi_host_node) {
> > > > > DRM_DEV_ERROR(dev, "fail to get internal panel.\n");
> > > > > return -ENODEV;
> > > > > }
> > > > >
> > > > > -   DRM_DEV_DEBUG_DRIVER(dev, "found dsi host node.\n");
> > > > > +   bus_type = V4L2_FWNODE_BUS_TYPE_PARALLEL;
> > > > > +   mipi_lanes = MAX_LANES_SUPPORT;
> > > > > +   ep0 = of_graph_get_endpoint_by_regs(np, 0, 0);
> > > > > +   if (ep0) {
> > > > > +   if (of_property_read_u32(ep0, "bus-type", _type))
> > > > > +   bus_type = 0;
> > > > > +
> > > > > +   mipi_lanes = of_property_count_u32_elems(ep0, 
> > > > > "data-lanes");
> > > > > +   }
> > > > > +
> > > > > +   if (bus_type == V4L2_FWNODE_BUS_TYPE_PARALLEL) /* bus type is 
> > > > > Parallel(DSI) */
> > > >
> > > > This is not correct *at all*. V4L2_FWNODE_BUS_TYPE_PARALLEL has nothing
> > > > to do with DSI. DSI stands for Digital *Serial* Interface. If anything,
> > > > the V4L2_FWNODE_BUS_TYPE_PARALLEL type would map better to DPI, even if
> > > > it's not an exact match.
> > > >
> > > > This patch has landed in v5.17-rc1, along with the corresponding
> > > > bindings. As DT bindings are an ABI, we should really fix this before
> > > > v5.17 is released. There is no DSI bus types defined in DT, and adding
> > > > one as a fix so late in the v5.17-rc cycle seems a bit of a stretch to
> > > > me (unless Rob disagrees).
> > > >
> > > > It would seem best to revert this series and the corresponding bindings,
> > > > and retry in v5.18.
> > >
> > > There is a DT patch using this property that is already queued up for 5.17
> > > in the soc tree:
> > >
> > > https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2F20220214200507.2500693-1-nfraprado%40collabora.com%2Fdata=04%7C01%7Cxji%40analogixsemi.com%7C69542695a9cd42cff5a508da00ea7baa%7Cb099b0b4f26c4cf59a0fd5be9acab205%7C0%7C0%7C637823304343387964

Re: [PATCH v2] drm/bridge: anx7625: Fix not correct get property counts

2022-03-14 Thread Xin Ji
On Fri, Mar 11, 2022 at 12:36:09PM +0100, Sam Ravnborg wrote:
> Hi Xin.
> 
> On Fri, Mar 11, 2022 at 06:35:25PM +0800, Xin Ji wrote:
> > The property length which returns from "of_get_property", it means array
> > bytes count if the property has prefix as "/bits/ 8". The driver should
> > call function "of_property_read_u8_array" to get correct array value.
> > 
> > Fixes: fd0310b6fe7d ("drm/bridge: anx7625: add MIPI DPI input feature")
> > Signed-off-by: Xin Ji 
> > 
> > ---
> > V1 -> V2: Fix Sam comment, use of_property_read_u8_array to get array
> > value
> > ---
> >  drivers/gpu/drm/bridge/analogix/anx7625.c | 8 
> >  drivers/gpu/drm/bridge/analogix/anx7625.h | 4 ++--
> >  2 files changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > index c6a9a02ed762..628cbf769141 100644
> > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > @@ -1598,8 +1598,8 @@ static int anx7625_get_swing_setting(struct device 
> > *dev,
> > num_regs = DP_TX_SWING_REG_CNT;
> >  
> > pdata->dp_lane0_swing_reg_cnt = num_regs;
> > -   of_property_read_u32_array(dev->of_node, "analogix,lane0-swing",
> > -  pdata->lane0_reg_data, num_regs);
> > +   of_property_read_u8_array(dev->of_node, "analogix,lane0-swing",
> > + pdata->lane0_reg_data, num_regs);
> 
> The current implementation do a two step approach. First is find the
> number of elements and then read the elements.
> The number of elements is only used to limit what is read.
> 
> I suggest to use:
> 
> of_property_read_u8_array(dev->of_node, "analogix,lane0-swing",
> pdata->lane0_reg_data, DP_TX_SWING_REG_CNT);
> 
> Then you a guaranteed to read at maximum DP_TX_SWING_REG_CNT entries.
> And as the number of elements is not stored anywhere that should be fine.
> 
> This looks simpler and matches what we for example do in
> drivers/gpu/drm/arm/malidp_drv.c - the only user in gpu/ of
> of_property_read_u8_array().
Hi Sam, the property is variable, so need two steps to approach, first
to get the property length, then to read the elements (the property
length may between 1 to DP_TX_SWING_REG_CNT). If directly to read the
element, I cannot exactly know how many registers need by configred.

Thanks,
Xin
> 
> 
>   Sam


[PATCH v2] drm/bridge: anx7625: Fix not correct get property counts

2022-03-11 Thread Xin Ji
The property length which returns from "of_get_property", it means array
bytes count if the property has prefix as "/bits/ 8". The driver should
call function "of_property_read_u8_array" to get correct array value.

Fixes: fd0310b6fe7d ("drm/bridge: anx7625: add MIPI DPI input feature")
Signed-off-by: Xin Ji 

---
V1 -> V2: Fix Sam comment, use of_property_read_u8_array to get array
value
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 8 
 drivers/gpu/drm/bridge/analogix/anx7625.h | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index c6a9a02ed762..628cbf769141 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1598,8 +1598,8 @@ static int anx7625_get_swing_setting(struct device *dev,
num_regs = DP_TX_SWING_REG_CNT;
 
pdata->dp_lane0_swing_reg_cnt = num_regs;
-   of_property_read_u32_array(dev->of_node, "analogix,lane0-swing",
-  pdata->lane0_reg_data, num_regs);
+   of_property_read_u8_array(dev->of_node, "analogix,lane0-swing",
+ pdata->lane0_reg_data, num_regs);
}
 
if (of_get_property(dev->of_node,
@@ -1608,8 +1608,8 @@ static int anx7625_get_swing_setting(struct device *dev,
num_regs = DP_TX_SWING_REG_CNT;
 
pdata->dp_lane1_swing_reg_cnt = num_regs;
-   of_property_read_u32_array(dev->of_node, "analogix,lane1-swing",
-  pdata->lane1_reg_data, num_regs);
+   of_property_read_u8_array(dev->of_node, "analogix,lane1-swing",
+ pdata->lane1_reg_data, num_regs);
}
 
return 0;
diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h 
b/drivers/gpu/drm/bridge/analogix/anx7625.h
index edbbfe410a56..2c340f16f2c3 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.h
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
@@ -426,9 +426,9 @@ struct anx7625_platform_data {
int mipi_lanes;
int audio_en;
int dp_lane0_swing_reg_cnt;
-   int lane0_reg_data[DP_TX_SWING_REG_CNT];
int dp_lane1_swing_reg_cnt;
-   int lane1_reg_data[DP_TX_SWING_REG_CNT];
+   u8 lane0_reg_data[DP_TX_SWING_REG_CNT];
+   u8 lane1_reg_data[DP_TX_SWING_REG_CNT];
u32 low_power_mode;
struct device_node *mipi_host_node;
 };
-- 
2.25.1



Re: [PATCH] drm/bridge: anx7625: Fix not correct get property counts

2022-03-10 Thread Xin Ji
On Thu, Mar 10, 2022 at 07:53:59PM +0100, Sam Ravnborg wrote:
> Hi Xin,
> 
> On Thu, Mar 10, 2022 at 05:16:53PM +0800, Xin Ji wrote:
> > The property length which returns from "of_get_property", divided by
> > sizeof(int) to get the total property counts.
> > 
> > Fixes: fd0310b6fe7d ("drm/bridge: anx7625: add MIPI DPI input feature")
> > 
> > Signed-off-by: Xin Ji 
> > ---
> >  drivers/gpu/drm/bridge/analogix/anx7625.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > index c6a9a02ed762..87081d5b408d 100644
> > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > @@ -1594,6 +1594,7 @@ static int anx7625_get_swing_setting(struct device 
> > *dev,
> >  
> > if (of_get_property(dev->of_node,
> > "analogix,lane0-swing", _regs)) {
> > +   num_regs /= sizeof(int);
> 
> Since the property is an array maybe use: of_property_read_u8_array()
> 
>   Sam
Hi Sam, OK, I'll use it to get property data.

Thanks,
Xin


[PATCH] drm/bridge: anx7625: Fix not correct get property counts

2022-03-10 Thread Xin Ji
The property length which returns from "of_get_property", divided by
sizeof(int) to get the total property counts.

Fixes: fd0310b6fe7d ("drm/bridge: anx7625: add MIPI DPI input feature")

Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index c6a9a02ed762..87081d5b408d 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1594,6 +1594,7 @@ static int anx7625_get_swing_setting(struct device *dev,
 
if (of_get_property(dev->of_node,
"analogix,lane0-swing", _regs)) {
+   num_regs /= sizeof(int);
if (num_regs > DP_TX_SWING_REG_CNT)
num_regs = DP_TX_SWING_REG_CNT;
 
@@ -1604,6 +1605,7 @@ static int anx7625_get_swing_setting(struct device *dev,
 
if (of_get_property(dev->of_node,
"analogix,lane1-swing", _regs)) {
+   num_regs /= sizeof(int);
if (num_regs > DP_TX_SWING_REG_CNT)
num_regs = DP_TX_SWING_REG_CNT;
 
-- 
2.25.1



Re: [PATCH v12 3/4] drm/bridge: anx7625: add MIPI DPI input feature

2022-03-06 Thread Xin Ji
On Mon, Mar 07, 2022 at 01:17:44PM +0800, Hsin-Yi Wang wrote:
> On Mon, Mar 7, 2022 at 1:09 PM Xin Ji  wrote:
> >
> > On Mon, Mar 07, 2022 at 06:47:44AM +0200, Laurent Pinchart wrote:
> > > Hello Xin,
> > >
> > > On Mon, Mar 07, 2022 at 12:32:49PM +0800, Xin Ji wrote:
> > > > On Mon, Mar 07, 2022 at 05:30:09AM +0200, Laurent Pinchart wrote:
> > > > > On Mon, Mar 07, 2022 at 11:22:48AM +0800, Xin Ji wrote:
> > > > > > On Sun, Mar 06, 2022 at 07:13:30PM +0200, Laurent Pinchart wrote:
> > > > > > > Hello Xin,
> > > > > > >
> > > > > > > (Question for Rob below, and I'm afraid this is urgent as we need 
> > > > > > > to
> > > > > > > merge a fix in v5.17).
> > > > > > >
> > > > > > > On Fri, Nov 05, 2021 at 11:19:03AM +0800, Xin Ji wrote:
> > > > > > > > The basic anx7625 driver only support MIPI DSI rx signal input.
> > > > > > > > This patch add MIPI DPI rx input configuration support, after 
> > > > > > > > apply
> > > > > > > > this patch, the driver can support DSI rx or DPI rx by adding
> > > > > > > > 'bus-type' in DT.
> > > > > > > >
> > > > > > > > Reviewed-by: Robert Foss 
> > > > > > > > Signed-off-by: Xin Ji 
> > > > > > > > ---
> > > > > > > >  drivers/gpu/drm/bridge/analogix/anx7625.c | 247 
> > > > > > > > --
> > > > > > > >  drivers/gpu/drm/bridge/analogix/anx7625.h |  18 +-
> > > > > > > >  2 files changed, 205 insertions(+), 60 deletions(-)
> > > > > > > >
> > > > > > > > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> > > > > > > > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > > > > > index f48e91134c20..f7c3386c8929 100644
> > > > > > > > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > > > > > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > > > > > @@ -32,6 +32,7 @@
> > > > > > > >  #include 
> > > > > > > >  #include 
> > > > > > > >
> > > > > > > > +#include 
> > > > > > > >  #include 
> > > > > > > >
> > > > > > > >  #include "anx7625.h"
> > > > > > > > @@ -152,18 +153,18 @@ static int anx7625_write_and(struct 
> > > > > > > > anx7625_data *ctx,
> > > > > > > > return anx7625_reg_write(ctx, client, offset, (val & 
> > > > > > > > (mask)));
> > > > > > > >  }
> > > > > > > >
> > > > > > > > -static int anx7625_write_and_or(struct anx7625_data *ctx,
> > > > > > > > -   struct i2c_client *client,
> > > > > > > > -   u8 offset, u8 and_mask, u8 or_mask)
> > > > > > > > +static int anx7625_config_bit_matrix(struct anx7625_data *ctx)
> > > > > > > >  {
> > > > > > > > -   int val;
> > > > > > > > +   int i, ret;
> > > > > > > >
> > > > > > > > -   val = anx7625_reg_read(ctx, client, offset);
> > > > > > > > -   if (val < 0)
> > > > > > > > -   return val;
> > > > > > > > +   ret = anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
> > > > > > > > +  AUDIO_CONTROL_REGISTER, 0x80);
> > > > > > > > +   for (i = 0; i < 13; i++)
> > > > > > > > +   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
> > > > > > > > +VIDEO_BIT_MATRIX_12 + i,
> > > > > > > > +0x18 + i);
> > > > > > > >
> > > > > > > > -   return anx7625_reg_write(ctx, client,
> > > > > > > > -offset, (val & and_mask) | 
> > > > > > > > (or_mask));
> > > > > > > > +   return ret;
> > > > > > > >  }
> > &

Re: [PATCH v12 3/4] drm/bridge: anx7625: add MIPI DPI input feature

2022-03-06 Thread Xin Ji
On Mon, Mar 07, 2022 at 06:47:44AM +0200, Laurent Pinchart wrote:
> Hello Xin,
> 
> On Mon, Mar 07, 2022 at 12:32:49PM +0800, Xin Ji wrote:
> > On Mon, Mar 07, 2022 at 05:30:09AM +0200, Laurent Pinchart wrote:
> > > On Mon, Mar 07, 2022 at 11:22:48AM +0800, Xin Ji wrote:
> > > > On Sun, Mar 06, 2022 at 07:13:30PM +0200, Laurent Pinchart wrote:
> > > > > Hello Xin,
> > > > > 
> > > > > (Question for Rob below, and I'm afraid this is urgent as we need to
> > > > > merge a fix in v5.17).
> > > > > 
> > > > > On Fri, Nov 05, 2021 at 11:19:03AM +0800, Xin Ji wrote:
> > > > > > The basic anx7625 driver only support MIPI DSI rx signal input.
> > > > > > This patch add MIPI DPI rx input configuration support, after apply
> > > > > > this patch, the driver can support DSI rx or DPI rx by adding
> > > > > > 'bus-type' in DT.
> > > > > > 
> > > > > > Reviewed-by: Robert Foss 
> > > > > > Signed-off-by: Xin Ji 
> > > > > > ---
> > > > > >  drivers/gpu/drm/bridge/analogix/anx7625.c | 247 
> > > > > > --
> > > > > >  drivers/gpu/drm/bridge/analogix/anx7625.h |  18 +-
> > > > > >  2 files changed, 205 insertions(+), 60 deletions(-)
> > > > > > 
> > > > > > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> > > > > > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > > > index f48e91134c20..f7c3386c8929 100644
> > > > > > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > > > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > > > @@ -32,6 +32,7 @@
> > > > > >  #include 
> > > > > >  #include 
> > > > > >  
> > > > > > +#include 
> > > > > >  #include 
> > > > > >  
> > > > > >  #include "anx7625.h"
> > > > > > @@ -152,18 +153,18 @@ static int anx7625_write_and(struct 
> > > > > > anx7625_data *ctx,
> > > > > > return anx7625_reg_write(ctx, client, offset, (val & (mask)));
> > > > > >  }
> > > > > >  
> > > > > > -static int anx7625_write_and_or(struct anx7625_data *ctx,
> > > > > > -   struct i2c_client *client,
> > > > > > -   u8 offset, u8 and_mask, u8 or_mask)
> > > > > > +static int anx7625_config_bit_matrix(struct anx7625_data *ctx)
> > > > > >  {
> > > > > > -   int val;
> > > > > > +   int i, ret;
> > > > > >  
> > > > > > -   val = anx7625_reg_read(ctx, client, offset);
> > > > > > -   if (val < 0)
> > > > > > -   return val;
> > > > > > +   ret = anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
> > > > > > +  AUDIO_CONTROL_REGISTER, 0x80);
> > > > > > +   for (i = 0; i < 13; i++)
> > > > > > +   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
> > > > > > +VIDEO_BIT_MATRIX_12 + i,
> > > > > > +0x18 + i);
> > > > > >  
> > > > > > -   return anx7625_reg_write(ctx, client,
> > > > > > -offset, (val & and_mask) | (or_mask));
> > > > > > +   return ret;
> > > > > >  }
> > > > > >  
> > > > > >  static int anx7625_read_ctrl_status_p0(struct anx7625_data *ctx)
> > > > > > @@ -221,38 +222,6 @@ static int anx7625_video_mute_control(struct 
> > > > > > anx7625_data *ctx,
> > > > > > return ret;
> > > > > >  }
> > > > > >  
> > > > > > -static int anx7625_config_audio_input(struct anx7625_data *ctx)
> > > > > > -{
> > > > > > -   struct device *dev = >client->dev;
> > > > > > -   int ret;
> > > > > > -
> > > > > > -   /* Channel num */
> > > > > > -   ret = anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
> > > > > > -   AUDIO_CHANNEL_STATUS_6, I2S_CH_2 << 5);
> &g

Re: [PATCH v12 3/4] drm/bridge: anx7625: add MIPI DPI input feature

2022-03-06 Thread Xin Ji
On Mon, Mar 07, 2022 at 05:30:09AM +0200, Laurent Pinchart wrote:
> Hello Xin,
> 
> On Mon, Mar 07, 2022 at 11:22:48AM +0800, Xin Ji wrote:
> > On Sun, Mar 06, 2022 at 07:13:30PM +0200, Laurent Pinchart wrote:
> > > Hello Xin,
> > > 
> > > (Question for Rob below, and I'm afraid this is urgent as we need to
> > > merge a fix in v5.17).
> > > 
> > > On Fri, Nov 05, 2021 at 11:19:03AM +0800, Xin Ji wrote:
> > > > The basic anx7625 driver only support MIPI DSI rx signal input.
> > > > This patch add MIPI DPI rx input configuration support, after apply
> > > > this patch, the driver can support DSI rx or DPI rx by adding
> > > > 'bus-type' in DT.
> > > > 
> > > > Reviewed-by: Robert Foss 
> > > > Signed-off-by: Xin Ji 
> > > > ---
> > > >  drivers/gpu/drm/bridge/analogix/anx7625.c | 247 --
> > > >  drivers/gpu/drm/bridge/analogix/anx7625.h |  18 +-
> > > >  2 files changed, 205 insertions(+), 60 deletions(-)
> > > > 
> > > > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> > > > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > index f48e91134c20..f7c3386c8929 100644
> > > > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > @@ -32,6 +32,7 @@
> > > >  #include 
> > > >  #include 
> > > >  
> > > > +#include 
> > > >  #include 
> > > >  
> > > >  #include "anx7625.h"
> > > > @@ -152,18 +153,18 @@ static int anx7625_write_and(struct anx7625_data 
> > > > *ctx,
> > > > return anx7625_reg_write(ctx, client, offset, (val & (mask)));
> > > >  }
> > > >  
> > > > -static int anx7625_write_and_or(struct anx7625_data *ctx,
> > > > -   struct i2c_client *client,
> > > > -   u8 offset, u8 and_mask, u8 or_mask)
> > > > +static int anx7625_config_bit_matrix(struct anx7625_data *ctx)
> > > >  {
> > > > -   int val;
> > > > +   int i, ret;
> > > >  
> > > > -   val = anx7625_reg_read(ctx, client, offset);
> > > > -   if (val < 0)
> > > > -   return val;
> > > > +   ret = anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
> > > > +  AUDIO_CONTROL_REGISTER, 0x80);
> > > > +   for (i = 0; i < 13; i++)
> > > > +   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
> > > > +VIDEO_BIT_MATRIX_12 + i,
> > > > +0x18 + i);
> > > >  
> > > > -   return anx7625_reg_write(ctx, client,
> > > > -offset, (val & and_mask) | (or_mask));
> > > > +   return ret;
> > > >  }
> > > >  
> > > >  static int anx7625_read_ctrl_status_p0(struct anx7625_data *ctx)
> > > > @@ -221,38 +222,6 @@ static int anx7625_video_mute_control(struct 
> > > > anx7625_data *ctx,
> > > > return ret;
> > > >  }
> > > >  
> > > > -static int anx7625_config_audio_input(struct anx7625_data *ctx)
> > > > -{
> > > > -   struct device *dev = >client->dev;
> > > > -   int ret;
> > > > -
> > > > -   /* Channel num */
> > > > -   ret = anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
> > > > -   AUDIO_CHANNEL_STATUS_6, I2S_CH_2 << 5);
> > > > -
> > > > -   /* FS */
> > > > -   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
> > > > -   AUDIO_CHANNEL_STATUS_4,
> > > > -   0xf0, AUDIO_FS_48K);
> > > > -   /* Word length */
> > > > -   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
> > > > -   AUDIO_CHANNEL_STATUS_5,
> > > > -   0xf0, AUDIO_W_LEN_24_24MAX);
> > > > -   /* I2S */
> > > > -   ret |= anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
> > > > -   AUDIO_CHANNEL_STATUS_6, I2S_SLAVE_MODE);
> > > > -   ret |= anx762

Re: [PATCH v12 3/4] drm/bridge: anx7625: add MIPI DPI input feature

2022-03-06 Thread Xin Ji
On Sun, Mar 06, 2022 at 07:13:30PM +0200, Laurent Pinchart wrote:
> Hello Xin,
> 
> (Question for Rob below, and I'm afraid this is urgent as we need to
> merge a fix in v5.17).
> 
> On Fri, Nov 05, 2021 at 11:19:03AM +0800, Xin Ji wrote:
> > The basic anx7625 driver only support MIPI DSI rx signal input.
> > This patch add MIPI DPI rx input configuration support, after apply
> > this patch, the driver can support DSI rx or DPI rx by adding
> > 'bus-type' in DT.
> > 
> > Reviewed-by: Robert Foss 
> > Signed-off-by: Xin Ji 
> > ---
> >  drivers/gpu/drm/bridge/analogix/anx7625.c | 247 --
> >  drivers/gpu/drm/bridge/analogix/anx7625.h |  18 +-
> >  2 files changed, 205 insertions(+), 60 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > index f48e91134c20..f7c3386c8929 100644
> > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > @@ -32,6 +32,7 @@
> >  #include 
> >  #include 
> >  
> > +#include 
> >  #include 
> >  
> >  #include "anx7625.h"
> > @@ -152,18 +153,18 @@ static int anx7625_write_and(struct anx7625_data *ctx,
> > return anx7625_reg_write(ctx, client, offset, (val & (mask)));
> >  }
> >  
> > -static int anx7625_write_and_or(struct anx7625_data *ctx,
> > -   struct i2c_client *client,
> > -   u8 offset, u8 and_mask, u8 or_mask)
> > +static int anx7625_config_bit_matrix(struct anx7625_data *ctx)
> >  {
> > -   int val;
> > +   int i, ret;
> >  
> > -   val = anx7625_reg_read(ctx, client, offset);
> > -   if (val < 0)
> > -   return val;
> > +   ret = anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
> > +  AUDIO_CONTROL_REGISTER, 0x80);
> > +   for (i = 0; i < 13; i++)
> > +   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
> > +VIDEO_BIT_MATRIX_12 + i,
> > +0x18 + i);
> >  
> > -   return anx7625_reg_write(ctx, client,
> > -offset, (val & and_mask) | (or_mask));
> > +   return ret;
> >  }
> >  
> >  static int anx7625_read_ctrl_status_p0(struct anx7625_data *ctx)
> > @@ -221,38 +222,6 @@ static int anx7625_video_mute_control(struct 
> > anx7625_data *ctx,
> > return ret;
> >  }
> >  
> > -static int anx7625_config_audio_input(struct anx7625_data *ctx)
> > -{
> > -   struct device *dev = >client->dev;
> > -   int ret;
> > -
> > -   /* Channel num */
> > -   ret = anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
> > -   AUDIO_CHANNEL_STATUS_6, I2S_CH_2 << 5);
> > -
> > -   /* FS */
> > -   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
> > -   AUDIO_CHANNEL_STATUS_4,
> > -   0xf0, AUDIO_FS_48K);
> > -   /* Word length */
> > -   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
> > -   AUDIO_CHANNEL_STATUS_5,
> > -   0xf0, AUDIO_W_LEN_24_24MAX);
> > -   /* I2S */
> > -   ret |= anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
> > -   AUDIO_CHANNEL_STATUS_6, I2S_SLAVE_MODE);
> > -   ret |= anx7625_write_and(ctx, ctx->i2c.tx_p2_client,
> > -AUDIO_CONTROL_REGISTER, ~TDM_TIMING_MODE);
> > -   /* Audio change flag */
> > -   ret |= anx7625_write_or(ctx, ctx->i2c.rx_p0_client,
> > -   AP_AV_STATUS, AP_AUDIO_CHG);
> > -
> > -   if (ret < 0)
> > -   DRM_DEV_ERROR(dev, "fail to config audio.\n");
> > -
> > -   return ret;
> > -}
> > -
> >  /* Reduction of fraction a/b */
> >  static void anx7625_reduction_of_a_fraction(unsigned long *a, unsigned 
> > long *b)
> >  {
> > @@ -431,7 +400,7 @@ static int anx7625_dsi_video_timing_config(struct 
> > anx7625_data *ctx)
> > ret |= anx7625_write_and(ctx, ctx->i2c.rx_p1_client,
> > MIPI_LANE_CTRL_0, 0xfc);
> > ret |= anx7625_write_or(ctx, ctx->i2c.rx_p1_client,
> > -   MIPI_LANE_CTRL_0, 3);
> > +   MIPI_LANE_CTRL_0, ctx->pdata.mipi_lanes - 1);
> >  
> > /* Htotal */
> > htotal = ctx->dt.hactive.mi

[PATCH] drm/bridge: anx7625: Set downstream sink into normal status

2022-03-02 Thread Xin Ji
As downstream sink was set into standby mode while bridge disabled,
this patch used for setting downstream sink into normal status
while enable bridge.

Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 9aab879a8851..963eaf73ecab 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -919,12 +919,20 @@ static void anx7625_dp_start(struct anx7625_data *ctx)
 {
int ret;
struct device *dev = >client->dev;
+   u8 data;
 
if (!ctx->display_timing_valid) {
DRM_DEV_ERROR(dev, "mipi not set display timing yet.\n");
return;
}
 
+   dev_info(dev, "set downstream sink into normal\n");
+   /* Downstream sink enter into normal mode */
+   data = 1;
+   ret = anx7625_aux_trans(ctx, DP_AUX_NATIVE_WRITE, 0x000600, 1, );
+   if (ret < 0)
+   dev_err(dev, "IO error : set sink into normal mode fail\n");
+
/* Disable HDCP */
anx7625_write_and(ctx, ctx->i2c.rx_p1_client, 0xee, 0x9f);
 
-- 
2.25.1



Re: [PATCH v2] drm/bridge: Clear the DP_AUX_I2C_MOT bit passed in aux read command.

2022-02-17 Thread Xin Ji
On Thu, Feb 17, 2022 at 04:22:25PM +0800, Hsin-Yi Wang wrote:
> If the previous transfer didn't end with a command without DP_AUX_I2C_MOT,
> the next read trasnfer will miss the first byte. But if the command in
> previous transfer is requested with length 0, it's a no-op to anx7625
> since it can't process this command. anx7625 requires the last command
> to be read command with length > 0.
> 
> It's observed that if we clear the DP_AUX_I2C_MOT in read transfer, we
> can still get correct data. Clear the read commands with DP_AUX_I2C_MOT
> bit to fix this issue.

Hi Hsin-Yi, thanks for the patch!

Reviewed-by: Xin Ji 

Thanks,
Xin
> 
> Fixes: adca62ec370c ("drm/bridge: anx7625: Support reading edid through aux 
> channel")
> Signed-off-by: Hsin-Yi Wang 
> ---
> v1->v2: Offline discussed with Xin Ji, it's better to clear the bit on
> read commands only.
> ---
>  drivers/gpu/drm/bridge/analogix/anx7625.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> b/drivers/gpu/drm/bridge/analogix/anx7625.c
> index 633618bafd75d3..2805e9bed2c2f4 100644
> --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> @@ -253,6 +253,8 @@ static int anx7625_aux_trans(struct anx7625_data *ctx, u8 
> op, u32 address,
>   addrm = (address >> 8) & 0xFF;
>   addrh = (address >> 16) & 0xFF;
>  
> + if (!is_write)
> + op &= ~DP_AUX_I2C_MOT;
>   cmd = DPCD_CMD(len, op);
>  
>   /* Set command and length */
> -- 
> 2.35.1.265.g69c8d7142f-goog


[PATCH] drm/bridge: anx7625: Fix release wrong workqueue

2022-02-16 Thread Xin Ji
From: Xin Ji 

If "hdcp_workqueue" exist, must release "hdcp_workqueue",
not "workqueue".

Fixes: cd1637c7e480 ("drm/bridge: anx7625: add HDCP support")
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 633618bafd75..9aab879a8851 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -2736,8 +2736,8 @@ static int anx7625_i2c_remove(struct i2c_client *client)
 
if (platform->hdcp_workqueue) {
cancel_delayed_work(>hdcp_work);
-   flush_workqueue(platform->workqueue);
-   destroy_workqueue(platform->workqueue);
+   flush_workqueue(platform->hdcp_workqueue);
+   destroy_workqueue(platform->hdcp_workqueue);
}
 
if (!platform->pdata.low_power_mode)
-- 
2.25.1



Re: [PATCH 2/3] drm/bridge: anx7625: Support reading edid through aux channel

2022-01-12 Thread Xin Ji
Hi Hsin-Yi, thanks for the patch! Please fix the follow comment, then
add my id.
Reviewed-by: Xin Ji 

On Tue, Jan 11, 2022 at 07:27:00PM +0800, Hsin-Yi Wang wrote:
> Support reading edid through aux channel if panel is connected to aux
> bus. Extend anx7625_aux_dpcd_trans() to implement aux transfer function:
> 
> 1. panel is populated in devm_of_dp_aux_populate_ep_devices(), so move
>anx7625_parse_dt() after.
> 2. Use pm runtime autosuspend since aux transfer function is called
>multiple times when reading edid.
> 3. No-op if aux transfer length is 0.
> 
> Signed-off-by: Hsin-Yi Wang 
> ---
> This patch is based on drm-misc-next and depends on 
> https://patchwork.freedesktop.org/patch/469081/
> ---
>  drivers/gpu/drm/bridge/analogix/anx7625.c | 123 ++
>  drivers/gpu/drm/bridge/analogix/anx7625.h |   4 +
>  2 files changed, 109 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> b/drivers/gpu/drm/bridge/analogix/anx7625.c
> index dbe708eb3bcf11..d60cfc058fbe7d 100644
> --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> @@ -24,6 +24,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -231,19 +232,22 @@ static int wait_aux_op_finish(struct anx7625_data *ctx)
>   return 0;
>  }
>  
> -static int anx7625_aux_dpcd_trans(struct anx7625_data *ctx, u8 op,
> -   u32 address, u8 len, u8 *buf)
> +static int anx7625_aux_trans(struct anx7625_data *ctx, u8 op, u32 address,
> +  u8 len, u8 *buf)
>  {
>   struct device *dev = >client->dev;
>   int ret;
>   u8 addrh, addrm, addrl;
>   u8 cmd;
>  
> - if (len > MAX_DPCD_BUFFER_SIZE) {
> + if (len > DP_AUX_MAX_PAYLOAD_BYTES) {
>   dev_err(dev, "exceed aux buffer len.\n");
>   return -EINVAL;

The native write command is 0x08, I2C Over aux write command is 0x04.
The native read command is 0x09, I2C Over aux read command is 0x05.

>   }
>  
> + if (!len)
> + return len;
> +
>   addrl = address & 0xFF;
>   addrm = (address >> 8) & 0xFF;
>   addrh = (address >> 16) & 0xFF;
> @@ -262,7 +266,7 @@ static int anx7625_aux_dpcd_trans(struct anx7625_data 
> *ctx, u8 op,
>   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
>AP_AUX_ADDR_19_16, addrh);
>  
> - if (op == DPCD_WRITE)
> + if (op == DPCD_WRITE || op == AP_AUX_WRITE)
>   ret |= anx7625_reg_block_write(ctx, ctx->i2c.rx_p0_client,
>  AP_AUX_BUFF_START, len, buf);
>   /* Enable aux access */
> @@ -275,14 +279,14 @@ static int anx7625_aux_dpcd_trans(struct anx7625_data 
> *ctx, u8 op,
>   }
>  
>   ret = wait_aux_op_finish(ctx);
> - if (ret) {
> + if (ret < 0) {
>   dev_err(dev, "aux IO error: wait aux op finish.\n");
>   return ret;
>   }
>  
>   /* Write done */
> - if (op == DPCD_WRITE)
> - return 0;
> + if (op == DPCD_WRITE || op == AP_AUX_WRITE)
> + return len;
>  
>   /* Read done, read out dpcd data */
>   ret = anx7625_reg_block_read(ctx, ctx->i2c.rx_p0_client,
> @@ -292,7 +296,7 @@ static int anx7625_aux_dpcd_trans(struct anx7625_data 
> *ctx, u8 op,
>   return -EIO;
>   }
>  
> - return 0;
> + return len;
>  }
>  
>  static int anx7625_video_mute_control(struct anx7625_data *ctx,
> @@ -867,7 +871,7 @@ static int anx7625_hdcp_enable(struct anx7625_data *ctx)
>   }
>  
>   /* Read downstream capability */
> - anx7625_aux_dpcd_trans(ctx, DPCD_READ, 0x68028, 1, );
> + anx7625_aux_trans(ctx, DPCD_READ, 0x68028, 1, );
>   if (!(bcap & 0x01)) {
>   pr_warn("downstream not support HDCP 1.4, cap(%x).\n", bcap);
>   return 0;
> @@ -956,7 +960,7 @@ static void anx7625_dp_stop(struct anx7625_data *ctx)
>   dev_dbg(dev, "notify downstream enter into standby\n");
>   /* Downstream monitor enter into standby mode */
>   data = 2;
> - ret |= anx7625_aux_dpcd_trans(ctx, DPCD_WRITE, 0x000600, 1, );
> + ret |= anx7625_aux_trans(ctx, DPCD_WRITE, 0x000600, 1, );
>   if (ret < 0)
>   DRM_DEV_ERROR(dev, "IO error : mute video fail\n");
>  
> @@ -1655,11 +1659,60 @@ static int anx7625_parse_dt(struct device *dev,
>   return 0;
>  }
>  
> +static bool anx7625_of_panel_on_aux

Re: [PATCH 3/3] dt-bindings: drm/bridge: anx7625: Add aux-bus node

2022-01-12 Thread Xin Ji
Hi Hsin-Yi, thanks for the patch! It's OK for me!
Reviewed-by: Xin Ji 

Thanks,
Xin

On Tue, Jan 11, 2022 at 07:27:01PM +0800, Hsin-Yi Wang wrote:
> List panel under aux-bus node if it's connected to anx7625's aux bus.
> 
> Signed-off-by: Hsin-Yi Wang 
> ---
>  .../display/bridge/analogix,anx7625.yaml| 17 +
>  1 file changed, 17 insertions(+)
> 
> diff --git 
> a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml 
> b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> index 1d3e88daca041a..0d38d6fe39830f 100644
> --- a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> +++ b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> @@ -83,6 +83,9 @@ properties:
>  type: boolean
>  description: let the driver enable audio HDMI codec function or not.
>  
> +  aux-bus:
> +$ref: /schemas/display/dp-aux-bus.yaml#
> +
>ports:
>  $ref: /schemas/graph.yaml#/properties/ports
>  
> @@ -167,5 +170,19 @@ examples:
>  };
>  };
>  };
> +
> +aux-bus {
> +panel {
> +compatible = "innolux,n125hce-gn1";
> +power-supply = <_disp_x>;
> +backlight = <_lcd0>;
> +
> +port {
> +panel_in: endpoint {
> +remote-endpoint = <_out>;
> +};
> +};
> +};
> +};
>  };
>  };
> -- 
> 2.34.1.575.g55b058a8bb-goog


Re: [PATCH 1/3] drm/bridge: anx7625: Convert to use devm_kzalloc

2022-01-12 Thread Xin Ji
Hi Hsin-Yi, thanks for the patch!
Reviewed-by: Xin Ji 

Thanks,
Xin

On Tue, Jan 11, 2022 at 07:26:59PM +0800, Hsin-Yi Wang wrote:
> Use devm_kzalloc instead of kzalloc and drop kfree(). Let the memory
> handled by driver detach.
> 
> Signed-off-by: Hsin-Yi Wang 
> ---
>  drivers/gpu/drm/bridge/analogix/anx7625.c | 9 +++--
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> b/drivers/gpu/drm/bridge/analogix/anx7625.c
> index 0b858c78abe8b6..dbe708eb3bcf11 100644
> --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> @@ -2515,7 +2515,7 @@ static int anx7625_i2c_probe(struct i2c_client *client,
>   return -ENODEV;
>   }
>  
> - platform = kzalloc(sizeof(*platform), GFP_KERNEL);
> + platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL);
>   if (!platform) {
>   DRM_DEV_ERROR(dev, "fail to allocate driver data\n");
>   return -ENOMEM;
> @@ -2527,7 +2527,7 @@ static int anx7625_i2c_probe(struct i2c_client *client,
>   if (ret) {
>   if (ret != -EPROBE_DEFER)
>   DRM_DEV_ERROR(dev, "fail to parse DT : %d\n", ret);
> - goto free_platform;
> + return ret;
>   }
>  
>   platform->client = client;
> @@ -2552,7 +2552,7 @@ static int anx7625_i2c_probe(struct i2c_client *client,
>   if (!platform->hdcp_workqueue) {
>   dev_err(dev, "fail to create work queue\n");
>   ret = -ENOMEM;
> - goto free_platform;
> + return ret;
>   }
>  
>   platform->pdata.intp_irq = client->irq;
> @@ -2637,9 +2637,6 @@ static int anx7625_i2c_probe(struct i2c_client *client,
>   if (platform->hdcp_workqueue)
>   destroy_workqueue(platform->hdcp_workqueue);
>  
> -free_platform:
> - kfree(platform);
> -
>   return ret;
>  }
>  
> -- 
> 2.34.1.575.g55b058a8bb-goog


[PATCH v3 1/1] drm/bridge: anx7625: send DPCD command to downstream

2022-01-11 Thread Xin Ji
Send DPCD command to downstream before anx7625 power down,
let downstream monitor enter into standby mode.

Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 42 +++
 1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 33383f83255d..0b858c78abe8 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -129,6 +129,23 @@ static int anx7625_reg_write(struct anx7625_data *ctx,
return ret;
 }
 
+static int anx7625_reg_block_write(struct anx7625_data *ctx,
+  struct i2c_client *client,
+  u8 reg_addr, u8 len, u8 *buf)
+{
+   int ret;
+   struct device *dev = >dev;
+
+   i2c_access_workaround(ctx, client);
+
+   ret = i2c_smbus_write_i2c_block_data(client, reg_addr, len, buf);
+   if (ret < 0)
+   dev_err(dev, "write i2c block failed id=%x\n:%x",
+   client->addr, reg_addr);
+
+   return ret;
+}
+
 static int anx7625_write_or(struct anx7625_data *ctx,
struct i2c_client *client,
u8 offset, u8 mask)
@@ -214,8 +231,8 @@ static int wait_aux_op_finish(struct anx7625_data *ctx)
return 0;
 }
 
-static int anx7625_aux_dpcd_read(struct anx7625_data *ctx,
-u32 address, u8 len, u8 *buf)
+static int anx7625_aux_dpcd_trans(struct anx7625_data *ctx, u8 op,
+ u32 address, u8 len, u8 *buf)
 {
struct device *dev = >client->dev;
int ret;
@@ -231,8 +248,7 @@ static int anx7625_aux_dpcd_read(struct anx7625_data *ctx,
addrm = (address >> 8) & 0xFF;
addrh = (address >> 16) & 0xFF;
 
-   cmd = DPCD_CMD(len, DPCD_READ);
-   cmd = ((len - 1) << 4) | 0x09;
+   cmd = DPCD_CMD(len, op);
 
/* Set command and length */
ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
@@ -246,6 +262,9 @@ static int anx7625_aux_dpcd_read(struct anx7625_data *ctx,
ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
 AP_AUX_ADDR_19_16, addrh);
 
+   if (op == DPCD_WRITE)
+   ret |= anx7625_reg_block_write(ctx, ctx->i2c.rx_p0_client,
+  AP_AUX_BUFF_START, len, buf);
/* Enable aux access */
ret |= anx7625_write_or(ctx, ctx->i2c.rx_p0_client,
AP_AUX_CTRL_STATUS, AP_AUX_CTRL_OP_EN);
@@ -255,14 +274,17 @@ static int anx7625_aux_dpcd_read(struct anx7625_data *ctx,
return -EIO;
}
 
-   usleep_range(2000, 2100);
-
ret = wait_aux_op_finish(ctx);
if (ret) {
dev_err(dev, "aux IO error: wait aux op finish.\n");
return ret;
}
 
+   /* Write done */
+   if (op == DPCD_WRITE)
+   return 0;
+
+   /* Read done, read out dpcd data */
ret = anx7625_reg_block_read(ctx, ctx->i2c.rx_p0_client,
 AP_AUX_BUFF_START, len, buf);
if (ret < 0) {
@@ -845,7 +867,7 @@ static int anx7625_hdcp_enable(struct anx7625_data *ctx)
}
 
/* Read downstream capability */
-   anx7625_aux_dpcd_read(ctx, 0x68028, 1, );
+   anx7625_aux_dpcd_trans(ctx, DPCD_READ, 0x68028, 1, );
if (!(bcap & 0x01)) {
pr_warn("downstream not support HDCP 1.4, cap(%x).\n", bcap);
return 0;
@@ -918,6 +940,7 @@ static void anx7625_dp_stop(struct anx7625_data *ctx)
 {
struct device *dev = >client->dev;
int ret;
+   u8 data;
 
DRM_DEV_DEBUG_DRIVER(dev, "stop dp output\n");
 
@@ -929,6 +952,11 @@ static void anx7625_dp_stop(struct anx7625_data *ctx)
ret |= anx7625_write_and(ctx, ctx->i2c.tx_p2_client, 0x08, 0x7f);
 
ret |= anx7625_video_mute_control(ctx, 1);
+
+   dev_dbg(dev, "notify downstream enter into standby\n");
+   /* Downstream monitor enter into standby mode */
+   data = 2;
+   ret |= anx7625_aux_dpcd_trans(ctx, DPCD_WRITE, 0x000600, 1, );
if (ret < 0)
DRM_DEV_ERROR(dev, "IO error : mute video fail\n");
 
-- 
2.25.1



[PATCH v2 1/1] drm/bridge: anx7625: send DPCD command to downstream

2022-01-10 Thread Xin Ji
Send DPCD command to downstream before anx7625 power down,
let downstream monitor enter into standby mode.

Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 40 ---
 1 file changed, 35 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 33383f83255d..fd2217ae455e 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -129,6 +129,23 @@ static int anx7625_reg_write(struct anx7625_data *ctx,
return ret;
 }
 
+static int anx7625_reg_block_write(struct anx7625_data *ctx,
+  struct i2c_client *client,
+  u8 reg_addr, u8 len, u8 *buf)
+{
+   int ret;
+   struct device *dev = >dev;
+
+   i2c_access_workaround(ctx, client);
+
+   ret = i2c_smbus_write_i2c_block_data(client, reg_addr, len, buf);
+   if (ret < 0)
+   DRM_DEV_ERROR(dev, "write i2c block failed id=%x\n:%x",
+ client->addr, reg_addr);
+
+   return ret;
+}
+
 static int anx7625_write_or(struct anx7625_data *ctx,
struct i2c_client *client,
u8 offset, u8 mask)
@@ -214,8 +231,8 @@ static int wait_aux_op_finish(struct anx7625_data *ctx)
return 0;
 }
 
-static int anx7625_aux_dpcd_read(struct anx7625_data *ctx,
-u32 address, u8 len, u8 *buf)
+static int anx7625_aux_dpcd_trans(struct anx7625_data *ctx, u8 op,
+ u32 address, u8 len, u8 *buf)
 {
struct device *dev = >client->dev;
int ret;
@@ -231,8 +248,7 @@ static int anx7625_aux_dpcd_read(struct anx7625_data *ctx,
addrm = (address >> 8) & 0xFF;
addrh = (address >> 16) & 0xFF;
 
-   cmd = DPCD_CMD(len, DPCD_READ);
-   cmd = ((len - 1) << 4) | 0x09;
+   cmd = DPCD_CMD(len, op);
 
/* Set command and length */
ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
@@ -246,6 +262,9 @@ static int anx7625_aux_dpcd_read(struct anx7625_data *ctx,
ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
 AP_AUX_ADDR_19_16, addrh);
 
+   if (op == DPCD_WRITE)
+   ret |= anx7625_reg_block_write(ctx, ctx->i2c.rx_p0_client,
+  AP_AUX_BUFF_START, len, buf);
/* Enable aux access */
ret |= anx7625_write_or(ctx, ctx->i2c.rx_p0_client,
AP_AUX_CTRL_STATUS, AP_AUX_CTRL_OP_EN);
@@ -263,6 +282,11 @@ static int anx7625_aux_dpcd_read(struct anx7625_data *ctx,
return ret;
}
 
+   /* Write done */
+   if (op == DPCD_WRITE)
+   return 0;
+
+   /* Read done, read out dpcd data */
ret = anx7625_reg_block_read(ctx, ctx->i2c.rx_p0_client,
 AP_AUX_BUFF_START, len, buf);
if (ret < 0) {
@@ -845,7 +869,7 @@ static int anx7625_hdcp_enable(struct anx7625_data *ctx)
}
 
/* Read downstream capability */
-   anx7625_aux_dpcd_read(ctx, 0x68028, 1, );
+   anx7625_aux_dpcd_trans(ctx, DPCD_READ, 0x68028, 1, );
if (!(bcap & 0x01)) {
pr_warn("downstream not support HDCP 1.4, cap(%x).\n", bcap);
return 0;
@@ -918,6 +942,7 @@ static void anx7625_dp_stop(struct anx7625_data *ctx)
 {
struct device *dev = >client->dev;
int ret;
+   u8 data;
 
DRM_DEV_DEBUG_DRIVER(dev, "stop dp output\n");
 
@@ -929,6 +954,11 @@ static void anx7625_dp_stop(struct anx7625_data *ctx)
ret |= anx7625_write_and(ctx, ctx->i2c.tx_p2_client, 0x08, 0x7f);
 
ret |= anx7625_video_mute_control(ctx, 1);
+
+   DRM_DEV_DEBUG_DRIVER(dev, "notify downstream enter into standby\n");
+   /* Downstream monitor enter into standby mode */
+   data = 2;
+   ret |= anx7625_aux_dpcd_trans(ctx, DPCD_WRITE, 0x000600, 1, );
if (ret < 0)
DRM_DEV_ERROR(dev, "IO error : mute video fail\n");
 
-- 
2.25.1



[PATCH v3 3/3] drm/bridge: anx7625: add audio codec .get_eld support

2022-01-06 Thread Xin Ji
Provide .get_eld interface in hdmi_codec_ops for hdmi-codec driver.

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 001460f62b0c..33383f83255d 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1840,9 +1840,27 @@ static int anx7625_audio_hook_plugged_cb(struct device 
*dev, void *data,
return 0;
 }
 
+static int anx7625_audio_get_eld(struct device *dev, void *data,
+u8 *buf, size_t len)
+{
+   struct anx7625_data *ctx = dev_get_drvdata(dev);
+
+   if (!ctx->connector) {
+   dev_err(dev, "connector not initial\n");
+   return -EINVAL;
+   }
+
+   dev_dbg(dev, "audio copy eld\n");
+   memcpy(buf, ctx->connector->eld,
+  min(sizeof(ctx->connector->eld), len));
+
+   return 0;
+}
+
 static const struct hdmi_codec_ops anx7625_codec_ops = {
.hw_params  = anx7625_audio_hw_params,
.audio_shutdown = anx7625_audio_shutdown,
+   .get_eld= anx7625_audio_get_eld,
.get_dai_id = anx7625_hdmi_i2s_get_dai_id,
.hook_plugged_cb = anx7625_audio_hook_plugged_cb,
 };
-- 
2.25.1



[PATCH v3 2/3] drm/bridge: anx7625: add HDCP support

2022-01-06 Thread Xin Ji
This patch provides HDCP setting interface for userspace to dynamic
enable/disable HDCP function.

Reported-by: kernel test robot 
Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 335 +-
 drivers/gpu/drm/bridge/analogix/anx7625.h |  79 -
 2 files changed, 404 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 6d5ae52f4142..001460f62b0c 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -213,6 +214,65 @@ static int wait_aux_op_finish(struct anx7625_data *ctx)
return 0;
 }
 
+static int anx7625_aux_dpcd_read(struct anx7625_data *ctx,
+u32 address, u8 len, u8 *buf)
+{
+   struct device *dev = >client->dev;
+   int ret;
+   u8 addrh, addrm, addrl;
+   u8 cmd;
+
+   if (len > MAX_DPCD_BUFFER_SIZE) {
+   dev_err(dev, "exceed aux buffer len.\n");
+   return -EINVAL;
+   }
+
+   addrl = address & 0xFF;
+   addrm = (address >> 8) & 0xFF;
+   addrh = (address >> 16) & 0xFF;
+
+   cmd = DPCD_CMD(len, DPCD_READ);
+   cmd = ((len - 1) << 4) | 0x09;
+
+   /* Set command and length */
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   AP_AUX_COMMAND, cmd);
+
+   /* Set aux access address */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+AP_AUX_ADDR_7_0, addrl);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+AP_AUX_ADDR_15_8, addrm);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+AP_AUX_ADDR_19_16, addrh);
+
+   /* Enable aux access */
+   ret |= anx7625_write_or(ctx, ctx->i2c.rx_p0_client,
+   AP_AUX_CTRL_STATUS, AP_AUX_CTRL_OP_EN);
+
+   if (ret < 0) {
+   dev_err(dev, "cannot access aux related register.\n");
+   return -EIO;
+   }
+
+   usleep_range(2000, 2100);
+
+   ret = wait_aux_op_finish(ctx);
+   if (ret) {
+   dev_err(dev, "aux IO error: wait aux op finish.\n");
+   return ret;
+   }
+
+   ret = anx7625_reg_block_read(ctx, ctx->i2c.rx_p0_client,
+AP_AUX_BUFF_START, len, buf);
+   if (ret < 0) {
+   dev_err(dev, "read dpcd register failed\n");
+   return -EIO;
+   }
+
+   return 0;
+}
+
 static int anx7625_video_mute_control(struct anx7625_data *ctx,
  u8 status)
 {
@@ -669,6 +729,165 @@ static int anx7625_dpi_config(struct anx7625_data *ctx)
return ret;
 }
 
+static int anx7625_read_flash_status(struct anx7625_data *ctx)
+{
+   return anx7625_reg_read(ctx, ctx->i2c.rx_p0_client, R_RAM_CTRL);
+}
+
+static int anx7625_hdcp_key_probe(struct anx7625_data *ctx)
+{
+   int ret, val;
+   struct device *dev = >client->dev;
+   u8 ident[FLASH_BUF_LEN];
+
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   FLASH_ADDR_HIGH, 0x91);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+FLASH_ADDR_LOW, 0xA0);
+   if (ret < 0) {
+   dev_err(dev, "IO error : set key flash address.\n");
+   return ret;
+   }
+
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   FLASH_LEN_HIGH, (FLASH_BUF_LEN - 1) >> 8);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+FLASH_LEN_LOW, (FLASH_BUF_LEN - 1) & 0xFF);
+   if (ret < 0) {
+   dev_err(dev, "IO error : set key flash len.\n");
+   return ret;
+   }
+
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   R_FLASH_RW_CTRL, FLASH_READ);
+   ret |= readx_poll_timeout(anx7625_read_flash_status,
+ ctx, val,
+ ((val & FLASH_DONE) || (val < 0)),
+ 2000,
+ 2000 * 150);
+   if (ret) {
+   dev_err(dev, "flash read access fail!\n");
+   return -EIO;
+   }
+
+   ret = anx7625_reg_block_read(ctx, ctx->i2c.rx_p0_client,
+FLASH_BUF_BASE_ADDR,
+FLASH_BUF_LEN, ident);
+   if (ret < 0) {
+   dev_err(dev, "read flash data fail!\n");
+   return -EIO;
+   

[PATCH v3 1/3] drm/bridge: anx7625: Add bridge helper atomic conversion

2022-01-06 Thread Xin Ji
Add bridge helper atomic conversion.

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 46 +++
 drivers/gpu/drm/bridge/analogix/anx7625.h |  1 +
 2 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 7b24213f7b13..6d5ae52f4142 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1911,25 +1911,54 @@ static bool anx7625_bridge_mode_fixup(struct drm_bridge 
*bridge,
return true;
 }
 
-static void anx7625_bridge_enable(struct drm_bridge *bridge)
+static int anx7625_bridge_atomic_check(struct drm_bridge *bridge,
+  struct drm_bridge_state *bridge_state,
+  struct drm_crtc_state *crtc_state,
+  struct drm_connector_state *conn_state)
 {
struct anx7625_data *ctx = bridge_to_anx7625(bridge);
struct device *dev = >client->dev;
 
-   DRM_DEV_DEBUG_DRIVER(dev, "drm enable\n");
+   dev_dbg(dev, "drm bridge atomic check\n");
+   return anx7625_bridge_mode_fixup(bridge, _state->mode,
+_state->adjusted_mode);
+}
+
+static void anx7625_bridge_atomic_enable(struct drm_bridge *bridge,
+struct drm_bridge_state *state)
+{
+   struct anx7625_data *ctx = bridge_to_anx7625(bridge);
+   struct device *dev = >client->dev;
+   struct drm_connector *connector;
+
+   dev_dbg(dev, "drm atomic enable\n");
+
+   if (!bridge->encoder) {
+   dev_err(dev, "Parent encoder object not found");
+   return;
+   }
+
+   connector = drm_atomic_get_new_connector_for_encoder(state->base.state,
+bridge->encoder);
+   if (!connector)
+   return;
+
+   ctx->connector = connector;
 
pm_runtime_get_sync(dev);
 
anx7625_dp_start(ctx);
 }
 
-static void anx7625_bridge_disable(struct drm_bridge *bridge)
+static void anx7625_bridge_atomic_disable(struct drm_bridge *bridge,
+ struct drm_bridge_state *old)
 {
struct anx7625_data *ctx = bridge_to_anx7625(bridge);
struct device *dev = >client->dev;
 
-   DRM_DEV_DEBUG_DRIVER(dev, "drm disable\n");
+   dev_dbg(dev, "drm atomic disable\n");
 
+   ctx->connector = NULL;
anx7625_dp_stop(ctx);
 
pm_runtime_put_sync(dev);
@@ -1959,11 +1988,14 @@ static struct edid *anx7625_bridge_get_edid(struct 
drm_bridge *bridge,
 
 static const struct drm_bridge_funcs anx7625_bridge_funcs = {
.attach = anx7625_bridge_attach,
-   .disable = anx7625_bridge_disable,
.mode_valid = anx7625_bridge_mode_valid,
.mode_set = anx7625_bridge_mode_set,
-   .mode_fixup = anx7625_bridge_mode_fixup,
-   .enable = anx7625_bridge_enable,
+   .atomic_check = anx7625_bridge_atomic_check,
+   .atomic_enable = anx7625_bridge_atomic_enable,
+   .atomic_disable = anx7625_bridge_atomic_disable,
+   .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
+   .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
+   .atomic_reset = drm_atomic_helper_bridge_reset,
.detect = anx7625_bridge_detect,
.get_edid = anx7625_bridge_get_edid,
 };
diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h 
b/drivers/gpu/drm/bridge/analogix/anx7625.h
index 3d79b6fb13c8..6f9d5f0e377c 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.h
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
@@ -407,6 +407,7 @@ struct anx7625_data {
u8 display_timing_valid;
struct drm_bridge bridge;
u8 bridge_attached;
+   struct drm_connector *connector;
struct mipi_dsi_device *dsi;
 };
 
-- 
2.25.1



[PATCH v2 3/3] drm/bridge: anx7625: add audio codec .get_eld support

2022-01-05 Thread Xin Ji
Provide .get_eld interface in hdmi_codec_ops for hdmi-codec driver.

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index a225dd1abf41..a41f22d0e088 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1840,9 +1840,27 @@ static int anx7625_audio_hook_plugged_cb(struct device 
*dev, void *data,
return 0;
 }
 
+static int anx7625_audio_get_eld(struct device *dev, void *data,
+u8 *buf, size_t len)
+{
+   struct anx7625_data *ctx = dev_get_drvdata(dev);
+
+   if (!ctx->connector) {
+   dev_err(dev, "connector not initial\n");
+   return -EINVAL;
+   }
+
+   dev_dbg(dev, "audio copy eld\n");
+   memcpy(buf, ctx->connector->eld,
+  min(sizeof(ctx->connector->eld), len));
+
+   return 0;
+}
+
 static const struct hdmi_codec_ops anx7625_codec_ops = {
.hw_params  = anx7625_audio_hw_params,
.audio_shutdown = anx7625_audio_shutdown,
+   .get_eld= anx7625_audio_get_eld,
.get_dai_id = anx7625_hdmi_i2s_get_dai_id,
.hook_plugged_cb = anx7625_audio_hook_plugged_cb,
 };
-- 
2.25.1



[PATCH v2 2/3] drm/bridge: anx7625: add HDCP support

2022-01-05 Thread Xin Ji
This patch provides HDCP setting interface for userspace to dynamic
enable/disable HDCP function.

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 335 +-
 drivers/gpu/drm/bridge/analogix/anx7625.h |  79 -
 2 files changed, 404 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 6d5ae52f4142..a225dd1abf41 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -213,6 +214,65 @@ static int wait_aux_op_finish(struct anx7625_data *ctx)
return 0;
 }
 
+static int anx7625_aux_dpcd_read(struct anx7625_data *ctx,
+u32 address, u8 len, u8 *buf)
+{
+   struct device *dev = >client->dev;
+   int ret;
+   u8 addrh, addrm, addrl;
+   u8 cmd;
+
+   if (len > MAX_DPCD_BUFFER_SIZE) {
+   dev_err(dev, "exceed aux buffer len.\n");
+   return -EINVAL;
+   }
+
+   addrl = address & 0xFF;
+   addrm = (address >> 8) & 0xFF;
+   addrh = (address >> 16) & 0xFF;
+
+   cmd = DPCD_CMD(len, DPCD_READ);
+   cmd = ((len - 1) << 4) | 0x09;
+
+   /* Set command and length */
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   AP_AUX_COMMAND, cmd);
+
+   /* Set aux access address */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+AP_AUX_ADDR_7_0, addrl);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+AP_AUX_ADDR_15_8, addrm);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+AP_AUX_ADDR_19_16, addrh);
+
+   /* Enable aux access */
+   ret |= anx7625_write_or(ctx, ctx->i2c.rx_p0_client,
+   AP_AUX_CTRL_STATUS, AP_AUX_CTRL_OP_EN);
+
+   if (ret < 0) {
+   dev_err(dev, "cannot access aux related register.\n");
+   return -EIO;
+   }
+
+   usleep_range(2000, 2100);
+
+   ret = wait_aux_op_finish(ctx);
+   if (ret) {
+   dev_err(dev, "aux IO error: wait aux op finish.\n");
+   return ret;
+   }
+
+   ret = anx7625_reg_block_read(ctx, ctx->i2c.rx_p0_client,
+AP_AUX_BUFF_START, len, buf);
+   if (ret < 0) {
+   dev_err(dev, "read dpcd register failed\n");
+   return -EIO;
+   }
+
+   return 0;
+}
+
 static int anx7625_video_mute_control(struct anx7625_data *ctx,
  u8 status)
 {
@@ -669,6 +729,165 @@ static int anx7625_dpi_config(struct anx7625_data *ctx)
return ret;
 }
 
+static int anx7625_read_flash_status(struct anx7625_data *ctx)
+{
+   return anx7625_reg_read(ctx, ctx->i2c.rx_p0_client, R_RAM_CTRL);
+}
+
+static int anx7625_hdcp_key_probe(struct anx7625_data *ctx)
+{
+   int ret, val;
+   struct device *dev = >client->dev;
+   u8 ident[FLASH_BUF_LEN];
+
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   FLASH_ADDR_HIGH, 0x91);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+FLASH_ADDR_LOW, 0xA0);
+   if (ret < 0) {
+   dev_err(dev, "IO error : set key flash address.\n");
+   return ret;
+   }
+
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   FLASH_LEN_HIGH, (FLASH_BUF_LEN - 1) >> 8);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+FLASH_LEN_LOW, (FLASH_BUF_LEN - 1) & 0xFF);
+   if (ret < 0) {
+   dev_err(dev, "IO error : set key flash len.\n");
+   return ret;
+   }
+
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   R_FLASH_RW_CTRL, FLASH_READ);
+   ret |= readx_poll_timeout(anx7625_read_flash_status,
+ ctx, val,
+ ((val & FLASH_DONE) || (val < 0)),
+ 2000,
+ 2000 * 150);
+   if (ret) {
+   dev_err(dev, "flash read access fail!\n");
+   return -EIO;
+   }
+
+   ret = anx7625_reg_block_read(ctx, ctx->i2c.rx_p0_client,
+FLASH_BUF_BASE_ADDR,
+FLASH_BUF_LEN, ident);
+   if (ret < 0) {
+   dev_err(dev, "read flash data fail!\n");
+   return -EIO;
+   }
+
+   if (

[PATCH v2 1/3] drm/bridge: anx7625: Add bridge helper atomic conversion

2022-01-05 Thread Xin Ji
Add bridge helper atomic conversion.

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 46 +++
 drivers/gpu/drm/bridge/analogix/anx7625.h |  1 +
 2 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 7b24213f7b13..6d5ae52f4142 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1911,25 +1911,54 @@ static bool anx7625_bridge_mode_fixup(struct drm_bridge 
*bridge,
return true;
 }
 
-static void anx7625_bridge_enable(struct drm_bridge *bridge)
+static int anx7625_bridge_atomic_check(struct drm_bridge *bridge,
+  struct drm_bridge_state *bridge_state,
+  struct drm_crtc_state *crtc_state,
+  struct drm_connector_state *conn_state)
 {
struct anx7625_data *ctx = bridge_to_anx7625(bridge);
struct device *dev = >client->dev;
 
-   DRM_DEV_DEBUG_DRIVER(dev, "drm enable\n");
+   dev_dbg(dev, "drm bridge atomic check\n");
+   return anx7625_bridge_mode_fixup(bridge, _state->mode,
+_state->adjusted_mode);
+}
+
+static void anx7625_bridge_atomic_enable(struct drm_bridge *bridge,
+struct drm_bridge_state *state)
+{
+   struct anx7625_data *ctx = bridge_to_anx7625(bridge);
+   struct device *dev = >client->dev;
+   struct drm_connector *connector;
+
+   dev_dbg(dev, "drm atomic enable\n");
+
+   if (!bridge->encoder) {
+   dev_err(dev, "Parent encoder object not found");
+   return;
+   }
+
+   connector = drm_atomic_get_new_connector_for_encoder(state->base.state,
+bridge->encoder);
+   if (!connector)
+   return;
+
+   ctx->connector = connector;
 
pm_runtime_get_sync(dev);
 
anx7625_dp_start(ctx);
 }
 
-static void anx7625_bridge_disable(struct drm_bridge *bridge)
+static void anx7625_bridge_atomic_disable(struct drm_bridge *bridge,
+ struct drm_bridge_state *old)
 {
struct anx7625_data *ctx = bridge_to_anx7625(bridge);
struct device *dev = >client->dev;
 
-   DRM_DEV_DEBUG_DRIVER(dev, "drm disable\n");
+   dev_dbg(dev, "drm atomic disable\n");
 
+   ctx->connector = NULL;
anx7625_dp_stop(ctx);
 
pm_runtime_put_sync(dev);
@@ -1959,11 +1988,14 @@ static struct edid *anx7625_bridge_get_edid(struct 
drm_bridge *bridge,
 
 static const struct drm_bridge_funcs anx7625_bridge_funcs = {
.attach = anx7625_bridge_attach,
-   .disable = anx7625_bridge_disable,
.mode_valid = anx7625_bridge_mode_valid,
.mode_set = anx7625_bridge_mode_set,
-   .mode_fixup = anx7625_bridge_mode_fixup,
-   .enable = anx7625_bridge_enable,
+   .atomic_check = anx7625_bridge_atomic_check,
+   .atomic_enable = anx7625_bridge_atomic_enable,
+   .atomic_disable = anx7625_bridge_atomic_disable,
+   .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
+   .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
+   .atomic_reset = drm_atomic_helper_bridge_reset,
.detect = anx7625_bridge_detect,
.get_edid = anx7625_bridge_get_edid,
 };
diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h 
b/drivers/gpu/drm/bridge/analogix/anx7625.h
index 3d79b6fb13c8..6f9d5f0e377c 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.h
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
@@ -407,6 +407,7 @@ struct anx7625_data {
u8 display_timing_valid;
struct drm_bridge bridge;
u8 bridge_attached;
+   struct drm_connector *connector;
struct mipi_dsi_device *dsi;
 };
 
-- 
2.25.1



Re: [PATCH 1/2] drm/bridge: anx7625: add HDCP support

2022-01-05 Thread Xin Ji
Hi Andrzej Hajda, thanks for the comment, I'll change it in next serial
patches.

Thanks,
Xin

On Wed, Jan 05, 2022 at 10:31:15AM +0100, Andrzej Hajda wrote:
> Hi Xin,
> 
> On 09.11.2021 03:42, Xin Ji wrote:
> > This patch provides HDCP setting interface for userspace to dynamic
> > enable/disable HDCP function.
> > 
> > Signed-off-by: Xin Ji 
> > ---
> >   drivers/gpu/drm/bridge/analogix/anx7625.c | 368 +-
> >   drivers/gpu/drm/bridge/analogix/anx7625.h |  69 +++-
> >   2 files changed, 425 insertions(+), 12 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > index 001fb39d9919..6d93026c2999 100644
> > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > @@ -26,6 +26,7 @@
> >   #include 
> >   #include 
> >   #include 
> > +#include 
> >   #include 
> >   #include 
> >   #include 
> > @@ -213,6 +214,60 @@ static int wait_aux_op_finish(struct anx7625_data *ctx)
> > return 0;
> >   }
> > +static int anx7625_aux_dpcd_read(struct anx7625_data *ctx,
> > +u8 addrh, u8 addrm, u8 addrl,
> 
> 
> Wouldn't be more convenient to use single u32 address (in fact 24 bits of
> it)?
OK, I'll use u32.
> 
> 
> > +u8 len, u8 *buf)
> > +{
> > +   struct device *dev = >client->dev;
> > +   int ret;
> > +   u8 cmd;
> > +
> > +   if (len > MAX_DPCD_BUFFER_SIZE) {
> > +   DRM_DEV_ERROR(dev, "exceed aux buffer len.\n");
> 
> 
> Here and below (note from inline docs)m regarding DRM_DEV_ERROR and friends:
> 
>  NOTE: this is deprecated in favor of drm_err() or dev_err()
OK. I'll use drm_err()
> 
> 
> > +   return -EINVAL;
> > +   }
> > +
> > +   cmd = ((len - 1) << 4) | 0x09;
> Here and below you can replace magic numbers by macros.
OK
> > +
> > +   /* Set command and length */
> > +   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
> > +   AP_AUX_COMMAND, cmd);
> > +
> > +   /* Set aux access address */
> > +   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
> > +AP_AUX_ADDR_7_0, addrl);
> > +   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
> > +AP_AUX_ADDR_15_8, addrm);
> > +   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
> > +AP_AUX_ADDR_19_16, addrh);
> > +
> > +   /* Enable aux access */
> > +   ret |= anx7625_write_or(ctx, ctx->i2c.rx_p0_client,
> > +   AP_AUX_CTRL_STATUS, AP_AUX_CTRL_OP_EN);
> > +
> > +   if (ret < 0) {
> > +   DRM_DEV_ERROR(dev, "cannot access aux related register.\n");
> > +   return -EIO;
> > +   }
> > +
> > +   usleep_range(2000, 2100);
> > +
> > +   ret = wait_aux_op_finish(ctx);
> > +   if (ret) {
> > +   DRM_DEV_ERROR(dev, "aux IO error: wait aux op finish.\n");
> > +   return ret;
> > +   }
> > +
> > +   ret = anx7625_reg_block_read(ctx, ctx->i2c.rx_p0_client,
> > +AP_AUX_BUFF_START, len, buf);
> > +   if (ret < 0) {
> > +   DRM_DEV_ERROR(dev, "read dpcd register failed\n");
> > +   return -EIO;
> > +   }
> > +
> > +   return 0;
> > +}
> > +
> >   static int anx7625_video_mute_control(struct anx7625_data *ctx,
> >   u8 status)
> >   {
> > @@ -669,6 +724,160 @@ static int anx7625_dpi_config(struct anx7625_data 
> > *ctx)
> > return ret;
> >   }
> > +static int anx7625_read_flash_status(struct anx7625_data *ctx)
> > +{
> > +   return anx7625_reg_read(ctx, ctx->i2c.rx_p0_client, R_RAM_CTRL);
> > +}
> > +
> > +static int anx7625_hdcp_key_probe(struct anx7625_data *ctx)
> > +{
> > +   int ret, val;
> > +   struct device *dev = >client->dev;
> > +   u8 ident[32];
> > +
> > +   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
> > +   FLASH_ADDR_HIGH, 0x91);
> > +   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
> > +FLASH_ADDR_LOW, 0xA0);
> > +   if (ret < 0) {
> > +   DRM_DEV_ERROR(dev, "IO error : set key flash address.\n");
> > +   return ret;
> > +   }
> >

Re: [PATCH 1/2] drm/bridge: anx7625: add HDCP support

2022-01-05 Thread Xin Ji
On Wed, Jan 05, 2022 at 11:32:01AM +0100, Robert Foss wrote:
> On Wed, 5 Jan 2022 at 08:17, Xin Ji  wrote:
> >
> > On Tue, Jan 04, 2022 at 03:50:34PM +0100, Robert Foss wrote:
> > > Hey Xin,
> > Hi Robert Foss, thanks for the reply.
> > As HDCP config interface "anx7625_hdcp_config(..)" need be called in
> > anx7625_connector_atomic_check(...) interface, so I cannot split out
> > atomic conversion patch.
> 
> I don't think that's correct, but maybe I'm missing something. The
> atomic conversion patch should be self-contained if done before the
> addition of HDCP support.
Hi Robert Foss, OK, you are right, I'll split out the atomic conversion patch.

Thanks,
Xin
> 
> >
> > Thanks,
> > Xin
> > >
> > > On Tue, 9 Nov 2021 at 03:42, Xin Ji  wrote:
> > > >
> > > > This patch provides HDCP setting interface for userspace to dynamic
> > > > enable/disable HDCP function.
> > > >
> > > > Signed-off-by: Xin Ji 
> > > > ---
> > > >  drivers/gpu/drm/bridge/analogix/anx7625.c | 368 +-
> > > >  drivers/gpu/drm/bridge/analogix/anx7625.h |  69 +++-
> > > >  2 files changed, 425 insertions(+), 12 deletions(-)
> > > >
> > > > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> > > > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > index 001fb39d9919..6d93026c2999 100644
> > > > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > > > @@ -26,6 +26,7 @@
> > > >  #include 
> > > >  #include 
> > > >  #include 
> > > > +#include 
> > > >  #include 
> > > >  #include 
> > > >  #include 
> > > > @@ -213,6 +214,60 @@ static int wait_aux_op_finish(struct anx7625_data 
> > > > *ctx)
> > > > return 0;
> > > >  }
> > > >
> > > > +static int anx7625_aux_dpcd_read(struct anx7625_data *ctx,
> > > > +u8 addrh, u8 addrm, u8 addrl,
> > > > +u8 len, u8 *buf)
> > > > +{
> > > > +   struct device *dev = >client->dev;
> > > > +   int ret;
> > > > +   u8 cmd;
> > > > +
> > > > +   if (len > MAX_DPCD_BUFFER_SIZE) {
> > > > +   DRM_DEV_ERROR(dev, "exceed aux buffer len.\n");
> > > > +   return -EINVAL;
> > > > +   }
> > > > +
> > > > +   cmd = ((len - 1) << 4) | 0x09;
> > > > +
> > > > +   /* Set command and length */
> > > > +   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
> > > > +   AP_AUX_COMMAND, cmd);
> > > > +
> > > > +   /* Set aux access address */
> > > > +   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
> > > > +AP_AUX_ADDR_7_0, addrl);
> > > > +   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
> > > > +AP_AUX_ADDR_15_8, addrm);
> > > > +   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
> > > > +AP_AUX_ADDR_19_16, addrh);
> > > > +
> > > > +   /* Enable aux access */
> > > > +   ret |= anx7625_write_or(ctx, ctx->i2c.rx_p0_client,
> > > > +   AP_AUX_CTRL_STATUS, AP_AUX_CTRL_OP_EN);
> > > > +
> > > > +   if (ret < 0) {
> > > > +   DRM_DEV_ERROR(dev, "cannot access aux related 
> > > > register.\n");
> > > > +   return -EIO;
> > > > +   }
> > > > +
> > > > +   usleep_range(2000, 2100);
> > > > +
> > > > +   ret = wait_aux_op_finish(ctx);
> > > > +   if (ret) {
> > > > +   DRM_DEV_ERROR(dev, "aux IO error: wait aux op 
> > > > finish.\n");
> > > > +   return ret;
> > > > +   }
> > > > +
> > > > +   ret = anx7625_reg_block_read(ctx, ctx->i2c.rx_p0_client,
> > > > +AP_AUX_BUFF_START, len, buf);
> > > > +   if (ret < 0) {
> > > > +   DRM_DEV_ERROR(dev, "read dpcd register failed\n");
>

Re: [PATCH 1/2] drm/bridge: anx7625: add HDCP support

2022-01-04 Thread Xin Ji
On Tue, Jan 04, 2022 at 03:50:34PM +0100, Robert Foss wrote:
> Hey Xin,
Hi Robert Foss, thanks for the reply.
As HDCP config interface "anx7625_hdcp_config(..)" need be called in
anx7625_connector_atomic_check(...) interface, so I cannot split out
atomic conversion patch.

Thanks,
Xin
> 
> On Tue, 9 Nov 2021 at 03:42, Xin Ji  wrote:
> >
> > This patch provides HDCP setting interface for userspace to dynamic
> > enable/disable HDCP function.
> >
> > Signed-off-by: Xin Ji 
> > ---
> >  drivers/gpu/drm/bridge/analogix/anx7625.c | 368 +-
> >  drivers/gpu/drm/bridge/analogix/anx7625.h |  69 +++-
> >  2 files changed, 425 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > index 001fb39d9919..6d93026c2999 100644
> > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > @@ -26,6 +26,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -213,6 +214,60 @@ static int wait_aux_op_finish(struct anx7625_data *ctx)
> > return 0;
> >  }
> >
> > +static int anx7625_aux_dpcd_read(struct anx7625_data *ctx,
> > +u8 addrh, u8 addrm, u8 addrl,
> > +u8 len, u8 *buf)
> > +{
> > +   struct device *dev = >client->dev;
> > +   int ret;
> > +   u8 cmd;
> > +
> > +   if (len > MAX_DPCD_BUFFER_SIZE) {
> > +   DRM_DEV_ERROR(dev, "exceed aux buffer len.\n");
> > +   return -EINVAL;
> > +   }
> > +
> > +   cmd = ((len - 1) << 4) | 0x09;
> > +
> > +   /* Set command and length */
> > +   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
> > +   AP_AUX_COMMAND, cmd);
> > +
> > +   /* Set aux access address */
> > +   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
> > +AP_AUX_ADDR_7_0, addrl);
> > +   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
> > +AP_AUX_ADDR_15_8, addrm);
> > +   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
> > +AP_AUX_ADDR_19_16, addrh);
> > +
> > +   /* Enable aux access */
> > +   ret |= anx7625_write_or(ctx, ctx->i2c.rx_p0_client,
> > +   AP_AUX_CTRL_STATUS, AP_AUX_CTRL_OP_EN);
> > +
> > +   if (ret < 0) {
> > +   DRM_DEV_ERROR(dev, "cannot access aux related register.\n");
> > +   return -EIO;
> > +   }
> > +
> > +   usleep_range(2000, 2100);
> > +
> > +   ret = wait_aux_op_finish(ctx);
> > +   if (ret) {
> > +   DRM_DEV_ERROR(dev, "aux IO error: wait aux op finish.\n");
> > +   return ret;
> > +   }
> > +
> > +   ret = anx7625_reg_block_read(ctx, ctx->i2c.rx_p0_client,
> > +AP_AUX_BUFF_START, len, buf);
> > +   if (ret < 0) {
> > +   DRM_DEV_ERROR(dev, "read dpcd register failed\n");
> > +   return -EIO;
> > +   }
> > +
> > +   return 0;
> > +}
> > +
> >  static int anx7625_video_mute_control(struct anx7625_data *ctx,
> >   u8 status)
> >  {
> > @@ -669,6 +724,160 @@ static int anx7625_dpi_config(struct anx7625_data 
> > *ctx)
> > return ret;
> >  }
> >
> > +static int anx7625_read_flash_status(struct anx7625_data *ctx)
> > +{
> > +   return anx7625_reg_read(ctx, ctx->i2c.rx_p0_client, R_RAM_CTRL);
> > +}
> > +
> > +static int anx7625_hdcp_key_probe(struct anx7625_data *ctx)
> > +{
> > +   int ret, val;
> > +   struct device *dev = >client->dev;
> > +   u8 ident[32];
> 
> Could this hardcoded array length be replaced with FLASH_BUF_LEN?
> 
> > +
> > +   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
> > +   FLASH_ADDR_HIGH, 0x91);
> > +   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
> > +FLASH_ADDR_LOW, 0xA0);
> > +   if (ret < 0) {
> > +   DRM_DEV_ERROR(dev, "IO error : set key flash address.\n");
> > 

[PATCH v2] drm/bridge: anx7625: Check GPIO description to avoid crash

2021-11-18 Thread Xin Ji
As GPIO probe function "devm_gpiod_get_optional()" may return error
code, driver should identify GPIO desc as NULL to avoid crash.

Acked-by: Tzung-Bi Shih 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 001fb39d9919..652ae814246d 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1098,9 +1098,18 @@ static void anx7625_init_gpio(struct anx7625_data 
*platform)
/* Gpio for chip power enable */
platform->pdata.gpio_p_on =
devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW);
+   if (IS_ERR_OR_NULL(platform->pdata.gpio_p_on)) {
+   DRM_DEV_DEBUG_DRIVER(dev, "no enable gpio found\n");
+   platform->pdata.gpio_p_on = NULL;
+   }
+
/* Gpio for chip reset */
platform->pdata.gpio_reset =
devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+   if (IS_ERR_OR_NULL(platform->pdata.gpio_reset)) {
+   DRM_DEV_DEBUG_DRIVER(dev, "no reset gpio found\n");
+   platform->pdata.gpio_reset = NULL;
+   }
 
if (platform->pdata.gpio_p_on && platform->pdata.gpio_reset) {
platform->pdata.low_power_mode = 1;
-- 
2.25.1



Re: [PATCH v2] drm/bridge: anx7625: Fix edid_read break case in sp_tx_edid_read()

2021-11-18 Thread Xin Ji
On Fri, Nov 19, 2021 at 03:30:02AM +0800, Hsin-Yi Wang wrote:
> edid_read() was assumed to return 0 on success. After
> 7f16d0f3b8e2("drm/bridge: anx7625: Propagate errors from sp_tx_rst_aux()"),
> the function will return > 0 for successful case, representing the i2c
> read bytes. Otherwise -EIO on failure cases. Update the g_edid_break
> break condition accordingly.
Hi Hsin-Yi, thanks for the patch!
Reviewed-by: Xin Ji 
> 
> Fixes: 7f16d0f3b8e2("drm/bridge: anx7625: Propagate errors from 
> sp_tx_rst_aux()")
> Signed-off-by: Hsin-Yi Wang 
> Reviewed-by: Robert Foss 
> ---
> v2: Fix type error.
> ---
>  drivers/gpu/drm/bridge/analogix/anx7625.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> b/drivers/gpu/drm/bridge/analogix/anx7625.c
> index 1a871f6b6822ee..3a18f1dabcfd51 100644
> --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> @@ -795,7 +795,7 @@ static int sp_tx_edid_read(struct anx7625_data *ctx,
>   int count, blocks_num;
>   u8 pblock_buf[MAX_DPCD_BUFFER_SIZE];
>   u8 i, j;
> - u8 g_edid_break = 0;
> + int g_edid_break = 0;
>   int ret;
>   struct device *dev = >client->dev;
>  
> @@ -826,7 +826,7 @@ static int sp_tx_edid_read(struct anx7625_data *ctx,
>   g_edid_break = edid_read(ctx, offset,
>pblock_buf);
>  
> - if (g_edid_break)
> + if (g_edid_break < 0)
>   break;
>  
>   memcpy(_blocks_buf[offset],
> -- 
> 2.34.0.rc2.393.gf8c9666880-goog


[PATCH v3] drm/bridge: anx7625: Check GPIO description to avoid crash

2021-11-17 Thread Xin Ji
As GPIO probe function "devm_gpiod_get_optional()" may return error
code, driver should identify GPIO desc as NULL to avoid crash.

Acked-by: Tzung-Bi Shih 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 001fb39d9919..652ae814246d 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1098,9 +1098,18 @@ static void anx7625_init_gpio(struct anx7625_data 
*platform)
/* Gpio for chip power enable */
platform->pdata.gpio_p_on =
devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW);
+   if (IS_ERR_OR_NULL(platform->pdata.gpio_p_on)) {
+   DRM_DEV_DEBUG_DRIVER(dev, "no enable gpio found\n");
+   platform->pdata.gpio_p_on = NULL;
+   }
+
/* Gpio for chip reset */
platform->pdata.gpio_reset =
devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+   if (IS_ERR_OR_NULL(platform->pdata.gpio_reset)) {
+   DRM_DEV_DEBUG_DRIVER(dev, "no reset gpio found\n");
+   platform->pdata.gpio_reset = NULL;
+   }
 
if (platform->pdata.gpio_p_on && platform->pdata.gpio_reset) {
platform->pdata.low_power_mode = 1;
-- 
2.25.1



[PATCH v2] drm/bridge: anx7625: Check GPIO description to avoid crash

2021-11-17 Thread Xin Ji
As GPIO probe function "devm_gpiod_get_optional()" may return error
code, driver should identify GPIO desc as NULL to avoid crash.

Acked-by: Tzung-Bi Shih 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 001fb39d9919..a872cfaf6257 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1098,9 +1098,18 @@ static void anx7625_init_gpio(struct anx7625_data 
*platform)
/* Gpio for chip power enable */
platform->pdata.gpio_p_on =
devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW);
+   if (IS_ERR_OR_NULL(platform->pdata.gpio_p_on)) {
+   DRM_DEV_DEBUG_DRIVER(dev, "no enable gpio found\n");
+   platform->pdata.gpio_p_on = NULL;
+   }
+
/* Gpio for chip reset */
platform->pdata.gpio_reset =
devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+   if (IS_ERR_OR_NULL(platform->pdata.gpio_reset)) {
+   DRM_DEV_DEBUG_DRIVER(dev, "no reset gpio found\n");
+   platform->pdata.gpio_p_on = NULL;
+   }
 
if (platform->pdata.gpio_p_on && platform->pdata.gpio_reset) {
platform->pdata.low_power_mode = 1;
-- 
2.25.1



Re: [PATCH] drm/bridge: anx7625: Check GPIO description to avoid crash

2021-11-17 Thread Xin Ji
On Thu, Nov 18, 2021 at 12:52:14PM +0800, Tzung-Bi Shih wrote:
> On Thu, Nov 18, 2021 at 11:11 AM Xin Ji  wrote:
> > @@ -1098,9 +1098,18 @@ static void anx7625_init_gpio(struct anx7625_data 
> > *platform)
> > /* Gpio for chip power enable */
> > platform->pdata.gpio_p_on =
> > devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW);
> > +   if (IS_ERR(platform->pdata.gpio_p_on)) {
> > +   DRM_DEV_DEBUG_DRIVER(dev, "no enable gpio found\n");
> > +   platform->pdata.gpio_p_on = NULL;
> > +   }
> > +
> > /* Gpio for chip reset */
> > platform->pdata.gpio_reset =
> > devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
> > +   if (IS_ERR(platform->pdata.gpio_reset)) {
> > +   DRM_DEV_DEBUG_DRIVER(dev, "no reset gpio found\n");
> > +   platform->pdata.gpio_p_on = NULL;
> > +   }
> >
> > if (platform->pdata.gpio_p_on && platform->pdata.gpio_reset) {
> > platform->pdata.low_power_mode = 1;
> 
> devm_gpiod_get_optional() is possible to return NULL (see
> https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Felixir.bootlin.com%2Flinux%2Fv5.15.2%2Fsource%2Fdrivers%2Fgpio%2Fgpiolib-devres.c%23L250data=04%7C01%7Cxji%40analogixsemi.com%7C40e84a44676149c2544a08d9aa4f37f0%7Cb099b0b4f26c4cf59a0fd5be9acab205%7C0%7C0%7C637728079481953910%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000sdata=2UPuAadtM%2FObwkwE6fLhJr7uCfWN%2Fr29o4t8uqUU2Ls%3Dreserved=0).
> Thus, we should use IS_ERR_OR_NULL for checking the return value.
Hi Tzung-Bi Shih, IS_ERR_OR_NULL is better, I'll use it.

Thanks,
Xin
> 
> The cases here would work fine except it will skip to print some
> informative messages.
> 
> Acked-by: Tzung-Bi Shih 


[PATCH] drm/bridge: anx7625: Check GPIO description to avoid crash

2021-11-17 Thread Xin Ji
As GPIO probe function "devm_gpiod_get_optional()" may return error
code, driver should identify GPIO desc as NULL to avoid crash.

Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 001fb39d9919..36e0ae5a1c7b 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1098,9 +1098,18 @@ static void anx7625_init_gpio(struct anx7625_data 
*platform)
/* Gpio for chip power enable */
platform->pdata.gpio_p_on =
devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW);
+   if (IS_ERR(platform->pdata.gpio_p_on)) {
+   DRM_DEV_DEBUG_DRIVER(dev, "no enable gpio found\n");
+   platform->pdata.gpio_p_on = NULL;
+   }
+
/* Gpio for chip reset */
platform->pdata.gpio_reset =
devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+   if (IS_ERR(platform->pdata.gpio_reset)) {
+   DRM_DEV_DEBUG_DRIVER(dev, "no reset gpio found\n");
+   platform->pdata.gpio_p_on = NULL;
+   }
 
if (platform->pdata.gpio_p_on && platform->pdata.gpio_reset) {
platform->pdata.low_power_mode = 1;
-- 
2.25.1



Re: [bug report] drm/bridge: anx7625: Add anx7625 MIPI DSI/DPI to DP

2021-11-17 Thread Xin Ji
On Wed, Nov 17, 2021 at 04:47:20PM +0300, Dan Carpenter wrote:
> Hello Xin Ji,
> 
> The patch 8bdfc5dae4e3: "drm/bridge: anx7625: Add anx7625 MIPI
> DSI/DPI to DP" from Sep 18, 2020, leads to the following Smatch
> static checker warning:
> 
>   drivers/gpu/drm/bridge/analogix/anx7625.c:1050 anx7625_init_gpio()
>   warn: 'platform->pdata.gpio_p_on' could be an error pointer
> 
>   drivers/gpu/drm/bridge/analogix/anx7625.c:1050 anx7625_init_gpio()
>   warn: 'platform->pdata.gpio_reset' could be an error pointer

Hi Dan Carpenter, thanks for the report, I'll upstream a patch to fix it.

Thanks,
Xin
> 
> drivers/gpu/drm/bridge/analogix/anx7625.c
> 1037 static void anx7625_init_gpio(struct anx7625_data *platform)
> 1038 {
> 1039 struct device *dev = >client->dev;
> 1040 
> 1041 DRM_DEV_DEBUG_DRIVER(dev, "init gpio\n");
> 1042 
> 1043 /* Gpio for chip power enable */
> 1044 platform->pdata.gpio_p_on =
> 1045 devm_gpiod_get_optional(dev, "enable", 
> GPIOD_OUT_LOW);
> 1046 /* Gpio for chip reset */
> 1047 platform->pdata.gpio_reset =
> 1048 devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
> 1049 
> --> 1050 if (platform->pdata.gpio_p_on && platform->pdata.gpio_reset) 
> {
> 1051 platform->pdata.low_power_mode = 1;
> 1052 DRM_DEV_DEBUG_DRIVER(dev, "low power mode, pon %d, 
> reset %d.\n",
> 1053  
> desc_to_gpio(platform->pdata.gpio_p_on),
>
> ^
> 1054  
> desc_to_gpio(platform->pdata.gpio_reset));
>
> ^^
> This will crash here but only when there is an error and debugging is
> enabled.
> 
> 1055 } else {
> 1056 platform->pdata.low_power_mode = 0;
> 1057 DRM_DEV_DEBUG_DRIVER(dev, "not low power mode.\n");
> 1058 }
> 1059 }
> 
> regards,
> dan carpenter


[PATCH 2/2] drm/bridge: anx7625: add audio codec .get_eld support

2021-11-08 Thread Xin Ji
Provide .get_eld interface in hdmi_codec_ops for hdmi-codec driver.

Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 6d93026c2999..67a87d21b0ba 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1821,9 +1821,27 @@ static int anx7625_audio_hook_plugged_cb(struct device 
*dev, void *data,
return 0;
 }
 
+static int anx7625_audio_get_eld(struct device *dev, void *data,
+u8 *buf, size_t len)
+{
+   struct anx7625_data *ctx = dev_get_drvdata(dev);
+
+   if (!ctx->connector) {
+   DRM_DEV_DEBUG_DRIVER(dev, "connector not initial\n");
+   return -EINVAL;
+   }
+
+   DRM_DEV_DEBUG_DRIVER(dev, "audio copy eld\n");
+   memcpy(buf, ctx->connector->eld,
+  min(sizeof(ctx->connector->eld), len));
+
+   return 0;
+}
+
 static const struct hdmi_codec_ops anx7625_codec_ops = {
.hw_params  = anx7625_audio_hw_params,
.audio_shutdown = anx7625_audio_shutdown,
+   .get_eld= anx7625_audio_get_eld,
.get_dai_id = anx7625_hdmi_i2s_get_dai_id,
.hook_plugged_cb = anx7625_audio_hook_plugged_cb,
 };
-- 
2.25.1



[PATCH 1/2] drm/bridge: anx7625: add HDCP support

2021-11-08 Thread Xin Ji
This patch provides HDCP setting interface for userspace to dynamic
enable/disable HDCP function.

Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 368 +-
 drivers/gpu/drm/bridge/analogix/anx7625.h |  69 +++-
 2 files changed, 425 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 001fb39d9919..6d93026c2999 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -213,6 +214,60 @@ static int wait_aux_op_finish(struct anx7625_data *ctx)
return 0;
 }
 
+static int anx7625_aux_dpcd_read(struct anx7625_data *ctx,
+u8 addrh, u8 addrm, u8 addrl,
+u8 len, u8 *buf)
+{
+   struct device *dev = >client->dev;
+   int ret;
+   u8 cmd;
+
+   if (len > MAX_DPCD_BUFFER_SIZE) {
+   DRM_DEV_ERROR(dev, "exceed aux buffer len.\n");
+   return -EINVAL;
+   }
+
+   cmd = ((len - 1) << 4) | 0x09;
+
+   /* Set command and length */
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   AP_AUX_COMMAND, cmd);
+
+   /* Set aux access address */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+AP_AUX_ADDR_7_0, addrl);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+AP_AUX_ADDR_15_8, addrm);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+AP_AUX_ADDR_19_16, addrh);
+
+   /* Enable aux access */
+   ret |= anx7625_write_or(ctx, ctx->i2c.rx_p0_client,
+   AP_AUX_CTRL_STATUS, AP_AUX_CTRL_OP_EN);
+
+   if (ret < 0) {
+   DRM_DEV_ERROR(dev, "cannot access aux related register.\n");
+   return -EIO;
+   }
+
+   usleep_range(2000, 2100);
+
+   ret = wait_aux_op_finish(ctx);
+   if (ret) {
+   DRM_DEV_ERROR(dev, "aux IO error: wait aux op finish.\n");
+   return ret;
+   }
+
+   ret = anx7625_reg_block_read(ctx, ctx->i2c.rx_p0_client,
+AP_AUX_BUFF_START, len, buf);
+   if (ret < 0) {
+   DRM_DEV_ERROR(dev, "read dpcd register failed\n");
+   return -EIO;
+   }
+
+   return 0;
+}
+
 static int anx7625_video_mute_control(struct anx7625_data *ctx,
  u8 status)
 {
@@ -669,6 +724,160 @@ static int anx7625_dpi_config(struct anx7625_data *ctx)
return ret;
 }
 
+static int anx7625_read_flash_status(struct anx7625_data *ctx)
+{
+   return anx7625_reg_read(ctx, ctx->i2c.rx_p0_client, R_RAM_CTRL);
+}
+
+static int anx7625_hdcp_key_probe(struct anx7625_data *ctx)
+{
+   int ret, val;
+   struct device *dev = >client->dev;
+   u8 ident[32];
+
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   FLASH_ADDR_HIGH, 0x91);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+FLASH_ADDR_LOW, 0xA0);
+   if (ret < 0) {
+   DRM_DEV_ERROR(dev, "IO error : set key flash address.\n");
+   return ret;
+   }
+
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   FLASH_LEN_HIGH, (FLASH_BUF_LEN - 1) >> 8);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+FLASH_LEN_LOW, (FLASH_BUF_LEN - 1) & 0xFF);
+   if (ret < 0) {
+   DRM_DEV_ERROR(dev, "IO error : set key flash len.\n");
+   return ret;
+   }
+
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   R_FLASH_RW_CTRL, FLASH_READ);
+   ret |= readx_poll_timeout(anx7625_read_flash_status,
+ ctx, val,
+ ((val & FLASH_DONE) || (val < 0)),
+ 2000,
+ 2000 * 150);
+   if (ret) {
+   DRM_DEV_ERROR(dev, "flash read access fail!\n");
+   return -EIO;
+   }
+
+   ret = anx7625_reg_block_read(ctx, ctx->i2c.rx_p0_client,
+FLASH_BUF_BASE_ADDR,
+FLASH_BUF_LEN, ident);
+   if (ret < 0) {
+   DRM_DEV_ERROR(dev, "read flash data fail!\n");
+   return -EIO;
+   }
+
+   if (ident[29] == 0xFF && ident[30] == 0xFF && ident[31] == 0xFF)
+   return -EINVAL;
+
+   return 0;
+}
+
+static int anx7625_hdcp_key_

[PATCH v12 4/4] drm/bridge: anx7625: add HDMI audio function

2021-11-04 Thread Xin Ji
Add audio HDMI codec function support, enable it through device true
flag "analogix,audio-enable".

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 226 ++
 drivers/gpu/drm/bridge/analogix/anx7625.h |   5 +
 2 files changed, 231 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index f7c3386c8929..001fb39d9919 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -33,6 +33,7 @@
 #include 
 
 #include 
+#include 
 #include 
 
 #include "anx7625.h"
@@ -153,6 +154,20 @@ static int anx7625_write_and(struct anx7625_data *ctx,
return anx7625_reg_write(ctx, client, offset, (val & (mask)));
 }
 
+static int anx7625_write_and_or(struct anx7625_data *ctx,
+   struct i2c_client *client,
+   u8 offset, u8 and_mask, u8 or_mask)
+{
+   int val;
+
+   val = anx7625_reg_read(ctx, client, offset);
+   if (val < 0)
+   return val;
+
+   return anx7625_reg_write(ctx, client,
+offset, (val & and_mask) | (or_mask));
+}
+
 static int anx7625_config_bit_matrix(struct anx7625_data *ctx)
 {
int i, ret;
@@ -1353,6 +1368,9 @@ static int anx7625_parse_dt(struct device *dev,
else
DRM_DEV_DEBUG_DRIVER(dev, "found MIPI DSI host node.\n");
 
+   if (of_property_read_bool(np, "analogix,audio-enable"))
+   pdata->audio_en = 1;
+
ret = drm_of_find_panel_or_bridge(np, 1, 0, , NULL);
if (ret < 0) {
if (ret == -ENODEV)
@@ -1423,6 +1441,208 @@ static enum drm_connector_status 
anx7625_sink_detect(struct anx7625_data *ctx)
 connector_status_disconnected;
 }
 
+static int anx7625_audio_hw_params(struct device *dev, void *data,
+  struct hdmi_codec_daifmt *fmt,
+  struct hdmi_codec_params *params)
+{
+   struct anx7625_data *ctx = dev_get_drvdata(dev);
+   int wl, ch, rate;
+   int ret = 0;
+
+   if (fmt->fmt != HDMI_DSP_A) {
+   DRM_DEV_ERROR(dev, "only supports DSP_A\n");
+   return -EINVAL;
+   }
+
+   DRM_DEV_DEBUG_DRIVER(dev, "setting %d Hz, %d bit, %d channels\n",
+params->sample_rate, params->sample_width,
+params->cea.channels);
+
+   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_6,
+   ~I2S_SLAVE_MODE,
+   TDM_SLAVE_MODE);
+
+   /* Word length */
+   switch (params->sample_width) {
+   case 16:
+   wl = AUDIO_W_LEN_16_20MAX;
+   break;
+   case 18:
+   wl = AUDIO_W_LEN_18_20MAX;
+   break;
+   case 20:
+   wl = AUDIO_W_LEN_20_20MAX;
+   break;
+   case 24:
+   wl = AUDIO_W_LEN_24_24MAX;
+   break;
+   default:
+   DRM_DEV_DEBUG_DRIVER(dev, "wordlength: %d bit not support",
+params->sample_width);
+   return -EINVAL;
+   }
+   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_5,
+   0xf0, wl);
+
+   /* Channel num */
+   switch (params->cea.channels) {
+   case 2:
+   ch = I2S_CH_2;
+   break;
+   case 4:
+   ch = TDM_CH_4;
+   break;
+   case 6:
+   ch = TDM_CH_6;
+   break;
+   case 8:
+   ch = TDM_CH_8;
+   break;
+   default:
+   DRM_DEV_DEBUG_DRIVER(dev, "channel number: %d not support",
+params->cea.channels);
+   return -EINVAL;
+   }
+   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+  AUDIO_CHANNEL_STATUS_6, 0x1f, ch << 5);
+   if (ch > I2S_CH_2)
+   ret |= anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_6, AUDIO_LAYOUT);
+   else
+   ret |= anx7625_write_and(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_6, ~AUDIO_LAYOUT);
+
+   /* FS */
+   switch (params->sample_rate) {
+   case 32000:
+   rate = AUDIO_FS_32K;
+   break;
+   case 44100:
+   rate = AUDIO_FS_441K;
+   break;
+   case 48000:
+   rate = AUDIO_FS_48K;
+   break;
+   case 88200:
+   

[PATCH v12 3/4] drm/bridge: anx7625: add MIPI DPI input feature

2021-11-04 Thread Xin Ji
The basic anx7625 driver only support MIPI DSI rx signal input.
This patch add MIPI DPI rx input configuration support, after apply
this patch, the driver can support DSI rx or DPI rx by adding
'bus-type' in DT.

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 247 --
 drivers/gpu/drm/bridge/analogix/anx7625.h |  18 +-
 2 files changed, 205 insertions(+), 60 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index f48e91134c20..f7c3386c8929 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -32,6 +32,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 #include "anx7625.h"
@@ -152,18 +153,18 @@ static int anx7625_write_and(struct anx7625_data *ctx,
return anx7625_reg_write(ctx, client, offset, (val & (mask)));
 }
 
-static int anx7625_write_and_or(struct anx7625_data *ctx,
-   struct i2c_client *client,
-   u8 offset, u8 and_mask, u8 or_mask)
+static int anx7625_config_bit_matrix(struct anx7625_data *ctx)
 {
-   int val;
+   int i, ret;
 
-   val = anx7625_reg_read(ctx, client, offset);
-   if (val < 0)
-   return val;
+   ret = anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
+  AUDIO_CONTROL_REGISTER, 0x80);
+   for (i = 0; i < 13; i++)
+   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
+VIDEO_BIT_MATRIX_12 + i,
+0x18 + i);
 
-   return anx7625_reg_write(ctx, client,
-offset, (val & and_mask) | (or_mask));
+   return ret;
 }
 
 static int anx7625_read_ctrl_status_p0(struct anx7625_data *ctx)
@@ -221,38 +222,6 @@ static int anx7625_video_mute_control(struct anx7625_data 
*ctx,
return ret;
 }
 
-static int anx7625_config_audio_input(struct anx7625_data *ctx)
-{
-   struct device *dev = >client->dev;
-   int ret;
-
-   /* Channel num */
-   ret = anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_6, I2S_CH_2 << 5);
-
-   /* FS */
-   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_4,
-   0xf0, AUDIO_FS_48K);
-   /* Word length */
-   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_5,
-   0xf0, AUDIO_W_LEN_24_24MAX);
-   /* I2S */
-   ret |= anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_6, I2S_SLAVE_MODE);
-   ret |= anx7625_write_and(ctx, ctx->i2c.tx_p2_client,
-AUDIO_CONTROL_REGISTER, ~TDM_TIMING_MODE);
-   /* Audio change flag */
-   ret |= anx7625_write_or(ctx, ctx->i2c.rx_p0_client,
-   AP_AV_STATUS, AP_AUDIO_CHG);
-
-   if (ret < 0)
-   DRM_DEV_ERROR(dev, "fail to config audio.\n");
-
-   return ret;
-}
-
 /* Reduction of fraction a/b */
 static void anx7625_reduction_of_a_fraction(unsigned long *a, unsigned long *b)
 {
@@ -431,7 +400,7 @@ static int anx7625_dsi_video_timing_config(struct 
anx7625_data *ctx)
ret |= anx7625_write_and(ctx, ctx->i2c.rx_p1_client,
MIPI_LANE_CTRL_0, 0xfc);
ret |= anx7625_write_or(ctx, ctx->i2c.rx_p1_client,
-   MIPI_LANE_CTRL_0, 3);
+   MIPI_LANE_CTRL_0, ctx->pdata.mipi_lanes - 1);
 
/* Htotal */
htotal = ctx->dt.hactive.min + ctx->dt.hfront_porch.min +
@@ -615,6 +584,76 @@ static int anx7625_dsi_config(struct anx7625_data *ctx)
return ret;
 }
 
+static int anx7625_api_dpi_config(struct anx7625_data *ctx)
+{
+   struct device *dev = >client->dev;
+   u16 freq = ctx->dt.pixelclock.min / 1000;
+   int ret;
+
+   /* configure pixel clock */
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   PIXEL_CLOCK_L, freq & 0xFF);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+PIXEL_CLOCK_H, (freq >> 8));
+
+   /* set DPI mode */
+   /* set to DPI PLL module sel */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_DIGITAL_PLL_9, 0x20);
+   /* power down MIPI */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_LANE_CTRL_10, 0x08);
+   /* enable DPI mode */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+  

[PATCH v12 2/4] drm/bridge: anx7625: fix not correct return value

2021-11-04 Thread Xin Ji
At some time, the original code may return non zero value, force return 0
if operation finished.

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index d0317651cd75..f48e91134c20 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -191,10 +191,10 @@ static int wait_aux_op_finish(struct anx7625_data *ctx)
   AP_AUX_CTRL_STATUS);
if (val < 0 || (val & 0x0F)) {
DRM_DEV_ERROR(dev, "aux status %02x\n", val);
-   val = -EIO;
+   return -EIO;
}
 
-   return val;
+   return 0;
 }
 
 static int anx7625_video_mute_control(struct anx7625_data *ctx,
-- 
2.25.1



[PATCH v12 1/4] dt-bindings:drm/bridge:anx7625:add vendor define

2021-11-04 Thread Xin Ji
Add 'bus-type' and 'data-lanes' define for port0. Add DP tx lane0,
lane1 swing register setting array, and audio enable flag.

The device which cannot pass DP tx PHY CTS caused by long PCB trace or
embedded MUX, adjusting ANX7625 PHY parameters can pass the CTS test. The
adjusting type include Pre-emphasis, Vp-p, Rterm(Resistor Termination)
and Rsel(Driven Strength). Each lane has maximum 20 registers for
these settings.

Signed-off-by: Xin Ji 
Reviewed-by: Rob Herring 
---
 .../display/bridge/analogix,anx7625.yaml  | 65 ++-
 1 file changed, 63 insertions(+), 2 deletions(-)

diff --git 
a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml 
b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
index ab48ab2f4240..1d3e88daca04 100644
--- a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
+++ b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
@@ -43,14 +43,70 @@ properties:
   vdd33-supply:
 description: Regulator that provides the supply 3.3V power.
 
+  analogix,lane0-swing:
+$ref: /schemas/types.yaml#/definitions/uint8-array
+minItems: 1
+maxItems: 20
+description:
+  an array of swing register setting for DP tx lane0 PHY.
+  Registers 0~9 are Swing0_Pre0, Swing1_Pre0, Swing2_Pre0,
+  Swing3_Pre0, Swing0_Pre1, Swing1_Pre1, Swing2_Pre1, Swing0_Pre2,
+  Swing1_Pre2, Swing0_Pre3, they are for [Boost control] and
+  [Swing control] setting.
+  Registers 0~9, bit 3:0 is [Boost control], these bits control
+  post cursor manual, increase the [Boost control] to increase
+  Pre-emphasis value.
+  Registers 0~9, bit 6:4 is [Swing control], these bits control
+  swing manual, increase [Swing control] setting to add Vp-p value
+  for each Swing, Pre.
+  Registers 10~19 are Swing0_Pre0, Swing1_Pre0, Swing2_Pre0,
+  Swing3_Pre0, Swing0_Pre1, Swing1_Pre1, Swing2_Pre1, Swing0_Pre2,
+  Swing1_Pre2, Swing0_Pre3, they are for [R select control] and
+  [R Termination control] setting.
+  Registers 10~19, bit 4:0 is [R select control], these bits are
+  compensation manual, increase it can enhance IO driven strength
+  and Vp-p.
+  Registers 10~19, bit 5:6 is [R termination control], these bits
+  adjust 50ohm impedance of DP tx termination. 00:55 ohm,
+  01:50 ohm(default), 10:45 ohm, 11:40 ohm.
+
+  analogix,lane1-swing:
+$ref: /schemas/types.yaml#/definitions/uint8-array
+minItems: 1
+maxItems: 20
+description:
+  an array of swing register setting for DP tx lane1 PHY.
+  DP TX lane1 swing register setting same with lane0
+  swing, please refer lane0-swing property description.
+
+  analogix,audio-enable:
+type: boolean
+description: let the driver enable audio HDMI codec function or not.
+
   ports:
 $ref: /schemas/graph.yaml#/properties/ports
 
 properties:
   port@0:
-$ref: /schemas/graph.yaml#/properties/port
+$ref: /schemas/graph.yaml#/$defs/port-base
+unevaluatedProperties: false
 description:
-  Video port for MIPI DSI input.
+  MIPI DSI/DPI input.
+
+properties:
+  endpoint:
+$ref: /schemas/media/video-interfaces.yaml#
+type: object
+additionalProperties: false
+
+properties:
+  remote-endpoint: true
+
+  bus-type:
+enum: [1, 5]
+default: 1
+
+  data-lanes: true
 
   port@1:
 $ref: /schemas/graph.yaml#/properties/port
@@ -87,6 +143,9 @@ examples:
 vdd10-supply = <_mipibrdg>;
 vdd18-supply = <_mipibrdg>;
 vdd33-supply = <_mipibrdg>;
+analogix,audio-enable;
+analogix,lane0-swing = /bits/ 8 <0x14 0x54 0x64 0x74>;
+analogix,lane1-swing = /bits/ 8 <0x14 0x54 0x64 0x74>;
 
 ports {
 #address-cells = <1>;
@@ -96,6 +155,8 @@ examples:
 reg = <0>;
 anx7625_in: endpoint {
 remote-endpoint = <_dsi>;
+bus-type = <5>;
+data-lanes = <0 1 2 3>;
 };
 };
 
-- 
2.25.1



Re: [PATCH v12 0/4] Add MIPI rx DPI support

2021-11-04 Thread Xin Ji
On Thu, Nov 04, 2021 at 11:20:21AM +0100, Robert Foss wrote:
> Hey Xin,
> 
> Applied to drm-misc-next.
> 
> The way this series was submitted to the mailing list is not correct
> and is breaking a lot of tooling. It seems like you used git
> send-email, but the individual patches of the series are not connected
> properly and both b4 and the patchwork tools are not able to handle
> this series properly.
> 
> Please try to use git send-email along the lines of this:
> git send-email -$NBR_PATCHES_IN_SERIES -v$VERSION_OF_SERIES --annotate 
> --to=
Hi Rob, thanks for the comment, sorry about that. I'll submit v12 by
your command.

Xin
> 
> 
> Rob.


[PATCH v12 4/4] drm/bridge: anx7625: add HDMI audio function

2021-11-03 Thread Xin Ji
Add audio HDMI codec function support, enable it through device true
flag "analogix,audio-enable".

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 226 ++
 drivers/gpu/drm/bridge/analogix/anx7625.h |   5 +
 2 files changed, 231 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index f7c3386c8929..001fb39d9919 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -33,6 +33,7 @@
 #include 
 
 #include 
+#include 
 #include 
 
 #include "anx7625.h"
@@ -153,6 +154,20 @@ static int anx7625_write_and(struct anx7625_data *ctx,
return anx7625_reg_write(ctx, client, offset, (val & (mask)));
 }
 
+static int anx7625_write_and_or(struct anx7625_data *ctx,
+   struct i2c_client *client,
+   u8 offset, u8 and_mask, u8 or_mask)
+{
+   int val;
+
+   val = anx7625_reg_read(ctx, client, offset);
+   if (val < 0)
+   return val;
+
+   return anx7625_reg_write(ctx, client,
+offset, (val & and_mask) | (or_mask));
+}
+
 static int anx7625_config_bit_matrix(struct anx7625_data *ctx)
 {
int i, ret;
@@ -1353,6 +1368,9 @@ static int anx7625_parse_dt(struct device *dev,
else
DRM_DEV_DEBUG_DRIVER(dev, "found MIPI DSI host node.\n");
 
+   if (of_property_read_bool(np, "analogix,audio-enable"))
+   pdata->audio_en = 1;
+
ret = drm_of_find_panel_or_bridge(np, 1, 0, , NULL);
if (ret < 0) {
if (ret == -ENODEV)
@@ -1423,6 +1441,208 @@ static enum drm_connector_status 
anx7625_sink_detect(struct anx7625_data *ctx)
 connector_status_disconnected;
 }
 
+static int anx7625_audio_hw_params(struct device *dev, void *data,
+  struct hdmi_codec_daifmt *fmt,
+  struct hdmi_codec_params *params)
+{
+   struct anx7625_data *ctx = dev_get_drvdata(dev);
+   int wl, ch, rate;
+   int ret = 0;
+
+   if (fmt->fmt != HDMI_DSP_A) {
+   DRM_DEV_ERROR(dev, "only supports DSP_A\n");
+   return -EINVAL;
+   }
+
+   DRM_DEV_DEBUG_DRIVER(dev, "setting %d Hz, %d bit, %d channels\n",
+params->sample_rate, params->sample_width,
+params->cea.channels);
+
+   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_6,
+   ~I2S_SLAVE_MODE,
+   TDM_SLAVE_MODE);
+
+   /* Word length */
+   switch (params->sample_width) {
+   case 16:
+   wl = AUDIO_W_LEN_16_20MAX;
+   break;
+   case 18:
+   wl = AUDIO_W_LEN_18_20MAX;
+   break;
+   case 20:
+   wl = AUDIO_W_LEN_20_20MAX;
+   break;
+   case 24:
+   wl = AUDIO_W_LEN_24_24MAX;
+   break;
+   default:
+   DRM_DEV_DEBUG_DRIVER(dev, "wordlength: %d bit not support",
+params->sample_width);
+   return -EINVAL;
+   }
+   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_5,
+   0xf0, wl);
+
+   /* Channel num */
+   switch (params->cea.channels) {
+   case 2:
+   ch = I2S_CH_2;
+   break;
+   case 4:
+   ch = TDM_CH_4;
+   break;
+   case 6:
+   ch = TDM_CH_6;
+   break;
+   case 8:
+   ch = TDM_CH_8;
+   break;
+   default:
+   DRM_DEV_DEBUG_DRIVER(dev, "channel number: %d not support",
+params->cea.channels);
+   return -EINVAL;
+   }
+   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+  AUDIO_CHANNEL_STATUS_6, 0x1f, ch << 5);
+   if (ch > I2S_CH_2)
+   ret |= anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_6, AUDIO_LAYOUT);
+   else
+   ret |= anx7625_write_and(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_6, ~AUDIO_LAYOUT);
+
+   /* FS */
+   switch (params->sample_rate) {
+   case 32000:
+   rate = AUDIO_FS_32K;
+   break;
+   case 44100:
+   rate = AUDIO_FS_441K;
+   break;
+   case 48000:
+   rate = AUDIO_FS_48K;
+   break;
+   case 88200:
+   

[PATCH v12 3/4] drm/bridge: anx7625: add MIPI DPI input feature

2021-11-03 Thread Xin Ji
The basic anx7625 driver only support MIPI DSI rx signal input.
This patch add MIPI DPI rx input configuration support, after apply
this patch, the driver can support DSI rx or DPI rx by adding
'bus-type' in DT.

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 247 --
 drivers/gpu/drm/bridge/analogix/anx7625.h |  18 +-
 2 files changed, 205 insertions(+), 60 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index f48e91134c20..f7c3386c8929 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -32,6 +32,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 #include "anx7625.h"
@@ -152,18 +153,18 @@ static int anx7625_write_and(struct anx7625_data *ctx,
return anx7625_reg_write(ctx, client, offset, (val & (mask)));
 }
 
-static int anx7625_write_and_or(struct anx7625_data *ctx,
-   struct i2c_client *client,
-   u8 offset, u8 and_mask, u8 or_mask)
+static int anx7625_config_bit_matrix(struct anx7625_data *ctx)
 {
-   int val;
+   int i, ret;
 
-   val = anx7625_reg_read(ctx, client, offset);
-   if (val < 0)
-   return val;
+   ret = anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
+  AUDIO_CONTROL_REGISTER, 0x80);
+   for (i = 0; i < 13; i++)
+   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
+VIDEO_BIT_MATRIX_12 + i,
+0x18 + i);
 
-   return anx7625_reg_write(ctx, client,
-offset, (val & and_mask) | (or_mask));
+   return ret;
 }
 
 static int anx7625_read_ctrl_status_p0(struct anx7625_data *ctx)
@@ -221,38 +222,6 @@ static int anx7625_video_mute_control(struct anx7625_data 
*ctx,
return ret;
 }
 
-static int anx7625_config_audio_input(struct anx7625_data *ctx)
-{
-   struct device *dev = >client->dev;
-   int ret;
-
-   /* Channel num */
-   ret = anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_6, I2S_CH_2 << 5);
-
-   /* FS */
-   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_4,
-   0xf0, AUDIO_FS_48K);
-   /* Word length */
-   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_5,
-   0xf0, AUDIO_W_LEN_24_24MAX);
-   /* I2S */
-   ret |= anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_6, I2S_SLAVE_MODE);
-   ret |= anx7625_write_and(ctx, ctx->i2c.tx_p2_client,
-AUDIO_CONTROL_REGISTER, ~TDM_TIMING_MODE);
-   /* Audio change flag */
-   ret |= anx7625_write_or(ctx, ctx->i2c.rx_p0_client,
-   AP_AV_STATUS, AP_AUDIO_CHG);
-
-   if (ret < 0)
-   DRM_DEV_ERROR(dev, "fail to config audio.\n");
-
-   return ret;
-}
-
 /* Reduction of fraction a/b */
 static void anx7625_reduction_of_a_fraction(unsigned long *a, unsigned long *b)
 {
@@ -431,7 +400,7 @@ static int anx7625_dsi_video_timing_config(struct 
anx7625_data *ctx)
ret |= anx7625_write_and(ctx, ctx->i2c.rx_p1_client,
MIPI_LANE_CTRL_0, 0xfc);
ret |= anx7625_write_or(ctx, ctx->i2c.rx_p1_client,
-   MIPI_LANE_CTRL_0, 3);
+   MIPI_LANE_CTRL_0, ctx->pdata.mipi_lanes - 1);
 
/* Htotal */
htotal = ctx->dt.hactive.min + ctx->dt.hfront_porch.min +
@@ -615,6 +584,76 @@ static int anx7625_dsi_config(struct anx7625_data *ctx)
return ret;
 }
 
+static int anx7625_api_dpi_config(struct anx7625_data *ctx)
+{
+   struct device *dev = >client->dev;
+   u16 freq = ctx->dt.pixelclock.min / 1000;
+   int ret;
+
+   /* configure pixel clock */
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   PIXEL_CLOCK_L, freq & 0xFF);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+PIXEL_CLOCK_H, (freq >> 8));
+
+   /* set DPI mode */
+   /* set to DPI PLL module sel */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_DIGITAL_PLL_9, 0x20);
+   /* power down MIPI */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_LANE_CTRL_10, 0x08);
+   /* enable DPI mode */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+  

[PATCH v12 2/4] drm/bridge: anx7625: fix not correct return value

2021-11-03 Thread Xin Ji
At some time, the original code may return non zero value, force return 0
if operation finished.

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index d0317651cd75..f48e91134c20 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -191,10 +191,10 @@ static int wait_aux_op_finish(struct anx7625_data *ctx)
   AP_AUX_CTRL_STATUS);
if (val < 0 || (val & 0x0F)) {
DRM_DEV_ERROR(dev, "aux status %02x\n", val);
-   val = -EIO;
+   return -EIO;
}
 
-   return val;
+   return 0;
 }
 
 static int anx7625_video_mute_control(struct anx7625_data *ctx,
-- 
2.25.1



[PATCH v12 1/4] dt-bindings:drm/bridge:anx7625:add vendor define

2021-11-03 Thread Xin Ji
Add 'bus-type' and 'data-lanes' define for port0. Add DP tx lane0,
lane1 swing register setting array, and audio enable flag.

The device which cannot pass DP tx PHY CTS caused by long PCB trace or
embedded MUX, adjusting ANX7625 PHY parameters can pass the CTS test. The
adjusting type include Pre-emphasis, Vp-p, Rterm(Resistor Termination)
and Rsel(Driven Strength). Each lane has maximum 20 registers for
these settings.

Signed-off-by: Xin Ji 
Reviewed-by: Rob Herring 
---
 .../display/bridge/analogix,anx7625.yaml  | 65 ++-
 1 file changed, 63 insertions(+), 2 deletions(-)

diff --git 
a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml 
b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
index ab48ab2f4240..1d3e88daca04 100644
--- a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
+++ b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
@@ -43,14 +43,70 @@ properties:
   vdd33-supply:
 description: Regulator that provides the supply 3.3V power.
 
+  analogix,lane0-swing:
+$ref: /schemas/types.yaml#/definitions/uint8-array
+minItems: 1
+maxItems: 20
+description:
+  an array of swing register setting for DP tx lane0 PHY.
+  Registers 0~9 are Swing0_Pre0, Swing1_Pre0, Swing2_Pre0,
+  Swing3_Pre0, Swing0_Pre1, Swing1_Pre1, Swing2_Pre1, Swing0_Pre2,
+  Swing1_Pre2, Swing0_Pre3, they are for [Boost control] and
+  [Swing control] setting.
+  Registers 0~9, bit 3:0 is [Boost control], these bits control
+  post cursor manual, increase the [Boost control] to increase
+  Pre-emphasis value.
+  Registers 0~9, bit 6:4 is [Swing control], these bits control
+  swing manual, increase [Swing control] setting to add Vp-p value
+  for each Swing, Pre.
+  Registers 10~19 are Swing0_Pre0, Swing1_Pre0, Swing2_Pre0,
+  Swing3_Pre0, Swing0_Pre1, Swing1_Pre1, Swing2_Pre1, Swing0_Pre2,
+  Swing1_Pre2, Swing0_Pre3, they are for [R select control] and
+  [R Termination control] setting.
+  Registers 10~19, bit 4:0 is [R select control], these bits are
+  compensation manual, increase it can enhance IO driven strength
+  and Vp-p.
+  Registers 10~19, bit 5:6 is [R termination control], these bits
+  adjust 50ohm impedance of DP tx termination. 00:55 ohm,
+  01:50 ohm(default), 10:45 ohm, 11:40 ohm.
+
+  analogix,lane1-swing:
+$ref: /schemas/types.yaml#/definitions/uint8-array
+minItems: 1
+maxItems: 20
+description:
+  an array of swing register setting for DP tx lane1 PHY.
+  DP TX lane1 swing register setting same with lane0
+  swing, please refer lane0-swing property description.
+
+  analogix,audio-enable:
+type: boolean
+description: let the driver enable audio HDMI codec function or not.
+
   ports:
 $ref: /schemas/graph.yaml#/properties/ports
 
 properties:
   port@0:
-$ref: /schemas/graph.yaml#/properties/port
+$ref: /schemas/graph.yaml#/$defs/port-base
+unevaluatedProperties: false
 description:
-  Video port for MIPI DSI input.
+  MIPI DSI/DPI input.
+
+properties:
+  endpoint:
+$ref: /schemas/media/video-interfaces.yaml#
+type: object
+additionalProperties: false
+
+properties:
+  remote-endpoint: true
+
+  bus-type:
+enum: [1, 5]
+default: 1
+
+  data-lanes: true
 
   port@1:
 $ref: /schemas/graph.yaml#/properties/port
@@ -87,6 +143,9 @@ examples:
 vdd10-supply = <_mipibrdg>;
 vdd18-supply = <_mipibrdg>;
 vdd33-supply = <_mipibrdg>;
+analogix,audio-enable;
+analogix,lane0-swing = /bits/ 8 <0x14 0x54 0x64 0x74>;
+analogix,lane1-swing = /bits/ 8 <0x14 0x54 0x64 0x74>;
 
 ports {
 #address-cells = <1>;
@@ -96,6 +155,8 @@ examples:
 reg = <0>;
 anx7625_in: endpoint {
 remote-endpoint = <_dsi>;
+bus-type = <5>;
+data-lanes = <0 1 2 3>;
 };
 };
 
-- 
2.25.1



[PATCH v12 0/4] Add MIPI rx DPI support

2021-11-03 Thread Xin Ji
Hi all, this patch series implement MIPI rx DPI feature. Please help to review.

This is the v12 version, rebase all patches on the drm-misc-next.
Any mistakes, please let me know, I'll fix it in the next series.

Change history:
v12: Fix Robert Foss comment
 - Apply code on drm-misc-next branch

v11: Fix Rob Herring comment
 - Move swing register description in property.
 - Remove additional property.

v10: Fix Rob Herring and Laurent Pinchart comments
 - Add more description about lane swing configuration in commit
   message.

v9: Fix Neil Amstrong comment
 - use macro define 'V4L2_FWNODE_BUS_TYPE_PARALLEL' instead of fixing
   value.

v8: Fix Laurent Pinchart comment
 - Expand the commit message.

v7:
 - Rebase DT on the latest branch 'drm-misc-next'.
 - Remove HDCP patch.

v6: Fix kernel robot compile warning

v5: Fix Rob Herring, Hsin-Yi, Robert Foss comments
 - Rebase code on the branch 'drm-misc-next', refer video-interfaces.yaml
 - Seprate HDCP function to a new patch
 - Fix driver not correctly get 'bus-type' 'data-lanes'
 - Add audio HDMI codec function support

v4: Fix Rob Herring comment
 - Rebase code on the branch 'drm-misc-next'
 - Change 'analogix,hdcp-support' type to boolean

v3: Fix Rob Herring, Dan Carpenter, Nicolas comment
 - Split the patch, fix not correct return data
 - Fix several coding format
 - Split DP tx swing register setting to two property
 - Add HDCP support vender flag
 - remove 'analogix,swing-setting' and 'analogix,mipi-dpi-in' property

v2: Fix Rob Herring comment
 - Fix yamllint warnings/errors in analogix,anx7625.yaml
 - Fix kernel robot compile warning

v1: initial MIPI rx DPI feature support

Xin Ji (4):
  dt-bindings:drm/bridge:anx7625:add vendor define
  drm/bridge: anx7625: fix not correct return value
  drm/bridge: anx7625: add MIPI DPI input feature
  drm/bridge: anx7625: add HDMI audio function

 .../display/bridge/analogix,anx7625.yaml  |  65 ++-
 drivers/gpu/drm/bridge/analogix/anx7625.c | 459 --
 drivers/gpu/drm/bridge/analogix/anx7625.h |  23 +-
 3 files changed, 492 insertions(+), 55 deletions(-)

-- 
2.25.1



Re: [PATCH v11 4/4] drm/bridge: anx7625: add HDMI audio function

2021-11-03 Thread Xin Ji
On Wed, Nov 03, 2021 at 04:04:00PM +0100, Robert Foss wrote:
> Hey Xin,
> 
> This series does not apply on drm-misc-next. Please fix this and
> resend. Make sure that checkpatch --strict passes as well.
OK, I'll apply on drm-misc-next, thanks!
Xin
> 
> On Wed, 3 Nov 2021 at 15:20, Dan Carpenter  wrote:
> >
> > This is a super awkward way to resend a patch series.  Next time, just
> > start a new thread and put [PATCH RESEND] in the subject.
> >
> > I am sorry that no one responded to your thread.  :/
> >
> > regards,
> > dan carpenter


Re: [PATCH v11 4/4] drm/bridge: anx7625: add HDMI audio function

2021-11-03 Thread Xin Ji
On Wed, Nov 03, 2021 at 05:20:03PM +0300, Dan Carpenter wrote:
> This is a super awkward way to resend a patch series.  Next time, just
> start a new thread and put [PATCH RESEND] in the subject.
OK, thanks!
Xin
> 
> I am sorry that no one responded to your thread.  :/
> 
> regards,
> dan carpenter


Re: [PATCH v7 3/3] drm/bridge: anx7625: config hs packets end aligned to avoid screen shift

2021-11-01 Thread Xin Ji
On Mon, Nov 01, 2021 at 11:16:15AM +0800, Jitao Shi wrote:
> Hi Xin,
> 
> Please help to review the changes in anx7625.c
> 
> On Thu, 2021-09-16 at 06:31 +0800, Jitao Shi wrote:
> > This device requires the packets on lanes aligned at the end to fix
> > screen shift or scroll.
> > 
> > Signed-off-by: Jitao Shi 
> > ---
> >  drivers/gpu/drm/bridge/analogix/anx7625.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > index 14d73fb1dd15..d76fb63fa9f7 100644
> > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > @@ -1327,6 +1327,7 @@ static int anx7625_attach_dsi(struct
> > anx7625_data *ctx)
> > MIPI_DSI_MODE_VIDEO_SYNC_PULSE  |
> > MIPI_DSI_MODE_NO_EOT_PACKET |
> >         MIPI_DSI_MODE_VIDEO_HSE;
> > +   dsi->hs_packet_end_aligned = true;

Looks good, it's OK for me.
Reviewed-by: Xin Ji 

> >  
> > if (mipi_dsi_attach(dsi) < 0) {
> > DRM_DEV_ERROR(dev, "fail to attach dsi to host.\n");


[PATCH v11 4/4] drm/bridge: anx7625: add HDMI audio function

2021-10-17 Thread Xin Ji
Add audio HDMI codec function support, enable it through device true
flag "analogix,audio-enable".

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 226 ++
 drivers/gpu/drm/bridge/analogix/anx7625.h |   5 +
 2 files changed, 231 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 92038c4661ff..12e148298ba9 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -33,6 +33,7 @@
 #include 
 
 #include 
+#include 
 #include 
 
 #include "anx7625.h"
@@ -153,6 +154,20 @@ static int anx7625_write_and(struct anx7625_data *ctx,
return anx7625_reg_write(ctx, client, offset, (val & (mask)));
 }
 
+static int anx7625_write_and_or(struct anx7625_data *ctx,
+   struct i2c_client *client,
+   u8 offset, u8 and_mask, u8 or_mask)
+{
+   int val;
+
+   val = anx7625_reg_read(ctx, client, offset);
+   if (val < 0)
+   return val;
+
+   return anx7625_reg_write(ctx, client,
+offset, (val & and_mask) | (or_mask));
+}
+
 static int anx7625_config_bit_matrix(struct anx7625_data *ctx)
 {
int i, ret;
@@ -1353,6 +1368,9 @@ static int anx7625_parse_dt(struct device *dev,
else
DRM_DEV_DEBUG_DRIVER(dev, "found MIPI DSI host node.\n");
 
+   if (of_property_read_bool(np, "analogix,audio-enable"))
+   pdata->audio_en = 1;
+
ret = drm_of_find_panel_or_bridge(np, 1, 0, , NULL);
if (ret < 0) {
if (ret == -ENODEV)
@@ -1423,6 +1441,208 @@ static enum drm_connector_status 
anx7625_sink_detect(struct anx7625_data *ctx)
 connector_status_disconnected;
 }
 
+static int anx7625_audio_hw_params(struct device *dev, void *data,
+  struct hdmi_codec_daifmt *fmt,
+  struct hdmi_codec_params *params)
+{
+   struct anx7625_data *ctx = dev_get_drvdata(dev);
+   int wl, ch, rate;
+   int ret = 0;
+
+   if (fmt->fmt != HDMI_DSP_A) {
+   DRM_DEV_ERROR(dev, "only supports DSP_A\n");
+   return -EINVAL;
+   }
+
+   DRM_DEV_DEBUG_DRIVER(dev, "setting %d Hz, %d bit, %d channels\n",
+params->sample_rate, params->sample_width,
+params->cea.channels);
+
+   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_6,
+   ~I2S_SLAVE_MODE,
+   TDM_SLAVE_MODE);
+
+   /* Word length */
+   switch (params->sample_width) {
+   case 16:
+   wl = AUDIO_W_LEN_16_20MAX;
+   break;
+   case 18:
+   wl = AUDIO_W_LEN_18_20MAX;
+   break;
+   case 20:
+   wl = AUDIO_W_LEN_20_20MAX;
+   break;
+   case 24:
+   wl = AUDIO_W_LEN_24_24MAX;
+   break;
+   default:
+   DRM_DEV_DEBUG_DRIVER(dev, "wordlength: %d bit not support",
+params->sample_width);
+   return -EINVAL;
+   }
+   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_5,
+   0xf0, wl);
+
+   /* Channel num */
+   switch (params->cea.channels) {
+   case 2:
+   ch = I2S_CH_2;
+   break;
+   case 4:
+   ch = TDM_CH_4;
+   break;
+   case 6:
+   ch = TDM_CH_6;
+   break;
+   case 8:
+   ch = TDM_CH_8;
+   break;
+   default:
+   DRM_DEV_DEBUG_DRIVER(dev, "channel number: %d not support",
+params->cea.channels);
+   return -EINVAL;
+   }
+   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+  AUDIO_CHANNEL_STATUS_6, 0x1f, ch << 5);
+   if (ch > I2S_CH_2)
+   ret |= anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_6, AUDIO_LAYOUT);
+   else
+   ret |= anx7625_write_and(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_6, ~AUDIO_LAYOUT);
+
+   /* FS */
+   switch (params->sample_rate) {
+   case 32000:
+   rate = AUDIO_FS_32K;
+   break;
+   case 44100:
+   rate = AUDIO_FS_441K;
+   break;
+   case 48000:
+   rate = AUDIO_FS_48K;
+   break;
+   case 88200:
+   

[PATCH v11 3/4] drm/bridge: anx7625: add MIPI DPI input feature

2021-10-17 Thread Xin Ji
The basic anx7625 driver only support MIPI DSI rx signal input.
This patch add MIPI DPI rx input configuration support, after apply
this patch, the driver can support DSI rx or DPI rx by adding
'bus-type' in DT.

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 246 --
 drivers/gpu/drm/bridge/analogix/anx7625.h |  18 +-
 2 files changed, 204 insertions(+), 60 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 469037f2fd3d..92038c4661ff 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -32,6 +32,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 #include "anx7625.h"
@@ -152,18 +153,18 @@ static int anx7625_write_and(struct anx7625_data *ctx,
return anx7625_reg_write(ctx, client, offset, (val & (mask)));
 }
 
-static int anx7625_write_and_or(struct anx7625_data *ctx,
-   struct i2c_client *client,
-   u8 offset, u8 and_mask, u8 or_mask)
+static int anx7625_config_bit_matrix(struct anx7625_data *ctx)
 {
-   int val;
+   int i, ret;
 
-   val = anx7625_reg_read(ctx, client, offset);
-   if (val < 0)
-   return val;
+   ret = anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
+  AUDIO_CONTROL_REGISTER, 0x80);
+   for (i = 0; i < 13; i++)
+   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
+VIDEO_BIT_MATRIX_12 + i,
+0x18 + i);
 
-   return anx7625_reg_write(ctx, client,
-offset, (val & and_mask) | (or_mask));
+   return ret;
 }
 
 static int anx7625_read_ctrl_status_p0(struct anx7625_data *ctx)
@@ -221,38 +222,6 @@ static int anx7625_video_mute_control(struct anx7625_data 
*ctx,
return ret;
 }
 
-static int anx7625_config_audio_input(struct anx7625_data *ctx)
-{
-   struct device *dev = >client->dev;
-   int ret;
-
-   /* Channel num */
-   ret = anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_6, I2S_CH_2 << 5);
-
-   /* FS */
-   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_4,
-   0xf0, AUDIO_FS_48K);
-   /* Word length */
-   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_5,
-   0xf0, AUDIO_W_LEN_24_24MAX);
-   /* I2S */
-   ret |= anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_6, I2S_SLAVE_MODE);
-   ret |= anx7625_write_and(ctx, ctx->i2c.tx_p2_client,
-AUDIO_CONTROL_REGISTER, ~TDM_TIMING_MODE);
-   /* Audio change flag */
-   ret |= anx7625_write_or(ctx, ctx->i2c.rx_p0_client,
-   AP_AV_STATUS, AP_AUDIO_CHG);
-
-   if (ret < 0)
-   DRM_DEV_ERROR(dev, "fail to config audio.\n");
-
-   return ret;
-}
-
 /* Reduction of fraction a/b */
 static void anx7625_reduction_of_a_fraction(unsigned long *a, unsigned long *b)
 {
@@ -431,7 +400,7 @@ static int anx7625_dsi_video_timing_config(struct 
anx7625_data *ctx)
ret |= anx7625_write_and(ctx, ctx->i2c.rx_p1_client,
MIPI_LANE_CTRL_0, 0xfc);
ret |= anx7625_write_or(ctx, ctx->i2c.rx_p1_client,
-   MIPI_LANE_CTRL_0, 3);
+   MIPI_LANE_CTRL_0, ctx->pdata.mipi_lanes - 1);
 
/* Htotal */
htotal = ctx->dt.hactive.min + ctx->dt.hfront_porch.min +
@@ -615,6 +584,76 @@ static int anx7625_dsi_config(struct anx7625_data *ctx)
return ret;
 }
 
+static int anx7625_api_dpi_config(struct anx7625_data *ctx)
+{
+   struct device *dev = >client->dev;
+   u16 freq = ctx->dt.pixelclock.min / 1000;
+   int ret;
+
+   /* configure pixel clock */
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   PIXEL_CLOCK_L, freq & 0xFF);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+PIXEL_CLOCK_H, (freq >> 8));
+
+   /* set DPI mode */
+   /* set to DPI PLL module sel */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_DIGITAL_PLL_9, 0x20);
+   /* power down MIPI */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_LANE_CTRL_10, 0x08);
+   /* enable DPI mode */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+  

[PATCH v11 2/4] drm/bridge: anx7625: fix not correct return value

2021-10-17 Thread Xin Ji
At some time, the original code may return non zero value, force return 0
if operation finished.

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 1a871f6b6822..469037f2fd3d 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -191,10 +191,10 @@ static int wait_aux_op_finish(struct anx7625_data *ctx)
   AP_AUX_CTRL_STATUS);
if (val < 0 || (val & 0x0F)) {
DRM_DEV_ERROR(dev, "aux status %02x\n", val);
-   val = -EIO;
+   return -EIO;
}
 
-   return val;
+   return 0;
 }
 
 static int anx7625_video_mute_control(struct anx7625_data *ctx,
-- 
2.25.1



[PATCH v11 1/4] dt-bindings:drm/bridge:anx7625:add vendor define

2021-10-17 Thread Xin Ji
Add 'bus-type' and 'data-lanes' define for port0. Add DP tx lane0,
lane1 swing register setting array, and audio enable flag.

The device which cannot pass DP tx PHY CTS caused by long PCB trace or
embedded MUX, adjusting ANX7625 PHY parameters can pass the CTS test. The
adjusting type include Pre-emphasis, Vp-p, Rterm(Resistor Termination)
and Rsel(Driven Strength). Each lane has maximum 20 registers for
these settings.

Signed-off-by: Xin Ji 
---
 .../display/bridge/analogix,anx7625.yaml  | 65 ++-
 1 file changed, 63 insertions(+), 2 deletions(-)

diff --git 
a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml 
b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
index ab48ab2f4240..1d3e88daca04 100644
--- a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
+++ b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
@@ -43,14 +43,70 @@ properties:
   vdd33-supply:
 description: Regulator that provides the supply 3.3V power.
 
+  analogix,lane0-swing:
+$ref: /schemas/types.yaml#/definitions/uint8-array
+minItems: 1
+maxItems: 20
+description:
+  an array of swing register setting for DP tx lane0 PHY.
+  Registers 0~9 are Swing0_Pre0, Swing1_Pre0, Swing2_Pre0,
+  Swing3_Pre0, Swing0_Pre1, Swing1_Pre1, Swing2_Pre1, Swing0_Pre2,
+  Swing1_Pre2, Swing0_Pre3, they are for [Boost control] and
+  [Swing control] setting.
+  Registers 0~9, bit 3:0 is [Boost control], these bits control
+  post cursor manual, increase the [Boost control] to increase
+  Pre-emphasis value.
+  Registers 0~9, bit 6:4 is [Swing control], these bits control
+  swing manual, increase [Swing control] setting to add Vp-p value
+  for each Swing, Pre.
+  Registers 10~19 are Swing0_Pre0, Swing1_Pre0, Swing2_Pre0,
+  Swing3_Pre0, Swing0_Pre1, Swing1_Pre1, Swing2_Pre1, Swing0_Pre2,
+  Swing1_Pre2, Swing0_Pre3, they are for [R select control] and
+  [R Termination control] setting.
+  Registers 10~19, bit 4:0 is [R select control], these bits are
+  compensation manual, increase it can enhance IO driven strength
+  and Vp-p.
+  Registers 10~19, bit 5:6 is [R termination control], these bits
+  adjust 50ohm impedance of DP tx termination. 00:55 ohm,
+  01:50 ohm(default), 10:45 ohm, 11:40 ohm.
+
+  analogix,lane1-swing:
+$ref: /schemas/types.yaml#/definitions/uint8-array
+minItems: 1
+maxItems: 20
+description:
+  an array of swing register setting for DP tx lane1 PHY.
+  DP TX lane1 swing register setting same with lane0
+  swing, please refer lane0-swing property description.
+
+  analogix,audio-enable:
+type: boolean
+description: let the driver enable audio HDMI codec function or not.
+
   ports:
 $ref: /schemas/graph.yaml#/properties/ports
 
 properties:
   port@0:
-$ref: /schemas/graph.yaml#/properties/port
+$ref: /schemas/graph.yaml#/$defs/port-base
+unevaluatedProperties: false
 description:
-  Video port for MIPI DSI input.
+  MIPI DSI/DPI input.
+
+properties:
+  endpoint:
+$ref: /schemas/media/video-interfaces.yaml#
+type: object
+additionalProperties: false
+
+properties:
+  remote-endpoint: true
+
+  bus-type:
+enum: [1, 5]
+default: 1
+
+  data-lanes: true
 
   port@1:
 $ref: /schemas/graph.yaml#/properties/port
@@ -87,6 +143,9 @@ examples:
 vdd10-supply = <_mipibrdg>;
 vdd18-supply = <_mipibrdg>;
 vdd33-supply = <_mipibrdg>;
+analogix,audio-enable;
+analogix,lane0-swing = /bits/ 8 <0x14 0x54 0x64 0x74>;
+analogix,lane1-swing = /bits/ 8 <0x14 0x54 0x64 0x74>;
 
 ports {
 #address-cells = <1>;
@@ -96,6 +155,8 @@ examples:
 reg = <0>;
 anx7625_in: endpoint {
 remote-endpoint = <_dsi>;
+bus-type = <5>;
+data-lanes = <0 1 2 3>;
 };
 };
 
-- 
2.25.1



[PATCH v11 0/4] Add MIPI rx DPI support

2021-10-17 Thread Xin Ji
Hi all, this patch series implement MIPI rx DPI feature. Please help to review.

This is the v11 version, rebase all patches on the latest code.
Any mistakes, please let me know, I'll fix it in the next series.

Change history:
v11: Fix Rob Herring comment
 - Move swing register description in property.
 - Remove additional property.

v10: Fix Rob Herring and Laurent Pinchart comments
 - Add more description about lane swing configuration in commit
   message.

v9: Fix Neil Amstrong comment
 - use macro define 'V4L2_FWNODE_BUS_TYPE_PARALLEL' instead of fixing
   value.

v8: Fix Laurent Pinchart comment
 - Expand the commit message.

v7:
 - Rebase DT on the latest branch 'drm-misc-next'.
 - Remove HDCP patch.

v6: Fix kernel robot compile warning

v5: Fix Rob Herring, Hsin-Yi, Robert Foss comments
 - Rebase code on the branch 'drm-misc-next', refer video-interfaces.yaml
 - Seprate HDCP function to a new patch
 - Fix driver not correctly get 'bus-type' 'data-lanes'
 - Add audio HDMI codec function support

v4: Fix Rob Herring comment
 - Rebase code on the branch 'drm-misc-next'
 - Change 'analogix,hdcp-support' type to boolean

v3: Fix Rob Herring, Dan Carpenter, Nicolas comment
 - Split the patch, fix not correct return data
 - Fix several coding format
 - Split DP tx swing register setting to two property
 - Add HDCP support vender flag
 - remove 'analogix,swing-setting' and 'analogix,mipi-dpi-in' property

v2: Fix Rob Herring comment
 - Fix yamllint warnings/errors in analogix,anx7625.yaml
 - Fix kernel robot compile warning

v1: initial MIPI rx DPI feature support

Xin Ji (4):
  dt-bindings:drm/bridge:anx7625:add vendor define
  drm/bridge: anx7625: fix not correct return value
  drm/bridge: anx7625: add MIPI DPI input feature
  drm/bridge: anx7625: add HDMI audio function

 .../display/bridge/analogix,anx7625.yaml  |  65 ++-
 drivers/gpu/drm/bridge/analogix/anx7625.c | 458 --
 drivers/gpu/drm/bridge/analogix/anx7625.h |  23 +-
 3 files changed, 491 insertions(+), 55 deletions(-)

-- 
2.25.1



[PATCH v2] drm/bridge: anx7625: enable DSI EOTP

2021-08-19 Thread Xin Ji
Enable DSI EOTP feature for fixing some panel screen constant shift issue.
Removing MIPI flag MIPI_DSI_MODE_NO_EOT_PACKET to enable DSI EOTP.

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index abc8db77bfd3..1a871f6b6822 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1335,7 +1335,6 @@ static int anx7625_attach_dsi(struct anx7625_data *ctx)
dsi->format = MIPI_DSI_FMT_RGB888;
dsi->mode_flags = MIPI_DSI_MODE_VIDEO   |
MIPI_DSI_MODE_VIDEO_SYNC_PULSE  |
-   MIPI_DSI_MODE_NO_EOT_PACKET |
MIPI_DSI_MODE_VIDEO_HSE;
 
if (mipi_dsi_attach(dsi) < 0) {
-- 
2.25.1



[PATCH v2] drm/bridge: anx7625: Tune K value for IVO panel

2021-08-06 Thread Xin Ji
IVO panel require less input video clock variation than video clock
variation in DP CTS spec.

This patch decreases the K value of ANX7625 which will shrink eDP Tx
video clock variation to meet IVO panel's requirement.

Acked-by: Sam Ravnborg 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 24 ---
 drivers/gpu/drm/bridge/analogix/anx7625.h |  4 +++-
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index a3d82377066b..9b9e3984dd38 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -384,6 +384,25 @@ static int anx7625_odfc_config(struct anx7625_data *ctx,
return ret;
 }
 
+/*
+ * The MIPI source video data exist large variation (e.g. 59Hz ~ 61Hz),
+ * anx7625 defined K ratio for matching MIPI input video clock and
+ * DP output video clock. Increase K value can match bigger video data
+ * variation. IVO panel has small variation than DP CTS spec, need
+ * decrease the K value.
+ */
+static int anx7625_set_k_value(struct anx7625_data *ctx)
+{
+   struct edid *edid = (struct edid *)ctx->slimport_edid_p.edid_raw_data;
+
+   if (edid->mfg_id[0] == IVO_MID0 && edid->mfg_id[1] == IVO_MID1)
+   return anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_DIGITAL_ADJ_1, 0x3B);
+
+   return anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_DIGITAL_ADJ_1, 0x3D);
+}
+
 static int anx7625_dsi_video_timing_config(struct anx7625_data *ctx)
 {
struct device *dev = >client->dev;
@@ -470,9 +489,8 @@ static int anx7625_dsi_video_timing_config(struct 
anx7625_data *ctx)
MIPI_PLL_N_NUM_15_8, (n >> 8) & 0xff);
ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client, MIPI_PLL_N_NUM_7_0,
(n & 0xff));
-   /* Diff */
-   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
-   MIPI_DIGITAL_ADJ_1, 0x3D);
+
+   anx7625_set_k_value(ctx);
 
ret |= anx7625_odfc_config(ctx, post_divider - 1);
 
diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h 
b/drivers/gpu/drm/bridge/analogix/anx7625.h
index 034c3840028f..6dcf64c703f9 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.h
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
@@ -210,7 +210,9 @@
 #define  MIPI_VIDEO_STABLE_CNT   0x0A
 
 #define  MIPI_LANE_CTRL_10   0x0F
-#define  MIPI_DIGITAL_ADJ_1   0x1B
+#define  MIPI_DIGITAL_ADJ_1 0x1B
+#define  IVO_MID0   0x26
+#define  IVO_MID1   0xCF
 
 #define  MIPI_PLL_M_NUM_23_16   0x1E
 #define  MIPI_PLL_M_NUM_15_80x1F
-- 
2.25.1



[PATCH v2] drm/bridge: anx7625: Tune K value for IVO panel

2021-08-06 Thread Xin Ji
IVO panel require less input video clock variation than video clock
variation in DP CTS spec.

This patch decreases the K value of ANX7625 which will shrink eDP Tx
video clock variation to meet IVO panel's requirement.

Acked-by: Sam Ravnborg 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 24 ---
 drivers/gpu/drm/bridge/analogix/anx7625.h |  4 +++-
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index a3d82377066b..9b9e3984dd38 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -384,6 +384,25 @@ static int anx7625_odfc_config(struct anx7625_data *ctx,
return ret;
 }
 
+/*
+ * The MIPI source video data exist large variation (e.g. 59Hz ~ 61Hz),
+ * anx7625 defined K ratio for matching MIPI input video clock and
+ * DP output video clock. Increase K value can match bigger video data
+ * variation. IVO panel has small variation than DP CTS spec, need
+ * decrease the K value.
+ */
+static int anx7625_set_k_value(struct anx7625_data *ctx)
+{
+   struct edid *edid = (struct edid *)ctx->slimport_edid_p.edid_raw_data;
+
+   if (edid->mfg_id[0] == IVO_MID0 && edid->mfg_id[1] == IVO_MID1)
+   return anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_DIGITAL_ADJ_1, 0x3B);
+
+   return anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_DIGITAL_ADJ_1, 0x3D);
+}
+
 static int anx7625_dsi_video_timing_config(struct anx7625_data *ctx)
 {
struct device *dev = >client->dev;
@@ -470,9 +489,8 @@ static int anx7625_dsi_video_timing_config(struct 
anx7625_data *ctx)
MIPI_PLL_N_NUM_15_8, (n >> 8) & 0xff);
ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client, MIPI_PLL_N_NUM_7_0,
(n & 0xff));
-   /* Diff */
-   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
-   MIPI_DIGITAL_ADJ_1, 0x3D);
+
+   anx7625_set_k_value(ctx);
 
ret |= anx7625_odfc_config(ctx, post_divider - 1);
 
diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h 
b/drivers/gpu/drm/bridge/analogix/anx7625.h
index 034c3840028f..6dcf64c703f9 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.h
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
@@ -210,7 +210,9 @@
 #define  MIPI_VIDEO_STABLE_CNT   0x0A
 
 #define  MIPI_LANE_CTRL_10   0x0F
-#define  MIPI_DIGITAL_ADJ_1   0x1B
+#define  MIPI_DIGITAL_ADJ_1 0x1B
+#define  IVO_MID0   0x26
+#define  IVO_MID1   0xCF
 
 #define  MIPI_PLL_M_NUM_23_16   0x1E
 #define  MIPI_PLL_M_NUM_15_80x1F
-- 
2.25.1



Re: [PATCH v2 1/1] drm/bridge: anx7625: Tune K value for IVO panel

2021-08-06 Thread Xin Ji
On Fri, Aug 06, 2021 at 11:42:26AM +0200, Robert Foss wrote:
> Hey Xin,
> 
> Thanks for implementing the suggestion so quickly.
> 
> Can you send this version of the patch out as v2? Versioning is
> important and both tools and processes break if different versions
> aren't submitted in different emails.
Hi Robert Foss, OK, thanks.
Xin
> 
> On Fri, 6 Aug 2021 at 11:35, Xin Ji  wrote:
> >
> > IVO panel require less input video clock variation than video clock
> > variation in DP CTS spec.
> >
> > This patch decreases the K value of ANX7625 which will shrink eDP Tx
> > video clock variation to meet IVO panel's requirement.
> >
> > Acked-by: Sam Ravnborg 
> > Signed-off-by: Xin Ji 
> > ---
> >  drivers/gpu/drm/bridge/analogix/anx7625.c | 24 ---
> >  drivers/gpu/drm/bridge/analogix/anx7625.h |  4 +++-
> >  2 files changed, 24 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > index a3d82377066b..9b9e3984dd38 100644
> > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > @@ -384,6 +384,25 @@ static int anx7625_odfc_config(struct anx7625_data 
> > *ctx,
> > return ret;
> >  }
> >
> > +/*
> > + * The MIPI source video data exist large variation (e.g. 59Hz ~ 61Hz),
> > + * anx7625 defined K ratio for matching MIPI input video clock and
> > + * DP output video clock. Increase K value can match bigger video data
> > + * variation. IVO panel has small variation than DP CTS spec, need
> > + * decrease the K value.
> > + */
> > +static int anx7625_set_k_value(struct anx7625_data *ctx)
> > +{
> > +   struct edid *edid = (struct edid 
> > *)ctx->slimport_edid_p.edid_raw_data;
> > +
> > +   if (edid->mfg_id[0] == IVO_MID0 && edid->mfg_id[1] == IVO_MID1)
> > +   return anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
> > +MIPI_DIGITAL_ADJ_1, 0x3B);
> > +
> > +   return anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
> > +MIPI_DIGITAL_ADJ_1, 0x3D);
> > +}
> > +
> >  static int anx7625_dsi_video_timing_config(struct anx7625_data *ctx)
> >  {
> > struct device *dev = >client->dev;
> > @@ -470,9 +489,8 @@ static int anx7625_dsi_video_timing_config(struct 
> > anx7625_data *ctx)
> > MIPI_PLL_N_NUM_15_8, (n >> 8) & 0xff);
> > ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client, 
> > MIPI_PLL_N_NUM_7_0,
> > (n & 0xff));
> > -   /* Diff */
> > -   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
> > -   MIPI_DIGITAL_ADJ_1, 0x3D);
> > +
> > +   anx7625_set_k_value(ctx);
> >
> > ret |= anx7625_odfc_config(ctx, post_divider - 1);
> >
> > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h 
> > b/drivers/gpu/drm/bridge/analogix/anx7625.h
> > index 034c3840028f..6dcf64c703f9 100644
> > --- a/drivers/gpu/drm/bridge/analogix/anx7625.h
> > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
> > @@ -210,7 +210,9 @@
> >  #define  MIPI_VIDEO_STABLE_CNT   0x0A
> >
> >  #define  MIPI_LANE_CTRL_10   0x0F
> > -#define  MIPI_DIGITAL_ADJ_1   0x1B
> > +#define  MIPI_DIGITAL_ADJ_1 0x1B
> > +#define  IVO_MID0   0x26
> > +#define  IVO_MID1   0xCF
> >
> >  #define  MIPI_PLL_M_NUM_23_16   0x1E
> >  #define  MIPI_PLL_M_NUM_15_80x1F
> > --
> > 2.25.1
> >


[PATCH v2 1/1] drm/bridge: anx7625: Tune K value for IVO panel

2021-08-06 Thread Xin Ji
IVO panel require less input video clock variation than video clock
variation in DP CTS spec.

This patch decreases the K value of ANX7625 which will shrink eDP Tx
video clock variation to meet IVO panel's requirement.

Acked-by: Sam Ravnborg 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 24 ---
 drivers/gpu/drm/bridge/analogix/anx7625.h |  4 +++-
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index a3d82377066b..9b9e3984dd38 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -384,6 +384,25 @@ static int anx7625_odfc_config(struct anx7625_data *ctx,
return ret;
 }
 
+/*
+ * The MIPI source video data exist large variation (e.g. 59Hz ~ 61Hz),
+ * anx7625 defined K ratio for matching MIPI input video clock and
+ * DP output video clock. Increase K value can match bigger video data
+ * variation. IVO panel has small variation than DP CTS spec, need
+ * decrease the K value.
+ */
+static int anx7625_set_k_value(struct anx7625_data *ctx)
+{
+   struct edid *edid = (struct edid *)ctx->slimport_edid_p.edid_raw_data;
+
+   if (edid->mfg_id[0] == IVO_MID0 && edid->mfg_id[1] == IVO_MID1)
+   return anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_DIGITAL_ADJ_1, 0x3B);
+
+   return anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_DIGITAL_ADJ_1, 0x3D);
+}
+
 static int anx7625_dsi_video_timing_config(struct anx7625_data *ctx)
 {
struct device *dev = >client->dev;
@@ -470,9 +489,8 @@ static int anx7625_dsi_video_timing_config(struct 
anx7625_data *ctx)
MIPI_PLL_N_NUM_15_8, (n >> 8) & 0xff);
ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client, MIPI_PLL_N_NUM_7_0,
(n & 0xff));
-   /* Diff */
-   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
-   MIPI_DIGITAL_ADJ_1, 0x3D);
+
+   anx7625_set_k_value(ctx);
 
ret |= anx7625_odfc_config(ctx, post_divider - 1);
 
diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h 
b/drivers/gpu/drm/bridge/analogix/anx7625.h
index 034c3840028f..6dcf64c703f9 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.h
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
@@ -210,7 +210,9 @@
 #define  MIPI_VIDEO_STABLE_CNT   0x0A
 
 #define  MIPI_LANE_CTRL_10   0x0F
-#define  MIPI_DIGITAL_ADJ_1   0x1B
+#define  MIPI_DIGITAL_ADJ_1 0x1B
+#define  IVO_MID0   0x26
+#define  IVO_MID1   0xCF
 
 #define  MIPI_PLL_M_NUM_23_16   0x1E
 #define  MIPI_PLL_M_NUM_15_80x1F
-- 
2.25.1



Re: [PATCH v1 1/1] drm/bridge: anx7625: Tune K value for IVO panel

2021-08-06 Thread Xin Ji
On Thu, Aug 05, 2021 at 09:33:20PM +0200, Sam Ravnborg wrote:
> On Thu, Aug 05, 2021 at 03:30:55PM +0800, Xin Ji wrote:
> > IVO panel require less input video clock variation than video clock
> > variation in DP CTS spec.
> > 
> > This patch decreases the K value of ANX7625 which will shrink eDP Tx
> > video clock variation to meet IVO panel's requirement.
> > 
> > Signed-off-by: Xin Ji 
> 
> Looks good, I assume someone else (Robert) picks this.
> 
> Acked-by: Sam Ravnborg 
> 
>   Sam
Hi Sam Ravnborg, OK, thanks,
Xin


Re: [PATCH v1 1/1] drm/bridge: anx7625: Tune K value for IVO panel

2021-08-06 Thread Xin Ji
On Thu, Aug 05, 2021 at 09:05:29PM +0200, Robert Foss wrote:
> Hey Xin,
> 
> Thanks for submitting this.
> 
> On Thu, 5 Aug 2021 at 09:31, Xin Ji  wrote:
> >
> > IVO panel require less input video clock variation than video clock
> > variation in DP CTS spec.
> >
> > This patch decreases the K value of ANX7625 which will shrink eDP Tx
> > video clock variation to meet IVO panel's requirement.
> >
> > Signed-off-by: Xin Ji 
> > ---
> >  drivers/gpu/drm/bridge/analogix/anx7625.c | 17 ++---
> >  drivers/gpu/drm/bridge/analogix/anx7625.h |  4 +++-
> >  2 files changed, 17 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
> > b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > index a3d82377066b..ceed1c7f3f28 100644
> > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > @@ -384,6 +384,18 @@ static int anx7625_odfc_config(struct anx7625_data 
> > *ctx,
> > return ret;
> >  }
> >
> > +static int anx7625_set_k_value(struct anx7625_data *ctx)
> 
> Pardon my ignorance, but I don't know what a K-value is. Could you add
> a comment detailing
> what the K-value does?

Hi Robert Foss, OK, I'll add more comment.
Thanks,
Xin
> 
> > +{
> > +   struct edid *edid = (struct edid 
> > *)ctx->slimport_edid_p.edid_raw_data;
> > +
> > +   if (edid->mfg_id[0] == IVO_MID0 && edid->mfg_id[1] == IVO_MID1)
> > +   return anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
> > +MIPI_DIGITAL_ADJ_1, 0x3B);
> > +
> > +   return anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
> > +MIPI_DIGITAL_ADJ_1, 0x3D);
> > +}
> > +
> >  static int anx7625_dsi_video_timing_config(struct anx7625_data *ctx)
> >  {
> > struct device *dev = >client->dev;
> > @@ -470,9 +482,8 @@ static int anx7625_dsi_video_timing_config(struct 
> > anx7625_data *ctx)
> > MIPI_PLL_N_NUM_15_8, (n >> 8) & 0xff);
> > ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client, 
> > MIPI_PLL_N_NUM_7_0,
> > (n & 0xff));
> > -   /* Diff */
> > -   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
> > -   MIPI_DIGITAL_ADJ_1, 0x3D);
> > +   /* Diff and K value */
> 
> With a proper comment above, this comment is no longer needed.
OK
> 
> > +   anx7625_set_k_value(ctx);
> >
> > ret |= anx7625_odfc_config(ctx, post_divider - 1);
> >
> > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h 
> > b/drivers/gpu/drm/bridge/analogix/anx7625.h
> > index 034c3840028f..6dcf64c703f9 100644
> > --- a/drivers/gpu/drm/bridge/analogix/anx7625.h
> > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
> > @@ -210,7 +210,9 @@
> >  #define  MIPI_VIDEO_STABLE_CNT   0x0A
> >
> >  #define  MIPI_LANE_CTRL_10   0x0F
> > -#define  MIPI_DIGITAL_ADJ_1   0x1B
> > +#define  MIPI_DIGITAL_ADJ_1 0x1B
> > +#define  IVO_MID0   0x26
> > +#define  IVO_MID1   0xCF
> >
> >  #define  MIPI_PLL_M_NUM_23_16   0x1E
> >  #define  MIPI_PLL_M_NUM_15_80x1F
> > --
> > 2.25.1
> >
> 
> LGTM with the above fix.
> 
> Reviewed-by: Robert Foss 


[PATCH v11 4/4] drm/bridge: anx7625: add HDMI audio function

2021-08-05 Thread Xin Ji
Add audio HDMI codec function support, enable it through device true
flag "analogix,audio-enable".

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 226 ++
 drivers/gpu/drm/bridge/analogix/anx7625.h |   5 +
 2 files changed, 231 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index a5a20cc0f3e0..44ab0893f600 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -33,6 +33,7 @@
 #include 
 
 #include 
+#include 
 #include 
 
 #include "anx7625.h"
@@ -153,6 +154,20 @@ static int anx7625_write_and(struct anx7625_data *ctx,
return anx7625_reg_write(ctx, client, offset, (val & (mask)));
 }
 
+static int anx7625_write_and_or(struct anx7625_data *ctx,
+   struct i2c_client *client,
+   u8 offset, u8 and_mask, u8 or_mask)
+{
+   int val;
+
+   val = anx7625_reg_read(ctx, client, offset);
+   if (val < 0)
+   return val;
+
+   return anx7625_reg_write(ctx, client,
+offset, (val & and_mask) | (or_mask));
+}
+
 static int anx7625_config_bit_matrix(struct anx7625_data *ctx)
 {
int i, ret;
@@ -1325,6 +1340,9 @@ static int anx7625_parse_dt(struct device *dev,
else
DRM_DEV_DEBUG_DRIVER(dev, "found MIPI DSI host node.\n");
 
+   if (of_property_read_bool(np, "analogix,audio-enable"))
+   pdata->audio_en = 1;
+
ret = drm_of_find_panel_or_bridge(np, 1, 0, , NULL);
if (ret < 0) {
if (ret == -ENODEV)
@@ -1395,6 +1413,208 @@ static enum drm_connector_status 
anx7625_sink_detect(struct anx7625_data *ctx)
 connector_status_disconnected;
 }
 
+static int anx7625_audio_hw_params(struct device *dev, void *data,
+  struct hdmi_codec_daifmt *fmt,
+  struct hdmi_codec_params *params)
+{
+   struct anx7625_data *ctx = dev_get_drvdata(dev);
+   int wl, ch, rate;
+   int ret = 0;
+
+   if (fmt->fmt != HDMI_DSP_A) {
+   DRM_DEV_ERROR(dev, "only supports DSP_A\n");
+   return -EINVAL;
+   }
+
+   DRM_DEV_DEBUG_DRIVER(dev, "setting %d Hz, %d bit, %d channels\n",
+params->sample_rate, params->sample_width,
+params->cea.channels);
+
+   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_6,
+   ~I2S_SLAVE_MODE,
+   TDM_SLAVE_MODE);
+
+   /* Word length */
+   switch (params->sample_width) {
+   case 16:
+   wl = AUDIO_W_LEN_16_20MAX;
+   break;
+   case 18:
+   wl = AUDIO_W_LEN_18_20MAX;
+   break;
+   case 20:
+   wl = AUDIO_W_LEN_20_20MAX;
+   break;
+   case 24:
+   wl = AUDIO_W_LEN_24_24MAX;
+   break;
+   default:
+   DRM_DEV_DEBUG_DRIVER(dev, "wordlength: %d bit not support",
+params->sample_width);
+   return -EINVAL;
+   }
+   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_5,
+   0xf0, wl);
+
+   /* Channel num */
+   switch (params->cea.channels) {
+   case 2:
+   ch = I2S_CH_2;
+   break;
+   case 4:
+   ch = TDM_CH_4;
+   break;
+   case 6:
+   ch = TDM_CH_6;
+   break;
+   case 8:
+   ch = TDM_CH_8;
+   break;
+   default:
+   DRM_DEV_DEBUG_DRIVER(dev, "channel number: %d not support",
+params->cea.channels);
+   return -EINVAL;
+   }
+   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+  AUDIO_CHANNEL_STATUS_6, 0x1f, ch << 5);
+   if (ch > I2S_CH_2)
+   ret |= anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_6, AUDIO_LAYOUT);
+   else
+   ret |= anx7625_write_and(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_6, ~AUDIO_LAYOUT);
+
+   /* FS */
+   switch (params->sample_rate) {
+   case 32000:
+   rate = AUDIO_FS_32K;
+   break;
+   case 44100:
+   rate = AUDIO_FS_441K;
+   break;
+   case 48000:
+   rate = AUDIO_FS_48K;
+   break;
+   case 88200:
+   

[PATCH v11 3/4] drm/bridge: anx7625: add MIPI DPI input feature

2021-08-05 Thread Xin Ji
The basic anx7625 driver only support MIPI DSI rx signal input.
This patch add MIPI DPI rx input configuration support, after apply
this patch, the driver can support DSI rx or DPI rx by adding
'bus-type' in DT.

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 246 --
 drivers/gpu/drm/bridge/analogix/anx7625.h |  18 +-
 2 files changed, 204 insertions(+), 60 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 3fc6b7ce7fc7..a5a20cc0f3e0 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -32,6 +32,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 #include "anx7625.h"
@@ -152,18 +153,18 @@ static int anx7625_write_and(struct anx7625_data *ctx,
return anx7625_reg_write(ctx, client, offset, (val & (mask)));
 }
 
-static int anx7625_write_and_or(struct anx7625_data *ctx,
-   struct i2c_client *client,
-   u8 offset, u8 and_mask, u8 or_mask)
+static int anx7625_config_bit_matrix(struct anx7625_data *ctx)
 {
-   int val;
+   int i, ret;
 
-   val = anx7625_reg_read(ctx, client, offset);
-   if (val < 0)
-   return val;
+   ret = anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
+  AUDIO_CONTROL_REGISTER, 0x80);
+   for (i = 0; i < 13; i++)
+   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
+VIDEO_BIT_MATRIX_12 + i,
+0x18 + i);
 
-   return anx7625_reg_write(ctx, client,
-offset, (val & and_mask) | (or_mask));
+   return ret;
 }
 
 static int anx7625_read_ctrl_status_p0(struct anx7625_data *ctx)
@@ -221,38 +222,6 @@ static int anx7625_video_mute_control(struct anx7625_data 
*ctx,
return ret;
 }
 
-static int anx7625_config_audio_input(struct anx7625_data *ctx)
-{
-   struct device *dev = >client->dev;
-   int ret;
-
-   /* Channel num */
-   ret = anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_6, I2S_CH_2 << 5);
-
-   /* FS */
-   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_4,
-   0xf0, AUDIO_FS_48K);
-   /* Word length */
-   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_5,
-   0xf0, AUDIO_W_LEN_24_24MAX);
-   /* I2S */
-   ret |= anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_6, I2S_SLAVE_MODE);
-   ret |= anx7625_write_and(ctx, ctx->i2c.tx_p2_client,
-AUDIO_CONTROL_REGISTER, ~TDM_TIMING_MODE);
-   /* Audio change flag */
-   ret |= anx7625_write_or(ctx, ctx->i2c.rx_p0_client,
-   AP_AV_STATUS, AP_AUDIO_CHG);
-
-   if (ret < 0)
-   DRM_DEV_ERROR(dev, "fail to config audio.\n");
-
-   return ret;
-}
-
 /* Reduction of fraction a/b */
 static void anx7625_reduction_of_a_fraction(unsigned long *a, unsigned long *b)
 {
@@ -412,7 +381,7 @@ static int anx7625_dsi_video_timing_config(struct 
anx7625_data *ctx)
ret |= anx7625_write_and(ctx, ctx->i2c.rx_p1_client,
MIPI_LANE_CTRL_0, 0xfc);
ret |= anx7625_write_or(ctx, ctx->i2c.rx_p1_client,
-   MIPI_LANE_CTRL_0, 3);
+   MIPI_LANE_CTRL_0, ctx->pdata.mipi_lanes - 1);
 
/* Htotal */
htotal = ctx->dt.hactive.min + ctx->dt.hfront_porch.min +
@@ -597,6 +566,76 @@ static int anx7625_dsi_config(struct anx7625_data *ctx)
return ret;
 }
 
+static int anx7625_api_dpi_config(struct anx7625_data *ctx)
+{
+   struct device *dev = >client->dev;
+   u16 freq = ctx->dt.pixelclock.min / 1000;
+   int ret;
+
+   /* configure pixel clock */
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   PIXEL_CLOCK_L, freq & 0xFF);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+PIXEL_CLOCK_H, (freq >> 8));
+
+   /* set DPI mode */
+   /* set to DPI PLL module sel */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_DIGITAL_PLL_9, 0x20);
+   /* power down MIPI */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_LANE_CTRL_10, 0x08);
+   /* enable DPI mode */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+  

[PATCH v11 2/4] drm/bridge: anx7625: fix not correct return value

2021-08-05 Thread Xin Ji
At some time, the original code may return non zero value, force return 0
if operation finished.

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index a3d82377066b..3fc6b7ce7fc7 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -191,10 +191,10 @@ static int wait_aux_op_finish(struct anx7625_data *ctx)
   AP_AUX_CTRL_STATUS);
if (val < 0 || (val & 0x0F)) {
DRM_DEV_ERROR(dev, "aux status %02x\n", val);
-   val = -EIO;
+   return -EIO;
}
 
-   return val;
+   return 0;
 }
 
 static int anx7625_video_mute_control(struct anx7625_data *ctx,
-- 
2.25.1



[PATCH v11 1/4] dt-bindings:drm/bridge:anx7625:add vendor define

2021-08-05 Thread Xin Ji
Add 'bus-type' and 'data-lanes' define for port0. Add DP tx lane0,
lane1 swing register setting array, and audio enable flag.

The device which cannot pass DP tx PHY CTS caused by long PCB trace or
embedded MUX, adjusting ANX7625 PHY parameters can pass the CTS test. The
adjusting type include Pre-emphasis, Vp-p, Rterm(Resistor Termination)
and Rsel(Driven Strength). Each lane has maximum 20 registers for
these settings.

Signed-off-by: Xin Ji 
---
 .../display/bridge/analogix,anx7625.yaml  | 65 ++-
 1 file changed, 63 insertions(+), 2 deletions(-)

diff --git 
a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml 
b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
index ab48ab2f4240..1d3e88daca04 100644
--- a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
+++ b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
@@ -43,14 +43,70 @@ properties:
   vdd33-supply:
 description: Regulator that provides the supply 3.3V power.
 
+  analogix,lane0-swing:
+$ref: /schemas/types.yaml#/definitions/uint8-array
+minItems: 1
+maxItems: 20
+description:
+  an array of swing register setting for DP tx lane0 PHY.
+  Registers 0~9 are Swing0_Pre0, Swing1_Pre0, Swing2_Pre0,
+  Swing3_Pre0, Swing0_Pre1, Swing1_Pre1, Swing2_Pre1, Swing0_Pre2,
+  Swing1_Pre2, Swing0_Pre3, they are for [Boost control] and
+  [Swing control] setting.
+  Registers 0~9, bit 3:0 is [Boost control], these bits control
+  post cursor manual, increase the [Boost control] to increase
+  Pre-emphasis value.
+  Registers 0~9, bit 6:4 is [Swing control], these bits control
+  swing manual, increase [Swing control] setting to add Vp-p value
+  for each Swing, Pre.
+  Registers 10~19 are Swing0_Pre0, Swing1_Pre0, Swing2_Pre0,
+  Swing3_Pre0, Swing0_Pre1, Swing1_Pre1, Swing2_Pre1, Swing0_Pre2,
+  Swing1_Pre2, Swing0_Pre3, they are for [R select control] and
+  [R Termination control] setting.
+  Registers 10~19, bit 4:0 is [R select control], these bits are
+  compensation manual, increase it can enhance IO driven strength
+  and Vp-p.
+  Registers 10~19, bit 5:6 is [R termination control], these bits
+  adjust 50ohm impedance of DP tx termination. 00:55 ohm,
+  01:50 ohm(default), 10:45 ohm, 11:40 ohm.
+
+  analogix,lane1-swing:
+$ref: /schemas/types.yaml#/definitions/uint8-array
+minItems: 1
+maxItems: 20
+description:
+  an array of swing register setting for DP tx lane1 PHY.
+  DP TX lane1 swing register setting same with lane0
+  swing, please refer lane0-swing property description.
+
+  analogix,audio-enable:
+type: boolean
+description: let the driver enable audio HDMI codec function or not.
+
   ports:
 $ref: /schemas/graph.yaml#/properties/ports
 
 properties:
   port@0:
-$ref: /schemas/graph.yaml#/properties/port
+$ref: /schemas/graph.yaml#/$defs/port-base
+unevaluatedProperties: false
 description:
-  Video port for MIPI DSI input.
+  MIPI DSI/DPI input.
+
+properties:
+  endpoint:
+$ref: /schemas/media/video-interfaces.yaml#
+type: object
+additionalProperties: false
+
+properties:
+  remote-endpoint: true
+
+  bus-type:
+enum: [1, 5]
+default: 1
+
+  data-lanes: true
 
   port@1:
 $ref: /schemas/graph.yaml#/properties/port
@@ -87,6 +143,9 @@ examples:
 vdd10-supply = <_mipibrdg>;
 vdd18-supply = <_mipibrdg>;
 vdd33-supply = <_mipibrdg>;
+analogix,audio-enable;
+analogix,lane0-swing = /bits/ 8 <0x14 0x54 0x64 0x74>;
+analogix,lane1-swing = /bits/ 8 <0x14 0x54 0x64 0x74>;
 
 ports {
 #address-cells = <1>;
@@ -96,6 +155,8 @@ examples:
 reg = <0>;
 anx7625_in: endpoint {
 remote-endpoint = <_dsi>;
+bus-type = <5>;
+data-lanes = <0 1 2 3>;
 };
 };
 
-- 
2.25.1



[PATCH v11 0/4] Add MIPI rx DPI support

2021-08-05 Thread Xin Ji
Hi all, this patch series implement MIPI rx DPI feature. Please help to review.

This is the v11 version, rebase all patches on the latest code.
Any mistakes, please let me know, I'll fix it in the next series.

Change history:
v11: Fix Rob Herring comment
 - Move swing register description in property.
 - Remove additional property.

v10: Fix Rob Herring and Laurent Pinchart comments
 - Add more description about lane swing configuration in commit
   message.

v9: Fix Neil Amstrong comment
 - use macro define 'V4L2_FWNODE_BUS_TYPE_PARALLEL' instead of fixing
   value.

v8: Fix Laurent Pinchart comment
 - Expand the commit message.

v7:
 - Rebase DT on the latest branch 'drm-misc-next'.
 - Remove HDCP patch.

v6: Fix kernel robot compile warning

v5: Fix Rob Herring, Hsin-Yi, Robert Foss comments
 - Rebase code on the branch 'drm-misc-next', refer video-interfaces.yaml
 - Seprate HDCP function to a new patch
 - Fix driver not correctly get 'bus-type' 'data-lanes'
 - Add audio HDMI codec function support

v4: Fix Rob Herring comment
 - Rebase code on the branch 'drm-misc-next'
 - Change 'analogix,hdcp-support' type to boolean

v3: Fix Rob Herring, Dan Carpenter, Nicolas comment
 - Split the patch, fix not correct return data
 - Fix several coding format
 - Split DP tx swing register setting to two property
 - Add HDCP support vender flag
 - remove 'analogix,swing-setting' and 'analogix,mipi-dpi-in' property

v2: Fix Rob Herring comment
 - Fix yamllint warnings/errors in analogix,anx7625.yaml
 - Fix kernel robot compile warning

v1: initial MIPI rx DPI feature support

Xin Ji (4):
  dt-bindings:drm/bridge:anx7625:add vendor define
  drm/bridge: anx7625: fix not correct return value
  drm/bridge: anx7625: add MIPI DPI input feature
  drm/bridge: anx7625: add HDMI audio function

 .../display/bridge/analogix,anx7625.yaml  |  65 ++-
 drivers/gpu/drm/bridge/analogix/anx7625.c | 458 --
 drivers/gpu/drm/bridge/analogix/anx7625.h |  23 +-
 3 files changed, 491 insertions(+), 55 deletions(-)

-- 
2.25.1



Re: [PATCH v10 1/4] dt-bindings:drm/bridge:anx7625:add vendor define flags

2021-08-05 Thread Xin Ji
On Thu, Jul 29, 2021 at 01:08:24PM -0600, Rob Herring wrote:
> On Mon, Jul 19, 2021 at 06:10:09PM +0800, Xin Ji wrote:
> > Add 'bus-type' and 'data-lanes' define for port0. Define DP tx lane0,
> > lane1 swing register array define, and audio enable flag.
> > 
> > The device which cannot pass DP tx PHY CTS caused by long PCB trace or
> > embedded MUX, adjusting ANX7625 PHY parameters can pass the CTS test. The
> > adjusting type include Pre-emphasis, Vp-p, Rterm(Resistor Termination)
> > and Rsel(Driven Strength). Each lane has maximum 20 registers for
> > these settings.
> > 
> > For the DP tx swing setting, each lane has 10 different combination for
> > swing, as Pre0: swing3|swing2|swing1|swing0, Pre1: swing2|swing1|swing0,
> > Pre2: swing1|swing0, Pre3: swing0.
> > 
> > Register definition as:
> > [Boost_ctrl]
> > These registers control post cursor manual, increase the Boost_Ctrl
> > setting can increase Pre-emphasis value separately.
> > LaneCondition   Register address
> > Lane0   Swing0_Pre0 0x7a:0x00 bit[3:0]
> > Lane0   Swing1_Pre0 0x7a:0x01 bit[3:0]
> > Lane0   Swing2_Pre0 0x7a:0x02 bit[3:0]
> > Lane0   Swing3_Pre0 0x7a:0x03 bit[3:0]
> > Lane0   Swing0_Pre1 0x7a:0x04 bit[3:0]
> > Lane0   Swing1_Pre1 0x7a:0x05 bit[3:0]
> > Lane0   Swing2_Pre1 0x7a:0x06 bit[3:0]
> > Lane0   Swing0_Pre2 0x7a:0x07 bit[3:0]
> > Lane0   Swing1_Pre2 0x7a:0x08 bit[3:0]
> > Lane0   Swing0_Pre3 0x7a:0x09 bit[3:0]
> > Lane1   Swing0_Pre0 0x7a:0x14 bit[3:0]
> > Lane1   Swing1_Pre0 0x7a:0x15 bit[3:0]
> > Lane1   Swing2_Pre0 0x7a:0x16 bit[3:0]
> > Lane1   Swing3_Pre0 0x7a:0x17 bit[3:0]
> > Lane1   Swing0_Pre1 0x7a:0x18 bit[3:0]
> > Lane1   Swing1_Pre1 0x7a:0x19 bit[3:0]
> > Lane1   Swing2_Pre1 0x7a:0x1a bit[3:0]
> > Lane1   Swing0_Pre2 0x7a:0x1b bit[3:0]
> > Lane1   Swing1_Pre2 0x7a:0x1c bit[3:0]
> > Lane1   Swing0_Pre3 0x7a:0x1d bit[3:0]
> > 
> > [Swing_ctrl]
> > These registers control swing manual, increase Swing_Ctrl setting can
> > increase Vp-p value separately.
> > LaneCondition   Register address
> > Lane0   Swing0_Pre0 0x7a:0x00 bit[6:4]
> > Lane0   Swing1_Pre0 0x7a:0x01 bit[6:4]
> > Lane0   Swing2_Pre0 0x7a:0x02 bit[6:4]
> > Lane0   Swing3_Pre0 0x7a:0x03 bit[6:4]
> > Lane0   Swing0_Pre1 0x7a:0x04 bit[6:4]
> > Lane0   Swing1_Pre1 0x7a:0x05 bit[6:4]
> > Lane0   Swing2_Pre1 0x7a:0x06 bit[6:4]
> > Lane0   Swing0_Pre2 0x7a:0x07 bit[6:4]
> > Lane0   Swing1_Pre2 0x7a:0x08 bit[6:4]
> > Lane0   Swing0_Pre3 0x7a:0x09 bit[6:4]
> > Lane1   Swing0_Pre0 0x7a:0x14 bit[6:4]
> > Lane1   Swing1_Pre0 0x7a:0x15 bit[6:4]
> > Lane1   Swing2_Pre0 0x7a:0x16 bit[6:4]
> > Lane1   Swing3_Pre0 0x7a:0x17 bit[6:4]
> > Lane1   Swing0_Pre1 0x7a:0x18 bit[6:4]
> > Lane1   Swing1_Pre1 0x7a:0x19 bit[6:4]
> > Lane1   Swing2_Pre1 0x7a:0x1a bit[6:4]
> > Lane1   Swing0_Pre2 0x7a:0x1b bit[6:4]
> > Lane1   Swing1_Pre2 0x7a:0x1c bit[6:4]
> > Lane1   Swing0_Pre3 0x7a:0x1d bit[6:4]
> > 
> > [Rsel_ctrl]
> > These registers control resistor compensation manual, increase Rsel_ctrl
> > can increase the IO driven strength, increase Vp-p simultaneously.
> > LaneCondition   Register address
> > Lane0   Swing0_Pre0 0x7a:0x0a bit[4:0]
> > Lane0   Swing1_Pre0 0x7a:0x0b bit[4:0]
> > Lane0   Swing2_Pre0 0x7a:0x0c bit[4:0]
> > Lane0   Swing3_Pre0 0x7a:0x0d bit[4:0]
> > Lane0   Swing0_Pre1 0x7a:0x0e bit[4:0]
> > Lane0   Swing1_Pre1 0x7a:0x0f bit[4:0]
> > Lane0   Swing2_Pre1 0x7a:0x10 bit[4:0]
> > Lane0   Swing0_Pre2 0x7a:0x11 bit[4:0]
> > Lane0   Swing1_Pre2 0x7a:0x12 bit[4:0]
> > Lane0   Swing0_Pre3 0x7a:0x13 bit[4:0]
> > Lane1   Swing0_Pre0 0x7a:0x1e bit[4:0]
> > Lane1   Swing1_Pre0 0x7a:0x1f bit[4:0]
> > Lane1   Swing2_Pre0 0x7a:0x20 bit[4:0]
> > Lane1   Swing3_Pre0 0x7a:0x21 bit[4:0]
> > Lane1   Swing0_Pre1 0x7a:0x22 bit[4:0]
> > Lane1   Swing1_Pre1 0x7a:0x23 bit[4:0]
> > Lane1   Swing2_Pre1 0x7a:0x24 bit[4:0]
> > Lane1   Swing0_Pre2 0x7a:0x25 bit[4:0]
> > Lane1   Swing1_Pre2 0x7a:0x26 bit[4:0]
> > Lane1   Swing0_Pre3 0x7a:0x27 bit[4:0]
>

[PATCH v1 1/1] drm/bridge: anx7625: Tune K value for IVO panel

2021-08-05 Thread Xin Ji
IVO panel require less input video clock variation than video clock
variation in DP CTS spec.

This patch decreases the K value of ANX7625 which will shrink eDP Tx
video clock variation to meet IVO panel's requirement.

Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 17 ++---
 drivers/gpu/drm/bridge/analogix/anx7625.h |  4 +++-
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index a3d82377066b..ceed1c7f3f28 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -384,6 +384,18 @@ static int anx7625_odfc_config(struct anx7625_data *ctx,
return ret;
 }
 
+static int anx7625_set_k_value(struct anx7625_data *ctx)
+{
+   struct edid *edid = (struct edid *)ctx->slimport_edid_p.edid_raw_data;
+
+   if (edid->mfg_id[0] == IVO_MID0 && edid->mfg_id[1] == IVO_MID1)
+   return anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_DIGITAL_ADJ_1, 0x3B);
+
+   return anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_DIGITAL_ADJ_1, 0x3D);
+}
+
 static int anx7625_dsi_video_timing_config(struct anx7625_data *ctx)
 {
struct device *dev = >client->dev;
@@ -470,9 +482,8 @@ static int anx7625_dsi_video_timing_config(struct 
anx7625_data *ctx)
MIPI_PLL_N_NUM_15_8, (n >> 8) & 0xff);
ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client, MIPI_PLL_N_NUM_7_0,
(n & 0xff));
-   /* Diff */
-   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
-   MIPI_DIGITAL_ADJ_1, 0x3D);
+   /* Diff and K value */
+   anx7625_set_k_value(ctx);
 
ret |= anx7625_odfc_config(ctx, post_divider - 1);
 
diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h 
b/drivers/gpu/drm/bridge/analogix/anx7625.h
index 034c3840028f..6dcf64c703f9 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.h
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
@@ -210,7 +210,9 @@
 #define  MIPI_VIDEO_STABLE_CNT   0x0A
 
 #define  MIPI_LANE_CTRL_10   0x0F
-#define  MIPI_DIGITAL_ADJ_1   0x1B
+#define  MIPI_DIGITAL_ADJ_1 0x1B
+#define  IVO_MID0   0x26
+#define  IVO_MID1   0xCF
 
 #define  MIPI_PLL_M_NUM_23_16   0x1E
 #define  MIPI_PLL_M_NUM_15_80x1F
-- 
2.25.1



[PATCH v10 4/4] drm/bridge: anx7625: add HDMI audio function

2021-07-19 Thread Xin Ji
Add audio HDMI codec function support, enable it through device true
flag "analogix,audio-enable".

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 226 ++
 drivers/gpu/drm/bridge/analogix/anx7625.h |   5 +
 2 files changed, 231 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index a5a20cc0f3e0..44ab0893f600 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -33,6 +33,7 @@
 #include 
 
 #include 
+#include 
 #include 
 
 #include "anx7625.h"
@@ -153,6 +154,20 @@ static int anx7625_write_and(struct anx7625_data *ctx,
return anx7625_reg_write(ctx, client, offset, (val & (mask)));
 }
 
+static int anx7625_write_and_or(struct anx7625_data *ctx,
+   struct i2c_client *client,
+   u8 offset, u8 and_mask, u8 or_mask)
+{
+   int val;
+
+   val = anx7625_reg_read(ctx, client, offset);
+   if (val < 0)
+   return val;
+
+   return anx7625_reg_write(ctx, client,
+offset, (val & and_mask) | (or_mask));
+}
+
 static int anx7625_config_bit_matrix(struct anx7625_data *ctx)
 {
int i, ret;
@@ -1325,6 +1340,9 @@ static int anx7625_parse_dt(struct device *dev,
else
DRM_DEV_DEBUG_DRIVER(dev, "found MIPI DSI host node.\n");
 
+   if (of_property_read_bool(np, "analogix,audio-enable"))
+   pdata->audio_en = 1;
+
ret = drm_of_find_panel_or_bridge(np, 1, 0, , NULL);
if (ret < 0) {
if (ret == -ENODEV)
@@ -1395,6 +1413,208 @@ static enum drm_connector_status 
anx7625_sink_detect(struct anx7625_data *ctx)
 connector_status_disconnected;
 }
 
+static int anx7625_audio_hw_params(struct device *dev, void *data,
+  struct hdmi_codec_daifmt *fmt,
+  struct hdmi_codec_params *params)
+{
+   struct anx7625_data *ctx = dev_get_drvdata(dev);
+   int wl, ch, rate;
+   int ret = 0;
+
+   if (fmt->fmt != HDMI_DSP_A) {
+   DRM_DEV_ERROR(dev, "only supports DSP_A\n");
+   return -EINVAL;
+   }
+
+   DRM_DEV_DEBUG_DRIVER(dev, "setting %d Hz, %d bit, %d channels\n",
+params->sample_rate, params->sample_width,
+params->cea.channels);
+
+   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_6,
+   ~I2S_SLAVE_MODE,
+   TDM_SLAVE_MODE);
+
+   /* Word length */
+   switch (params->sample_width) {
+   case 16:
+   wl = AUDIO_W_LEN_16_20MAX;
+   break;
+   case 18:
+   wl = AUDIO_W_LEN_18_20MAX;
+   break;
+   case 20:
+   wl = AUDIO_W_LEN_20_20MAX;
+   break;
+   case 24:
+   wl = AUDIO_W_LEN_24_24MAX;
+   break;
+   default:
+   DRM_DEV_DEBUG_DRIVER(dev, "wordlength: %d bit not support",
+params->sample_width);
+   return -EINVAL;
+   }
+   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_5,
+   0xf0, wl);
+
+   /* Channel num */
+   switch (params->cea.channels) {
+   case 2:
+   ch = I2S_CH_2;
+   break;
+   case 4:
+   ch = TDM_CH_4;
+   break;
+   case 6:
+   ch = TDM_CH_6;
+   break;
+   case 8:
+   ch = TDM_CH_8;
+   break;
+   default:
+   DRM_DEV_DEBUG_DRIVER(dev, "channel number: %d not support",
+params->cea.channels);
+   return -EINVAL;
+   }
+   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
+  AUDIO_CHANNEL_STATUS_6, 0x1f, ch << 5);
+   if (ch > I2S_CH_2)
+   ret |= anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_6, AUDIO_LAYOUT);
+   else
+   ret |= anx7625_write_and(ctx, ctx->i2c.tx_p2_client,
+   AUDIO_CHANNEL_STATUS_6, ~AUDIO_LAYOUT);
+
+   /* FS */
+   switch (params->sample_rate) {
+   case 32000:
+   rate = AUDIO_FS_32K;
+   break;
+   case 44100:
+   rate = AUDIO_FS_441K;
+   break;
+   case 48000:
+   rate = AUDIO_FS_48K;
+   break;
+   case 88200:
+   

[PATCH v10 3/4] drm/bridge: anx7625: add MIPI DPI input feature

2021-07-19 Thread Xin Ji
The basic anx7625 driver only support MIPI DSI rx signal input.
This patch add MIPI DPI rx input configuration support, after apply
this patch, the driver can support DSI rx or DPI rx by adding
'bus-type' in DT.

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 246 --
 drivers/gpu/drm/bridge/analogix/anx7625.h |  18 +-
 2 files changed, 204 insertions(+), 60 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 3fc6b7ce7fc7..a5a20cc0f3e0 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -32,6 +32,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 #include "anx7625.h"
@@ -152,18 +153,18 @@ static int anx7625_write_and(struct anx7625_data *ctx,
return anx7625_reg_write(ctx, client, offset, (val & (mask)));
 }
 
-static int anx7625_write_and_or(struct anx7625_data *ctx,
-   struct i2c_client *client,
-   u8 offset, u8 and_mask, u8 or_mask)
+static int anx7625_config_bit_matrix(struct anx7625_data *ctx)
 {
-   int val;
+   int i, ret;
 
-   val = anx7625_reg_read(ctx, client, offset);
-   if (val < 0)
-   return val;
+   ret = anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
+  AUDIO_CONTROL_REGISTER, 0x80);
+   for (i = 0; i < 13; i++)
+   ret |= anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
+VIDEO_BIT_MATRIX_12 + i,
+0x18 + i);
 
-   return anx7625_reg_write(ctx, client,
-offset, (val & and_mask) | (or_mask));
+   return ret;
 }
 
 static int anx7625_read_ctrl_status_p0(struct anx7625_data *ctx)
@@ -221,38 +222,6 @@ static int anx7625_video_mute_control(struct anx7625_data 
*ctx,
return ret;
 }
 
-static int anx7625_config_audio_input(struct anx7625_data *ctx)
-{
-   struct device *dev = >client->dev;
-   int ret;
-
-   /* Channel num */
-   ret = anx7625_reg_write(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_6, I2S_CH_2 << 5);
-
-   /* FS */
-   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_4,
-   0xf0, AUDIO_FS_48K);
-   /* Word length */
-   ret |= anx7625_write_and_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_5,
-   0xf0, AUDIO_W_LEN_24_24MAX);
-   /* I2S */
-   ret |= anx7625_write_or(ctx, ctx->i2c.tx_p2_client,
-   AUDIO_CHANNEL_STATUS_6, I2S_SLAVE_MODE);
-   ret |= anx7625_write_and(ctx, ctx->i2c.tx_p2_client,
-AUDIO_CONTROL_REGISTER, ~TDM_TIMING_MODE);
-   /* Audio change flag */
-   ret |= anx7625_write_or(ctx, ctx->i2c.rx_p0_client,
-   AP_AV_STATUS, AP_AUDIO_CHG);
-
-   if (ret < 0)
-   DRM_DEV_ERROR(dev, "fail to config audio.\n");
-
-   return ret;
-}
-
 /* Reduction of fraction a/b */
 static void anx7625_reduction_of_a_fraction(unsigned long *a, unsigned long *b)
 {
@@ -412,7 +381,7 @@ static int anx7625_dsi_video_timing_config(struct 
anx7625_data *ctx)
ret |= anx7625_write_and(ctx, ctx->i2c.rx_p1_client,
MIPI_LANE_CTRL_0, 0xfc);
ret |= anx7625_write_or(ctx, ctx->i2c.rx_p1_client,
-   MIPI_LANE_CTRL_0, 3);
+   MIPI_LANE_CTRL_0, ctx->pdata.mipi_lanes - 1);
 
/* Htotal */
htotal = ctx->dt.hactive.min + ctx->dt.hfront_porch.min +
@@ -597,6 +566,76 @@ static int anx7625_dsi_config(struct anx7625_data *ctx)
return ret;
 }
 
+static int anx7625_api_dpi_config(struct anx7625_data *ctx)
+{
+   struct device *dev = >client->dev;
+   u16 freq = ctx->dt.pixelclock.min / 1000;
+   int ret;
+
+   /* configure pixel clock */
+   ret = anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+   PIXEL_CLOCK_L, freq & 0xFF);
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p0_client,
+PIXEL_CLOCK_H, (freq >> 8));
+
+   /* set DPI mode */
+   /* set to DPI PLL module sel */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_DIGITAL_PLL_9, 0x20);
+   /* power down MIPI */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+MIPI_LANE_CTRL_10, 0x08);
+   /* enable DPI mode */
+   ret |= anx7625_reg_write(ctx, ctx->i2c.rx_p1_client,
+  

[PATCH v10 2/4] drm/bridge: anx7625: fix not correct return value

2021-07-19 Thread Xin Ji
At some time, the original code may return non zero value, force return 0
if operation finished.

Reviewed-by: Robert Foss 
Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
index a3d82377066b..3fc6b7ce7fc7 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -191,10 +191,10 @@ static int wait_aux_op_finish(struct anx7625_data *ctx)
   AP_AUX_CTRL_STATUS);
if (val < 0 || (val & 0x0F)) {
DRM_DEV_ERROR(dev, "aux status %02x\n", val);
-   val = -EIO;
+   return -EIO;
}
 
-   return val;
+   return 0;
 }
 
 static int anx7625_video_mute_control(struct anx7625_data *ctx,
-- 
2.25.1



  1   2   3   >