corgi_lcd.c 7.9 KB

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