Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ld9040 AMOLED LCD panel driver. |
| 3 | * |
| 4 | * Copyright (c) 2011 Samsung Electronics |
| 5 | * Author: Donghwa Lee <dh09.lee@samsung.com> |
| 6 | * Derived from drivers/video/backlight/s6e63m0.c |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2 of the License, or (at your |
| 11 | * option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/wait.h> |
| 24 | #include <linux/fb.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/gpio.h> |
| 27 | #include <linux/spi/spi.h> |
| 28 | #include <linux/irq.h> |
| 29 | #include <linux/interrupt.h> |
| 30 | #include <linux/kernel.h> |
| 31 | #include <linux/lcd.h> |
| 32 | #include <linux/backlight.h> |
Paul Gortmaker | 355b200 | 2011-07-03 16:17:28 -0400 | [diff] [blame] | 33 | #include <linux/module.h> |
Donghwa Lee | b148a27 | 2012-01-10 15:09:15 -0800 | [diff] [blame] | 34 | #include <linux/regulator/consumer.h> |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 35 | |
| 36 | #include "ld9040_gamma.h" |
| 37 | |
| 38 | #define SLEEPMSEC 0x1000 |
| 39 | #define ENDDEF 0x2000 |
| 40 | #define DEFMASK 0xFF00 |
| 41 | #define COMMAND_ONLY 0xFE |
| 42 | #define DATA_ONLY 0xFF |
| 43 | |
| 44 | #define MIN_BRIGHTNESS 0 |
| 45 | #define MAX_BRIGHTNESS 24 |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 46 | |
| 47 | struct ld9040 { |
| 48 | struct device *dev; |
| 49 | struct spi_device *spi; |
| 50 | unsigned int power; |
| 51 | unsigned int current_brightness; |
| 52 | |
| 53 | struct lcd_device *ld; |
| 54 | struct backlight_device *bd; |
| 55 | struct lcd_platform_data *lcd_pd; |
Donghwa Lee | b148a27 | 2012-01-10 15:09:15 -0800 | [diff] [blame] | 56 | |
| 57 | struct mutex lock; |
| 58 | bool enabled; |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
Donghwa Lee | b148a27 | 2012-01-10 15:09:15 -0800 | [diff] [blame] | 61 | static struct regulator_bulk_data supplies[] = { |
| 62 | { .supply = "vdd3", }, |
| 63 | { .supply = "vci", }, |
| 64 | }; |
| 65 | |
| 66 | static void ld9040_regulator_enable(struct ld9040 *lcd) |
| 67 | { |
| 68 | int ret = 0; |
| 69 | struct lcd_platform_data *pd = NULL; |
| 70 | |
| 71 | pd = lcd->lcd_pd; |
| 72 | mutex_lock(&lcd->lock); |
| 73 | if (!lcd->enabled) { |
| 74 | ret = regulator_bulk_enable(ARRAY_SIZE(supplies), supplies); |
| 75 | if (ret) |
| 76 | goto out; |
| 77 | |
| 78 | lcd->enabled = true; |
| 79 | } |
Jingoo Han | d2fff29 | 2013-02-21 16:43:15 -0800 | [diff] [blame] | 80 | msleep(pd->power_on_delay); |
Donghwa Lee | b148a27 | 2012-01-10 15:09:15 -0800 | [diff] [blame] | 81 | out: |
| 82 | mutex_unlock(&lcd->lock); |
| 83 | } |
| 84 | |
| 85 | static void ld9040_regulator_disable(struct ld9040 *lcd) |
| 86 | { |
| 87 | int ret = 0; |
| 88 | |
| 89 | mutex_lock(&lcd->lock); |
| 90 | if (lcd->enabled) { |
| 91 | ret = regulator_bulk_disable(ARRAY_SIZE(supplies), supplies); |
| 92 | if (ret) |
| 93 | goto out; |
| 94 | |
| 95 | lcd->enabled = false; |
| 96 | } |
| 97 | out: |
| 98 | mutex_unlock(&lcd->lock); |
| 99 | } |
| 100 | |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 101 | static const unsigned short seq_swreset[] = { |
| 102 | 0x01, COMMAND_ONLY, |
| 103 | ENDDEF, 0x00 |
| 104 | }; |
| 105 | |
| 106 | static const unsigned short seq_user_setting[] = { |
| 107 | 0xF0, 0x5A, |
| 108 | |
| 109 | DATA_ONLY, 0x5A, |
| 110 | ENDDEF, 0x00 |
| 111 | }; |
| 112 | |
| 113 | static const unsigned short seq_elvss_on[] = { |
| 114 | 0xB1, 0x0D, |
| 115 | |
| 116 | DATA_ONLY, 0x00, |
| 117 | DATA_ONLY, 0x16, |
| 118 | ENDDEF, 0x00 |
| 119 | }; |
| 120 | |
| 121 | static const unsigned short seq_gtcon[] = { |
| 122 | 0xF7, 0x09, |
| 123 | |
| 124 | DATA_ONLY, 0x00, |
| 125 | DATA_ONLY, 0x00, |
| 126 | ENDDEF, 0x00 |
| 127 | }; |
| 128 | |
| 129 | static const unsigned short seq_panel_condition[] = { |
| 130 | 0xF8, 0x05, |
| 131 | |
| 132 | DATA_ONLY, 0x65, |
| 133 | DATA_ONLY, 0x96, |
| 134 | DATA_ONLY, 0x71, |
| 135 | DATA_ONLY, 0x7D, |
| 136 | DATA_ONLY, 0x19, |
| 137 | DATA_ONLY, 0x3B, |
| 138 | DATA_ONLY, 0x0D, |
| 139 | DATA_ONLY, 0x19, |
| 140 | DATA_ONLY, 0x7E, |
| 141 | DATA_ONLY, 0x0D, |
| 142 | DATA_ONLY, 0xE2, |
| 143 | DATA_ONLY, 0x00, |
| 144 | DATA_ONLY, 0x00, |
| 145 | DATA_ONLY, 0x7E, |
| 146 | DATA_ONLY, 0x7D, |
| 147 | DATA_ONLY, 0x07, |
| 148 | DATA_ONLY, 0x07, |
| 149 | DATA_ONLY, 0x20, |
| 150 | DATA_ONLY, 0x20, |
| 151 | DATA_ONLY, 0x20, |
| 152 | DATA_ONLY, 0x02, |
| 153 | DATA_ONLY, 0x02, |
| 154 | ENDDEF, 0x00 |
| 155 | }; |
| 156 | |
| 157 | static const unsigned short seq_gamma_set1[] = { |
| 158 | 0xF9, 0x00, |
| 159 | |
| 160 | DATA_ONLY, 0xA7, |
| 161 | DATA_ONLY, 0xB4, |
| 162 | DATA_ONLY, 0xAE, |
| 163 | DATA_ONLY, 0xBF, |
| 164 | DATA_ONLY, 0x00, |
| 165 | DATA_ONLY, 0x91, |
| 166 | DATA_ONLY, 0x00, |
| 167 | DATA_ONLY, 0xB2, |
| 168 | DATA_ONLY, 0xB4, |
| 169 | DATA_ONLY, 0xAA, |
| 170 | DATA_ONLY, 0xBB, |
| 171 | DATA_ONLY, 0x00, |
| 172 | DATA_ONLY, 0xAC, |
| 173 | DATA_ONLY, 0x00, |
| 174 | DATA_ONLY, 0xB3, |
| 175 | DATA_ONLY, 0xB1, |
| 176 | DATA_ONLY, 0xAA, |
| 177 | DATA_ONLY, 0xBC, |
| 178 | DATA_ONLY, 0x00, |
| 179 | DATA_ONLY, 0xB3, |
| 180 | ENDDEF, 0x00 |
| 181 | }; |
| 182 | |
| 183 | static const unsigned short seq_gamma_ctrl[] = { |
| 184 | 0xFB, 0x02, |
| 185 | |
| 186 | DATA_ONLY, 0x5A, |
| 187 | ENDDEF, 0x00 |
| 188 | }; |
| 189 | |
| 190 | static const unsigned short seq_gamma_start[] = { |
| 191 | 0xF9, COMMAND_ONLY, |
| 192 | |
| 193 | ENDDEF, 0x00 |
| 194 | }; |
| 195 | |
| 196 | static const unsigned short seq_apon[] = { |
| 197 | 0xF3, 0x00, |
| 198 | |
| 199 | DATA_ONLY, 0x00, |
| 200 | DATA_ONLY, 0x00, |
| 201 | DATA_ONLY, 0x0A, |
| 202 | DATA_ONLY, 0x02, |
| 203 | ENDDEF, 0x00 |
| 204 | }; |
| 205 | |
| 206 | static const unsigned short seq_display_ctrl[] = { |
| 207 | 0xF2, 0x02, |
| 208 | |
| 209 | DATA_ONLY, 0x08, |
| 210 | DATA_ONLY, 0x08, |
| 211 | DATA_ONLY, 0x10, |
| 212 | DATA_ONLY, 0x10, |
| 213 | ENDDEF, 0x00 |
| 214 | }; |
| 215 | |
| 216 | static const unsigned short seq_manual_pwr[] = { |
| 217 | 0xB0, 0x04, |
| 218 | ENDDEF, 0x00 |
| 219 | }; |
| 220 | |
| 221 | static const unsigned short seq_pwr_ctrl[] = { |
| 222 | 0xF4, 0x0A, |
| 223 | |
| 224 | DATA_ONLY, 0x87, |
| 225 | DATA_ONLY, 0x25, |
| 226 | DATA_ONLY, 0x6A, |
| 227 | DATA_ONLY, 0x44, |
| 228 | DATA_ONLY, 0x02, |
| 229 | DATA_ONLY, 0x88, |
| 230 | ENDDEF, 0x00 |
| 231 | }; |
| 232 | |
| 233 | static const unsigned short seq_sleep_out[] = { |
| 234 | 0x11, COMMAND_ONLY, |
| 235 | ENDDEF, 0x00 |
| 236 | }; |
| 237 | |
| 238 | static const unsigned short seq_sleep_in[] = { |
| 239 | 0x10, COMMAND_ONLY, |
| 240 | ENDDEF, 0x00 |
| 241 | }; |
| 242 | |
| 243 | static const unsigned short seq_display_on[] = { |
| 244 | 0x29, COMMAND_ONLY, |
| 245 | ENDDEF, 0x00 |
| 246 | }; |
| 247 | |
| 248 | static const unsigned short seq_display_off[] = { |
| 249 | 0x28, COMMAND_ONLY, |
| 250 | ENDDEF, 0x00 |
| 251 | }; |
| 252 | |
| 253 | static const unsigned short seq_vci1_1st_en[] = { |
| 254 | 0xF3, 0x10, |
| 255 | |
| 256 | DATA_ONLY, 0x00, |
| 257 | DATA_ONLY, 0x00, |
| 258 | DATA_ONLY, 0x00, |
| 259 | DATA_ONLY, 0x02, |
| 260 | ENDDEF, 0x00 |
| 261 | }; |
| 262 | |
| 263 | static const unsigned short seq_vl1_en[] = { |
| 264 | 0xF3, 0x11, |
| 265 | |
| 266 | DATA_ONLY, 0x00, |
| 267 | DATA_ONLY, 0x00, |
| 268 | DATA_ONLY, 0x00, |
| 269 | DATA_ONLY, 0x02, |
| 270 | ENDDEF, 0x00 |
| 271 | }; |
| 272 | |
| 273 | static const unsigned short seq_vl2_en[] = { |
| 274 | 0xF3, 0x13, |
| 275 | |
| 276 | DATA_ONLY, 0x00, |
| 277 | DATA_ONLY, 0x00, |
| 278 | DATA_ONLY, 0x00, |
| 279 | DATA_ONLY, 0x02, |
| 280 | ENDDEF, 0x00 |
| 281 | }; |
| 282 | |
| 283 | static const unsigned short seq_vci1_2nd_en[] = { |
| 284 | 0xF3, 0x33, |
| 285 | |
| 286 | DATA_ONLY, 0x00, |
| 287 | DATA_ONLY, 0x00, |
| 288 | DATA_ONLY, 0x00, |
| 289 | DATA_ONLY, 0x02, |
| 290 | ENDDEF, 0x00 |
| 291 | }; |
| 292 | |
| 293 | static const unsigned short seq_vl3_en[] = { |
| 294 | 0xF3, 0x37, |
| 295 | |
| 296 | DATA_ONLY, 0x00, |
| 297 | DATA_ONLY, 0x00, |
| 298 | DATA_ONLY, 0x00, |
| 299 | DATA_ONLY, 0x02, |
| 300 | ENDDEF, 0x00 |
| 301 | }; |
| 302 | |
| 303 | static const unsigned short seq_vreg1_amp_en[] = { |
| 304 | 0xF3, 0x37, |
| 305 | |
| 306 | DATA_ONLY, 0x01, |
| 307 | DATA_ONLY, 0x00, |
| 308 | DATA_ONLY, 0x00, |
| 309 | DATA_ONLY, 0x02, |
| 310 | ENDDEF, 0x00 |
| 311 | }; |
| 312 | |
| 313 | static const unsigned short seq_vgh_amp_en[] = { |
| 314 | 0xF3, 0x37, |
| 315 | |
| 316 | DATA_ONLY, 0x11, |
| 317 | DATA_ONLY, 0x00, |
| 318 | DATA_ONLY, 0x00, |
| 319 | DATA_ONLY, 0x02, |
| 320 | ENDDEF, 0x00 |
| 321 | }; |
| 322 | |
| 323 | static const unsigned short seq_vgl_amp_en[] = { |
| 324 | 0xF3, 0x37, |
| 325 | |
| 326 | DATA_ONLY, 0x31, |
| 327 | DATA_ONLY, 0x00, |
| 328 | DATA_ONLY, 0x00, |
| 329 | DATA_ONLY, 0x02, |
| 330 | ENDDEF, 0x00 |
| 331 | }; |
| 332 | |
| 333 | static const unsigned short seq_vmos_amp_en[] = { |
| 334 | 0xF3, 0x37, |
| 335 | |
| 336 | DATA_ONLY, 0xB1, |
| 337 | DATA_ONLY, 0x00, |
| 338 | DATA_ONLY, 0x00, |
| 339 | DATA_ONLY, 0x03, |
| 340 | ENDDEF, 0x00 |
| 341 | }; |
| 342 | |
| 343 | static const unsigned short seq_vint_amp_en[] = { |
| 344 | 0xF3, 0x37, |
| 345 | |
| 346 | DATA_ONLY, 0xF1, |
| 347 | /* DATA_ONLY, 0x71, VMOS/VBL/VBH not used */ |
| 348 | DATA_ONLY, 0x00, |
| 349 | DATA_ONLY, 0x00, |
| 350 | DATA_ONLY, 0x03, |
| 351 | /* DATA_ONLY, 0x02, VMOS/VBL/VBH not used */ |
| 352 | ENDDEF, 0x00 |
| 353 | }; |
| 354 | |
| 355 | static const unsigned short seq_vbh_amp_en[] = { |
| 356 | 0xF3, 0x37, |
| 357 | |
| 358 | DATA_ONLY, 0xF9, |
| 359 | DATA_ONLY, 0x00, |
| 360 | DATA_ONLY, 0x00, |
| 361 | DATA_ONLY, 0x03, |
| 362 | ENDDEF, 0x00 |
| 363 | }; |
| 364 | |
| 365 | static const unsigned short seq_vbl_amp_en[] = { |
| 366 | 0xF3, 0x37, |
| 367 | |
| 368 | DATA_ONLY, 0xFD, |
| 369 | DATA_ONLY, 0x00, |
| 370 | DATA_ONLY, 0x00, |
| 371 | DATA_ONLY, 0x03, |
| 372 | ENDDEF, 0x00 |
| 373 | }; |
| 374 | |
| 375 | static const unsigned short seq_gam_amp_en[] = { |
| 376 | 0xF3, 0x37, |
| 377 | |
| 378 | DATA_ONLY, 0xFF, |
| 379 | /* DATA_ONLY, 0x73, VMOS/VBL/VBH not used */ |
| 380 | DATA_ONLY, 0x00, |
| 381 | DATA_ONLY, 0x00, |
| 382 | DATA_ONLY, 0x03, |
| 383 | /* DATA_ONLY, 0x02, VMOS/VBL/VBH not used */ |
| 384 | ENDDEF, 0x00 |
| 385 | }; |
| 386 | |
| 387 | static const unsigned short seq_sd_amp_en[] = { |
| 388 | 0xF3, 0x37, |
| 389 | |
| 390 | DATA_ONLY, 0xFF, |
| 391 | /* DATA_ONLY, 0x73, VMOS/VBL/VBH not used */ |
| 392 | DATA_ONLY, 0x80, |
| 393 | DATA_ONLY, 0x00, |
| 394 | DATA_ONLY, 0x03, |
| 395 | /* DATA_ONLY, 0x02, VMOS/VBL/VBH not used */ |
| 396 | ENDDEF, 0x00 |
| 397 | }; |
| 398 | |
| 399 | static const unsigned short seq_gls_en[] = { |
| 400 | 0xF3, 0x37, |
| 401 | |
| 402 | DATA_ONLY, 0xFF, |
| 403 | /* DATA_ONLY, 0x73, VMOS/VBL/VBH not used */ |
| 404 | DATA_ONLY, 0x81, |
| 405 | DATA_ONLY, 0x00, |
| 406 | DATA_ONLY, 0x03, |
| 407 | /* DATA_ONLY, 0x02, VMOS/VBL/VBH not used */ |
| 408 | ENDDEF, 0x00 |
| 409 | }; |
| 410 | |
| 411 | static const unsigned short seq_els_en[] = { |
| 412 | 0xF3, 0x37, |
| 413 | |
| 414 | DATA_ONLY, 0xFF, |
| 415 | /* DATA_ONLY, 0x73, VMOS/VBL/VBH not used */ |
| 416 | DATA_ONLY, 0x83, |
| 417 | DATA_ONLY, 0x00, |
| 418 | DATA_ONLY, 0x03, |
| 419 | /* DATA_ONLY, 0x02, VMOS/VBL/VBH not used */ |
| 420 | ENDDEF, 0x00 |
| 421 | }; |
| 422 | |
| 423 | static const unsigned short seq_el_on[] = { |
| 424 | 0xF3, 0x37, |
| 425 | |
| 426 | DATA_ONLY, 0xFF, |
| 427 | /* DATA_ONLY, 0x73, VMOS/VBL/VBH not used */ |
| 428 | DATA_ONLY, 0x87, |
| 429 | DATA_ONLY, 0x00, |
| 430 | DATA_ONLY, 0x03, |
| 431 | /* DATA_ONLY, 0x02, VMOS/VBL/VBH not used */ |
| 432 | ENDDEF, 0x00 |
| 433 | }; |
| 434 | |
| 435 | static int ld9040_spi_write_byte(struct ld9040 *lcd, int addr, int data) |
| 436 | { |
| 437 | u16 buf[1]; |
| 438 | struct spi_message msg; |
| 439 | |
| 440 | struct spi_transfer xfer = { |
| 441 | .len = 2, |
| 442 | .tx_buf = buf, |
| 443 | }; |
| 444 | |
| 445 | buf[0] = (addr << 8) | data; |
| 446 | |
| 447 | spi_message_init(&msg); |
| 448 | spi_message_add_tail(&xfer, &msg); |
| 449 | |
| 450 | return spi_sync(lcd->spi, &msg); |
| 451 | } |
| 452 | |
| 453 | static int ld9040_spi_write(struct ld9040 *lcd, unsigned char address, |
| 454 | unsigned char command) |
| 455 | { |
| 456 | int ret = 0; |
| 457 | |
| 458 | if (address != DATA_ONLY) |
| 459 | ret = ld9040_spi_write_byte(lcd, 0x0, address); |
| 460 | if (command != COMMAND_ONLY) |
| 461 | ret = ld9040_spi_write_byte(lcd, 0x1, command); |
| 462 | |
| 463 | return ret; |
| 464 | } |
| 465 | |
| 466 | static int ld9040_panel_send_sequence(struct ld9040 *lcd, |
| 467 | const unsigned short *wbuf) |
| 468 | { |
| 469 | int ret = 0, i = 0; |
| 470 | |
| 471 | while ((wbuf[i] & DEFMASK) != ENDDEF) { |
| 472 | if ((wbuf[i] & DEFMASK) != SLEEPMSEC) { |
| 473 | ret = ld9040_spi_write(lcd, wbuf[i], wbuf[i+1]); |
| 474 | if (ret) |
| 475 | break; |
Jingoo Han | d2fff29 | 2013-02-21 16:43:15 -0800 | [diff] [blame] | 476 | } else { |
| 477 | msleep(wbuf[i+1]); |
| 478 | } |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 479 | i += 2; |
| 480 | } |
| 481 | |
| 482 | return ret; |
| 483 | } |
| 484 | |
| 485 | static int _ld9040_gamma_ctl(struct ld9040 *lcd, const unsigned int *gamma) |
| 486 | { |
| 487 | unsigned int i = 0; |
| 488 | int ret = 0; |
| 489 | |
| 490 | /* start gamma table updating. */ |
| 491 | ret = ld9040_panel_send_sequence(lcd, seq_gamma_start); |
| 492 | if (ret) { |
| 493 | dev_err(lcd->dev, "failed to disable gamma table updating.\n"); |
| 494 | goto gamma_err; |
| 495 | } |
| 496 | |
| 497 | for (i = 0 ; i < GAMMA_TABLE_COUNT; i++) { |
| 498 | ret = ld9040_spi_write(lcd, DATA_ONLY, gamma[i]); |
| 499 | if (ret) { |
| 500 | dev_err(lcd->dev, "failed to set gamma table.\n"); |
| 501 | goto gamma_err; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | /* update gamma table. */ |
| 506 | ret = ld9040_panel_send_sequence(lcd, seq_gamma_ctrl); |
| 507 | if (ret) |
| 508 | dev_err(lcd->dev, "failed to update gamma table.\n"); |
| 509 | |
| 510 | gamma_err: |
| 511 | return ret; |
| 512 | } |
| 513 | |
| 514 | static int ld9040_gamma_ctl(struct ld9040 *lcd, int gamma) |
| 515 | { |
Jingoo Han | 2ca8b90 | 2013-02-21 16:43:18 -0800 | [diff] [blame^] | 516 | return _ld9040_gamma_ctl(lcd, gamma_table.gamma_22_table[gamma]); |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 519 | static int ld9040_ldi_init(struct ld9040 *lcd) |
| 520 | { |
| 521 | int ret, i; |
| 522 | static const unsigned short *init_seq[] = { |
| 523 | seq_user_setting, |
| 524 | seq_panel_condition, |
| 525 | seq_display_ctrl, |
| 526 | seq_manual_pwr, |
| 527 | seq_elvss_on, |
| 528 | seq_gtcon, |
| 529 | seq_gamma_set1, |
| 530 | seq_gamma_ctrl, |
| 531 | seq_sleep_out, |
| 532 | }; |
| 533 | |
| 534 | for (i = 0; i < ARRAY_SIZE(init_seq); i++) { |
| 535 | ret = ld9040_panel_send_sequence(lcd, init_seq[i]); |
| 536 | /* workaround: minimum delay time for transferring CMD */ |
Jingoo Han | d2fff29 | 2013-02-21 16:43:15 -0800 | [diff] [blame] | 537 | usleep_range(300, 310); |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 538 | if (ret) |
| 539 | break; |
| 540 | } |
| 541 | |
| 542 | return ret; |
| 543 | } |
| 544 | |
| 545 | static int ld9040_ldi_enable(struct ld9040 *lcd) |
| 546 | { |
Jingoo Han | 2ca8b90 | 2013-02-21 16:43:18 -0800 | [diff] [blame^] | 547 | return ld9040_panel_send_sequence(lcd, seq_display_on); |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | static int ld9040_ldi_disable(struct ld9040 *lcd) |
| 551 | { |
| 552 | int ret; |
| 553 | |
| 554 | ret = ld9040_panel_send_sequence(lcd, seq_display_off); |
| 555 | ret = ld9040_panel_send_sequence(lcd, seq_sleep_in); |
| 556 | |
| 557 | return ret; |
| 558 | } |
| 559 | |
Jingoo Han | e2ffe85 | 2013-02-21 16:43:16 -0800 | [diff] [blame] | 560 | static int ld9040_power_is_on(int power) |
| 561 | { |
| 562 | return power <= FB_BLANK_NORMAL; |
| 563 | } |
| 564 | |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 565 | static int ld9040_power_on(struct ld9040 *lcd) |
| 566 | { |
| 567 | int ret = 0; |
Jingoo Han | e2ffe85 | 2013-02-21 16:43:16 -0800 | [diff] [blame] | 568 | struct lcd_platform_data *pd; |
| 569 | |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 570 | pd = lcd->lcd_pd; |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 571 | |
Donghwa Lee | b148a27 | 2012-01-10 15:09:15 -0800 | [diff] [blame] | 572 | /* lcd power on */ |
| 573 | ld9040_regulator_enable(lcd); |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 574 | |
| 575 | if (!pd->reset) { |
| 576 | dev_err(lcd->dev, "reset is NULL.\n"); |
Jingoo Han | 30f085c | 2013-02-21 16:43:17 -0800 | [diff] [blame] | 577 | return -EINVAL; |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 578 | } else { |
| 579 | pd->reset(lcd->ld); |
Jingoo Han | d2fff29 | 2013-02-21 16:43:15 -0800 | [diff] [blame] | 580 | msleep(pd->reset_delay); |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | ret = ld9040_ldi_init(lcd); |
| 584 | if (ret) { |
| 585 | dev_err(lcd->dev, "failed to initialize ldi.\n"); |
| 586 | return ret; |
| 587 | } |
| 588 | |
| 589 | ret = ld9040_ldi_enable(lcd); |
| 590 | if (ret) { |
| 591 | dev_err(lcd->dev, "failed to enable ldi.\n"); |
| 592 | return ret; |
| 593 | } |
| 594 | |
| 595 | return 0; |
| 596 | } |
| 597 | |
| 598 | static int ld9040_power_off(struct ld9040 *lcd) |
| 599 | { |
Jingoo Han | e2ffe85 | 2013-02-21 16:43:16 -0800 | [diff] [blame] | 600 | int ret; |
| 601 | struct lcd_platform_data *pd; |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 602 | |
| 603 | pd = lcd->lcd_pd; |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 604 | |
| 605 | ret = ld9040_ldi_disable(lcd); |
| 606 | if (ret) { |
| 607 | dev_err(lcd->dev, "lcd setting failed.\n"); |
| 608 | return -EIO; |
| 609 | } |
| 610 | |
Jingoo Han | d2fff29 | 2013-02-21 16:43:15 -0800 | [diff] [blame] | 611 | msleep(pd->power_off_delay); |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 612 | |
Donghwa Lee | b148a27 | 2012-01-10 15:09:15 -0800 | [diff] [blame] | 613 | /* lcd power off */ |
| 614 | ld9040_regulator_disable(lcd); |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 615 | |
| 616 | return 0; |
| 617 | } |
| 618 | |
| 619 | static int ld9040_power(struct ld9040 *lcd, int power) |
| 620 | { |
| 621 | int ret = 0; |
| 622 | |
Jingoo Han | e2ffe85 | 2013-02-21 16:43:16 -0800 | [diff] [blame] | 623 | if (ld9040_power_is_on(power) && !ld9040_power_is_on(lcd->power)) |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 624 | ret = ld9040_power_on(lcd); |
Jingoo Han | e2ffe85 | 2013-02-21 16:43:16 -0800 | [diff] [blame] | 625 | else if (!ld9040_power_is_on(power) && ld9040_power_is_on(lcd->power)) |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 626 | ret = ld9040_power_off(lcd); |
| 627 | |
| 628 | if (!ret) |
| 629 | lcd->power = power; |
| 630 | |
| 631 | return ret; |
| 632 | } |
| 633 | |
| 634 | static int ld9040_set_power(struct lcd_device *ld, int power) |
| 635 | { |
| 636 | struct ld9040 *lcd = lcd_get_data(ld); |
| 637 | |
| 638 | if (power != FB_BLANK_UNBLANK && power != FB_BLANK_POWERDOWN && |
| 639 | power != FB_BLANK_NORMAL) { |
| 640 | dev_err(lcd->dev, "power value should be 0, 1 or 4.\n"); |
| 641 | return -EINVAL; |
| 642 | } |
| 643 | |
| 644 | return ld9040_power(lcd, power); |
| 645 | } |
| 646 | |
| 647 | static int ld9040_get_power(struct lcd_device *ld) |
| 648 | { |
| 649 | struct ld9040 *lcd = lcd_get_data(ld); |
| 650 | |
| 651 | return lcd->power; |
| 652 | } |
| 653 | |
| 654 | static int ld9040_get_brightness(struct backlight_device *bd) |
| 655 | { |
| 656 | return bd->props.brightness; |
| 657 | } |
| 658 | |
| 659 | static int ld9040_set_brightness(struct backlight_device *bd) |
| 660 | { |
| 661 | int ret = 0, brightness = bd->props.brightness; |
| 662 | struct ld9040 *lcd = bl_get_data(bd); |
| 663 | |
| 664 | if (brightness < MIN_BRIGHTNESS || |
| 665 | brightness > bd->props.max_brightness) { |
| 666 | dev_err(&bd->dev, "lcd brightness should be %d to %d.\n", |
| 667 | MIN_BRIGHTNESS, MAX_BRIGHTNESS); |
| 668 | return -EINVAL; |
| 669 | } |
| 670 | |
| 671 | ret = ld9040_gamma_ctl(lcd, bd->props.brightness); |
| 672 | if (ret) { |
| 673 | dev_err(&bd->dev, "lcd brightness setting failed.\n"); |
| 674 | return -EIO; |
| 675 | } |
| 676 | |
| 677 | return ret; |
| 678 | } |
| 679 | |
| 680 | static struct lcd_ops ld9040_lcd_ops = { |
| 681 | .set_power = ld9040_set_power, |
| 682 | .get_power = ld9040_get_power, |
| 683 | }; |
| 684 | |
| 685 | static const struct backlight_ops ld9040_backlight_ops = { |
| 686 | .get_brightness = ld9040_get_brightness, |
| 687 | .update_status = ld9040_set_brightness, |
| 688 | }; |
| 689 | |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 690 | static int ld9040_probe(struct spi_device *spi) |
| 691 | { |
| 692 | int ret = 0; |
| 693 | struct ld9040 *lcd = NULL; |
| 694 | struct lcd_device *ld = NULL; |
| 695 | struct backlight_device *bd = NULL; |
Axel Lin | ef22f6a | 2011-07-25 17:12:01 -0700 | [diff] [blame] | 696 | struct backlight_properties props; |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 697 | |
Jingoo Han | 86f6be4 | 2012-05-29 15:07:23 -0700 | [diff] [blame] | 698 | lcd = devm_kzalloc(&spi->dev, sizeof(struct ld9040), GFP_KERNEL); |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 699 | if (!lcd) |
| 700 | return -ENOMEM; |
| 701 | |
| 702 | /* ld9040 lcd panel uses 3-wire 9bits SPI Mode. */ |
| 703 | spi->bits_per_word = 9; |
| 704 | |
| 705 | ret = spi_setup(spi); |
| 706 | if (ret < 0) { |
| 707 | dev_err(&spi->dev, "spi setup failed.\n"); |
Jingoo Han | 86f6be4 | 2012-05-29 15:07:23 -0700 | [diff] [blame] | 708 | return ret; |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | lcd->spi = spi; |
| 712 | lcd->dev = &spi->dev; |
| 713 | |
| 714 | lcd->lcd_pd = spi->dev.platform_data; |
| 715 | if (!lcd->lcd_pd) { |
| 716 | dev_err(&spi->dev, "platform data is NULL.\n"); |
Jingoo Han | 30f085c | 2013-02-21 16:43:17 -0800 | [diff] [blame] | 717 | return -EINVAL; |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Donghwa Lee | b148a27 | 2012-01-10 15:09:15 -0800 | [diff] [blame] | 720 | mutex_init(&lcd->lock); |
| 721 | |
| 722 | ret = regulator_bulk_get(lcd->dev, ARRAY_SIZE(supplies), supplies); |
| 723 | if (ret) { |
| 724 | dev_err(lcd->dev, "Failed to get regulators: %d\n", ret); |
Jingoo Han | 86f6be4 | 2012-05-29 15:07:23 -0700 | [diff] [blame] | 725 | return ret; |
Donghwa Lee | b148a27 | 2012-01-10 15:09:15 -0800 | [diff] [blame] | 726 | } |
| 727 | |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 728 | ld = lcd_device_register("ld9040", &spi->dev, lcd, &ld9040_lcd_ops); |
| 729 | if (IS_ERR(ld)) { |
| 730 | ret = PTR_ERR(ld); |
Jingoo Han | 86f6be4 | 2012-05-29 15:07:23 -0700 | [diff] [blame] | 731 | goto out_free_regulator; |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | lcd->ld = ld; |
| 735 | |
Axel Lin | ef22f6a | 2011-07-25 17:12:01 -0700 | [diff] [blame] | 736 | memset(&props, 0, sizeof(struct backlight_properties)); |
| 737 | props.type = BACKLIGHT_RAW; |
| 738 | props.max_brightness = MAX_BRIGHTNESS; |
| 739 | |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 740 | bd = backlight_device_register("ld9040-bl", &spi->dev, |
Axel Lin | ef22f6a | 2011-07-25 17:12:01 -0700 | [diff] [blame] | 741 | lcd, &ld9040_backlight_ops, &props); |
Axel Lin | e2e7da9 | 2011-07-25 17:11:58 -0700 | [diff] [blame] | 742 | if (IS_ERR(bd)) { |
| 743 | ret = PTR_ERR(bd); |
| 744 | goto out_unregister_lcd; |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 747 | bd->props.brightness = MAX_BRIGHTNESS; |
| 748 | lcd->bd = bd; |
| 749 | |
| 750 | /* |
| 751 | * if lcd panel was on from bootloader like u-boot then |
| 752 | * do not lcd on. |
| 753 | */ |
| 754 | if (!lcd->lcd_pd->lcd_enabled) { |
| 755 | /* |
| 756 | * if lcd panel was off from bootloader then |
| 757 | * current lcd status is powerdown and then |
| 758 | * it enables lcd panel. |
| 759 | */ |
| 760 | lcd->power = FB_BLANK_POWERDOWN; |
| 761 | |
| 762 | ld9040_power(lcd, FB_BLANK_UNBLANK); |
Jingoo Han | e2ffe85 | 2013-02-21 16:43:16 -0800 | [diff] [blame] | 763 | } else { |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 764 | lcd->power = FB_BLANK_UNBLANK; |
Jingoo Han | e2ffe85 | 2013-02-21 16:43:16 -0800 | [diff] [blame] | 765 | } |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 766 | |
| 767 | dev_set_drvdata(&spi->dev, lcd); |
| 768 | |
| 769 | dev_info(&spi->dev, "ld9040 panel driver has been probed.\n"); |
| 770 | return 0; |
| 771 | |
Axel Lin | e2e7da9 | 2011-07-25 17:11:58 -0700 | [diff] [blame] | 772 | out_unregister_lcd: |
| 773 | lcd_device_unregister(lcd->ld); |
Jingoo Han | 86f6be4 | 2012-05-29 15:07:23 -0700 | [diff] [blame] | 774 | out_free_regulator: |
Donghwa Lee | b148a27 | 2012-01-10 15:09:15 -0800 | [diff] [blame] | 775 | regulator_bulk_free(ARRAY_SIZE(supplies), supplies); |
| 776 | |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 777 | return ret; |
| 778 | } |
| 779 | |
Bill Pemberton | 7e4b9d0 | 2012-11-19 13:26:34 -0500 | [diff] [blame] | 780 | static int ld9040_remove(struct spi_device *spi) |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 781 | { |
| 782 | struct ld9040 *lcd = dev_get_drvdata(&spi->dev); |
| 783 | |
| 784 | ld9040_power(lcd, FB_BLANK_POWERDOWN); |
Axel Lin | e2e7da9 | 2011-07-25 17:11:58 -0700 | [diff] [blame] | 785 | backlight_device_unregister(lcd->bd); |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 786 | lcd_device_unregister(lcd->ld); |
Donghwa Lee | b148a27 | 2012-01-10 15:09:15 -0800 | [diff] [blame] | 787 | regulator_bulk_free(ARRAY_SIZE(supplies), supplies); |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 788 | |
| 789 | return 0; |
| 790 | } |
| 791 | |
| 792 | #if defined(CONFIG_PM) |
| 793 | static int ld9040_suspend(struct spi_device *spi, pm_message_t mesg) |
| 794 | { |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 795 | struct ld9040 *lcd = dev_get_drvdata(&spi->dev); |
| 796 | |
| 797 | dev_dbg(&spi->dev, "lcd->power = %d\n", lcd->power); |
| 798 | |
| 799 | /* |
| 800 | * when lcd panel is suspend, lcd panel becomes off |
| 801 | * regardless of status. |
| 802 | */ |
Jingoo Han | 2ca8b90 | 2013-02-21 16:43:18 -0800 | [diff] [blame^] | 803 | return ld9040_power(lcd, FB_BLANK_POWERDOWN); |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | static int ld9040_resume(struct spi_device *spi) |
| 807 | { |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 808 | struct ld9040 *lcd = dev_get_drvdata(&spi->dev); |
| 809 | |
| 810 | lcd->power = FB_BLANK_POWERDOWN; |
| 811 | |
Jingoo Han | 2ca8b90 | 2013-02-21 16:43:18 -0800 | [diff] [blame^] | 812 | return ld9040_power(lcd, FB_BLANK_UNBLANK); |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 813 | } |
| 814 | #else |
| 815 | #define ld9040_suspend NULL |
| 816 | #define ld9040_resume NULL |
| 817 | #endif |
| 818 | |
| 819 | /* Power down all displays on reboot, poweroff or halt. */ |
| 820 | static void ld9040_shutdown(struct spi_device *spi) |
| 821 | { |
| 822 | struct ld9040 *lcd = dev_get_drvdata(&spi->dev); |
| 823 | |
| 824 | ld9040_power(lcd, FB_BLANK_POWERDOWN); |
| 825 | } |
| 826 | |
| 827 | static struct spi_driver ld9040_driver = { |
| 828 | .driver = { |
| 829 | .name = "ld9040", |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 830 | .owner = THIS_MODULE, |
| 831 | }, |
| 832 | .probe = ld9040_probe, |
Bill Pemberton | d1723fa | 2012-11-19 13:21:09 -0500 | [diff] [blame] | 833 | .remove = ld9040_remove, |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 834 | .shutdown = ld9040_shutdown, |
| 835 | .suspend = ld9040_suspend, |
| 836 | .resume = ld9040_resume, |
| 837 | }; |
| 838 | |
Axel Lin | 462dd83 | 2012-03-23 15:01:59 -0700 | [diff] [blame] | 839 | module_spi_driver(ld9040_driver); |
Donghwa Lee | 1baf0eb | 2011-03-22 16:30:18 -0700 | [diff] [blame] | 840 | |
| 841 | MODULE_AUTHOR("Donghwa Lee <dh09.lee@samsung.com>"); |
| 842 | MODULE_DESCRIPTION("ld9040 LCD Driver"); |
| 843 | MODULE_LICENSE("GPL"); |