corgi_lcd.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * linux/arch/arm/mach-pxa/corgi_lcd.c
  3. *
  4. * Corgi/Spitz LCD Specific Code
  5. *
  6. * Copyright (C) 2005 Richard Purdie
  7. *
  8. * Connectivity:
  9. * Corgi - LCD to ATI Imageon w100 (Wallaby)
  10. * Spitz - LCD to PXA Framebuffer
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. *
  16. */
  17. #include <linux/delay.h>
  18. #include <linux/kernel.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/module.h>
  21. #include <linux/string.h>
  22. #include <mach/corgi.h>
  23. #include <mach/hardware.h>
  24. #include <mach/sharpsl.h>
  25. #include <mach/spitz.h>
  26. #include <asm/hardware/scoop.h>
  27. #include <asm/mach/sharpsl_param.h>
  28. #include "generic.h"
  29. /* Register Addresses */
  30. #define RESCTL_ADRS 0x00
  31. #define PHACTRL_ADRS 0x01
  32. #define DUTYCTRL_ADRS 0x02
  33. #define POWERREG0_ADRS 0x03
  34. #define POWERREG1_ADRS 0x04
  35. #define GPOR3_ADRS 0x05
  36. #define PICTRL_ADRS 0x06
  37. #define POLCTRL_ADRS 0x07
  38. /* Register Bit Definitions */
  39. #define RESCTL_QVGA 0x01
  40. #define RESCTL_VGA 0x00
  41. #define POWER1_VW_ON 0x01 /* VW Supply FET ON */
  42. #define POWER1_GVSS_ON 0x02 /* GVSS(-8V) Power Supply ON */
  43. #define POWER1_VDD_ON 0x04 /* VDD(8V),SVSS(-4V) Power Supply ON */
  44. #define POWER1_VW_OFF 0x00 /* VW Supply FET OFF */
  45. #define POWER1_GVSS_OFF 0x00 /* GVSS(-8V) Power Supply OFF */
  46. #define POWER1_VDD_OFF 0x00 /* VDD(8V),SVSS(-4V) Power Supply OFF */
  47. #define POWER0_COM_DCLK 0x01 /* COM Voltage DC Bias DAC Serial Data Clock */
  48. #define POWER0_COM_DOUT 0x02 /* COM Voltage DC Bias DAC Serial Data Out */
  49. #define POWER0_DAC_ON 0x04 /* DAC Power Supply ON */
  50. #define POWER0_COM_ON 0x08 /* COM Power Supply ON */
  51. #define POWER0_VCC5_ON 0x10 /* VCC5 Power Supply ON */
  52. #define POWER0_DAC_OFF 0x00 /* DAC Power Supply OFF */
  53. #define POWER0_COM_OFF 0x00 /* COM Power Supply OFF */
  54. #define POWER0_VCC5_OFF 0x00 /* VCC5 Power Supply OFF */
  55. #define PICTRL_INIT_STATE 0x01
  56. #define PICTRL_INIOFF 0x02
  57. #define PICTRL_POWER_DOWN 0x04
  58. #define PICTRL_COM_SIGNAL_OFF 0x08
  59. #define PICTRL_DAC_SIGNAL_OFF 0x10
  60. #define POLCTRL_SYNC_POL_FALL 0x01
  61. #define POLCTRL_EN_POL_FALL 0x02
  62. #define POLCTRL_DATA_POL_FALL 0x04
  63. #define POLCTRL_SYNC_ACT_H 0x08
  64. #define POLCTRL_EN_ACT_L 0x10
  65. #define POLCTRL_SYNC_POL_RISE 0x00
  66. #define POLCTRL_EN_POL_RISE 0x00
  67. #define POLCTRL_DATA_POL_RISE 0x00
  68. #define POLCTRL_SYNC_ACT_L 0x00
  69. #define POLCTRL_EN_ACT_H 0x00
  70. #define PHACTRL_PHASE_MANUAL 0x01
  71. #define DEFAULT_PHAD_QVGA (9)
  72. #define DEFAULT_COMADJ (125)
  73. /*
  74. * This is only a psuedo I2C interface. We can't use the standard kernel
  75. * routines as the interface is write only. We just assume the data is acked...
  76. */
  77. static void lcdtg_ssp_i2c_send(u8 data)
  78. {
  79. corgi_ssp_lcdtg_send(POWERREG0_ADRS, data);
  80. udelay(10);
  81. }
  82. static void lcdtg_i2c_send_bit(u8 data)
  83. {
  84. lcdtg_ssp_i2c_send(data);
  85. lcdtg_ssp_i2c_send(data | POWER0_COM_DCLK);
  86. lcdtg_ssp_i2c_send(data);
  87. }
  88. static void lcdtg_i2c_send_start(u8 base)
  89. {
  90. lcdtg_ssp_i2c_send(base | POWER0_COM_DCLK | POWER0_COM_DOUT);
  91. lcdtg_ssp_i2c_send(base | POWER0_COM_DCLK);
  92. lcdtg_ssp_i2c_send(base);
  93. }
  94. static void lcdtg_i2c_send_stop(u8 base)
  95. {
  96. lcdtg_ssp_i2c_send(base);
  97. lcdtg_ssp_i2c_send(base | POWER0_COM_DCLK);
  98. lcdtg_ssp_i2c_send(base | POWER0_COM_DCLK | POWER0_COM_DOUT);
  99. }
  100. static void lcdtg_i2c_send_byte(u8 base, u8 data)
  101. {
  102. int i;
  103. for (i = 0; i < 8; i++) {
  104. if (data & 0x80)
  105. lcdtg_i2c_send_bit(base | POWER0_COM_DOUT);
  106. else
  107. lcdtg_i2c_send_bit(base);
  108. data <<= 1;
  109. }
  110. }
  111. static void lcdtg_i2c_wait_ack(u8 base)
  112. {
  113. lcdtg_i2c_send_bit(base);
  114. }
  115. static void lcdtg_set_common_voltage(u8 base_data, u8 data)
  116. {
  117. /* Set Common Voltage to M62332FP via I2C */
  118. lcdtg_i2c_send_start(base_data);
  119. lcdtg_i2c_send_byte(base_data, 0x9c);
  120. lcdtg_i2c_wait_ack(base_data);
  121. lcdtg_i2c_send_byte(base_data, 0x00);
  122. lcdtg_i2c_wait_ack(base_data);
  123. lcdtg_i2c_send_byte(base_data, data);
  124. lcdtg_i2c_wait_ack(base_data);
  125. lcdtg_i2c_send_stop(base_data);
  126. }
  127. /* Set Phase Adjust */
  128. static void lcdtg_set_phadadj(int mode)
  129. {
  130. int adj;
  131. switch(mode) {
  132. case 480:
  133. case 640:
  134. /* Setting for VGA */
  135. adj = sharpsl_param.phadadj;
  136. if (adj < 0) {
  137. adj = PHACTRL_PHASE_MANUAL;
  138. } else {
  139. adj = ((adj & 0x0f) << 1) | PHACTRL_PHASE_MANUAL;
  140. }
  141. break;
  142. case 240:
  143. case 320:
  144. default:
  145. /* Setting for QVGA */
  146. adj = (DEFAULT_PHAD_QVGA << 1) | PHACTRL_PHASE_MANUAL;
  147. break;
  148. }
  149. corgi_ssp_lcdtg_send(PHACTRL_ADRS, adj);
  150. }
  151. static int lcd_inited;
  152. void corgi_lcdtg_hw_init(int mode)
  153. {
  154. if (!lcd_inited) {
  155. int comadj;
  156. /* Initialize Internal Logic & Port */
  157. corgi_ssp_lcdtg_send(PICTRL_ADRS, PICTRL_POWER_DOWN | PICTRL_INIOFF | PICTRL_INIT_STATE
  158. | PICTRL_COM_SIGNAL_OFF | PICTRL_DAC_SIGNAL_OFF);
  159. corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_OFF
  160. | POWER0_COM_OFF | POWER0_VCC5_OFF);
  161. corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_OFF);
  162. /* VDD(+8V), SVSS(-4V) ON */
  163. corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_ON);
  164. mdelay(3);
  165. /* DAC ON */
  166. corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_ON
  167. | POWER0_COM_OFF | POWER0_VCC5_OFF);
  168. /* INIB = H, INI = L */
  169. /* PICTL[0] = H , PICTL[1] = PICTL[2] = PICTL[4] = L */
  170. corgi_ssp_lcdtg_send(PICTRL_ADRS, PICTRL_INIT_STATE | PICTRL_COM_SIGNAL_OFF);
  171. /* Set Common Voltage */
  172. comadj = sharpsl_param.comadj;
  173. if (comadj < 0)
  174. comadj = DEFAULT_COMADJ;
  175. lcdtg_set_common_voltage((POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_OFF), comadj);
  176. /* VCC5 ON, DAC ON */
  177. corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_ON |
  178. POWER0_COM_OFF | POWER0_VCC5_ON);
  179. /* GVSS(-8V) ON, VDD ON */
  180. corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_ON | POWER1_VDD_ON);
  181. mdelay(2);
  182. /* COM SIGNAL ON (PICTL[3] = L) */
  183. corgi_ssp_lcdtg_send(PICTRL_ADRS, PICTRL_INIT_STATE);
  184. /* COM ON, DAC ON, VCC5_ON */
  185. corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_ON
  186. | POWER0_COM_ON | POWER0_VCC5_ON);
  187. /* VW ON, GVSS ON, VDD ON */
  188. corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_ON | POWER1_GVSS_ON | POWER1_VDD_ON);
  189. /* Signals output enable */
  190. corgi_ssp_lcdtg_send(PICTRL_ADRS, 0);
  191. /* Set Phase Adjust */
  192. lcdtg_set_phadadj(mode);
  193. /* Initialize for Input Signals from ATI */
  194. corgi_ssp_lcdtg_send(POLCTRL_ADRS, POLCTRL_SYNC_POL_RISE | POLCTRL_EN_POL_RISE
  195. | POLCTRL_DATA_POL_RISE | POLCTRL_SYNC_ACT_L | POLCTRL_EN_ACT_H);
  196. udelay(1000);
  197. lcd_inited=1;
  198. } else {
  199. lcdtg_set_phadadj(mode);
  200. }
  201. switch(mode) {
  202. case 480:
  203. case 640:
  204. /* Set Lcd Resolution (VGA) */
  205. corgi_ssp_lcdtg_send(RESCTL_ADRS, RESCTL_VGA);
  206. break;
  207. case 240:
  208. case 320:
  209. default:
  210. /* Set Lcd Resolution (QVGA) */
  211. corgi_ssp_lcdtg_send(RESCTL_ADRS, RESCTL_QVGA);
  212. break;
  213. }
  214. }
  215. void corgi_lcdtg_suspend(void)
  216. {
  217. /* 60Hz x 2 frame = 16.7msec x 2 = 33.4 msec */
  218. mdelay(34);
  219. /* (1)VW OFF */
  220. corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_ON | POWER1_VDD_ON);
  221. /* (2)COM OFF */
  222. corgi_ssp_lcdtg_send(PICTRL_ADRS, PICTRL_COM_SIGNAL_OFF);
  223. corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_ON);
  224. /* (3)Set Common Voltage Bias 0V */
  225. lcdtg_set_common_voltage(POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_ON, 0);
  226. /* (4)GVSS OFF */
  227. corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_ON);
  228. /* (5)VCC5 OFF */
  229. corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_OFF);
  230. /* (6)Set PDWN, INIOFF, DACOFF */
  231. corgi_ssp_lcdtg_send(PICTRL_ADRS, PICTRL_INIOFF | PICTRL_DAC_SIGNAL_OFF |
  232. PICTRL_POWER_DOWN | PICTRL_COM_SIGNAL_OFF);
  233. /* (7)DAC OFF */
  234. corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_DAC_OFF | POWER0_COM_OFF | POWER0_VCC5_OFF);
  235. /* (8)VDD OFF */
  236. corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_OFF);
  237. lcd_inited = 0;
  238. }