1 /* 2 * MIPI DSI Bus 3 * 4 * Copyright (C) 2012-2013, Samsung Electronics, Co., Ltd. 5 * Andrzej Hajda <a.hajda@samsung.com> 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and associated documentation files (the 9 * "Software"), to deal in the Software without restriction, including 10 * without limitation the rights to use, copy, modify, merge, publish, 11 * distribute, sub license, and/or sell copies of the Software, and to 12 * permit persons to whom the Software is furnished to do so, subject to 13 * the following conditions: 14 * 15 * The above copyright notice and this permission notice (including the 16 * next paragraph) shall be included in all copies or substantial portions 17 * of the Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 22 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 23 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 24 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 25 * USE OR OTHER DEALINGS IN THE SOFTWARE. 26 */ 27 28 #include <drm/drmP.h> 29 #include <drm/drm_mipi_dsi.h> 30 31 #include <linux/device.h> 32 #include <linux/module.h> 33 #include <linux/slab.h> 34 35 #include <video/mipi_display.h> 36 37 /** 38 * DOC: dsi helpers 39 * 40 * These functions contain some common logic and helpers to deal with MIPI DSI 41 * peripherals. 42 * 43 * Helpers are provided for a number of standard MIPI DSI command as well as a 44 * subset of the MIPI DCS command set. 45 */ 46 47 #if 0 48 static int mipi_dsi_device_match(struct device *dev, struct device_driver *drv) 49 { 50 return of_driver_match_device(dev, drv); 51 } 52 53 static const struct dev_pm_ops mipi_dsi_device_pm_ops = { 54 .runtime_suspend = pm_generic_runtime_suspend, 55 .runtime_resume = pm_generic_runtime_resume, 56 .suspend = pm_generic_suspend, 57 .resume = pm_generic_resume, 58 .freeze = pm_generic_freeze, 59 .thaw = pm_generic_thaw, 60 .poweroff = pm_generic_poweroff, 61 .restore = pm_generic_restore, 62 }; 63 64 static struct bus_type mipi_dsi_bus_type = { 65 .name = "mipi-dsi", 66 .match = mipi_dsi_device_match, 67 .pm = &mipi_dsi_device_pm_ops, 68 }; 69 70 static int of_device_match(struct device *dev, void *data) 71 { 72 return dev->of_node == data; 73 } 74 75 /** 76 * of_find_mipi_dsi_device_by_node() - find the MIPI DSI device matching a 77 * device tree node 78 * @np: device tree node 79 * 80 * Return: A pointer to the MIPI DSI device corresponding to @np or NULL if no 81 * such device exists (or has not been registered yet). 82 */ 83 struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np) 84 { 85 struct device *dev; 86 87 dev = bus_find_device(&mipi_dsi_bus_type, NULL, np, of_device_match); 88 89 return dev ? to_mipi_dsi_device(dev) : NULL; 90 } 91 EXPORT_SYMBOL(of_find_mipi_dsi_device_by_node); 92 93 static void mipi_dsi_dev_release(struct device *dev) 94 { 95 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev); 96 97 of_node_put(dev->of_node); 98 kfree(dsi); 99 } 100 101 static const struct device_type mipi_dsi_device_type = { 102 .release = mipi_dsi_dev_release, 103 }; 104 105 static struct mipi_dsi_device *mipi_dsi_device_alloc(struct mipi_dsi_host *host) 106 { 107 struct mipi_dsi_device *dsi; 108 109 dsi = kzalloc(sizeof(*dsi), GFP_KERNEL); 110 if (!dsi) 111 return ERR_PTR(-ENOMEM); 112 113 dsi->host = host; 114 dsi->dev.bus = &mipi_dsi_bus_type; 115 dsi->dev.parent = host->dev; 116 dsi->dev.type = &mipi_dsi_device_type; 117 118 device_initialize(&dsi->dev); 119 120 return dsi; 121 } 122 123 static int mipi_dsi_device_add(struct mipi_dsi_device *dsi) 124 { 125 struct mipi_dsi_host *host = dsi->host; 126 127 dev_set_name(&dsi->dev, "%s.%d", dev_name(host->dev), dsi->channel); 128 129 return device_add(&dsi->dev); 130 } 131 132 static struct mipi_dsi_device * 133 of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node) 134 { 135 struct mipi_dsi_device *dsi; 136 struct device *dev = host->dev; 137 int ret; 138 u32 reg; 139 140 ret = of_property_read_u32(node, "reg", ®); 141 if (ret) { 142 dev_err(dev, "device node %s has no valid reg property: %d\n", 143 node->full_name, ret); 144 return ERR_PTR(-EINVAL); 145 } 146 147 if (reg > 3) { 148 dev_err(dev, "device node %s has invalid reg property: %u\n", 149 node->full_name, reg); 150 return ERR_PTR(-EINVAL); 151 } 152 153 dsi = mipi_dsi_device_alloc(host); 154 if (IS_ERR(dsi)) { 155 dev_err(dev, "failed to allocate DSI device %s: %ld\n", 156 node->full_name, PTR_ERR(dsi)); 157 return dsi; 158 } 159 160 dsi->dev.of_node = of_node_get(node); 161 dsi->channel = reg; 162 163 ret = mipi_dsi_device_add(dsi); 164 if (ret) { 165 dev_err(dev, "failed to add DSI device %s: %d\n", 166 node->full_name, ret); 167 kfree(dsi); 168 return ERR_PTR(ret); 169 } 170 171 return dsi; 172 } 173 174 int mipi_dsi_host_register(struct mipi_dsi_host *host) 175 { 176 struct device_node *node; 177 178 for_each_available_child_of_node(host->dev->of_node, node) { 179 /* skip nodes without reg property */ 180 if (!of_find_property(node, "reg", NULL)) 181 continue; 182 of_mipi_dsi_device_add(host, node); 183 } 184 185 return 0; 186 } 187 EXPORT_SYMBOL(mipi_dsi_host_register); 188 189 static int mipi_dsi_remove_device_fn(struct device *dev, void *priv) 190 { 191 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev); 192 193 device_unregister(&dsi->dev); 194 195 return 0; 196 } 197 198 void mipi_dsi_host_unregister(struct mipi_dsi_host *host) 199 { 200 device_for_each_child(host->dev, NULL, mipi_dsi_remove_device_fn); 201 } 202 EXPORT_SYMBOL(mipi_dsi_host_unregister); 203 #endif 204 205 /** 206 * mipi_dsi_attach - attach a DSI device to its DSI host 207 * @dsi: DSI peripheral 208 */ 209 int mipi_dsi_attach(struct mipi_dsi_device *dsi) 210 { 211 const struct mipi_dsi_host_ops *ops = dsi->host->ops; 212 213 if (!ops || !ops->attach) 214 return -ENOSYS; 215 216 return ops->attach(dsi->host, dsi); 217 } 218 EXPORT_SYMBOL(mipi_dsi_attach); 219 220 /** 221 * mipi_dsi_detach - detach a DSI device from its DSI host 222 * @dsi: DSI peripheral 223 */ 224 int mipi_dsi_detach(struct mipi_dsi_device *dsi) 225 { 226 const struct mipi_dsi_host_ops *ops = dsi->host->ops; 227 228 if (!ops || !ops->detach) 229 return -ENOSYS; 230 231 return ops->detach(dsi->host, dsi); 232 } 233 EXPORT_SYMBOL(mipi_dsi_detach); 234 235 static ssize_t mipi_dsi_device_transfer(struct mipi_dsi_device *dsi, 236 struct mipi_dsi_msg *msg) 237 { 238 const struct mipi_dsi_host_ops *ops = dsi->host->ops; 239 240 if (!ops || !ops->transfer) 241 return -ENOSYS; 242 243 if (dsi->mode_flags & MIPI_DSI_MODE_LPM) 244 msg->flags |= MIPI_DSI_MSG_USE_LPM; 245 246 return ops->transfer(dsi->host, msg); 247 } 248 249 /** 250 * mipi_dsi_packet_format_is_short - check if a packet is of the short format 251 * @type: MIPI DSI data type of the packet 252 * 253 * Return: true if the packet for the given data type is a short packet, false 254 * otherwise. 255 */ 256 bool mipi_dsi_packet_format_is_short(u8 type) 257 { 258 switch (type) { 259 case MIPI_DSI_V_SYNC_START: 260 case MIPI_DSI_V_SYNC_END: 261 case MIPI_DSI_H_SYNC_START: 262 case MIPI_DSI_H_SYNC_END: 263 case MIPI_DSI_END_OF_TRANSMISSION: 264 case MIPI_DSI_COLOR_MODE_OFF: 265 case MIPI_DSI_COLOR_MODE_ON: 266 case MIPI_DSI_SHUTDOWN_PERIPHERAL: 267 case MIPI_DSI_TURN_ON_PERIPHERAL: 268 case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM: 269 case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM: 270 case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM: 271 case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM: 272 case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM: 273 case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM: 274 case MIPI_DSI_DCS_SHORT_WRITE: 275 case MIPI_DSI_DCS_SHORT_WRITE_PARAM: 276 case MIPI_DSI_DCS_READ: 277 case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE: 278 return true; 279 } 280 281 return false; 282 } 283 EXPORT_SYMBOL(mipi_dsi_packet_format_is_short); 284 285 /** 286 * mipi_dsi_packet_format_is_long - check if a packet is of the long format 287 * @type: MIPI DSI data type of the packet 288 * 289 * Return: true if the packet for the given data type is a long packet, false 290 * otherwise. 291 */ 292 bool mipi_dsi_packet_format_is_long(u8 type) 293 { 294 switch (type) { 295 case MIPI_DSI_NULL_PACKET: 296 case MIPI_DSI_BLANKING_PACKET: 297 case MIPI_DSI_GENERIC_LONG_WRITE: 298 case MIPI_DSI_DCS_LONG_WRITE: 299 case MIPI_DSI_LOOSELY_PACKED_PIXEL_STREAM_YCBCR20: 300 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR24: 301 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16: 302 case MIPI_DSI_PACKED_PIXEL_STREAM_30: 303 case MIPI_DSI_PACKED_PIXEL_STREAM_36: 304 case MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12: 305 case MIPI_DSI_PACKED_PIXEL_STREAM_16: 306 case MIPI_DSI_PACKED_PIXEL_STREAM_18: 307 case MIPI_DSI_PIXEL_STREAM_3BYTE_18: 308 case MIPI_DSI_PACKED_PIXEL_STREAM_24: 309 return true; 310 } 311 312 return false; 313 } 314 EXPORT_SYMBOL(mipi_dsi_packet_format_is_long); 315 316 /** 317 * mipi_dsi_create_packet - create a packet from a message according to the 318 * DSI protocol 319 * @packet: pointer to a DSI packet structure 320 * @msg: message to translate into a packet 321 * 322 * Return: 0 on success or a negative error code on failure. 323 */ 324 int mipi_dsi_create_packet(struct mipi_dsi_packet *packet, 325 const struct mipi_dsi_msg *msg) 326 { 327 if (!packet || !msg) 328 return -EINVAL; 329 330 /* do some minimum sanity checking */ 331 if (!mipi_dsi_packet_format_is_short(msg->type) && 332 !mipi_dsi_packet_format_is_long(msg->type)) 333 return -EINVAL; 334 335 if (msg->channel > 3) 336 return -EINVAL; 337 338 memset(packet, 0, sizeof(*packet)); 339 packet->header[0] = ((msg->channel & 0x3) << 6) | (msg->type & 0x3f); 340 341 /* TODO: compute ECC if hardware support is not available */ 342 343 /* 344 * Long write packets contain the word count in header bytes 1 and 2. 345 * The payload follows the header and is word count bytes long. 346 * 347 * Short write packets encode up to two parameters in header bytes 1 348 * and 2. 349 */ 350 if (mipi_dsi_packet_format_is_long(msg->type)) { 351 packet->header[1] = (msg->tx_len >> 0) & 0xff; 352 packet->header[2] = (msg->tx_len >> 8) & 0xff; 353 354 packet->payload_length = msg->tx_len; 355 packet->payload = msg->tx_buf; 356 } else { 357 const u8 *tx = msg->tx_buf; 358 359 packet->header[1] = (msg->tx_len > 0) ? tx[0] : 0; 360 packet->header[2] = (msg->tx_len > 1) ? tx[1] : 0; 361 } 362 363 packet->size = sizeof(packet->header) + packet->payload_length; 364 365 return 0; 366 } 367 EXPORT_SYMBOL(mipi_dsi_create_packet); 368 369 /** 370 * mipi_dsi_shutdown_peripheral() - sends a Shutdown Peripheral command 371 * @dsi: DSI peripheral device 372 * 373 * Return: 0 on success or a negative error code on failure. 374 */ 375 int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi) 376 { 377 struct mipi_dsi_msg msg = { 378 .channel = dsi->channel, 379 .type = MIPI_DSI_SHUTDOWN_PERIPHERAL, 380 .tx_buf = (u8 [2]) { 0, 0 }, 381 .tx_len = 2, 382 }; 383 384 return mipi_dsi_device_transfer(dsi, &msg); 385 } 386 EXPORT_SYMBOL(mipi_dsi_shutdown_peripheral); 387 388 /** 389 * mipi_dsi_turn_on_peripheral() - sends a Turn On Peripheral command 390 * @dsi: DSI peripheral device 391 * 392 * Return: 0 on success or a negative error code on failure. 393 */ 394 int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi) 395 { 396 struct mipi_dsi_msg msg = { 397 .channel = dsi->channel, 398 .type = MIPI_DSI_TURN_ON_PERIPHERAL, 399 .tx_buf = (u8 [2]) { 0, 0 }, 400 .tx_len = 2, 401 }; 402 403 return mipi_dsi_device_transfer(dsi, &msg); 404 } 405 EXPORT_SYMBOL(mipi_dsi_turn_on_peripheral); 406 407 #if 0 408 /* 409 * mipi_dsi_set_maximum_return_packet_size() - specify the maximum size of the 410 * the payload in a long packet transmitted from the peripheral back to the 411 * host processor 412 * @dsi: DSI peripheral device 413 * @value: the maximum size of the payload 414 * 415 * Return: 0 on success or a negative error code on failure. 416 */ 417 int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi, 418 u16 value) 419 { 420 u8 tx[2] = { value & 0xff, value >> 8 }; 421 struct mipi_dsi_msg msg = { 422 .channel = dsi->channel, 423 .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, 424 .tx_len = sizeof(tx), 425 .tx_buf = tx, 426 }; 427 428 return mipi_dsi_device_transfer(dsi, &msg); 429 } 430 EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size); 431 #endif 432 433 /** 434 * mipi_dsi_generic_write() - transmit data using a generic write packet 435 * @dsi: DSI peripheral device 436 * @payload: buffer containing the payload 437 * @size: size of payload buffer 438 * 439 * This function will automatically choose the right data type depending on 440 * the payload length. 441 * 442 * Return: The number of bytes transmitted on success or a negative error code 443 * on failure. 444 */ 445 ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload, 446 size_t size) 447 { 448 struct mipi_dsi_msg msg = { 449 .channel = dsi->channel, 450 .tx_buf = payload, 451 .tx_len = size 452 }; 453 454 switch (size) { 455 case 0: 456 msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM; 457 break; 458 459 case 1: 460 msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM; 461 break; 462 463 case 2: 464 msg.type = MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM; 465 break; 466 467 default: 468 msg.type = MIPI_DSI_GENERIC_LONG_WRITE; 469 break; 470 } 471 472 return mipi_dsi_device_transfer(dsi, &msg); 473 } 474 EXPORT_SYMBOL(mipi_dsi_generic_write); 475 476 /** 477 * mipi_dsi_generic_read() - receive data using a generic read packet 478 * @dsi: DSI peripheral device 479 * @params: buffer containing the request parameters 480 * @num_params: number of request parameters 481 * @data: buffer in which to return the received data 482 * @size: size of receive buffer 483 * 484 * This function will automatically choose the right data type depending on 485 * the number of parameters passed in. 486 * 487 * Return: The number of bytes successfully read or a negative error code on 488 * failure. 489 */ 490 ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params, 491 size_t num_params, void *data, size_t size) 492 { 493 struct mipi_dsi_msg msg = { 494 .channel = dsi->channel, 495 .tx_len = num_params, 496 .tx_buf = params, 497 .rx_len = size, 498 .rx_buf = data 499 }; 500 501 switch (num_params) { 502 case 0: 503 msg.type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM; 504 break; 505 506 case 1: 507 msg.type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM; 508 break; 509 510 case 2: 511 msg.type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM; 512 break; 513 514 default: 515 return -EINVAL; 516 } 517 518 return mipi_dsi_device_transfer(dsi, &msg); 519 } 520 EXPORT_SYMBOL(mipi_dsi_generic_read); 521 522 /** 523 * mipi_dsi_dcs_write_buffer() - transmit a DCS command with payload 524 * @dsi: DSI peripheral device 525 * @data: buffer containing data to be transmitted 526 * @len: size of transmission buffer 527 * 528 * This function will automatically choose the right data type depending on 529 * the command payload length. 530 * 531 * Return: The number of bytes successfully transmitted or a negative error 532 * code on failure. 533 */ 534 ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi, 535 const void *data, size_t len) 536 { 537 struct mipi_dsi_msg msg = { 538 .channel = dsi->channel, 539 .tx_buf = data, 540 .tx_len = len 541 }; 542 543 switch (len) { 544 case 0: 545 return -EINVAL; 546 547 case 1: 548 msg.type = MIPI_DSI_DCS_SHORT_WRITE; 549 break; 550 551 case 2: 552 msg.type = MIPI_DSI_DCS_SHORT_WRITE_PARAM; 553 break; 554 555 default: 556 msg.type = MIPI_DSI_DCS_LONG_WRITE; 557 break; 558 } 559 560 return mipi_dsi_device_transfer(dsi, &msg); 561 } 562 EXPORT_SYMBOL(mipi_dsi_dcs_write_buffer); 563 564 #if 0 565 /** 566 * mipi_dsi_dcs_write() - send DCS write command 567 * @dsi: DSI peripheral device 568 * @cmd: DCS command 569 * @data: buffer containing the command payload 570 * @len: command payload length 571 * 572 * This function will automatically choose the right data type depending on 573 * the command payload length. 574 * 575 * Return: The number of bytes successfully transmitted or a negative error 576 * code on failure. 577 */ 578 ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd, 579 const void *data, size_t len) 580 { 581 ssize_t err; 582 size_t size; 583 u8 *tx; 584 585 if (len > 0) { 586 size = 1 + len; 587 588 tx = kmalloc(size, GFP_KERNEL); 589 if (!tx) 590 return -ENOMEM; 591 592 /* concatenate the DCS command byte and the payload */ 593 tx[0] = cmd; 594 memcpy(&tx[1], data, len); 595 } else { 596 tx = &cmd; 597 size = 1; 598 } 599 600 err = mipi_dsi_dcs_write_buffer(dsi, tx, size); 601 602 if (len > 0) 603 kfree(tx); 604 605 return err; 606 } 607 EXPORT_SYMBOL(mipi_dsi_dcs_write); 608 #endif 609 610 /** 611 * mipi_dsi_dcs_read() - send DCS read request command 612 * @dsi: DSI peripheral device 613 * @cmd: DCS command 614 * @data: buffer in which to receive data 615 * @len: size of receive buffer 616 * 617 * Return: The number of bytes read or a negative error code on failure. 618 */ 619 ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data, 620 size_t len) 621 { 622 struct mipi_dsi_msg msg = { 623 .channel = dsi->channel, 624 .type = MIPI_DSI_DCS_READ, 625 .tx_buf = &cmd, 626 .tx_len = 1, 627 .rx_buf = data, 628 .rx_len = len 629 }; 630 631 return mipi_dsi_device_transfer(dsi, &msg); 632 } 633 EXPORT_SYMBOL(mipi_dsi_dcs_read); 634 635 #if 0 636 /** 637 * mipi_dsi_dcs_nop() - send DCS nop packet 638 * @dsi: DSI peripheral device 639 * 640 * Return: 0 on success or a negative error code on failure. 641 */ 642 int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi) 643 { 644 ssize_t err; 645 646 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_NOP, NULL, 0); 647 if (err < 0) 648 return err; 649 650 return 0; 651 } 652 EXPORT_SYMBOL(mipi_dsi_dcs_nop); 653 654 /** 655 * mipi_dsi_dcs_soft_reset() - perform a software reset of the display module 656 * @dsi: DSI peripheral device 657 * 658 * Return: 0 on success or a negative error code on failure. 659 */ 660 int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi) 661 { 662 ssize_t err; 663 664 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SOFT_RESET, NULL, 0); 665 if (err < 0) 666 return err; 667 668 return 0; 669 } 670 EXPORT_SYMBOL(mipi_dsi_dcs_soft_reset); 671 672 /** 673 * mipi_dsi_dcs_get_power_mode() - query the display module's current power 674 * mode 675 * @dsi: DSI peripheral device 676 * @mode: return location for the current power mode 677 * 678 * Return: 0 on success or a negative error code on failure. 679 */ 680 int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode) 681 { 682 ssize_t err; 683 684 err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_POWER_MODE, mode, 685 sizeof(*mode)); 686 if (err <= 0) { 687 if (err == 0) 688 err = -ENODATA; 689 690 return err; 691 } 692 693 return 0; 694 } 695 EXPORT_SYMBOL(mipi_dsi_dcs_get_power_mode); 696 697 /** 698 * mipi_dsi_dcs_get_pixel_format() - gets the pixel format for the RGB image 699 * data used by the interface 700 * @dsi: DSI peripheral device 701 * @format: return location for the pixel format 702 * 703 * Return: 0 on success or a negative error code on failure. 704 */ 705 int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format) 706 { 707 ssize_t err; 708 709 err = mipi_dsi_dcs_read(dsi, MIPI_DCS_GET_PIXEL_FORMAT, format, 710 sizeof(*format)); 711 if (err <= 0) { 712 if (err == 0) 713 err = -ENODATA; 714 715 return err; 716 } 717 718 return 0; 719 } 720 EXPORT_SYMBOL(mipi_dsi_dcs_get_pixel_format); 721 722 /** 723 * mipi_dsi_dcs_enter_sleep_mode() - disable all unnecessary blocks inside the 724 * display module except interface communication 725 * @dsi: DSI peripheral device 726 * 727 * Return: 0 on success or a negative error code on failure. 728 */ 729 int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi) 730 { 731 ssize_t err; 732 733 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_ENTER_SLEEP_MODE, NULL, 0); 734 if (err < 0) 735 return err; 736 737 return 0; 738 } 739 EXPORT_SYMBOL(mipi_dsi_dcs_enter_sleep_mode); 740 741 /** 742 * mipi_dsi_dcs_exit_sleep_mode() - enable all blocks inside the display 743 * module 744 * @dsi: DSI peripheral device 745 * 746 * Return: 0 on success or a negative error code on failure. 747 */ 748 int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi) 749 { 750 ssize_t err; 751 752 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_EXIT_SLEEP_MODE, NULL, 0); 753 if (err < 0) 754 return err; 755 756 return 0; 757 } 758 EXPORT_SYMBOL(mipi_dsi_dcs_exit_sleep_mode); 759 760 /** 761 * mipi_dsi_dcs_set_display_off() - stop displaying the image data on the 762 * display device 763 * @dsi: DSI peripheral device 764 * 765 * Return: 0 on success or a negative error code on failure. 766 */ 767 int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi) 768 { 769 ssize_t err; 770 771 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_OFF, NULL, 0); 772 if (err < 0) 773 return err; 774 775 return 0; 776 } 777 EXPORT_SYMBOL(mipi_dsi_dcs_set_display_off); 778 779 /** 780 * mipi_dsi_dcs_set_display_on() - start displaying the image data on the 781 * display device 782 * @dsi: DSI peripheral device 783 * 784 * Return: 0 on success or a negative error code on failure 785 */ 786 int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi) 787 { 788 ssize_t err; 789 790 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_ON, NULL, 0); 791 if (err < 0) 792 return err; 793 794 return 0; 795 } 796 EXPORT_SYMBOL(mipi_dsi_dcs_set_display_on); 797 798 /** 799 * mipi_dsi_dcs_set_column_address() - define the column extent of the frame 800 * memory accessed by the host processor 801 * @dsi: DSI peripheral device 802 * @start: first column of frame memory 803 * @end: last column of frame memory 804 * 805 * Return: 0 on success or a negative error code on failure. 806 */ 807 int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start, 808 u16 end) 809 { 810 u8 payload[4] = { start >> 8, start & 0xff, end >> 8, end & 0xff }; 811 ssize_t err; 812 813 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, payload, 814 sizeof(payload)); 815 if (err < 0) 816 return err; 817 818 return 0; 819 } 820 EXPORT_SYMBOL(mipi_dsi_dcs_set_column_address); 821 822 /** 823 * mipi_dsi_dcs_set_page_address() - define the page extent of the frame 824 * memory accessed by the host processor 825 * @dsi: DSI peripheral device 826 * @start: first page of frame memory 827 * @end: last page of frame memory 828 * 829 * Return: 0 on success or a negative error code on failure. 830 */ 831 int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start, 832 u16 end) 833 { 834 u8 payload[4] = { start >> 8, start & 0xff, end >> 8, end & 0xff }; 835 ssize_t err; 836 837 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PAGE_ADDRESS, payload, 838 sizeof(payload)); 839 if (err < 0) 840 return err; 841 842 return 0; 843 } 844 EXPORT_SYMBOL(mipi_dsi_dcs_set_page_address); 845 846 /** 847 * mipi_dsi_dcs_set_tear_off() - turn off the display module's Tearing Effect 848 * output signal on the TE signal line 849 * @dsi: DSI peripheral device 850 * 851 * Return: 0 on success or a negative error code on failure 852 */ 853 int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device *dsi) 854 { 855 ssize_t err; 856 857 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_OFF, NULL, 0); 858 if (err < 0) 859 return err; 860 861 return 0; 862 } 863 EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_off); 864 865 /** 866 * mipi_dsi_dcs_set_tear_on() - turn on the display module's Tearing Effect 867 * output signal on the TE signal line. 868 * @dsi: DSI peripheral device 869 * @mode: the Tearing Effect Output Line mode 870 * 871 * Return: 0 on success or a negative error code on failure 872 */ 873 int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi, 874 enum mipi_dsi_dcs_tear_mode mode) 875 { 876 u8 value = mode; 877 ssize_t err; 878 879 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_ON, &value, 880 sizeof(value)); 881 if (err < 0) 882 return err; 883 884 return 0; 885 } 886 EXPORT_SYMBOL(mipi_dsi_dcs_set_tear_on); 887 888 /** 889 * mipi_dsi_dcs_set_pixel_format() - sets the pixel format for the RGB image 890 * data used by the interface 891 * @dsi: DSI peripheral device 892 * @format: pixel format 893 * 894 * Return: 0 on success or a negative error code on failure. 895 */ 896 int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format) 897 { 898 ssize_t err; 899 900 err = mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PIXEL_FORMAT, &format, 901 sizeof(format)); 902 if (err < 0) 903 return err; 904 905 return 0; 906 } 907 EXPORT_SYMBOL(mipi_dsi_dcs_set_pixel_format); 908 909 static int mipi_dsi_drv_probe(struct device *dev) 910 { 911 struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver); 912 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev); 913 914 return drv->probe(dsi); 915 } 916 917 static int mipi_dsi_drv_remove(struct device *dev) 918 { 919 struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver); 920 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev); 921 922 return drv->remove(dsi); 923 } 924 925 static void mipi_dsi_drv_shutdown(struct device *dev) 926 { 927 struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver); 928 struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev); 929 930 drv->shutdown(dsi); 931 } 932 933 /** 934 * mipi_dsi_driver_register_full() - register a driver for DSI devices 935 * @drv: DSI driver structure 936 * @owner: owner module 937 * 938 * Return: 0 on success or a negative error code on failure. 939 */ 940 int mipi_dsi_driver_register_full(struct mipi_dsi_driver *drv, 941 struct module *owner) 942 { 943 drv->driver.bus = &mipi_dsi_bus_type; 944 drv->driver.owner = owner; 945 946 if (drv->probe) 947 drv->driver.probe = mipi_dsi_drv_probe; 948 if (drv->remove) 949 drv->driver.remove = mipi_dsi_drv_remove; 950 if (drv->shutdown) 951 drv->driver.shutdown = mipi_dsi_drv_shutdown; 952 953 return driver_register(&drv->driver); 954 } 955 EXPORT_SYMBOL(mipi_dsi_driver_register_full); 956 957 /** 958 * mipi_dsi_driver_unregister() - unregister a driver for DSI devices 959 * @drv: DSI driver structure 960 * 961 * Return: 0 on success or a negative error code on failure. 962 */ 963 void mipi_dsi_driver_unregister(struct mipi_dsi_driver *drv) 964 { 965 driver_unregister(&drv->driver); 966 } 967 EXPORT_SYMBOL(mipi_dsi_driver_unregister); 968 969 static int __init mipi_dsi_bus_init(void) 970 { 971 return bus_register(&mipi_dsi_bus_type); 972 } 973 postcore_initcall(mipi_dsi_bus_init); 974 #endif 975 976 MODULE_AUTHOR("Andrzej Hajda <a.hajda@samsung.com>"); 977 MODULE_DESCRIPTION("MIPI DSI Bus"); 978