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) 2019 STMicroelectronics - All Rights Reserved |
| 7 | * Andrzej Hajda <a.hajda@samsung.com> |
| 8 | * |
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | * copy of this software and associated documentation files (the |
| 11 | * "Software"), to deal in the Software without restriction, including |
| 12 | * without limitation the rights to use, copy, modify, merge, publish, |
| 13 | * distribute, sub license, and/or sell copies of the Software, and to |
| 14 | * permit persons to whom the Software is furnished to do so, subject to |
| 15 | * the following conditions: |
| 16 | * |
| 17 | * The above copyright notice and this permission notice (including the |
| 18 | * next paragraph) shall be included in all copies or substantial portions |
| 19 | * of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 24 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, |
| 25 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 26 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 27 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 28 | * |
| 29 | * Mipi_dsi.c contains a set of dsi helpers. |
| 30 | * This file is inspired from the drm helper file drivers/gpu/drm/drm_mipi_dsi.c |
| 31 | * (kernel linux). |
| 32 | * |
| 33 | */ |
| 34 | |
Yannick Fertré | 66c3724 | 2019-10-07 15:29:04 +0200 | [diff] [blame] | 35 | #include <clk.h> |
| 36 | #include <display.h> |
| 37 | #include <dm.h> |
| 38 | #include <mipi_display.h> |
| 39 | #include <mipi_dsi.h> |
Simon Glass | 61b29b8 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 40 | #include <dm/devres.h> |
Yannick Fertré | 66c3724 | 2019-10-07 15:29:04 +0200 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * DOC: dsi helpers |
| 44 | * |
| 45 | * These functions contain some common logic and helpers to deal with MIPI DSI |
| 46 | * peripherals. |
| 47 | * |
| 48 | * Helpers are provided for a number of standard MIPI DSI command as well as a |
| 49 | * subset of the MIPI DCS command set. |
| 50 | */ |
| 51 | |
| 52 | /** |
| 53 | * mipi_dsi_attach - attach a DSI device to its DSI host |
| 54 | * @dsi: DSI peripheral |
| 55 | */ |
| 56 | int mipi_dsi_attach(struct mipi_dsi_device *dsi) |
| 57 | { |
| 58 | const struct mipi_dsi_host_ops *ops = dsi->host->ops; |
| 59 | |
| 60 | if (!ops || !ops->attach) |
| 61 | return -ENOSYS; |
| 62 | |
| 63 | return ops->attach(dsi->host, dsi); |
| 64 | } |
| 65 | EXPORT_SYMBOL(mipi_dsi_attach); |
| 66 | |
| 67 | /** |
| 68 | * mipi_dsi_detach - detach a DSI device from its DSI host |
| 69 | * @dsi: DSI peripheral |
| 70 | */ |
| 71 | int mipi_dsi_detach(struct mipi_dsi_device *dsi) |
| 72 | { |
| 73 | const struct mipi_dsi_host_ops *ops = dsi->host->ops; |
| 74 | |
| 75 | if (!ops || !ops->detach) |
| 76 | return -ENOSYS; |
| 77 | |
| 78 | return ops->detach(dsi->host, dsi); |
| 79 | } |
| 80 | EXPORT_SYMBOL(mipi_dsi_detach); |
| 81 | |
| 82 | /** |
| 83 | * mipi_dsi_device_transfer - transfer message to a DSI device |
| 84 | * @dsi: DSI peripheral |
| 85 | * @msg: message |
| 86 | */ |
| 87 | static ssize_t mipi_dsi_device_transfer(struct mipi_dsi_device *dsi, |
| 88 | struct mipi_dsi_msg *msg) |
| 89 | { |
| 90 | const struct mipi_dsi_host_ops *ops = dsi->host->ops; |
| 91 | |
| 92 | if (!ops || !ops->transfer) |
| 93 | return -ENOSYS; |
| 94 | |
| 95 | if (dsi->mode_flags & MIPI_DSI_MODE_LPM) |
| 96 | msg->flags |= MIPI_DSI_MSG_USE_LPM; |
| 97 | |
| 98 | return ops->transfer(dsi->host, msg); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * mipi_dsi_packet_format_is_short - check if a packet is of the short format |
| 103 | * @type: MIPI DSI data type of the packet |
| 104 | * |
| 105 | * Return: true if the packet for the given data type is a short packet, false |
| 106 | * otherwise. |
| 107 | */ |
| 108 | bool mipi_dsi_packet_format_is_short(u8 type) |
| 109 | { |
| 110 | switch (type) { |
| 111 | case MIPI_DSI_V_SYNC_START: |
| 112 | case MIPI_DSI_V_SYNC_END: |
| 113 | case MIPI_DSI_H_SYNC_START: |
| 114 | case MIPI_DSI_H_SYNC_END: |
| 115 | case MIPI_DSI_END_OF_TRANSMISSION: |
| 116 | case MIPI_DSI_COLOR_MODE_OFF: |
| 117 | case MIPI_DSI_COLOR_MODE_ON: |
| 118 | case MIPI_DSI_SHUTDOWN_PERIPHERAL: |
| 119 | case MIPI_DSI_TURN_ON_PERIPHERAL: |
| 120 | case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM: |
| 121 | case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM: |
| 122 | case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM: |
| 123 | case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM: |
| 124 | case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM: |
| 125 | case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM: |
| 126 | case MIPI_DSI_DCS_SHORT_WRITE: |
| 127 | case MIPI_DSI_DCS_SHORT_WRITE_PARAM: |
| 128 | case MIPI_DSI_DCS_READ: |
| 129 | case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE: |
| 130 | return true; |
| 131 | } |
| 132 | |
| 133 | return false; |
| 134 | } |
| 135 | EXPORT_SYMBOL(mipi_dsi_packet_format_is_short); |
| 136 | |
| 137 | /** |
| 138 | * mipi_dsi_packet_format_is_long - check if a packet is of the long format |
| 139 | * @type: MIPI DSI data type of the packet |
| 140 | * |
| 141 | * Return: true if the packet for the given data type is a long packet, false |
| 142 | * otherwise. |
| 143 | */ |
| 144 | bool mipi_dsi_packet_format_is_long(u8 type) |
| 145 | { |
| 146 | switch (type) { |
| 147 | case MIPI_DSI_NULL_PACKET: |
| 148 | case MIPI_DSI_BLANKING_PACKET: |
| 149 | case MIPI_DSI_GENERIC_LONG_WRITE: |
| 150 | case MIPI_DSI_DCS_LONG_WRITE: |
| 151 | case MIPI_DSI_LOOSELY_PACKED_PIXEL_STREAM_YCBCR20: |
| 152 | case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR24: |
| 153 | case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16: |
| 154 | case MIPI_DSI_PACKED_PIXEL_STREAM_30: |
| 155 | case MIPI_DSI_PACKED_PIXEL_STREAM_36: |
| 156 | case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12: |
| 157 | case MIPI_DSI_PACKED_PIXEL_STREAM_16: |
| 158 | case MIPI_DSI_PACKED_PIXEL_STREAM_18: |
| 159 | case MIPI_DSI_PIXEL_STREAM_3BYTE_18: |
| 160 | case MIPI_DSI_PACKED_PIXEL_STREAM_24: |
| 161 | return true; |
| 162 | } |
| 163 | |
| 164 | return false; |
| 165 | } |
| 166 | EXPORT_SYMBOL(mipi_dsi_packet_format_is_long); |
| 167 | |
| 168 | /** |
| 169 | * mipi_dsi_create_packet - create a packet from a message according to the |
| 170 | * DSI protocol |
| 171 | * @packet: pointer to a DSI packet structure |
| 172 | * @msg: message to translate into a packet |
| 173 | * |
| 174 | * Return: 0 on success or a negative error code on failure. |
| 175 | */ |
| 176 | int mipi_dsi_create_packet(struct mipi_dsi_packet *packet, |
| 177 | const struct mipi_dsi_msg *msg) |
| 178 | { |
| 179 | if (!packet || !msg) |
| 180 | return -EINVAL; |
| 181 | |
| 182 | /* do some minimum sanity checking */ |
| 183 | if (!mipi_dsi_packet_format_is_short(msg->type) && |
| 184 | !mipi_dsi_packet_format_is_long(msg->type)) |
| 185 | return -EINVAL; |
| 186 | |
| 187 | if (msg->channel > 3) |
| 188 | return -EINVAL; |
| 189 | |
| 190 | memset(packet, 0, sizeof(*packet)); |
| 191 | packet->header[0] = ((msg->channel & 0x3) << 6) | (msg->type & 0x3f); |
| 192 | |
| 193 | /* TODO: compute ECC if hardware support is not available */ |
| 194 | |
| 195 | /* |
| 196 | * Long write packets contain the word count in header bytes 1 and 2. |
| 197 | * The payload follows the header and is word count bytes long. |
| 198 | * |
| 199 | * Short write packets encode up to two parameters in header bytes 1 |
| 200 | * and 2. |
| 201 | */ |
| 202 | if (mipi_dsi_packet_format_is_long(msg->type)) { |
| 203 | packet->header[1] = (msg->tx_len >> 0) & 0xff; |
| 204 | packet->header[2] = (msg->tx_len >> 8) & 0xff; |
| 205 | |
| 206 | packet->payload_length = msg->tx_len; |
| 207 | packet->payload = msg->tx_buf; |
| 208 | } else { |
| 209 | const u8 *tx = msg->tx_buf; |
| 210 | |
| 211 | packet->header[1] = (msg->tx_len > 0) ? tx[0] : 0; |
| 212 | packet->header[2] = (msg->tx_len > 1) ? tx[1] : 0; |
| 213 | } |
| 214 | |
| 215 | packet->size = sizeof(packet->header) + packet->payload_length; |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | EXPORT_SYMBOL(mipi_dsi_create_packet); |
| 220 | |
| 221 | /** |
| 222 | * mipi_dsi_shutdown_peripheral() - sends a Shutdown Peripheral command |
| 223 | * @dsi: DSI peripheral device |
| 224 | * |
| 225 | * Return: 0 on success or a negative error code on failure. |
| 226 | */ |
| 227 | int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi) |
| 228 | { |
| 229 | struct mipi_dsi_msg msg = { |
| 230 | .channel = dsi->channel, |
| 231 | .type = MIPI_DSI_SHUTDOWN_PERIPHERAL, |
| 232 | .tx_buf = (u8 [2]) { 0, 0 }, |
| 233 | .tx_len = 2, |
| 234 | }; |
| 235 | int ret = mipi_dsi_device_transfer(dsi, &msg); |
| 236 | |
| 237 | return (ret < 0) ? ret : 0; |
| 238 | } |
| 239 | EXPORT_SYMBOL(mipi_dsi_shutdown_peripheral); |
| 240 | |
| 241 | /** |
| 242 | * mipi_dsi_turn_on_peripheral() - sends a Turn On Peripheral command |
| 243 | * @dsi: DSI peripheral device |
| 244 | * |
| 245 | * Return: 0 on success or a negative error code on failure. |
| 246 | */ |
| 247 | int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi) |
| 248 | { |
| 249 | struct mipi_dsi_msg msg = { |
| 250 | .channel = dsi->channel, |
| 251 | .type = MIPI_DSI_TURN_ON_PERIPHERAL, |
| 252 | .tx_buf = (u8 [2]) { 0, 0 }, |
| 253 | .tx_len = 2, |
| 254 | }; |
| 255 | int ret = mipi_dsi_device_transfer(dsi, &msg); |
| 256 | |
| 257 | return (ret < 0) ? ret : 0; |
| 258 | } |
| 259 | EXPORT_SYMBOL(mipi_dsi_turn_on_peripheral); |
| 260 | |
| 261 | /* |
| 262 | * mipi_dsi_set_maximum_return_packet_size() - specify the maximum size of the |
| 263 | * the payload in a long packet transmitted from the peripheral back to the |
| 264 | * host processor |
| 265 | * @dsi: DSI peripheral device |
| 266 | * @value: the maximum size of the payload |
| 267 | * |
| 268 | * Return: 0 on success or a negative error code on failure. |
| 269 | */ |
| 270 | int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi, |
| 271 | u16 value) |
| 272 | { |
| 273 | u8 tx[2] = { value & 0xff, value >> 8 }; |
| 274 | struct mipi_dsi_msg msg = { |
| 275 | .channel = dsi->channel, |
| 276 | .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, |
| 277 | .tx_len = sizeof(tx), |
| 278 | .tx_buf = tx, |
| 279 | }; |
| 280 | int ret = mipi_dsi_device_transfer(dsi, &msg); |
| 281 | |
| 282 | return (ret < 0) ? ret : 0; |
| 283 | } |
| 284 | EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size); |
| 285 | |
| 286 | /** |
| 287 | * mipi_dsi_generic_write() - transmit data using a generic write packet |
| 288 | * @dsi: DSI peripheral device |
| 289 | * @payload: buffer containing the payload |
| 290 | * @size: size of payload buffer |
| 291 | * |
| 292 | * This function will automatically choose the right data type depending on |
| 293 | * the payload length. |
| 294 | * |
| 295 | * Return: The number of bytes transmitted on success or a negative error code |
| 296 | * on failure. |
| 297 | */ |
| 298 | ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload, |
| 299 | size_t size) |
| 300 | { |
| 301 | struct mipi_dsi_msg msg = { |
| 302 | .channel = dsi->channel, |
| 303 | .tx_buf = payload, |
| 304 | .tx_len = size |
| 305 | }; |
| 306 | |
| 307 | switch (size) { |
| 308 | case 0: |
| 309 | msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM; |
| 310 | break; |
| 311 | |
| 312 | case 1: |
| 313 | msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM; |
| 314 | break; |
| 315 | |
| 316 | case 2: |
| 317 | msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM; |
| 318 | break; |
| 319 | |
| 320 | default: |
| 321 | msg.type = MIPI_DSI_GENERIC_LONG_WRITE; |
| 322 | break; |
| 323 | } |
| 324 | |
| 325 | return mipi_dsi_device_transfer(dsi, &msg); |
| 326 | } |
| 327 | EXPORT_SYMBOL(mipi_dsi_generic_write); |
| 328 | |
| 329 | /** |
| 330 | * mipi_dsi_generic_read() - receive data using a generic read packet |
| 331 | * @dsi: DSI peripheral device |
| 332 | * @params: buffer containing the request parameters |
| 333 | * @num_params: number of request parameters |
| 334 | * @data: buffer in which to return the received data |
| 335 | * @size: size of receive buffer |
| 336 | * |
| 337 | * This function will automatically choose the right data type depending on |
| 338 | * the number of parameters passed in. |
| 339 | * |
| 340 | * Return: The number of bytes successfully read or a negative error code on |
| 341 | * failure. |
| 342 | */ |
| 343 | ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params, |
| 344 | size_t num_params, void *data, size_t size) |
| 345 | { |
| 346 | struct mipi_dsi_msg msg = { |
| 347 | .channel = dsi->channel, |
| 348 | .tx_len = num_params, |
| 349 | .tx_buf = params, |
| 350 | .rx_len = size, |
| 351 | .rx_buf = data |
| 352 | }; |
| 353 | |
| 354 | switch (num_params) { |
| 355 | case 0: |
| 356 | msg.type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM; |
| 357 | break; |
| 358 | |
| 359 | case 1: |
| 360 | msg.type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM; |
| 361 | break; |
| 362 | |
| 363 | case 2: |
| 364 | msg.type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM; |
| 365 | break; |
| 366 | |
| 367 | default: |
| 368 | return -EINVAL; |
| 369 | } |
| 370 | |
| 371 | return mipi_dsi_device_transfer(dsi, &msg); |
| 372 | } |
| 373 | EXPORT_SYMBOL(mipi_dsi_generic_read); |
| 374 | |
| 375 | /** |
| 376 | * mipi_dsi_dcs_write_buffer() - transmit a DCS command with payload |
| 377 | * @dsi: DSI peripheral device |
| 378 | * @data: buffer containing data to be transmitted |
| 379 | * @len: size of transmission buffer |
| 380 | * |
| 381 | * This function will automatically choose the right data type depending on |
| 382 | * the command payload length. |
| 383 | * |
| 384 | * Return: The number of bytes successfully transmitted or a negative error |
| 385 | * code on failure. |
| 386 | */ |
| 387 | ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi, |
| 388 | const void *data, size_t len) |
| 389 | { |
| 390 | struct mipi_dsi_msg msg = { |
| 391 | .channel = dsi->channel, |
| 392 | .tx_buf = data, |
| 393 | .tx_len = len |
| 394 | }; |
| 395 | |
| 396 | switch (len) { |
| 397 | case 0: |
| 398 | return -EINVAL; |
| 399 | |
| 400 | case 1: |
| 401 | msg.type = MIPI_DSI_DCS_SHORT_WRITE; |
| 402 | break; |
| 403 | |
| 404 | case 2: |
| 405 | msg.type = MIPI_DSI_DCS_SHORT_WRITE_PARAM; |
| 406 | break; |
| 407 | |
| 408 | default: |
| 409 | msg.type = MIPI_DSI_DCS_LONG_WRITE; |
| 410 | break; |
| 411 | } |
| 412 | |
| 413 | return mipi_dsi_device_transfer(dsi, &msg); |
| 414 | } |
| 415 | EXPORT_SYMBOL(mipi_dsi_dcs_write_buffer); |
| 416 | |
| 417 | /** |
| 418 | * mipi_dsi_dcs_write() - send DCS write command |
| 419 | * @dsi: DSI peripheral device |
| 420 | * @cmd: DCS command |
| 421 | * @data: buffer containing the command payload |
| 422 | * @len: command payload length |
| 423 | * |
| 424 | * This function will automatically choose the right data type depending on |
| 425 | * the command payload length. |
| 426 | * |
| 427 | * Return: The number of bytes successfully transmitted or a negative error |
| 428 | * code on failure. |
| 429 | */ |
| 430 | ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd, |
| 431 | const void *data, size_t len) |
| 432 | { |
| 433 | ssize_t err; |
| 434 | size_t size; |
| 435 | u8 *tx; |
| 436 | |
| 437 | if (len > 0) { |
| 438 | size = 1 + len; |
| 439 | |
| 440 | tx = kmalloc(size, GFP_KERNEL); |
| 441 | if (!tx) |
| 442 | return -ENOMEM; |
| 443 | |
| 444 | /* concatenate the DCS command byte and the payload */ |
| 445 | tx[0] = cmd; |
| 446 | memcpy(&tx[1], data, len); |
| 447 | } else { |
| 448 | tx = &cmd; |
| 449 | size = 1; |
| 450 | } |
| 451 | |
| 452 | err = mipi_dsi_dcs_write_buffer(dsi, tx, size); |
| 453 | |
| 454 | if (len > 0) |
| 455 | kfree(tx); |
| 456 | |
| 457 | return err; |
| 458 | } |
| 459 | EXPORT_SYMBOL(mipi_dsi_dcs_write); |
| 460 | |
| 461 | /** |
| 462 | * mipi_dsi_dcs_read() - send DCS read request command |
| 463 | * @dsi: DSI peripheral device |
| 464 | * @cmd: DCS command |
| 465 | * @data: buffer in which to receive data |
| 466 | * @len: size of receive buffer |
| 467 | * |
| 468 | * Return: The number of bytes read or a negative error code on failure. |
| 469 | */ |
| 470 | ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data, |
| 471 | size_t len) |
| 472 | { |
| 473 | struct mipi_dsi_msg msg = { |
| 474 | .channel = dsi->channel, |
| 475 | .type = MIPI_DSI_DCS_READ, |
| 476 | .tx_buf = &cmd, |
| 477 | .tx_len = 1, |
| 478 | .rx_buf = data, |
| 479 | .rx_len = len |
| 480 | }; |
| 481 | |
| 482 | return mipi_dsi_device_transfer(dsi, &msg); |
| 483 | } |
| 484 | EXPORT_SYMBOL(mipi_dsi_dcs_read); |
| 485 | |
| 486 | /** |
| 487 | * mipi_dsi_dcs_nop() - send DCS nop packet |
| 488 | * @dsi: DSI peripheral device |
| 489 | * |
| 490 | * Return: 0 on success or a negative error code on failure. |
| 491 | */ |
| 492 | int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi) |
| 493 | { |
| 494 | ssize_t err; |
| 495 | |
| 496 | err = mipi_dsi_dcs_write(dsi, MIPI_DCS_NOP, NULL, 0); |
| 497 | if (err < 0) |
| 498 | return err; |
| 499 | |
| 500 | return 0; |
| 501 | } |
| 502 | EXPORT_SYMBOL(mipi_dsi_dcs_nop); |
| 503 | |
| 504 | /** |
| 505 | * mipi_dsi_dcs_soft_reset() - perform a software reset of the display module |
| 506 | * @dsi: DSI peripheral device |
| 507 | * |
| 508 | * Return: 0 on success or a negative error code on failure. |
| 509 | */ |
| 510 | int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi) |
| 511 | { |
| 512 | ssize_t err; |
| 513 | |
| 514 | err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SOFT_RESET, NULL, 0); |
| 515 | if (err < 0) |
| 516 | return err; |
| 517 | |
| 518 | return 0; |
| 519 | } |
| 520 | EXPORT_SYMBOL(mipi_dsi_dcs_soft_reset); |
| 521 | |
| 522 | /** |
| 523 | * mipi_dsi_dcs_get_power_mode() - query the display module's current power |
| 524 | * mode |
| 525 | * @dsi: DSI peripheral device |
| 526 | * @mode: return location for the current power mode |
| 527 | * |
| 528 | * Return: 0 on success or a negative error code on failure. |
| 529 | */ |
| 530 | int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode) |
| 531 | { |
| 532 | ssize_t err; |
| 533 | |
| 534 | err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_POWER_MODE, mode, |
| 535 | sizeof(*mode)); |
| 536 | if (err <= 0) { |
| 537 | if (err == 0) |
| 538 | err = -ENODATA; |
| 539 | |
| 540 | return err; |
| 541 | } |
| 542 | |
| 543 | return 0; |
| 544 | } |
| 545 | EXPORT_SYMBOL(mipi_dsi_dcs_get_power_mode); |
| 546 | |
| 547 | /** |
| 548 | * mipi_dsi_dcs_get_pixel_format() - gets the pixel format for the RGB image |
| 549 | * data used by the interface |
| 550 | * @dsi: DSI peripheral device |
| 551 | * @format: return location for the pixel format |
| 552 | * |
| 553 | * Return: 0 on success or a negative error code on failure. |
| 554 | */ |
| 555 | int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format) |
| 556 | { |
| 557 | ssize_t err; |
| 558 | |
| 559 | err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_PIXEL_FORMAT, format, |
| 560 | sizeof(*format)); |
| 561 | if (err <= 0) { |
| 562 | if (err == 0) |
| 563 | err = -ENODATA; |
| 564 | |
| 565 | return err; |
| 566 | } |
| 567 | |
| 568 | return 0; |
| 569 | } |
| 570 | EXPORT_SYMBOL(mipi_dsi_dcs_get_pixel_format); |
| 571 | |
| 572 | /** |
| 573 | * mipi_dsi_dcs_enter_sleep_mode() - disable all unnecessary blocks inside the |
| 574 | * display module except interface communication |
| 575 | * @dsi: DSI peripheral device |
| 576 | * |
| 577 | * Return: 0 on success or a negative error code on failure. |
| 578 | */ |
| 579 | int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi) |
| 580 | { |
| 581 | ssize_t err; |
| 582 | |
| 583 | err = mipi_dsi_dcs_write(dsi, MIPI_DCS_ENTER_SLEEP_MODE, NULL, 0); |
| 584 | if (err < 0) |
| 585 | return err; |
| 586 | |
| 587 | return 0; |
| 588 | } |
| 589 | EXPORT_SYMBOL(mipi_dsi_dcs_enter_sleep_mode); |
| 590 | |
| 591 | /** |
| 592 | * mipi_dsi_dcs_exit_sleep_mode() - enable all blocks inside the display |
| 593 | * module |
| 594 | * @dsi: DSI peripheral device |
| 595 | * |
| 596 | * Return: 0 on success or a negative error code on failure. |
| 597 | */ |
| 598 | int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi) |
| 599 | { |
| 600 | ssize_t err; |
| 601 | |
| 602 | err = mipi_dsi_dcs_write(dsi, MIPI_DCS_EXIT_SLEEP_MODE, NULL, 0); |
| 603 | if (err < 0) |
| 604 | return err; |
| 605 | |
| 606 | return 0; |
| 607 | } |
| 608 | EXPORT_SYMBOL(mipi_dsi_dcs_exit_sleep_mode); |
| 609 | |
| 610 | /** |
| 611 | * mipi_dsi_dcs_set_display_off() - stop displaying the image data on the |
| 612 | * display device |
| 613 | * @dsi: DSI peripheral device |
| 614 | * |
| 615 | * Return: 0 on success or a negative error code on failure. |
| 616 | */ |
| 617 | int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi) |
| 618 | { |
| 619 | ssize_t err; |
| 620 | |
| 621 | err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_OFF, NULL, 0); |
| 622 | if (err < 0) |
| 623 | return err; |
| 624 | |
| 625 | return 0; |
| 626 | } |
| 627 | EXPORT_SYMBOL(mipi_dsi_dcs_set_display_off); |
| 628 | |
| 629 | /** |
| 630 | * mipi_dsi_dcs_set_display_on() - start displaying the image data on the |
| 631 | * display device |
| 632 | * @dsi: DSI peripheral device |
| 633 | * |
| 634 | * Return: 0 on success or a negative error code on failure |
| 635 | */ |
| 636 | int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi) |
| 637 | { |
| 638 | ssize_t err; |
| 639 | |
| 640 | err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_ON, NULL, 0); |
| 641 | if (err < 0) |
| 642 | return err; |
| 643 | |
| 644 | return 0; |
| 645 | } |
| 646 | EXPORT_SYMBOL(mipi_dsi_dcs_set_display_on); |
| 647 | |
| 648 | /** |
| 649 | * mipi_dsi_dcs_set_column_address() - define the column extent of the frame |
| 650 | * memory accessed by the host processor |
| 651 | * @dsi: DSI peripheral device |
| 652 | * @start: first column of frame memory |
| 653 | * @end: last column of frame memory |
| 654 | * |
| 655 | * Return: 0 on success or a negative error code on failure. |
| 656 | */ |
| 657 | int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start, |
| 658 | u16 end) |
| 659 | { |
| 660 | u8 payload[4] = { start >> 8, start & 0xff, end >> 8, end & 0xff }; |
| 661 | ssize_t err; |
| 662 | |
| 663 | err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, payload, |
| 664 | sizeof(payload)); |
| 665 | if (err < 0) |
| 666 | return err; |
| 667 | |
| 668 | return 0; |
| 669 | } |
| 670 | EXPORT_SYMBOL(mipi_dsi_dcs_set_column_address); |
| 671 | |
| 672 | /** |
| 673 | * mipi_dsi_dcs_set_page_address() - define the page extent of the frame |
| 674 | * memory accessed by the host processor |
| 675 | * @dsi: DSI peripheral device |
| 676 | * @start: first page of frame memory |
| 677 | * @end: last page of frame memory |
| 678 | * |
| 679 | * Return: 0 on success or a negative error code on failure. |
| 680 | */ |
| 681 | int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start, |
| 682 | u16 end) |
| 683 | { |
| 684 | u8 payload[4] = { start >> 8, start & 0xff, end >> 8, end & 0xff }; |
| 685 | ssize_t err; |
| 686 | |
| 687 | err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PAGE_ADDRESS, payload, |
| 688 | sizeof(payload)); |
| 689 | if (err < 0) |
| 690 | return err; |
| 691 | |
| 692 | return 0; |
| 693 | } |
| 694 | EXPORT_SYMBOL(mipi_dsi_dcs_set_page_address); |
| 695 | |
| 696 | /** |
| 697 | * mipi_dsi_dcs_set_tear_off() - turn off the display module's Tearing Effect |
| 698 | * output signal on the TE signal line |
| 699 | * @dsi: DSI peripheral device |
| 700 | * |
| 701 | * Return: 0 on success or a negative error code on failure |
| 702 | */ |
| 703 | int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device *dsi) |
| 704 | { |
| 705 | ssize_t err; |
| 706 | |
| 707 | err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_OFF, NULL, 0); |
| 708 | if (err < 0) |
| 709 | return err; |
| 710 | |
| 711 | return 0; |
| 712 | } |
| 713 | EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_off); |
| 714 | |
| 715 | /** |
| 716 | * mipi_dsi_dcs_set_tear_on() - turn on the display module's Tearing Effect |
| 717 | * output signal on the TE signal line. |
| 718 | * @dsi: DSI peripheral device |
| 719 | * @mode: the Tearing Effect Output Line mode |
| 720 | * |
| 721 | * Return: 0 on success or a negative error code on failure |
| 722 | */ |
| 723 | int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi, |
| 724 | enum mipi_dsi_dcs_tear_mode mode) |
| 725 | { |
| 726 | u8 value = mode; |
| 727 | ssize_t err; |
| 728 | |
| 729 | err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_ON, &value, |
| 730 | sizeof(value)); |
| 731 | if (err < 0) |
| 732 | return err; |
| 733 | |
| 734 | return 0; |
| 735 | } |
| 736 | EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_on); |
| 737 | |
| 738 | /** |
| 739 | * mipi_dsi_dcs_set_pixel_format() - sets the pixel format for the RGB image |
| 740 | * data used by the interface |
| 741 | * @dsi: DSI peripheral device |
| 742 | * @format: pixel format |
| 743 | * |
| 744 | * Return: 0 on success or a negative error code on failure. |
| 745 | */ |
| 746 | int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format) |
| 747 | { |
| 748 | ssize_t err; |
| 749 | |
| 750 | err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PIXEL_FORMAT, &format, |
| 751 | sizeof(format)); |
| 752 | if (err < 0) |
| 753 | return err; |
| 754 | |
| 755 | return 0; |
| 756 | } |
| 757 | EXPORT_SYMBOL(mipi_dsi_dcs_set_pixel_format); |
| 758 | |
| 759 | /** |
| 760 | * mipi_dsi_dcs_set_tear_scanline() - set the scanline to use as trigger for |
| 761 | * the Tearing Effect output signal of the display module |
| 762 | * @dsi: DSI peripheral device |
| 763 | * @scanline: scanline to use as trigger |
| 764 | * |
| 765 | * Return: 0 on success or a negative error code on failure |
| 766 | */ |
| 767 | int mipi_dsi_dcs_set_tear_scanline(struct mipi_dsi_device *dsi, u16 scanline) |
| 768 | { |
| 769 | u8 payload[3] = { MIPI_DCS_SET_TEAR_SCANLINE, scanline >> 8, |
| 770 | scanline & 0xff }; |
| 771 | ssize_t err; |
| 772 | |
| 773 | err = mipi_dsi_generic_write(dsi, payload, sizeof(payload)); |
| 774 | if (err < 0) |
| 775 | return err; |
| 776 | |
| 777 | return 0; |
| 778 | } |
| 779 | EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_scanline); |
| 780 | |
| 781 | /** |
| 782 | * mipi_dsi_dcs_set_display_brightness() - sets the brightness value of the |
| 783 | * display |
| 784 | * @dsi: DSI peripheral device |
| 785 | * @brightness: brightness value |
| 786 | * |
| 787 | * Return: 0 on success or a negative error code on failure. |
| 788 | */ |
| 789 | int mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device *dsi, |
| 790 | u16 brightness) |
| 791 | { |
| 792 | u8 payload[2] = { brightness & 0xff, brightness >> 8 }; |
| 793 | ssize_t err; |
| 794 | |
| 795 | err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_BRIGHTNESS, |
| 796 | payload, sizeof(payload)); |
| 797 | if (err < 0) |
| 798 | return err; |
| 799 | |
| 800 | return 0; |
| 801 | } |
| 802 | EXPORT_SYMBOL(mipi_dsi_dcs_set_display_brightness); |
| 803 | |
| 804 | /** |
| 805 | * mipi_dsi_dcs_get_display_brightness() - gets the current brightness value |
| 806 | * of the display |
| 807 | * @dsi: DSI peripheral device |
| 808 | * @brightness: brightness value |
| 809 | * |
| 810 | * Return: 0 on success or a negative error code on failure. |
| 811 | */ |
| 812 | int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi, |
| 813 | u16 *brightness) |
| 814 | { |
| 815 | ssize_t err; |
| 816 | |
| 817 | err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_DISPLAY_BRIGHTNESS, |
| 818 | brightness, sizeof(*brightness)); |
| 819 | if (err <= 0) { |
| 820 | if (err == 0) |
| 821 | err = -ENODATA; |
| 822 | |
| 823 | return err; |
| 824 | } |
| 825 | |
| 826 | return 0; |
| 827 | } |
| 828 | EXPORT_SYMBOL(mipi_dsi_dcs_get_display_brightness); |