LCOV - code coverage report
Current view: top level - zephyr/drivers - mipi_dsi.h Coverage Total Hit
Test: new.info Lines: 91.7 % 48 44
Test Date: 2025-09-25 19:22:35

            Line data    Source code
       1            1 : /*
       2              :  * Copyright (c) 2020 Teslabs Engineering S.L.
       3              :  *
       4              :  * SPDX-License-Identifier: Apache-2.0
       5              :  */
       6              : 
       7              : /**
       8              :  * @file
       9              :  * @ingroup mipi_dsi_interface
      10              :  * @brief Main header file for MIPI-DSI (Display Serial Interface) driver API.
      11              :  */
      12              : 
      13              : #ifndef ZEPHYR_INCLUDE_DRIVERS_MIPI_DSI_H_
      14              : #define ZEPHYR_INCLUDE_DRIVERS_MIPI_DSI_H_
      15              : 
      16              : /**
      17              :  * @brief Interfaces for MIPI-DSI (Display Serial Interface).
      18              :  * @defgroup mipi_dsi_interface MIPI-DSI
      19              :  * @since 3.1
      20              :  * @version 0.8.0
      21              :  * @ingroup display_interface
      22              :  * @{
      23              :  */
      24              : #include <errno.h>
      25              : #include <sys/types.h>
      26              : #include <zephyr/device.h>
      27              : #include <zephyr/display/mipi_display.h>
      28              : #include <zephyr/dt-bindings/mipi_dsi/mipi_dsi.h>
      29              : 
      30              : #ifdef __cplusplus
      31              : extern "C" {
      32              : #endif
      33              : 
      34              : /** MIPI-DSI display timings. */
      35            1 : struct mipi_dsi_timings {
      36              :         /** Horizontal active video. */
      37            1 :         uint32_t hactive;
      38              :         /** Horizontal front porch. */
      39            1 :         uint32_t hfp;
      40              :         /** Horizontal back porch. */
      41            1 :         uint32_t hbp;
      42              :         /** Horizontal sync length. */
      43            1 :         uint32_t hsync;
      44              :         /** Vertical active video. */
      45            1 :         uint32_t vactive;
      46              :         /** Vertical front porch. */
      47            1 :         uint32_t vfp;
      48              :         /** Vertical back porch. */
      49            1 :         uint32_t vbp;
      50              :         /** Vertical sync length. */
      51            1 :         uint32_t vsync;
      52              : };
      53              : 
      54              : /**
      55              :  * @name MIPI-DSI Device mode flags.
      56              :  * @{
      57              :  */
      58              : 
      59              : /** Video mode */
      60            1 : #define MIPI_DSI_MODE_VIDEO             BIT(0)
      61              : /** Video burst mode */
      62            1 : #define MIPI_DSI_MODE_VIDEO_BURST       BIT(1)
      63              : /** Video pulse mode */
      64            1 : #define MIPI_DSI_MODE_VIDEO_SYNC_PULSE  BIT(2)
      65              : /** Enable auto vertical count mode */
      66            1 : #define MIPI_DSI_MODE_VIDEO_AUTO_VERT   BIT(3)
      67              : /** Enable hsync-end packets in vsync-pulse and v-porch area */
      68            1 : #define MIPI_DSI_MODE_VIDEO_HSE         BIT(4)
      69              : /** Disable hfront-porch area */
      70            1 : #define MIPI_DSI_MODE_VIDEO_HFP         BIT(5)
      71              : /** Disable hback-porch area */
      72            1 : #define MIPI_DSI_MODE_VIDEO_HBP         BIT(6)
      73              : /** Disable hsync-active area */
      74            1 : #define MIPI_DSI_MODE_VIDEO_HSA         BIT(7)
      75              : /** Flush display FIFO on vsync pulse */
      76            1 : #define MIPI_DSI_MODE_VSYNC_FLUSH       BIT(8)
      77              : /** Disable EoT packets in HS mode */
      78            1 : #define MIPI_DSI_MODE_EOT_PACKET        BIT(9)
      79              : /** Device supports non-continuous clock behavior (DSI spec 5.6.1) */
      80            1 : #define MIPI_DSI_CLOCK_NON_CONTINUOUS   BIT(10)
      81              : /** Transmit data in low power */
      82            1 : #define MIPI_DSI_MODE_LPM               BIT(11)
      83              : 
      84              : /** @} */
      85              : 
      86              : /** MIPI-DSI device. */
      87            1 : struct mipi_dsi_device {
      88              :         /** Number of data lanes. */
      89            1 :         uint8_t data_lanes;
      90              :         /** Display timings. */
      91            1 :         struct mipi_dsi_timings timings;
      92              :         /** Pixel format. */
      93            1 :         uint32_t pixfmt;
      94              :         /** Mode flags. */
      95            1 :         uint32_t mode_flags;
      96              : };
      97              : 
      98              : /*
      99              :  * Per message flag to indicate the message must be sent
     100              :  * using Low Power Mode instead of controller default.
     101              :  */
     102            0 : #define MIPI_DSI_MSG_USE_LPM BIT(0x0)
     103              : 
     104              : /** MIPI-DSI read/write message. */
     105            1 : struct mipi_dsi_msg {
     106              :         /** Payload data type. */
     107            1 :         uint8_t type;
     108              :         /** Flags controlling message transmission. */
     109            1 :         uint16_t flags;
     110              :         /** Command (only for DCS) */
     111            1 :         uint8_t cmd;
     112              :         /** Transmission buffer length. */
     113            1 :         size_t tx_len;
     114              :         /** Transmission buffer. */
     115            1 :         const void *tx_buf;
     116              :         /** Reception buffer length. */
     117            1 :         size_t rx_len;
     118              :         /** Reception buffer. */
     119            1 :         void *rx_buf;
     120              :         /** User data. */
     121            1 :         void *user_data;
     122              : };
     123              : 
     124              : /** MIPI-DSI host driver API. */
     125            1 : __subsystem struct mipi_dsi_driver_api {
     126            0 :         int (*attach)(const struct device *dev, uint8_t channel,
     127              :                       const struct mipi_dsi_device *mdev);
     128            0 :         ssize_t (*transfer)(const struct device *dev, uint8_t channel,
     129              :                             struct mipi_dsi_msg *msg);
     130            0 :         int (*detach)(const struct device *dev, uint8_t channel,
     131              :                       const struct mipi_dsi_device *mdev);
     132              : };
     133              : 
     134              : /**
     135              :  * @brief Attach a new device to the MIPI-DSI bus.
     136              :  *
     137              :  * @param dev MIPI-DSI host device.
     138              :  * @param channel Device channel (VID).
     139              :  * @param mdev MIPI-DSI device description.
     140              :  *
     141              :  * @return 0 on success, negative on error
     142              :  */
     143            1 : static inline int mipi_dsi_attach(const struct device *dev,
     144              :                                   uint8_t channel,
     145              :                                   const struct mipi_dsi_device *mdev)
     146              : {
     147              :         const struct mipi_dsi_driver_api *api = (const struct mipi_dsi_driver_api *)dev->api;
     148              : 
     149              :         return api->attach(dev, channel, mdev);
     150              : }
     151              : 
     152              : /**
     153              :  * @brief Transfer data to/from a device attached to the MIPI-DSI bus.
     154              :  *
     155              :  * @param dev MIPI-DSI device.
     156              :  * @param channel Device channel (VID).
     157              :  * @param msg Message.
     158              :  *
     159              :  * @return Size of the transferred data on success, negative on error.
     160              :  */
     161            1 : static inline ssize_t mipi_dsi_transfer(const struct device *dev,
     162              :                                         uint8_t channel,
     163              :                                         struct mipi_dsi_msg *msg)
     164              : {
     165              :         const struct mipi_dsi_driver_api *api = (const struct mipi_dsi_driver_api *)dev->api;
     166              : 
     167              :         return api->transfer(dev, channel, msg);
     168              : }
     169              : 
     170              : /**
     171              :  * @brief MIPI-DSI generic read.
     172              :  *
     173              :  * @param dev MIPI-DSI host device.
     174              :  * @param channel Device channel (VID).
     175              :  * @param params Buffer containing request parameters.
     176              :  * @param nparams Number of parameters.
     177              :  * @param buf Buffer where read data will be stored.
     178              :  * @param len Length of the reception buffer.
     179              :  *
     180              :  * @return Size of the read data on success, negative on error.
     181              :  */
     182            1 : ssize_t mipi_dsi_generic_read(const struct device *dev, uint8_t channel,
     183              :                               const void *params, size_t nparams,
     184              :                               void *buf, size_t len);
     185              : 
     186              : /**
     187              :  * @brief MIPI-DSI generic write.
     188              :  *
     189              :  * @param dev MIPI-DSI host device.
     190              :  * @param channel Device channel (VID).
     191              :  * @param buf Transmission buffer.
     192              :  * @param len Length of the transmission buffer
     193              :  *
     194              :  * @return Size of the written data on success, negative on error.
     195              :  */
     196            1 : ssize_t mipi_dsi_generic_write(const struct device *dev, uint8_t channel,
     197              :                                const void *buf, size_t len);
     198              : 
     199              : /**
     200              :  * @brief MIPI-DSI DCS read.
     201              :  *
     202              :  * @param dev MIPI-DSI host device.
     203              :  * @param channel Device channel (VID).
     204              :  * @param cmd DCS command.
     205              :  * @param buf Buffer where read data will be stored.
     206              :  * @param len Length of the reception buffer.
     207              :  *
     208              :  * @return Size of the read data on success, negative on error.
     209              :  */
     210            1 : ssize_t mipi_dsi_dcs_read(const struct device *dev, uint8_t channel,
     211              :                           uint8_t cmd, void *buf, size_t len);
     212              : 
     213              : /**
     214              :  * @brief MIPI-DSI DCS write.
     215              :  *
     216              :  * @param dev MIPI-DSI host device.
     217              :  * @param channel Device channel (VID).
     218              :  * @param cmd DCS command.
     219              :  * @param buf Transmission buffer.
     220              :  * @param len Length of the transmission buffer
     221              :  *
     222              :  * @return Size of the written data on success, negative on error.
     223              :  */
     224            1 : ssize_t mipi_dsi_dcs_write(const struct device *dev, uint8_t channel,
     225              :                            uint8_t cmd, const void *buf, size_t len);
     226              : 
     227              : 
     228              : /**
     229              :  * @brief Detach a device from the MIPI-DSI bus
     230              :  *
     231              :  * @param dev MIPI-DSI host device.
     232              :  * @param channel Device channel (VID).
     233              :  * @param mdev MIPI-DSI device description.
     234              :  *
     235              :  * @return 0 on success, negative on error
     236              :  */
     237            1 : static inline int mipi_dsi_detach(const struct device *dev,
     238              :                                   uint8_t channel,
     239              :                                   const struct mipi_dsi_device *mdev)
     240              : {
     241              :         const struct mipi_dsi_driver_api *api = (const struct mipi_dsi_driver_api *)dev->api;
     242              : 
     243              :         if (api->detach == NULL) {
     244              :                 return -ENOSYS;
     245              :         }
     246              : 
     247              :         return api->detach(dev, channel, mdev);
     248              : }
     249              : 
     250              : #ifdef __cplusplus
     251              : }
     252              : #endif
     253              : 
     254              : /**
     255              :  * @}
     256              :  */
     257              : 
     258              : #endif /* ZEPHYR_INCLUDE_DRIVERS_MIPI_DSI_H_ */
        

Generated by: LCOV version 2.0-1