1 From 635f44cfde6c057a2ecbb8c9d9a67225e53b6545 Mon Sep 17 00:00:00 2001
2 From: Roger Quadros <roger.quadros@nokia.com>
3 Date: Wed, 10 Mar 2010 17:32:44 +0200
4 Subject: [PATCH 3/10] OMAP: DSS2: Add ACX565AKM Panel Driver
6 From: Roger Quadros <roger.quadros@nokia.com>
8 Patch-mainline: 2.6.35?
9 Git-repo: http://www.gitorious.org/linux-omap-dss2/linux/commit/4f2308f3be2fe631412ea85a80c91414c3bfe730
11 This is the panel used on Nokia N900
13 Signed-off-by: Roger Quadros <roger.quadros@nokia.com>
15 drivers/video/omap2/displays/Kconfig | 6 +
16 drivers/video/omap2/displays/Makefile | 1 +
17 drivers/video/omap2/displays/panel-acx565akm.c | 760 ++++++++++++++++++++++++
18 3 files changed, 767 insertions(+), 0 deletions(-)
19 create mode 100644 drivers/video/omap2/displays/panel-acx565akm.c
21 diff --git a/drivers/video/omap2/displays/Kconfig b/drivers/video/omap2/displays/Kconfig
22 index b12a59c..1f5b7d1 100644
23 --- a/drivers/video/omap2/displays/Kconfig
24 +++ b/drivers/video/omap2/displays/Kconfig
25 @@ -19,4 +19,10 @@ config PANEL_TAAL
27 Taal DSI command mode panel from TPO.
29 +config PANEL_ACX565AKM
30 + tristate "ACX565AKM Panel"
31 + depends on OMAP2_DSS_SDI
32 + select BACKLIGHT_CLASS_DEVICE
34 + This is the LCD panel used on Nokia N900
36 diff --git a/drivers/video/omap2/displays/Makefile b/drivers/video/omap2/displays/Makefile
37 index 9556464..0af16b7 100644
38 --- a/drivers/video/omap2/displays/Makefile
39 +++ b/drivers/video/omap2/displays/Makefile
40 @@ -2,3 +2,4 @@ obj-$(CONFIG_PANEL_GENERIC) += panel-generic.o
41 obj-$(CONFIG_PANEL_SHARP_LS037V7DW01) += panel-sharp-ls037v7dw01.o
43 obj-$(CONFIG_PANEL_TAAL) += panel-taal.o
44 +obj-$(CONFIG_PANEL_ACX565AKM) += panel-acx565akm.o
45 diff --git a/drivers/video/omap2/displays/panel-acx565akm.c b/drivers/video/omap2/displays/panel-acx565akm.c
47 index 0000000..27e9847
49 +++ b/drivers/video/omap2/displays/panel-acx565akm.c
52 + * Support for ACX565AKM LCD Panel used on Nokia N900
54 + * Copyright (C) 2010 Nokia Corporation
56 + * Original Driver Author: Imre Deak <imre.deak@nokia.com>
57 + * Based on panel-generic.c by Tomi Valkeinen <tomi.valkeinen@nokia.com>
58 + * Adapted to new DSS2 framework: Roger Quadros <roger.quadros@nokia.com>
60 + * This program is free software; you can redistribute it and/or modify it
61 + * under the terms of the GNU General Public License version 2 as published by
62 + * the Free Software Foundation.
64 + * This program is distributed in the hope that it will be useful, but WITHOUT
65 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
66 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
69 + * You should have received a copy of the GNU General Public License along with
70 + * this program. If not, see <http://www.gnu.org/licenses/>.
73 +#include <linux/kernel.h>
74 +#include <linux/module.h>
75 +#include <linux/platform_device.h>
76 +#include <linux/delay.h>
77 +#include <linux/spi/spi.h>
78 +#include <linux/jiffies.h>
79 +#include <linux/sched.h>
80 +#include <linux/backlight.h>
81 +#include <linux/fb.h>
83 +#include <plat/display.h>
85 +#define MIPID_CMD_READ_DISP_ID 0x04
86 +#define MIPID_CMD_READ_RED 0x06
87 +#define MIPID_CMD_READ_GREEN 0x07
88 +#define MIPID_CMD_READ_BLUE 0x08
89 +#define MIPID_CMD_READ_DISP_STATUS 0x09
90 +#define MIPID_CMD_RDDSDR 0x0F
91 +#define MIPID_CMD_SLEEP_IN 0x10
92 +#define MIPID_CMD_SLEEP_OUT 0x11
93 +#define MIPID_CMD_DISP_OFF 0x28
94 +#define MIPID_CMD_DISP_ON 0x29
95 +#define MIPID_CMD_WRITE_DISP_BRIGHTNESS 0x51
96 +#define MIPID_CMD_READ_DISP_BRIGHTNESS 0x52
97 +#define MIPID_CMD_WRITE_CTRL_DISP 0x53
99 +#define CTRL_DISP_BRIGHTNESS_CTRL_ON (1 << 5)
100 +#define CTRL_DISP_AMBIENT_LIGHT_CTRL_ON (1 << 4)
101 +#define CTRL_DISP_BACKLIGHT_ON (1 << 2)
102 +#define CTRL_DISP_AUTO_BRIGHTNESS_ON (1 << 1)
104 +#define MIPID_CMD_READ_CTRL_DISP 0x54
105 +#define MIPID_CMD_WRITE_CABC 0x55
106 +#define MIPID_CMD_READ_CABC 0x56
108 +#define MIPID_VER_LPH8923 3
109 +#define MIPID_VER_LS041Y3 4
110 +#define MIPID_VER_L4F00311 8
111 +#define MIPID_VER_ACX565AKM 9
113 +struct acx565akm_device {
120 + unsigned has_cabc:1;
121 + unsigned cabc_mode;
122 + unsigned long hw_guard_end; /* next value of jiffies
123 + when we can issue the
124 + next sleep in/out command */
125 + unsigned long hw_guard_wait; /* max guard time in jiffies */
127 + struct spi_device *spi;
128 + struct mutex mutex;
130 + struct omap_dss_device *dssdev;
131 + struct backlight_device *bl_dev;
134 +static struct acx565akm_device acx_dev;
135 +static int acx565akm_bl_update_status(struct backlight_device *dev);
137 +/*--------------------MIPID interface-----------------------------*/
139 +static void acx565akm_transfer(struct acx565akm_device *md, int cmd,
140 + const u8 *wbuf, int wlen, u8 *rbuf, int rlen)
142 + struct spi_message m;
143 + struct spi_transfer *x, xfer[5];
146 + BUG_ON(md->spi == NULL);
148 + spi_message_init(&m);
150 + memset(xfer, 0, sizeof(xfer));
155 + x->bits_per_word = 9;
158 + if (rlen > 1 && wlen == 0) {
160 + * Between the command and the response data there is a
161 + * dummy clock cycle. Add an extra bit after the command
162 + * word to account for this.
164 + x->bits_per_word = 10;
167 + spi_message_add_tail(x, &m);
173 + x->bits_per_word = 9;
174 + spi_message_add_tail(x, &m);
181 + spi_message_add_tail(x, &m);
184 + r = spi_sync(md->spi, &m);
186 + dev_dbg(&md->spi->dev, "spi_sync %d\n", r);
189 +static inline void acx565akm_cmd(struct acx565akm_device *md, int cmd)
191 + acx565akm_transfer(md, cmd, NULL, 0, NULL, 0);
194 +static inline void acx565akm_write(struct acx565akm_device *md,
195 + int reg, const u8 *buf, int len)
197 + acx565akm_transfer(md, reg, buf, len, NULL, 0);
200 +static inline void acx565akm_read(struct acx565akm_device *md,
201 + int reg, u8 *buf, int len)
203 + acx565akm_transfer(md, reg, NULL, 0, buf, len);
206 +static void hw_guard_start(struct acx565akm_device *md, int guard_msec)
208 + md->hw_guard_wait = msecs_to_jiffies(guard_msec);
209 + md->hw_guard_end = jiffies + md->hw_guard_wait;
212 +static void hw_guard_wait(struct acx565akm_device *md)
214 + unsigned long wait = md->hw_guard_end - jiffies;
216 + if ((long)wait > 0 && wait <= md->hw_guard_wait) {
217 + set_current_state(TASK_UNINTERRUPTIBLE);
218 + schedule_timeout(wait);
222 +/*----------------------MIPID wrappers----------------------------*/
224 +static void set_sleep_mode(struct acx565akm_device *md, int on)
229 + cmd = MIPID_CMD_SLEEP_IN;
231 + cmd = MIPID_CMD_SLEEP_OUT;
233 + * We have to keep 120msec between sleep in/out commands.
234 + * (8.2.15, 8.2.16).
237 + acx565akm_cmd(md, cmd);
238 + hw_guard_start(md, 120);
241 +static void set_display_state(struct acx565akm_device *md, int enabled)
243 + int cmd = enabled ? MIPID_CMD_DISP_ON : MIPID_CMD_DISP_OFF;
245 + acx565akm_cmd(md, cmd);
248 +static int panel_enabled(struct acx565akm_device *md)
253 + acx565akm_read(md, MIPID_CMD_READ_DISP_STATUS, (u8 *)&disp_status, 4);
254 + disp_status = __be32_to_cpu(disp_status);
255 + enabled = (disp_status & (1 << 17)) && (disp_status & (1 << 10));
256 + dev_dbg(&md->spi->dev,
257 + "LCD panel %senabled by bootloader (status 0x%04x)\n",
258 + enabled ? "" : "not ", disp_status);
262 +static int panel_detect(struct acx565akm_device *md)
264 + acx565akm_read(md, MIPID_CMD_READ_DISP_ID, md->display_id, 3);
265 + dev_dbg(&md->spi->dev, "MIPI display ID: %02x%02x%02x\n",
266 + md->display_id[0], md->display_id[1], md->display_id[2]);
268 + switch (md->display_id[0]) {
270 + md->model = MIPID_VER_ACX565AKM;
271 + md->name = "acx565akm";
276 + md->model = MIPID_VER_L4F00311;
277 + md->name = "l4f00311";
280 + md->model = MIPID_VER_LPH8923;
281 + md->name = "lph8923";
284 + md->model = MIPID_VER_LS041Y3;
285 + md->name = "ls041y3";
288 + md->name = "unknown";
289 + dev_err(&md->spi->dev, "invalid display ID\n");
293 + md->revision = md->display_id[1];
295 + dev_info(&md->spi->dev, "omapfb: %s rev %02x LCD detected\n",
296 + md->name, md->revision);
301 +/*----------------------Backlight Control-------------------------*/
303 +static void enable_backlight_ctrl(struct acx565akm_device *md, int enable)
307 + acx565akm_read(md, MIPID_CMD_READ_CTRL_DISP, (u8 *)&ctrl, 1);
309 + ctrl |= CTRL_DISP_BRIGHTNESS_CTRL_ON |
310 + CTRL_DISP_BACKLIGHT_ON;
312 + ctrl &= ~(CTRL_DISP_BRIGHTNESS_CTRL_ON |
313 + CTRL_DISP_BACKLIGHT_ON);
317 + acx565akm_write(md, MIPID_CMD_WRITE_CTRL_DISP, (u8 *)&ctrl, 2);
320 +static void set_cabc_mode(struct acx565akm_device *md, unsigned mode)
324 + md->cabc_mode = mode;
328 + acx565akm_read(md, MIPID_CMD_READ_CABC, (u8 *)&cabc_ctrl, 1);
330 + cabc_ctrl |= (1 << 8) | (mode & 3);
331 + acx565akm_write(md, MIPID_CMD_WRITE_CABC, (u8 *)&cabc_ctrl, 2);
334 +static unsigned get_cabc_mode(struct acx565akm_device *md)
336 + return md->cabc_mode;
339 +static unsigned get_hw_cabc_mode(struct acx565akm_device *md)
343 + acx565akm_read(md, MIPID_CMD_READ_CABC, &cabc_ctrl, 1);
344 + return cabc_ctrl & 3;
347 +static void acx565akm_set_brightness(struct acx565akm_device *md, int level)
351 + bv = level | (1 << 8);
352 + acx565akm_write(md, MIPID_CMD_WRITE_DISP_BRIGHTNESS, (u8 *)&bv, 2);
355 + enable_backlight_ctrl(md, 1);
357 + enable_backlight_ctrl(md, 0);
360 +static int acx565akm_get_actual_brightness(struct acx565akm_device *md)
364 + acx565akm_read(md, MIPID_CMD_READ_DISP_BRIGHTNESS, &bv, 1);
370 +static int acx565akm_bl_update_status(struct backlight_device *dev)
372 + struct acx565akm_device *md = dev_get_drvdata(&dev->dev);
376 + dev_dbg(&md->spi->dev, "%s\n", __func__);
378 + mutex_lock(&md->mutex);
380 + if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
381 + dev->props.power == FB_BLANK_UNBLANK)
382 + level = dev->props.brightness;
388 + acx565akm_set_brightness(md, level);
389 + else if (md->dssdev->set_backlight)
390 + r = md->dssdev->set_backlight(md->dssdev, level);
394 + mutex_unlock(&md->mutex);
399 +static int acx565akm_bl_get_intensity(struct backlight_device *dev)
401 + struct acx565akm_device *md = dev_get_drvdata(&dev->dev);
403 + dev_dbg(&dev->dev, "%s\n", __func__);
405 + if (!md->has_bc && md->dssdev->set_backlight == NULL)
408 + if (dev->props.fb_blank == FB_BLANK_UNBLANK &&
409 + dev->props.power == FB_BLANK_UNBLANK) {
411 + return acx565akm_get_actual_brightness(md);
413 + return dev->props.brightness;
419 +static struct backlight_ops acx565akm_bl_ops = {
420 + .get_brightness = acx565akm_bl_get_intensity,
421 + .update_status = acx565akm_bl_update_status,
424 +/*--------------------Auto Brightness control via Sysfs---------------------*/
426 +static const char *cabc_modes[] = {
427 + "off", /* always used when CABC is not supported */
433 +static ssize_t show_cabc_mode(struct device *dev,
434 + struct device_attribute *attr,
437 + struct acx565akm_device *md = dev_get_drvdata(dev);
438 + const char *mode_str;
445 + mode = get_cabc_mode(md);
446 + mode_str = "unknown";
447 + if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes))
448 + mode_str = cabc_modes[mode];
449 + len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str);
451 + return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1;
454 +static ssize_t store_cabc_mode(struct device *dev,
455 + struct device_attribute *attr,
456 + const char *buf, size_t count)
458 + struct acx565akm_device *md = dev_get_drvdata(dev);
461 + for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) {
462 + const char *mode_str = cabc_modes[i];
463 + int cmp_len = strlen(mode_str);
465 + if (count > 0 && buf[count - 1] == '\n')
467 + if (count != cmp_len)
470 + if (strncmp(buf, mode_str, cmp_len) == 0)
474 + if (i == ARRAY_SIZE(cabc_modes))
477 + if (!md->has_cabc && i != 0)
480 + mutex_lock(&md->mutex);
481 + set_cabc_mode(md, i);
482 + mutex_unlock(&md->mutex);
487 +static ssize_t show_cabc_available_modes(struct device *dev,
488 + struct device_attribute *attr,
491 + struct acx565akm_device *md = dev_get_drvdata(dev);
496 + return snprintf(buf, PAGE_SIZE, "%s\n", cabc_modes[0]);
498 + for (i = 0, len = 0;
499 + len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++)
500 + len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s",
501 + i ? " " : "", cabc_modes[i],
502 + i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : "");
504 + return len < PAGE_SIZE ? len : PAGE_SIZE - 1;
507 +static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR,
508 + show_cabc_mode, store_cabc_mode);
509 +static DEVICE_ATTR(cabc_available_modes, S_IRUGO,
510 + show_cabc_available_modes, NULL);
512 +static struct attribute *bldev_attrs[] = {
513 + &dev_attr_cabc_mode.attr,
514 + &dev_attr_cabc_available_modes.attr,
518 +static struct attribute_group bldev_attr_group = {
519 + .attrs = bldev_attrs,
522 +/*---------------------------ACX Panel----------------------------*/
524 +static struct omap_video_timings acx_panel_timings = {
527 + .pixel_clock = 24000,
536 +static int acx_panel_probe(struct omap_dss_device *dssdev)
539 + struct acx565akm_device *md = &acx_dev;
540 + struct backlight_device *bldev;
541 + int max_brightness, brightness;
543 + dev_dbg(&dssdev->dev, "%s\n", __func__);
544 + dssdev->panel.config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
546 + /* FIXME AC bias ? */
547 + dssdev->panel.timings = acx_panel_timings;
548 + dssdev->panel.recommended_bpp = 16;
550 + if (dssdev->platform_enable)
551 + dssdev->platform_enable(dssdev);
553 + * After reset we have to wait 5 msec before the first
554 + * command can be sent.
558 + md->enabled = panel_enabled(md);
560 + r = panel_detect(md);
562 + dev_err(&dssdev->dev, "%s panel detect error\n", __func__);
563 + if (!md->enabled && dssdev->platform_disable)
564 + dssdev->platform_disable(dssdev);
568 + mutex_lock(&acx_dev.mutex);
569 + acx_dev.dssdev = dssdev;
570 + mutex_unlock(&acx_dev.mutex);
572 + if (!md->enabled) {
573 + if (dssdev->platform_disable)
574 + dssdev->platform_disable(dssdev);
577 + /*------- Backlight control --------*/
579 + bldev = backlight_device_register("acx565akm", &md->spi->dev,
580 + md, &acx565akm_bl_ops);
581 + md->bl_dev = bldev;
582 + if (md->has_cabc) {
583 + r = sysfs_create_group(&bldev->dev.kobj, &bldev_attr_group);
585 + dev_err(&bldev->dev,
586 + "%s failed to create sysfs files\n", __func__);
587 + backlight_device_unregister(bldev);
590 + md->cabc_mode = get_hw_cabc_mode(md);
593 + bldev->props.fb_blank = FB_BLANK_UNBLANK;
594 + bldev->props.power = FB_BLANK_UNBLANK;
597 + max_brightness = 255;
599 + max_brightness = dssdev->max_backlight_level;
602 + brightness = acx565akm_get_actual_brightness(md);
603 + else if (dssdev->get_backlight)
604 + brightness = dssdev->get_backlight(dssdev);
608 + bldev->props.max_brightness = max_brightness;
609 + bldev->props.brightness = brightness;
611 + acx565akm_bl_update_status(bldev);
615 +static void acx_panel_remove(struct omap_dss_device *dssdev)
617 + struct acx565akm_device *md = &acx_dev;
619 + dev_dbg(&dssdev->dev, "%s\n", __func__);
620 + sysfs_remove_group(&md->bl_dev->dev.kobj, &bldev_attr_group);
621 + backlight_device_unregister(md->bl_dev);
622 + mutex_lock(&acx_dev.mutex);
623 + acx_dev.dssdev = NULL;
624 + mutex_unlock(&acx_dev.mutex);
627 +static int acx_panel_power_on(struct omap_dss_device *dssdev)
629 + struct acx565akm_device *md = &acx_dev;
632 + dev_dbg(&dssdev->dev, "%s\n", __func__);
634 + mutex_lock(&md->mutex);
636 + if (dssdev->platform_enable) {
637 + r = dssdev->platform_enable(dssdev);
643 + dev_dbg(&md->spi->dev, "panel already enabled\n");
644 + mutex_unlock(&md->mutex);
649 + * We have to meet all the following delay requirements:
650 + * 1. tRW: reset pulse width 10usec (7.12.1)
651 + * 2. tRT: reset cancel time 5msec (7.12.1)
652 + * 3. Providing PCLK,HS,VS signals for 2 frames = ~50msec worst
654 + * 4. 120msec before the sleep out command (7.12.1)
658 + set_sleep_mode(md, 0);
661 + /* 5msec between sleep out and the next command. (8.2.16) */
663 + set_display_state(md, 1);
664 + set_cabc_mode(md, md->cabc_mode);
666 + mutex_unlock(&md->mutex);
668 + return acx565akm_bl_update_status(md->bl_dev);
671 +static void acx_panel_power_off(struct omap_dss_device *dssdev)
673 + struct acx565akm_device *md = &acx_dev;
675 + dev_dbg(&dssdev->dev, "%s\n", __func__);
677 + mutex_lock(&md->mutex);
679 + if (!md->enabled) {
680 + mutex_unlock(&md->mutex);
683 + set_display_state(md, 0);
684 + set_sleep_mode(md, 1);
687 + * We have to provide PCLK,HS,VS signals for 2 frames (worst case
688 + * ~50msec) after sending the sleep in command and asserting the
689 + * reset signal. We probably could assert the reset w/o the delay
690 + * but we still delay to avoid possible artifacts. (7.6.1)
694 + if (dssdev->platform_disable)
695 + dssdev->platform_disable(dssdev);
697 + mutex_unlock(&md->mutex);
700 +static int acx_panel_enable(struct omap_dss_device *dssdev)
704 + dev_dbg(&dssdev->dev, "%s\n", __func__);
705 + r = acx_panel_power_on(dssdev);
710 + dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
714 +static void acx_panel_disable(struct omap_dss_device *dssdev)
716 + dev_dbg(&dssdev->dev, "%s\n", __func__);
717 + acx_panel_power_off(dssdev);
718 + dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
721 +static int acx_panel_suspend(struct omap_dss_device *dssdev)
723 + dev_dbg(&dssdev->dev, "%s\n", __func__);
724 + acx_panel_power_off(dssdev);
725 + dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
729 +static int acx_panel_resume(struct omap_dss_device *dssdev)
733 + dev_dbg(&dssdev->dev, "%s\n", __func__);
734 + r = acx_panel_power_on(dssdev);
738 + dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
742 +static struct omap_dss_driver acx_panel_driver = {
743 + .probe = acx_panel_probe,
744 + .remove = acx_panel_remove,
746 + .enable = acx_panel_enable,
747 + .disable = acx_panel_disable,
748 + .suspend = acx_panel_suspend,
749 + .resume = acx_panel_resume,
752 + .name = "panel-acx565akm",
753 + .owner = THIS_MODULE,
757 +/*--------------------SPI probe-------------------------*/
759 +static int acx565akm_spi_probe(struct spi_device *spi)
761 + struct acx565akm_device *md = &acx_dev;
763 + dev_dbg(&spi->dev, "%s\n", __func__);
765 + spi->mode = SPI_MODE_3;
767 + mutex_init(&md->mutex);
768 + dev_set_drvdata(&spi->dev, md);
770 + omap_dss_register_driver(&acx_panel_driver);
775 +static int acx565akm_spi_remove(struct spi_device *spi)
777 + struct acx565akm_device *md = dev_get_drvdata(&spi->dev);
779 + dev_dbg(&md->spi->dev, "%s\n", __func__);
780 + omap_dss_unregister_driver(&acx_panel_driver);
785 +static struct spi_driver acx565akm_spi_driver = {
787 + .name = "acx565akm",
788 + .bus = &spi_bus_type,
789 + .owner = THIS_MODULE,
791 + .probe = acx565akm_spi_probe,
792 + .remove = __devexit_p(acx565akm_spi_remove),
795 +static int __init acx565akm_init(void)
797 + return spi_register_driver(&acx565akm_spi_driver);
800 +static void __exit acx565akm_exit(void)
802 + spi_unregister_driver(&acx565akm_spi_driver);
805 +module_init(acx565akm_init);
806 +module_exit(acx565akm_exit);
808 +MODULE_AUTHOR("Nokia Corporation");
809 +MODULE_DESCRIPTION("acx565akm LCD Driver");
810 +MODULE_LICENSE("GPL");