panel-sony-acx565akm.c 18.7 KB
Newer Older
1 2 3 4 5 6
/*
 * Sony ACX565AKM LCD Panel driver
 *
 * Copyright (C) 2010 Nokia Corporation
 *
 * Original Driver Author: Imre Deak <imre.deak@nokia.com>
T
Tomi Valkeinen 已提交
7
 * Based on panel-generic.c by Tomi Valkeinen <tomi.valkeinen@ti.com>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 * Adapted to new DSS2 framework: Roger Quadros <roger.quadros@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/>.
 */

23 24 25 26
#include <linux/backlight.h>
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
#include <linux/jiffies.h>
27 28 29 30
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/sched.h>
31
#include <linux/spi/spi.h>
32

33 34
#include "../dss/omapdss.h"

35 36 37 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
#define MIPID_CMD_READ_DISP_ID		0x04
#define MIPID_CMD_READ_RED		0x06
#define MIPID_CMD_READ_GREEN		0x07
#define MIPID_CMD_READ_BLUE		0x08
#define MIPID_CMD_READ_DISP_STATUS	0x09
#define MIPID_CMD_RDDSDR		0x0F
#define MIPID_CMD_SLEEP_IN		0x10
#define MIPID_CMD_SLEEP_OUT		0x11
#define MIPID_CMD_DISP_OFF		0x28
#define MIPID_CMD_DISP_ON		0x29
#define MIPID_CMD_WRITE_DISP_BRIGHTNESS	0x51
#define MIPID_CMD_READ_DISP_BRIGHTNESS	0x52
#define MIPID_CMD_WRITE_CTRL_DISP	0x53

#define CTRL_DISP_BRIGHTNESS_CTRL_ON	(1 << 5)
#define CTRL_DISP_AMBIENT_LIGHT_CTRL_ON	(1 << 4)
#define CTRL_DISP_BACKLIGHT_ON		(1 << 2)
#define CTRL_DISP_AUTO_BRIGHTNESS_ON	(1 << 1)

#define MIPID_CMD_READ_CTRL_DISP	0x54
#define MIPID_CMD_WRITE_CABC		0x55
#define MIPID_CMD_READ_CABC		0x56

#define MIPID_VER_LPH8923		3
#define MIPID_VER_LS041Y3		4
#define MIPID_VER_L4F00311		8
#define MIPID_VER_ACX565AKM		9

struct panel_drv_data {
	struct omap_dss_device	dssdev;

66
	struct gpio_desc *reset_gpio;
67

68
	struct videomode vm;
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88

	char		*name;
	int		enabled;
	int		model;
	int		revision;
	u8		display_id[3];
	unsigned	has_bc:1;
	unsigned	has_cabc:1;
	unsigned	cabc_mode;
	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 spi_device	*spi;
	struct mutex		mutex;

	struct backlight_device *bl_dev;
};

89
static const struct videomode acx565akm_panel_vm = {
90
	.hactive	= 800,
91
	.vactive	= 480,
92
	.pixelclock	= 24000000,
93
	.hfront_porch	= 28,
94
	.hsync_len	= 4,
95
	.hback_porch	= 24,
96
	.vfront_porch	= 3,
97
	.vsync_len	= 3,
98
	.vback_porch	= 4,
99

100
	.flags		= DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW |
101 102
			  DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_NEGEDGE |
			  DISPLAY_FLAGS_PIXDATA_POSEDGE,
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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
};

#define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)

static void acx565akm_transfer(struct panel_drv_data *ddata, int cmd,
			      const u8 *wbuf, int wlen, u8 *rbuf, int rlen)
{
	struct spi_message	m;
	struct spi_transfer	*x, xfer[5];
	int			r;

	BUG_ON(ddata->spi == NULL);

	spi_message_init(&m);

	memset(xfer, 0, sizeof(xfer));
	x = &xfer[0];

	cmd &=  0xff;
	x->tx_buf = &cmd;
	x->bits_per_word = 9;
	x->len = 2;

	if (rlen > 1 && wlen == 0) {
		/*
		 * Between the command and the response data there is a
		 * dummy clock cycle. Add an extra bit after the command
		 * word to account for this.
		 */
		x->bits_per_word = 10;
		cmd <<= 1;
	}
	spi_message_add_tail(x, &m);

	if (wlen) {
		x++;
		x->tx_buf = wbuf;
		x->len = wlen;
		x->bits_per_word = 9;
		spi_message_add_tail(x, &m);
	}

	if (rlen) {
		x++;
		x->rx_buf	= rbuf;
		x->len		= rlen;
		spi_message_add_tail(x, &m);
	}

	r = spi_sync(ddata->spi, &m);
	if (r < 0)
		dev_dbg(&ddata->spi->dev, "spi_sync %d\n", r);
}

static inline void acx565akm_cmd(struct panel_drv_data *ddata, int cmd)
{
	acx565akm_transfer(ddata, cmd, NULL, 0, NULL, 0);
}

static inline void acx565akm_write(struct panel_drv_data *ddata,
			       int reg, const u8 *buf, int len)
{
	acx565akm_transfer(ddata, reg, buf, len, NULL, 0);
}

static inline void acx565akm_read(struct panel_drv_data *ddata,
			      int reg, u8 *buf, int len)
{
	acx565akm_transfer(ddata, reg, NULL, 0, buf, len);
}

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

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

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

static void set_sleep_mode(struct panel_drv_data *ddata, int on)
{
	int cmd;

	if (on)
		cmd = MIPID_CMD_SLEEP_IN;
	else
		cmd = MIPID_CMD_SLEEP_OUT;
	/*
	 * We have to keep 120msec between sleep in/out commands.
	 * (8.2.15, 8.2.16).
	 */
	hw_guard_wait(ddata);
	acx565akm_cmd(ddata, cmd);
	hw_guard_start(ddata, 120);
}

static void set_display_state(struct panel_drv_data *ddata, int enabled)
{
	int cmd = enabled ? MIPID_CMD_DISP_ON : MIPID_CMD_DISP_OFF;

	acx565akm_cmd(ddata, cmd);
}

static int panel_enabled(struct panel_drv_data *ddata)
{
216
	__be32 v;
217 218 219
	u32 disp_status;
	int enabled;

220 221
	acx565akm_read(ddata, MIPID_CMD_READ_DISP_STATUS, (u8 *)&v, 4);
	disp_status = __be32_to_cpu(v);
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
	enabled = (disp_status & (1 << 17)) && (disp_status & (1 << 10));
	dev_dbg(&ddata->spi->dev,
		"LCD panel %senabled by bootloader (status 0x%04x)\n",
		enabled ? "" : "not ", disp_status);
	return enabled;
}

static int panel_detect(struct panel_drv_data *ddata)
{
	acx565akm_read(ddata, MIPID_CMD_READ_DISP_ID, ddata->display_id, 3);
	dev_dbg(&ddata->spi->dev, "MIPI display ID: %02x%02x%02x\n",
		ddata->display_id[0],
		ddata->display_id[1],
		ddata->display_id[2]);

	switch (ddata->display_id[0]) {
	case 0x10:
		ddata->model = MIPID_VER_ACX565AKM;
		ddata->name = "acx565akm";
		ddata->has_bc = 1;
		ddata->has_cabc = 1;
		break;
	case 0x29:
		ddata->model = MIPID_VER_L4F00311;
		ddata->name = "l4f00311";
		break;
	case 0x45:
		ddata->model = MIPID_VER_LPH8923;
		ddata->name = "lph8923";
		break;
	case 0x83:
		ddata->model = MIPID_VER_LS041Y3;
		ddata->name = "ls041y3";
		break;
	default:
		ddata->name = "unknown";
		dev_err(&ddata->spi->dev, "invalid display ID\n");
		return -ENODEV;
	}

	ddata->revision = ddata->display_id[1];

	dev_info(&ddata->spi->dev, "omapfb: %s rev %02x LCD detected\n",
			ddata->name, ddata->revision);

	return 0;
}

/*----------------------Backlight Control-------------------------*/

static void enable_backlight_ctrl(struct panel_drv_data *ddata, int enable)
{
	u16 ctrl;

	acx565akm_read(ddata, MIPID_CMD_READ_CTRL_DISP, (u8 *)&ctrl, 1);
	if (enable) {
		ctrl |= CTRL_DISP_BRIGHTNESS_CTRL_ON |
			CTRL_DISP_BACKLIGHT_ON;
	} else {
		ctrl &= ~(CTRL_DISP_BRIGHTNESS_CTRL_ON |
			  CTRL_DISP_BACKLIGHT_ON);
	}

	ctrl |= 1 << 8;
	acx565akm_write(ddata, MIPID_CMD_WRITE_CTRL_DISP, (u8 *)&ctrl, 2);
}

289
static void set_cabc_mode(struct panel_drv_data *ddata, unsigned int mode)
290 291 292 293 294 295 296 297 298 299 300 301 302
{
	u16 cabc_ctrl;

	ddata->cabc_mode = mode;
	if (!ddata->enabled)
		return;
	cabc_ctrl = 0;
	acx565akm_read(ddata, MIPID_CMD_READ_CABC, (u8 *)&cabc_ctrl, 1);
	cabc_ctrl &= ~3;
	cabc_ctrl |= (1 << 8) | (mode & 3);
	acx565akm_write(ddata, MIPID_CMD_WRITE_CABC, (u8 *)&cabc_ctrl, 2);
}

303
static unsigned int get_cabc_mode(struct panel_drv_data *ddata)
304 305 306 307
{
	return ddata->cabc_mode;
}

308
static unsigned int get_hw_cabc_mode(struct panel_drv_data *ddata)
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
{
	u8 cabc_ctrl;

	acx565akm_read(ddata, MIPID_CMD_READ_CABC, &cabc_ctrl, 1);
	return cabc_ctrl & 3;
}

static void acx565akm_set_brightness(struct panel_drv_data *ddata, int level)
{
	int bv;

	bv = level | (1 << 8);
	acx565akm_write(ddata, MIPID_CMD_WRITE_DISP_BRIGHTNESS, (u8 *)&bv, 2);

	if (level)
		enable_backlight_ctrl(ddata, 1);
	else
		enable_backlight_ctrl(ddata, 0);
}

static int acx565akm_get_actual_brightness(struct panel_drv_data *ddata)
{
	u8 bv;

	acx565akm_read(ddata, MIPID_CMD_READ_DISP_BRIGHTNESS, &bv, 1);

	return bv;
}


static int acx565akm_bl_update_status(struct backlight_device *dev)
{
	struct panel_drv_data *ddata = dev_get_drvdata(&dev->dev);
	int level;

	dev_dbg(&ddata->spi->dev, "%s\n", __func__);

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

	if (ddata->has_bc)
		acx565akm_set_brightness(ddata, level);
	else
355
		return -ENODEV;
356

357
	return 0;
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
}

static int acx565akm_bl_get_intensity(struct backlight_device *dev)
{
	struct panel_drv_data *ddata = dev_get_drvdata(&dev->dev);

	dev_dbg(&dev->dev, "%s\n", __func__);

	if (!ddata->has_bc)
		return -ENODEV;

	if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
			dev->props.power == FB_BLANK_UNBLANK) {
		if (ddata->has_bc)
			return acx565akm_get_actual_brightness(ddata);
		else
			return dev->props.brightness;
	}

	return 0;
}

380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
static int acx565akm_bl_update_status_locked(struct backlight_device *dev)
{
	struct panel_drv_data *ddata = dev_get_drvdata(&dev->dev);
	int r;

	mutex_lock(&ddata->mutex);
	r = acx565akm_bl_update_status(dev);
	mutex_unlock(&ddata->mutex);

	return r;
}

static int acx565akm_bl_get_intensity_locked(struct backlight_device *dev)
{
	struct panel_drv_data *ddata = dev_get_drvdata(&dev->dev);
	int r;

	mutex_lock(&ddata->mutex);
	r = acx565akm_bl_get_intensity(dev);
	mutex_unlock(&ddata->mutex);

	return r;
}

404
static const struct backlight_ops acx565akm_bl_ops = {
405 406
	.get_brightness = acx565akm_bl_get_intensity_locked,
	.update_status  = acx565akm_bl_update_status_locked,
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
};

/*--------------------Auto Brightness control via Sysfs---------------------*/

static const char * const cabc_modes[] = {
	"off",		/* always used 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 panel_drv_data *ddata = dev_get_drvdata(dev);
	const char *mode_str;
	int mode;
	int len;

	if (!ddata->has_cabc)
		mode = 0;
	else
		mode = get_cabc_mode(ddata);
	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 panel_drv_data *ddata = dev_get_drvdata(dev);
	int i;

	for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
		const char *mode_str = cabc_modes[i];
		int cmp_len = strlen(mode_str);

		if (count > 0 && buf[count - 1] == '\n')
			count--;
		if (count != cmp_len)
			continue;

		if (strncmp(buf, mode_str, cmp_len) == 0)
			break;
	}

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

	if (!ddata->has_cabc && i != 0)
		return -EINVAL;

	mutex_lock(&ddata->mutex);
	set_cabc_mode(ddata, i);
	mutex_unlock(&ddata->mutex);

	return count;
}

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

	if (!ddata->has_cabc)
		return snprintf(buf, PAGE_SIZE, "%s\n", cabc_modes[0]);

	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;
}

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);

static struct attribute *bldev_attrs[] = {
	&dev_attr_cabc_mode.attr,
	&dev_attr_cabc_available_modes.attr,
	NULL,
};

503
static const struct attribute_group bldev_attr_group = {
504 505 506
	.attrs = bldev_attrs,
};

507 508
static int acx565akm_connect(struct omap_dss_device *src,
			     struct omap_dss_device *dst)
509 510 511 512
{
	return 0;
}

513 514
static void acx565akm_disconnect(struct omap_dss_device *src,
				 struct omap_dss_device *dst)
515 516 517 518 519 520
{
}

static int acx565akm_panel_power_on(struct omap_dss_device *dssdev)
{
	struct panel_drv_data *ddata = to_panel_data(dssdev);
521
	struct omap_dss_device *src = dssdev->src;
522 523 524 525
	int r;

	dev_dbg(&ddata->spi->dev, "%s\n", __func__);

526
	src->ops->set_timings(src, &ddata->vm);
527

528
	r = src->ops->enable(src);
529 530 531 532 533 534 535 536
	if (r) {
		pr_err("%s sdi enable failed\n", __func__);
		return r;
	}

	/*FIXME tweak me */
	msleep(50);

537 538
	if (ddata->reset_gpio)
		gpiod_set_value(ddata->reset_gpio, 1);
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568

	if (ddata->enabled) {
		dev_dbg(&ddata->spi->dev, "panel already enabled\n");
		return 0;
	}

	/*
	 * We have to meet all the following delay requirements:
	 * 1. tRW: reset pulse width 10usec (7.12.1)
	 * 2. tRT: reset cancel time 5msec (7.12.1)
	 * 3. Providing PCLK,HS,VS signals for 2 frames = ~50msec worst
	 *    case (7.6.2)
	 * 4. 120msec before the sleep out command (7.12.1)
	 */
	msleep(120);

	set_sleep_mode(ddata, 0);
	ddata->enabled = 1;

	/* 5msec between sleep out and the next command. (8.2.16) */
	usleep_range(5000, 10000);
	set_display_state(ddata, 1);
	set_cabc_mode(ddata, ddata->cabc_mode);

	return acx565akm_bl_update_status(ddata->bl_dev);
}

static void acx565akm_panel_power_off(struct omap_dss_device *dssdev)
{
	struct panel_drv_data *ddata = to_panel_data(dssdev);
569
	struct omap_dss_device *src = dssdev->src;
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586

	dev_dbg(dssdev->dev, "%s\n", __func__);

	if (!ddata->enabled)
		return;

	set_display_state(ddata, 0);
	set_sleep_mode(ddata, 1);
	ddata->enabled = 0;
	/*
	 * We have to provide PCLK,HS,VS signals for 2 frames (worst case
	 * ~50msec) after sending the sleep in command and asserting the
	 * reset signal. We probably could assert the reset w/o the delay
	 * but we still delay to avoid possible artifacts. (7.6.1)
	 */
	msleep(50);

587 588
	if (ddata->reset_gpio)
		gpiod_set_value(ddata->reset_gpio, 0);
589 590 591 592

	/* FIXME need to tweak this delay */
	msleep(100);

593
	src->ops->disable(src);
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
}

static int acx565akm_enable(struct omap_dss_device *dssdev)
{
	struct panel_drv_data *ddata = to_panel_data(dssdev);
	int r;

	dev_dbg(dssdev->dev, "%s\n", __func__);

	if (!omapdss_device_is_connected(dssdev))
		return -ENODEV;

	if (omapdss_device_is_enabled(dssdev))
		return 0;

609
	mutex_lock(&ddata->mutex);
610
	r = acx565akm_panel_power_on(dssdev);
611
	mutex_unlock(&ddata->mutex);
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
	if (r)
		return r;

	dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;

	return 0;
}

static void acx565akm_disable(struct omap_dss_device *dssdev)
{
	struct panel_drv_data *ddata = to_panel_data(dssdev);

	dev_dbg(dssdev->dev, "%s\n", __func__);

	if (!omapdss_device_is_enabled(dssdev))
		return;

	mutex_lock(&ddata->mutex);
	acx565akm_panel_power_off(dssdev);
	mutex_unlock(&ddata->mutex);

	dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
}

static void acx565akm_set_timings(struct omap_dss_device *dssdev,
637
				  struct videomode *vm)
638 639
{
	struct panel_drv_data *ddata = to_panel_data(dssdev);
640
	struct omap_dss_device *src = dssdev->src;
641

642
	ddata->vm = *vm;
643

644
	src->ops->set_timings(src, vm);
645 646 647
}

static void acx565akm_get_timings(struct omap_dss_device *dssdev,
648
				  struct videomode *vm)
649 650 651
{
	struct panel_drv_data *ddata = to_panel_data(dssdev);

652
	*vm = ddata->vm;
653 654 655
}

static int acx565akm_check_timings(struct omap_dss_device *dssdev,
656
				   struct videomode *vm)
657
{
658
	struct omap_dss_device *src = dssdev->src;
659

660
	return src->ops->check_timings(src, vm);
661 662
}

663
static const struct omap_dss_driver acx565akm_ops = {
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
	.connect	= acx565akm_connect,
	.disconnect	= acx565akm_disconnect,

	.enable		= acx565akm_enable,
	.disable	= acx565akm_disable,

	.set_timings	= acx565akm_set_timings,
	.get_timings	= acx565akm_get_timings,
	.check_timings	= acx565akm_check_timings,
};

static int acx565akm_probe(struct spi_device *spi)
{
	struct panel_drv_data *ddata;
	struct omap_dss_device *dssdev;
	struct backlight_device *bldev;
	int max_brightness, brightness;
	struct backlight_properties props;
682
	struct gpio_desc *gpio;
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
	int r;

	dev_dbg(&spi->dev, "%s\n", __func__);

	spi->mode = SPI_MODE_3;

	ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
	if (ddata == NULL)
		return -ENOMEM;

	dev_set_drvdata(&spi->dev, ddata);

	ddata->spi = spi;

	mutex_init(&ddata->mutex);

699 700 701 702
	gpio = devm_gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_LOW);
	if (IS_ERR(gpio)) {
		dev_err(&spi->dev, "failed to parse reset gpio\n");
		return PTR_ERR(gpio);
703 704
	}

705 706 707 708
	ddata->reset_gpio = gpio;

	if (ddata->reset_gpio)
		gpiod_set_value(ddata->reset_gpio, 1);
709 710 711 712 713 714 715 716 717 718 719

	/*
	 * After reset we have to wait 5 msec before the first
	 * command can be sent.
	 */
	usleep_range(5000, 10000);

	ddata->enabled = panel_enabled(ddata);

	r = panel_detect(ddata);

720 721
	if (!ddata->enabled && ddata->reset_gpio)
		gpiod_set_value(ddata->reset_gpio, 0);
722 723 724

	if (r) {
		dev_err(&spi->dev, "%s panel detect error\n", __func__);
725
		return r;
726 727 728 729 730 731 732 733 734
	}

	memset(&props, 0, sizeof(props));
	props.fb_blank = FB_BLANK_UNBLANK;
	props.power = FB_BLANK_UNBLANK;
	props.type = BACKLIGHT_RAW;

	bldev = backlight_device_register("acx565akm", &ddata->spi->dev,
			ddata, &acx565akm_bl_ops, &props);
735 736
	if (IS_ERR(bldev))
		return PTR_ERR(bldev);
737 738 739 740 741 742
	ddata->bl_dev = bldev;
	if (ddata->has_cabc) {
		r = sysfs_create_group(&bldev->dev.kobj, &bldev_attr_group);
		if (r) {
			dev_err(&bldev->dev,
				"%s failed to create sysfs files\n", __func__);
743
			goto err_backlight_unregister;
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
		}
		ddata->cabc_mode = get_hw_cabc_mode(ddata);
	}

	max_brightness = 255;

	if (ddata->has_bc)
		brightness = acx565akm_get_actual_brightness(ddata);
	else
		brightness = 0;

	bldev->props.max_brightness = max_brightness;
	bldev->props.brightness = brightness;

	acx565akm_bl_update_status(bldev);


761
	ddata->vm = acx565akm_panel_vm;
762 763 764 765 766 767

	dssdev = &ddata->dssdev;
	dssdev->dev = &spi->dev;
	dssdev->driver = &acx565akm_ops;
	dssdev->type = OMAP_DISPLAY_TYPE_SDI;
	dssdev->owner = THIS_MODULE;
768
	dssdev->of_ports = BIT(0);
769

770
	omapdss_display_init(dssdev);
771
	omapdss_device_register(dssdev);
772 773 774

	return 0;

775
err_backlight_unregister:
776 777 778 779 780 781 782 783 784 785 786 787 788 789
	backlight_device_unregister(bldev);
	return r;
}

static int acx565akm_remove(struct spi_device *spi)
{
	struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
	struct omap_dss_device *dssdev = &ddata->dssdev;

	dev_dbg(&ddata->spi->dev, "%s\n", __func__);

	sysfs_remove_group(&ddata->bl_dev->dev.kobj, &bldev_attr_group);
	backlight_device_unregister(ddata->bl_dev);

790
	omapdss_device_unregister(dssdev);
791 792 793 794 795 796

	acx565akm_disable(dssdev);

	return 0;
}

797 798 799 800
static const struct of_device_id acx565akm_of_match[] = {
	{ .compatible = "omapdss,sony,acx565akm", },
	{},
};
801
MODULE_DEVICE_TABLE(of, acx565akm_of_match);
802

803 804 805
static struct spi_driver acx565akm_driver = {
	.driver = {
		.name	= "acx565akm",
806
		.of_match_table = acx565akm_of_match,
T
Tomi Valkeinen 已提交
807
		.suppress_bind_attrs = true,
808 809 810 811 812 813 814
	},
	.probe	= acx565akm_probe,
	.remove	= acx565akm_remove,
};

module_spi_driver(acx565akm_driver);

815
MODULE_ALIAS("spi:sony,acx565akm");
816 817 818
MODULE_AUTHOR("Nokia Corporation");
MODULE_DESCRIPTION("acx565akm LCD Driver");
MODULE_LICENSE("GPL");