Jeevan Shriram | 033ee13 | 2012-02-28 12:24:39 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2008-2010, 2012 Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include "msm_fb.h" |
| 15 | #include "mddihost.h" |
| 16 | #include "mddihosti.h" |
| 17 | |
| 18 | #define SHARP_QVGA_PRIM 1 |
| 19 | #define SHARP_128X128_SECD 2 |
| 20 | |
| 21 | extern uint32 mddi_host_core_version; |
| 22 | static boolean mddi_debug_prim_wait = FALSE; |
| 23 | static boolean mddi_sharp_vsync_wake = TRUE; |
| 24 | static boolean mddi_sharp_monitor_refresh_value = TRUE; |
| 25 | static boolean mddi_sharp_report_refresh_measurements = FALSE; |
| 26 | static uint32 mddi_sharp_rows_per_second = 13830; /* 5200000/376 */ |
| 27 | static uint32 mddi_sharp_rows_per_refresh = 338; |
| 28 | static uint32 mddi_sharp_usecs_per_refresh = 24440; /* (376+338)/5200000 */ |
| 29 | static boolean mddi_sharp_debug_60hz_refresh = FALSE; |
| 30 | |
| 31 | extern mddi_gpio_info_type mddi_gpio; |
| 32 | extern boolean mddi_vsync_detect_enabled; |
| 33 | static msm_fb_vsync_handler_type mddi_sharp_vsync_handler; |
| 34 | static void *mddi_sharp_vsync_handler_arg; |
| 35 | static uint16 mddi_sharp_vsync_attempts; |
| 36 | |
| 37 | static void mddi_sharp_prim_lcd_init(void); |
| 38 | static void mddi_sharp_sub_lcd_init(void); |
| 39 | static void mddi_sharp_lcd_set_backlight(struct msm_fb_data_type *mfd); |
| 40 | static void mddi_sharp_vsync_set_handler(msm_fb_vsync_handler_type handler, |
| 41 | void *); |
| 42 | static void mddi_sharp_lcd_vsync_detected(boolean detected); |
| 43 | static struct msm_panel_common_pdata *mddi_sharp_pdata; |
| 44 | |
| 45 | #define REG_SYSCTL 0x0000 |
| 46 | #define REG_INTR 0x0006 |
| 47 | #define REG_CLKCNF 0x000C |
| 48 | #define REG_CLKDIV1 0x000E |
| 49 | #define REG_CLKDIV2 0x0010 |
| 50 | |
| 51 | #define REG_GIOD 0x0040 |
| 52 | #define REG_GIOA 0x0042 |
| 53 | |
| 54 | #define REG_AGM 0x010A |
| 55 | #define REG_FLFT 0x0110 |
| 56 | #define REG_FRGT 0x0112 |
| 57 | #define REG_FTOP 0x0114 |
| 58 | #define REG_FBTM 0x0116 |
| 59 | #define REG_FSTRX 0x0118 |
| 60 | #define REG_FSTRY 0x011A |
| 61 | #define REG_VRAM 0x0202 |
| 62 | #define REG_SSDCTL 0x0330 |
| 63 | #define REG_SSD0 0x0332 |
| 64 | #define REG_PSTCTL1 0x0400 |
| 65 | #define REG_PSTCTL2 0x0402 |
| 66 | #define REG_PTGCTL 0x042A |
| 67 | #define REG_PTHP 0x042C |
| 68 | #define REG_PTHB 0x042E |
| 69 | #define REG_PTHW 0x0430 |
| 70 | #define REG_PTHF 0x0432 |
| 71 | #define REG_PTVP 0x0434 |
| 72 | #define REG_PTVB 0x0436 |
| 73 | #define REG_PTVW 0x0438 |
| 74 | #define REG_PTVF 0x043A |
| 75 | #define REG_VBLKS 0x0458 |
| 76 | #define REG_VBLKE 0x045A |
| 77 | #define REG_SUBCTL 0x0700 |
| 78 | #define REG_SUBTCMD 0x0702 |
| 79 | #define REG_SUBTCMDD 0x0704 |
| 80 | #define REG_REVBYTE 0x0A02 |
| 81 | #define REG_REVCNT 0x0A04 |
| 82 | #define REG_REVATTR 0x0A06 |
| 83 | #define REG_REVFMT 0x0A08 |
| 84 | |
| 85 | #define SHARP_SUB_UNKNOWN 0xffffffff |
| 86 | #define SHARP_SUB_HYNIX 1 |
| 87 | #define SHARP_SUB_ROHM 2 |
| 88 | |
| 89 | static uint32 sharp_subpanel_type = SHARP_SUB_UNKNOWN; |
| 90 | |
| 91 | static void sub_through_write(int sub_rs, uint32 sub_data) |
| 92 | { |
| 93 | mddi_queue_register_write(REG_SUBTCMDD, sub_data, FALSE, 0); |
| 94 | |
| 95 | /* CS=1,RD=1,WE=1,RS=sub_rs */ |
| 96 | mddi_queue_register_write(REG_SUBTCMD, 0x000e | sub_rs, FALSE, 0); |
| 97 | |
| 98 | /* CS=0,RD=1,WE=1,RS=sub_rs */ |
| 99 | mddi_queue_register_write(REG_SUBTCMD, 0x0006 | sub_rs, FALSE, 0); |
| 100 | |
| 101 | /* CS=0,RD=1,WE=0,RS=sub_rs */ |
| 102 | mddi_queue_register_write(REG_SUBTCMD, 0x0004 | sub_rs, FALSE, 0); |
| 103 | |
| 104 | /* CS=0,RD=1,WE=1,RS=sub_rs */ |
| 105 | mddi_queue_register_write(REG_SUBTCMD, 0x0006 | sub_rs, FALSE, 0); |
| 106 | |
| 107 | /* CS=1,RD=1,WE=1,RS=sub_rs */ |
| 108 | mddi_queue_register_write(REG_SUBTCMD, 0x000e | sub_rs, TRUE, 0); |
| 109 | } |
| 110 | |
| 111 | static uint32 sub_through_read(int sub_rs) |
| 112 | { |
| 113 | uint32 sub_data; |
| 114 | |
| 115 | /* CS=1,RD=1,WE=1,RS=sub_rs */ |
| 116 | mddi_queue_register_write(REG_SUBTCMD, 0x000e | sub_rs, FALSE, 0); |
| 117 | |
| 118 | /* CS=0,RD=1,WE=1,RS=sub_rs */ |
| 119 | mddi_queue_register_write(REG_SUBTCMD, 0x0006 | sub_rs, FALSE, 0); |
| 120 | |
| 121 | /* CS=0,RD=1,WE=0,RS=sub_rs */ |
| 122 | mddi_queue_register_write(REG_SUBTCMD, 0x0002 | sub_rs, TRUE, 0); |
| 123 | |
| 124 | mddi_queue_register_read(REG_SUBTCMDD, &sub_data, TRUE, 0); |
| 125 | |
| 126 | /* CS=0,RD=1,WE=1,RS=sub_rs */ |
| 127 | mddi_queue_register_write(REG_SUBTCMD, 0x0006 | sub_rs, FALSE, 0); |
| 128 | |
| 129 | /* CS=1,RD=1,WE=1,RS=sub_rs */ |
| 130 | mddi_queue_register_write(REG_SUBTCMD, 0x000e | sub_rs, TRUE, 0); |
| 131 | |
| 132 | return sub_data; |
| 133 | } |
| 134 | |
| 135 | static void serigo(uint32 ssd) |
| 136 | { |
| 137 | uint32 ssdctl; |
| 138 | |
| 139 | mddi_queue_register_read(REG_SSDCTL, &ssdctl, TRUE, 0); |
| 140 | ssdctl = ((ssdctl & 0xE7) | 0x02); |
| 141 | |
| 142 | mddi_queue_register_write(REG_SSD0, ssd, FALSE, 0); |
| 143 | mddi_queue_register_write(REG_SSDCTL, ssdctl, TRUE, 0); |
| 144 | |
| 145 | do { |
| 146 | mddi_queue_register_read(REG_SSDCTL, &ssdctl, TRUE, 0); |
| 147 | } while ((ssdctl & 0x0002) != 0); |
| 148 | |
| 149 | if (mddi_debug_prim_wait) |
| 150 | mddi_wait(2); |
| 151 | } |
| 152 | |
| 153 | static void mddi_sharp_lcd_powerdown(void) |
| 154 | { |
| 155 | serigo(0x0131); |
| 156 | serigo(0x0300); |
| 157 | mddi_wait(40); |
| 158 | serigo(0x0135); |
| 159 | mddi_wait(20); |
| 160 | serigo(0x2122); |
| 161 | mddi_wait(20); |
| 162 | serigo(0x0201); |
| 163 | mddi_wait(20); |
| 164 | serigo(0x2100); |
| 165 | mddi_wait(20); |
| 166 | serigo(0x2000); |
| 167 | mddi_wait(20); |
| 168 | |
| 169 | mddi_queue_register_write(REG_PSTCTL1, 0x1, TRUE, 0); |
| 170 | mddi_wait(100); |
| 171 | mddi_queue_register_write(REG_PSTCTL1, 0x0, TRUE, 0); |
| 172 | mddi_wait(2); |
| 173 | mddi_queue_register_write(REG_SYSCTL, 0x1, TRUE, 0); |
| 174 | mddi_wait(2); |
| 175 | mddi_queue_register_write(REG_CLKDIV1, 0x3, TRUE, 0); |
| 176 | mddi_wait(2); |
| 177 | mddi_queue_register_write(REG_SSDCTL, 0x0000, TRUE, 0); /* SSDRESET */ |
| 178 | mddi_queue_register_write(REG_SYSCTL, 0x0, TRUE, 0); |
| 179 | mddi_wait(2); |
| 180 | } |
| 181 | |
| 182 | static void mddi_sharp_lcd_set_backlight(struct msm_fb_data_type *mfd) |
| 183 | { |
| 184 | uint32 regdata; |
| 185 | int32 level; |
| 186 | int max = mfd->panel_info.bl_max; |
| 187 | int min = mfd->panel_info.bl_min; |
| 188 | |
| 189 | if (mddi_sharp_pdata && mddi_sharp_pdata->backlight_level) { |
| 190 | level = mddi_sharp_pdata->backlight_level(mfd->bl_level, |
| 191 | max, |
| 192 | min); |
| 193 | |
| 194 | if (level < 0) |
| 195 | return; |
| 196 | |
| 197 | /* use Rodem GPIO(2:0) to give 8 levels of backlight (7-0) */ |
| 198 | /* Set lower 3 GPIOs as Outputs (set to 0) */ |
| 199 | mddi_queue_register_read(REG_GIOA, ®data, TRUE, 0); |
| 200 | mddi_queue_register_write(REG_GIOA, regdata & 0xfff8, TRUE, 0); |
| 201 | |
| 202 | /* Set lower 3 GPIOs as level */ |
| 203 | mddi_queue_register_read(REG_GIOD, ®data, TRUE, 0); |
| 204 | mddi_queue_register_write(REG_GIOD, |
| 205 | (regdata & 0xfff8) | (0x07 & level), TRUE, 0); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | static void mddi_sharp_prim_lcd_init(void) |
| 210 | { |
| 211 | mddi_queue_register_write(REG_SYSCTL, 0x4000, TRUE, 0); |
| 212 | mddi_wait(1); |
| 213 | mddi_queue_register_write(REG_SYSCTL, 0x0000, TRUE, 0); |
| 214 | mddi_wait(5); |
| 215 | mddi_queue_register_write(REG_SYSCTL, 0x0001, FALSE, 0); |
| 216 | mddi_queue_register_write(REG_CLKDIV1, 0x000b, FALSE, 0); |
| 217 | |
| 218 | /* new reg write below */ |
| 219 | if (mddi_sharp_debug_60hz_refresh) |
| 220 | mddi_queue_register_write(REG_CLKCNF, 0x070d, FALSE, 0); |
| 221 | else |
| 222 | mddi_queue_register_write(REG_CLKCNF, 0x0708, FALSE, 0); |
| 223 | |
| 224 | mddi_queue_register_write(REG_SYSCTL, 0x0201, FALSE, 0); |
| 225 | mddi_queue_register_write(REG_PTGCTL, 0x0010, FALSE, 0); |
| 226 | mddi_queue_register_write(REG_PTHP, 4, FALSE, 0); |
| 227 | mddi_queue_register_write(REG_PTHB, 40, FALSE, 0); |
| 228 | mddi_queue_register_write(REG_PTHW, 240, FALSE, 0); |
| 229 | if (mddi_sharp_debug_60hz_refresh) |
| 230 | mddi_queue_register_write(REG_PTHF, 12, FALSE, 0); |
| 231 | else |
| 232 | mddi_queue_register_write(REG_PTHF, 92, FALSE, 0); |
| 233 | |
| 234 | mddi_wait(1); |
| 235 | |
| 236 | mddi_queue_register_write(REG_PTVP, 1, FALSE, 0); |
| 237 | mddi_queue_register_write(REG_PTVB, 2, FALSE, 0); |
| 238 | mddi_queue_register_write(REG_PTVW, 320, FALSE, 0); |
| 239 | mddi_queue_register_write(REG_PTVF, 15, FALSE, 0); |
| 240 | |
| 241 | mddi_wait(1); |
| 242 | |
| 243 | /* vram_color set REG_AGM???? */ |
| 244 | mddi_queue_register_write(REG_AGM, 0x0000, TRUE, 0); |
| 245 | |
| 246 | mddi_queue_register_write(REG_SSDCTL, 0x0000, FALSE, 0); |
| 247 | mddi_queue_register_write(REG_SSDCTL, 0x0001, TRUE, 0); |
| 248 | mddi_wait(1); |
| 249 | mddi_queue_register_write(REG_PSTCTL1, 0x0001, TRUE, 0); |
| 250 | mddi_wait(10); |
| 251 | |
| 252 | serigo(0x0701); |
| 253 | /* software reset */ |
| 254 | mddi_wait(1); |
| 255 | /* Wait over 50us */ |
| 256 | |
| 257 | serigo(0x0400); |
| 258 | /* DCLK~ACHSYNC~ACVSYNC polarity setting */ |
| 259 | serigo(0x2900); |
| 260 | /* EEPROM start read address setting */ |
| 261 | serigo(0x2606); |
| 262 | /* EEPROM start read register setting */ |
| 263 | mddi_wait(20); |
| 264 | /* Wait over 20ms */ |
| 265 | |
| 266 | serigo(0x0503); |
| 267 | /* Horizontal timing setting */ |
| 268 | serigo(0x062C); |
| 269 | /* Veritical timing setting */ |
| 270 | serigo(0x2001); |
| 271 | /* power initialize setting(VDC2) */ |
| 272 | mddi_wait(20); |
| 273 | /* Wait over 20ms */ |
| 274 | |
| 275 | serigo(0x2120); |
| 276 | /* Initialize power setting(CPS) */ |
| 277 | mddi_wait(20); |
| 278 | /* Wait over 20ms */ |
| 279 | |
| 280 | serigo(0x2130); |
| 281 | /* Initialize power setting(CPS) */ |
| 282 | mddi_wait(20); |
| 283 | /* Wait over 20ms */ |
| 284 | |
| 285 | serigo(0x2132); |
| 286 | /* Initialize power setting(CPS) */ |
| 287 | mddi_wait(10); |
| 288 | /* Wait over 10ms */ |
| 289 | |
| 290 | serigo(0x2133); |
| 291 | /* Initialize power setting(CPS) */ |
| 292 | mddi_wait(20); |
| 293 | /* Wait over 20ms */ |
| 294 | |
| 295 | serigo(0x0200); |
| 296 | /* Panel initialize release(INIT) */ |
| 297 | mddi_wait(1); |
| 298 | /* Wait over 1ms */ |
| 299 | |
| 300 | serigo(0x0131); |
| 301 | /* Panel setting(CPS) */ |
| 302 | mddi_wait(1); |
| 303 | /* Wait over 1ms */ |
| 304 | |
| 305 | mddi_queue_register_write(REG_PSTCTL1, 0x0003, TRUE, 0); |
| 306 | |
| 307 | /* if (FFA LCD is upside down) -> serigo(0x0100); */ |
| 308 | serigo(0x0130); |
| 309 | |
| 310 | /* Black mask release(display ON) */ |
| 311 | mddi_wait(1); |
| 312 | /* Wait over 1ms */ |
| 313 | |
| 314 | if (mddi_sharp_vsync_wake) { |
| 315 | mddi_queue_register_write(REG_VBLKS, 0x1001, TRUE, 0); |
| 316 | mddi_queue_register_write(REG_VBLKE, 0x1002, TRUE, 0); |
| 317 | } |
| 318 | |
| 319 | /* Set the MDP pixel data attributes for Primary Display */ |
| 320 | mddi_host_write_pix_attr_reg(0x00C3); |
| 321 | return; |
| 322 | |
| 323 | } |
| 324 | |
| 325 | void mddi_sharp_sub_lcd_init(void) |
| 326 | { |
| 327 | |
| 328 | mddi_queue_register_write(REG_SYSCTL, 0x4000, FALSE, 0); |
| 329 | mddi_queue_register_write(REG_SYSCTL, 0x0000, TRUE, 0); |
| 330 | mddi_wait(100); |
| 331 | |
| 332 | mddi_queue_register_write(REG_SYSCTL, 0x0001, FALSE, 0); |
| 333 | mddi_queue_register_write(REG_CLKDIV1, 0x000b, FALSE, 0); |
| 334 | mddi_queue_register_write(REG_CLKCNF, 0x0708, FALSE, 0); |
| 335 | mddi_queue_register_write(REG_SYSCTL, 0x0201, FALSE, 0); |
| 336 | mddi_queue_register_write(REG_PTGCTL, 0x0010, FALSE, 0); |
| 337 | mddi_queue_register_write(REG_PTHP, 4, FALSE, 0); |
| 338 | mddi_queue_register_write(REG_PTHB, 40, FALSE, 0); |
| 339 | mddi_queue_register_write(REG_PTHW, 128, FALSE, 0); |
| 340 | mddi_queue_register_write(REG_PTHF, 92, FALSE, 0); |
| 341 | mddi_queue_register_write(REG_PTVP, 1, FALSE, 0); |
| 342 | mddi_queue_register_write(REG_PTVB, 2, FALSE, 0); |
| 343 | mddi_queue_register_write(REG_PTVW, 128, FALSE, 0); |
| 344 | mddi_queue_register_write(REG_PTVF, 15, FALSE, 0); |
| 345 | |
| 346 | /* Now the sub display..... */ |
| 347 | /* Reset High */ |
| 348 | mddi_queue_register_write(REG_SUBCTL, 0x0200, FALSE, 0); |
| 349 | /* CS=1,RD=1,WE=1,RS=1 */ |
| 350 | mddi_queue_register_write(REG_SUBTCMD, 0x000f, TRUE, 0); |
| 351 | mddi_wait(1); |
| 352 | /* Wait 5us */ |
| 353 | |
| 354 | if (sharp_subpanel_type == SHARP_SUB_UNKNOWN) { |
| 355 | uint32 data; |
| 356 | |
| 357 | sub_through_write(1, 0x05); |
| 358 | sub_through_write(1, 0x6A); |
| 359 | sub_through_write(1, 0x1D); |
| 360 | sub_through_write(1, 0x05); |
| 361 | data = sub_through_read(1); |
| 362 | if (data == 0x6A) { |
| 363 | sharp_subpanel_type = SHARP_SUB_HYNIX; |
| 364 | } else { |
| 365 | sub_through_write(0, 0x36); |
| 366 | sub_through_write(1, 0xA8); |
| 367 | sub_through_write(0, 0x09); |
| 368 | data = sub_through_read(1); |
| 369 | data = sub_through_read(1); |
| 370 | if (data == 0x54) { |
| 371 | sub_through_write(0, 0x36); |
| 372 | sub_through_write(1, 0x00); |
| 373 | sharp_subpanel_type = SHARP_SUB_ROHM; |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | if (sharp_subpanel_type == SHARP_SUB_HYNIX) { |
| 379 | sub_through_write(1, 0x00); /* Display setting 1 */ |
| 380 | sub_through_write(1, 0x04); |
| 381 | sub_through_write(1, 0x01); |
| 382 | sub_through_write(1, 0x05); |
| 383 | sub_through_write(1, 0x0280); |
| 384 | sub_through_write(1, 0x0301); |
| 385 | sub_through_write(1, 0x0402); |
| 386 | sub_through_write(1, 0x0500); |
| 387 | sub_through_write(1, 0x0681); |
| 388 | sub_through_write(1, 0x077F); |
| 389 | sub_through_write(1, 0x08C0); |
| 390 | sub_through_write(1, 0x0905); |
| 391 | sub_through_write(1, 0x0A02); |
| 392 | sub_through_write(1, 0x0B00); |
| 393 | sub_through_write(1, 0x0C00); |
| 394 | sub_through_write(1, 0x0D00); |
| 395 | sub_through_write(1, 0x0E00); |
| 396 | sub_through_write(1, 0x0F00); |
| 397 | |
| 398 | sub_through_write(1, 0x100B); /* Display setting 2 */ |
| 399 | sub_through_write(1, 0x1103); |
| 400 | sub_through_write(1, 0x1237); |
| 401 | sub_through_write(1, 0x1300); |
| 402 | sub_through_write(1, 0x1400); |
| 403 | sub_through_write(1, 0x1500); |
| 404 | sub_through_write(1, 0x1605); |
| 405 | sub_through_write(1, 0x1700); |
| 406 | sub_through_write(1, 0x1800); |
| 407 | sub_through_write(1, 0x192E); |
| 408 | sub_through_write(1, 0x1A00); |
| 409 | sub_through_write(1, 0x1B00); |
| 410 | sub_through_write(1, 0x1C00); |
| 411 | |
| 412 | sub_through_write(1, 0x151A); /* Power setting */ |
| 413 | |
| 414 | sub_through_write(1, 0x2002); /* Gradation Palette setting */ |
| 415 | sub_through_write(1, 0x2107); |
| 416 | sub_through_write(1, 0x220C); |
| 417 | sub_through_write(1, 0x2310); |
| 418 | sub_through_write(1, 0x2414); |
| 419 | sub_through_write(1, 0x2518); |
| 420 | sub_through_write(1, 0x261C); |
| 421 | sub_through_write(1, 0x2720); |
| 422 | sub_through_write(1, 0x2824); |
| 423 | sub_through_write(1, 0x2928); |
| 424 | sub_through_write(1, 0x2A2B); |
| 425 | sub_through_write(1, 0x2B2E); |
| 426 | sub_through_write(1, 0x2C31); |
| 427 | sub_through_write(1, 0x2D34); |
| 428 | sub_through_write(1, 0x2E37); |
| 429 | sub_through_write(1, 0x2F3A); |
| 430 | sub_through_write(1, 0x303C); |
| 431 | sub_through_write(1, 0x313E); |
| 432 | sub_through_write(1, 0x323F); |
| 433 | sub_through_write(1, 0x3340); |
| 434 | sub_through_write(1, 0x3441); |
| 435 | sub_through_write(1, 0x3543); |
| 436 | sub_through_write(1, 0x3646); |
| 437 | sub_through_write(1, 0x3749); |
| 438 | sub_through_write(1, 0x384C); |
| 439 | sub_through_write(1, 0x394F); |
| 440 | sub_through_write(1, 0x3A52); |
| 441 | sub_through_write(1, 0x3B59); |
| 442 | sub_through_write(1, 0x3C60); |
| 443 | sub_through_write(1, 0x3D67); |
| 444 | sub_through_write(1, 0x3E6E); |
| 445 | sub_through_write(1, 0x3F7F); |
| 446 | sub_through_write(1, 0x4001); |
| 447 | sub_through_write(1, 0x4107); |
| 448 | sub_through_write(1, 0x420C); |
| 449 | sub_through_write(1, 0x4310); |
| 450 | sub_through_write(1, 0x4414); |
| 451 | sub_through_write(1, 0x4518); |
| 452 | sub_through_write(1, 0x461C); |
| 453 | sub_through_write(1, 0x4720); |
| 454 | sub_through_write(1, 0x4824); |
| 455 | sub_through_write(1, 0x4928); |
| 456 | sub_through_write(1, 0x4A2B); |
| 457 | sub_through_write(1, 0x4B2E); |
| 458 | sub_through_write(1, 0x4C31); |
| 459 | sub_through_write(1, 0x4D34); |
| 460 | sub_through_write(1, 0x4E37); |
| 461 | sub_through_write(1, 0x4F3A); |
| 462 | sub_through_write(1, 0x503C); |
| 463 | sub_through_write(1, 0x513E); |
| 464 | sub_through_write(1, 0x523F); |
| 465 | sub_through_write(1, 0x5340); |
| 466 | sub_through_write(1, 0x5441); |
| 467 | sub_through_write(1, 0x5543); |
| 468 | sub_through_write(1, 0x5646); |
| 469 | sub_through_write(1, 0x5749); |
| 470 | sub_through_write(1, 0x584C); |
| 471 | sub_through_write(1, 0x594F); |
| 472 | sub_through_write(1, 0x5A52); |
| 473 | sub_through_write(1, 0x5B59); |
| 474 | sub_through_write(1, 0x5C60); |
| 475 | sub_through_write(1, 0x5D67); |
| 476 | sub_through_write(1, 0x5E6E); |
| 477 | sub_through_write(1, 0x5F7E); |
| 478 | sub_through_write(1, 0x6000); |
| 479 | sub_through_write(1, 0x6107); |
| 480 | sub_through_write(1, 0x620C); |
| 481 | sub_through_write(1, 0x6310); |
| 482 | sub_through_write(1, 0x6414); |
| 483 | sub_through_write(1, 0x6518); |
| 484 | sub_through_write(1, 0x661C); |
| 485 | sub_through_write(1, 0x6720); |
| 486 | sub_through_write(1, 0x6824); |
| 487 | sub_through_write(1, 0x6928); |
| 488 | sub_through_write(1, 0x6A2B); |
| 489 | sub_through_write(1, 0x6B2E); |
| 490 | sub_through_write(1, 0x6C31); |
| 491 | sub_through_write(1, 0x6D34); |
| 492 | sub_through_write(1, 0x6E37); |
| 493 | sub_through_write(1, 0x6F3A); |
| 494 | sub_through_write(1, 0x703C); |
| 495 | sub_through_write(1, 0x713E); |
| 496 | sub_through_write(1, 0x723F); |
| 497 | sub_through_write(1, 0x7340); |
| 498 | sub_through_write(1, 0x7441); |
| 499 | sub_through_write(1, 0x7543); |
| 500 | sub_through_write(1, 0x7646); |
| 501 | sub_through_write(1, 0x7749); |
| 502 | sub_through_write(1, 0x784C); |
| 503 | sub_through_write(1, 0x794F); |
| 504 | sub_through_write(1, 0x7A52); |
| 505 | sub_through_write(1, 0x7B59); |
| 506 | sub_through_write(1, 0x7C60); |
| 507 | sub_through_write(1, 0x7D67); |
| 508 | sub_through_write(1, 0x7E6E); |
| 509 | sub_through_write(1, 0x7F7D); |
| 510 | |
| 511 | sub_through_write(1, 0x1851); /* Display on */ |
| 512 | |
| 513 | mddi_queue_register_write(REG_AGM, 0x0000, TRUE, 0); |
| 514 | |
| 515 | /* 1 pixel / 1 post clock */ |
| 516 | mddi_queue_register_write(REG_CLKDIV2, 0x3b00, FALSE, 0); |
| 517 | |
| 518 | /* SUB LCD select */ |
| 519 | mddi_queue_register_write(REG_PSTCTL2, 0x0080, FALSE, 0); |
| 520 | |
| 521 | /* RS=0,command initiate number=0,select master mode */ |
| 522 | mddi_queue_register_write(REG_SUBCTL, 0x0202, FALSE, 0); |
| 523 | |
| 524 | /* Sub LCD Data transform start */ |
| 525 | mddi_queue_register_write(REG_PSTCTL1, 0x0003, FALSE, 0); |
| 526 | |
| 527 | } else if (sharp_subpanel_type == SHARP_SUB_ROHM) { |
| 528 | |
| 529 | sub_through_write(0, 0x01); /* Display setting */ |
| 530 | sub_through_write(1, 0x00); |
| 531 | |
| 532 | mddi_wait(1); |
| 533 | /* Wait 100us <----- ******* Update 2005/01/24 */ |
| 534 | |
| 535 | sub_through_write(0, 0xB6); |
| 536 | sub_through_write(1, 0x0C); |
| 537 | sub_through_write(1, 0x4A); |
| 538 | sub_through_write(1, 0x20); |
| 539 | sub_through_write(0, 0x3A); |
| 540 | sub_through_write(1, 0x05); |
| 541 | sub_through_write(0, 0xB7); |
| 542 | sub_through_write(1, 0x01); |
| 543 | sub_through_write(0, 0xBA); |
| 544 | sub_through_write(1, 0x20); |
| 545 | sub_through_write(1, 0x02); |
| 546 | sub_through_write(0, 0x25); |
| 547 | sub_through_write(1, 0x4F); |
| 548 | sub_through_write(0, 0xBB); |
| 549 | sub_through_write(1, 0x00); |
| 550 | sub_through_write(0, 0x36); |
| 551 | sub_through_write(1, 0x00); |
| 552 | sub_through_write(0, 0xB1); |
| 553 | sub_through_write(1, 0x05); |
| 554 | sub_through_write(0, 0xBE); |
| 555 | sub_through_write(1, 0x80); |
| 556 | sub_through_write(0, 0x26); |
| 557 | sub_through_write(1, 0x01); |
| 558 | sub_through_write(0, 0x2A); |
| 559 | sub_through_write(1, 0x02); |
| 560 | sub_through_write(1, 0x81); |
| 561 | sub_through_write(0, 0x2B); |
| 562 | sub_through_write(1, 0x00); |
| 563 | sub_through_write(1, 0x7F); |
| 564 | |
| 565 | sub_through_write(0, 0x2C); |
| 566 | sub_through_write(0, 0x11); /* Sleep mode off */ |
| 567 | |
| 568 | mddi_wait(1); |
| 569 | /* Wait 100 ms <----- ******* Update 2005/01/24 */ |
| 570 | |
| 571 | sub_through_write(0, 0x29); /* Display on */ |
| 572 | sub_through_write(0, 0xB3); |
| 573 | sub_through_write(1, 0x20); |
| 574 | sub_through_write(1, 0xAA); |
| 575 | sub_through_write(1, 0xA0); |
| 576 | sub_through_write(1, 0x20); |
| 577 | sub_through_write(1, 0x30); |
| 578 | sub_through_write(1, 0xA6); |
| 579 | sub_through_write(1, 0xFF); |
| 580 | sub_through_write(1, 0x9A); |
| 581 | sub_through_write(1, 0x9F); |
| 582 | sub_through_write(1, 0xAF); |
| 583 | sub_through_write(1, 0xBC); |
| 584 | sub_through_write(1, 0xCF); |
| 585 | sub_through_write(1, 0xDF); |
| 586 | sub_through_write(1, 0x20); |
| 587 | sub_through_write(1, 0x9C); |
| 588 | sub_through_write(1, 0x8A); |
| 589 | |
| 590 | sub_through_write(0, 0x002C); /* Display on */ |
| 591 | |
| 592 | /* 1 pixel / 2 post clock */ |
| 593 | mddi_queue_register_write(REG_CLKDIV2, 0x7b00, FALSE, 0); |
| 594 | |
| 595 | /* SUB LCD select */ |
| 596 | mddi_queue_register_write(REG_PSTCTL2, 0x0080, FALSE, 0); |
| 597 | |
| 598 | /* RS=1,command initiate number=0,select master mode */ |
| 599 | mddi_queue_register_write(REG_SUBCTL, 0x0242, FALSE, 0); |
| 600 | |
| 601 | /* Sub LCD Data transform start */ |
| 602 | mddi_queue_register_write(REG_PSTCTL1, 0x0003, FALSE, 0); |
| 603 | |
| 604 | } |
| 605 | |
| 606 | /* Set the MDP pixel data attributes for Sub Display */ |
| 607 | mddi_host_write_pix_attr_reg(0x00C0); |
| 608 | } |
| 609 | |
| 610 | void mddi_sharp_lcd_vsync_detected(boolean detected) |
| 611 | { |
| 612 | /* static timetick_type start_time = 0; */ |
| 613 | static struct timeval start_time; |
| 614 | static boolean first_time = TRUE; |
| 615 | /* uint32 mdp_cnt_val = 0; */ |
| 616 | /* timetick_type elapsed_us; */ |
| 617 | struct timeval now; |
| 618 | uint32 elapsed_us; |
| 619 | uint32 num_vsyncs; |
| 620 | |
| 621 | if ((detected) || (mddi_sharp_vsync_attempts > 5)) { |
| 622 | if ((detected) && (mddi_sharp_monitor_refresh_value)) { |
| 623 | /* if (start_time != 0) */ |
| 624 | if (!first_time) { |
| 625 | jiffies_to_timeval(jiffies, &now); |
| 626 | elapsed_us = |
| 627 | (now.tv_sec - start_time.tv_sec) * 1000000 + |
| 628 | now.tv_usec - start_time.tv_usec; |
| 629 | /* |
| 630 | * LCD is configured for a refresh every usecs, |
| 631 | * so to determine the number of vsyncs that |
| 632 | * have occurred since the last measurement add |
| 633 | * half that to the time difference and divide |
| 634 | * by the refresh rate. |
| 635 | */ |
| 636 | num_vsyncs = (elapsed_us + |
| 637 | (mddi_sharp_usecs_per_refresh >> |
| 638 | 1)) / |
| 639 | mddi_sharp_usecs_per_refresh; |
| 640 | /* |
| 641 | * LCD is configured for * hsyncs (rows) per |
| 642 | * refresh cycle. Calculate new rows_per_second |
| 643 | * value based upon these new measurements. |
| 644 | * MDP can update with this new value. |
| 645 | */ |
| 646 | mddi_sharp_rows_per_second = |
| 647 | (mddi_sharp_rows_per_refresh * 1000 * |
| 648 | num_vsyncs) / (elapsed_us / 1000); |
| 649 | } |
| 650 | /* start_time = timetick_get(); */ |
| 651 | first_time = FALSE; |
| 652 | jiffies_to_timeval(jiffies, &start_time); |
| 653 | if (mddi_sharp_report_refresh_measurements) { |
| 654 | /* mdp_cnt_val = MDP_LINE_COUNT; */ |
| 655 | } |
| 656 | } |
| 657 | /* if detected = TRUE, client initiated wakeup was detected */ |
| 658 | if (mddi_sharp_vsync_handler != NULL) { |
| 659 | (*mddi_sharp_vsync_handler) |
| 660 | (mddi_sharp_vsync_handler_arg); |
| 661 | mddi_sharp_vsync_handler = NULL; |
| 662 | } |
| 663 | mddi_vsync_detect_enabled = FALSE; |
| 664 | mddi_sharp_vsync_attempts = 0; |
| 665 | /* need to clear this vsync wakeup */ |
| 666 | if (!mddi_queue_register_write_int(REG_INTR, 0x0000)) { |
| 667 | MDDI_MSG_ERR("Vsync interrupt clear failed!\n"); |
| 668 | } |
| 669 | if (!detected) { |
| 670 | /* give up after 5 failed attempts but show error */ |
| 671 | MDDI_MSG_NOTICE("Vsync detection failed!\n"); |
| 672 | } else if ((mddi_sharp_monitor_refresh_value) && |
| 673 | (mddi_sharp_report_refresh_measurements)) { |
| 674 | MDDI_MSG_NOTICE(" Lines Per Second=%d!\n", |
| 675 | mddi_sharp_rows_per_second); |
| 676 | } |
| 677 | } else |
| 678 | /* if detected = FALSE, we woke up from hibernation, but did not |
| 679 | * detect client initiated wakeup. |
| 680 | */ |
| 681 | mddi_sharp_vsync_attempts++; |
| 682 | } |
| 683 | |
| 684 | /* ISR to be executed */ |
| 685 | void mddi_sharp_vsync_set_handler(msm_fb_vsync_handler_type handler, void *arg) |
| 686 | { |
| 687 | boolean error = FALSE; |
| 688 | unsigned long flags; |
| 689 | |
| 690 | /* Disable interrupts */ |
| 691 | spin_lock_irqsave(&mddi_host_spin_lock, flags); |
| 692 | /* INTLOCK(); */ |
| 693 | |
| 694 | if (mddi_sharp_vsync_handler != NULL) |
| 695 | error = TRUE; |
| 696 | |
| 697 | /* Register the handler for this particular GROUP interrupt source */ |
| 698 | mddi_sharp_vsync_handler = handler; |
| 699 | mddi_sharp_vsync_handler_arg = arg; |
| 700 | |
| 701 | /* Restore interrupts */ |
| 702 | spin_unlock_irqrestore(&mddi_host_spin_lock, flags); |
| 703 | /* INTFREE(); */ |
| 704 | |
| 705 | if (error) |
| 706 | MDDI_MSG_ERR("MDDI: Previous Vsync handler never called\n"); |
| 707 | |
| 708 | /* Enable the vsync wakeup */ |
| 709 | mddi_queue_register_write(REG_INTR, 0x8100, FALSE, 0); |
| 710 | |
| 711 | mddi_sharp_vsync_attempts = 1; |
| 712 | mddi_vsync_detect_enabled = TRUE; |
| 713 | } /* mddi_sharp_vsync_set_handler */ |
| 714 | |
| 715 | static int mddi_sharp_lcd_on(struct platform_device *pdev) |
| 716 | { |
| 717 | struct msm_fb_data_type *mfd; |
| 718 | |
| 719 | mfd = platform_get_drvdata(pdev); |
| 720 | |
| 721 | if (!mfd) |
| 722 | return -ENODEV; |
| 723 | |
| 724 | if (mfd->key != MFD_KEY) |
| 725 | return -EINVAL; |
| 726 | |
| 727 | mddi_host_client_cnt_reset(); |
| 728 | |
| 729 | if (mfd->panel.id == SHARP_QVGA_PRIM) |
| 730 | mddi_sharp_prim_lcd_init(); |
| 731 | else |
| 732 | mddi_sharp_sub_lcd_init(); |
| 733 | |
| 734 | return 0; |
| 735 | } |
| 736 | |
| 737 | static int mddi_sharp_lcd_off(struct platform_device *pdev) |
| 738 | { |
| 739 | if (mddi_sharp_vsync_handler != NULL) { |
| 740 | (*mddi_sharp_vsync_handler) |
| 741 | (mddi_sharp_vsync_handler_arg); |
| 742 | mddi_sharp_vsync_handler = NULL; |
| 743 | printk(KERN_INFO "%s: clean up vsyn_handler=%x\n", __func__, |
| 744 | (int)mddi_sharp_vsync_handler); |
| 745 | } |
| 746 | |
| 747 | mddi_sharp_lcd_powerdown(); |
| 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | static int __devinit mddi_sharp_probe(struct platform_device *pdev) |
| 752 | { |
| 753 | if (pdev->id == 0) { |
| 754 | mddi_sharp_pdata = pdev->dev.platform_data; |
| 755 | return 0; |
| 756 | } |
| 757 | |
| 758 | msm_fb_add_device(pdev); |
| 759 | |
| 760 | return 0; |
| 761 | } |
| 762 | |
| 763 | static struct platform_driver this_driver = { |
| 764 | .probe = mddi_sharp_probe, |
| 765 | .driver = { |
| 766 | .name = "mddi_sharp_qvga", |
| 767 | }, |
| 768 | }; |
| 769 | |
| 770 | static struct msm_fb_panel_data mddi_sharp_panel_data0 = { |
| 771 | .on = mddi_sharp_lcd_on, |
| 772 | .off = mddi_sharp_lcd_off, |
| 773 | .set_backlight = mddi_sharp_lcd_set_backlight, |
| 774 | .set_vsync_notifier = mddi_sharp_vsync_set_handler, |
| 775 | }; |
| 776 | |
| 777 | static struct platform_device this_device_0 = { |
| 778 | .name = "mddi_sharp_qvga", |
| 779 | .id = SHARP_QVGA_PRIM, |
| 780 | .dev = { |
| 781 | .platform_data = &mddi_sharp_panel_data0, |
| 782 | } |
| 783 | }; |
| 784 | |
| 785 | static struct msm_fb_panel_data mddi_sharp_panel_data1 = { |
| 786 | .on = mddi_sharp_lcd_on, |
| 787 | .off = mddi_sharp_lcd_off, |
| 788 | }; |
| 789 | |
| 790 | static struct platform_device this_device_1 = { |
| 791 | .name = "mddi_sharp_qvga", |
| 792 | .id = SHARP_128X128_SECD, |
| 793 | .dev = { |
| 794 | .platform_data = &mddi_sharp_panel_data1, |
| 795 | } |
| 796 | }; |
| 797 | |
| 798 | static int __init mddi_sharp_init(void) |
| 799 | { |
| 800 | int ret; |
| 801 | struct msm_panel_info *pinfo; |
| 802 | |
| 803 | #ifdef CONFIG_FB_MSM_MDDI_AUTO_DETECT |
| 804 | u32 id; |
| 805 | |
| 806 | ret = msm_fb_detect_client("mddi_sharp_qvga"); |
| 807 | if (ret == -ENODEV) |
| 808 | return 0; |
| 809 | |
| 810 | if (ret) { |
| 811 | id = mddi_get_client_id(); |
| 812 | |
| 813 | if (((id >> 16) != 0x0) || ((id & 0xffff) != 0x8835)) |
| 814 | return 0; |
| 815 | } |
| 816 | #endif |
| 817 | if (mddi_host_core_version > 8) { |
| 818 | /* can use faster refresh with newer hw revisions */ |
| 819 | mddi_sharp_debug_60hz_refresh = TRUE; |
| 820 | |
| 821 | /* Timing variables for tracking vsync */ |
| 822 | /* dot_clock = 6.00MHz |
| 823 | * horizontal count = 296 |
| 824 | * vertical count = 338 |
| 825 | * refresh rate = 6000000/(296+338) = 60Hz |
| 826 | */ |
| 827 | mddi_sharp_rows_per_second = 20270; /* 6000000/296 */ |
| 828 | mddi_sharp_rows_per_refresh = 338; |
| 829 | mddi_sharp_usecs_per_refresh = 16674; /* (296+338)/6000000 */ |
| 830 | } else { |
| 831 | /* Timing variables for tracking vsync */ |
| 832 | /* dot_clock = 5.20MHz |
| 833 | * horizontal count = 376 |
| 834 | * vertical count = 338 |
| 835 | * refresh rate = 5200000/(376+338) = 41Hz |
| 836 | */ |
| 837 | mddi_sharp_rows_per_second = 13830; /* 5200000/376 */ |
| 838 | mddi_sharp_rows_per_refresh = 338; |
| 839 | mddi_sharp_usecs_per_refresh = 24440; /* (376+338)/5200000 */ |
| 840 | } |
| 841 | |
| 842 | ret = platform_driver_register(&this_driver); |
| 843 | if (!ret) { |
| 844 | pinfo = &mddi_sharp_panel_data0.panel_info; |
| 845 | pinfo->xres = 240; |
| 846 | pinfo->yres = 320; |
| 847 | MSM_FB_SINGLE_MODE_PANEL(pinfo); |
| 848 | pinfo->type = MDDI_PANEL; |
| 849 | pinfo->pdest = DISPLAY_1; |
| 850 | pinfo->mddi.vdopkt = MDDI_DEFAULT_PRIM_PIX_ATTR; |
| 851 | pinfo->wait_cycle = 0; |
| 852 | pinfo->bpp = 18; |
| 853 | pinfo->fb_num = 2; |
| 854 | pinfo->clk_rate = 122880000; |
| 855 | pinfo->clk_min = 120000000; |
| 856 | pinfo->clk_max = 125000000; |
| 857 | pinfo->lcd.vsync_enable = TRUE; |
Jeevan Shriram | 033ee13 | 2012-02-28 12:24:39 +0530 | [diff] [blame] | 858 | pinfo->mddi.is_type1 = TRUE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 859 | pinfo->lcd.refx100 = |
| 860 | (mddi_sharp_rows_per_second * 100) / |
| 861 | mddi_sharp_rows_per_refresh; |
| 862 | pinfo->lcd.v_back_porch = 12; |
| 863 | pinfo->lcd.v_front_porch = 6; |
| 864 | pinfo->lcd.v_pulse_width = 0; |
| 865 | pinfo->lcd.hw_vsync_mode = FALSE; |
| 866 | pinfo->lcd.vsync_notifier_period = (1 * HZ); |
| 867 | pinfo->bl_max = 7; |
| 868 | pinfo->bl_min = 1; |
| 869 | |
| 870 | ret = platform_device_register(&this_device_0); |
| 871 | if (ret) |
| 872 | platform_driver_unregister(&this_driver); |
| 873 | |
| 874 | pinfo = &mddi_sharp_panel_data1.panel_info; |
| 875 | pinfo->xres = 128; |
| 876 | pinfo->yres = 128; |
| 877 | MSM_FB_SINGLE_MODE_PANEL(pinfo); |
| 878 | pinfo->type = MDDI_PANEL; |
| 879 | pinfo->pdest = DISPLAY_2; |
| 880 | pinfo->mddi.vdopkt = 0x400; |
| 881 | pinfo->wait_cycle = 0; |
| 882 | pinfo->bpp = 18; |
| 883 | pinfo->clk_rate = 122880000; |
| 884 | pinfo->clk_min = 120000000; |
| 885 | pinfo->clk_max = 125000000; |
| 886 | pinfo->fb_num = 2; |
| 887 | |
| 888 | ret = platform_device_register(&this_device_1); |
| 889 | if (ret) { |
| 890 | platform_device_unregister(&this_device_0); |
| 891 | platform_driver_unregister(&this_driver); |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | if (!ret) |
| 896 | mddi_lcd.vsync_detected = mddi_sharp_lcd_vsync_detected; |
| 897 | |
| 898 | return ret; |
| 899 | } |
| 900 | |
| 901 | module_init(mddi_sharp_init); |