Roger Quadros | 0188352 | 2010-03-10 17:32:44 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Support for ACX565AKM LCD Panel used on Nokia N900 |
| 3 | * |
| 4 | * Copyright (C) 2010 Nokia Corporation |
| 5 | * |
| 6 | * Original Driver Author: Imre Deak <imre.deak@nokia.com> |
| 7 | * Based on panel-generic.c by Tomi Valkeinen <tomi.valkeinen@nokia.com> |
| 8 | * Adapted to new DSS2 framework: Roger Quadros <roger.quadros@nokia.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License version 2 as published by |
| 12 | * the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 17 | * more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along with |
| 20 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/platform_device.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/spi/spi.h> |
| 28 | #include <linux/jiffies.h> |
| 29 | #include <linux/sched.h> |
| 30 | #include <linux/backlight.h> |
| 31 | #include <linux/fb.h> |
| 32 | |
Tomi Valkeinen | a0b38cc | 2011-05-11 14:05:07 +0300 | [diff] [blame] | 33 | #include <video/omapdss.h> |
Roger Quadros | 0188352 | 2010-03-10 17:32:44 +0200 | [diff] [blame] | 34 | |
| 35 | #define MIPID_CMD_READ_DISP_ID 0x04 |
| 36 | #define MIPID_CMD_READ_RED 0x06 |
| 37 | #define MIPID_CMD_READ_GREEN 0x07 |
| 38 | #define MIPID_CMD_READ_BLUE 0x08 |
| 39 | #define MIPID_CMD_READ_DISP_STATUS 0x09 |
| 40 | #define MIPID_CMD_RDDSDR 0x0F |
| 41 | #define MIPID_CMD_SLEEP_IN 0x10 |
| 42 | #define MIPID_CMD_SLEEP_OUT 0x11 |
| 43 | #define MIPID_CMD_DISP_OFF 0x28 |
| 44 | #define MIPID_CMD_DISP_ON 0x29 |
| 45 | #define MIPID_CMD_WRITE_DISP_BRIGHTNESS 0x51 |
| 46 | #define MIPID_CMD_READ_DISP_BRIGHTNESS 0x52 |
| 47 | #define MIPID_CMD_WRITE_CTRL_DISP 0x53 |
| 48 | |
| 49 | #define CTRL_DISP_BRIGHTNESS_CTRL_ON (1 << 5) |
| 50 | #define CTRL_DISP_AMBIENT_LIGHT_CTRL_ON (1 << 4) |
| 51 | #define CTRL_DISP_BACKLIGHT_ON (1 << 2) |
| 52 | #define CTRL_DISP_AUTO_BRIGHTNESS_ON (1 << 1) |
| 53 | |
| 54 | #define MIPID_CMD_READ_CTRL_DISP 0x54 |
| 55 | #define MIPID_CMD_WRITE_CABC 0x55 |
| 56 | #define MIPID_CMD_READ_CABC 0x56 |
| 57 | |
| 58 | #define MIPID_VER_LPH8923 3 |
| 59 | #define MIPID_VER_LS041Y3 4 |
| 60 | #define MIPID_VER_L4F00311 8 |
| 61 | #define MIPID_VER_ACX565AKM 9 |
| 62 | |
| 63 | struct acx565akm_device { |
| 64 | char *name; |
| 65 | int enabled; |
| 66 | int model; |
| 67 | int revision; |
| 68 | u8 display_id[3]; |
| 69 | unsigned has_bc:1; |
| 70 | unsigned has_cabc:1; |
| 71 | unsigned cabc_mode; |
| 72 | unsigned long hw_guard_end; /* next value of jiffies |
| 73 | when we can issue the |
| 74 | next sleep in/out command */ |
| 75 | unsigned long hw_guard_wait; /* max guard time in jiffies */ |
| 76 | |
| 77 | struct spi_device *spi; |
| 78 | struct mutex mutex; |
| 79 | |
| 80 | struct omap_dss_device *dssdev; |
| 81 | struct backlight_device *bl_dev; |
| 82 | }; |
| 83 | |
| 84 | static struct acx565akm_device acx_dev; |
| 85 | static int acx565akm_bl_update_status(struct backlight_device *dev); |
| 86 | |
| 87 | /*--------------------MIPID interface-----------------------------*/ |
| 88 | |
| 89 | static void acx565akm_transfer(struct acx565akm_device *md, int cmd, |
| 90 | const u8 *wbuf, int wlen, u8 *rbuf, int rlen) |
| 91 | { |
| 92 | struct spi_message m; |
| 93 | struct spi_transfer *x, xfer[5]; |
| 94 | int r; |
| 95 | |
| 96 | BUG_ON(md->spi == NULL); |
| 97 | |
| 98 | spi_message_init(&m); |
| 99 | |
| 100 | memset(xfer, 0, sizeof(xfer)); |
| 101 | x = &xfer[0]; |
| 102 | |
| 103 | cmd &= 0xff; |
| 104 | x->tx_buf = &cmd; |
| 105 | x->bits_per_word = 9; |
| 106 | x->len = 2; |
| 107 | |
| 108 | if (rlen > 1 && wlen == 0) { |
| 109 | /* |
| 110 | * Between the command and the response data there is a |
| 111 | * dummy clock cycle. Add an extra bit after the command |
| 112 | * word to account for this. |
| 113 | */ |
| 114 | x->bits_per_word = 10; |
| 115 | cmd <<= 1; |
| 116 | } |
| 117 | spi_message_add_tail(x, &m); |
| 118 | |
| 119 | if (wlen) { |
| 120 | x++; |
| 121 | x->tx_buf = wbuf; |
| 122 | x->len = wlen; |
| 123 | x->bits_per_word = 9; |
| 124 | spi_message_add_tail(x, &m); |
| 125 | } |
| 126 | |
| 127 | if (rlen) { |
| 128 | x++; |
| 129 | x->rx_buf = rbuf; |
| 130 | x->len = rlen; |
| 131 | spi_message_add_tail(x, &m); |
| 132 | } |
| 133 | |
| 134 | r = spi_sync(md->spi, &m); |
| 135 | if (r < 0) |
| 136 | dev_dbg(&md->spi->dev, "spi_sync %d\n", r); |
| 137 | } |
| 138 | |
| 139 | static inline void acx565akm_cmd(struct acx565akm_device *md, int cmd) |
| 140 | { |
| 141 | acx565akm_transfer(md, cmd, NULL, 0, NULL, 0); |
| 142 | } |
| 143 | |
| 144 | static inline void acx565akm_write(struct acx565akm_device *md, |
| 145 | int reg, const u8 *buf, int len) |
| 146 | { |
| 147 | acx565akm_transfer(md, reg, buf, len, NULL, 0); |
| 148 | } |
| 149 | |
| 150 | static inline void acx565akm_read(struct acx565akm_device *md, |
| 151 | int reg, u8 *buf, int len) |
| 152 | { |
| 153 | acx565akm_transfer(md, reg, NULL, 0, buf, len); |
| 154 | } |
| 155 | |
| 156 | static void hw_guard_start(struct acx565akm_device *md, int guard_msec) |
| 157 | { |
| 158 | md->hw_guard_wait = msecs_to_jiffies(guard_msec); |
| 159 | md->hw_guard_end = jiffies + md->hw_guard_wait; |
| 160 | } |
| 161 | |
| 162 | static void hw_guard_wait(struct acx565akm_device *md) |
| 163 | { |
| 164 | unsigned long wait = md->hw_guard_end - jiffies; |
| 165 | |
| 166 | if ((long)wait > 0 && wait <= md->hw_guard_wait) { |
| 167 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 168 | schedule_timeout(wait); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | /*----------------------MIPID wrappers----------------------------*/ |
| 173 | |
| 174 | static void set_sleep_mode(struct acx565akm_device *md, int on) |
| 175 | { |
| 176 | int cmd; |
| 177 | |
| 178 | if (on) |
| 179 | cmd = MIPID_CMD_SLEEP_IN; |
| 180 | else |
| 181 | cmd = MIPID_CMD_SLEEP_OUT; |
| 182 | /* |
| 183 | * We have to keep 120msec between sleep in/out commands. |
| 184 | * (8.2.15, 8.2.16). |
| 185 | */ |
| 186 | hw_guard_wait(md); |
| 187 | acx565akm_cmd(md, cmd); |
| 188 | hw_guard_start(md, 120); |
| 189 | } |
| 190 | |
| 191 | static void set_display_state(struct acx565akm_device *md, int enabled) |
| 192 | { |
| 193 | int cmd = enabled ? MIPID_CMD_DISP_ON : MIPID_CMD_DISP_OFF; |
| 194 | |
| 195 | acx565akm_cmd(md, cmd); |
| 196 | } |
| 197 | |
| 198 | static int panel_enabled(struct acx565akm_device *md) |
| 199 | { |
| 200 | u32 disp_status; |
| 201 | int enabled; |
| 202 | |
| 203 | acx565akm_read(md, MIPID_CMD_READ_DISP_STATUS, (u8 *)&disp_status, 4); |
| 204 | disp_status = __be32_to_cpu(disp_status); |
| 205 | enabled = (disp_status & (1 << 17)) && (disp_status & (1 << 10)); |
| 206 | dev_dbg(&md->spi->dev, |
| 207 | "LCD panel %senabled by bootloader (status 0x%04x)\n", |
| 208 | enabled ? "" : "not ", disp_status); |
| 209 | return enabled; |
| 210 | } |
| 211 | |
| 212 | static int panel_detect(struct acx565akm_device *md) |
| 213 | { |
| 214 | acx565akm_read(md, MIPID_CMD_READ_DISP_ID, md->display_id, 3); |
| 215 | dev_dbg(&md->spi->dev, "MIPI display ID: %02x%02x%02x\n", |
| 216 | md->display_id[0], md->display_id[1], md->display_id[2]); |
| 217 | |
| 218 | switch (md->display_id[0]) { |
| 219 | case 0x10: |
| 220 | md->model = MIPID_VER_ACX565AKM; |
| 221 | md->name = "acx565akm"; |
| 222 | md->has_bc = 1; |
| 223 | md->has_cabc = 1; |
| 224 | break; |
| 225 | case 0x29: |
| 226 | md->model = MIPID_VER_L4F00311; |
| 227 | md->name = "l4f00311"; |
| 228 | break; |
| 229 | case 0x45: |
| 230 | md->model = MIPID_VER_LPH8923; |
| 231 | md->name = "lph8923"; |
| 232 | break; |
| 233 | case 0x83: |
| 234 | md->model = MIPID_VER_LS041Y3; |
| 235 | md->name = "ls041y3"; |
| 236 | break; |
| 237 | default: |
| 238 | md->name = "unknown"; |
| 239 | dev_err(&md->spi->dev, "invalid display ID\n"); |
| 240 | return -ENODEV; |
| 241 | } |
| 242 | |
| 243 | md->revision = md->display_id[1]; |
| 244 | |
| 245 | dev_info(&md->spi->dev, "omapfb: %s rev %02x LCD detected\n", |
| 246 | md->name, md->revision); |
| 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | /*----------------------Backlight Control-------------------------*/ |
| 252 | |
| 253 | static void enable_backlight_ctrl(struct acx565akm_device *md, int enable) |
| 254 | { |
| 255 | u16 ctrl; |
| 256 | |
| 257 | acx565akm_read(md, MIPID_CMD_READ_CTRL_DISP, (u8 *)&ctrl, 1); |
| 258 | if (enable) { |
| 259 | ctrl |= CTRL_DISP_BRIGHTNESS_CTRL_ON | |
| 260 | CTRL_DISP_BACKLIGHT_ON; |
| 261 | } else { |
| 262 | ctrl &= ~(CTRL_DISP_BRIGHTNESS_CTRL_ON | |
| 263 | CTRL_DISP_BACKLIGHT_ON); |
| 264 | } |
| 265 | |
| 266 | ctrl |= 1 << 8; |
| 267 | acx565akm_write(md, MIPID_CMD_WRITE_CTRL_DISP, (u8 *)&ctrl, 2); |
| 268 | } |
| 269 | |
| 270 | static void set_cabc_mode(struct acx565akm_device *md, unsigned mode) |
| 271 | { |
| 272 | u16 cabc_ctrl; |
| 273 | |
| 274 | md->cabc_mode = mode; |
| 275 | if (!md->enabled) |
| 276 | return; |
| 277 | cabc_ctrl = 0; |
| 278 | acx565akm_read(md, MIPID_CMD_READ_CABC, (u8 *)&cabc_ctrl, 1); |
| 279 | cabc_ctrl &= ~3; |
| 280 | cabc_ctrl |= (1 << 8) | (mode & 3); |
| 281 | acx565akm_write(md, MIPID_CMD_WRITE_CABC, (u8 *)&cabc_ctrl, 2); |
| 282 | } |
| 283 | |
| 284 | static unsigned get_cabc_mode(struct acx565akm_device *md) |
| 285 | { |
| 286 | return md->cabc_mode; |
| 287 | } |
| 288 | |
| 289 | static unsigned get_hw_cabc_mode(struct acx565akm_device *md) |
| 290 | { |
| 291 | u8 cabc_ctrl; |
| 292 | |
| 293 | acx565akm_read(md, MIPID_CMD_READ_CABC, &cabc_ctrl, 1); |
| 294 | return cabc_ctrl & 3; |
| 295 | } |
| 296 | |
| 297 | static void acx565akm_set_brightness(struct acx565akm_device *md, int level) |
| 298 | { |
| 299 | int bv; |
| 300 | |
| 301 | bv = level | (1 << 8); |
| 302 | acx565akm_write(md, MIPID_CMD_WRITE_DISP_BRIGHTNESS, (u8 *)&bv, 2); |
| 303 | |
| 304 | if (level) |
| 305 | enable_backlight_ctrl(md, 1); |
| 306 | else |
| 307 | enable_backlight_ctrl(md, 0); |
| 308 | } |
| 309 | |
| 310 | static int acx565akm_get_actual_brightness(struct acx565akm_device *md) |
| 311 | { |
| 312 | u8 bv; |
| 313 | |
| 314 | acx565akm_read(md, MIPID_CMD_READ_DISP_BRIGHTNESS, &bv, 1); |
| 315 | |
| 316 | return bv; |
| 317 | } |
| 318 | |
| 319 | |
| 320 | static int acx565akm_bl_update_status(struct backlight_device *dev) |
| 321 | { |
| 322 | struct acx565akm_device *md = dev_get_drvdata(&dev->dev); |
| 323 | int r; |
| 324 | int level; |
| 325 | |
| 326 | dev_dbg(&md->spi->dev, "%s\n", __func__); |
| 327 | |
| 328 | mutex_lock(&md->mutex); |
| 329 | |
| 330 | if (dev->props.fb_blank == FB_BLANK_UNBLANK && |
| 331 | dev->props.power == FB_BLANK_UNBLANK) |
| 332 | level = dev->props.brightness; |
| 333 | else |
| 334 | level = 0; |
| 335 | |
| 336 | r = 0; |
| 337 | if (md->has_bc) |
| 338 | acx565akm_set_brightness(md, level); |
| 339 | else if (md->dssdev->set_backlight) |
| 340 | r = md->dssdev->set_backlight(md->dssdev, level); |
| 341 | else |
| 342 | r = -ENODEV; |
| 343 | |
| 344 | mutex_unlock(&md->mutex); |
| 345 | |
| 346 | return r; |
| 347 | } |
| 348 | |
| 349 | static int acx565akm_bl_get_intensity(struct backlight_device *dev) |
| 350 | { |
| 351 | struct acx565akm_device *md = dev_get_drvdata(&dev->dev); |
| 352 | |
| 353 | dev_dbg(&dev->dev, "%s\n", __func__); |
| 354 | |
| 355 | if (!md->has_bc && md->dssdev->set_backlight == NULL) |
| 356 | return -ENODEV; |
| 357 | |
| 358 | if (dev->props.fb_blank == FB_BLANK_UNBLANK && |
| 359 | dev->props.power == FB_BLANK_UNBLANK) { |
| 360 | if (md->has_bc) |
| 361 | return acx565akm_get_actual_brightness(md); |
| 362 | else |
| 363 | return dev->props.brightness; |
| 364 | } |
| 365 | |
| 366 | return 0; |
| 367 | } |
| 368 | |
| 369 | static const struct backlight_ops acx565akm_bl_ops = { |
| 370 | .get_brightness = acx565akm_bl_get_intensity, |
| 371 | .update_status = acx565akm_bl_update_status, |
| 372 | }; |
| 373 | |
| 374 | /*--------------------Auto Brightness control via Sysfs---------------------*/ |
| 375 | |
| 376 | static const char *cabc_modes[] = { |
| 377 | "off", /* always used when CABC is not supported */ |
| 378 | "ui", |
| 379 | "still-image", |
| 380 | "moving-image", |
| 381 | }; |
| 382 | |
| 383 | static ssize_t show_cabc_mode(struct device *dev, |
| 384 | struct device_attribute *attr, |
| 385 | char *buf) |
| 386 | { |
| 387 | struct acx565akm_device *md = dev_get_drvdata(dev); |
| 388 | const char *mode_str; |
| 389 | int mode; |
| 390 | int len; |
| 391 | |
| 392 | if (!md->has_cabc) |
| 393 | mode = 0; |
| 394 | else |
| 395 | mode = get_cabc_mode(md); |
| 396 | mode_str = "unknown"; |
| 397 | if (mode >= 0 && mode < ARRAY_SIZE(cabc_modes)) |
| 398 | mode_str = cabc_modes[mode]; |
| 399 | len = snprintf(buf, PAGE_SIZE, "%s\n", mode_str); |
| 400 | |
| 401 | return len < PAGE_SIZE - 1 ? len : PAGE_SIZE - 1; |
| 402 | } |
| 403 | |
| 404 | static ssize_t store_cabc_mode(struct device *dev, |
| 405 | struct device_attribute *attr, |
| 406 | const char *buf, size_t count) |
| 407 | { |
| 408 | struct acx565akm_device *md = dev_get_drvdata(dev); |
| 409 | int i; |
| 410 | |
| 411 | for (i = 0; i < ARRAY_SIZE(cabc_modes); i++) { |
| 412 | const char *mode_str = cabc_modes[i]; |
| 413 | int cmp_len = strlen(mode_str); |
| 414 | |
| 415 | if (count > 0 && buf[count - 1] == '\n') |
| 416 | count--; |
| 417 | if (count != cmp_len) |
| 418 | continue; |
| 419 | |
| 420 | if (strncmp(buf, mode_str, cmp_len) == 0) |
| 421 | break; |
| 422 | } |
| 423 | |
| 424 | if (i == ARRAY_SIZE(cabc_modes)) |
| 425 | return -EINVAL; |
| 426 | |
| 427 | if (!md->has_cabc && i != 0) |
| 428 | return -EINVAL; |
| 429 | |
| 430 | mutex_lock(&md->mutex); |
| 431 | set_cabc_mode(md, i); |
| 432 | mutex_unlock(&md->mutex); |
| 433 | |
| 434 | return count; |
| 435 | } |
| 436 | |
| 437 | static ssize_t show_cabc_available_modes(struct device *dev, |
| 438 | struct device_attribute *attr, |
| 439 | char *buf) |
| 440 | { |
| 441 | struct acx565akm_device *md = dev_get_drvdata(dev); |
| 442 | int len; |
| 443 | int i; |
| 444 | |
| 445 | if (!md->has_cabc) |
| 446 | return snprintf(buf, PAGE_SIZE, "%s\n", cabc_modes[0]); |
| 447 | |
| 448 | for (i = 0, len = 0; |
| 449 | len < PAGE_SIZE && i < ARRAY_SIZE(cabc_modes); i++) |
| 450 | len += snprintf(&buf[len], PAGE_SIZE - len, "%s%s%s", |
| 451 | i ? " " : "", cabc_modes[i], |
| 452 | i == ARRAY_SIZE(cabc_modes) - 1 ? "\n" : ""); |
| 453 | |
| 454 | return len < PAGE_SIZE ? len : PAGE_SIZE - 1; |
| 455 | } |
| 456 | |
| 457 | static DEVICE_ATTR(cabc_mode, S_IRUGO | S_IWUSR, |
| 458 | show_cabc_mode, store_cabc_mode); |
| 459 | static DEVICE_ATTR(cabc_available_modes, S_IRUGO, |
| 460 | show_cabc_available_modes, NULL); |
| 461 | |
| 462 | static struct attribute *bldev_attrs[] = { |
| 463 | &dev_attr_cabc_mode.attr, |
| 464 | &dev_attr_cabc_available_modes.attr, |
| 465 | NULL, |
| 466 | }; |
| 467 | |
| 468 | static struct attribute_group bldev_attr_group = { |
| 469 | .attrs = bldev_attrs, |
| 470 | }; |
| 471 | |
| 472 | |
| 473 | /*---------------------------ACX Panel----------------------------*/ |
| 474 | |
| 475 | static int acx_get_recommended_bpp(struct omap_dss_device *dssdev) |
| 476 | { |
| 477 | return 16; |
| 478 | } |
| 479 | |
| 480 | static struct omap_video_timings acx_panel_timings = { |
| 481 | .x_res = 800, |
| 482 | .y_res = 480, |
| 483 | .pixel_clock = 24000, |
| 484 | .hfp = 28, |
| 485 | .hsw = 4, |
| 486 | .hbp = 24, |
| 487 | .vfp = 3, |
| 488 | .vsw = 3, |
| 489 | .vbp = 4, |
Archit Taneja | a8d5e41 | 2012-06-25 12:26:38 +0530 | [diff] [blame] | 490 | |
| 491 | .vsync_level = OMAPDSS_SIG_ACTIVE_LOW, |
| 492 | .hsync_level = OMAPDSS_SIG_ACTIVE_LOW, |
| 493 | |
| 494 | .data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE, |
| 495 | .de_level = OMAPDSS_SIG_ACTIVE_HIGH, |
| 496 | .sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES, |
Roger Quadros | 0188352 | 2010-03-10 17:32:44 +0200 | [diff] [blame] | 497 | }; |
| 498 | |
| 499 | static int acx_panel_probe(struct omap_dss_device *dssdev) |
| 500 | { |
| 501 | int r; |
| 502 | struct acx565akm_device *md = &acx_dev; |
| 503 | struct backlight_device *bldev; |
| 504 | int max_brightness, brightness; |
| 505 | struct backlight_properties props; |
| 506 | |
| 507 | dev_dbg(&dssdev->dev, "%s\n", __func__); |
Archit Taneja | 5ae9eaa | 2012-06-21 09:41:10 +0530 | [diff] [blame] | 508 | |
Roger Quadros | 0188352 | 2010-03-10 17:32:44 +0200 | [diff] [blame] | 509 | /* FIXME AC bias ? */ |
| 510 | dssdev->panel.timings = acx_panel_timings; |
| 511 | |
| 512 | if (dssdev->platform_enable) |
| 513 | dssdev->platform_enable(dssdev); |
| 514 | /* |
| 515 | * After reset we have to wait 5 msec before the first |
| 516 | * command can be sent. |
| 517 | */ |
| 518 | msleep(5); |
| 519 | |
| 520 | md->enabled = panel_enabled(md); |
| 521 | |
| 522 | r = panel_detect(md); |
| 523 | if (r) { |
| 524 | dev_err(&dssdev->dev, "%s panel detect error\n", __func__); |
| 525 | if (!md->enabled && dssdev->platform_disable) |
| 526 | dssdev->platform_disable(dssdev); |
| 527 | return r; |
| 528 | } |
| 529 | |
| 530 | mutex_lock(&acx_dev.mutex); |
| 531 | acx_dev.dssdev = dssdev; |
| 532 | mutex_unlock(&acx_dev.mutex); |
| 533 | |
| 534 | if (!md->enabled) { |
| 535 | if (dssdev->platform_disable) |
| 536 | dssdev->platform_disable(dssdev); |
| 537 | } |
| 538 | |
| 539 | /*------- Backlight control --------*/ |
| 540 | |
Corentin Chary | f5f4fd4 | 2012-05-29 15:07:20 -0700 | [diff] [blame] | 541 | memset(&props, 0, sizeof(props)); |
Roger Quadros | 0188352 | 2010-03-10 17:32:44 +0200 | [diff] [blame] | 542 | props.fb_blank = FB_BLANK_UNBLANK; |
| 543 | props.power = FB_BLANK_UNBLANK; |
Matthew Garrett | bb7ca74 | 2011-03-22 16:30:21 -0700 | [diff] [blame] | 544 | props.type = BACKLIGHT_RAW; |
Roger Quadros | 0188352 | 2010-03-10 17:32:44 +0200 | [diff] [blame] | 545 | |
| 546 | bldev = backlight_device_register("acx565akm", &md->spi->dev, |
| 547 | md, &acx565akm_bl_ops, &props); |
| 548 | md->bl_dev = bldev; |
| 549 | if (md->has_cabc) { |
| 550 | r = sysfs_create_group(&bldev->dev.kobj, &bldev_attr_group); |
| 551 | if (r) { |
| 552 | dev_err(&bldev->dev, |
| 553 | "%s failed to create sysfs files\n", __func__); |
| 554 | backlight_device_unregister(bldev); |
| 555 | return r; |
| 556 | } |
| 557 | md->cabc_mode = get_hw_cabc_mode(md); |
| 558 | } |
| 559 | |
| 560 | if (md->has_bc) |
| 561 | max_brightness = 255; |
| 562 | else |
| 563 | max_brightness = dssdev->max_backlight_level; |
| 564 | |
| 565 | if (md->has_bc) |
| 566 | brightness = acx565akm_get_actual_brightness(md); |
| 567 | else if (dssdev->get_backlight) |
| 568 | brightness = dssdev->get_backlight(dssdev); |
| 569 | else |
| 570 | brightness = 0; |
| 571 | |
| 572 | bldev->props.max_brightness = max_brightness; |
| 573 | bldev->props.brightness = brightness; |
| 574 | |
| 575 | acx565akm_bl_update_status(bldev); |
| 576 | return 0; |
| 577 | } |
| 578 | |
| 579 | static void acx_panel_remove(struct omap_dss_device *dssdev) |
| 580 | { |
| 581 | struct acx565akm_device *md = &acx_dev; |
| 582 | |
| 583 | dev_dbg(&dssdev->dev, "%s\n", __func__); |
| 584 | sysfs_remove_group(&md->bl_dev->dev.kobj, &bldev_attr_group); |
| 585 | backlight_device_unregister(md->bl_dev); |
| 586 | mutex_lock(&acx_dev.mutex); |
| 587 | acx_dev.dssdev = NULL; |
| 588 | mutex_unlock(&acx_dev.mutex); |
| 589 | } |
| 590 | |
| 591 | static int acx_panel_power_on(struct omap_dss_device *dssdev) |
| 592 | { |
| 593 | struct acx565akm_device *md = &acx_dev; |
| 594 | int r; |
| 595 | |
| 596 | dev_dbg(&dssdev->dev, "%s\n", __func__); |
| 597 | |
Stanley.Miao | 18016e3 | 2010-09-03 05:03:48 +0200 | [diff] [blame] | 598 | if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) |
| 599 | return 0; |
| 600 | |
Roger Quadros | 0188352 | 2010-03-10 17:32:44 +0200 | [diff] [blame] | 601 | mutex_lock(&md->mutex); |
| 602 | |
Archit Taneja | 9b4a571 | 2012-08-08 16:56:06 +0530 | [diff] [blame] | 603 | omapdss_sdi_set_timings(dssdev, &dssdev->panel.timings); |
| 604 | |
Roger Quadros | 0188352 | 2010-03-10 17:32:44 +0200 | [diff] [blame] | 605 | r = omapdss_sdi_display_enable(dssdev); |
| 606 | if (r) { |
| 607 | pr_err("%s sdi enable failed\n", __func__); |
Julia Lawall | 5c79b49 | 2010-07-20 19:22:44 -0300 | [diff] [blame] | 608 | goto fail_unlock; |
Roger Quadros | 0188352 | 2010-03-10 17:32:44 +0200 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | /*FIXME tweak me */ |
| 612 | msleep(50); |
| 613 | |
| 614 | if (dssdev->platform_enable) { |
| 615 | r = dssdev->platform_enable(dssdev); |
| 616 | if (r) |
| 617 | goto fail; |
| 618 | } |
| 619 | |
| 620 | if (md->enabled) { |
| 621 | dev_dbg(&md->spi->dev, "panel already enabled\n"); |
| 622 | mutex_unlock(&md->mutex); |
| 623 | return 0; |
| 624 | } |
| 625 | |
| 626 | /* |
| 627 | * We have to meet all the following delay requirements: |
| 628 | * 1. tRW: reset pulse width 10usec (7.12.1) |
| 629 | * 2. tRT: reset cancel time 5msec (7.12.1) |
| 630 | * 3. Providing PCLK,HS,VS signals for 2 frames = ~50msec worst |
| 631 | * case (7.6.2) |
| 632 | * 4. 120msec before the sleep out command (7.12.1) |
| 633 | */ |
| 634 | msleep(120); |
| 635 | |
| 636 | set_sleep_mode(md, 0); |
| 637 | md->enabled = 1; |
| 638 | |
| 639 | /* 5msec between sleep out and the next command. (8.2.16) */ |
| 640 | msleep(5); |
| 641 | set_display_state(md, 1); |
| 642 | set_cabc_mode(md, md->cabc_mode); |
| 643 | |
| 644 | mutex_unlock(&md->mutex); |
| 645 | |
| 646 | return acx565akm_bl_update_status(md->bl_dev); |
| 647 | fail: |
| 648 | omapdss_sdi_display_disable(dssdev); |
Julia Lawall | 5c79b49 | 2010-07-20 19:22:44 -0300 | [diff] [blame] | 649 | fail_unlock: |
| 650 | mutex_unlock(&md->mutex); |
Roger Quadros | 0188352 | 2010-03-10 17:32:44 +0200 | [diff] [blame] | 651 | return r; |
| 652 | } |
| 653 | |
| 654 | static void acx_panel_power_off(struct omap_dss_device *dssdev) |
| 655 | { |
| 656 | struct acx565akm_device *md = &acx_dev; |
| 657 | |
| 658 | dev_dbg(&dssdev->dev, "%s\n", __func__); |
| 659 | |
Stanley.Miao | 18016e3 | 2010-09-03 05:03:48 +0200 | [diff] [blame] | 660 | if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) |
| 661 | return; |
| 662 | |
Roger Quadros | 0188352 | 2010-03-10 17:32:44 +0200 | [diff] [blame] | 663 | mutex_lock(&md->mutex); |
| 664 | |
| 665 | if (!md->enabled) { |
| 666 | mutex_unlock(&md->mutex); |
| 667 | return; |
| 668 | } |
| 669 | set_display_state(md, 0); |
| 670 | set_sleep_mode(md, 1); |
| 671 | md->enabled = 0; |
| 672 | /* |
| 673 | * We have to provide PCLK,HS,VS signals for 2 frames (worst case |
| 674 | * ~50msec) after sending the sleep in command and asserting the |
| 675 | * reset signal. We probably could assert the reset w/o the delay |
| 676 | * but we still delay to avoid possible artifacts. (7.6.1) |
| 677 | */ |
| 678 | msleep(50); |
| 679 | |
| 680 | if (dssdev->platform_disable) |
| 681 | dssdev->platform_disable(dssdev); |
| 682 | |
| 683 | /* FIXME need to tweak this delay */ |
| 684 | msleep(100); |
| 685 | |
| 686 | omapdss_sdi_display_disable(dssdev); |
| 687 | |
| 688 | mutex_unlock(&md->mutex); |
| 689 | } |
| 690 | |
| 691 | static int acx_panel_enable(struct omap_dss_device *dssdev) |
| 692 | { |
| 693 | int r; |
| 694 | |
| 695 | dev_dbg(&dssdev->dev, "%s\n", __func__); |
| 696 | r = acx_panel_power_on(dssdev); |
| 697 | |
| 698 | if (r) |
| 699 | return r; |
| 700 | |
| 701 | dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; |
| 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | static void acx_panel_disable(struct omap_dss_device *dssdev) |
| 706 | { |
| 707 | dev_dbg(&dssdev->dev, "%s\n", __func__); |
| 708 | acx_panel_power_off(dssdev); |
| 709 | dssdev->state = OMAP_DSS_DISPLAY_DISABLED; |
| 710 | } |
| 711 | |
| 712 | static int acx_panel_suspend(struct omap_dss_device *dssdev) |
| 713 | { |
| 714 | dev_dbg(&dssdev->dev, "%s\n", __func__); |
| 715 | acx_panel_power_off(dssdev); |
| 716 | dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED; |
| 717 | return 0; |
| 718 | } |
| 719 | |
| 720 | static int acx_panel_resume(struct omap_dss_device *dssdev) |
| 721 | { |
| 722 | int r; |
| 723 | |
| 724 | dev_dbg(&dssdev->dev, "%s\n", __func__); |
| 725 | r = acx_panel_power_on(dssdev); |
| 726 | if (r) |
| 727 | return r; |
| 728 | |
| 729 | dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; |
| 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | static void acx_panel_set_timings(struct omap_dss_device *dssdev, |
| 734 | struct omap_video_timings *timings) |
| 735 | { |
Archit Taneja | c7833f7 | 2012-07-05 17:11:12 +0530 | [diff] [blame] | 736 | omapdss_sdi_set_timings(dssdev, timings); |
Archit Taneja | 9b4a571 | 2012-08-08 16:56:06 +0530 | [diff] [blame] | 737 | |
| 738 | dssdev->panel.timings = *timings; |
Roger Quadros | 0188352 | 2010-03-10 17:32:44 +0200 | [diff] [blame] | 739 | } |
| 740 | |
Roger Quadros | 0188352 | 2010-03-10 17:32:44 +0200 | [diff] [blame] | 741 | static int acx_panel_check_timings(struct omap_dss_device *dssdev, |
| 742 | struct omap_video_timings *timings) |
| 743 | { |
| 744 | return 0; |
| 745 | } |
| 746 | |
| 747 | |
| 748 | static struct omap_dss_driver acx_panel_driver = { |
| 749 | .probe = acx_panel_probe, |
| 750 | .remove = acx_panel_remove, |
| 751 | |
| 752 | .enable = acx_panel_enable, |
| 753 | .disable = acx_panel_disable, |
| 754 | .suspend = acx_panel_suspend, |
| 755 | .resume = acx_panel_resume, |
| 756 | |
| 757 | .set_timings = acx_panel_set_timings, |
Roger Quadros | 0188352 | 2010-03-10 17:32:44 +0200 | [diff] [blame] | 758 | .check_timings = acx_panel_check_timings, |
| 759 | |
| 760 | .get_recommended_bpp = acx_get_recommended_bpp, |
| 761 | |
| 762 | .driver = { |
| 763 | .name = "panel-acx565akm", |
| 764 | .owner = THIS_MODULE, |
| 765 | }, |
| 766 | }; |
| 767 | |
| 768 | /*--------------------SPI probe-------------------------*/ |
| 769 | |
| 770 | static int acx565akm_spi_probe(struct spi_device *spi) |
| 771 | { |
| 772 | struct acx565akm_device *md = &acx_dev; |
| 773 | |
| 774 | dev_dbg(&spi->dev, "%s\n", __func__); |
| 775 | |
| 776 | spi->mode = SPI_MODE_3; |
| 777 | md->spi = spi; |
| 778 | mutex_init(&md->mutex); |
| 779 | dev_set_drvdata(&spi->dev, md); |
| 780 | |
| 781 | omap_dss_register_driver(&acx_panel_driver); |
| 782 | |
| 783 | return 0; |
| 784 | } |
| 785 | |
| 786 | static int acx565akm_spi_remove(struct spi_device *spi) |
| 787 | { |
| 788 | struct acx565akm_device *md = dev_get_drvdata(&spi->dev); |
| 789 | |
| 790 | dev_dbg(&md->spi->dev, "%s\n", __func__); |
| 791 | omap_dss_unregister_driver(&acx_panel_driver); |
| 792 | |
| 793 | return 0; |
| 794 | } |
| 795 | |
| 796 | static struct spi_driver acx565akm_spi_driver = { |
| 797 | .driver = { |
| 798 | .name = "acx565akm", |
Roger Quadros | 0188352 | 2010-03-10 17:32:44 +0200 | [diff] [blame] | 799 | .owner = THIS_MODULE, |
| 800 | }, |
| 801 | .probe = acx565akm_spi_probe, |
| 802 | .remove = __devexit_p(acx565akm_spi_remove), |
| 803 | }; |
| 804 | |
Axel Lin | c6d242a | 2012-01-27 16:02:54 +0800 | [diff] [blame] | 805 | module_spi_driver(acx565akm_spi_driver); |
Roger Quadros | 0188352 | 2010-03-10 17:32:44 +0200 | [diff] [blame] | 806 | |
| 807 | MODULE_AUTHOR("Nokia Corporation"); |
| 808 | MODULE_DESCRIPTION("acx565akm LCD Driver"); |
| 809 | MODULE_LICENSE("GPL"); |