Re: [PATCH 10/10] drm: bridge: it66121: Add support for the IT6610

2022-12-15 Thread Robert Foss
On Wed, 14 Dec 2022 at 14:01, Paul Cercueil  wrote:
>
> Add support for the IT6610 HDMI encoder.
>
> The hardware is very similar, and therefore the driver did not require
> too many changes. Some bits are only available on the IT66121, and
> vice-versa. Also, the IT6610 requires specific polarities on the DE and
> pixel lines.
>
> Signed-off-by: Paul Cercueil 
> ---
>  drivers/gpu/drm/bridge/ite-it66121.c | 108 +--
>  1 file changed, 86 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/ite-it66121.c 
> b/drivers/gpu/drm/bridge/ite-it66121.c
> index 43b027b85b8e..b34860871627 100644
> --- a/drivers/gpu/drm/bridge/ite-it66121.c
> +++ b/drivers/gpu/drm/bridge/ite-it66121.c
> @@ -68,6 +68,7 @@
>  #define IT66121_AFE_XP_ENO BIT(4)
>  #define IT66121_AFE_XP_RESETB  BIT(3)
>  #define IT66121_AFE_XP_PWDIBIT(2)
> +#define IT6610_AFE_XP_BYPASS   BIT(0)
>
>  #define IT66121_AFE_IP_REG 0x64
>  #define IT66121_AFE_IP_GAINBIT BIT(7)
> @@ -284,7 +285,13 @@
>
>  #define IT66121_AFE_CLK_HIGH   8 /* Khz */
>
> +enum chip_id {
> +   ID_IT6610,
> +   ID_IT66121,
> +};
> +
>  struct it66121_chip_info {
> +   enum chip_id id;
> u16 vid, pid;
>  };
>
> @@ -391,16 +398,22 @@ static int it66121_configure_afe(struct it66121_ctx 
> *ctx,
>
> ret = regmap_write_bits(ctx->regmap, IT66121_AFE_IP_REG,
> IT66121_AFE_IP_GAINBIT |
> -   IT66121_AFE_IP_ER0 |
> -   IT66121_AFE_IP_EC1,
> +   IT66121_AFE_IP_ER0,
> IT66121_AFE_IP_GAINBIT);
> if (ret)
> return ret;
>
> -   ret = regmap_write_bits(ctx->regmap, IT66121_AFE_XP_EC1_REG,
> -   IT66121_AFE_XP_EC1_LOWCLK, 0x80);
> -   if (ret)
> -   return ret;
> +   if (ctx->info->id == ID_IT66121) {
> +   ret = regmap_write_bits(ctx->regmap, 
> IT66121_AFE_IP_REG,
> +   IT66121_AFE_IP_EC1, 0);
> +   if (ret)
> +   return ret;
> +
> +   ret = regmap_write_bits(ctx->regmap, 
> IT66121_AFE_XP_EC1_REG,
> +   IT66121_AFE_XP_EC1_LOWCLK, 
> 0x80);
> +   if (ret)
> +   return ret;
> +   }
> } else {
> ret = regmap_write_bits(ctx->regmap, IT66121_AFE_XP_REG,
> IT66121_AFE_XP_GAINBIT |
> @@ -411,17 +424,24 @@ static int it66121_configure_afe(struct it66121_ctx 
> *ctx,
>
> ret = regmap_write_bits(ctx->regmap, IT66121_AFE_IP_REG,
> IT66121_AFE_IP_GAINBIT |
> -   IT66121_AFE_IP_ER0 |
> -   IT66121_AFE_IP_EC1, 
> IT66121_AFE_IP_ER0 |
> -   IT66121_AFE_IP_EC1);
> +   IT66121_AFE_IP_ER0,
> +   IT66121_AFE_IP_ER0);
> if (ret)
> return ret;
>
> -   ret = regmap_write_bits(ctx->regmap, IT66121_AFE_XP_EC1_REG,
> -   IT66121_AFE_XP_EC1_LOWCLK,
> -   IT66121_AFE_XP_EC1_LOWCLK);
> -   if (ret)
> -   return ret;
> +   if (ctx->info->id == ID_IT66121) {
> +   ret = regmap_write_bits(ctx->regmap, 
> IT66121_AFE_IP_REG,
> +   IT66121_AFE_IP_EC1,
> +   IT66121_AFE_IP_EC1);
> +   if (ret)
> +   return ret;
> +
> +   ret = regmap_write_bits(ctx->regmap, 
> IT66121_AFE_XP_EC1_REG,
> +   IT66121_AFE_XP_EC1_LOWCLK,
> +   IT66121_AFE_XP_EC1_LOWCLK);
> +   if (ret)
> +   return ret;
> +   }
> }
>
> /* Clear reset flags */
> @@ -430,6 +450,14 @@ static int it66121_configure_afe(struct it66121_ctx *ctx,
> if (ret)
> return ret;
>
> +   if (ctx->info->id == ID_IT6610) {
> +   ret = regmap_write_bits(ctx->regmap, IT66121_AFE_XP_REG,
> +   IT6610_AFE_XP_BYPASS,
> +   IT6610_AFE_XP_BYPASS);
> +   if (ret)
> +   return ret;
> +   }
> +
> 

[PATCH 10/10] drm: bridge: it66121: Add support for the IT6610

2022-12-14 Thread Paul Cercueil
Add support for the IT6610 HDMI encoder.

The hardware is very similar, and therefore the driver did not require
too many changes. Some bits are only available on the IT66121, and
vice-versa. Also, the IT6610 requires specific polarities on the DE and
pixel lines.

Signed-off-by: Paul Cercueil 
---
 drivers/gpu/drm/bridge/ite-it66121.c | 108 +--
 1 file changed, 86 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/bridge/ite-it66121.c 
b/drivers/gpu/drm/bridge/ite-it66121.c
index 43b027b85b8e..b34860871627 100644
--- a/drivers/gpu/drm/bridge/ite-it66121.c
+++ b/drivers/gpu/drm/bridge/ite-it66121.c
@@ -68,6 +68,7 @@
 #define IT66121_AFE_XP_ENO BIT(4)
 #define IT66121_AFE_XP_RESETB  BIT(3)
 #define IT66121_AFE_XP_PWDIBIT(2)
+#define IT6610_AFE_XP_BYPASS   BIT(0)
 
 #define IT66121_AFE_IP_REG 0x64
 #define IT66121_AFE_IP_GAINBIT BIT(7)
@@ -284,7 +285,13 @@
 
 #define IT66121_AFE_CLK_HIGH   8 /* Khz */
 
+enum chip_id {
+   ID_IT6610,
+   ID_IT66121,
+};
+
 struct it66121_chip_info {
+   enum chip_id id;
u16 vid, pid;
 };
 
@@ -391,16 +398,22 @@ static int it66121_configure_afe(struct it66121_ctx *ctx,
 
ret = regmap_write_bits(ctx->regmap, IT66121_AFE_IP_REG,
IT66121_AFE_IP_GAINBIT |
-   IT66121_AFE_IP_ER0 |
-   IT66121_AFE_IP_EC1,
+   IT66121_AFE_IP_ER0,
IT66121_AFE_IP_GAINBIT);
if (ret)
return ret;
 
-   ret = regmap_write_bits(ctx->regmap, IT66121_AFE_XP_EC1_REG,
-   IT66121_AFE_XP_EC1_LOWCLK, 0x80);
-   if (ret)
-   return ret;
+   if (ctx->info->id == ID_IT66121) {
+   ret = regmap_write_bits(ctx->regmap, IT66121_AFE_IP_REG,
+   IT66121_AFE_IP_EC1, 0);
+   if (ret)
+   return ret;
+
+   ret = regmap_write_bits(ctx->regmap, 
IT66121_AFE_XP_EC1_REG,
+   IT66121_AFE_XP_EC1_LOWCLK, 
0x80);
+   if (ret)
+   return ret;
+   }
} else {
ret = regmap_write_bits(ctx->regmap, IT66121_AFE_XP_REG,
IT66121_AFE_XP_GAINBIT |
@@ -411,17 +424,24 @@ static int it66121_configure_afe(struct it66121_ctx *ctx,
 
ret = regmap_write_bits(ctx->regmap, IT66121_AFE_IP_REG,
IT66121_AFE_IP_GAINBIT |
-   IT66121_AFE_IP_ER0 |
-   IT66121_AFE_IP_EC1, IT66121_AFE_IP_ER0 |
-   IT66121_AFE_IP_EC1);
+   IT66121_AFE_IP_ER0,
+   IT66121_AFE_IP_ER0);
if (ret)
return ret;
 
-   ret = regmap_write_bits(ctx->regmap, IT66121_AFE_XP_EC1_REG,
-   IT66121_AFE_XP_EC1_LOWCLK,
-   IT66121_AFE_XP_EC1_LOWCLK);
-   if (ret)
-   return ret;
+   if (ctx->info->id == ID_IT66121) {
+   ret = regmap_write_bits(ctx->regmap, IT66121_AFE_IP_REG,
+   IT66121_AFE_IP_EC1,
+   IT66121_AFE_IP_EC1);
+   if (ret)
+   return ret;
+
+   ret = regmap_write_bits(ctx->regmap, 
IT66121_AFE_XP_EC1_REG,
+   IT66121_AFE_XP_EC1_LOWCLK,
+   IT66121_AFE_XP_EC1_LOWCLK);
+   if (ret)
+   return ret;
+   }
}
 
/* Clear reset flags */
@@ -430,6 +450,14 @@ static int it66121_configure_afe(struct it66121_ctx *ctx,
if (ret)
return ret;
 
+   if (ctx->info->id == ID_IT6610) {
+   ret = regmap_write_bits(ctx->regmap, IT66121_AFE_XP_REG,
+   IT6610_AFE_XP_BYPASS,
+   IT6610_AFE_XP_BYPASS);
+   if (ret)
+   return ret;
+   }
+
return it66121_fire_afe(ctx);
 }
 
@@ -491,7 +519,6 @@ static int it66121_get_edid_block(void *context, u8 *buf,
  unsigned int block, size_t len)
 {
struct it66121_ctx *ctx = context;
-   unsigned int val;
int remain = len;