mddi_sharp.c 25 KB

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