You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2023/01/13 09:00:39 UTC

[GitHub] [nuttx] shuai532209720 opened a new pull request, #8103: feat: add mipidsi support

shuai532209720 opened a new pull request, #8103:
URL: https://github.com/apache/nuttx/pull/8103

   add mipi dsi subsystem support.
   
   reference links:
   https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/drm_mipi_dsi.c https://github.com/torvalds/linux/blob/master/include/video/mipi_display.h
   
   Signed-off-by: liushuai25 <li...@xiaomi.com>
   
   ## Summary
   Add mipi dsi subsystem.
   Decouple panel driver and chip dsi driver.
   ## Impact
   
   ## Testing
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 merged pull request #8103: feat: add mipidsi support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #8103:
URL: https://github.com/apache/nuttx/pull/8103


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #8103: feat: add mipidsi support

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #8103:
URL: https://github.com/apache/nuttx/pull/8103#discussion_r1069116924


##########
drivers/video/mipidsi/mipi_dsi_device.c:
##########
@@ -0,0 +1,1023 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_device.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <nuttx/video/mipi_display.h>
+#include <nuttx/kmalloc.h>
+
+#include "mipi_dsi.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_transfer
+ *
+ * Description:
+ *   Transfer message to display modules
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *   msg - Message to transfer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transfered or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_transfer(FAR struct mipi_dsi_device *device,
+                          FAR struct mipi_dsi_msg *msg)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->transfer == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_LPM)

Review Comment:
   minor
   ```suggestion
     if ((device->mode_flags & MIPI_DSI_MODE_LPM) != 0)
   ```



##########
drivers/video/mipidsi/mipi_dsi_device.c:
##########
@@ -0,0 +1,1023 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_device.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <nuttx/video/mipi_display.h>
+#include <nuttx/kmalloc.h>
+
+#include "mipi_dsi.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_transfer
+ *
+ * Description:
+ *   Transfer message to display modules
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *   msg - Message to transfer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transfered or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_transfer(FAR struct mipi_dsi_device *device,
+                          FAR struct mipi_dsi_msg *msg)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->transfer == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_LPM)
+    {
+      msg->flags |= MIPI_DSI_MSG_USE_LPM;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_AFTER_FRAME)

Review Comment:
   minor
   ```suggestion
     if ((device->mode_flags & MIPI_DSI_MODE_AFTER_FRAME) != 0)
   ```



##########
drivers/video/mipidsi/mipi_dsi_device.c:
##########
@@ -0,0 +1,1023 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_device.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <nuttx/video/mipi_display.h>
+#include <nuttx/kmalloc.h>
+
+#include "mipi_dsi.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_transfer
+ *
+ * Description:
+ *   Transfer message to display modules
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *   msg - Message to transfer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transfered or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_transfer(FAR struct mipi_dsi_device *device,
+                          FAR struct mipi_dsi_msg *msg)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->transfer == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_LPM)
+    {
+      msg->flags |= MIPI_DSI_MSG_USE_LPM;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_AFTER_FRAME)
+    {
+      msg->flags |= MIPI_DSI_MSG_AFTER_FRAME;
+    }
+
+  return ops->transfer(device->host, msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_attach
+ *
+ * Description:
+ *   Attach a DSI device to its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_attach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->attach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->attach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_detach
+ *
+ * Description:
+ *   Detach a DSI device from its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_detach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->detach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->detach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_shutdown_peripheral
+ *
+ * Description:
+ *   Send a Shutdown Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_shutdown_peripheral(FAR struct mipi_dsi_device *device)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SHUTDOWN_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,

Review Comment:
   can we use C89 compatible initializer?



##########
drivers/video/mipidsi/mipi_dsi_device.c:
##########
@@ -0,0 +1,1023 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_device.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <nuttx/video/mipi_display.h>
+#include <nuttx/kmalloc.h>
+
+#include "mipi_dsi.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_transfer
+ *
+ * Description:
+ *   Transfer message to display modules
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *   msg - Message to transfer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transfered or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_transfer(FAR struct mipi_dsi_device *device,
+                          FAR struct mipi_dsi_msg *msg)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->transfer == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_LPM)
+    {
+      msg->flags |= MIPI_DSI_MSG_USE_LPM;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_AFTER_FRAME)
+    {
+      msg->flags |= MIPI_DSI_MSG_AFTER_FRAME;
+    }
+
+  return ops->transfer(device->host, msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_attach
+ *
+ * Description:
+ *   Attach a DSI device to its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_attach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->attach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->attach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_detach
+ *
+ * Description:
+ *   Detach a DSI device from its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_detach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->detach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->detach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_shutdown_peripheral
+ *
+ * Description:
+ *   Send a Shutdown Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_shutdown_peripheral(FAR struct mipi_dsi_device *device)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SHUTDOWN_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  int ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_turn_on_peripheral
+ *
+ * Description:
+ *   Send a Turn On Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_turn_on_peripheral(FAR struct mipi_dsi_device *device)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_TURN_ON_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,

Review Comment:
   ditto



##########
drivers/video/mipidsi/mipi_dsi_device.c:
##########
@@ -0,0 +1,1023 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_device.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <nuttx/video/mipi_display.h>
+#include <nuttx/kmalloc.h>
+
+#include "mipi_dsi.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_transfer
+ *
+ * Description:
+ *   Transfer message to display modules
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *   msg - Message to transfer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transfered or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_transfer(FAR struct mipi_dsi_device *device,
+                          FAR struct mipi_dsi_msg *msg)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->transfer == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_LPM)
+    {
+      msg->flags |= MIPI_DSI_MSG_USE_LPM;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_AFTER_FRAME)
+    {
+      msg->flags |= MIPI_DSI_MSG_AFTER_FRAME;
+    }
+
+  return ops->transfer(device->host, msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_attach
+ *
+ * Description:
+ *   Attach a DSI device to its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_attach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->attach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->attach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_detach
+ *
+ * Description:
+ *   Detach a DSI device from its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_detach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->detach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->detach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_shutdown_peripheral
+ *
+ * Description:
+ *   Send a Shutdown Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_shutdown_peripheral(FAR struct mipi_dsi_device *device)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SHUTDOWN_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  int ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_turn_on_peripheral
+ *
+ * Description:
+ *   Send a Turn On Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_turn_on_peripheral(FAR struct mipi_dsi_device *device)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_TURN_ON_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_set_maximum_return_packet_size
+ *
+ * Description:
+ *   Specify the maximum size of the payload in a long packet transmitted
+ *   from the peripheral back to the device host processor
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   value - The maximum size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_set_maximum_return_packet_size(
+                          FAR struct mipi_dsi_device *device, uint16_t value)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { value & 0xff, value >> 8 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_compression_mode
+ *
+ * Description:
+ *   Enable / disable DSC on the peripheral. Enable or disable Display Stream
+ *   Compression on the peripheral using the default Picture Parameter Set
+ *   and VESA DSC 1.1 algorithm.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   enable - Whether to enable or disable the DSC
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_compression_mode(FAR struct mipi_dsi_device *device,
+                              bool enable)
+{
+  /* Note: Needs updating for non-default PPS or algorithm */
+
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_COMPRESSION_MODE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { enable & 0xff, 0 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_generic_write
+ *
+ * Description:
+ *   Transmit data using a generic write packet
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   payload - buffer containing the payload
+ *   size - size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_generic_write(FAR struct mipi_dsi_device *device,
+                           FAR const void *payload,
+                           size_t size)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_buf = payload,
+    .tx_len = size
+  };
+
+  switch (size)
+    {
+    case 0:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM;
+      break;
+
+    case 1:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM;
+      break;
+
+    case 2:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM;
+      break;
+
+    default:
+      msg.type = MIPI_DSI_LONG_GENERIC_WRITE;
+      break;
+    }
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_generic_read
+ *
+ * Description:
+ *   Receive data using a generic read packet.
+ *   This function will automatically choose the right data type depending on
+ *   the number of parameters passed in.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   params - buffer containing the request parameters
+ *   num_params - number of request parameters
+ *   data - buffer in which to return the received data
+ *   size - size of receive buffer
+ *
+ * Returned Value:
+ *   The number of bytes successfully read or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_generic_read(FAR struct mipi_dsi_device *device,
+                              FAR const void *params,
+                              size_t num_params,
+                              FAR void *data,
+                              size_t size)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_len = num_params,
+    .tx_buf = params,
+    .rx_len = size,

Review Comment:
   ditto



##########
drivers/video/mipidsi/mipi_dsi_device.c:
##########
@@ -0,0 +1,1023 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_device.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <nuttx/video/mipi_display.h>
+#include <nuttx/kmalloc.h>
+
+#include "mipi_dsi.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_transfer
+ *
+ * Description:
+ *   Transfer message to display modules
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *   msg - Message to transfer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transfered or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_transfer(FAR struct mipi_dsi_device *device,
+                          FAR struct mipi_dsi_msg *msg)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->transfer == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_LPM)
+    {
+      msg->flags |= MIPI_DSI_MSG_USE_LPM;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_AFTER_FRAME)
+    {
+      msg->flags |= MIPI_DSI_MSG_AFTER_FRAME;
+    }
+
+  return ops->transfer(device->host, msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_attach
+ *
+ * Description:
+ *   Attach a DSI device to its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_attach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->attach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->attach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_detach
+ *
+ * Description:
+ *   Detach a DSI device from its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_detach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->detach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->detach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_shutdown_peripheral
+ *
+ * Description:
+ *   Send a Shutdown Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_shutdown_peripheral(FAR struct mipi_dsi_device *device)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SHUTDOWN_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  int ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_turn_on_peripheral
+ *
+ * Description:
+ *   Send a Turn On Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_turn_on_peripheral(FAR struct mipi_dsi_device *device)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_TURN_ON_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_set_maximum_return_packet_size
+ *
+ * Description:
+ *   Specify the maximum size of the payload in a long packet transmitted
+ *   from the peripheral back to the device host processor
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   value - The maximum size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_set_maximum_return_packet_size(
+                          FAR struct mipi_dsi_device *device, uint16_t value)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { value & 0xff, value >> 8 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_compression_mode
+ *
+ * Description:
+ *   Enable / disable DSC on the peripheral. Enable or disable Display Stream
+ *   Compression on the peripheral using the default Picture Parameter Set
+ *   and VESA DSC 1.1 algorithm.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   enable - Whether to enable or disable the DSC
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_compression_mode(FAR struct mipi_dsi_device *device,
+                              bool enable)
+{
+  /* Note: Needs updating for non-default PPS or algorithm */
+
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_COMPRESSION_MODE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { enable & 0xff, 0 },

Review Comment:
   ditto



##########
drivers/video/mipidsi/mipi_dsi_device.c:
##########
@@ -0,0 +1,1023 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_device.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <nuttx/video/mipi_display.h>
+#include <nuttx/kmalloc.h>
+
+#include "mipi_dsi.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_transfer
+ *
+ * Description:
+ *   Transfer message to display modules
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *   msg - Message to transfer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transfered or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_transfer(FAR struct mipi_dsi_device *device,
+                          FAR struct mipi_dsi_msg *msg)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->transfer == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_LPM)
+    {
+      msg->flags |= MIPI_DSI_MSG_USE_LPM;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_AFTER_FRAME)
+    {
+      msg->flags |= MIPI_DSI_MSG_AFTER_FRAME;
+    }
+
+  return ops->transfer(device->host, msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_attach
+ *
+ * Description:
+ *   Attach a DSI device to its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_attach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->attach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->attach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_detach
+ *
+ * Description:
+ *   Detach a DSI device from its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_detach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->detach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->detach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_shutdown_peripheral
+ *
+ * Description:
+ *   Send a Shutdown Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_shutdown_peripheral(FAR struct mipi_dsi_device *device)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SHUTDOWN_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  int ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_turn_on_peripheral
+ *
+ * Description:
+ *   Send a Turn On Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_turn_on_peripheral(FAR struct mipi_dsi_device *device)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_TURN_ON_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_set_maximum_return_packet_size
+ *
+ * Description:
+ *   Specify the maximum size of the payload in a long packet transmitted
+ *   from the peripheral back to the device host processor
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   value - The maximum size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_set_maximum_return_packet_size(
+                          FAR struct mipi_dsi_device *device, uint16_t value)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { value & 0xff, value >> 8 },
+  };

Review Comment:
   ditto



##########
drivers/video/mipidsi/mipi_dsi_device.c:
##########
@@ -0,0 +1,1023 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_device.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <nuttx/video/mipi_display.h>
+#include <nuttx/kmalloc.h>
+
+#include "mipi_dsi.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_transfer
+ *
+ * Description:
+ *   Transfer message to display modules
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *   msg - Message to transfer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transfered or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_transfer(FAR struct mipi_dsi_device *device,
+                          FAR struct mipi_dsi_msg *msg)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->transfer == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_LPM)
+    {
+      msg->flags |= MIPI_DSI_MSG_USE_LPM;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_AFTER_FRAME)
+    {
+      msg->flags |= MIPI_DSI_MSG_AFTER_FRAME;
+    }
+
+  return ops->transfer(device->host, msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_attach
+ *
+ * Description:
+ *   Attach a DSI device to its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_attach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->attach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->attach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_detach
+ *
+ * Description:
+ *   Detach a DSI device from its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_detach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->detach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->detach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_shutdown_peripheral
+ *
+ * Description:
+ *   Send a Shutdown Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_shutdown_peripheral(FAR struct mipi_dsi_device *device)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SHUTDOWN_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  int ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_turn_on_peripheral
+ *
+ * Description:
+ *   Send a Turn On Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_turn_on_peripheral(FAR struct mipi_dsi_device *device)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_TURN_ON_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_set_maximum_return_packet_size
+ *
+ * Description:
+ *   Specify the maximum size of the payload in a long packet transmitted
+ *   from the peripheral back to the device host processor
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   value - The maximum size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_set_maximum_return_packet_size(
+                          FAR struct mipi_dsi_device *device, uint16_t value)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { value & 0xff, value >> 8 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_compression_mode
+ *
+ * Description:
+ *   Enable / disable DSC on the peripheral. Enable or disable Display Stream
+ *   Compression on the peripheral using the default Picture Parameter Set
+ *   and VESA DSC 1.1 algorithm.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   enable - Whether to enable or disable the DSC
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_compression_mode(FAR struct mipi_dsi_device *device,
+                              bool enable)
+{
+  /* Note: Needs updating for non-default PPS or algorithm */
+
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_COMPRESSION_MODE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { enable & 0xff, 0 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_generic_write
+ *
+ * Description:
+ *   Transmit data using a generic write packet
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   payload - buffer containing the payload
+ *   size - size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_generic_write(FAR struct mipi_dsi_device *device,
+                           FAR const void *payload,
+                           size_t size)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_buf = payload,
+    .tx_len = size
+  };
+
+  switch (size)
+    {
+    case 0:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM;
+      break;
+
+    case 1:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM;
+      break;
+
+    case 2:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM;
+      break;
+
+    default:
+      msg.type = MIPI_DSI_LONG_GENERIC_WRITE;
+      break;
+    }
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_generic_read
+ *
+ * Description:
+ *   Receive data using a generic read packet.
+ *   This function will automatically choose the right data type depending on
+ *   the number of parameters passed in.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   params - buffer containing the request parameters
+ *   num_params - number of request parameters
+ *   data - buffer in which to return the received data
+ *   size - size of receive buffer
+ *
+ * Returned Value:
+ *   The number of bytes successfully read or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_generic_read(FAR struct mipi_dsi_device *device,
+                              FAR const void *params,
+                              size_t num_params,
+                              FAR void *data,
+                              size_t size)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_len = num_params,
+    .tx_buf = params,
+    .rx_len = size,
+    .rx_buf = data
+  };
+
+  switch (num_params)
+    {
+    case 0:
+      msg.type = MIPI_DSI_GENERIC_READ_0_PARAM;
+      break;
+    case 1:
+      msg.type = MIPI_DSI_GENERIC_READ_1_PARAM;
+      break;
+    case 2:
+      msg.type = MIPI_DSI_GENERIC_READ_2_PARAM;
+      break;
+    default:
+      return -EINVAL;
+    }
+
+  return mipi_dsi_transfer(device, &msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_dcs_write_buffer
+ *
+ * Description:
+ *   Transmit a DCS command with payload.
+ *   This function will automatically choose the right data type depending on
+ *   the command payload length.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   data - buffer containing data to be transmitted
+ *   len - size of transmission buffer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transmitted or a negative error
+ *   code on failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_dcs_write_buffer(FAR struct mipi_dsi_device *device,
+                                  FAR const void *data,
+                                  size_t len)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_buf = data,
+    .tx_len = len
+  };
+
+  switch (len)
+    {
+    case 0:
+      return -EINVAL;
+    case 1:
+      msg.type = MIPI_DSI_DCS_SHORT_WRITE_0_PARAM;
+      break;
+    case 2:
+      msg.type = MIPI_DSI_DCS_SHORT_WRITE_1_PARAM;
+      break;
+    default:
+      msg.type = MIPI_DSI_DCS_LONG_WRITE;
+      break;

Review Comment:
   ```suggestion
         case 0:
           return -EINVAL;
         case 1:
           msg.type = MIPI_DSI_DCS_SHORT_WRITE_0_PARAM;
           break;
         case 2:
           msg.type = MIPI_DSI_DCS_SHORT_WRITE_1_PARAM;
           break;
         default:
           msg.type = MIPI_DSI_DCS_LONG_WRITE;
           break;
   ```



##########
drivers/video/mipidsi/mipi_dsi_device.c:
##########
@@ -0,0 +1,1023 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_device.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <nuttx/video/mipi_display.h>
+#include <nuttx/kmalloc.h>
+
+#include "mipi_dsi.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_transfer
+ *
+ * Description:
+ *   Transfer message to display modules
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *   msg - Message to transfer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transfered or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_transfer(FAR struct mipi_dsi_device *device,
+                          FAR struct mipi_dsi_msg *msg)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->transfer == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_LPM)
+    {
+      msg->flags |= MIPI_DSI_MSG_USE_LPM;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_AFTER_FRAME)
+    {
+      msg->flags |= MIPI_DSI_MSG_AFTER_FRAME;
+    }
+
+  return ops->transfer(device->host, msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_attach
+ *
+ * Description:
+ *   Attach a DSI device to its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_attach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->attach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->attach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_detach
+ *
+ * Description:
+ *   Detach a DSI device from its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_detach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->detach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->detach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_shutdown_peripheral
+ *
+ * Description:
+ *   Send a Shutdown Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_shutdown_peripheral(FAR struct mipi_dsi_device *device)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SHUTDOWN_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  int ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_turn_on_peripheral
+ *
+ * Description:
+ *   Send a Turn On Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_turn_on_peripheral(FAR struct mipi_dsi_device *device)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_TURN_ON_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_set_maximum_return_packet_size
+ *
+ * Description:
+ *   Specify the maximum size of the payload in a long packet transmitted
+ *   from the peripheral back to the device host processor
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   value - The maximum size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_set_maximum_return_packet_size(
+                          FAR struct mipi_dsi_device *device, uint16_t value)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { value & 0xff, value >> 8 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_compression_mode
+ *
+ * Description:
+ *   Enable / disable DSC on the peripheral. Enable or disable Display Stream
+ *   Compression on the peripheral using the default Picture Parameter Set
+ *   and VESA DSC 1.1 algorithm.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   enable - Whether to enable or disable the DSC
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_compression_mode(FAR struct mipi_dsi_device *device,
+                              bool enable)
+{
+  /* Note: Needs updating for non-default PPS or algorithm */
+
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_COMPRESSION_MODE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { enable & 0xff, 0 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_generic_write
+ *
+ * Description:
+ *   Transmit data using a generic write packet
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   payload - buffer containing the payload
+ *   size - size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_generic_write(FAR struct mipi_dsi_device *device,
+                           FAR const void *payload,
+                           size_t size)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_buf = payload,
+    .tx_len = size
+  };
+
+  switch (size)
+    {
+    case 0:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM;
+      break;
+
+    case 1:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM;
+      break;
+
+    case 2:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM;
+      break;
+
+    default:
+      msg.type = MIPI_DSI_LONG_GENERIC_WRITE;
+      break;
+    }

Review Comment:
   ```suggestion
     switch (size)
       {
         case 0:
           msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM;
           break;
   
         case 1:
           msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM;
           break;
   
         case 2:
           msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM;
           break;
   
         default:
           msg.type = MIPI_DSI_LONG_GENERIC_WRITE;
           break;
       }
   ```



##########
drivers/video/mipidsi/mipi_dsi_host.c:
##########
@@ -0,0 +1,165 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_host.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <debug.h>
+
+#include <nuttx/kmalloc.h>
+
+#include "mipi_dsi.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct mipi_dsi_hosts_s
+{
+  int count;
+  struct mipi_dsi_host *hosts[0];

Review Comment:
   C89 incompatible.
   Maybe `struct mipi_dsi_host *hosts[1];` can be used?



##########
drivers/video/mipidsi/mipi_dsi_packet.c:
##########
@@ -0,0 +1,220 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_packet.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <assert.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include <nuttx/video/mipi_dsi.h>
+#include <nuttx/video/mipi_display.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_pixel_format_to_bpp
+ *
+ * Description:
+ *   Obtain the number of bits per pixel for any given pixel format defined
+ *   by the MIPI DSI specification
+ *
+ * Input Parameters:
+ *   fmt - MIPI DSI pixel format
+ *
+ * Returned Value:
+ *   The number of bits per pixel of the given pixel format.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_pixel_format_to_bpp(uint8_t fmt)
+{
+  switch (fmt)
+    {
+    case MIPI_DSI_FMT_RGB888:
+    case MIPI_DSI_FMT_RGB666:
+      return 24;
+    case MIPI_DSI_FMT_RGB666_PACKED:
+      return 18;
+    case MIPI_DSI_FMT_RGB565:
+      return 16;
+    }
+
+  return -EINVAL;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_packet_format_is_short
+ *
+ * Description:
+ *   Check if a packet is of the short format
+ *
+ * Input Parameters:
+ *   type - MIPI DSI data type of the packet
+ *
+ * Returned Value:
+ *   True if the packet for the given data type is a short packet, false
+ *   otherwise.
+ *
+ ****************************************************************************/
+
+bool mipi_dsi_packet_format_is_short(uint8_t type)
+{
+  switch (type)
+    {
+    case MIPI_DSI_VSYNC_START:
+    case MIPI_DSI_VSYNC_END:
+    case MIPI_DSI_HSYNC_START:
+    case MIPI_DSI_HSYNC_END:
+    case MIPI_DSI_COMPRESSION_MODE:
+    case MIPI_DSI_END_OF_TRANSMISSION:
+    case MIPI_DSI_COLOR_MODE_OFF:
+    case MIPI_DSI_COLOR_MODE_ON:
+    case MIPI_DSI_SHUTDOWN_PERIPHERAL:
+    case MIPI_DSI_TURN_ON_PERIPHERAL:
+    case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
+    case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
+    case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
+    case MIPI_DSI_GENERIC_READ_0_PARAM:
+    case MIPI_DSI_GENERIC_READ_1_PARAM:
+    case MIPI_DSI_GENERIC_READ_2_PARAM:
+    case MIPI_DSI_DCS_SHORT_WRITE_0_PARAM:
+    case MIPI_DSI_DCS_SHORT_WRITE_1_PARAM:
+    case MIPI_DSI_DCS_READ_0_PARAM:
+    case MIPI_DSI_EXECUTE_QUEUE:
+    case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE:
+      return true;

Review Comment:
   add 2 more spaces for case block



##########
drivers/video/mipidsi/mipi_dsi_host_driver.c:
##########
@@ -0,0 +1,209 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_host_driver.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <debug.h>
+#include <stdio.h>
+
+#include <nuttx/kmalloc.h>
+
+#include "mipi_dsi.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Device naming ************************************************************/
+
+#define MIPI_DSI_HOSTNAME_FMT "/dev/dsi%d/host"
+#define MIPI_DSI_HOSTNAME_LEN 128
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* Driver state structure */
+
+struct mipi_dsi_host_driver_s
+{
+  FAR struct mipi_dsi_host *host;
+  mutex_t lock;                           /* Mutual exclusion */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static ssize_t dsi_host_read(FAR struct file *filep, FAR char *buffer,
+                             size_t len);
+static ssize_t dsi_host_write(FAR struct file *filep, FAR const char *buffer,
+                              size_t len);
+static int     dsi_host_ioctl(FAR struct file *filep, int cmd,
+                              unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations dsi_host_fops =
+{
+  NULL,             /* open */
+  NULL,             /* close */
+  dsi_host_read,    /* read */
+  dsi_host_write,   /* write */
+  NULL,             /* seek */
+  dsi_host_ioctl,   /* ioctl */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: dsi_host_read
+ ****************************************************************************/
+
+static ssize_t dsi_host_read(FAR struct file *filep, FAR char *buffer,
+                             size_t len)
+{
+  return 0; /* Return EOF */
+}
+
+/****************************************************************************
+ * Name: DSI hostdrvr_write
+ ****************************************************************************/
+
+static ssize_t dsi_host_write(FAR struct file *filep, FAR const char *buffer,
+                              size_t len)
+{
+  return len; /* Say that everything was written */
+}
+
+/****************************************************************************
+ * Name: dsi_host_ioctl
+ ****************************************************************************/
+
+static int dsi_host_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct mipi_dsi_host_driver_s *priv;
+  FAR struct inode *inode;
+  FAR struct mipi_dsi_msg *msg;
+  FAR struct mipi_dsi_host *host;
+  int ret;
+
+  /* Get our private data structure */
+
+  DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
+  inode = filep->f_inode;
+
+  priv = inode->i_private;
+  DEBUGASSERT(priv);
+
+  /* Get exclusive access to the dsi host driver state structure */
+
+  ret = nxmutex_lock(&priv->lock);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Process the IOCTL command */
+
+  switch (cmd)
+    {
+      case MIPIDSI_TRANSFER:
+        {
+          /* Get the reference to the mipi_dsi_msg structure */
+
+          msg = (FAR struct mipi_dsi_msg *)((uintptr_t)arg);
+
+          /* Get the reference to the mipi_dsi_host structure */
+
+          host = priv->host;
+          DEBUGASSERT(host != NULL && msg != NULL);
+
+          ret = host->ops->transfer(host, msg);
+        }

Review Comment:
   minor
   ```suggestion
         case MIPIDSI_TRANSFER:
           /* Get the reference to the mipi_dsi_msg structure */
   
           msg = (FAR struct mipi_dsi_msg *)((uintptr_t)arg);
   
           /* Get the reference to the mipi_dsi_host structure */
   
           host = priv->host;
           DEBUGASSERT(host != NULL && msg != NULL);
   
           ret = host->ops->transfer(host, msg);
   ```



##########
drivers/video/mipidsi/mipi_dsi_device.c:
##########
@@ -0,0 +1,1023 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_device.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <nuttx/video/mipi_display.h>
+#include <nuttx/kmalloc.h>
+
+#include "mipi_dsi.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_transfer
+ *
+ * Description:
+ *   Transfer message to display modules
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *   msg - Message to transfer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transfered or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_transfer(FAR struct mipi_dsi_device *device,
+                          FAR struct mipi_dsi_msg *msg)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->transfer == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_LPM)
+    {
+      msg->flags |= MIPI_DSI_MSG_USE_LPM;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_AFTER_FRAME)
+    {
+      msg->flags |= MIPI_DSI_MSG_AFTER_FRAME;
+    }
+
+  return ops->transfer(device->host, msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_attach
+ *
+ * Description:
+ *   Attach a DSI device to its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_attach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->attach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->attach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_detach
+ *
+ * Description:
+ *   Detach a DSI device from its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_detach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->detach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->detach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_shutdown_peripheral
+ *
+ * Description:
+ *   Send a Shutdown Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_shutdown_peripheral(FAR struct mipi_dsi_device *device)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SHUTDOWN_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  int ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_turn_on_peripheral
+ *
+ * Description:
+ *   Send a Turn On Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_turn_on_peripheral(FAR struct mipi_dsi_device *device)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_TURN_ON_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_set_maximum_return_packet_size
+ *
+ * Description:
+ *   Specify the maximum size of the payload in a long packet transmitted
+ *   from the peripheral back to the device host processor
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   value - The maximum size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_set_maximum_return_packet_size(
+                          FAR struct mipi_dsi_device *device, uint16_t value)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { value & 0xff, value >> 8 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_compression_mode
+ *
+ * Description:
+ *   Enable / disable DSC on the peripheral. Enable or disable Display Stream
+ *   Compression on the peripheral using the default Picture Parameter Set
+ *   and VESA DSC 1.1 algorithm.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   enable - Whether to enable or disable the DSC
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_compression_mode(FAR struct mipi_dsi_device *device,
+                              bool enable)
+{
+  /* Note: Needs updating for non-default PPS or algorithm */
+
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_COMPRESSION_MODE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { enable & 0xff, 0 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_generic_write
+ *
+ * Description:
+ *   Transmit data using a generic write packet
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   payload - buffer containing the payload
+ *   size - size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_generic_write(FAR struct mipi_dsi_device *device,
+                           FAR const void *payload,
+                           size_t size)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_buf = payload,
+    .tx_len = size

Review Comment:
   ditto



##########
drivers/video/mipidsi/mipi_dsi_device.c:
##########
@@ -0,0 +1,1023 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_device.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <nuttx/video/mipi_display.h>
+#include <nuttx/kmalloc.h>
+
+#include "mipi_dsi.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_transfer
+ *
+ * Description:
+ *   Transfer message to display modules
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *   msg - Message to transfer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transfered or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_transfer(FAR struct mipi_dsi_device *device,
+                          FAR struct mipi_dsi_msg *msg)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->transfer == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_LPM)
+    {
+      msg->flags |= MIPI_DSI_MSG_USE_LPM;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_AFTER_FRAME)
+    {
+      msg->flags |= MIPI_DSI_MSG_AFTER_FRAME;
+    }
+
+  return ops->transfer(device->host, msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_attach
+ *
+ * Description:
+ *   Attach a DSI device to its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_attach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->attach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->attach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_detach
+ *
+ * Description:
+ *   Detach a DSI device from its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_detach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->detach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->detach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_shutdown_peripheral
+ *
+ * Description:
+ *   Send a Shutdown Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_shutdown_peripheral(FAR struct mipi_dsi_device *device)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SHUTDOWN_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  int ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_turn_on_peripheral
+ *
+ * Description:
+ *   Send a Turn On Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_turn_on_peripheral(FAR struct mipi_dsi_device *device)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_TURN_ON_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_set_maximum_return_packet_size
+ *
+ * Description:
+ *   Specify the maximum size of the payload in a long packet transmitted
+ *   from the peripheral back to the device host processor
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   value - The maximum size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_set_maximum_return_packet_size(
+                          FAR struct mipi_dsi_device *device, uint16_t value)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { value & 0xff, value >> 8 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_compression_mode
+ *
+ * Description:
+ *   Enable / disable DSC on the peripheral. Enable or disable Display Stream
+ *   Compression on the peripheral using the default Picture Parameter Set
+ *   and VESA DSC 1.1 algorithm.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   enable - Whether to enable or disable the DSC
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_compression_mode(FAR struct mipi_dsi_device *device,
+                              bool enable)
+{
+  /* Note: Needs updating for non-default PPS or algorithm */
+
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_COMPRESSION_MODE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { enable & 0xff, 0 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_generic_write
+ *
+ * Description:
+ *   Transmit data using a generic write packet
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   payload - buffer containing the payload
+ *   size - size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_generic_write(FAR struct mipi_dsi_device *device,
+                           FAR const void *payload,
+                           size_t size)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_buf = payload,
+    .tx_len = size
+  };
+
+  switch (size)
+    {
+    case 0:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM;
+      break;
+
+    case 1:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM;
+      break;
+
+    case 2:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM;
+      break;
+
+    default:
+      msg.type = MIPI_DSI_LONG_GENERIC_WRITE;
+      break;
+    }
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_generic_read
+ *
+ * Description:
+ *   Receive data using a generic read packet.
+ *   This function will automatically choose the right data type depending on
+ *   the number of parameters passed in.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   params - buffer containing the request parameters
+ *   num_params - number of request parameters
+ *   data - buffer in which to return the received data
+ *   size - size of receive buffer
+ *
+ * Returned Value:
+ *   The number of bytes successfully read or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_generic_read(FAR struct mipi_dsi_device *device,
+                              FAR const void *params,
+                              size_t num_params,
+                              FAR void *data,
+                              size_t size)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_len = num_params,
+    .tx_buf = params,
+    .rx_len = size,
+    .rx_buf = data
+  };
+
+  switch (num_params)
+    {
+    case 0:
+      msg.type = MIPI_DSI_GENERIC_READ_0_PARAM;
+      break;
+    case 1:
+      msg.type = MIPI_DSI_GENERIC_READ_1_PARAM;
+      break;
+    case 2:
+      msg.type = MIPI_DSI_GENERIC_READ_2_PARAM;
+      break;
+    default:
+      return -EINVAL;
+    }
+
+  return mipi_dsi_transfer(device, &msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_dcs_write_buffer
+ *
+ * Description:
+ *   Transmit a DCS command with payload.
+ *   This function will automatically choose the right data type depending on
+ *   the command payload length.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   data - buffer containing data to be transmitted
+ *   len - size of transmission buffer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transmitted or a negative error
+ *   code on failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_dcs_write_buffer(FAR struct mipi_dsi_device *device,
+                                  FAR const void *data,
+                                  size_t len)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_buf = data,
+    .tx_len = len
+  };
+
+  switch (len)
+    {
+    case 0:
+      return -EINVAL;
+    case 1:
+      msg.type = MIPI_DSI_DCS_SHORT_WRITE_0_PARAM;
+      break;
+    case 2:
+      msg.type = MIPI_DSI_DCS_SHORT_WRITE_1_PARAM;
+      break;
+    default:
+      msg.type = MIPI_DSI_DCS_LONG_WRITE;
+      break;
+    }
+
+  return mipi_dsi_transfer(device, &msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_dcs_write
+ *
+ * Description:
+ *   Send DCS write command.
+ *   This function will automatically choose the right data type depending on
+ *   the command payload length.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   cmd - DCS command
+ *   data - buffer containing the command payload
+ *   len - command payload length
+ *
+ * Returned Value:
+ *   The number of bytes successfully transmitted or a negative error
+ *   code on failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_dcs_write(FAR struct mipi_dsi_device *device,
+                           uint8_t cmd,
+                           FAR const void *data,
+                           size_t len)
+{
+  ssize_t ret;
+  uint8_t stack_tx[8];
+  FAR uint8_t *tx = stack_tx;
+
+  if (len > sizeof(stack_tx) - 1)
+    {
+      tx = kmm_malloc(len + 1);
+      if (!tx)

Review Comment:
   minor
   ```suggestion
         if (tx == NULL)
   ```



##########
drivers/video/mipidsi/mipi_dsi_device.c:
##########
@@ -0,0 +1,1023 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_device.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <nuttx/video/mipi_display.h>
+#include <nuttx/kmalloc.h>
+
+#include "mipi_dsi.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_transfer
+ *
+ * Description:
+ *   Transfer message to display modules
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *   msg - Message to transfer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transfered or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_transfer(FAR struct mipi_dsi_device *device,
+                          FAR struct mipi_dsi_msg *msg)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->transfer == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_LPM)
+    {
+      msg->flags |= MIPI_DSI_MSG_USE_LPM;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_AFTER_FRAME)
+    {
+      msg->flags |= MIPI_DSI_MSG_AFTER_FRAME;
+    }
+
+  return ops->transfer(device->host, msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_attach
+ *
+ * Description:
+ *   Attach a DSI device to its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_attach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->attach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->attach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_detach
+ *
+ * Description:
+ *   Detach a DSI device from its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_detach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->detach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->detach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_shutdown_peripheral
+ *
+ * Description:
+ *   Send a Shutdown Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_shutdown_peripheral(FAR struct mipi_dsi_device *device)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SHUTDOWN_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  int ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_turn_on_peripheral
+ *
+ * Description:
+ *   Send a Turn On Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_turn_on_peripheral(FAR struct mipi_dsi_device *device)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_TURN_ON_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_set_maximum_return_packet_size
+ *
+ * Description:
+ *   Specify the maximum size of the payload in a long packet transmitted
+ *   from the peripheral back to the device host processor
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   value - The maximum size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_set_maximum_return_packet_size(
+                          FAR struct mipi_dsi_device *device, uint16_t value)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { value & 0xff, value >> 8 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_compression_mode
+ *
+ * Description:
+ *   Enable / disable DSC on the peripheral. Enable or disable Display Stream
+ *   Compression on the peripheral using the default Picture Parameter Set
+ *   and VESA DSC 1.1 algorithm.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   enable - Whether to enable or disable the DSC
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_compression_mode(FAR struct mipi_dsi_device *device,
+                              bool enable)
+{
+  /* Note: Needs updating for non-default PPS or algorithm */
+
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_COMPRESSION_MODE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { enable & 0xff, 0 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_generic_write
+ *
+ * Description:
+ *   Transmit data using a generic write packet
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   payload - buffer containing the payload
+ *   size - size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_generic_write(FAR struct mipi_dsi_device *device,
+                           FAR const void *payload,
+                           size_t size)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_buf = payload,
+    .tx_len = size
+  };
+
+  switch (size)
+    {
+    case 0:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM;
+      break;
+
+    case 1:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM;
+      break;
+
+    case 2:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM;
+      break;
+
+    default:
+      msg.type = MIPI_DSI_LONG_GENERIC_WRITE;
+      break;
+    }
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_generic_read
+ *
+ * Description:
+ *   Receive data using a generic read packet.
+ *   This function will automatically choose the right data type depending on
+ *   the number of parameters passed in.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   params - buffer containing the request parameters
+ *   num_params - number of request parameters
+ *   data - buffer in which to return the received data
+ *   size - size of receive buffer
+ *
+ * Returned Value:
+ *   The number of bytes successfully read or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_generic_read(FAR struct mipi_dsi_device *device,
+                              FAR const void *params,
+                              size_t num_params,
+                              FAR void *data,
+                              size_t size)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_len = num_params,
+    .tx_buf = params,
+    .rx_len = size,
+    .rx_buf = data
+  };
+
+  switch (num_params)
+    {
+    case 0:
+      msg.type = MIPI_DSI_GENERIC_READ_0_PARAM;
+      break;
+    case 1:
+      msg.type = MIPI_DSI_GENERIC_READ_1_PARAM;
+      break;
+    case 2:
+      msg.type = MIPI_DSI_GENERIC_READ_2_PARAM;
+      break;
+    default:
+      return -EINVAL;

Review Comment:
   ```suggestion
         case 0:
           msg.type = MIPI_DSI_GENERIC_READ_0_PARAM;
           break;
         case 1:
           msg.type = MIPI_DSI_GENERIC_READ_1_PARAM;
           break;
         case 2:
           msg.type = MIPI_DSI_GENERIC_READ_2_PARAM;
           break;
         default:
           return -EINVAL;
   ```



##########
drivers/video/mipidsi/mipi_dsi_device.c:
##########
@@ -0,0 +1,1023 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_device.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <nuttx/video/mipi_display.h>
+#include <nuttx/kmalloc.h>
+
+#include "mipi_dsi.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_transfer
+ *
+ * Description:
+ *   Transfer message to display modules
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *   msg - Message to transfer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transfered or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_transfer(FAR struct mipi_dsi_device *device,
+                          FAR struct mipi_dsi_msg *msg)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->transfer == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_LPM)
+    {
+      msg->flags |= MIPI_DSI_MSG_USE_LPM;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_AFTER_FRAME)
+    {
+      msg->flags |= MIPI_DSI_MSG_AFTER_FRAME;
+    }
+
+  return ops->transfer(device->host, msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_attach
+ *
+ * Description:
+ *   Attach a DSI device to its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_attach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->attach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->attach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_detach
+ *
+ * Description:
+ *   Detach a DSI device from its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_detach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->detach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->detach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_shutdown_peripheral
+ *
+ * Description:
+ *   Send a Shutdown Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_shutdown_peripheral(FAR struct mipi_dsi_device *device)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SHUTDOWN_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  int ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_turn_on_peripheral
+ *
+ * Description:
+ *   Send a Turn On Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_turn_on_peripheral(FAR struct mipi_dsi_device *device)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_TURN_ON_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_set_maximum_return_packet_size
+ *
+ * Description:
+ *   Specify the maximum size of the payload in a long packet transmitted
+ *   from the peripheral back to the device host processor
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   value - The maximum size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_set_maximum_return_packet_size(
+                          FAR struct mipi_dsi_device *device, uint16_t value)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { value & 0xff, value >> 8 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_compression_mode
+ *
+ * Description:
+ *   Enable / disable DSC on the peripheral. Enable or disable Display Stream
+ *   Compression on the peripheral using the default Picture Parameter Set
+ *   and VESA DSC 1.1 algorithm.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   enable - Whether to enable or disable the DSC
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_compression_mode(FAR struct mipi_dsi_device *device,
+                              bool enable)
+{
+  /* Note: Needs updating for non-default PPS or algorithm */
+
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_COMPRESSION_MODE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { enable & 0xff, 0 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_generic_write
+ *
+ * Description:
+ *   Transmit data using a generic write packet
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   payload - buffer containing the payload
+ *   size - size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_generic_write(FAR struct mipi_dsi_device *device,
+                           FAR const void *payload,
+                           size_t size)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_buf = payload,
+    .tx_len = size
+  };
+
+  switch (size)
+    {
+    case 0:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM;
+      break;
+
+    case 1:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM;
+      break;
+
+    case 2:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM;
+      break;
+
+    default:
+      msg.type = MIPI_DSI_LONG_GENERIC_WRITE;
+      break;
+    }
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_generic_read
+ *
+ * Description:
+ *   Receive data using a generic read packet.
+ *   This function will automatically choose the right data type depending on
+ *   the number of parameters passed in.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   params - buffer containing the request parameters
+ *   num_params - number of request parameters
+ *   data - buffer in which to return the received data
+ *   size - size of receive buffer
+ *
+ * Returned Value:
+ *   The number of bytes successfully read or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_generic_read(FAR struct mipi_dsi_device *device,
+                              FAR const void *params,
+                              size_t num_params,
+                              FAR void *data,
+                              size_t size)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_len = num_params,
+    .tx_buf = params,
+    .rx_len = size,
+    .rx_buf = data
+  };
+
+  switch (num_params)
+    {
+    case 0:
+      msg.type = MIPI_DSI_GENERIC_READ_0_PARAM;
+      break;
+    case 1:
+      msg.type = MIPI_DSI_GENERIC_READ_1_PARAM;
+      break;
+    case 2:
+      msg.type = MIPI_DSI_GENERIC_READ_2_PARAM;
+      break;
+    default:
+      return -EINVAL;
+    }
+
+  return mipi_dsi_transfer(device, &msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_dcs_write_buffer
+ *
+ * Description:
+ *   Transmit a DCS command with payload.
+ *   This function will automatically choose the right data type depending on
+ *   the command payload length.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   data - buffer containing data to be transmitted
+ *   len - size of transmission buffer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transmitted or a negative error
+ *   code on failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_dcs_write_buffer(FAR struct mipi_dsi_device *device,
+                                  FAR const void *data,
+                                  size_t len)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_buf = data,

Review Comment:
   ditto



##########
drivers/video/mipidsi/mipi_dsi_device.c:
##########
@@ -0,0 +1,1023 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_device.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <nuttx/video/mipi_display.h>
+#include <nuttx/kmalloc.h>
+
+#include "mipi_dsi.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_transfer
+ *
+ * Description:
+ *   Transfer message to display modules
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *   msg - Message to transfer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transfered or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_transfer(FAR struct mipi_dsi_device *device,
+                          FAR struct mipi_dsi_msg *msg)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->transfer == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_LPM)
+    {
+      msg->flags |= MIPI_DSI_MSG_USE_LPM;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_AFTER_FRAME)
+    {
+      msg->flags |= MIPI_DSI_MSG_AFTER_FRAME;
+    }
+
+  return ops->transfer(device->host, msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_attach
+ *
+ * Description:
+ *   Attach a DSI device to its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_attach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->attach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->attach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_detach
+ *
+ * Description:
+ *   Detach a DSI device from its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_detach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->detach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->detach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_shutdown_peripheral
+ *
+ * Description:
+ *   Send a Shutdown Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_shutdown_peripheral(FAR struct mipi_dsi_device *device)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SHUTDOWN_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  int ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_turn_on_peripheral
+ *
+ * Description:
+ *   Send a Turn On Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_turn_on_peripheral(FAR struct mipi_dsi_device *device)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_TURN_ON_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_set_maximum_return_packet_size
+ *
+ * Description:
+ *   Specify the maximum size of the payload in a long packet transmitted
+ *   from the peripheral back to the device host processor
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   value - The maximum size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_set_maximum_return_packet_size(
+                          FAR struct mipi_dsi_device *device, uint16_t value)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { value & 0xff, value >> 8 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_compression_mode
+ *
+ * Description:
+ *   Enable / disable DSC on the peripheral. Enable or disable Display Stream
+ *   Compression on the peripheral using the default Picture Parameter Set
+ *   and VESA DSC 1.1 algorithm.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   enable - Whether to enable or disable the DSC
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_compression_mode(FAR struct mipi_dsi_device *device,
+                              bool enable)
+{
+  /* Note: Needs updating for non-default PPS or algorithm */
+
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_COMPRESSION_MODE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { enable & 0xff, 0 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_generic_write
+ *
+ * Description:
+ *   Transmit data using a generic write packet
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   payload - buffer containing the payload
+ *   size - size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_generic_write(FAR struct mipi_dsi_device *device,
+                           FAR const void *payload,
+                           size_t size)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_buf = payload,
+    .tx_len = size
+  };
+
+  switch (size)
+    {
+    case 0:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM;
+      break;
+
+    case 1:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM;
+      break;
+
+    case 2:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM;
+      break;
+
+    default:
+      msg.type = MIPI_DSI_LONG_GENERIC_WRITE;
+      break;
+    }
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_generic_read
+ *
+ * Description:
+ *   Receive data using a generic read packet.
+ *   This function will automatically choose the right data type depending on
+ *   the number of parameters passed in.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   params - buffer containing the request parameters
+ *   num_params - number of request parameters
+ *   data - buffer in which to return the received data
+ *   size - size of receive buffer
+ *
+ * Returned Value:
+ *   The number of bytes successfully read or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_generic_read(FAR struct mipi_dsi_device *device,
+                              FAR const void *params,
+                              size_t num_params,
+                              FAR void *data,
+                              size_t size)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_len = num_params,
+    .tx_buf = params,
+    .rx_len = size,
+    .rx_buf = data
+  };
+
+  switch (num_params)
+    {
+    case 0:
+      msg.type = MIPI_DSI_GENERIC_READ_0_PARAM;
+      break;
+    case 1:
+      msg.type = MIPI_DSI_GENERIC_READ_1_PARAM;
+      break;
+    case 2:
+      msg.type = MIPI_DSI_GENERIC_READ_2_PARAM;
+      break;
+    default:
+      return -EINVAL;
+    }
+
+  return mipi_dsi_transfer(device, &msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_dcs_write_buffer
+ *
+ * Description:
+ *   Transmit a DCS command with payload.
+ *   This function will automatically choose the right data type depending on
+ *   the command payload length.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   data - buffer containing data to be transmitted
+ *   len - size of transmission buffer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transmitted or a negative error
+ *   code on failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_dcs_write_buffer(FAR struct mipi_dsi_device *device,
+                                  FAR const void *data,
+                                  size_t len)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_buf = data,
+    .tx_len = len
+  };
+
+  switch (len)
+    {
+    case 0:
+      return -EINVAL;
+    case 1:
+      msg.type = MIPI_DSI_DCS_SHORT_WRITE_0_PARAM;
+      break;
+    case 2:
+      msg.type = MIPI_DSI_DCS_SHORT_WRITE_1_PARAM;
+      break;
+    default:
+      msg.type = MIPI_DSI_DCS_LONG_WRITE;
+      break;
+    }
+
+  return mipi_dsi_transfer(device, &msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_dcs_write
+ *
+ * Description:
+ *   Send DCS write command.
+ *   This function will automatically choose the right data type depending on
+ *   the command payload length.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   cmd - DCS command
+ *   data - buffer containing the command payload
+ *   len - command payload length
+ *
+ * Returned Value:
+ *   The number of bytes successfully transmitted or a negative error
+ *   code on failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_dcs_write(FAR struct mipi_dsi_device *device,
+                           uint8_t cmd,
+                           FAR const void *data,
+                           size_t len)
+{
+  ssize_t ret;
+  uint8_t stack_tx[8];
+  FAR uint8_t *tx = stack_tx;
+
+  if (len > sizeof(stack_tx) - 1)
+    {
+      tx = kmm_malloc(len + 1);
+      if (!tx)
+        {
+          return -ENOMEM;
+        }
+    }
+
+  /* concatenate the DCS command byte and the payload */
+
+  tx[0] = cmd;
+  if (data)

Review Comment:
   minor
   ```suggestion
     if (data != NULL)
   ```



##########
drivers/video/mipidsi/mipi_dsi_device.c:
##########
@@ -0,0 +1,1023 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_device.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <nuttx/video/mipi_display.h>
+#include <nuttx/kmalloc.h>
+
+#include "mipi_dsi.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_transfer
+ *
+ * Description:
+ *   Transfer message to display modules
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *   msg - Message to transfer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transfered or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_transfer(FAR struct mipi_dsi_device *device,
+                          FAR struct mipi_dsi_msg *msg)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->transfer == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_LPM)
+    {
+      msg->flags |= MIPI_DSI_MSG_USE_LPM;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_AFTER_FRAME)
+    {
+      msg->flags |= MIPI_DSI_MSG_AFTER_FRAME;
+    }
+
+  return ops->transfer(device->host, msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_attach
+ *
+ * Description:
+ *   Attach a DSI device to its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_attach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->attach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->attach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_detach
+ *
+ * Description:
+ *   Detach a DSI device from its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_detach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->detach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->detach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_shutdown_peripheral
+ *
+ * Description:
+ *   Send a Shutdown Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_shutdown_peripheral(FAR struct mipi_dsi_device *device)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SHUTDOWN_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  int ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_turn_on_peripheral
+ *
+ * Description:
+ *   Send a Turn On Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_turn_on_peripheral(FAR struct mipi_dsi_device *device)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_TURN_ON_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_set_maximum_return_packet_size
+ *
+ * Description:
+ *   Specify the maximum size of the payload in a long packet transmitted
+ *   from the peripheral back to the device host processor
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   value - The maximum size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_set_maximum_return_packet_size(
+                          FAR struct mipi_dsi_device *device, uint16_t value)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { value & 0xff, value >> 8 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_compression_mode
+ *
+ * Description:
+ *   Enable / disable DSC on the peripheral. Enable or disable Display Stream
+ *   Compression on the peripheral using the default Picture Parameter Set
+ *   and VESA DSC 1.1 algorithm.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   enable - Whether to enable or disable the DSC
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_compression_mode(FAR struct mipi_dsi_device *device,
+                              bool enable)
+{
+  /* Note: Needs updating for non-default PPS or algorithm */
+
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_COMPRESSION_MODE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { enable & 0xff, 0 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_generic_write
+ *
+ * Description:
+ *   Transmit data using a generic write packet
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   payload - buffer containing the payload
+ *   size - size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_generic_write(FAR struct mipi_dsi_device *device,
+                           FAR const void *payload,
+                           size_t size)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_buf = payload,
+    .tx_len = size
+  };
+
+  switch (size)
+    {
+    case 0:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM;
+      break;
+
+    case 1:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM;
+      break;
+
+    case 2:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM;
+      break;
+
+    default:
+      msg.type = MIPI_DSI_LONG_GENERIC_WRITE;
+      break;
+    }
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_generic_read
+ *
+ * Description:
+ *   Receive data using a generic read packet.
+ *   This function will automatically choose the right data type depending on
+ *   the number of parameters passed in.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   params - buffer containing the request parameters
+ *   num_params - number of request parameters
+ *   data - buffer in which to return the received data
+ *   size - size of receive buffer
+ *
+ * Returned Value:
+ *   The number of bytes successfully read or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_generic_read(FAR struct mipi_dsi_device *device,
+                              FAR const void *params,
+                              size_t num_params,
+                              FAR void *data,
+                              size_t size)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_len = num_params,
+    .tx_buf = params,
+    .rx_len = size,
+    .rx_buf = data
+  };
+
+  switch (num_params)
+    {
+    case 0:
+      msg.type = MIPI_DSI_GENERIC_READ_0_PARAM;
+      break;
+    case 1:
+      msg.type = MIPI_DSI_GENERIC_READ_1_PARAM;
+      break;
+    case 2:
+      msg.type = MIPI_DSI_GENERIC_READ_2_PARAM;
+      break;
+    default:
+      return -EINVAL;
+    }
+
+  return mipi_dsi_transfer(device, &msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_dcs_write_buffer
+ *
+ * Description:
+ *   Transmit a DCS command with payload.
+ *   This function will automatically choose the right data type depending on
+ *   the command payload length.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   data - buffer containing data to be transmitted
+ *   len - size of transmission buffer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transmitted or a negative error
+ *   code on failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_dcs_write_buffer(FAR struct mipi_dsi_device *device,
+                                  FAR const void *data,
+                                  size_t len)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_buf = data,
+    .tx_len = len
+  };
+
+  switch (len)
+    {
+    case 0:
+      return -EINVAL;
+    case 1:
+      msg.type = MIPI_DSI_DCS_SHORT_WRITE_0_PARAM;
+      break;
+    case 2:
+      msg.type = MIPI_DSI_DCS_SHORT_WRITE_1_PARAM;
+      break;
+    default:
+      msg.type = MIPI_DSI_DCS_LONG_WRITE;
+      break;
+    }
+
+  return mipi_dsi_transfer(device, &msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_dcs_write
+ *
+ * Description:
+ *   Send DCS write command.
+ *   This function will automatically choose the right data type depending on
+ *   the command payload length.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   cmd - DCS command
+ *   data - buffer containing the command payload
+ *   len - command payload length
+ *
+ * Returned Value:
+ *   The number of bytes successfully transmitted or a negative error
+ *   code on failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_dcs_write(FAR struct mipi_dsi_device *device,
+                           uint8_t cmd,
+                           FAR const void *data,
+                           size_t len)
+{
+  ssize_t ret;
+  uint8_t stack_tx[8];
+  FAR uint8_t *tx = stack_tx;
+
+  if (len > sizeof(stack_tx) - 1)
+    {
+      tx = kmm_malloc(len + 1);
+      if (!tx)
+        {
+          return -ENOMEM;
+        }
+    }
+
+  /* concatenate the DCS command byte and the payload */
+
+  tx[0] = cmd;
+  if (data)
+    {
+      memcpy(&tx[1], data, len);
+    }
+
+  ret = mipi_dsi_dcs_write_buffer(device, tx, len + 1);
+
+  if (tx != stack_tx)
+    {
+      kmm_free(tx);
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_dcs_read
+ *
+ * Description:
+ *   Send DCS read request command.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   cmd - DCS command
+ *   data - buffer in which to receive data
+ *   len - size of receive buffer
+ *
+ * Returned Value:
+ *   The number of bytes read or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_dcs_read(FAR struct mipi_dsi_device *device,
+                          uint8_t cmd,
+                          FAR void *data,
+                          size_t len)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_DCS_READ_0_PARAM,
+    .tx_buf = &cmd,
+    .tx_len = 1,
+    .rx_buf = data,
+    .rx_len = len
+  };
+
+  return mipi_dsi_transfer(device, &msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_dcs_nop
+ *
+ * Description:
+ *   Send DCS nop packet
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_dcs_nop(FAR struct mipi_dsi_device *device)
+{
+  int ret;
+
+  ret = mipi_dsi_dcs_write(device, MIPI_DCS_NOP, NULL, 0);
+  return ret < 0 ? ret : OK;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_dcs_soft_reset
+ *
+ * Description:
+ *   Send a software reset of the display module
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_dcs_soft_reset(FAR struct mipi_dsi_device *device)
+{
+  int ret;
+
+  ret = mipi_dsi_dcs_write(device, MIPI_DCS_SOFT_RESET, NULL, 0);
+

Review Comment:
   some similar places have new line while other do not. Maybe some common style can be used across this file?



##########
drivers/video/mipidsi/mipi_dsi_packet.c:
##########
@@ -0,0 +1,220 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_packet.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <assert.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include <nuttx/video/mipi_dsi.h>
+#include <nuttx/video/mipi_display.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_pixel_format_to_bpp
+ *
+ * Description:
+ *   Obtain the number of bits per pixel for any given pixel format defined
+ *   by the MIPI DSI specification
+ *
+ * Input Parameters:
+ *   fmt - MIPI DSI pixel format
+ *
+ * Returned Value:
+ *   The number of bits per pixel of the given pixel format.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_pixel_format_to_bpp(uint8_t fmt)
+{
+  switch (fmt)
+    {
+    case MIPI_DSI_FMT_RGB888:
+    case MIPI_DSI_FMT_RGB666:
+      return 24;
+    case MIPI_DSI_FMT_RGB666_PACKED:
+      return 18;
+    case MIPI_DSI_FMT_RGB565:
+      return 16;

Review Comment:
   ```suggestion
         case MIPI_DSI_FMT_RGB888:
         case MIPI_DSI_FMT_RGB666:
           return 24;
         case MIPI_DSI_FMT_RGB666_PACKED:
           return 18;
         case MIPI_DSI_FMT_RGB565:
           return 16;
   ```



##########
drivers/video/mipidsi/mipi_dsi_packet.c:
##########
@@ -0,0 +1,220 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_packet.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <assert.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include <nuttx/video/mipi_dsi.h>
+#include <nuttx/video/mipi_display.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_pixel_format_to_bpp
+ *
+ * Description:
+ *   Obtain the number of bits per pixel for any given pixel format defined
+ *   by the MIPI DSI specification
+ *
+ * Input Parameters:
+ *   fmt - MIPI DSI pixel format
+ *
+ * Returned Value:
+ *   The number of bits per pixel of the given pixel format.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_pixel_format_to_bpp(uint8_t fmt)
+{
+  switch (fmt)
+    {
+    case MIPI_DSI_FMT_RGB888:
+    case MIPI_DSI_FMT_RGB666:
+      return 24;
+    case MIPI_DSI_FMT_RGB666_PACKED:
+      return 18;
+    case MIPI_DSI_FMT_RGB565:
+      return 16;
+    }
+
+  return -EINVAL;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_packet_format_is_short
+ *
+ * Description:
+ *   Check if a packet is of the short format
+ *
+ * Input Parameters:
+ *   type - MIPI DSI data type of the packet
+ *
+ * Returned Value:
+ *   True if the packet for the given data type is a short packet, false
+ *   otherwise.
+ *
+ ****************************************************************************/
+
+bool mipi_dsi_packet_format_is_short(uint8_t type)
+{
+  switch (type)
+    {
+    case MIPI_DSI_VSYNC_START:
+    case MIPI_DSI_VSYNC_END:
+    case MIPI_DSI_HSYNC_START:
+    case MIPI_DSI_HSYNC_END:
+    case MIPI_DSI_COMPRESSION_MODE:
+    case MIPI_DSI_END_OF_TRANSMISSION:
+    case MIPI_DSI_COLOR_MODE_OFF:
+    case MIPI_DSI_COLOR_MODE_ON:
+    case MIPI_DSI_SHUTDOWN_PERIPHERAL:
+    case MIPI_DSI_TURN_ON_PERIPHERAL:
+    case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
+    case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
+    case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
+    case MIPI_DSI_GENERIC_READ_0_PARAM:
+    case MIPI_DSI_GENERIC_READ_1_PARAM:
+    case MIPI_DSI_GENERIC_READ_2_PARAM:
+    case MIPI_DSI_DCS_SHORT_WRITE_0_PARAM:
+    case MIPI_DSI_DCS_SHORT_WRITE_1_PARAM:
+    case MIPI_DSI_DCS_READ_0_PARAM:
+    case MIPI_DSI_EXECUTE_QUEUE:
+    case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE:
+      return true;
+    }
+
+  return false;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_packet_format_is_long
+ *
+ * Description:
+ *   Check if a packet is of the long format
+ *
+ * Input Parameters:
+ *   type - MIPI DSI data type of the packet
+ *
+ * Returned Value:
+ *   True if the packet for the given data type is a long packet, false
+ *   otherwise.
+ *
+ ****************************************************************************/
+
+bool mipi_dsi_packet_format_is_long(uint8_t type)
+{
+  switch (type)
+    {
+    case MIPI_DSI_NULL_PACKET:
+    case MIPI_DSI_BLANKING_PACKET:
+    case MIPI_DSI_LONG_GENERIC_WRITE:
+    case MIPI_DSI_DCS_LONG_WRITE:
+    case MIPI_DSI_PICTURE_PARAMETER_SET:
+    case MIPI_DSI_COMPRESSED_PIXEL_STREAM:
+    case MIPI_DSI_LOOSELY_PACKED_PIXEL_STREAM_YCBCR20:
+    case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR24:
+    case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16:
+    case MIPI_DSI_PACKED_PIXEL_STREAM_RGB30:
+    case MIPI_DSI_PACKED_PIXEL_STREAM_RGB36:
+    case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12:
+    case MIPI_DSI_PACKED_PIXEL_STREAM_RGB16:
+    case MIPI_DSI_PACKED_PIXEL_STREAM_RGB18:
+    case MIPI_DSI_PIXEL_STREAM_3BYTE_RGB18:
+    case MIPI_DSI_PACKED_PIXEL_STREAM_RGB24:
+      return true;

Review Comment:
   ditto



##########
drivers/video/mipidsi/mipi_dsi_device.c:
##########
@@ -0,0 +1,1023 @@
+/****************************************************************************
+ * drivers/video/mipidsi/mipi_dsi_device.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <assert.h>
+#include <debug.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <nuttx/video/mipi_display.h>
+#include <nuttx/kmalloc.h>
+
+#include "mipi_dsi.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mipi_dsi_transfer
+ *
+ * Description:
+ *   Transfer message to display modules
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *   msg - Message to transfer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transfered or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_transfer(FAR struct mipi_dsi_device *device,
+                          FAR struct mipi_dsi_msg *msg)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->transfer == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_LPM)
+    {
+      msg->flags |= MIPI_DSI_MSG_USE_LPM;
+    }
+
+  if (device->mode_flags & MIPI_DSI_MODE_AFTER_FRAME)
+    {
+      msg->flags |= MIPI_DSI_MSG_AFTER_FRAME;
+    }
+
+  return ops->transfer(device->host, msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_attach
+ *
+ * Description:
+ *   Attach a DSI device to its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_attach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->attach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->attach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_detach
+ *
+ * Description:
+ *   Detach a DSI device from its DSI host
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_detach(FAR struct mipi_dsi_device *device)
+{
+  FAR const struct mipi_dsi_host_ops *ops = device->host->ops;
+
+  if (ops == NULL || ops->detach == NULL)
+    {
+      return -ENOSYS;
+    }
+
+  return ops->detach(device->host, device);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_shutdown_peripheral
+ *
+ * Description:
+ *   Send a Shutdown Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_shutdown_peripheral(FAR struct mipi_dsi_device *device)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SHUTDOWN_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  int ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_turn_on_peripheral
+ *
+ * Description:
+ *   Send a Turn On Peripheral command to the device device
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_turn_on_peripheral(FAR struct mipi_dsi_device *device)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_TURN_ON_PERIPHERAL,
+    .tx_buf = (uint8_t [2]) { 0, 0 },
+    .tx_len = 2,
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_set_maximum_return_packet_size
+ *
+ * Description:
+ *   Specify the maximum size of the payload in a long packet transmitted
+ *   from the peripheral back to the device host processor
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   value - The maximum size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_set_maximum_return_packet_size(
+                          FAR struct mipi_dsi_device *device, uint16_t value)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { value & 0xff, value >> 8 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_compression_mode
+ *
+ * Description:
+ *   Enable / disable DSC on the peripheral. Enable or disable Display Stream
+ *   Compression on the peripheral using the default Picture Parameter Set
+ *   and VESA DSC 1.1 algorithm.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   enable - Whether to enable or disable the DSC
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_compression_mode(FAR struct mipi_dsi_device *device,
+                              bool enable)
+{
+  /* Note: Needs updating for non-default PPS or algorithm */
+
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_COMPRESSION_MODE,
+    .tx_len = 2,
+    .tx_buf = (uint8_t [2]) { enable & 0xff, 0 },
+  };
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_generic_write
+ *
+ * Description:
+ *   Transmit data using a generic write packet
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   payload - buffer containing the payload
+ *   size - size of the payload
+ *
+ * Returned Value:
+ *   OK on success or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+int mipi_dsi_generic_write(FAR struct mipi_dsi_device *device,
+                           FAR const void *payload,
+                           size_t size)
+{
+  int ret;
+
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_buf = payload,
+    .tx_len = size
+  };
+
+  switch (size)
+    {
+    case 0:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM;
+      break;
+
+    case 1:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM;
+      break;
+
+    case 2:
+      msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM;
+      break;
+
+    default:
+      msg.type = MIPI_DSI_LONG_GENERIC_WRITE;
+      break;
+    }
+
+  ret = mipi_dsi_transfer(device, &msg);
+  return ret < 0 ? ret : 0;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_generic_read
+ *
+ * Description:
+ *   Receive data using a generic read packet.
+ *   This function will automatically choose the right data type depending on
+ *   the number of parameters passed in.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   params - buffer containing the request parameters
+ *   num_params - number of request parameters
+ *   data - buffer in which to return the received data
+ *   size - size of receive buffer
+ *
+ * Returned Value:
+ *   The number of bytes successfully read or a negative error code on
+ *   failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_generic_read(FAR struct mipi_dsi_device *device,
+                              FAR const void *params,
+                              size_t num_params,
+                              FAR void *data,
+                              size_t size)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_len = num_params,
+    .tx_buf = params,
+    .rx_len = size,
+    .rx_buf = data
+  };
+
+  switch (num_params)
+    {
+    case 0:
+      msg.type = MIPI_DSI_GENERIC_READ_0_PARAM;
+      break;
+    case 1:
+      msg.type = MIPI_DSI_GENERIC_READ_1_PARAM;
+      break;
+    case 2:
+      msg.type = MIPI_DSI_GENERIC_READ_2_PARAM;
+      break;
+    default:
+      return -EINVAL;
+    }
+
+  return mipi_dsi_transfer(device, &msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_dcs_write_buffer
+ *
+ * Description:
+ *   Transmit a DCS command with payload.
+ *   This function will automatically choose the right data type depending on
+ *   the command payload length.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   data - buffer containing data to be transmitted
+ *   len - size of transmission buffer
+ *
+ * Returned Value:
+ *   The number of bytes successfully transmitted or a negative error
+ *   code on failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_dcs_write_buffer(FAR struct mipi_dsi_device *device,
+                                  FAR const void *data,
+                                  size_t len)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .tx_buf = data,
+    .tx_len = len
+  };
+
+  switch (len)
+    {
+    case 0:
+      return -EINVAL;
+    case 1:
+      msg.type = MIPI_DSI_DCS_SHORT_WRITE_0_PARAM;
+      break;
+    case 2:
+      msg.type = MIPI_DSI_DCS_SHORT_WRITE_1_PARAM;
+      break;
+    default:
+      msg.type = MIPI_DSI_DCS_LONG_WRITE;
+      break;
+    }
+
+  return mipi_dsi_transfer(device, &msg);
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_dcs_write
+ *
+ * Description:
+ *   Send DCS write command.
+ *   This function will automatically choose the right data type depending on
+ *   the command payload length.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   cmd - DCS command
+ *   data - buffer containing the command payload
+ *   len - command payload length
+ *
+ * Returned Value:
+ *   The number of bytes successfully transmitted or a negative error
+ *   code on failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_dcs_write(FAR struct mipi_dsi_device *device,
+                           uint8_t cmd,
+                           FAR const void *data,
+                           size_t len)
+{
+  ssize_t ret;
+  uint8_t stack_tx[8];
+  FAR uint8_t *tx = stack_tx;
+
+  if (len > sizeof(stack_tx) - 1)
+    {
+      tx = kmm_malloc(len + 1);
+      if (!tx)
+        {
+          return -ENOMEM;
+        }
+    }
+
+  /* concatenate the DCS command byte and the payload */
+
+  tx[0] = cmd;
+  if (data)
+    {
+      memcpy(&tx[1], data, len);
+    }
+
+  ret = mipi_dsi_dcs_write_buffer(device, tx, len + 1);
+
+  if (tx != stack_tx)
+    {
+      kmm_free(tx);
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: mipi_dsi_dcs_read
+ *
+ * Description:
+ *   Send DCS read request command.
+ *
+ * Input Parameters:
+ *   device - DSI peripheral device
+ *   cmd - DCS command
+ *   data - buffer in which to receive data
+ *   len - size of receive buffer
+ *
+ * Returned Value:
+ *   The number of bytes read or a negative error code on failure.
+ *
+ ****************************************************************************/
+
+ssize_t mipi_dsi_dcs_read(FAR struct mipi_dsi_device *device,
+                          uint8_t cmd,
+                          FAR void *data,
+                          size_t len)
+{
+  struct mipi_dsi_msg msg =
+  {
+    .channel = device->channel,
+    .type = MIPI_DSI_DCS_READ_0_PARAM,
+    .tx_buf = &cmd,
+    .tx_len = 1,
+    .rx_buf = data,
+    .rx_len = len

Review Comment:
   ditto



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on pull request #8103: feat: add mipidsi support

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #8103:
URL: https://github.com/apache/nuttx/pull/8103#issuecomment-1381532384

   @lupyuen @shuai532209720 provide a general mipi dsi driver framework. Your owrk on A64 may benefit from it. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org