Re: [PATCH v16 2/2] drm/bridge: anx7625: Add anx7625 MIPI DSI/DPI to DP

2020-09-19 Thread Xin Ji
On Fri, Sep 18, 2020 at 11:45:34AM +0300, Dan Carpenter wrote:
> Hi Xin,
> 
> url:
> https://github.com/0day-ci/linux/commits/Xin-Ji/Add-initial-support-for-slimport-anx7625/20200917-163238
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
> 5925fa68fe8244651b3f78a88c4af99190a88f0d
> config: mips-randconfig-m031-20200917 (attached as .config)
> compiler: mips-linux-gcc (GCC) 9.3.0
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot 
> Reported-by: Dan Carpenter 
Hi Dan, OK, I'll fix it right now.
Thanks,
Xin
> 
> smatch warnings:
> drivers/gpu/drm/bridge/analogix/anx7625.c:1289 anx7625_get_edid() warn: 
> possible memory leak of 'edid'
> 
> # 
> https://github.com/0day-ci/linux/commit/667ee517c70d2bedafe5bfa0dc5f13fc60d5133d
> git remote add linux-review https://github.com/0day-ci/linux
> git fetch --no-tags linux-review 
> Xin-Ji/Add-initial-support-for-slimport-anx7625/20200917-163238
> git checkout 667ee517c70d2bedafe5bfa0dc5f13fc60d5133d
> vim +/edid +1289 drivers/gpu/drm/bridge/analogix/anx7625.c
> 
> 667ee517c70d2be Xin Ji 2020-09-17  1264  static struct edid 
> *anx7625_get_edid(struct anx7625_data *ctx)
> 667ee517c70d2be Xin Ji 2020-09-17  1265  {
> 667ee517c70d2be Xin Ji 2020-09-17  1266   struct device *dev = 
> >client->dev;
> 667ee517c70d2be Xin Ji 2020-09-17  1267   struct s_edid_data *p_edid = 
> >slimport_edid_p;
> 667ee517c70d2be Xin Ji 2020-09-17  1268   int edid_num;
> 667ee517c70d2be Xin Ji 2020-09-17  1269   u8 *edid;
> 667ee517c70d2be Xin Ji 2020-09-17  1270  
> 667ee517c70d2be Xin Ji 2020-09-17  1271   edid = kmalloc(FOUR_BLOCK_SIZE, 
> GFP_KERNEL);
> 667ee517c70d2be Xin Ji 2020-09-17  1272   if (!edid) {
> 667ee517c70d2be Xin Ji 2020-09-17  1273   DRM_DEV_ERROR(dev, 
> "Fail to allocate buffer\n");
> 667ee517c70d2be Xin Ji 2020-09-17  1274   return NULL;
> 667ee517c70d2be Xin Ji 2020-09-17  1275   }
> 667ee517c70d2be Xin Ji 2020-09-17  1276  
> 667ee517c70d2be Xin Ji 2020-09-17  1277   if 
> (ctx->slimport_edid_p.edid_block_num > 0) {
> 667ee517c70d2be Xin Ji 2020-09-17  1278   memcpy(edid, 
> ctx->slimport_edid_p.edid_raw_data,
> 667ee517c70d2be Xin Ji 2020-09-17  1279  FOUR_BLOCK_SIZE);
> 667ee517c70d2be Xin Ji 2020-09-17  1280   return (struct edid 
> *)edid;
> 667ee517c70d2be Xin Ji 2020-09-17  1281   }
> 667ee517c70d2be Xin Ji 2020-09-17  1282  
> 667ee517c70d2be Xin Ji 2020-09-17  1283   
> anx7625_low_power_mode_check(ctx, 1);
> 667ee517c70d2be Xin Ji 2020-09-17  1284   edid_num = sp_tx_edid_read(ctx, 
> p_edid->edid_raw_data);
> 667ee517c70d2be Xin Ji 2020-09-17  1285   
> anx7625_low_power_mode_check(ctx, 0);
> 667ee517c70d2be Xin Ji 2020-09-17  1286  
> 667ee517c70d2be Xin Ji 2020-09-17  1287   if (edid_num < 1) {
> 667ee517c70d2be Xin Ji 2020-09-17  1288   DRM_DEV_ERROR(dev, 
> "Fail to read EDID: %d\n", edid_num);
> 667ee517c70d2be Xin Ji 2020-09-17 @1289   return NULL;
> 
> kfree(edid); before returning.
> 
> 667ee517c70d2be Xin Ji 2020-09-17  1290   }
> 667ee517c70d2be Xin Ji 2020-09-17  1291  
> 667ee517c70d2be Xin Ji 2020-09-17  1292   p_edid->edid_block_num = 
> edid_num;
> 667ee517c70d2be Xin Ji 2020-09-17  1293  
> 667ee517c70d2be Xin Ji 2020-09-17  1294   memcpy(edid, 
> ctx->slimport_edid_p.edid_raw_data, FOUR_BLOCK_SIZE);
> 667ee517c70d2be Xin Ji 2020-09-17  1295   return (struct edid *)edid;
> 667ee517c70d2be Xin Ji 2020-09-17  1296  }
> 
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v16 2/2] drm/bridge: anx7625: Add anx7625 MIPI DSI/DPI to DP

2020-09-17 Thread Xin Ji
The ANX7625 is an ultra-low power 4K Mobile HD Transmitter designed
for portable device. It converts MIPI DSI/DPI to DisplayPort 1.3 4K.

Signed-off-by: Xin Ji 
---
 drivers/gpu/drm/bridge/analogix/Kconfig   |9 +
 drivers/gpu/drm/bridge/analogix/Makefile  |1 +
 drivers/gpu/drm/bridge/analogix/anx7625.c | 1849 +
 drivers/gpu/drm/bridge/analogix/anx7625.h |  390 ++
 4 files changed, 2249 insertions(+)
 create mode 100644 drivers/gpu/drm/bridge/analogix/anx7625.c
 create mode 100644 drivers/gpu/drm/bridge/analogix/anx7625.h

diff --git a/drivers/gpu/drm/bridge/analogix/Kconfig 
b/drivers/gpu/drm/bridge/analogix/Kconfig
index e1fa7d8..024ea2a 100644
--- a/drivers/gpu/drm/bridge/analogix/Kconfig
+++ b/drivers/gpu/drm/bridge/analogix/Kconfig
@@ -25,3 +25,12 @@ config DRM_ANALOGIX_ANX78XX
 config DRM_ANALOGIX_DP
tristate
depends on DRM
+
+config DRM_ANALOGIX_ANX7625
+   tristate "Analogix Anx7625 MIPI to DP interface support"
+   depends on DRM
+   depends on OF
+   help
+ ANX7625 is an ultra-low power 4K mobile HD transmitter
+ designed for portable devices. It converts MIPI/DPI to
+ DisplayPort1.3 4K.
diff --git a/drivers/gpu/drm/bridge/analogix/Makefile 
b/drivers/gpu/drm/bridge/analogix/Makefile
index 97669b3..44da392 100644
--- a/drivers/gpu/drm/bridge/analogix/Makefile
+++ b/drivers/gpu/drm/bridge/analogix/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 analogix_dp-objs := analogix_dp_core.o analogix_dp_reg.o analogix-i2c-dptx.o
 obj-$(CONFIG_DRM_ANALOGIX_ANX6345) += analogix-anx6345.o
+obj-$(CONFIG_DRM_ANALOGIX_ANX7625) += anx7625.o
 obj-$(CONFIG_DRM_ANALOGIX_ANX78XX) += analogix-anx78xx.o
 obj-$(CONFIG_DRM_ANALOGIX_DP) += analogix_dp.o
diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c 
b/drivers/gpu/drm/bridge/analogix/anx7625.c
new file mode 100644
index 000..cec37da
--- /dev/null
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -0,0 +1,1849 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright(c) 2020, Analogix Semiconductor. All rights reserved.
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "anx7625.h"
+
+/*
+ * There is a sync issue while access I2C register between AP(CPU) and
+ * internal firmware(OCM), to avoid the race condition, AP should access
+ * the reserved slave address before slave address occurs changes.
+ */
+static int i2c_access_workaround(struct anx7625_data *ctx,
+struct i2c_client *client)
+{
+   u8 offset;
+   struct device *dev = >dev;
+   int ret;
+
+   if (client == ctx->last_client)
+   return 0;
+
+   ctx->last_client = client;
+
+   if (client == ctx->i2c.tcpc_client)
+   offset = RSVD_00_ADDR;
+   else if (client == ctx->i2c.tx_p0_client)
+   offset = RSVD_D1_ADDR;
+   else if (client == ctx->i2c.tx_p1_client)
+   offset = RSVD_60_ADDR;
+   else if (client == ctx->i2c.rx_p0_client)
+   offset = RSVD_39_ADDR;
+   else if (client == ctx->i2c.rx_p1_client)
+   offset = RSVD_7F_ADDR;
+   else
+   offset = RSVD_00_ADDR;
+
+   ret = i2c_smbus_write_byte_data(client, offset, 0x00);
+   if (ret < 0)
+   DRM_DEV_ERROR(dev,
+ "fail to access i2c id=%x\n:%x",
+ client->addr, offset);
+
+   return ret;
+}
+
+static int anx7625_reg_read(struct anx7625_data *ctx,
+   struct i2c_client *client, u8 reg_addr)
+{
+   int ret;
+   struct device *dev = >dev;
+
+   i2c_access_workaround(ctx, client);
+
+   ret = i2c_smbus_read_byte_data(client, reg_addr);
+   if (ret < 0)
+   DRM_DEV_ERROR(dev, "read i2c fail id=%x:%x\n",
+ client->addr, reg_addr);
+
+   return ret;
+}
+
+static int anx7625_reg_block_read(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_read_i2c_block_data(client, reg_addr, len, buf);
+   if (ret < 0)
+   DRM_DEV_ERROR(dev, "read i2c block fail id=%x:%x\n",
+ client->addr, reg_addr);
+
+   return ret;
+}
+
+static int anx7625_reg_write(struct anx7625_data *ctx,
+struct i2c_client *client,
+u8 reg_addr, u8 reg_val)
+{
+   int ret;
+   struct device *dev = >dev;
+
+   i2c_access_workaround(ctx, client);
+
+   ret =