lcd_wqvga.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. * KFR2R09 LCD panel support
  3. *
  4. * Copyright (C) 2009 Magnus Damm
  5. *
  6. * Register settings based on the out-of-tree t33fb.c driver
  7. * Copyright (C) 2008 Lineo Solutions, Inc.
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file COPYING in the main directory of this archive for
  11. * more details.
  12. */
  13. #include <linux/delay.h>
  14. #include <linux/err.h>
  15. #include <linux/fb.h>
  16. #include <linux/init.h>
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/gpio.h>
  20. #include <video/sh_mobile_lcdc.h>
  21. #include <mach/kfr2r09.h>
  22. #include <cpu/sh7724.h>
  23. /* The on-board LCD module is a Hitachi TX07D34VM0AAA. This module is made
  24. * up of a 240x400 LCD hooked up to a R61517 driver IC. The driver IC is
  25. * communicating with the main port of the LCDC using an 18-bit SYS interface.
  26. *
  27. * The device code for this LCD module is 0x01221517.
  28. */
  29. static const unsigned char data_frame_if[] = {
  30. 0x02, /* WEMODE: 1=cont, 0=one-shot */
  31. 0x00, 0x00,
  32. 0x00, /* EPF, DFM */
  33. 0x02, /* RIM[1] : 1 (18bpp) */
  34. };
  35. static const unsigned char data_panel[] = {
  36. 0x0b,
  37. 0x63, /* 400 lines */
  38. 0x04, 0x00, 0x00, 0x04, 0x11, 0x00, 0x00,
  39. };
  40. static const unsigned char data_timing[] = {
  41. 0x00, 0x00, 0x13, 0x08, 0x08,
  42. };
  43. static const unsigned char data_timing_src[] = {
  44. 0x11, 0x01, 0x00, 0x01,
  45. };
  46. static const unsigned char data_gamma[] = {
  47. 0x01, 0x02, 0x08, 0x23, 0x03, 0x0c, 0x00, 0x06, 0x00, 0x00,
  48. 0x01, 0x00, 0x0c, 0x23, 0x03, 0x08, 0x02, 0x06, 0x00, 0x00,
  49. };
  50. static const unsigned char data_power[] = {
  51. 0x07, 0xc5, 0xdc, 0x02, 0x33, 0x0a,
  52. };
  53. static unsigned long read_reg(void *sohandle,
  54. struct sh_mobile_lcdc_sys_bus_ops *so)
  55. {
  56. return so->read_data(sohandle);
  57. }
  58. static void write_reg(void *sohandle,
  59. struct sh_mobile_lcdc_sys_bus_ops *so,
  60. int i, unsigned long v)
  61. {
  62. if (i)
  63. so->write_data(sohandle, v); /* PTH4/LCDRS High [param, 17:0] */
  64. else
  65. so->write_index(sohandle, v); /* PTH4/LCDRS Low [cmd, 7:0] */
  66. }
  67. static void write_data(void *sohandle,
  68. struct sh_mobile_lcdc_sys_bus_ops *so,
  69. unsigned char const *data, int no_data)
  70. {
  71. int i;
  72. for (i = 0; i < no_data; i++)
  73. write_reg(sohandle, so, 1, data[i]);
  74. }
  75. static unsigned long read_device_code(void *sohandle,
  76. struct sh_mobile_lcdc_sys_bus_ops *so)
  77. {
  78. unsigned long device_code;
  79. /* access protect OFF */
  80. write_reg(sohandle, so, 0, 0xb0);
  81. write_reg(sohandle, so, 1, 0x00);
  82. /* deep standby OFF */
  83. write_reg(sohandle, so, 0, 0xb1);
  84. write_reg(sohandle, so, 1, 0x00);
  85. /* device code command */
  86. write_reg(sohandle, so, 0, 0xbf);
  87. mdelay(50);
  88. /* dummy read */
  89. read_reg(sohandle, so);
  90. /* read device code */
  91. device_code = ((read_reg(sohandle, so) & 0xff) << 24);
  92. device_code |= ((read_reg(sohandle, so) & 0xff) << 16);
  93. device_code |= ((read_reg(sohandle, so) & 0xff) << 8);
  94. device_code |= (read_reg(sohandle, so) & 0xff);
  95. return device_code;
  96. }
  97. static void write_memory_start(void *sohandle,
  98. struct sh_mobile_lcdc_sys_bus_ops *so)
  99. {
  100. write_reg(sohandle, so, 0, 0x2c);
  101. }
  102. static void clear_memory(void *sohandle,
  103. struct sh_mobile_lcdc_sys_bus_ops *so)
  104. {
  105. int i;
  106. /* write start */
  107. write_memory_start(sohandle, so);
  108. /* paint it black */
  109. for (i = 0; i < (240 * 400); i++)
  110. write_reg(sohandle, so, 1, 0x00);
  111. }
  112. static void display_on(void *sohandle,
  113. struct sh_mobile_lcdc_sys_bus_ops *so)
  114. {
  115. /* access protect off */
  116. write_reg(sohandle, so, 0, 0xb0);
  117. write_reg(sohandle, so, 1, 0x00);
  118. /* exit deep standby mode */
  119. write_reg(sohandle, so, 0, 0xb1);
  120. write_reg(sohandle, so, 1, 0x00);
  121. /* frame memory I/F */
  122. write_reg(sohandle, so, 0, 0xb3);
  123. write_data(sohandle, so, data_frame_if, ARRAY_SIZE(data_frame_if));
  124. /* display mode and frame memory write mode */
  125. write_reg(sohandle, so, 0, 0xb4);
  126. write_reg(sohandle, so, 1, 0x00); /* DBI, internal clock */
  127. /* panel */
  128. write_reg(sohandle, so, 0, 0xc0);
  129. write_data(sohandle, so, data_panel, ARRAY_SIZE(data_panel));
  130. /* timing (normal) */
  131. write_reg(sohandle, so, 0, 0xc1);
  132. write_data(sohandle, so, data_timing, ARRAY_SIZE(data_timing));
  133. /* timing (partial) */
  134. write_reg(sohandle, so, 0, 0xc2);
  135. write_data(sohandle, so, data_timing, ARRAY_SIZE(data_timing));
  136. /* timing (idle) */
  137. write_reg(sohandle, so, 0, 0xc3);
  138. write_data(sohandle, so, data_timing, ARRAY_SIZE(data_timing));
  139. /* timing (source/VCOM/gate driving) */
  140. write_reg(sohandle, so, 0, 0xc4);
  141. write_data(sohandle, so, data_timing_src, ARRAY_SIZE(data_timing_src));
  142. /* gamma (red) */
  143. write_reg(sohandle, so, 0, 0xc8);
  144. write_data(sohandle, so, data_gamma, ARRAY_SIZE(data_gamma));
  145. /* gamma (green) */
  146. write_reg(sohandle, so, 0, 0xc9);
  147. write_data(sohandle, so, data_gamma, ARRAY_SIZE(data_gamma));
  148. /* gamma (blue) */
  149. write_reg(sohandle, so, 0, 0xca);
  150. write_data(sohandle, so, data_gamma, ARRAY_SIZE(data_gamma));
  151. /* power (common) */
  152. write_reg(sohandle, so, 0, 0xd0);
  153. write_data(sohandle, so, data_power, ARRAY_SIZE(data_power));
  154. /* VCOM */
  155. write_reg(sohandle, so, 0, 0xd1);
  156. write_reg(sohandle, so, 1, 0x00);
  157. write_reg(sohandle, so, 1, 0x0f);
  158. write_reg(sohandle, so, 1, 0x02);
  159. /* power (normal) */
  160. write_reg(sohandle, so, 0, 0xd2);
  161. write_reg(sohandle, so, 1, 0x63);
  162. write_reg(sohandle, so, 1, 0x24);
  163. /* power (partial) */
  164. write_reg(sohandle, so, 0, 0xd3);
  165. write_reg(sohandle, so, 1, 0x63);
  166. write_reg(sohandle, so, 1, 0x24);
  167. /* power (idle) */
  168. write_reg(sohandle, so, 0, 0xd4);
  169. write_reg(sohandle, so, 1, 0x63);
  170. write_reg(sohandle, so, 1, 0x24);
  171. write_reg(sohandle, so, 0, 0xd8);
  172. write_reg(sohandle, so, 1, 0x77);
  173. write_reg(sohandle, so, 1, 0x77);
  174. /* TE signal */
  175. write_reg(sohandle, so, 0, 0x35);
  176. write_reg(sohandle, so, 1, 0x00);
  177. /* TE signal line */
  178. write_reg(sohandle, so, 0, 0x44);
  179. write_reg(sohandle, so, 1, 0x00);
  180. write_reg(sohandle, so, 1, 0x00);
  181. /* column address */
  182. write_reg(sohandle, so, 0, 0x2a);
  183. write_reg(sohandle, so, 1, 0x00);
  184. write_reg(sohandle, so, 1, 0x00);
  185. write_reg(sohandle, so, 1, 0x00);
  186. write_reg(sohandle, so, 1, 0xef);
  187. /* page address */
  188. write_reg(sohandle, so, 0, 0x2b);
  189. write_reg(sohandle, so, 1, 0x00);
  190. write_reg(sohandle, so, 1, 0x00);
  191. write_reg(sohandle, so, 1, 0x01);
  192. write_reg(sohandle, so, 1, 0x8f);
  193. /* exit sleep mode */
  194. write_reg(sohandle, so, 0, 0x11);
  195. mdelay(120);
  196. /* clear vram */
  197. clear_memory(sohandle, so);
  198. /* display ON */
  199. write_reg(sohandle, so, 0, 0x29);
  200. mdelay(1);
  201. write_memory_start(sohandle, so);
  202. }
  203. int kfr2r09_lcd_setup(void *sohandle, struct sh_mobile_lcdc_sys_bus_ops *so)
  204. {
  205. /* power on */
  206. gpio_set_value(GPIO_PTF4, 0); /* PROTECT/ -> L */
  207. gpio_set_value(GPIO_PTE4, 0); /* LCD_RST/ -> L */
  208. gpio_set_value(GPIO_PTF4, 1); /* PROTECT/ -> H */
  209. udelay(1100);
  210. gpio_set_value(GPIO_PTE4, 1); /* LCD_RST/ -> H */
  211. udelay(10);
  212. gpio_set_value(GPIO_PTF4, 0); /* PROTECT/ -> L */
  213. mdelay(20);
  214. if (read_device_code(sohandle, so) != 0x01221517)
  215. return -ENODEV;
  216. pr_info("KFR2R09 WQVGA LCD Module detected.\n");
  217. display_on(sohandle, so);
  218. return 0;
  219. }
  220. void kfr2r09_lcd_start(void *sohandle, struct sh_mobile_lcdc_sys_bus_ops *so)
  221. {
  222. write_memory_start(sohandle, so);
  223. }