1/* 2 * Taal DSI command mode panel 3 * 4 * Copyright (C) 2009 Nokia Corporation 5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com> 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License version 2 as published by 9 * the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 * more details. 15 * 16 * You should have received a copy of the GNU General Public License along with 17 * this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20/*#define DEBUG*/ 21 22#include <linux/module.h> 23#include <linux/delay.h> 24#include <linux/err.h> 25#include <linux/jiffies.h> 26#include <linux/sched.h> 27#include <linux/backlight.h> 28#include <linux/fb.h> 29#include <linux/interrupt.h> 30#include <linux/gpio.h> 31#include <linux/workqueue.h> 32#include <linux/slab.h> 33#include <linux/regulator/consumer.h> 34#include <linux/mutex.h> 35 36#include <plat/display.h> 37#include <plat/nokia-dsi-panel.h> 38 39/* DSI Virtual channel. Hardcoded for now. */ 40#define TCH 0 41 42#define DCS_READ_NUM_ERRORS 0x05 43#define DCS_READ_POWER_MODE 0x0a 44#define DCS_READ_MADCTL 0x0b 45#define DCS_READ_PIXEL_FORMAT 0x0c 46#define DCS_RDDSDR 0x0f 47#define DCS_SLEEP_IN 0x10 48#define DCS_SLEEP_OUT 0x11 49#define DCS_DISPLAY_OFF 0x28 50#define DCS_DISPLAY_ON 0x29 51#define DCS_COLUMN_ADDR 0x2a 52#define DCS_PAGE_ADDR 0x2b 53#define DCS_MEMORY_WRITE 0x2c 54#define DCS_TEAR_OFF 0x34 55#define DCS_TEAR_ON 0x35 56#define DCS_MEM_ACC_CTRL 0x36 57#define DCS_PIXEL_FORMAT 0x3a 58#define DCS_BRIGHTNESS 0x51 59#define DCS_CTRL_DISPLAY 0x53 60#define DCS_WRITE_CABC 0x55 61#define DCS_READ_CABC 0x56 62#define DCS_GET_ID1 0xda 63#define DCS_GET_ID2 0xdb 64#define DCS_GET_ID3 0xdc 65 66#define TAAL_ESD_CHECK_PERIOD msecs_to_jiffies(5000) 67 68static irqreturn_t taal_te_isr(int irq, void *data); 69static void taal_te_timeout_work_callback(struct work_struct *work); 70static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable); 71 72struct panel_regulator { 73 struct regulator *regulator; 74 const char *name; 75 int min_uV; 76 int max_uV; 77}; 78 79static void free_regulators(struct panel_regulator *regulators, int n) 80{ 81 int i; 82 83 for (i = 0; i < n; i++) { 84 /* disable/put in reverse order */ 85 regulator_disable(regulators[n - i - 1].regulator); 86 regulator_put(regulators[n - i - 1].regulator); 87 } 88} 89 90static int init_regulators(struct omap_dss_device *dssdev, 91 struct panel_regulator *regulators, int n) 92{ 93 int r, i, v; 94 95 for (i = 0; i < n; i++) { 96 struct regulator *reg; 97 98 reg = regulator_get(&dssdev->dev, regulators[i].name); 99 if (IS_ERR(reg)) { 100 dev_err(&dssdev->dev, "failed to get regulator %s\n", 101 regulators[i].name); 102 r = PTR_ERR(reg); 103 goto err; 104 } 105 106 v = regulator_get_voltage(reg); 107 if (v < regulators[i].min_uV || v > regulators[i].max_uV) { 108 r = regulator_set_voltage(reg, regulators[i].min_uV, 109 regulators[i].max_uV); 110 if (r) { 111 dev_err(&dssdev->dev, 112 "failed to set regulator %s voltage\n", 113 regulators[i].name); 114 regulator_put(reg); 115 goto err; 116 } 117 } 118 119 r = regulator_enable(reg); 120 if (r) { 121 dev_err(&dssdev->dev, "failed to enable regulator %s\n", 122 regulators[i].name); 123 regulator_put(reg); 124 goto err; 125 } 126 127 regulators[i].regulator = reg; 128 } 129 130 return 0; 131 132err: 133 free_regulators(regulators, i); 134 135 return r; 136} 137 138/** 139 * struct panel_config - panel configuration 140 * @name: panel name 141 * @type: panel type 142 * @timings: panel resolution 143 * @sleep: various panel specific delays, passed to msleep() if non-zero 144 * @reset_sequence: reset sequence timings, passed to udelay() if non-zero 145 * @regulators: array of panel regulators 146 * @num_regulators: number of regulators in the array 147 */ 148struct panel_config { 149 const char *name; 150 int type; 151 152 struct omap_video_timings timings; 153 154 struct { 155 unsigned int sleep_in; 156 unsigned int sleep_out; 157 unsigned int hw_reset; 158 unsigned int enable_te; 159 } sleep; 160 161 struct { 162 unsigned int high; 163 unsigned int low; 164 } reset_sequence; 165 166 struct panel_regulator *regulators; 167 int num_regulators; 168}; 169 170enum { 171 PANEL_TAAL, 172}; 173 174static struct panel_config panel_configs[] = { 175 { 176 .name = "taal", 177 .type = PANEL_TAAL, 178 .timings = { 179 .x_res = 864, 180 .y_res = 480, 181 }, 182 .sleep = { 183 .sleep_in = 5, 184 .sleep_out = 5, 185 .hw_reset = 5, 186 .enable_te = 100, /* possible panel bug */ 187 }, 188 .reset_sequence = { 189 .high = 10, 190 .low = 10, 191 }, 192 }, 193}; 194 195struct taal_data { 196 struct mutex lock; 197 198 struct backlight_device *bldev; 199 200 unsigned long hw_guard_end; /* next value of jiffies when we can 201 * issue the next sleep in/out command 202 */ 203 unsigned long hw_guard_wait; /* max guard time in jiffies */ 204 205 struct omap_dss_device *dssdev; 206 207 bool enabled; 208 u8 rotate; 209 bool mirror; 210 211 bool te_enabled; 212 213 atomic_t do_update; 214 struct { 215 u16 x; 216 u16 y; 217 u16 w; 218 u16 h; 219 } update_region; 220 struct delayed_work te_timeout_work; 221 222 bool use_dsi_bl; 223 224 bool cabc_broken; 225 unsigned cabc_mode; 226 227 bool intro_printed; 228 229 struct workqueue_struct *esd_wq; 230 struct delayed_work esd_work; 231 232 struct panel_config *panel_config; 233}; 234 235static inline struct nokia_dsi_panel_data 236*get_panel_data(const struct omap_dss_device *dssdev) 237{ 238 return (struct nokia_dsi_panel_data *) dssdev->data; 239} 240 241static void taal_esd_work(struct work_struct *work); 242 243static void hw_guard_start(struct taal_data *td, int guard_msec) 244{ 245 td->hw_guard_wait = msecs_to_jiffies(guard_msec); 246 td->hw_guard_end = jiffies + td->hw_guard_wait; 247} 248 249static void hw_guard_wait(struct taal_data *td) 250{ 251 unsigned long wait = td->hw_guard_end - jiffies; 252 253 if ((long)wait > 0 && wait <= td->hw_guard_wait) { 254 set_current_state(TASK_UNINTERRUPTIBLE); 255 schedule_timeout(wait); 256 } 257} 258 259static int taal_dcs_read_1(u8 dcs_cmd, u8 *data) 260{ 261 int r; 262 u8 buf[1]; 263 264 r = dsi_vc_dcs_read(TCH, dcs_cmd, buf, 1); 265 266 if (r < 0) 267 return r; 268 269 *data = buf[0]; 270 271 return 0; 272} 273 274static int taal_dcs_write_0(u8 dcs_cmd) 275{ 276 return dsi_vc_dcs_write(TCH, &dcs_cmd, 1); 277} 278 279static int taal_dcs_write_1(u8 dcs_cmd, u8 param) 280{ 281 u8 buf[2]; 282 buf[0] = dcs_cmd; 283 buf[1] = param; 284 return dsi_vc_dcs_write(TCH, buf, 2); 285} 286 287static int taal_sleep_in(struct taal_data *td) 288 289{ 290 u8 cmd; 291 int r; 292 293 hw_guard_wait(td); 294 295 cmd = DCS_SLEEP_IN; 296 r = dsi_vc_dcs_write_nosync(TCH, &cmd, 1); 297 if (r) 298 return r; 299 300 hw_guard_start(td, 120); 301 302 if (td->panel_config->sleep.sleep_in) 303 msleep(td->panel_config->sleep.sleep_in); 304 305 return 0; 306} 307 308static int taal_sleep_out(struct taal_data *td) 309{ 310 int r; 311 312 hw_guard_wait(td); 313 314 r = taal_dcs_write_0(DCS_SLEEP_OUT); 315 if (r) 316 return r; 317 318 hw_guard_start(td, 120); 319 320 if (td->panel_config->sleep.sleep_out) 321 msleep(td->panel_config->sleep.sleep_out); 322 323 return 0; 324} 325 326static int taal_get_id(u8 *id1, u8 *id2, u8 *id3) 327{ 328 int r; 329 330 r = taal_dcs_read_1(DCS_GET_ID1, id1); 331 if (r) 332 return r; 333 r = taal_dcs_read_1(DCS_GET_ID2, id2); 334 if (r) 335 return r; 336 r = taal_dcs_read_1(DCS_GET_ID3, id3); 337 if (r) 338 return r; 339 340 return 0; 341} 342 343static int taal_set_addr_mode(u8 rotate, bool mirror) 344{ 345 int r; 346 u8 mode; 347 int b5, b6, b7; 348 349 r = taal_dcs_read_1(DCS_READ_MADCTL, &mode); 350 if (r) 351 return r; 352 353 switch (rotate) { 354 default: 355 case 0: 356 b7 = 0; 357 b6 = 0; 358 b5 = 0; 359 break; 360 case 1: 361 b7 = 0; 362 b6 = 1; 363 b5 = 1; 364 break; 365 case 2: 366 b7 = 1; 367 b6 = 1; 368 b5 = 0; 369 break; 370 case 3: 371 b7 = 1; 372 b6 = 0; 373 b5 = 1; 374 break; 375 } 376 377 if (mirror) 378 b6 = !b6; 379 380 mode &= ~((1<<7) | (1<<6) | (1<<5)); 381 mode |= (b7 << 7) | (b6 << 6) | (b5 << 5); 382 383 return taal_dcs_write_1(DCS_MEM_ACC_CTRL, mode); 384} 385 386static int taal_set_update_window(u16 x, u16 y, u16 w, u16 h) 387{ 388 int r; 389 u16 x1 = x; 390 u16 x2 = x + w - 1; 391 u16 y1 = y; 392 u16 y2 = y + h - 1; 393 394 u8 buf[5]; 395 buf[0] = DCS_COLUMN_ADDR; 396 buf[1] = (x1 >> 8) & 0xff; 397 buf[2] = (x1 >> 0) & 0xff; 398 buf[3] = (x2 >> 8) & 0xff; 399 buf[4] = (x2 >> 0) & 0xff; 400 401 r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf)); 402 if (r) 403 return r; 404 405 buf[0] = DCS_PAGE_ADDR; 406 buf[1] = (y1 >> 8) & 0xff; 407 buf[2] = (y1 >> 0) & 0xff; 408 buf[3] = (y2 >> 8) & 0xff; 409 buf[4] = (y2 >> 0) & 0xff; 410 411 r = dsi_vc_dcs_write_nosync(TCH, buf, sizeof(buf)); 412 if (r) 413 return r; 414 415 dsi_vc_send_bta_sync(TCH); 416 417 return r; 418} 419 420static int taal_bl_update_status(struct backlight_device *dev) 421{ 422 struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev); 423 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 424 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); 425 int r; 426 int level; 427 428 if (dev->props.fb_blank == FB_BLANK_UNBLANK && 429 dev->props.power == FB_BLANK_UNBLANK) 430 level = dev->props.brightness; 431 else 432 level = 0; 433 434 dev_dbg(&dssdev->dev, "update brightness to %d\n", level); 435 436 mutex_lock(&td->lock); 437 438 if (td->use_dsi_bl) { 439 if (td->enabled) { 440 dsi_bus_lock(); 441 r = taal_dcs_write_1(DCS_BRIGHTNESS, level); 442 dsi_bus_unlock(); 443 } else { 444 r = 0; 445 } 446 } else { 447 if (!panel_data->set_backlight) 448 r = -EINVAL; 449 else 450 r = panel_data->set_backlight(dssdev, level); 451 } 452 453 mutex_unlock(&td->lock); 454 455 return r; 456} 457 458static int taal_bl_get_intensity(struct backlight_device *dev) 459{ 460 if (dev->props.fb_blank == FB_BLANK_UNBLANK && 461 dev->props.power == FB_BLANK_UNBLANK) 462 return dev->props.brightness; 463 464 return 0; 465} 466 467static struct backlight_ops taal_bl_ops = { 468 .get_brightness = taal_bl_get_intensity, 469 .update_status = taal_bl_update_status, 470}; 471 472static void taal_get_timings(struct omap_dss_device *dssdev, 473 struct omap_video_timings *timings) 474{ 475 *timings = dssdev->panel.timings; 476} 477 478static void taal_get_resolution(struct omap_dss_device *dssdev, 479 u16 *xres, u16 *yres) 480{ 481 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 482 483 if (td->rotate == 0 || td->rotate == 2) { 484 *xres = dssdev->panel.timings.x_res; 485 *yres = dssdev->panel.timings.y_res; 486 } else { 487 *yres = dssdev->panel.timings.x_res; 488 *xres = dssdev->panel.timings.y_res; 489 } 490} 491 492static ssize_t taal_num_errors_show(struct device *dev, 493 struct device_attribute *attr, char *buf) 494{ 495 struct omap_dss_device *dssdev = to_dss_device(dev); 496 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 497 u8 errors; 498 int r; 499 500 mutex_lock(&td->lock); 501 502 if (td->enabled) { 503 dsi_bus_lock(); 504 r = taal_dcs_read_1(DCS_READ_NUM_ERRORS, &errors); 505 dsi_bus_unlock(); 506 } else { 507 r = -ENODEV; 508 } 509 510 mutex_unlock(&td->lock); 511 512 if (r) 513 return r; 514 515 return snprintf(buf, PAGE_SIZE, "%d\n", errors); 516} 517 518static ssize_t taal_hw_revision_show(struct device *dev, 519 struct device_attribute *attr, char *buf) 520{ 521 struct omap_dss_device *dssdev = to_dss_device(dev); 522 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 523 u8 id1, id2, id3; 524 int r; 525 526 mutex_lock(&td->lock); 527 528 if (td->enabled) { 529 dsi_bus_lock(); 530 r = taal_get_id(&id1, &id2, &id3); 531 dsi_bus_unlock(); 532 } else { 533 r = -ENODEV; 534 } 535 536 mutex_unlock(&td->lock); 537 538 if (r) 539 return r; 540 541 return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3); 542} 543 544static const char *cabc_modes[] = { 545 "off", /* used also always when CABC is not supported */ 546 "ui", 547 "still-image", 548 "moving-image", 549}; 550 551static ssize_t show_cabc_mode(struct device *dev, 552 struct device_attribute *attr, 553 char *buf) 554{ 555 struct omap_dss_device *dssdev = to_dss_device(dev); 556 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 557 const char *mode_str; 558 int mode; 559 int len; 560 561 mode = td->cabc_mode; 562 563 mode_str = "unknown"; 564 if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes)) 565 mode_str = cabc_modes[mode]; 566 len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str); 567 568 return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1; 569} 570 571static ssize_t store_cabc_mode(struct device *dev, 572 struct device_attribute *attr, 573 const char *buf, size_t count) 574{ 575 struct omap_dss_device *dssdev = to_dss_device(dev); 576 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 577 int i; 578 579 for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) { 580 if (sysfs_streq(cabc_modes[i], buf)) 581 break; 582 } 583 584 if (i == ARRAY_SIZE(cabc_modes)) 585 return -EINVAL; 586 587 mutex_lock(&td->lock); 588 589 if (td->enabled) { 590 dsi_bus_lock(); 591 if (!td->cabc_broken) 592 taal_dcs_write_1(DCS_WRITE_CABC, i); 593 dsi_bus_unlock(); 594 } 595 596 td->cabc_mode = i; 597 598 mutex_unlock(&td->lock); 599 600 return count; 601} 602 603static ssize_t show_cabc_available_modes(struct device *dev, 604 struct device_attribute *attr, 605 char *buf) 606{ 607 int len; 608 int i; 609 610 for (i = 0, len = 0; 611 len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++) 612 len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s", 613 i ? " " : "", cabc_modes[i], 614 i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : ""); 615 616 return len < PAGE_SIZE ? len : PAGE_SIZE - 1; 617} 618 619static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL); 620static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL); 621static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR, 622 show_cabc_mode, store_cabc_mode); 623static DEVICE_ATTR(cabc_available_modes, S_IRUGO, 624 show_cabc_available_modes, NULL); 625 626static struct attribute *taal_attrs[] = { 627 &dev_attr_num_dsi_errors.attr, 628 &dev_attr_hw_revision.attr, 629 &dev_attr_cabc_mode.attr, 630 &dev_attr_cabc_available_modes.attr, 631 NULL, 632}; 633 634static struct attribute_group taal_attr_group = { 635 .attrs = taal_attrs, 636}; 637 638static void taal_hw_reset(struct omap_dss_device *dssdev) 639{ 640 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 641 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); 642 643 if (panel_data->reset_gpio == -1) 644 return; 645 646 gpio_set_value(panel_data->reset_gpio, 1); 647 if (td->panel_config->reset_sequence.high) 648 udelay(td->panel_config->reset_sequence.high); 649 /* reset the panel */ 650 gpio_set_value(panel_data->reset_gpio, 0); 651 /* assert reset */ 652 if (td->panel_config->reset_sequence.low) 653 udelay(td->panel_config->reset_sequence.low); 654 gpio_set_value(panel_data->reset_gpio, 1); 655 /* wait after releasing reset */ 656 if (td->panel_config->sleep.hw_reset) 657 msleep(td->panel_config->sleep.hw_reset); 658} 659 660static int taal_probe(struct omap_dss_device *dssdev) 661{ 662 struct backlight_properties props; 663 struct taal_data *td; 664 struct backlight_device *bldev; 665 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); 666 struct panel_config *panel_config = NULL; 667 int r, i; 668 669 dev_dbg(&dssdev->dev, "probe\n"); 670 671 if (!panel_data || !panel_data->name) { 672 r = -EINVAL; 673 goto err; 674 } 675 676 for (i = 0; i < ARRAY_SIZE(panel_configs); i++) { 677 if (strcmp(panel_data->name, panel_configs[i].name) == 0) { 678 panel_config = &panel_configs[i]; 679 break; 680 } 681 } 682 683 if (!panel_config) { 684 r = -EINVAL; 685 goto err; 686 } 687 688 dssdev->panel.config = OMAP_DSS_LCD_TFT; 689 dssdev->panel.timings = panel_config->timings; 690 dssdev->ctrl.pixel_size = 24; 691 692 td = kzalloc(sizeof(*td), GFP_KERNEL); 693 if (!td) { 694 r = -ENOMEM; 695 goto err; 696 } 697 td->dssdev = dssdev; 698 td->panel_config = panel_config; 699 700 mutex_init(&td->lock); 701 702 atomic_set(&td->do_update, 0); 703 704 r = init_regulators(dssdev, panel_config->regulators, 705 panel_config->num_regulators); 706 if (r) 707 goto err_reg; 708 709 td->esd_wq = create_singlethread_workqueue("taal_esd"); 710 if (td->esd_wq == NULL) { 711 dev_err(&dssdev->dev, "can't create ESD workqueue\n"); 712 r = -ENOMEM; 713 goto err_wq; 714 } 715 INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work); 716 717 dev_set_drvdata(&dssdev->dev, td); 718 719 taal_hw_reset(dssdev); 720 721 /* if no platform set_backlight() defined, presume DSI backlight 722 * control */ 723 memset(&props, 0, sizeof(struct backlight_properties)); 724 if (!panel_data->set_backlight) 725 td->use_dsi_bl = true; 726 727 if (td->use_dsi_bl) 728 props.max_brightness = 255; 729 else 730 props.max_brightness = 127; 731 bldev = backlight_device_register("taal", &dssdev->dev, dssdev, 732 &taal_bl_ops, &props); 733 if (IS_ERR(bldev)) { 734 r = PTR_ERR(bldev); 735 goto err_bl; 736 } 737 738 td->bldev = bldev; 739 740 bldev->props.fb_blank = FB_BLANK_UNBLANK; 741 bldev->props.power = FB_BLANK_UNBLANK; 742 if (td->use_dsi_bl) 743 bldev->props.brightness = 255; 744 else 745 bldev->props.brightness = 127; 746 747 taal_bl_update_status(bldev); 748 749 if (panel_data->use_ext_te) { 750 int gpio = panel_data->ext_te_gpio; 751 752 r = gpio_request(gpio, "taal irq"); 753 if (r) { 754 dev_err(&dssdev->dev, "GPIO request failed\n"); 755 goto err_gpio; 756 } 757 758 gpio_direction_input(gpio); 759 760 r = request_irq(gpio_to_irq(gpio), taal_te_isr, 761 IRQF_DISABLED | IRQF_TRIGGER_RISING, 762 "taal vsync", dssdev); 763 764 if (r) { 765 dev_err(&dssdev->dev, "IRQ request failed\n"); 766 gpio_free(gpio); 767 goto err_irq; 768 } 769 770 INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work, 771 taal_te_timeout_work_callback); 772 773 dev_dbg(&dssdev->dev, "Using GPIO TE\n"); 774 } 775 776 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group); 777 if (r) { 778 dev_err(&dssdev->dev, "failed to create sysfs files\n"); 779 goto err_sysfs; 780 } 781 782 return 0; 783err_sysfs: 784 if (panel_data->use_ext_te) 785 free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev); 786err_irq: 787 if (panel_data->use_ext_te) 788 gpio_free(panel_data->ext_te_gpio); 789err_gpio: 790 backlight_device_unregister(bldev); 791err_bl: 792 destroy_workqueue(td->esd_wq); 793err_wq: 794 free_regulators(panel_config->regulators, panel_config->num_regulators); 795err_reg: 796 kfree(td); 797err: 798 return r; 799} 800 801static void taal_remove(struct omap_dss_device *dssdev) 802{ 803 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 804 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); 805 struct backlight_device *bldev; 806 807 dev_dbg(&dssdev->dev, "remove\n"); 808 809 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group); 810 811 if (panel_data->use_ext_te) { 812 int gpio = panel_data->ext_te_gpio; 813 free_irq(gpio_to_irq(gpio), dssdev); 814 gpio_free(gpio); 815 } 816 817 bldev = td->bldev; 818 bldev->props.power = FB_BLANK_POWERDOWN; 819 taal_bl_update_status(bldev); 820 backlight_device_unregister(bldev); 821 822 cancel_delayed_work(&td->esd_work); 823 destroy_workqueue(td->esd_wq); 824 825 /* reset, to be sure that the panel is in a valid state */ 826 taal_hw_reset(dssdev); 827 828 free_regulators(td->panel_config->regulators, 829 td->panel_config->num_regulators); 830 831 kfree(td); 832} 833 834static int taal_power_on(struct omap_dss_device *dssdev) 835{ 836 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 837 u8 id1, id2, id3; 838 int r; 839 840 r = omapdss_dsi_display_enable(dssdev); 841 if (r) { 842 dev_err(&dssdev->dev, "failed to enable DSI\n"); 843 goto err0; 844 } 845 846 taal_hw_reset(dssdev); 847 848 omapdss_dsi_vc_enable_hs(TCH, false); 849 850 r = taal_sleep_out(td); 851 if (r) 852 goto err; 853 854 r = taal_get_id(&id1, &id2, &id3); 855 if (r) 856 goto err; 857 858 /* on early Taal revisions CABC is broken */ 859 if (td->panel_config->type == PANEL_TAAL && 860 (id2 == 0x00 || id2 == 0xff || id2 == 0x81)) 861 td->cabc_broken = true; 862 863 r = taal_dcs_write_1(DCS_BRIGHTNESS, 0xff); 864 if (r) 865 goto err; 866 867 r = taal_dcs_write_1(DCS_CTRL_DISPLAY, 868 (1<<2) | (1<<5)); /* BL | BCTRL */ 869 if (r) 870 goto err; 871 872 r = taal_dcs_write_1(DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */ 873 if (r) 874 goto err; 875 876 r = taal_set_addr_mode(td->rotate, td->mirror); 877 if (r) 878 goto err; 879 880 if (!td->cabc_broken) { 881 r = taal_dcs_write_1(DCS_WRITE_CABC, td->cabc_mode); 882 if (r) 883 goto err; 884 } 885 886 r = taal_dcs_write_0(DCS_DISPLAY_ON); 887 if (r) 888 goto err; 889 890 r = _taal_enable_te(dssdev, td->te_enabled); 891 if (r) 892 goto err; 893 894 td->enabled = 1; 895 896 if (!td->intro_printed) { 897 dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n", 898 td->panel_config->name, id1, id2, id3); 899 if (td->cabc_broken) 900 dev_info(&dssdev->dev, 901 "old Taal version, CABC disabled\n"); 902 td->intro_printed = true; 903 } 904 905 omapdss_dsi_vc_enable_hs(TCH, true); 906 907 return 0; 908err: 909 dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n"); 910 911 taal_hw_reset(dssdev); 912 913 omapdss_dsi_display_disable(dssdev); 914err0: 915 return r; 916} 917 918static void taal_power_off(struct omap_dss_device *dssdev) 919{ 920 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 921 int r; 922 923 r = taal_dcs_write_0(DCS_DISPLAY_OFF); 924 if (!r) { 925 r = taal_sleep_in(td); 926 /* HACK: wait a bit so that the message goes through */ 927 msleep(10); 928 } 929 930 if (r) { 931 dev_err(&dssdev->dev, 932 "error disabling panel, issuing HW reset\n"); 933 taal_hw_reset(dssdev); 934 } 935 936 omapdss_dsi_display_disable(dssdev); 937 938 td->enabled = 0; 939} 940 941static int taal_enable(struct omap_dss_device *dssdev) 942{ 943 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 944 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); 945 int r; 946 947 dev_dbg(&dssdev->dev, "enable\n"); 948 949 mutex_lock(&td->lock); 950 951 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) { 952 r = -EINVAL; 953 goto err; 954 } 955 956 dsi_bus_lock(); 957 958 r = taal_power_on(dssdev); 959 960 dsi_bus_unlock(); 961 962 if (r) 963 goto err; 964 965 if (panel_data->use_esd_check) 966 queue_delayed_work(td->esd_wq, &td->esd_work, 967 TAAL_ESD_CHECK_PERIOD); 968 969 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; 970 971 mutex_unlock(&td->lock); 972 973 return 0; 974err: 975 dev_dbg(&dssdev->dev, "enable failed\n"); 976 mutex_unlock(&td->lock); 977 return r; 978} 979 980static void taal_disable(struct omap_dss_device *dssdev) 981{ 982 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 983 984 dev_dbg(&dssdev->dev, "disable\n"); 985 986 mutex_lock(&td->lock); 987 988 cancel_delayed_work(&td->esd_work); 989 990 dsi_bus_lock(); 991 992 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) 993 taal_power_off(dssdev); 994 995 dsi_bus_unlock(); 996 997 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 998 999 mutex_unlock(&td->lock); 1000} 1001 1002static int taal_suspend(struct omap_dss_device *dssdev) 1003{ 1004 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 1005 int r; 1006 1007 dev_dbg(&dssdev->dev, "suspend\n"); 1008 1009 mutex_lock(&td->lock); 1010 1011 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) { 1012 r = -EINVAL; 1013 goto err; 1014 } 1015 1016 cancel_delayed_work(&td->esd_work); 1017 1018 dsi_bus_lock(); 1019 1020 taal_power_off(dssdev); 1021 1022 dsi_bus_unlock(); 1023 1024 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED; 1025 1026 mutex_unlock(&td->lock); 1027 1028 return 0; 1029err: 1030 mutex_unlock(&td->lock); 1031 return r; 1032} 1033 1034static int taal_resume(struct omap_dss_device *dssdev) 1035{ 1036 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 1037 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); 1038 int r; 1039 1040 dev_dbg(&dssdev->dev, "resume\n"); 1041 1042 mutex_lock(&td->lock); 1043 1044 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) { 1045 r = -EINVAL; 1046 goto err; 1047 } 1048 1049 dsi_bus_lock(); 1050 1051 r = taal_power_on(dssdev); 1052 1053 dsi_bus_unlock(); 1054 1055 if (r) { 1056 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 1057 } else { 1058 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; 1059 if (panel_data->use_esd_check) 1060 queue_delayed_work(td->esd_wq, &td->esd_work, 1061 TAAL_ESD_CHECK_PERIOD); 1062 } 1063 1064 mutex_unlock(&td->lock); 1065 1066 return r; 1067err: 1068 mutex_unlock(&td->lock); 1069 return r; 1070} 1071 1072static void taal_framedone_cb(int err, void *data) 1073{ 1074 struct omap_dss_device *dssdev = data; 1075 dev_dbg(&dssdev->dev, "framedone, err %d\n", err); 1076 dsi_bus_unlock(); 1077} 1078 1079static irqreturn_t taal_te_isr(int irq, void *data) 1080{ 1081 struct omap_dss_device *dssdev = data; 1082 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 1083 int old; 1084 int r; 1085 1086 old = atomic_cmpxchg(&td->do_update, 1, 0); 1087 1088 if (old) { 1089 cancel_delayed_work(&td->te_timeout_work); 1090 1091 r = omap_dsi_update(dssdev, TCH, 1092 td->update_region.x, 1093 td->update_region.y, 1094 td->update_region.w, 1095 td->update_region.h, 1096 taal_framedone_cb, dssdev); 1097 if (r) 1098 goto err; 1099 } 1100 1101 return IRQ_HANDLED; 1102err: 1103 dev_err(&dssdev->dev, "start update failed\n"); 1104 dsi_bus_unlock(); 1105 return IRQ_HANDLED; 1106} 1107 1108static void taal_te_timeout_work_callback(struct work_struct *work) 1109{ 1110 struct taal_data *td = container_of(work, struct taal_data, 1111 te_timeout_work.work); 1112 struct omap_dss_device *dssdev = td->dssdev; 1113 1114 dev_err(&dssdev->dev, "TE not received for 250ms!\n"); 1115 1116 atomic_set(&td->do_update, 0); 1117 dsi_bus_unlock(); 1118} 1119 1120static int taal_update(struct omap_dss_device *dssdev, 1121 u16 x, u16 y, u16 w, u16 h) 1122{ 1123 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 1124 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); 1125 int r; 1126 1127 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h); 1128 1129 mutex_lock(&td->lock); 1130 dsi_bus_lock(); 1131 1132 if (!td->enabled) { 1133 r = 0; 1134 goto err; 1135 } 1136 1137 r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true); 1138 if (r) 1139 goto err; 1140 1141 r = taal_set_update_window(x, y, w, h); 1142 if (r) 1143 goto err; 1144 1145 if (td->te_enabled && panel_data->use_ext_te) { 1146 td->update_region.x = x; 1147 td->update_region.y = y; 1148 td->update_region.w = w; 1149 td->update_region.h = h; 1150 barrier(); 1151 schedule_delayed_work(&td->te_timeout_work, 1152 msecs_to_jiffies(250)); 1153 atomic_set(&td->do_update, 1); 1154 } else { 1155 r = omap_dsi_update(dssdev, TCH, x, y, w, h, 1156 taal_framedone_cb, dssdev); 1157 if (r) 1158 goto err; 1159 } 1160 1161 /* note: no bus_unlock here. unlock is in framedone_cb */ 1162 mutex_unlock(&td->lock); 1163 return 0; 1164err: 1165 dsi_bus_unlock(); 1166 mutex_unlock(&td->lock); 1167 return r; 1168} 1169 1170static int taal_sync(struct omap_dss_device *dssdev) 1171{ 1172 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 1173 1174 dev_dbg(&dssdev->dev, "sync\n"); 1175 1176 mutex_lock(&td->lock); 1177 dsi_bus_lock(); 1178 dsi_bus_unlock(); 1179 mutex_unlock(&td->lock); 1180 1181 dev_dbg(&dssdev->dev, "sync done\n"); 1182 1183 return 0; 1184} 1185 1186static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable) 1187{ 1188 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 1189 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); 1190 int r; 1191 1192 if (enable) 1193 r = taal_dcs_write_1(DCS_TEAR_ON, 0); 1194 else 1195 r = taal_dcs_write_0(DCS_TEAR_OFF); 1196 1197 if (!panel_data->use_ext_te) 1198 omapdss_dsi_enable_te(dssdev, enable); 1199 1200 if (td->panel_config->sleep.enable_te) 1201 msleep(td->panel_config->sleep.enable_te); 1202 1203 return r; 1204} 1205 1206static int taal_enable_te(struct omap_dss_device *dssdev, bool enable) 1207{ 1208 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 1209 int r; 1210 1211 mutex_lock(&td->lock); 1212 1213 if (td->te_enabled == enable) 1214 goto end; 1215 1216 dsi_bus_lock(); 1217 1218 if (td->enabled) { 1219 r = _taal_enable_te(dssdev, enable); 1220 if (r) 1221 goto err; 1222 } 1223 1224 td->te_enabled = enable; 1225 1226 dsi_bus_unlock(); 1227end: 1228 mutex_unlock(&td->lock); 1229 1230 return 0; 1231err: 1232 dsi_bus_unlock(); 1233 mutex_unlock(&td->lock); 1234 1235 return r; 1236} 1237 1238static int taal_get_te(struct omap_dss_device *dssdev) 1239{ 1240 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 1241 int r; 1242 1243 mutex_lock(&td->lock); 1244 r = td->te_enabled; 1245 mutex_unlock(&td->lock); 1246 1247 return r; 1248} 1249 1250static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate) 1251{ 1252 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 1253 int r; 1254 1255 dev_dbg(&dssdev->dev, "rotate %d\n", rotate); 1256 1257 mutex_lock(&td->lock); 1258 1259 if (td->rotate == rotate) 1260 goto end; 1261 1262 dsi_bus_lock(); 1263 1264 if (td->enabled) { 1265 r = taal_set_addr_mode(rotate, td->mirror); 1266 if (r) 1267 goto err; 1268 } 1269 1270 td->rotate = rotate; 1271 1272 dsi_bus_unlock(); 1273end: 1274 mutex_unlock(&td->lock); 1275 return 0; 1276err: 1277 dsi_bus_unlock(); 1278 mutex_unlock(&td->lock); 1279 return r; 1280} 1281 1282static u8 taal_get_rotate(struct omap_dss_device *dssdev) 1283{ 1284 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 1285 int r; 1286 1287 mutex_lock(&td->lock); 1288 r = td->rotate; 1289 mutex_unlock(&td->lock); 1290 1291 return r; 1292} 1293 1294static int taal_mirror(struct omap_dss_device *dssdev, bool enable) 1295{ 1296 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 1297 int r; 1298 1299 dev_dbg(&dssdev->dev, "mirror %d\n", enable); 1300 1301 mutex_lock(&td->lock); 1302 1303 if (td->mirror == enable) 1304 goto end; 1305 1306 dsi_bus_lock(); 1307 if (td->enabled) { 1308 r = taal_set_addr_mode(td->rotate, enable); 1309 if (r) 1310 goto err; 1311 } 1312 1313 td->mirror = enable; 1314 1315 dsi_bus_unlock(); 1316end: 1317 mutex_unlock(&td->lock); 1318 return 0; 1319err: 1320 dsi_bus_unlock(); 1321 mutex_unlock(&td->lock); 1322 return r; 1323} 1324 1325static bool taal_get_mirror(struct omap_dss_device *dssdev) 1326{ 1327 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 1328 int r; 1329 1330 mutex_lock(&td->lock); 1331 r = td->mirror; 1332 mutex_unlock(&td->lock); 1333 1334 return r; 1335} 1336 1337static int taal_run_test(struct omap_dss_device *dssdev, int test_num) 1338{ 1339 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 1340 u8 id1, id2, id3; 1341 int r; 1342 1343 mutex_lock(&td->lock); 1344 1345 if (!td->enabled) { 1346 r = -ENODEV; 1347 goto err1; 1348 } 1349 1350 dsi_bus_lock(); 1351 1352 r = taal_dcs_read_1(DCS_GET_ID1, &id1); 1353 if (r) 1354 goto err2; 1355 r = taal_dcs_read_1(DCS_GET_ID2, &id2); 1356 if (r) 1357 goto err2; 1358 r = taal_dcs_read_1(DCS_GET_ID3, &id3); 1359 if (r) 1360 goto err2; 1361 1362 dsi_bus_unlock(); 1363 mutex_unlock(&td->lock); 1364 return 0; 1365err2: 1366 dsi_bus_unlock(); 1367err1: 1368 mutex_unlock(&td->lock); 1369 return r; 1370} 1371 1372static int taal_memory_read(struct omap_dss_device *dssdev, 1373 void *buf, size_t size, 1374 u16 x, u16 y, u16 w, u16 h) 1375{ 1376 int r; 1377 int first = 1; 1378 int plen; 1379 unsigned buf_used = 0; 1380 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 1381 1382 if (size < w * h * 3) 1383 return -ENOMEM; 1384 1385 mutex_lock(&td->lock); 1386 1387 if (!td->enabled) { 1388 r = -ENODEV; 1389 goto err1; 1390 } 1391 1392 size = min(w * h * 3, 1393 dssdev->panel.timings.x_res * 1394 dssdev->panel.timings.y_res * 3); 1395 1396 dsi_bus_lock(); 1397 1398 /* plen 1 or 2 goes into short packet. until checksum error is fixed, 1399 * use short packets. plen 32 works, but bigger packets seem to cause 1400 * an error. */ 1401 if (size % 2) 1402 plen = 1; 1403 else 1404 plen = 2; 1405 1406 taal_set_update_window(x, y, w, h); 1407 1408 r = dsi_vc_set_max_rx_packet_size(TCH, plen); 1409 if (r) 1410 goto err2; 1411 1412 while (buf_used < size) { 1413 u8 dcs_cmd = first ? 0x2e : 0x3e; 1414 first = 0; 1415 1416 r = dsi_vc_dcs_read(TCH, dcs_cmd, 1417 buf + buf_used, size - buf_used); 1418 1419 if (r < 0) { 1420 dev_err(&dssdev->dev, "read error\n"); 1421 goto err3; 1422 } 1423 1424 buf_used += r; 1425 1426 if (r < plen) { 1427 dev_err(&dssdev->dev, "short read\n"); 1428 break; 1429 } 1430 1431 if (signal_pending(current)) { 1432 dev_err(&dssdev->dev, "signal pending, " 1433 "aborting memory read\n"); 1434 r = -ERESTARTSYS; 1435 goto err3; 1436 } 1437 } 1438 1439 r = buf_used; 1440 1441err3: 1442 dsi_vc_set_max_rx_packet_size(TCH, 1); 1443err2: 1444 dsi_bus_unlock(); 1445err1: 1446 mutex_unlock(&td->lock); 1447 return r; 1448} 1449 1450static void taal_esd_work(struct work_struct *work) 1451{ 1452 struct taal_data *td = container_of(work, struct taal_data, 1453 esd_work.work); 1454 struct omap_dss_device *dssdev = td->dssdev; 1455 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev); 1456 u8 state1, state2; 1457 int r; 1458 1459 mutex_lock(&td->lock); 1460 1461 if (!td->enabled) { 1462 mutex_unlock(&td->lock); 1463 return; 1464 } 1465 1466 dsi_bus_lock(); 1467 1468 r = taal_dcs_read_1(DCS_RDDSDR, &state1); 1469 if (r) { 1470 dev_err(&dssdev->dev, "failed to read Taal status\n"); 1471 goto err; 1472 } 1473 1474 /* Run self diagnostics */ 1475 r = taal_sleep_out(td); 1476 if (r) { 1477 dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n"); 1478 goto err; 1479 } 1480 1481 r = taal_dcs_read_1(DCS_RDDSDR, &state2); 1482 if (r) { 1483 dev_err(&dssdev->dev, "failed to read Taal status\n"); 1484 goto err; 1485 } 1486 1487 /* Each sleep out command will trigger a self diagnostic and flip 1488 * Bit6 if the test passes. 1489 */ 1490 if (!((state1 ^ state2) & (1 << 6))) { 1491 dev_err(&dssdev->dev, "LCD self diagnostics failed\n"); 1492 goto err; 1493 } 1494 /* Self-diagnostics result is also shown on TE GPIO line. We need 1495 * to re-enable TE after self diagnostics */ 1496 if (td->te_enabled && panel_data->use_ext_te) { 1497 r = taal_dcs_write_1(DCS_TEAR_ON, 0); 1498 if (r) 1499 goto err; 1500 } 1501 1502 dsi_bus_unlock(); 1503 1504 queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD); 1505 1506 mutex_unlock(&td->lock); 1507 return; 1508err: 1509 dev_err(&dssdev->dev, "performing LCD reset\n"); 1510 1511 taal_power_off(dssdev); 1512 taal_hw_reset(dssdev); 1513 taal_power_on(dssdev); 1514 1515 dsi_bus_unlock(); 1516 1517 queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD); 1518 1519 mutex_unlock(&td->lock); 1520} 1521 1522static int taal_set_update_mode(struct omap_dss_device *dssdev, 1523 enum omap_dss_update_mode mode) 1524{ 1525 if (mode != OMAP_DSS_UPDATE_MANUAL) 1526 return -EINVAL; 1527 return 0; 1528} 1529 1530static enum omap_dss_update_mode taal_get_update_mode( 1531 struct omap_dss_device *dssdev) 1532{ 1533 return OMAP_DSS_UPDATE_MANUAL; 1534} 1535 1536static struct omap_dss_driver taal_driver = { 1537 .probe = taal_probe, 1538 .remove = taal_remove, 1539 1540 .enable = taal_enable, 1541 .disable = taal_disable, 1542 .suspend = taal_suspend, 1543 .resume = taal_resume, 1544 1545 .set_update_mode = taal_set_update_mode, 1546 .get_update_mode = taal_get_update_mode, 1547 1548 .update = taal_update, 1549 .sync = taal_sync, 1550 1551 .get_resolution = taal_get_resolution, 1552 .get_recommended_bpp = omapdss_default_get_recommended_bpp, 1553 1554 .enable_te = taal_enable_te, 1555 .get_te = taal_get_te, 1556 1557 .set_rotate = taal_rotate, 1558 .get_rotate = taal_get_rotate, 1559 .set_mirror = taal_mirror, 1560 .get_mirror = taal_get_mirror, 1561 .run_test = taal_run_test, 1562 .memory_read = taal_memory_read, 1563 1564 .get_timings = taal_get_timings, 1565 1566 .driver = { 1567 .name = "taal", 1568 .owner = THIS_MODULE, 1569 }, 1570}; 1571 1572static int __init taal_init(void) 1573{ 1574 omap_dss_register_driver(&taal_driver); 1575 1576 return 0; 1577} 1578 1579static void __exit taal_exit(void) 1580{ 1581 omap_dss_unregister_driver(&taal_driver); 1582} 1583 1584module_init(taal_init); 1585module_exit(taal_exit); 1586 1587MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>"); 1588MODULE_DESCRIPTION("Taal Driver"); 1589MODULE_LICENSE("GPL"); 1590