corgi_lcd.c 8.0 KB

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