Yannick Fertré | 66c3724 | 2019-10-07 15:29:04 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * MIPI DSI Bus |
| 4 | * |
| 5 | * Copyright (C) 2012-2013, Samsung Electronics, Co., Ltd. |
| 6 | * Copyright (C) 2018 STMicroelectronics - All Rights Reserved |
| 7 | * Author(s): Andrzej Hajda <a.hajda@samsung.com> |
| 8 | * Yannick Fertre <yannick.fertre@st.com> |
| 9 | * Philippe Cornu <philippe.cornu@st.com> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | */ |
| 15 | #ifndef MIPI_DSI_H |
| 16 | #define MIPI_DSI_H |
| 17 | |
| 18 | #include <mipi_display.h> |
| 19 | |
| 20 | struct mipi_dsi_host; |
| 21 | struct mipi_dsi_device; |
| 22 | |
| 23 | /* request ACK from peripheral */ |
| 24 | #define MIPI_DSI_MSG_REQ_ACK BIT(0) |
| 25 | /* use Low Power Mode to transmit message */ |
| 26 | #define MIPI_DSI_MSG_USE_LPM BIT(1) |
| 27 | |
| 28 | /** |
| 29 | * struct mipi_dsi_msg - read/write DSI buffer |
| 30 | * @channel: virtual channel id |
| 31 | * @type: payload data type |
| 32 | * @flags: flags controlling this message transmission |
| 33 | * @tx_len: length of @tx_buf |
| 34 | * @tx_buf: data to be written |
| 35 | * @rx_len: length of @rx_buf |
| 36 | * @rx_buf: data to be read, or NULL |
| 37 | */ |
| 38 | struct mipi_dsi_msg { |
| 39 | u8 channel; |
| 40 | u8 type; |
| 41 | u16 flags; |
| 42 | |
| 43 | size_t tx_len; |
| 44 | const void *tx_buf; |
| 45 | |
| 46 | size_t rx_len; |
| 47 | void *rx_buf; |
| 48 | }; |
| 49 | |
| 50 | bool mipi_dsi_packet_format_is_short(u8 type); |
| 51 | bool mipi_dsi_packet_format_is_long(u8 type); |
| 52 | |
| 53 | /** |
| 54 | * struct mipi_dsi_packet - represents a MIPI DSI packet in protocol format |
| 55 | * @size: size (in bytes) of the packet |
| 56 | * @header: the four bytes that make up the header (Data ID, Word Count or |
| 57 | * Packet Data, and ECC) |
| 58 | * @payload_length: number of bytes in the payload |
| 59 | * @payload: a pointer to a buffer containing the payload, if any |
| 60 | */ |
| 61 | struct mipi_dsi_packet { |
| 62 | size_t size; |
| 63 | u8 header[4]; |
| 64 | size_t payload_length; |
| 65 | const u8 *payload; |
| 66 | }; |
| 67 | |
| 68 | int mipi_dsi_create_packet(struct mipi_dsi_packet *packet, |
| 69 | const struct mipi_dsi_msg *msg); |
| 70 | |
| 71 | /** |
| 72 | * struct mipi_dsi_host_ops - DSI bus operations |
| 73 | * @attach: attach DSI device to DSI host |
| 74 | * @detach: detach DSI device from DSI host |
| 75 | * @transfer: transmit a DSI packet |
| 76 | * |
| 77 | * DSI packets transmitted by .transfer() are passed in as mipi_dsi_msg |
| 78 | * structures. This structure contains information about the type of packet |
| 79 | * being transmitted as well as the transmit and receive buffers. When an |
| 80 | * error is encountered during transmission, this function will return a |
| 81 | * negative error code. On success it shall return the number of bytes |
| 82 | * transmitted for write packets or the number of bytes received for read |
| 83 | * packets. |
| 84 | * |
| 85 | * Note that typically DSI packet transmission is atomic, so the .transfer() |
| 86 | * function will seldomly return anything other than the number of bytes |
| 87 | * contained in the transmit buffer on success. |
| 88 | */ |
| 89 | struct mipi_dsi_host_ops { |
| 90 | int (*attach)(struct mipi_dsi_host *host, |
| 91 | struct mipi_dsi_device *dsi); |
| 92 | int (*detach)(struct mipi_dsi_host *host, |
| 93 | struct mipi_dsi_device *dsi); |
| 94 | ssize_t (*transfer)(struct mipi_dsi_host *host, |
| 95 | const struct mipi_dsi_msg *msg); |
| 96 | }; |
| 97 | |
| 98 | /** |
| 99 | * struct mipi_dsi_phy_ops - DSI host physical operations |
| 100 | * @init: initialized host physical part |
| 101 | * @get_lane_mbps: get lane bitrate per lane (mbps) |
| 102 | * @post_set_mode: operation that should after set mode |
| 103 | */ |
| 104 | struct mipi_dsi_phy_ops { |
| 105 | int (*init)(void *priv_data); |
| 106 | int (*get_lane_mbps)(void *priv_data, struct display_timing *timings, |
| 107 | u32 lanes, u32 format, unsigned int *lane_mbps); |
| 108 | void (*post_set_mode)(void *priv_data, unsigned long mode_flags); |
| 109 | }; |
| 110 | |
| 111 | /** |
| 112 | * struct mipi_dsi_host - DSI host device |
| 113 | * @dev: driver model device node for this DSI host |
| 114 | * @ops: DSI host operations |
| 115 | * @list: list management |
| 116 | */ |
| 117 | struct mipi_dsi_host { |
| 118 | struct device *dev; |
| 119 | const struct mipi_dsi_host_ops *ops; |
| 120 | struct list_head list; |
| 121 | }; |
| 122 | |
| 123 | /* DSI mode flags */ |
| 124 | |
| 125 | /* video mode */ |
| 126 | #define MIPI_DSI_MODE_VIDEO BIT(0) |
| 127 | /* video burst mode */ |
| 128 | #define MIPI_DSI_MODE_VIDEO_BURST BIT(1) |
| 129 | /* video pulse mode */ |
| 130 | #define MIPI_DSI_MODE_VIDEO_SYNC_PULSE BIT(2) |
| 131 | /* enable auto vertical count mode */ |
| 132 | #define MIPI_DSI_MODE_VIDEO_AUTO_VERT BIT(3) |
| 133 | /* enable hsync-end packets in vsync-pulse and v-porch area */ |
| 134 | #define MIPI_DSI_MODE_VIDEO_HSE BIT(4) |
| 135 | /* disable hfront-porch area */ |
| 136 | #define MIPI_DSI_MODE_VIDEO_HFP BIT(5) |
| 137 | /* disable hback-porch area */ |
| 138 | #define MIPI_DSI_MODE_VIDEO_HBP BIT(6) |
| 139 | /* disable hsync-active area */ |
| 140 | #define MIPI_DSI_MODE_VIDEO_HSA BIT(7) |
| 141 | /* flush display FIFO on vsync pulse */ |
| 142 | #define MIPI_DSI_MODE_VSYNC_FLUSH BIT(8) |
| 143 | /* disable EoT packets in HS mode */ |
| 144 | #define MIPI_DSI_MODE_EOT_PACKET BIT(9) |
| 145 | /* device supports non-continuous clock behavior (DSI spec 5.6.1) */ |
| 146 | #define MIPI_DSI_CLOCK_NON_CONTINUOUS BIT(10) |
| 147 | /* transmit data in low power */ |
| 148 | #define MIPI_DSI_MODE_LPM BIT(11) |
| 149 | |
| 150 | enum mipi_dsi_pixel_format { |
| 151 | MIPI_DSI_FMT_RGB888, |
| 152 | MIPI_DSI_FMT_RGB666, |
| 153 | MIPI_DSI_FMT_RGB666_PACKED, |
| 154 | MIPI_DSI_FMT_RGB565, |
| 155 | }; |
| 156 | |
| 157 | #define DSI_DEV_NAME_SIZE 20 |
| 158 | |
| 159 | /** |
| 160 | * struct mipi_dsi_device_info - template for creating a mipi_dsi_device |
| 161 | * @type: DSI peripheral chip type |
| 162 | * @channel: DSI virtual channel assigned to peripheral |
| 163 | * @node: pointer to OF device node or NULL |
| 164 | * |
| 165 | * This is populated and passed to mipi_dsi_device_new to create a new |
| 166 | * DSI device |
| 167 | */ |
| 168 | struct mipi_dsi_device_info { |
| 169 | char type[DSI_DEV_NAME_SIZE]; |
| 170 | u32 channel; |
| 171 | struct device_node *node; |
| 172 | }; |
| 173 | |
| 174 | /** |
| 175 | * struct mipi_dsi_device - DSI peripheral device |
| 176 | * @host: DSI host for this peripheral |
| 177 | * @dev: driver model device node for this peripheral |
| 178 | * @name: DSI peripheral chip type |
| 179 | * @channel: virtual channel assigned to the peripheral |
| 180 | * @format: pixel format for video mode |
| 181 | * @lanes: number of active data lanes |
| 182 | * @mode_flags: DSI operation mode related flags |
| 183 | */ |
| 184 | struct mipi_dsi_device { |
| 185 | struct mipi_dsi_host *host; |
| 186 | struct udevice *dev; |
| 187 | |
| 188 | char name[DSI_DEV_NAME_SIZE]; |
| 189 | unsigned int channel; |
| 190 | unsigned int lanes; |
| 191 | enum mipi_dsi_pixel_format format; |
| 192 | unsigned long mode_flags; |
| 193 | }; |
| 194 | |
| 195 | /** |
| 196 | * mipi_dsi_pixel_format_to_bpp - obtain the number of bits per pixel for any |
| 197 | * given pixel format defined by the MIPI DSI |
| 198 | * specification |
| 199 | * @fmt: MIPI DSI pixel format |
| 200 | * |
| 201 | * Returns: The number of bits per pixel of the given pixel format. |
| 202 | */ |
| 203 | static inline int mipi_dsi_pixel_format_to_bpp(enum mipi_dsi_pixel_format fmt) |
| 204 | { |
| 205 | switch (fmt) { |
| 206 | case MIPI_DSI_FMT_RGB888: |
| 207 | case MIPI_DSI_FMT_RGB666: |
| 208 | return 24; |
| 209 | |
| 210 | case MIPI_DSI_FMT_RGB666_PACKED: |
| 211 | return 18; |
| 212 | |
| 213 | case MIPI_DSI_FMT_RGB565: |
| 214 | return 16; |
| 215 | } |
| 216 | |
| 217 | return -EINVAL; |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * struct mipi_dsi_panel_plat - DSI panel platform data |
| 222 | * @device: DSI peripheral device |
| 223 | */ |
| 224 | struct mipi_dsi_panel_plat { |
| 225 | struct mipi_dsi_device *device; |
| 226 | }; |
| 227 | |
| 228 | /** |
| 229 | * mipi_dsi_attach - attach a DSI device to its DSI host |
| 230 | * @dsi: DSI peripheral |
| 231 | */ |
| 232 | int mipi_dsi_attach(struct mipi_dsi_device *dsi); |
| 233 | |
| 234 | /** |
| 235 | * mipi_dsi_detach - detach a DSI device from its DSI host |
| 236 | * @dsi: DSI peripheral |
| 237 | */ |
| 238 | int mipi_dsi_detach(struct mipi_dsi_device *dsi); |
| 239 | int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi); |
| 240 | int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi); |
| 241 | int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi, |
| 242 | u16 value); |
| 243 | |
| 244 | ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload, |
| 245 | size_t size); |
| 246 | ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params, |
| 247 | size_t num_params, void *data, size_t size); |
| 248 | |
| 249 | /** |
| 250 | * enum mipi_dsi_dcs_tear_mode - Tearing Effect Output Line mode |
| 251 | * @MIPI_DSI_DCS_TEAR_MODE_VBLANK: the TE output line consists of V-Blanking |
| 252 | * information only |
| 253 | * @MIPI_DSI_DCS_TEAR_MODE_VHBLANK : the TE output line consists of both |
| 254 | * V-Blanking and H-Blanking information |
| 255 | */ |
| 256 | enum mipi_dsi_dcs_tear_mode { |
| 257 | MIPI_DSI_DCS_TEAR_MODE_VBLANK, |
| 258 | MIPI_DSI_DCS_TEAR_MODE_VHBLANK, |
| 259 | }; |
| 260 | |
| 261 | #define MIPI_DSI_DCS_POWER_MODE_DISPLAY BIT(2) |
| 262 | #define MIPI_DSI_DCS_POWER_MODE_NORMAL BIT(3) |
| 263 | #define MIPI_DSI_DCS_POWER_MODE_SLEEP BIT(4) |
| 264 | #define MIPI_DSI_DCS_POWER_MODE_PARTIAL BIT(5) |
| 265 | #define MIPI_DSI_DCS_POWER_MODE_IDLE BIT(6) |
| 266 | |
| 267 | /** |
| 268 | * mipi_dsi_dcs_write_buffer() - transmit a DCS command with payload |
| 269 | * @dsi: DSI peripheral device |
| 270 | * @data: buffer containing data to be transmitted |
| 271 | * @len: size of transmission buffer |
| 272 | * |
| 273 | * This function will automatically choose the right data type depending on |
| 274 | * the command payload length. |
| 275 | * |
| 276 | * Return: The number of bytes successfully transmitted or a negative error |
| 277 | * code on failure. |
| 278 | */ |
| 279 | ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi, |
| 280 | const void *data, size_t len); |
| 281 | |
| 282 | /** |
| 283 | * mipi_dsi_dcs_write() - send DCS write command |
| 284 | * @dsi: DSI peripheral device |
| 285 | * @cmd: DCS command |
| 286 | * @data: buffer containing the command payload |
| 287 | * @len: command payload length |
| 288 | * |
| 289 | * This function will automatically choose the right data type depending on |
| 290 | * the command payload length. |
| 291 | |
| 292 | * code on failure. |
| 293 | */ |
| 294 | ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd, |
| 295 | const void *data, size_t len); |
| 296 | |
| 297 | /** |
| 298 | * mipi_dsi_dcs_read() - send DCS read request command |
| 299 | * @dsi: DSI peripheral device |
| 300 | * @cmd: DCS command |
| 301 | * @data: buffer in which to receive data |
| 302 | * @len: size of receive buffer |
| 303 | * |
| 304 | * Return: The number of bytes read or a negative error code on failure. |
| 305 | */ |
| 306 | ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data, |
| 307 | size_t len); |
| 308 | |
| 309 | /** |
| 310 | * mipi_dsi_dcs_nop() - send DCS nop packet |
| 311 | * @dsi: DSI peripheral device |
| 312 | * |
| 313 | * Return: 0 on success or a negative error code on failure. |
| 314 | */ |
| 315 | int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi); |
| 316 | |
| 317 | /** |
| 318 | * mipi_dsi_dcs_soft_reset() - perform a software reset of the display module |
| 319 | * @dsi: DSI peripheral device |
| 320 | * |
| 321 | * Return: 0 on success or a negative error code on failure. |
| 322 | */ |
| 323 | int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi); |
| 324 | |
| 325 | /** |
| 326 | * mipi_dsi_dcs_get_power_mode() - query the display module's current power |
| 327 | * mode |
| 328 | * @dsi: DSI peripheral device |
| 329 | * @mode: return location for the current power mode |
| 330 | * |
| 331 | * Return: 0 on success or a negative error code on failure. |
| 332 | */ |
| 333 | int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode); |
| 334 | |
| 335 | /** |
| 336 | * mipi_dsi_dcs_get_pixel_format() - gets the pixel format for the RGB image |
| 337 | * data used by the interface |
| 338 | * @dsi: DSI peripheral device |
| 339 | * @format: return location for the pixel format |
| 340 | * |
| 341 | * Return: 0 on success or a negative error code on failure. |
| 342 | */ |
| 343 | int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format); |
| 344 | |
| 345 | /** |
| 346 | * mipi_dsi_dcs_enter_sleep_mode() - disable all unnecessary blocks inside the |
| 347 | * display module except interface communication |
| 348 | * @dsi: DSI peripheral device |
| 349 | * |
| 350 | * Return: 0 on success or a negative error code on failure. |
| 351 | */ |
| 352 | int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi); |
| 353 | |
| 354 | /** |
| 355 | * mipi_dsi_dcs_exit_sleep_mode() - enable all blocks inside the display |
| 356 | * module |
| 357 | * @dsi: DSI peripheral device |
| 358 | * |
| 359 | * Return: 0 on success or a negative error code on failure. |
| 360 | */ |
| 361 | int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi); |
| 362 | |
| 363 | /** |
| 364 | * mipi_dsi_dcs_set_display_off() - stop displaying the image data on the |
| 365 | * display device |
| 366 | * @dsi: DSI peripheral device |
| 367 | * |
| 368 | * Return: 0 on success or a negative error code on failure. |
| 369 | */ |
| 370 | int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi); |
| 371 | |
| 372 | /** |
| 373 | * mipi_dsi_dcs_set_display_on() - start displaying the image data on the |
| 374 | * display device |
| 375 | * @dsi: DSI peripheral device |
| 376 | * |
| 377 | * Return: 0 on success or a negative error code on failure |
| 378 | */ |
| 379 | int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi); |
| 380 | |
| 381 | /** |
| 382 | * mipi_dsi_dcs_set_column_address() - define the column extent of the frame |
| 383 | * memory accessed by the host processor |
| 384 | * @dsi: DSI peripheral device |
| 385 | * @start: first column of frame memory |
| 386 | * @end: last column of frame memory |
| 387 | * |
| 388 | * Return: 0 on success or a negative error code on failure. |
| 389 | */ |
| 390 | int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start, |
| 391 | u16 end); |
| 392 | /** |
| 393 | * mipi_dsi_dcs_set_page_address() - define the page extent of the frame |
| 394 | * memory accessed by the host processor |
| 395 | * @dsi: DSI peripheral device |
| 396 | * @start: first page of frame memory |
| 397 | * @end: last page of frame memory |
| 398 | * |
| 399 | * Return: 0 on success or a negative error code on failure. |
| 400 | */ |
| 401 | int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start, |
| 402 | u16 end); |
| 403 | |
| 404 | /** |
| 405 | * mipi_dsi_dcs_set_tear_off() - turn off the display module's Tearing Effect |
| 406 | * output signal on the TE signal line |
| 407 | * @dsi: DSI peripheral device |
| 408 | * |
| 409 | * Return: 0 on success or a negative error code on failure |
| 410 | */ |
| 411 | int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device *dsi); |
| 412 | |
| 413 | /** |
| 414 | * mipi_dsi_dcs_set_tear_on() - turn on the display module's Tearing Effect |
| 415 | * output signal on the TE signal line. |
| 416 | * @dsi: DSI peripheral device |
| 417 | * @mode: the Tearing Effect Output Line mode |
| 418 | * |
| 419 | * Return: 0 on success or a negative error code on failure |
| 420 | */ |
| 421 | int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi, |
| 422 | enum mipi_dsi_dcs_tear_mode mode); |
| 423 | |
| 424 | /** |
| 425 | * mipi_dsi_dcs_set_pixel_format() - sets the pixel format for the RGB image |
| 426 | * data used by the interface |
| 427 | * @dsi: DSI peripheral device |
| 428 | * @format: pixel format |
| 429 | * |
| 430 | * Return: 0 on success or a negative error code on failure. |
| 431 | */ |
| 432 | int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format); |
| 433 | |
| 434 | /** |
| 435 | * mipi_dsi_dcs_set_tear_scanline() - set the scanline to use as trigger for |
| 436 | * the Tearing Effect output signal of the display module |
| 437 | * @dsi: DSI peripheral device |
| 438 | * @scanline: scanline to use as trigger |
| 439 | * |
| 440 | * Return: 0 on success or a negative error code on failure |
| 441 | */ |
| 442 | int mipi_dsi_dcs_set_tear_scanline(struct mipi_dsi_device *dsi, u16 scanline); |
| 443 | |
| 444 | /** |
| 445 | * mipi_dsi_dcs_set_display_brightness() - sets the brightness value of the |
| 446 | * display |
| 447 | * @dsi: DSI peripheral device |
| 448 | * @brightness: brightness value |
| 449 | * |
| 450 | * Return: 0 on success or a negative error code on failure. |
| 451 | */ |
| 452 | int mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device *dsi, |
| 453 | u16 brightness); |
| 454 | |
| 455 | /** |
| 456 | * mipi_dsi_dcs_get_display_brightness() - gets the current brightness value |
| 457 | * of the display |
| 458 | * @dsi: DSI peripheral device |
| 459 | * @brightness: brightness value |
| 460 | * |
| 461 | * Return: 0 on success or a negative error code on failure. |
| 462 | */ |
| 463 | int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi, |
| 464 | u16 *brightness); |
| 465 | |
| 466 | #endif /* MIPI_DSI_H */ |