corgi_lcd.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. /*
  2. * linux/drivers/video/w100fb.c
  3. *
  4. * Corgi LCD Specific Code for ATI Imageon w100 (Wallaby)
  5. *
  6. * Copyright (C) 2005 Richard Purdie
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. */
  13. #include <linux/delay.h>
  14. #include <linux/kernel.h>
  15. #include <linux/device.h>
  16. #include <asm/arch/corgi.h>
  17. #include <asm/mach/sharpsl_param.h>
  18. #include <video/w100fb.h>
  19. /* Register Addresses */
  20. #define RESCTL_ADRS 0x00
  21. #define PHACTRL_ADRS 0x01
  22. #define DUTYCTRL_ADRS 0x02
  23. #define POWERREG0_ADRS 0x03
  24. #define POWERREG1_ADRS 0x04
  25. #define GPOR3_ADRS 0x05
  26. #define PICTRL_ADRS 0x06
  27. #define POLCTRL_ADRS 0x07
  28. /* Resgister Bit Definitions */
  29. #define RESCTL_QVGA 0x01
  30. #define RESCTL_VGA 0x00
  31. #define POWER1_VW_ON 0x01 /* VW Supply FET ON */
  32. #define POWER1_GVSS_ON 0x02 /* GVSS(-8V) Power Supply ON */
  33. #define POWER1_VDD_ON 0x04 /* VDD(8V),SVSS(-4V) Power Supply ON */
  34. #define POWER1_VW_OFF 0x00 /* VW Supply FET OFF */
  35. #define POWER1_GVSS_OFF 0x00 /* GVSS(-8V) Power Supply OFF */
  36. #define POWER1_VDD_OFF 0x00 /* VDD(8V),SVSS(-4V) Power Supply OFF */
  37. #define POWER0_COM_DCLK 0x01 /* COM Voltage DC Bias DAC Serial Data Clock */
  38. #define POWER0_COM_DOUT 0x02 /* COM Voltage DC Bias DAC Serial Data Out */
  39. #define POWER0_DAC_ON 0x04 /* DAC Power Supply ON */
  40. #define POWER0_COM_ON 0x08 /* COM Powewr Supply ON */
  41. #define POWER0_VCC5_ON 0x10 /* VCC5 Power Supply ON */
  42. #define POWER0_DAC_OFF 0x00 /* DAC Power Supply OFF */
  43. #define POWER0_COM_OFF 0x00 /* COM Powewr Supply OFF */
  44. #define POWER0_VCC5_OFF 0x00 /* VCC5 Power Supply OFF */
  45. #define PICTRL_INIT_STATE 0x01
  46. #define PICTRL_INIOFF 0x02
  47. #define PICTRL_POWER_DOWN 0x04
  48. #define PICTRL_COM_SIGNAL_OFF 0x08
  49. #define PICTRL_DAC_SIGNAL_OFF 0x10
  50. #define POLCTRL_SYNC_POL_FALL 0x01
  51. #define POLCTRL_EN_POL_FALL 0x02
  52. #define POLCTRL_DATA_POL_FALL 0x04
  53. #define POLCTRL_SYNC_ACT_H 0x08
  54. #define POLCTRL_EN_ACT_L 0x10
  55. #define POLCTRL_SYNC_POL_RISE 0x00
  56. #define POLCTRL_EN_POL_RISE 0x00
  57. #define POLCTRL_DATA_POL_RISE 0x00
  58. #define POLCTRL_SYNC_ACT_L 0x00
  59. #define POLCTRL_EN_ACT_H 0x00
  60. #define PHACTRL_PHASE_MANUAL 0x01
  61. #define DEFAULT_PHAD_QVGA (9)
  62. #define DEFAULT_COMADJ (125)
  63. /*
  64. * This is only a psuedo I2C interface. We can't use the standard kernel
  65. * routines as the interface is write only. We just assume the data is acked...
  66. */
  67. static void lcdtg_ssp_i2c_send(u8 data)
  68. {
  69. corgi_ssp_lcdtg_send(POWERREG0_ADRS, data);
  70. udelay(10);
  71. }
  72. static void lcdtg_i2c_send_bit(u8 data)
  73. {
  74. lcdtg_ssp_i2c_send(data);
  75. lcdtg_ssp_i2c_send(data | POWER0_COM_DCLK);
  76. lcdtg_ssp_i2c_send(data);
  77. }
  78. static void lcdtg_i2c_send_start(u8 base)
  79. {
  80. lcdtg_ssp_i2c_send(base | POWER0_COM_DCLK | POWER0_COM_DOUT);
  81. lcdtg_ssp_i2c_send(base | POWER0_COM_DCLK);
  82. lcdtg_ssp_i2c_send(base);
  83. }
  84. static void lcdtg_i2c_send_stop(u8 base)
  85. {
  86. lcdtg_ssp_i2c_send(base);
  87. lcdtg_ssp_i2c_send(base | POWER0_COM_DCLK);
  88. lcdtg_ssp_i2c_send(base | POWER0_COM_DCLK | POWER0_COM_DOUT);
  89. }
  90. static void lcdtg_i2c_send_byte(u8 base, u8 data)
  91. {
  92. int i;
  93. for (i = 0; i < 8; i++) {
  94. if (data & 0x80)
  95. lcdtg_i2c_send_bit(base | POWER0_COM_DOUT);
  96. else
  97. lcdtg_i2c_send_bit(base);
  98. data <<= 1;
  99. }
  100. }
  101. static void lcdtg_i2c_wait_ack(u8 base)
  102. {
  103. lcdtg_i2c_send_bit(base);
  104. }
  105. static void lcdtg_set_common_voltage(u8 base_data, u8 data)
  106. {
  107. /* Set Common Voltage to M62332FP via I2C */
  108. lcdtg_i2c_send_start(base_data);
  109. lcdtg_i2c_send_byte(base_data, 0x9c);
  110. lcdtg_i2c_wait_ack(base_data);
  111. lcdtg_i2c_send_byte(base_data, 0x00);
  112. lcdtg_i2c_wait_ack(base_data);
  113. lcdtg_i2c_send_byte(base_data, data);
  114. lcdtg_i2c_wait_ack(base_data);
  115. lcdtg_i2c_send_stop(base_data);
  116. }
  117. /* Set Phase Adjuct */
  118. static void lcdtg_set_phadadj(struct w100fb_par *par)
  119. {
  120. int adj;
  121. switch(par->xres) {
  122. case 480:
  123. case 640:
  124. /* Setting for VGA */
  125. adj = sharpsl_param.phadadj;
  126. if (adj < 0) {
  127. adj = PHACTRL_PHASE_MANUAL;
  128. } else {
  129. adj = ((adj & 0x0f) << 1) | PHACTRL_PHASE_MANUAL;
  130. }
  131. break;
  132. case 240:
  133. case 320:
  134. default:
  135. /* Setting for QVGA */
  136. adj = (DEFAULT_PHAD_QVGA << 1) | PHACTRL_PHASE_MANUAL;
  137. break;
  138. }
  139. corgi_ssp_lcdtg_send(PHACTRL_ADRS, adj);
  140. }
  141. static int lcd_inited;
  142. static void lcdtg_hw_init(struct w100fb_par *par)
  143. {
  144. if (!lcd_inited) {
  145. int comadj;
  146. /* Initialize Internal Logic & Port */
  147. corgi_ssp_lcdtg_send(PICTRL_ADRS, PICTRL_POWER_DOWN | PICTRL_INIOFF | PICTRL_INIT_STATE
  148. | PICTRL_COM_SIGNAL_OFF | PICTRL_DAC_SIGNAL_OFF);
  149. corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_OFF
  150. | POWER0_COM_OFF | POWER0_VCC5_OFF);
  151. corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_OFF);
  152. /* VDD(+8V), SVSS(-4V) ON */
  153. corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_ON);
  154. mdelay(3);
  155. /* DAC ON */
  156. corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_ON
  157. | POWER0_COM_OFF | POWER0_VCC5_OFF);
  158. /* INIB = H, INI = L */
  159. /* PICTL[0] = H , PICTL[1] = PICTL[2] = PICTL[4] = L */
  160. corgi_ssp_lcdtg_send(PICTRL_ADRS, PICTRL_INIT_STATE | PICTRL_COM_SIGNAL_OFF);
  161. /* Set Common Voltage */
  162. comadj = sharpsl_param.comadj;
  163. if (comadj < 0)
  164. comadj = DEFAULT_COMADJ;
  165. lcdtg_set_common_voltage((POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_OFF), comadj);
  166. /* VCC5 ON, DAC ON */
  167. corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_ON |
  168. POWER0_COM_OFF | POWER0_VCC5_ON);
  169. /* GVSS(-8V) ON, VDD ON */
  170. corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_ON | POWER1_VDD_ON);
  171. mdelay(2);
  172. /* COM SIGNAL ON (PICTL[3] = L) */
  173. corgi_ssp_lcdtg_send(PICTRL_ADRS, PICTRL_INIT_STATE);
  174. /* COM ON, DAC ON, VCC5_ON */
  175. corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_ON
  176. | POWER0_COM_ON | POWER0_VCC5_ON);
  177. /* VW ON, GVSS ON, VDD ON */
  178. corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_ON | POWER1_GVSS_ON | POWER1_VDD_ON);
  179. /* Signals output enable */
  180. corgi_ssp_lcdtg_send(PICTRL_ADRS, 0);
  181. /* Set Phase Adjuct */
  182. lcdtg_set_phadadj(par);
  183. /* Initialize for Input Signals from ATI */
  184. corgi_ssp_lcdtg_send(POLCTRL_ADRS, POLCTRL_SYNC_POL_RISE | POLCTRL_EN_POL_RISE
  185. | POLCTRL_DATA_POL_RISE | POLCTRL_SYNC_ACT_L | POLCTRL_EN_ACT_H);
  186. udelay(1000);
  187. lcd_inited=1;
  188. } else {
  189. lcdtg_set_phadadj(par);
  190. }
  191. switch(par->xres) {
  192. case 480:
  193. case 640:
  194. /* Set Lcd Resolution (VGA) */
  195. corgi_ssp_lcdtg_send(RESCTL_ADRS, RESCTL_VGA);
  196. break;
  197. case 240:
  198. case 320:
  199. default:
  200. /* Set Lcd Resolution (QVGA) */
  201. corgi_ssp_lcdtg_send(RESCTL_ADRS, RESCTL_QVGA);
  202. break;
  203. }
  204. }
  205. static void lcdtg_suspend(struct w100fb_par *par)
  206. {
  207. /* 60Hz x 2 frame = 16.7msec x 2 = 33.4 msec */
  208. mdelay(34);
  209. /* (1)VW OFF */
  210. corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_ON | POWER1_VDD_ON);
  211. /* (2)COM OFF */
  212. corgi_ssp_lcdtg_send(PICTRL_ADRS, PICTRL_COM_SIGNAL_OFF);
  213. corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_ON);
  214. /* (3)Set Common Voltage Bias 0V */
  215. lcdtg_set_common_voltage(POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_ON, 0);
  216. /* (4)GVSS OFF */
  217. corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_ON);
  218. /* (5)VCC5 OFF */
  219. corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_OFF);
  220. /* (6)Set PDWN, INIOFF, DACOFF */
  221. corgi_ssp_lcdtg_send(PICTRL_ADRS, PICTRL_INIOFF | PICTRL_DAC_SIGNAL_OFF |
  222. PICTRL_POWER_DOWN | PICTRL_COM_SIGNAL_OFF);
  223. /* (7)DAC OFF */
  224. corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_DAC_OFF | POWER0_COM_OFF | POWER0_VCC5_OFF);
  225. /* (8)VDD OFF */
  226. corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_OFF);
  227. lcd_inited = 0;
  228. }
  229. static struct w100_tg_info corgi_lcdtg_info = {
  230. .change=lcdtg_hw_init,
  231. .suspend=lcdtg_suspend,
  232. .resume=lcdtg_hw_init,
  233. };
  234. /*
  235. * Corgi w100 Frame Buffer Device
  236. */
  237. static struct w100_mem_info corgi_fb_mem = {
  238. .ext_cntl = 0x00040003,
  239. .sdram_mode_reg = 0x00650021,
  240. .ext_timing_cntl = 0x10002a4a,
  241. .io_cntl = 0x7ff87012,
  242. .size = 0x1fffff,
  243. };
  244. static struct w100_gen_regs corgi_fb_regs = {
  245. .lcd_format = 0x00000003,
  246. .lcdd_cntl1 = 0x01CC0000,
  247. .lcdd_cntl2 = 0x0003FFFF,
  248. .genlcd_cntl1 = 0x00FFFF0D,
  249. .genlcd_cntl2 = 0x003F3003,
  250. .genlcd_cntl3 = 0x000102aa,
  251. };
  252. static struct w100_gpio_regs corgi_fb_gpio = {
  253. .init_data1 = 0x000000bf,
  254. .init_data2 = 0x00000000,
  255. .gpio_dir1 = 0x00000000,
  256. .gpio_oe1 = 0x03c0feff,
  257. .gpio_dir2 = 0x00000000,
  258. .gpio_oe2 = 0x00000000,
  259. };
  260. static struct w100_mode corgi_fb_modes[] = {
  261. {
  262. .xres = 480,
  263. .yres = 640,
  264. .left_margin = 0x56,
  265. .right_margin = 0x55,
  266. .upper_margin = 0x03,
  267. .lower_margin = 0x00,
  268. .crtc_ss = 0x82360056,
  269. .crtc_ls = 0xA0280000,
  270. .crtc_gs = 0x80280028,
  271. .crtc_vpos_gs = 0x02830002,
  272. .crtc_rev = 0x00400008,
  273. .crtc_dclk = 0xA0000000,
  274. .crtc_gclk = 0x8015010F,
  275. .crtc_goe = 0x80100110,
  276. .crtc_ps1_active = 0x41060010,
  277. .pll_freq = 75,
  278. .fast_pll_freq = 100,
  279. .sysclk_src = CLK_SRC_PLL,
  280. .sysclk_divider = 0,
  281. .pixclk_src = CLK_SRC_PLL,
  282. .pixclk_divider = 2,
  283. .pixclk_divider_rotated = 6,
  284. },{
  285. .xres = 240,
  286. .yres = 320,
  287. .left_margin = 0x27,
  288. .right_margin = 0x2e,
  289. .upper_margin = 0x01,
  290. .lower_margin = 0x00,
  291. .crtc_ss = 0x81170027,
  292. .crtc_ls = 0xA0140000,
  293. .crtc_gs = 0xC0140014,
  294. .crtc_vpos_gs = 0x00010141,
  295. .crtc_rev = 0x00400008,
  296. .crtc_dclk = 0xA0000000,
  297. .crtc_gclk = 0x8015010F,
  298. .crtc_goe = 0x80100110,
  299. .crtc_ps1_active = 0x41060010,
  300. .pll_freq = 0,
  301. .fast_pll_freq = 0,
  302. .sysclk_src = CLK_SRC_XTAL,
  303. .sysclk_divider = 0,
  304. .pixclk_src = CLK_SRC_XTAL,
  305. .pixclk_divider = 1,
  306. .pixclk_divider_rotated = 1,
  307. },
  308. };
  309. static struct w100fb_mach_info corgi_fb_info = {
  310. .tg = &corgi_lcdtg_info,
  311. .init_mode = INIT_MODE_ROTATED,
  312. .mem = &corgi_fb_mem,
  313. .regs = &corgi_fb_regs,
  314. .modelist = &corgi_fb_modes[0],
  315. .num_modes = 2,
  316. .gpio = &corgi_fb_gpio,
  317. .xtal_freq = 12500000,
  318. .xtal_dbl = 0,
  319. };
  320. static struct resource corgi_fb_resources[] = {
  321. [0] = {
  322. .start = 0x08000000,
  323. .end = 0x08ffffff,
  324. .flags = IORESOURCE_MEM,
  325. },
  326. };
  327. struct platform_device corgifb_device = {
  328. .name = "w100fb",
  329. .id = -1,
  330. .num_resources = ARRAY_SIZE(corgi_fb_resources),
  331. .resource = corgi_fb_resources,
  332. .dev = {
  333. .platform_data = &corgi_fb_info,
  334. .parent = &corgissp_device.dev,
  335. },
  336. };