lcd_wqvga.c 6.8 KB

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