panel-taal.c 33.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/*
 * Taal DSI command mode panel
 *
 * Copyright (C) 2009 Nokia Corporation
 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*#define DEBUG*/

#include <linux/module.h>
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/jiffies.h>
#include <linux/sched.h>
#include <linux/backlight.h>
#include <linux/fb.h>
#include <linux/interrupt.h>
#include <linux/gpio.h>
#include <linux/workqueue.h>
32
#include <linux/slab.h>
33
#include <linux/regulator/consumer.h>
34
#include <linux/mutex.h>
35

36
#include <video/omapdss.h>
37
#include <video/omap-panel-nokia-dsi.h>
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

/* DSI Virtual channel. Hardcoded for now. */
#define TCH 0

#define DCS_READ_NUM_ERRORS	0x05
#define DCS_READ_POWER_MODE	0x0a
#define DCS_READ_MADCTL		0x0b
#define DCS_READ_PIXEL_FORMAT	0x0c
#define DCS_RDDSDR		0x0f
#define DCS_SLEEP_IN		0x10
#define DCS_SLEEP_OUT		0x11
#define DCS_DISPLAY_OFF		0x28
#define DCS_DISPLAY_ON		0x29
#define DCS_COLUMN_ADDR		0x2a
#define DCS_PAGE_ADDR		0x2b
#define DCS_MEMORY_WRITE	0x2c
#define DCS_TEAR_OFF		0x34
#define DCS_TEAR_ON		0x35
#define DCS_MEM_ACC_CTRL	0x36
#define DCS_PIXEL_FORMAT	0x3a
#define DCS_BRIGHTNESS		0x51
#define DCS_CTRL_DISPLAY	0x53
#define DCS_WRITE_CABC		0x55
#define DCS_READ_CABC		0x56
#define DCS_GET_ID1		0xda
#define DCS_GET_ID2		0xdb
#define DCS_GET_ID3		0xdc

66 67
static irqreturn_t taal_te_isr(int irq, void *data);
static void taal_te_timeout_work_callback(struct work_struct *work);
68 69
static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable);

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
struct panel_regulator {
	struct regulator *regulator;
	const char *name;
	int min_uV;
	int max_uV;
};

static void free_regulators(struct panel_regulator *regulators, int n)
{
	int i;

	for (i = 0; i < n; i++) {
		/* disable/put in reverse order */
		regulator_disable(regulators[n - i - 1].regulator);
		regulator_put(regulators[n - i - 1].regulator);
	}
}

static int init_regulators(struct omap_dss_device *dssdev,
			struct panel_regulator *regulators, int n)
{
	int r, i, v;

	for (i = 0; i < n; i++) {
		struct regulator *reg;

		reg = regulator_get(&dssdev->dev, regulators[i].name);
		if (IS_ERR(reg)) {
			dev_err(&dssdev->dev, "failed to get regulator %s\n",
				regulators[i].name);
			r = PTR_ERR(reg);
			goto err;
		}

		/* FIXME: better handling of fixed vs. variable regulators */
		v = regulator_get_voltage(reg);
		if (v < regulators[i].min_uV || v > regulators[i].max_uV) {
			r = regulator_set_voltage(reg, regulators[i].min_uV,
						regulators[i].max_uV);
			if (r) {
				dev_err(&dssdev->dev,
					"failed to set regulator %s voltage\n",
					regulators[i].name);
				regulator_put(reg);
				goto err;
			}
		}

		r = regulator_enable(reg);
		if (r) {
			dev_err(&dssdev->dev, "failed to enable regulator %s\n",
				regulators[i].name);
			regulator_put(reg);
			goto err;
		}

		regulators[i].regulator = reg;
	}

	return 0;

err:
	free_regulators(regulators, i);

	return r;
}

137 138 139 140 141 142 143
/**
 * struct panel_config - panel configuration
 * @name: panel name
 * @type: panel type
 * @timings: panel resolution
 * @sleep: various panel specific delays, passed to msleep() if non-zero
 * @reset_sequence: reset sequence timings, passed to udelay() if non-zero
144 145
 * @regulators: array of panel regulators
 * @num_regulators: number of regulators in the array
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
 */
struct panel_config {
	const char *name;
	int type;

	struct omap_video_timings timings;

	struct {
		unsigned int sleep_in;
		unsigned int sleep_out;
		unsigned int hw_reset;
		unsigned int enable_te;
	} sleep;

	struct {
		unsigned int high;
		unsigned int low;
	} reset_sequence;
164 165 166

	struct panel_regulator *regulators;
	int num_regulators;
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
};

enum {
	PANEL_TAAL,
};

static struct panel_config panel_configs[] = {
	{
		.name		= "taal",
		.type		= PANEL_TAAL,
		.timings	= {
			.x_res		= 864,
			.y_res		= 480,
		},
		.sleep		= {
			.sleep_in	= 5,
			.sleep_out	= 5,
			.hw_reset	= 5,
			.enable_te	= 100, /* possible panel bug */
		},
		.reset_sequence	= {
			.high		= 10,
			.low		= 10,
		},
	},
};

194
struct taal_data {
195 196
	struct mutex lock;

197 198 199 200 201 202 203 204 205 206 207 208 209 210
	struct backlight_device *bldev;

	unsigned long	hw_guard_end;	/* next value of jiffies when we can
					 * issue the next sleep in/out command
					 */
	unsigned long	hw_guard_wait;	/* max guard time in jiffies */

	struct omap_dss_device *dssdev;

	bool enabled;
	u8 rotate;
	bool mirror;

	bool te_enabled;
211 212 213 214 215 216 217 218

	atomic_t do_update;
	struct {
		u16 x;
		u16 y;
		u16 w;
		u16 h;
	} update_region;
219 220
	int channel;

221
	struct delayed_work te_timeout_work;
222 223 224 225 226 227 228 229 230 231

	bool use_dsi_bl;

	bool cabc_broken;
	unsigned cabc_mode;

	bool intro_printed;

	struct workqueue_struct *esd_wq;
	struct delayed_work esd_work;
232
	unsigned esd_interval;
233 234

	struct panel_config *panel_config;
235 236
};

237 238 239 240 241 242
static inline struct nokia_dsi_panel_data
*get_panel_data(const struct omap_dss_device *dssdev)
{
	return (struct nokia_dsi_panel_data *) dssdev->data;
}

243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
static void taal_esd_work(struct work_struct *work);

static void hw_guard_start(struct taal_data *td, int guard_msec)
{
	td->hw_guard_wait = msecs_to_jiffies(guard_msec);
	td->hw_guard_end = jiffies + td->hw_guard_wait;
}

static void hw_guard_wait(struct taal_data *td)
{
	unsigned long wait = td->hw_guard_end - jiffies;

	if ((long)wait > 0 && wait <= td->hw_guard_wait) {
		set_current_state(TASK_UNINTERRUPTIBLE);
		schedule_timeout(wait);
	}
}

261
static int taal_dcs_read_1(struct taal_data *td, u8 dcs_cmd, u8 *data)
262 263 264 265
{
	int r;
	u8 buf[1];

266
	r = dsi_vc_dcs_read(td->channel, dcs_cmd, buf, 1);
267 268 269 270 271 272 273 274 275

	if (r < 0)
		return r;

	*data = buf[0];

	return 0;
}

276
static int taal_dcs_write_0(struct taal_data *td, u8 dcs_cmd)
277
{
278
	return dsi_vc_dcs_write(td->channel, &dcs_cmd, 1);
279 280
}

281
static int taal_dcs_write_1(struct taal_data *td, u8 dcs_cmd, u8 param)
282 283 284 285
{
	u8 buf[2];
	buf[0] = dcs_cmd;
	buf[1] = param;
286
	return dsi_vc_dcs_write(td->channel, buf, 2);
287 288 289 290 291 292 293 294 295 296 297
}

static int taal_sleep_in(struct taal_data *td)

{
	u8 cmd;
	int r;

	hw_guard_wait(td);

	cmd = DCS_SLEEP_IN;
298
	r = dsi_vc_dcs_write_nosync(td->channel, &cmd, 1);
299 300 301 302 303
	if (r)
		return r;

	hw_guard_start(td, 120);

304 305
	if (td->panel_config->sleep.sleep_in)
		msleep(td->panel_config->sleep.sleep_in);
306 307 308 309 310 311 312 313 314 315

	return 0;
}

static int taal_sleep_out(struct taal_data *td)
{
	int r;

	hw_guard_wait(td);

316
	r = taal_dcs_write_0(td, DCS_SLEEP_OUT);
317 318 319 320 321
	if (r)
		return r;

	hw_guard_start(td, 120);

322 323
	if (td->panel_config->sleep.sleep_out)
		msleep(td->panel_config->sleep.sleep_out);
324 325 326 327

	return 0;
}

328
static int taal_get_id(struct taal_data *td, u8 *id1, u8 *id2, u8 *id3)
329 330 331
{
	int r;

332
	r = taal_dcs_read_1(td, DCS_GET_ID1, id1);
333 334
	if (r)
		return r;
335
	r = taal_dcs_read_1(td, DCS_GET_ID2, id2);
336 337
	if (r)
		return r;
338
	r = taal_dcs_read_1(td, DCS_GET_ID3, id3);
339 340 341 342 343 344
	if (r)
		return r;

	return 0;
}

345
static int taal_set_addr_mode(struct taal_data *td, u8 rotate, bool mirror)
346 347 348 349 350
{
	int r;
	u8 mode;
	int b5, b6, b7;

351
	r = taal_dcs_read_1(td, DCS_READ_MADCTL, &mode);
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
	if (r)
		return r;

	switch (rotate) {
	default:
	case 0:
		b7 = 0;
		b6 = 0;
		b5 = 0;
		break;
	case 1:
		b7 = 0;
		b6 = 1;
		b5 = 1;
		break;
	case 2:
		b7 = 1;
		b6 = 1;
		b5 = 0;
		break;
	case 3:
		b7 = 1;
		b6 = 0;
		b5 = 1;
		break;
	}

	if (mirror)
		b6 = !b6;

	mode &= ~((1<<7) | (1<<6) | (1<<5));
	mode |= (b7 << 7) | (b6 << 6) | (b5 << 5);

385
	return taal_dcs_write_1(td, DCS_MEM_ACC_CTRL, mode);
386 387
}

388 389
static int taal_set_update_window(struct taal_data *td,
		u16 x, u16 y, u16 w, u16 h)
390 391 392 393 394 395 396 397 398 399 400 401 402 403
{
	int r;
	u16 x1 = x;
	u16 x2 = x + w - 1;
	u16 y1 = y;
	u16 y2 = y + h - 1;

	u8 buf[5];
	buf[0] = DCS_COLUMN_ADDR;
	buf[1] = (x1 >> 8) & 0xff;
	buf[2] = (x1 >> 0) & 0xff;
	buf[3] = (x2 >> 8) & 0xff;
	buf[4] = (x2 >> 0) & 0xff;

404
	r = dsi_vc_dcs_write_nosync(td->channel, buf, sizeof(buf));
405 406 407 408 409 410 411 412 413
	if (r)
		return r;

	buf[0] = DCS_PAGE_ADDR;
	buf[1] = (y1 >> 8) & 0xff;
	buf[2] = (y1 >> 0) & 0xff;
	buf[3] = (y2 >> 8) & 0xff;
	buf[4] = (y2 >> 0) & 0xff;

414
	r = dsi_vc_dcs_write_nosync(td->channel, buf, sizeof(buf));
415 416 417
	if (r)
		return r;

418
	dsi_vc_send_bta_sync(td->channel);
419 420 421 422

	return r;
}

423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
static void taal_queue_esd_work(struct omap_dss_device *dssdev)
{
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);

	if (td->esd_interval > 0)
		queue_delayed_work(td->esd_wq, &td->esd_work,
				msecs_to_jiffies(td->esd_interval));
}

static void taal_cancel_esd_work(struct omap_dss_device *dssdev)
{
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);

	cancel_delayed_work(&td->esd_work);
}

439 440 441 442
static int taal_bl_update_status(struct backlight_device *dev)
{
	struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
443
	struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
444 445 446 447 448 449 450 451 452 453 454
	int r;
	int level;

	if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
			dev->props.power == FB_BLANK_UNBLANK)
		level = dev->props.brightness;
	else
		level = 0;

	dev_dbg(&dssdev->dev, "update brightness to %d\n", level);

455 456
	mutex_lock(&td->lock);

457 458 459
	if (td->use_dsi_bl) {
		if (td->enabled) {
			dsi_bus_lock();
460
			r = taal_dcs_write_1(td, DCS_BRIGHTNESS, level);
461
			dsi_bus_unlock();
462 463
		} else {
			r = 0;
464 465
		}
	} else {
466
		if (!panel_data->set_backlight)
467 468
			r = -EINVAL;
		else
469
			r = panel_data->set_backlight(dssdev, level);
470 471
	}

472 473 474
	mutex_unlock(&td->lock);

	return r;
475 476 477 478 479 480 481 482 483 484 485
}

static int taal_bl_get_intensity(struct backlight_device *dev)
{
	if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
			dev->props.power == FB_BLANK_UNBLANK)
		return dev->props.brightness;

	return 0;
}

L
Lionel Debroux 已提交
486
static const struct backlight_ops taal_bl_ops = {
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
	.get_brightness = taal_bl_get_intensity,
	.update_status  = taal_bl_update_status,
};

static void taal_get_timings(struct omap_dss_device *dssdev,
			struct omap_video_timings *timings)
{
	*timings = dssdev->panel.timings;
}

static void taal_get_resolution(struct omap_dss_device *dssdev,
		u16 *xres, u16 *yres)
{
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);

	if (td->rotate == 0 || td->rotate == 2) {
		*xres = dssdev->panel.timings.x_res;
		*yres = dssdev->panel.timings.y_res;
	} else {
		*yres = dssdev->panel.timings.x_res;
		*xres = dssdev->panel.timings.y_res;
	}
}

static ssize_t taal_num_errors_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct omap_dss_device *dssdev = to_dss_device(dev);
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
	u8 errors;
	int r;

519 520
	mutex_lock(&td->lock);

521 522
	if (td->enabled) {
		dsi_bus_lock();
523
		r = taal_dcs_read_1(td, DCS_READ_NUM_ERRORS, &errors);
524 525 526 527 528
		dsi_bus_unlock();
	} else {
		r = -ENODEV;
	}

529 530
	mutex_unlock(&td->lock);

531 532 533 534 535 536 537 538 539 540 541 542 543 544
	if (r)
		return r;

	return snprintf(buf, PAGE_SIZE, "%d\n", errors);
}

static ssize_t taal_hw_revision_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct omap_dss_device *dssdev = to_dss_device(dev);
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
	u8 id1, id2, id3;
	int r;

545 546
	mutex_lock(&td->lock);

547 548
	if (td->enabled) {
		dsi_bus_lock();
549
		r = taal_get_id(td, &id1, &id2, &id3);
550 551 552 553 554
		dsi_bus_unlock();
	} else {
		r = -ENODEV;
	}

555 556
	mutex_unlock(&td->lock);

557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
	if (r)
		return r;

	return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x\n", id1, id2, id3);
}

static const char *cabc_modes[] = {
	"off",		/* used also always when CABC is not supported */
	"ui",
	"still-image",
	"moving-image",
};

static ssize_t show_cabc_mode(struct device *dev,
		struct device_attribute *attr,
		char *buf)
{
	struct omap_dss_device *dssdev = to_dss_device(dev);
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
	const char *mode_str;
	int mode;
	int len;

	mode = td->cabc_mode;

	mode_str = "unknown";
	if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
		mode_str = cabc_modes[mode];
	len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);

	return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
}

static ssize_t store_cabc_mode(struct device *dev,
		struct device_attribute *attr,
		const char *buf, size_t count)
{
	struct omap_dss_device *dssdev = to_dss_device(dev);
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
	int i;

	for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
		if (sysfs_streq(cabc_modes[i], buf))
			break;
	}

	if (i == ARRAY_SIZE(cabc_modes))
		return -EINVAL;

606 607
	mutex_lock(&td->lock);

608 609 610
	if (td->enabled) {
		dsi_bus_lock();
		if (!td->cabc_broken)
611
			taal_dcs_write_1(td, DCS_WRITE_CABC, i);
612 613 614 615 616
		dsi_bus_unlock();
	}

	td->cabc_mode = i;

617 618
	mutex_unlock(&td->lock);

619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
	return count;
}

static ssize_t show_cabc_available_modes(struct device *dev,
		struct device_attribute *attr,
		char *buf)
{
	int len;
	int i;

	for (i = 0, len = 0;
	     len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
		len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
			i ? " " : "", cabc_modes[i],
			i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");

	return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
}

638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
static ssize_t taal_store_esd_interval(struct device *dev,
		struct device_attribute *attr,
		const char *buf, size_t count)
{
	struct omap_dss_device *dssdev = to_dss_device(dev);
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);

	unsigned long t;
	int r;

	r = strict_strtoul(buf, 10, &t);
	if (r)
		return r;

	mutex_lock(&td->lock);
	taal_cancel_esd_work(dssdev);
	td->esd_interval = t;
	if (td->enabled)
		taal_queue_esd_work(dssdev);
	mutex_unlock(&td->lock);

	return count;
}

static ssize_t taal_show_esd_interval(struct device *dev,
		struct device_attribute *attr,
		char *buf)
{
	struct omap_dss_device *dssdev = to_dss_device(dev);
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
	unsigned t;

	mutex_lock(&td->lock);
	t = td->esd_interval;
	mutex_unlock(&td->lock);

	return snprintf(buf, PAGE_SIZE, "%u\n", t);
}

677 678 679 680 681 682
static DEVICE_ATTR(num_dsi_errors, S_IRUGO, taal_num_errors_show, NULL);
static DEVICE_ATTR(hw_revision, S_IRUGO, taal_hw_revision_show, NULL);
static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
		show_cabc_mode, store_cabc_mode);
static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
		show_cabc_available_modes, NULL);
683 684
static DEVICE_ATTR(esd_interval, S_IRUGO | S_IWUSR,
		taal_show_esd_interval, taal_store_esd_interval);
685 686 687 688 689 690

static struct attribute *taal_attrs[] = {
	&dev_attr_num_dsi_errors.attr,
	&dev_attr_hw_revision.attr,
	&dev_attr_cabc_mode.attr,
	&dev_attr_cabc_available_modes.attr,
691
	&dev_attr_esd_interval.attr,
692 693 694 695 696 697 698
	NULL,
};

static struct attribute_group taal_attr_group = {
	.attrs = taal_attrs,
};

699 700
static void taal_hw_reset(struct omap_dss_device *dssdev)
{
701
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
702 703 704
	struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);

	if (panel_data->reset_gpio == -1)
705 706
		return;

707
	gpio_set_value(panel_data->reset_gpio, 1);
708 709
	if (td->panel_config->reset_sequence.high)
		udelay(td->panel_config->reset_sequence.high);
710
	/* reset the panel */
711
	gpio_set_value(panel_data->reset_gpio, 0);
712 713 714
	/* assert reset */
	if (td->panel_config->reset_sequence.low)
		udelay(td->panel_config->reset_sequence.low);
715
	gpio_set_value(panel_data->reset_gpio, 1);
716 717 718
	/* wait after releasing reset */
	if (td->panel_config->sleep.hw_reset)
		msleep(td->panel_config->sleep.hw_reset);
719 720
}

721 722
static int taal_probe(struct omap_dss_device *dssdev)
{
723
	struct backlight_properties props;
724 725
	struct taal_data *td;
	struct backlight_device *bldev;
726
	struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
727 728
	struct panel_config *panel_config = NULL;
	int r, i;
729 730 731

	dev_dbg(&dssdev->dev, "probe\n");

732 733 734 735 736
	if (!panel_data || !panel_data->name) {
		r = -EINVAL;
		goto err;
	}

737 738 739 740 741 742 743 744 745 746 747 748
	for (i = 0; i < ARRAY_SIZE(panel_configs); i++) {
		if (strcmp(panel_data->name, panel_configs[i].name) == 0) {
			panel_config = &panel_configs[i];
			break;
		}
	}

	if (!panel_config) {
		r = -EINVAL;
		goto err;
	}

749
	dssdev->panel.config = OMAP_DSS_LCD_TFT;
750
	dssdev->panel.timings = panel_config->timings;
751 752 753 754 755
	dssdev->ctrl.pixel_size = 24;

	td = kzalloc(sizeof(*td), GFP_KERNEL);
	if (!td) {
		r = -ENOMEM;
756
		goto err;
757 758
	}
	td->dssdev = dssdev;
759
	td->panel_config = panel_config;
760
	td->esd_interval = panel_data->esd_interval;
761

762 763
	mutex_init(&td->lock);

764 765
	atomic_set(&td->do_update, 0);

766 767 768 769 770
	r = init_regulators(dssdev, panel_config->regulators,
			panel_config->num_regulators);
	if (r)
		goto err_reg;

771 772 773 774
	td->esd_wq = create_singlethread_workqueue("taal_esd");
	if (td->esd_wq == NULL) {
		dev_err(&dssdev->dev, "can't create ESD workqueue\n");
		r = -ENOMEM;
775
		goto err_wq;
776 777 778 779 780
	}
	INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);

	dev_set_drvdata(&dssdev->dev, td);

781 782
	taal_hw_reset(dssdev);

783 784
	/* if no platform set_backlight() defined, presume DSI backlight
	 * control */
785
	memset(&props, 0, sizeof(struct backlight_properties));
786
	if (!panel_data->set_backlight)
787 788
		td->use_dsi_bl = true;

789 790 791 792
	if (td->use_dsi_bl)
		props.max_brightness = 255;
	else
		props.max_brightness = 127;
M
Matthew Garrett 已提交
793 794

	props.type = BACKLIGHT_RAW;
795
	bldev = backlight_device_register("taal", &dssdev->dev, dssdev,
796
					  &taal_bl_ops, &props);
797 798
	if (IS_ERR(bldev)) {
		r = PTR_ERR(bldev);
799
		goto err_bl;
800 801 802 803 804 805
	}

	td->bldev = bldev;

	bldev->props.fb_blank = FB_BLANK_UNBLANK;
	bldev->props.power = FB_BLANK_UNBLANK;
806
	if (td->use_dsi_bl)
807
		bldev->props.brightness = 255;
808
	else
809 810 811 812
		bldev->props.brightness = 127;

	taal_bl_update_status(bldev);

813 814
	if (panel_data->use_ext_te) {
		int gpio = panel_data->ext_te_gpio;
815 816 817 818

		r = gpio_request(gpio, "taal irq");
		if (r) {
			dev_err(&dssdev->dev, "GPIO request failed\n");
819
			goto err_gpio;
820 821 822 823 824 825 826 827 828 829 830
		}

		gpio_direction_input(gpio);

		r = request_irq(gpio_to_irq(gpio), taal_te_isr,
				IRQF_DISABLED | IRQF_TRIGGER_RISING,
				"taal vsync", dssdev);

		if (r) {
			dev_err(&dssdev->dev, "IRQ request failed\n");
			gpio_free(gpio);
831
			goto err_irq;
832 833
		}

834 835
		INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
					taal_te_timeout_work_callback);
836

837
		dev_dbg(&dssdev->dev, "Using GPIO TE\n");
838 839
	}

840 841 842 843 844 845 846 847 848 849 850 851
	r = omap_dsi_request_vc(dssdev, &td->channel);
	if (r) {
		dev_err(&dssdev->dev, "failed to get virtual channel\n");
		goto err_req_vc;
	}

	r = omap_dsi_set_vc_id(dssdev, td->channel, TCH);
	if (r) {
		dev_err(&dssdev->dev, "failed to set VC_ID\n");
		goto err_vc_id;
	}

852 853 854
	r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
	if (r) {
		dev_err(&dssdev->dev, "failed to create sysfs files\n");
855
		goto err_vc_id;
856 857 858
	}

	return 0;
859 860 861 862

err_vc_id:
	omap_dsi_release_vc(dssdev, td->channel);
err_req_vc:
863 864
	if (panel_data->use_ext_te)
		free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
865
err_irq:
866 867
	if (panel_data->use_ext_te)
		gpio_free(panel_data->ext_te_gpio);
868
err_gpio:
869
	backlight_device_unregister(bldev);
870
err_bl:
871
	destroy_workqueue(td->esd_wq);
872
err_wq:
873 874
	free_regulators(panel_config->regulators, panel_config->num_regulators);
err_reg:
875
	kfree(td);
876
err:
877 878 879
	return r;
}

880
static void __exit taal_remove(struct omap_dss_device *dssdev)
881 882
{
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
883
	struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
884 885 886 887 888
	struct backlight_device *bldev;

	dev_dbg(&dssdev->dev, "remove\n");

	sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
889
	omap_dsi_release_vc(dssdev, td->channel);
890

891 892
	if (panel_data->use_ext_te) {
		int gpio = panel_data->ext_te_gpio;
893 894 895 896 897 898 899 900 901
		free_irq(gpio_to_irq(gpio), dssdev);
		gpio_free(gpio);
	}

	bldev = td->bldev;
	bldev->props.power = FB_BLANK_POWERDOWN;
	taal_bl_update_status(bldev);
	backlight_device_unregister(bldev);

902
	taal_cancel_esd_work(dssdev);
903 904
	destroy_workqueue(td->esd_wq);

905 906 907
	/* reset, to be sure that the panel is in a valid state */
	taal_hw_reset(dssdev);

908 909 910
	free_regulators(td->panel_config->regulators,
			td->panel_config->num_regulators);

911 912 913
	kfree(td);
}

914
static int taal_power_on(struct omap_dss_device *dssdev)
915 916 917 918 919
{
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
	u8 id1, id2, id3;
	int r;

920 921 922 923 924 925
	r = omapdss_dsi_display_enable(dssdev);
	if (r) {
		dev_err(&dssdev->dev, "failed to enable DSI\n");
		goto err0;
	}

926 927
	taal_hw_reset(dssdev);

928
	omapdss_dsi_vc_enable_hs(td->channel, false);
929

930 931 932 933
	r = taal_sleep_out(td);
	if (r)
		goto err;

934
	r = taal_get_id(td, &id1, &id2, &id3);
935 936 937
	if (r)
		goto err;

938 939 940
	/* on early Taal revisions CABC is broken */
	if (td->panel_config->type == PANEL_TAAL &&
		(id2 == 0x00 || id2 == 0xff || id2 == 0x81))
941 942
		td->cabc_broken = true;

943
	r = taal_dcs_write_1(td, DCS_BRIGHTNESS, 0xff);
944 945
	if (r)
		goto err;
946

947
	r = taal_dcs_write_1(td, DCS_CTRL_DISPLAY,
948 949 950
			(1<<2) | (1<<5));	/* BL | BCTRL */
	if (r)
		goto err;
951

952
	r = taal_dcs_write_1(td, DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
953 954
	if (r)
		goto err;
955

956
	r = taal_set_addr_mode(td, td->rotate, td->mirror);
957 958 959 960
	if (r)
		goto err;

	if (!td->cabc_broken) {
961
		r = taal_dcs_write_1(td, DCS_WRITE_CABC, td->cabc_mode);
962 963 964 965
		if (r)
			goto err;
	}

966
	r = taal_dcs_write_0(td, DCS_DISPLAY_ON);
967 968
	if (r)
		goto err;
969

970 971 972 973
	r = _taal_enable_te(dssdev, td->te_enabled);
	if (r)
		goto err;

974 975 976
	td->enabled = 1;

	if (!td->intro_printed) {
977 978
		dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
			td->panel_config->name, id1, id2, id3);
979 980 981 982 983 984
		if (td->cabc_broken)
			dev_info(&dssdev->dev,
					"old Taal version, CABC disabled\n");
		td->intro_printed = true;
	}

985
	omapdss_dsi_vc_enable_hs(td->channel, true);
986

987 988
	return 0;
err:
989 990 991 992
	dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");

	taal_hw_reset(dssdev);

993
	omapdss_dsi_display_disable(dssdev, true, false);
994
err0:
995 996 997
	return r;
}

998
static void taal_power_off(struct omap_dss_device *dssdev)
999 1000
{
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1001
	int r;
1002

1003
	r = taal_dcs_write_0(td, DCS_DISPLAY_OFF);
1004 1005
	if (!r) {
		r = taal_sleep_in(td);
1006
		/* HACK: wait a bit so that the message goes through */
1007 1008
		msleep(10);
	}
1009

1010 1011 1012 1013 1014
	if (r) {
		dev_err(&dssdev->dev,
				"error disabling panel, issuing HW reset\n");
		taal_hw_reset(dssdev);
	}
1015

1016
	omapdss_dsi_display_disable(dssdev, true, false);
1017

1018
	td->enabled = 0;
1019 1020
}

1021 1022 1023 1024 1025 1026 1027 1028 1029
static int taal_panel_reset(struct omap_dss_device *dssdev)
{
	dev_err(&dssdev->dev, "performing LCD reset\n");

	taal_power_off(dssdev);
	taal_hw_reset(dssdev);
	return taal_power_on(dssdev);
}

1030 1031
static int taal_enable(struct omap_dss_device *dssdev)
{
1032
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1033
	int r;
1034

1035 1036
	dev_dbg(&dssdev->dev, "enable\n");

1037 1038 1039 1040 1041 1042
	mutex_lock(&td->lock);

	if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
		r = -EINVAL;
		goto err;
	}
1043

1044 1045
	dsi_bus_lock();

1046
	r = taal_power_on(dssdev);
1047 1048 1049

	dsi_bus_unlock();

1050
	if (r)
1051
		goto err;
1052

1053
	taal_queue_esd_work(dssdev);
1054

1055 1056
	dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;

1057 1058 1059 1060 1061 1062
	mutex_unlock(&td->lock);

	return 0;
err:
	dev_dbg(&dssdev->dev, "enable failed\n");
	mutex_unlock(&td->lock);
1063 1064 1065 1066 1067
	return r;
}

static void taal_disable(struct omap_dss_device *dssdev)
{
1068 1069
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);

1070 1071
	dev_dbg(&dssdev->dev, "disable\n");

1072 1073
	mutex_lock(&td->lock);

1074
	taal_cancel_esd_work(dssdev);
1075

1076 1077
	dsi_bus_lock();

1078 1079 1080
	if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
		taal_power_off(dssdev);

1081 1082
	dsi_bus_unlock();

1083
	dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1084 1085

	mutex_unlock(&td->lock);
1086 1087 1088 1089
}

static int taal_suspend(struct omap_dss_device *dssdev)
{
1090 1091 1092
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
	int r;

1093
	dev_dbg(&dssdev->dev, "suspend\n");
1094

1095 1096 1097 1098 1099 1100
	mutex_lock(&td->lock);

	if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
		r = -EINVAL;
		goto err;
	}
1101

1102
	taal_cancel_esd_work(dssdev);
1103

1104 1105
	dsi_bus_lock();

1106
	taal_power_off(dssdev);
1107 1108 1109

	dsi_bus_unlock();

1110
	dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
1111

1112 1113
	mutex_unlock(&td->lock);

1114
	return 0;
1115 1116 1117
err:
	mutex_unlock(&td->lock);
	return r;
1118 1119 1120 1121
}

static int taal_resume(struct omap_dss_device *dssdev)
{
1122
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1123
	int r;
1124

1125
	dev_dbg(&dssdev->dev, "resume\n");
1126

1127 1128 1129 1130 1131 1132
	mutex_lock(&td->lock);

	if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
		r = -EINVAL;
		goto err;
	}
1133

1134 1135
	dsi_bus_lock();

1136
	r = taal_power_on(dssdev);
1137 1138 1139

	dsi_bus_unlock();

1140
	if (r) {
1141
		dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1142
	} else {
1143
		dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1144
		taal_queue_esd_work(dssdev);
1145
	}
1146 1147 1148 1149 1150 1151

	mutex_unlock(&td->lock);

	return r;
err:
	mutex_unlock(&td->lock);
1152
	return r;
1153 1154
}

1155 1156 1157 1158 1159 1160 1161
static void taal_framedone_cb(int err, void *data)
{
	struct omap_dss_device *dssdev = data;
	dev_dbg(&dssdev->dev, "framedone, err %d\n", err);
	dsi_bus_unlock();
}

1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173
static irqreturn_t taal_te_isr(int irq, void *data)
{
	struct omap_dss_device *dssdev = data;
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
	int old;
	int r;

	old = atomic_cmpxchg(&td->do_update, 1, 0);

	if (old) {
		cancel_delayed_work(&td->te_timeout_work);

1174
		r = omap_dsi_update(dssdev, td->channel,
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
				td->update_region.x,
				td->update_region.y,
				td->update_region.w,
				td->update_region.h,
				taal_framedone_cb, dssdev);
		if (r)
			goto err;
	}

	return IRQ_HANDLED;
err:
	dev_err(&dssdev->dev, "start update failed\n");
	dsi_bus_unlock();
	return IRQ_HANDLED;
}

static void taal_te_timeout_work_callback(struct work_struct *work)
{
	struct taal_data *td = container_of(work, struct taal_data,
					te_timeout_work.work);
	struct omap_dss_device *dssdev = td->dssdev;

	dev_err(&dssdev->dev, "TE not received for 250ms!\n");

	atomic_set(&td->do_update, 0);
	dsi_bus_unlock();
}

1203
static int taal_update(struct omap_dss_device *dssdev,
1204 1205
				    u16 x, u16 y, u16 w, u16 h)
{
1206
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1207
	struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1208 1209 1210 1211
	int r;

	dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);

1212
	mutex_lock(&td->lock);
1213 1214 1215 1216 1217 1218 1219
	dsi_bus_lock();

	if (!td->enabled) {
		r = 0;
		goto err;
	}

1220
	r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true);
1221 1222 1223
	if (r)
		goto err;

1224
	r = taal_set_update_window(td, x, y, w, h);
1225 1226 1227
	if (r)
		goto err;

1228
	if (td->te_enabled && panel_data->use_ext_te) {
1229 1230 1231 1232 1233 1234 1235 1236 1237
		td->update_region.x = x;
		td->update_region.y = y;
		td->update_region.w = w;
		td->update_region.h = h;
		barrier();
		schedule_delayed_work(&td->te_timeout_work,
				msecs_to_jiffies(250));
		atomic_set(&td->do_update, 1);
	} else {
1238
		r = omap_dsi_update(dssdev, td->channel, x, y, w, h,
1239 1240 1241 1242
				taal_framedone_cb, dssdev);
		if (r)
			goto err;
	}
1243 1244

	/* note: no bus_unlock here. unlock is in framedone_cb */
1245
	mutex_unlock(&td->lock);
1246 1247 1248
	return 0;
err:
	dsi_bus_unlock();
1249
	mutex_unlock(&td->lock);
1250 1251 1252 1253 1254
	return r;
}

static int taal_sync(struct omap_dss_device *dssdev)
{
1255 1256
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);

1257 1258
	dev_dbg(&dssdev->dev, "sync\n");

1259
	mutex_lock(&td->lock);
1260 1261
	dsi_bus_lock();
	dsi_bus_unlock();
1262
	mutex_unlock(&td->lock);
1263 1264 1265 1266

	dev_dbg(&dssdev->dev, "sync done\n");

	return 0;
1267 1268
}

1269
static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
1270
{
1271
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1272
	struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1273 1274 1275
	int r;

	if (enable)
1276
		r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
1277
	else
1278
		r = taal_dcs_write_0(td, DCS_TEAR_OFF);
1279

1280
	if (!panel_data->use_ext_te)
1281
		omapdss_dsi_enable_te(dssdev, enable);
1282

1283 1284
	if (td->panel_config->sleep.enable_te)
		msleep(td->panel_config->sleep.enable_te);
1285

1286 1287 1288 1289 1290
	return r;
}

static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
{
1291
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1292 1293
	int r;

1294
	mutex_lock(&td->lock);
1295 1296 1297 1298

	if (td->te_enabled == enable)
		goto end;

1299 1300
	dsi_bus_lock();

1301 1302 1303 1304 1305 1306 1307
	if (td->enabled) {
		r = _taal_enable_te(dssdev, enable);
		if (r)
			goto err;
	}

	td->te_enabled = enable;
1308

1309
	dsi_bus_unlock();
1310
end:
1311
	mutex_unlock(&td->lock);
1312

1313 1314 1315 1316 1317
	return 0;
err:
	dsi_bus_unlock();
	mutex_unlock(&td->lock);

1318 1319 1320
	return r;
}

1321 1322 1323
static int taal_get_te(struct omap_dss_device *dssdev)
{
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1324 1325 1326 1327 1328 1329 1330
	int r;

	mutex_lock(&td->lock);
	r = td->te_enabled;
	mutex_unlock(&td->lock);

	return r;
1331 1332
}

1333 1334 1335 1336 1337 1338 1339
static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
{
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
	int r;

	dev_dbg(&dssdev->dev, "rotate %d\n", rotate);

1340
	mutex_lock(&td->lock);
1341 1342 1343 1344

	if (td->rotate == rotate)
		goto end;

1345 1346
	dsi_bus_lock();

1347
	if (td->enabled) {
1348
		r = taal_set_addr_mode(td, rotate, td->mirror);
1349
		if (r)
1350
			goto err;
1351 1352 1353 1354
	}

	td->rotate = rotate;

1355
	dsi_bus_unlock();
1356
end:
1357
	mutex_unlock(&td->lock);
1358
	return 0;
1359 1360
err:
	dsi_bus_unlock();
1361
	mutex_unlock(&td->lock);
1362
	return r;
1363 1364 1365 1366 1367
}

static u8 taal_get_rotate(struct omap_dss_device *dssdev)
{
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1368 1369 1370 1371 1372 1373 1374
	int r;

	mutex_lock(&td->lock);
	r = td->rotate;
	mutex_unlock(&td->lock);

	return r;
1375 1376 1377 1378 1379 1380 1381 1382 1383
}

static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
{
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
	int r;

	dev_dbg(&dssdev->dev, "mirror %d\n", enable);

1384
	mutex_lock(&td->lock);
1385 1386 1387 1388

	if (td->mirror == enable)
		goto end;

1389
	dsi_bus_lock();
1390
	if (td->enabled) {
1391
		r = taal_set_addr_mode(td, td->rotate, enable);
1392
		if (r)
1393
			goto err;
1394 1395 1396 1397
	}

	td->mirror = enable;

1398
	dsi_bus_unlock();
1399
end:
1400
	mutex_unlock(&td->lock);
1401
	return 0;
1402 1403
err:
	dsi_bus_unlock();
1404
	mutex_unlock(&td->lock);
1405
	return r;
1406 1407 1408 1409 1410
}

static bool taal_get_mirror(struct omap_dss_device *dssdev)
{
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1411 1412 1413 1414 1415 1416 1417
	int r;

	mutex_lock(&td->lock);
	r = td->mirror;
	mutex_unlock(&td->lock);

	return r;
1418 1419 1420 1421
}

static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
{
1422
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1423 1424 1425
	u8 id1, id2, id3;
	int r;

1426
	mutex_lock(&td->lock);
1427 1428 1429 1430 1431 1432

	if (!td->enabled) {
		r = -ENODEV;
		goto err1;
	}

T
Tomi Valkeinen 已提交
1433 1434
	dsi_bus_lock();

1435
	r = taal_dcs_read_1(td, DCS_GET_ID1, &id1);
1436
	if (r)
1437
		goto err2;
1438
	r = taal_dcs_read_1(td, DCS_GET_ID2, &id2);
1439
	if (r)
1440
		goto err2;
1441
	r = taal_dcs_read_1(td, DCS_GET_ID3, &id3);
1442
	if (r)
1443
		goto err2;
1444

T
Tomi Valkeinen 已提交
1445
	dsi_bus_unlock();
1446
	mutex_unlock(&td->lock);
1447
	return 0;
1448
err2:
T
Tomi Valkeinen 已提交
1449
	dsi_bus_unlock();
1450
err1:
1451
	mutex_unlock(&td->lock);
T
Tomi Valkeinen 已提交
1452
	return r;
1453 1454 1455 1456 1457 1458 1459 1460 1461 1462
}

static int taal_memory_read(struct omap_dss_device *dssdev,
		void *buf, size_t size,
		u16 x, u16 y, u16 w, u16 h)
{
	int r;
	int first = 1;
	int plen;
	unsigned buf_used = 0;
T
Tomi Valkeinen 已提交
1463 1464
	struct taal_data *td = dev_get_drvdata(&dssdev->dev);

1465 1466 1467
	if (size < w * h * 3)
		return -ENOMEM;

1468 1469 1470 1471 1472 1473 1474
	mutex_lock(&td->lock);

	if (!td->enabled) {
		r = -ENODEV;
		goto err1;
	}

1475 1476 1477 1478
	size = min(w * h * 3,
			dssdev->panel.timings.x_res *
			dssdev->panel.timings.y_res * 3);

T
Tomi Valkeinen 已提交
1479 1480
	dsi_bus_lock();

1481 1482 1483 1484 1485 1486 1487 1488
	/* plen 1 or 2 goes into short packet. until checksum error is fixed,
	 * use short packets. plen 32 works, but bigger packets seem to cause
	 * an error. */
	if (size % 2)
		plen = 1;
	else
		plen = 2;

1489
	taal_set_update_window(td, x, y, w, h);
1490

1491
	r = dsi_vc_set_max_rx_packet_size(td->channel, plen);
1492
	if (r)
1493
		goto err2;
1494 1495 1496 1497 1498

	while (buf_used < size) {
		u8 dcs_cmd = first ? 0x2e : 0x3e;
		first = 0;

1499
		r = dsi_vc_dcs_read(td->channel, dcs_cmd,
1500 1501 1502 1503
				buf + buf_used, size - buf_used);

		if (r < 0) {
			dev_err(&dssdev->dev, "read error\n");
1504
			goto err3;
1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517
		}

		buf_used += r;

		if (r < plen) {
			dev_err(&dssdev->dev, "short read\n");
			break;
		}

		if (signal_pending(current)) {
			dev_err(&dssdev->dev, "signal pending, "
					"aborting memory read\n");
			r = -ERESTARTSYS;
1518
			goto err3;
1519 1520 1521 1522 1523
		}
	}

	r = buf_used;

1524
err3:
1525
	dsi_vc_set_max_rx_packet_size(td->channel, 1);
1526
err2:
T
Tomi Valkeinen 已提交
1527
	dsi_bus_unlock();
1528 1529
err1:
	mutex_unlock(&td->lock);
1530 1531 1532 1533 1534 1535 1536 1537
	return r;
}

static void taal_esd_work(struct work_struct *work)
{
	struct taal_data *td = container_of(work, struct taal_data,
			esd_work.work);
	struct omap_dss_device *dssdev = td->dssdev;
1538
	struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1539 1540 1541
	u8 state1, state2;
	int r;

1542 1543 1544 1545
	mutex_lock(&td->lock);

	if (!td->enabled) {
		mutex_unlock(&td->lock);
1546
		return;
1547
	}
1548 1549 1550

	dsi_bus_lock();

1551
	r = taal_dcs_read_1(td, DCS_RDDSDR, &state1);
1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563
	if (r) {
		dev_err(&dssdev->dev, "failed to read Taal status\n");
		goto err;
	}

	/* Run self diagnostics */
	r = taal_sleep_out(td);
	if (r) {
		dev_err(&dssdev->dev, "failed to run Taal self-diagnostics\n");
		goto err;
	}

1564
	r = taal_dcs_read_1(td, DCS_RDDSDR, &state2);
1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578
	if (r) {
		dev_err(&dssdev->dev, "failed to read Taal status\n");
		goto err;
	}

	/* Each sleep out command will trigger a self diagnostic and flip
	 * Bit6 if the test passes.
	 */
	if (!((state1 ^ state2) & (1 << 6))) {
		dev_err(&dssdev->dev, "LCD self diagnostics failed\n");
		goto err;
	}
	/* Self-diagnostics result is also shown on TE GPIO line. We need
	 * to re-enable TE after self diagnostics */
1579
	if (td->te_enabled && panel_data->use_ext_te) {
1580
		r = taal_dcs_write_1(td, DCS_TEAR_ON, 0);
T
Tomi Valkeinen 已提交
1581 1582 1583
		if (r)
			goto err;
	}
1584 1585 1586

	dsi_bus_unlock();

1587
	taal_queue_esd_work(dssdev);
1588

1589
	mutex_unlock(&td->lock);
1590 1591 1592 1593
	return;
err:
	dev_err(&dssdev->dev, "performing LCD reset\n");

1594
	taal_panel_reset(dssdev);
1595 1596 1597

	dsi_bus_unlock();

1598
	taal_queue_esd_work(dssdev);
1599 1600

	mutex_unlock(&td->lock);
1601 1602
}

1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616
static int taal_set_update_mode(struct omap_dss_device *dssdev,
		enum omap_dss_update_mode mode)
{
	if (mode != OMAP_DSS_UPDATE_MANUAL)
		return -EINVAL;
	return 0;
}

static enum omap_dss_update_mode taal_get_update_mode(
		struct omap_dss_device *dssdev)
{
	return OMAP_DSS_UPDATE_MANUAL;
}

1617 1618
static struct omap_dss_driver taal_driver = {
	.probe		= taal_probe,
1619
	.remove		= __exit_p(taal_remove),
1620 1621 1622 1623 1624 1625

	.enable		= taal_enable,
	.disable	= taal_disable,
	.suspend	= taal_suspend,
	.resume		= taal_resume,

1626 1627
	.set_update_mode = taal_set_update_mode,
	.get_update_mode = taal_get_update_mode,
1628 1629 1630 1631

	.update		= taal_update,
	.sync		= taal_sync,

1632
	.get_resolution	= taal_get_resolution,
1633 1634
	.get_recommended_bpp = omapdss_default_get_recommended_bpp,

1635
	.enable_te	= taal_enable_te,
1636 1637
	.get_te		= taal_get_te,

1638 1639 1640 1641 1642 1643 1644
	.set_rotate	= taal_rotate,
	.get_rotate	= taal_get_rotate,
	.set_mirror	= taal_mirror,
	.get_mirror	= taal_get_mirror,
	.run_test	= taal_run_test,
	.memory_read	= taal_memory_read,

1645 1646
	.get_timings	= taal_get_timings,

1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670
	.driver         = {
		.name   = "taal",
		.owner  = THIS_MODULE,
	},
};

static int __init taal_init(void)
{
	omap_dss_register_driver(&taal_driver);

	return 0;
}

static void __exit taal_exit(void)
{
	omap_dss_unregister_driver(&taal_driver);
}

module_init(taal_init);
module_exit(taal_exit);

MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
MODULE_DESCRIPTION("Taal Driver");
MODULE_LICENSE("GPL");