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-05 16:43:28

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

Generated by: LCOV version 2.0-1