1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (c) 2019, Huaqin Telecom Technology Co., Ltd 4 * 5 * Author: Jerry Han <jerry.han.hq@gmail.com> 6 * 7 */ 8 9 #include <linux/delay.h> 10 #include <linux/kernel.h> 11 #include <linux/module.h> 12 #include <linux/of.h> 13 #include <linux/of_device.h> 14 15 #include <linux/gpio/consumer.h> 16 #include <linux/regulator/consumer.h> 17 18 #include <drm/drm_device.h> 19 #include <drm/drm_mipi_dsi.h> 20 #include <drm/drm_modes.h> 21 #include <drm/drm_panel.h> 22 #include <drm/drm_print.h> 23 24 #include <video/mipi_display.h> 25 26 struct panel_cmd { 27 char cmd; 28 char data; 29 }; 30 31 struct panel_desc { 32 const struct drm_display_mode *display_mode; 33 unsigned int bpc; 34 unsigned int width_mm; 35 unsigned int height_mm; 36 37 unsigned long mode_flags; 38 enum mipi_dsi_pixel_format format; 39 unsigned int lanes; 40 const struct panel_cmd *on_cmds; 41 unsigned int on_cmds_num; 42 }; 43 44 struct panel_info { 45 struct drm_panel base; 46 struct mipi_dsi_device *link; 47 const struct panel_desc *desc; 48 49 struct gpio_desc *enable_gpio; 50 struct gpio_desc *pp33_gpio; 51 struct gpio_desc *pp18_gpio; 52 53 bool prepared; 54 bool enabled; 55 }; 56 57 static inline struct panel_info *to_panel_info(struct drm_panel *panel) 58 { 59 return container_of(panel, struct panel_info, base); 60 } 61 62 static void disable_gpios(struct panel_info *pinfo) 63 { 64 gpiod_set_value(pinfo->enable_gpio, 0); 65 gpiod_set_value(pinfo->pp33_gpio, 0); 66 gpiod_set_value(pinfo->pp18_gpio, 0); 67 } 68 69 static int send_mipi_cmds(struct drm_panel *panel, const struct panel_cmd *cmds) 70 { 71 struct panel_info *pinfo = to_panel_info(panel); 72 unsigned int i = 0; 73 int err; 74 75 for (i = 0; i < pinfo->desc->on_cmds_num; i++) { 76 err = mipi_dsi_dcs_write_buffer(pinfo->link, &cmds[i], 77 sizeof(struct panel_cmd)); 78 79 if (err < 0) 80 return err; 81 } 82 83 return 0; 84 } 85 86 static int boe_panel_disable(struct drm_panel *panel) 87 { 88 struct panel_info *pinfo = to_panel_info(panel); 89 int err; 90 91 if (!pinfo->enabled) 92 return 0; 93 94 err = mipi_dsi_dcs_set_display_off(pinfo->link); 95 if (err < 0) { 96 DRM_DEV_ERROR(panel->dev, "failed to set display off: %d\n", 97 err); 98 return err; 99 } 100 101 pinfo->enabled = false; 102 103 return 0; 104 } 105 106 static int boe_panel_unprepare(struct drm_panel *panel) 107 { 108 struct panel_info *pinfo = to_panel_info(panel); 109 int err; 110 111 if (!pinfo->prepared) 112 return 0; 113 114 err = mipi_dsi_dcs_set_display_off(pinfo->link); 115 if (err < 0) 116 DRM_DEV_ERROR(panel->dev, "failed to set display off: %d\n", 117 err); 118 119 err = mipi_dsi_dcs_enter_sleep_mode(pinfo->link); 120 if (err < 0) 121 DRM_DEV_ERROR(panel->dev, "failed to enter sleep mode: %d\n", 122 err); 123 124 /* sleep_mode_delay: 1ms - 2ms */ 125 usleep_range(1000, 2000); 126 127 disable_gpios(pinfo); 128 129 pinfo->prepared = false; 130 131 return 0; 132 } 133 134 static int boe_panel_prepare(struct drm_panel *panel) 135 { 136 struct panel_info *pinfo = to_panel_info(panel); 137 int err; 138 139 if (pinfo->prepared) 140 return 0; 141 142 gpiod_set_value(pinfo->pp18_gpio, 1); 143 /* T1: 5ms - 6ms */ 144 usleep_range(5000, 6000); 145 gpiod_set_value(pinfo->pp33_gpio, 1); 146 147 /* reset sequence */ 148 /* T2: 14ms - 15ms */ 149 usleep_range(14000, 15000); 150 gpiod_set_value(pinfo->enable_gpio, 1); 151 152 /* T3: 1ms - 2ms */ 153 usleep_range(1000, 2000); 154 gpiod_set_value(pinfo->enable_gpio, 0); 155 156 /* T4: 1ms - 2ms */ 157 usleep_range(1000, 2000); 158 gpiod_set_value(pinfo->enable_gpio, 1); 159 160 /* T5: 5ms - 6ms */ 161 usleep_range(5000, 6000); 162 163 /* send init code */ 164 err = send_mipi_cmds(panel, pinfo->desc->on_cmds); 165 if (err < 0) { 166 DRM_DEV_ERROR(panel->dev, "failed to send DCS Init Code: %d\n", 167 err); 168 goto poweroff; 169 } 170 171 err = mipi_dsi_dcs_exit_sleep_mode(pinfo->link); 172 if (err < 0) { 173 DRM_DEV_ERROR(panel->dev, "failed to exit sleep mode: %d\n", 174 err); 175 goto poweroff; 176 } 177 178 /* T6: 120ms - 121ms */ 179 usleep_range(120000, 121000); 180 181 err = mipi_dsi_dcs_set_display_on(pinfo->link); 182 if (err < 0) { 183 DRM_DEV_ERROR(panel->dev, "failed to set display on: %d\n", 184 err); 185 goto poweroff; 186 } 187 188 /* T7: 20ms - 21ms */ 189 usleep_range(20000, 21000); 190 191 pinfo->prepared = true; 192 193 return 0; 194 195 poweroff: 196 disable_gpios(pinfo); 197 return err; 198 } 199 200 static int boe_panel_enable(struct drm_panel *panel) 201 { 202 struct panel_info *pinfo = to_panel_info(panel); 203 int ret; 204 205 if (pinfo->enabled) 206 return 0; 207 208 usleep_range(120000, 121000); 209 210 ret = mipi_dsi_dcs_set_display_on(pinfo->link); 211 if (ret < 0) { 212 DRM_DEV_ERROR(panel->dev, "failed to set display on: %d\n", 213 ret); 214 return ret; 215 } 216 217 pinfo->enabled = true; 218 219 return 0; 220 } 221 222 static int boe_panel_get_modes(struct drm_panel *panel, 223 struct drm_connector *connector) 224 { 225 struct panel_info *pinfo = to_panel_info(panel); 226 const struct drm_display_mode *m = pinfo->desc->display_mode; 227 struct drm_display_mode *mode; 228 229 mode = drm_mode_duplicate(connector->dev, m); 230 if (!mode) { 231 DRM_DEV_ERROR(pinfo->base.dev, "failed to add mode %ux%u@%u\n", 232 m->hdisplay, m->vdisplay, drm_mode_vrefresh(m)); 233 return -ENOMEM; 234 } 235 236 drm_mode_set_name(mode); 237 238 drm_mode_probed_add(connector, mode); 239 240 connector->display_info.width_mm = pinfo->desc->width_mm; 241 connector->display_info.height_mm = pinfo->desc->height_mm; 242 connector->display_info.bpc = pinfo->desc->bpc; 243 244 return 1; 245 } 246 247 static const struct drm_panel_funcs panel_funcs = { 248 .disable = boe_panel_disable, 249 .unprepare = boe_panel_unprepare, 250 .prepare = boe_panel_prepare, 251 .enable = boe_panel_enable, 252 .get_modes = boe_panel_get_modes, 253 }; 254 255 static const struct drm_display_mode default_display_mode = { 256 .clock = 159420, 257 .hdisplay = 1200, 258 .hsync_start = 1200 + 80, 259 .hsync_end = 1200 + 80 + 60, 260 .htotal = 1200 + 80 + 60 + 24, 261 .vdisplay = 1920, 262 .vsync_start = 1920 + 10, 263 .vsync_end = 1920 + 10 + 14, 264 .vtotal = 1920 + 10 + 14 + 4, 265 }; 266 267 /* 8 inch */ 268 static const struct panel_cmd boe_himax8279d8p_on_cmds[] = { 269 { 0xB0, 0x05 }, 270 { 0xB1, 0xE5 }, 271 { 0xB3, 0x52 }, 272 { 0xC0, 0x00 }, 273 { 0xC2, 0x57 }, 274 { 0xD9, 0x85 }, 275 { 0xB0, 0x01 }, 276 { 0xC8, 0x00 }, 277 { 0xC9, 0x00 }, 278 { 0xCC, 0x26 }, 279 { 0xCD, 0x26 }, 280 { 0xDC, 0x00 }, 281 { 0xDD, 0x00 }, 282 { 0xE0, 0x26 }, 283 { 0xE1, 0x26 }, 284 { 0xB0, 0x03 }, 285 { 0xC3, 0x2A }, 286 { 0xE7, 0x2A }, 287 { 0xC5, 0x2A }, 288 { 0xDE, 0x2A }, 289 { 0xBC, 0x02 }, 290 { 0xCB, 0x02 }, 291 { 0xB0, 0x00 }, 292 { 0xB6, 0x03 }, 293 { 0xBA, 0x8B }, 294 { 0xBF, 0x15 }, 295 { 0xC0, 0x18 }, 296 { 0xC2, 0x14 }, 297 { 0xC3, 0x02 }, 298 { 0xC4, 0x14 }, 299 { 0xC5, 0x02 }, 300 { 0xCC, 0x0A }, 301 { 0xB0, 0x06 }, 302 { 0xC0, 0xA5 }, 303 { 0xD5, 0x20 }, 304 { 0xC0, 0x00 }, 305 { 0xB0, 0x02 }, 306 { 0xC0, 0x00 }, 307 { 0xC1, 0x02 }, 308 { 0xC2, 0x06 }, 309 { 0xC3, 0x16 }, 310 { 0xC4, 0x0E }, 311 { 0xC5, 0x18 }, 312 { 0xC6, 0x26 }, 313 { 0xC7, 0x32 }, 314 { 0xC8, 0x3F }, 315 { 0xC9, 0x3F }, 316 { 0xCA, 0x3F }, 317 { 0xCB, 0x3F }, 318 { 0xCC, 0x3D }, 319 { 0xCD, 0x2F }, 320 { 0xCE, 0x2F }, 321 { 0xCF, 0x2F }, 322 { 0xD0, 0x07 }, 323 { 0xD2, 0x00 }, 324 { 0xD3, 0x02 }, 325 { 0xD4, 0x06 }, 326 { 0xD5, 0x12 }, 327 { 0xD6, 0x0A }, 328 { 0xD7, 0x14 }, 329 { 0xD8, 0x22 }, 330 { 0xD9, 0x2E }, 331 { 0xDA, 0x3D }, 332 { 0xDB, 0x3F }, 333 { 0xDC, 0x3F }, 334 { 0xDD, 0x3F }, 335 { 0xDE, 0x3D }, 336 { 0xDF, 0x2F }, 337 { 0xE0, 0x2F }, 338 { 0xE1, 0x2F }, 339 { 0xE2, 0x07 }, 340 { 0xB0, 0x07 }, 341 { 0xB1, 0x18 }, 342 { 0xB2, 0x19 }, 343 { 0xB3, 0x2E }, 344 { 0xB4, 0x52 }, 345 { 0xB5, 0x72 }, 346 { 0xB6, 0x8C }, 347 { 0xB7, 0xBD }, 348 { 0xB8, 0xEB }, 349 { 0xB9, 0x47 }, 350 { 0xBA, 0x96 }, 351 { 0xBB, 0x1E }, 352 { 0xBC, 0x90 }, 353 { 0xBD, 0x93 }, 354 { 0xBE, 0xFA }, 355 { 0xBF, 0x56 }, 356 { 0xC0, 0x8C }, 357 { 0xC1, 0xB7 }, 358 { 0xC2, 0xCC }, 359 { 0xC3, 0xDF }, 360 { 0xC4, 0xE8 }, 361 { 0xC5, 0xF0 }, 362 { 0xC6, 0xF8 }, 363 { 0xC7, 0xFA }, 364 { 0xC8, 0xFC }, 365 { 0xC9, 0x00 }, 366 { 0xCA, 0x00 }, 367 { 0xCB, 0x5A }, 368 { 0xCC, 0xAF }, 369 { 0xCD, 0xFF }, 370 { 0xCE, 0xFF }, 371 { 0xB0, 0x08 }, 372 { 0xB1, 0x04 }, 373 { 0xB2, 0x15 }, 374 { 0xB3, 0x2D }, 375 { 0xB4, 0x51 }, 376 { 0xB5, 0x72 }, 377 { 0xB6, 0x8D }, 378 { 0xB7, 0xBE }, 379 { 0xB8, 0xED }, 380 { 0xB9, 0x4A }, 381 { 0xBA, 0x9A }, 382 { 0xBB, 0x23 }, 383 { 0xBC, 0x95 }, 384 { 0xBD, 0x98 }, 385 { 0xBE, 0xFF }, 386 { 0xBF, 0x59 }, 387 { 0xC0, 0x8E }, 388 { 0xC1, 0xB9 }, 389 { 0xC2, 0xCD }, 390 { 0xC3, 0xDF }, 391 { 0xC4, 0xE8 }, 392 { 0xC5, 0xF0 }, 393 { 0xC6, 0xF8 }, 394 { 0xC7, 0xFA }, 395 { 0xC8, 0xFC }, 396 { 0xC9, 0x00 }, 397 { 0xCA, 0x00 }, 398 { 0xCB, 0x5A }, 399 { 0xCC, 0xAF }, 400 { 0xCD, 0xFF }, 401 { 0xCE, 0xFF }, 402 { 0xB0, 0x09 }, 403 { 0xB1, 0x04 }, 404 { 0xB2, 0x2C }, 405 { 0xB3, 0x36 }, 406 { 0xB4, 0x53 }, 407 { 0xB5, 0x73 }, 408 { 0xB6, 0x8E }, 409 { 0xB7, 0xC0 }, 410 { 0xB8, 0xEF }, 411 { 0xB9, 0x4C }, 412 { 0xBA, 0x9D }, 413 { 0xBB, 0x25 }, 414 { 0xBC, 0x96 }, 415 { 0xBD, 0x9A }, 416 { 0xBE, 0x01 }, 417 { 0xBF, 0x59 }, 418 { 0xC0, 0x8E }, 419 { 0xC1, 0xB9 }, 420 { 0xC2, 0xCD }, 421 { 0xC3, 0xDF }, 422 { 0xC4, 0xE8 }, 423 { 0xC5, 0xF0 }, 424 { 0xC6, 0xF8 }, 425 { 0xC7, 0xFA }, 426 { 0xC8, 0xFC }, 427 { 0xC9, 0x00 }, 428 { 0xCA, 0x00 }, 429 { 0xCB, 0x5A }, 430 { 0xCC, 0xBF }, 431 { 0xCD, 0xFF }, 432 { 0xCE, 0xFF }, 433 { 0xB0, 0x0A }, 434 { 0xB1, 0x18 }, 435 { 0xB2, 0x19 }, 436 { 0xB3, 0x2E }, 437 { 0xB4, 0x52 }, 438 { 0xB5, 0x72 }, 439 { 0xB6, 0x8C }, 440 { 0xB7, 0xBD }, 441 { 0xB8, 0xEB }, 442 { 0xB9, 0x47 }, 443 { 0xBA, 0x96 }, 444 { 0xBB, 0x1E }, 445 { 0xBC, 0x90 }, 446 { 0xBD, 0x93 }, 447 { 0xBE, 0xFA }, 448 { 0xBF, 0x56 }, 449 { 0xC0, 0x8C }, 450 { 0xC1, 0xB7 }, 451 { 0xC2, 0xCC }, 452 { 0xC3, 0xDF }, 453 { 0xC4, 0xE8 }, 454 { 0xC5, 0xF0 }, 455 { 0xC6, 0xF8 }, 456 { 0xC7, 0xFA }, 457 { 0xC8, 0xFC }, 458 { 0xC9, 0x00 }, 459 { 0xCA, 0x00 }, 460 { 0xCB, 0x5A }, 461 { 0xCC, 0xAF }, 462 { 0xCD, 0xFF }, 463 { 0xCE, 0xFF }, 464 { 0xB0, 0x0B }, 465 { 0xB1, 0x04 }, 466 { 0xB2, 0x15 }, 467 { 0xB3, 0x2D }, 468 { 0xB4, 0x51 }, 469 { 0xB5, 0x72 }, 470 { 0xB6, 0x8D }, 471 { 0xB7, 0xBE }, 472 { 0xB8, 0xED }, 473 { 0xB9, 0x4A }, 474 { 0xBA, 0x9A }, 475 { 0xBB, 0x23 }, 476 { 0xBC, 0x95 }, 477 { 0xBD, 0x98 }, 478 { 0xBE, 0xFF }, 479 { 0xBF, 0x59 }, 480 { 0xC0, 0x8E }, 481 { 0xC1, 0xB9 }, 482 { 0xC2, 0xCD }, 483 { 0xC3, 0xDF }, 484 { 0xC4, 0xE8 }, 485 { 0xC5, 0xF0 }, 486 { 0xC6, 0xF8 }, 487 { 0xC7, 0xFA }, 488 { 0xC8, 0xFC }, 489 { 0xC9, 0x00 }, 490 { 0xCA, 0x00 }, 491 { 0xCB, 0x5A }, 492 { 0xCC, 0xAF }, 493 { 0xCD, 0xFF }, 494 { 0xCE, 0xFF }, 495 { 0xB0, 0x0C }, 496 { 0xB1, 0x04 }, 497 { 0xB2, 0x2C }, 498 { 0xB3, 0x36 }, 499 { 0xB4, 0x53 }, 500 { 0xB5, 0x73 }, 501 { 0xB6, 0x8E }, 502 { 0xB7, 0xC0 }, 503 { 0xB8, 0xEF }, 504 { 0xB9, 0x4C }, 505 { 0xBA, 0x9D }, 506 { 0xBB, 0x25 }, 507 { 0xBC, 0x96 }, 508 { 0xBD, 0x9A }, 509 { 0xBE, 0x01 }, 510 { 0xBF, 0x59 }, 511 { 0xC0, 0x8E }, 512 { 0xC1, 0xB9 }, 513 { 0xC2, 0xCD }, 514 { 0xC3, 0xDF }, 515 { 0xC4, 0xE8 }, 516 { 0xC5, 0xF0 }, 517 { 0xC6, 0xF8 }, 518 { 0xC7, 0xFA }, 519 { 0xC8, 0xFC }, 520 { 0xC9, 0x00 }, 521 { 0xCA, 0x00 }, 522 { 0xCB, 0x5A }, 523 { 0xCC, 0xBF }, 524 { 0xCD, 0xFF }, 525 { 0xCE, 0xFF }, 526 { 0xB0, 0x04 }, 527 { 0xB5, 0x02 }, 528 { 0xB6, 0x01 }, 529 }; 530 531 static const struct panel_desc boe_himax8279d8p_panel_desc = { 532 .display_mode = &default_display_mode, 533 .bpc = 8, 534 .width_mm = 107, 535 .height_mm = 172, 536 .mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE | 537 MIPI_DSI_CLOCK_NON_CONTINUOUS | MIPI_DSI_MODE_LPM, 538 .format = MIPI_DSI_FMT_RGB888, 539 .lanes = 4, 540 .on_cmds = boe_himax8279d8p_on_cmds, 541 .on_cmds_num = 260, 542 }; 543 544 /* 10 inch */ 545 static const struct panel_cmd boe_himax8279d10p_on_cmds[] = { 546 { 0xB0, 0x05 }, 547 { 0xB1, 0xE5 }, 548 { 0xB3, 0x52 }, 549 { 0xB0, 0x00 }, 550 { 0xB6, 0x03 }, 551 { 0xBA, 0x8B }, 552 { 0xBF, 0x1A }, 553 { 0xC0, 0x0F }, 554 { 0xC2, 0x0C }, 555 { 0xC3, 0x02 }, 556 { 0xC4, 0x0C }, 557 { 0xC5, 0x02 }, 558 { 0xB0, 0x01 }, 559 { 0xE0, 0x26 }, 560 { 0xE1, 0x26 }, 561 { 0xDC, 0x00 }, 562 { 0xDD, 0x00 }, 563 { 0xCC, 0x26 }, 564 { 0xCD, 0x26 }, 565 { 0xC8, 0x00 }, 566 { 0xC9, 0x00 }, 567 { 0xD2, 0x03 }, 568 { 0xD3, 0x03 }, 569 { 0xE6, 0x04 }, 570 { 0xE7, 0x04 }, 571 { 0xC4, 0x09 }, 572 { 0xC5, 0x09 }, 573 { 0xD8, 0x0A }, 574 { 0xD9, 0x0A }, 575 { 0xC2, 0x0B }, 576 { 0xC3, 0x0B }, 577 { 0xD6, 0x0C }, 578 { 0xD7, 0x0C }, 579 { 0xC0, 0x05 }, 580 { 0xC1, 0x05 }, 581 { 0xD4, 0x06 }, 582 { 0xD5, 0x06 }, 583 { 0xCA, 0x07 }, 584 { 0xCB, 0x07 }, 585 { 0xDE, 0x08 }, 586 { 0xDF, 0x08 }, 587 { 0xB0, 0x02 }, 588 { 0xC0, 0x00 }, 589 { 0xC1, 0x0D }, 590 { 0xC2, 0x17 }, 591 { 0xC3, 0x26 }, 592 { 0xC4, 0x31 }, 593 { 0xC5, 0x1C }, 594 { 0xC6, 0x2C }, 595 { 0xC7, 0x33 }, 596 { 0xC8, 0x31 }, 597 { 0xC9, 0x37 }, 598 { 0xCA, 0x37 }, 599 { 0xCB, 0x37 }, 600 { 0xCC, 0x39 }, 601 { 0xCD, 0x2E }, 602 { 0xCE, 0x2F }, 603 { 0xCF, 0x2F }, 604 { 0xD0, 0x07 }, 605 { 0xD2, 0x00 }, 606 { 0xD3, 0x0D }, 607 { 0xD4, 0x17 }, 608 { 0xD5, 0x26 }, 609 { 0xD6, 0x31 }, 610 { 0xD7, 0x3F }, 611 { 0xD8, 0x3F }, 612 { 0xD9, 0x3F }, 613 { 0xDA, 0x3F }, 614 { 0xDB, 0x37 }, 615 { 0xDC, 0x37 }, 616 { 0xDD, 0x37 }, 617 { 0xDE, 0x39 }, 618 { 0xDF, 0x2E }, 619 { 0xE0, 0x2F }, 620 { 0xE1, 0x2F }, 621 { 0xE2, 0x07 }, 622 { 0xB0, 0x03 }, 623 { 0xC8, 0x0B }, 624 { 0xC9, 0x07 }, 625 { 0xC3, 0x00 }, 626 { 0xE7, 0x00 }, 627 { 0xC5, 0x2A }, 628 { 0xDE, 0x2A }, 629 { 0xCA, 0x43 }, 630 { 0xC9, 0x07 }, 631 { 0xE4, 0xC0 }, 632 { 0xE5, 0x0D }, 633 { 0xCB, 0x01 }, 634 { 0xBC, 0x01 }, 635 { 0xB0, 0x06 }, 636 { 0xB8, 0xA5 }, 637 { 0xC0, 0xA5 }, 638 { 0xC7, 0x0F }, 639 { 0xD5, 0x32 }, 640 { 0xB8, 0x00 }, 641 { 0xC0, 0x00 }, 642 { 0xBC, 0x00 }, 643 { 0xB0, 0x07 }, 644 { 0xB1, 0x00 }, 645 { 0xB2, 0x05 }, 646 { 0xB3, 0x10 }, 647 { 0xB4, 0x22 }, 648 { 0xB5, 0x36 }, 649 { 0xB6, 0x4A }, 650 { 0xB7, 0x6C }, 651 { 0xB8, 0x9A }, 652 { 0xB9, 0xD7 }, 653 { 0xBA, 0x17 }, 654 { 0xBB, 0x92 }, 655 { 0xBC, 0x15 }, 656 { 0xBD, 0x18 }, 657 { 0xBE, 0x8C }, 658 { 0xBF, 0x00 }, 659 { 0xC0, 0x3A }, 660 { 0xC1, 0x72 }, 661 { 0xC2, 0x8C }, 662 { 0xC3, 0xA5 }, 663 { 0xC4, 0xB1 }, 664 { 0xC5, 0xBE }, 665 { 0xC6, 0xCA }, 666 { 0xC7, 0xD1 }, 667 { 0xC8, 0xD4 }, 668 { 0xC9, 0x00 }, 669 { 0xCA, 0x00 }, 670 { 0xCB, 0x16 }, 671 { 0xCC, 0xAF }, 672 { 0xCD, 0xFF }, 673 { 0xCE, 0xFF }, 674 { 0xB0, 0x08 }, 675 { 0xB1, 0x04 }, 676 { 0xB2, 0x05 }, 677 { 0xB3, 0x11 }, 678 { 0xB4, 0x24 }, 679 { 0xB5, 0x39 }, 680 { 0xB6, 0x4E }, 681 { 0xB7, 0x72 }, 682 { 0xB8, 0xA3 }, 683 { 0xB9, 0xE1 }, 684 { 0xBA, 0x25 }, 685 { 0xBB, 0xA8 }, 686 { 0xBC, 0x2E }, 687 { 0xBD, 0x32 }, 688 { 0xBE, 0xAD }, 689 { 0xBF, 0x28 }, 690 { 0xC0, 0x63 }, 691 { 0xC1, 0x9B }, 692 { 0xC2, 0xB5 }, 693 { 0xC3, 0xCF }, 694 { 0xC4, 0xDB }, 695 { 0xC5, 0xE8 }, 696 { 0xC6, 0xF5 }, 697 { 0xC7, 0xFA }, 698 { 0xC8, 0xFC }, 699 { 0xC9, 0x00 }, 700 { 0xCA, 0x00 }, 701 { 0xCB, 0x16 }, 702 { 0xCC, 0xAF }, 703 { 0xCD, 0xFF }, 704 { 0xCE, 0xFF }, 705 { 0xB0, 0x09 }, 706 { 0xB1, 0x04 }, 707 { 0xB2, 0x04 }, 708 { 0xB3, 0x0F }, 709 { 0xB4, 0x22 }, 710 { 0xB5, 0x37 }, 711 { 0xB6, 0x4D }, 712 { 0xB7, 0x71 }, 713 { 0xB8, 0xA2 }, 714 { 0xB9, 0xE1 }, 715 { 0xBA, 0x26 }, 716 { 0xBB, 0xA9 }, 717 { 0xBC, 0x2F }, 718 { 0xBD, 0x33 }, 719 { 0xBE, 0xAC }, 720 { 0xBF, 0x24 }, 721 { 0xC0, 0x5D }, 722 { 0xC1, 0x94 }, 723 { 0xC2, 0xAC }, 724 { 0xC3, 0xC5 }, 725 { 0xC4, 0xD1 }, 726 { 0xC5, 0xDC }, 727 { 0xC6, 0xE8 }, 728 { 0xC7, 0xED }, 729 { 0xC8, 0xF0 }, 730 { 0xC9, 0x00 }, 731 { 0xCA, 0x00 }, 732 { 0xCB, 0x16 }, 733 { 0xCC, 0xAF }, 734 { 0xCD, 0xFF }, 735 { 0xCE, 0xFF }, 736 { 0xB0, 0x0A }, 737 { 0xB1, 0x00 }, 738 { 0xB2, 0x05 }, 739 { 0xB3, 0x10 }, 740 { 0xB4, 0x22 }, 741 { 0xB5, 0x36 }, 742 { 0xB6, 0x4A }, 743 { 0xB7, 0x6C }, 744 { 0xB8, 0x9A }, 745 { 0xB9, 0xD7 }, 746 { 0xBA, 0x17 }, 747 { 0xBB, 0x92 }, 748 { 0xBC, 0x15 }, 749 { 0xBD, 0x18 }, 750 { 0xBE, 0x8C }, 751 { 0xBF, 0x00 }, 752 { 0xC0, 0x3A }, 753 { 0xC1, 0x72 }, 754 { 0xC2, 0x8C }, 755 { 0xC3, 0xA5 }, 756 { 0xC4, 0xB1 }, 757 { 0xC5, 0xBE }, 758 { 0xC6, 0xCA }, 759 { 0xC7, 0xD1 }, 760 { 0xC8, 0xD4 }, 761 { 0xC9, 0x00 }, 762 { 0xCA, 0x00 }, 763 { 0xCB, 0x16 }, 764 { 0xCC, 0xAF }, 765 { 0xCD, 0xFF }, 766 { 0xCE, 0xFF }, 767 { 0xB0, 0x0B }, 768 { 0xB1, 0x04 }, 769 { 0xB2, 0x05 }, 770 { 0xB3, 0x11 }, 771 { 0xB4, 0x24 }, 772 { 0xB5, 0x39 }, 773 { 0xB6, 0x4E }, 774 { 0xB7, 0x72 }, 775 { 0xB8, 0xA3 }, 776 { 0xB9, 0xE1 }, 777 { 0xBA, 0x25 }, 778 { 0xBB, 0xA8 }, 779 { 0xBC, 0x2E }, 780 { 0xBD, 0x32 }, 781 { 0xBE, 0xAD }, 782 { 0xBF, 0x28 }, 783 { 0xC0, 0x63 }, 784 { 0xC1, 0x9B }, 785 { 0xC2, 0xB5 }, 786 { 0xC3, 0xCF }, 787 { 0xC4, 0xDB }, 788 { 0xC5, 0xE8 }, 789 { 0xC6, 0xF5 }, 790 { 0xC7, 0xFA }, 791 { 0xC8, 0xFC }, 792 { 0xC9, 0x00 }, 793 { 0xCA, 0x00 }, 794 { 0xCB, 0x16 }, 795 { 0xCC, 0xAF }, 796 { 0xCD, 0xFF }, 797 { 0xCE, 0xFF }, 798 { 0xB0, 0x0C }, 799 { 0xB1, 0x04 }, 800 { 0xB2, 0x04 }, 801 { 0xB3, 0x0F }, 802 { 0xB4, 0x22 }, 803 { 0xB5, 0x37 }, 804 { 0xB6, 0x4D }, 805 { 0xB7, 0x71 }, 806 { 0xB8, 0xA2 }, 807 { 0xB9, 0xE1 }, 808 { 0xBA, 0x26 }, 809 { 0xBB, 0xA9 }, 810 { 0xBC, 0x2F }, 811 { 0xBD, 0x33 }, 812 { 0xBE, 0xAC }, 813 { 0xBF, 0x24 }, 814 { 0xC0, 0x5D }, 815 { 0xC1, 0x94 }, 816 { 0xC2, 0xAC }, 817 { 0xC3, 0xC5 }, 818 { 0xC4, 0xD1 }, 819 { 0xC5, 0xDC }, 820 { 0xC6, 0xE8 }, 821 { 0xC7, 0xED }, 822 { 0xC8, 0xF0 }, 823 { 0xC9, 0x00 }, 824 { 0xCA, 0x00 }, 825 { 0xCB, 0x16 }, 826 { 0xCC, 0xAF }, 827 { 0xCD, 0xFF }, 828 { 0xCE, 0xFF }, 829 }; 830 831 static const struct panel_desc boe_himax8279d10p_panel_desc = { 832 .display_mode = &default_display_mode, 833 .bpc = 8, 834 .width_mm = 135, 835 .height_mm = 216, 836 .mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE | 837 MIPI_DSI_CLOCK_NON_CONTINUOUS | MIPI_DSI_MODE_LPM, 838 .format = MIPI_DSI_FMT_RGB888, 839 .lanes = 4, 840 .on_cmds = boe_himax8279d10p_on_cmds, 841 .on_cmds_num = 283, 842 }; 843 844 static const struct of_device_id panel_of_match[] = { 845 { 846 .compatible = "boe,himax8279d8p", 847 .data = &boe_himax8279d8p_panel_desc, 848 }, 849 { 850 .compatible = "boe,himax8279d10p", 851 .data = &boe_himax8279d10p_panel_desc, 852 }, 853 { 854 /* sentinel */ 855 } 856 }; 857 MODULE_DEVICE_TABLE(of, panel_of_match); 858 859 static int panel_add(struct panel_info *pinfo) 860 { 861 struct device *dev = &pinfo->link->dev; 862 int ret; 863 864 pinfo->pp18_gpio = devm_gpiod_get(dev, "pp18", GPIOD_OUT_HIGH); 865 if (IS_ERR(pinfo->pp18_gpio)) { 866 ret = PTR_ERR(pinfo->pp18_gpio); 867 if (ret != -EPROBE_DEFER) 868 DRM_DEV_ERROR(dev, "failed to get pp18 gpio: %d\n", 869 ret); 870 return ret; 871 } 872 873 pinfo->pp33_gpio = devm_gpiod_get(dev, "pp33", GPIOD_OUT_HIGH); 874 if (IS_ERR(pinfo->pp33_gpio)) { 875 ret = PTR_ERR(pinfo->pp33_gpio); 876 if (ret != -EPROBE_DEFER) 877 DRM_DEV_ERROR(dev, "failed to get pp33 gpio: %d\n", 878 ret); 879 return ret; 880 } 881 882 pinfo->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH); 883 if (IS_ERR(pinfo->enable_gpio)) { 884 ret = PTR_ERR(pinfo->enable_gpio); 885 if (ret != -EPROBE_DEFER) 886 DRM_DEV_ERROR(dev, "failed to get enable gpio: %d\n", 887 ret); 888 return ret; 889 } 890 891 drm_panel_init(&pinfo->base, dev, &panel_funcs, 892 DRM_MODE_CONNECTOR_DSI); 893 894 ret = drm_panel_of_backlight(&pinfo->base); 895 if (ret) 896 return ret; 897 898 return drm_panel_add(&pinfo->base); 899 } 900 901 static int panel_probe(struct mipi_dsi_device *dsi) 902 { 903 struct panel_info *pinfo; 904 const struct panel_desc *desc; 905 int err; 906 907 pinfo = devm_kzalloc(&dsi->dev, sizeof(*pinfo), GFP_KERNEL); 908 if (!pinfo) 909 return -ENOMEM; 910 911 desc = of_device_get_match_data(&dsi->dev); 912 dsi->mode_flags = desc->mode_flags; 913 dsi->format = desc->format; 914 dsi->lanes = desc->lanes; 915 pinfo->desc = desc; 916 917 pinfo->link = dsi; 918 mipi_dsi_set_drvdata(dsi, pinfo); 919 920 err = panel_add(pinfo); 921 if (err < 0) 922 return err; 923 924 err = mipi_dsi_attach(dsi); 925 if (err < 0) 926 drm_panel_remove(&pinfo->base); 927 928 return err; 929 } 930 931 static int panel_remove(struct mipi_dsi_device *dsi) 932 { 933 struct panel_info *pinfo = mipi_dsi_get_drvdata(dsi); 934 int err; 935 936 err = boe_panel_disable(&pinfo->base); 937 if (err < 0) 938 DRM_DEV_ERROR(&dsi->dev, "failed to disable panel: %d\n", 939 err); 940 941 err = boe_panel_unprepare(&pinfo->base); 942 if (err < 0) 943 DRM_DEV_ERROR(&dsi->dev, "failed to unprepare panel: %d\n", 944 err); 945 946 err = mipi_dsi_detach(dsi); 947 if (err < 0) 948 DRM_DEV_ERROR(&dsi->dev, "failed to detach from DSI host: %d\n", 949 err); 950 951 drm_panel_remove(&pinfo->base); 952 953 return 0; 954 } 955 956 static void panel_shutdown(struct mipi_dsi_device *dsi) 957 { 958 struct panel_info *pinfo = mipi_dsi_get_drvdata(dsi); 959 960 boe_panel_disable(&pinfo->base); 961 boe_panel_unprepare(&pinfo->base); 962 } 963 964 static struct mipi_dsi_driver panel_driver = { 965 .driver = { 966 .name = "panel-boe-himax8279d", 967 .of_match_table = panel_of_match, 968 }, 969 .probe = panel_probe, 970 .remove = panel_remove, 971 .shutdown = panel_shutdown, 972 }; 973 module_mipi_dsi_driver(panel_driver); 974 975 MODULE_AUTHOR("Jerry Han <jerry.han.hq@gmail.com>"); 976 MODULE_DESCRIPTION("Boe Himax8279d driver"); 977 MODULE_LICENSE("GPL v2"); 978