dvi.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. /*
  2. * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
  3. * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License as published by the Free Software Foundation;
  7. * either version 2, or (at your option) any later version.
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
  10. * the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. * A PARTICULAR PURPOSE.See the GNU General Public License
  12. * for more details.
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc.,
  16. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include <linux/via-core.h>
  19. #include <linux/via_i2c.h>
  20. #include "global.h"
  21. static void tmds_register_write(int index, u8 data);
  22. static int tmds_register_read(int index);
  23. static int tmds_register_read_bytes(int index, u8 *buff, int buff_len);
  24. static void __devinit dvi_get_panel_size_from_DDCv1(
  25. struct tmds_chip_information *tmds_chip,
  26. struct tmds_setting_information *tmds_setting);
  27. static int viafb_dvi_query_EDID(void);
  28. static int check_tmds_chip(int device_id_subaddr, int device_id)
  29. {
  30. if (tmds_register_read(device_id_subaddr) == device_id)
  31. return OK;
  32. else
  33. return FAIL;
  34. }
  35. void __devinit viafb_init_dvi_size(struct tmds_chip_information *tmds_chip,
  36. struct tmds_setting_information *tmds_setting)
  37. {
  38. DEBUG_MSG(KERN_INFO "viafb_init_dvi_size()\n");
  39. viafb_dvi_sense();
  40. if (viafb_dvi_query_EDID() == 1)
  41. dvi_get_panel_size_from_DDCv1(tmds_chip, tmds_setting);
  42. return;
  43. }
  44. int __devinit viafb_tmds_trasmitter_identify(void)
  45. {
  46. unsigned char sr2a = 0, sr1e = 0, sr3e = 0;
  47. /* Turn on ouputting pad */
  48. switch (viaparinfo->chip_info->gfx_chip_name) {
  49. case UNICHROME_K8M890:
  50. /*=* DFP Low Pad on *=*/
  51. sr2a = viafb_read_reg(VIASR, SR2A);
  52. viafb_write_reg_mask(SR2A, VIASR, 0x03, BIT0 + BIT1);
  53. break;
  54. case UNICHROME_P4M900:
  55. case UNICHROME_P4M890:
  56. /* DFP Low Pad on */
  57. sr2a = viafb_read_reg(VIASR, SR2A);
  58. viafb_write_reg_mask(SR2A, VIASR, 0x03, BIT0 + BIT1);
  59. /* DVP0 Pad on */
  60. sr1e = viafb_read_reg(VIASR, SR1E);
  61. viafb_write_reg_mask(SR1E, VIASR, 0xC0, BIT6 + BIT7);
  62. break;
  63. default:
  64. /* DVP0/DVP1 Pad on */
  65. sr1e = viafb_read_reg(VIASR, SR1E);
  66. viafb_write_reg_mask(SR1E, VIASR, 0xF0, BIT4 +
  67. BIT5 + BIT6 + BIT7);
  68. /* SR3E[1]Multi-function selection:
  69. 0 = Emulate I2C and DDC bus by GPIO2/3/4. */
  70. sr3e = viafb_read_reg(VIASR, SR3E);
  71. viafb_write_reg_mask(SR3E, VIASR, 0x0, BIT5);
  72. break;
  73. }
  74. /* Check for VT1632: */
  75. viaparinfo->chip_info->tmds_chip_info.tmds_chip_name = VT1632_TMDS;
  76. viaparinfo->chip_info->
  77. tmds_chip_info.tmds_chip_slave_addr = VT1632_TMDS_I2C_ADDR;
  78. viaparinfo->chip_info->tmds_chip_info.i2c_port = VIA_PORT_31;
  79. if (check_tmds_chip(VT1632_DEVICE_ID_REG, VT1632_DEVICE_ID) != FAIL) {
  80. /*
  81. * Currently only support 12bits,dual edge,add 24bits mode later
  82. */
  83. tmds_register_write(0x08, 0x3b);
  84. DEBUG_MSG(KERN_INFO "\n VT1632 TMDS ! \n");
  85. DEBUG_MSG(KERN_INFO "\n %2d",
  86. viaparinfo->chip_info->tmds_chip_info.tmds_chip_name);
  87. DEBUG_MSG(KERN_INFO "\n %2d",
  88. viaparinfo->chip_info->tmds_chip_info.i2c_port);
  89. return OK;
  90. } else {
  91. viaparinfo->chip_info->tmds_chip_info.i2c_port = VIA_PORT_2C;
  92. if (check_tmds_chip(VT1632_DEVICE_ID_REG, VT1632_DEVICE_ID)
  93. != FAIL) {
  94. tmds_register_write(0x08, 0x3b);
  95. DEBUG_MSG(KERN_INFO "\n VT1632 TMDS ! \n");
  96. DEBUG_MSG(KERN_INFO "\n %2d",
  97. viaparinfo->chip_info->
  98. tmds_chip_info.tmds_chip_name);
  99. DEBUG_MSG(KERN_INFO "\n %2d",
  100. viaparinfo->chip_info->
  101. tmds_chip_info.i2c_port);
  102. return OK;
  103. }
  104. }
  105. viaparinfo->chip_info->tmds_chip_info.tmds_chip_name = INTEGRATED_TMDS;
  106. if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700) &&
  107. ((viafb_display_hardware_layout == HW_LAYOUT_DVI_ONLY) ||
  108. (viafb_display_hardware_layout == HW_LAYOUT_LCD_DVI))) {
  109. DEBUG_MSG(KERN_INFO "\n Integrated TMDS ! \n");
  110. return OK;
  111. }
  112. switch (viaparinfo->chip_info->gfx_chip_name) {
  113. case UNICHROME_K8M890:
  114. viafb_write_reg(SR2A, VIASR, sr2a);
  115. break;
  116. case UNICHROME_P4M900:
  117. case UNICHROME_P4M890:
  118. viafb_write_reg(SR2A, VIASR, sr2a);
  119. viafb_write_reg(SR1E, VIASR, sr1e);
  120. break;
  121. default:
  122. viafb_write_reg(SR1E, VIASR, sr1e);
  123. viafb_write_reg(SR3E, VIASR, sr3e);
  124. break;
  125. }
  126. viaparinfo->chip_info->
  127. tmds_chip_info.tmds_chip_name = NON_TMDS_TRANSMITTER;
  128. viaparinfo->chip_info->tmds_chip_info.
  129. tmds_chip_slave_addr = VT1632_TMDS_I2C_ADDR;
  130. return FAIL;
  131. }
  132. static void tmds_register_write(int index, u8 data)
  133. {
  134. viafb_i2c_writebyte(viaparinfo->chip_info->tmds_chip_info.i2c_port,
  135. viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr,
  136. index, data);
  137. }
  138. static int tmds_register_read(int index)
  139. {
  140. u8 data;
  141. viafb_i2c_readbyte(viaparinfo->chip_info->tmds_chip_info.i2c_port,
  142. (u8) viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr,
  143. (u8) index, &data);
  144. return data;
  145. }
  146. static int tmds_register_read_bytes(int index, u8 *buff, int buff_len)
  147. {
  148. viafb_i2c_readbytes(viaparinfo->chip_info->tmds_chip_info.i2c_port,
  149. (u8) viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr,
  150. (u8) index, buff, buff_len);
  151. return 0;
  152. }
  153. /* DVI Set Mode */
  154. void viafb_dvi_set_mode(struct VideoModeTable *mode, int mode_bpp,
  155. int set_iga)
  156. {
  157. struct VideoModeTable *rb_mode;
  158. struct crt_mode_table *pDviTiming;
  159. unsigned long desirePixelClock, maxPixelClock;
  160. pDviTiming = mode->crtc;
  161. desirePixelClock = pDviTiming->refresh_rate
  162. * pDviTiming->crtc.hor_total * pDviTiming->crtc.ver_total
  163. / 1000000;
  164. maxPixelClock = (unsigned long)viaparinfo->
  165. tmds_setting_info->max_pixel_clock;
  166. DEBUG_MSG(KERN_INFO "\nDVI_set_mode!!\n");
  167. if ((maxPixelClock != 0) && (desirePixelClock > maxPixelClock)) {
  168. rb_mode = viafb_get_rb_mode(mode->crtc[0].crtc.hor_addr,
  169. mode->crtc[0].crtc.ver_addr);
  170. if (rb_mode) {
  171. mode = rb_mode;
  172. pDviTiming = rb_mode->crtc;
  173. }
  174. }
  175. viafb_fill_crtc_timing(pDviTiming, mode, mode_bpp / 8, set_iga);
  176. }
  177. /* Sense DVI Connector */
  178. int viafb_dvi_sense(void)
  179. {
  180. u8 RegSR1E = 0, RegSR3E = 0, RegCR6B = 0, RegCR91 = 0,
  181. RegCR93 = 0, RegCR9B = 0, data;
  182. int ret = false;
  183. DEBUG_MSG(KERN_INFO "viafb_dvi_sense!!\n");
  184. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266) {
  185. /* DI1 Pad on */
  186. RegSR1E = viafb_read_reg(VIASR, SR1E);
  187. viafb_write_reg(SR1E, VIASR, RegSR1E | 0x30);
  188. /* CR6B[0]VCK Input Selection: 1 = External clock. */
  189. RegCR6B = viafb_read_reg(VIACR, CR6B);
  190. viafb_write_reg(CR6B, VIACR, RegCR6B | 0x08);
  191. /* CR91[4] VDD On [3] Data On [2] VEE On [1] Back Light Off
  192. [0] Software Control Power Sequence */
  193. RegCR91 = viafb_read_reg(VIACR, CR91);
  194. viafb_write_reg(CR91, VIACR, 0x1D);
  195. /* CR93[7] DI1 Data Source Selection: 1 = DSP2.
  196. CR93[5] DI1 Clock Source: 1 = internal.
  197. CR93[4] DI1 Clock Polarity.
  198. CR93[3:1] DI1 Clock Adjust. CR93[0] DI1 enable */
  199. RegCR93 = viafb_read_reg(VIACR, CR93);
  200. viafb_write_reg(CR93, VIACR, 0x01);
  201. } else {
  202. /* DVP0/DVP1 Pad on */
  203. RegSR1E = viafb_read_reg(VIASR, SR1E);
  204. viafb_write_reg(SR1E, VIASR, RegSR1E | 0xF0);
  205. /* SR3E[1]Multi-function selection:
  206. 0 = Emulate I2C and DDC bus by GPIO2/3/4. */
  207. RegSR3E = viafb_read_reg(VIASR, SR3E);
  208. viafb_write_reg(SR3E, VIASR, RegSR3E & (~0x20));
  209. /* CR91[4] VDD On [3] Data On [2] VEE On [1] Back Light Off
  210. [0] Software Control Power Sequence */
  211. RegCR91 = viafb_read_reg(VIACR, CR91);
  212. viafb_write_reg(CR91, VIACR, 0x1D);
  213. /*CR9B[4] DVP1 Data Source Selection: 1 = From secondary
  214. display.CR9B[2:0] DVP1 Clock Adjust */
  215. RegCR9B = viafb_read_reg(VIACR, CR9B);
  216. viafb_write_reg(CR9B, VIACR, 0x01);
  217. }
  218. data = (u8) tmds_register_read(0x09);
  219. if (data & 0x04)
  220. ret = true;
  221. if (ret == false) {
  222. if (viafb_dvi_query_EDID())
  223. ret = true;
  224. }
  225. /* Restore status */
  226. viafb_write_reg(SR1E, VIASR, RegSR1E);
  227. viafb_write_reg(CR91, VIACR, RegCR91);
  228. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266) {
  229. viafb_write_reg(CR6B, VIACR, RegCR6B);
  230. viafb_write_reg(CR93, VIACR, RegCR93);
  231. } else {
  232. viafb_write_reg(SR3E, VIASR, RegSR3E);
  233. viafb_write_reg(CR9B, VIACR, RegCR9B);
  234. }
  235. return ret;
  236. }
  237. /* Query Flat Panel's EDID Table Version Through DVI Connector */
  238. static int viafb_dvi_query_EDID(void)
  239. {
  240. u8 data0, data1;
  241. int restore;
  242. DEBUG_MSG(KERN_INFO "viafb_dvi_query_EDID!!\n");
  243. restore = viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr;
  244. viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr = 0xA0;
  245. data0 = (u8) tmds_register_read(0x00);
  246. data1 = (u8) tmds_register_read(0x01);
  247. if ((data0 == 0) && (data1 == 0xFF)) {
  248. viaparinfo->chip_info->
  249. tmds_chip_info.tmds_chip_slave_addr = restore;
  250. return EDID_VERSION_1; /* Found EDID1 Table */
  251. }
  252. return false;
  253. }
  254. /* Get Panel Size Using EDID1 Table */
  255. static void __devinit dvi_get_panel_size_from_DDCv1(
  256. struct tmds_chip_information *tmds_chip,
  257. struct tmds_setting_information *tmds_setting)
  258. {
  259. int i, restore;
  260. unsigned char EDID_DATA[18];
  261. DEBUG_MSG(KERN_INFO "\n dvi_get_panel_size_from_DDCv1 \n");
  262. restore = tmds_chip->tmds_chip_slave_addr;
  263. tmds_chip->tmds_chip_slave_addr = 0xA0;
  264. for (i = 0x25; i < 0x6D; i++) {
  265. switch (i) {
  266. case 0x36:
  267. case 0x48:
  268. case 0x5A:
  269. case 0x6C:
  270. tmds_register_read_bytes(i, EDID_DATA, 10);
  271. if (!(EDID_DATA[0] || EDID_DATA[1])) {
  272. /* The first two byte must be zero. */
  273. if (EDID_DATA[3] == 0xFD) {
  274. /* To get max pixel clock. */
  275. tmds_setting->max_pixel_clock =
  276. EDID_DATA[9] * 10;
  277. }
  278. }
  279. break;
  280. default:
  281. break;
  282. }
  283. }
  284. DEBUG_MSG(KERN_INFO "DVI max pixelclock = %d\n",
  285. tmds_setting->max_pixel_clock);
  286. tmds_chip->tmds_chip_slave_addr = restore;
  287. }
  288. /* If Disable DVI, turn off pad */
  289. void viafb_dvi_disable(void)
  290. {
  291. if (viaparinfo->chip_info->
  292. tmds_chip_info.output_interface == INTERFACE_TMDS)
  293. /* Turn off TMDS power. */
  294. viafb_write_reg(CRD2, VIACR,
  295. viafb_read_reg(VIACR, CRD2) | 0x08);
  296. }
  297. static void dvi_patch_skew_dvp0(void)
  298. {
  299. /* Reset data driving first: */
  300. viafb_write_reg_mask(SR1B, VIASR, 0, BIT1);
  301. viafb_write_reg_mask(SR2A, VIASR, 0, BIT4);
  302. switch (viaparinfo->chip_info->gfx_chip_name) {
  303. case UNICHROME_P4M890:
  304. {
  305. if ((viaparinfo->tmds_setting_info->h_active == 1600) &&
  306. (viaparinfo->tmds_setting_info->v_active ==
  307. 1200))
  308. viafb_write_reg_mask(CR96, VIACR, 0x03,
  309. BIT0 + BIT1 + BIT2);
  310. else
  311. viafb_write_reg_mask(CR96, VIACR, 0x07,
  312. BIT0 + BIT1 + BIT2);
  313. break;
  314. }
  315. case UNICHROME_P4M900:
  316. {
  317. viafb_write_reg_mask(CR96, VIACR, 0x07,
  318. BIT0 + BIT1 + BIT2 + BIT3);
  319. viafb_write_reg_mask(SR1B, VIASR, 0x02, BIT1);
  320. viafb_write_reg_mask(SR2A, VIASR, 0x10, BIT4);
  321. break;
  322. }
  323. default:
  324. {
  325. break;
  326. }
  327. }
  328. }
  329. static void dvi_patch_skew_dvp_low(void)
  330. {
  331. switch (viaparinfo->chip_info->gfx_chip_name) {
  332. case UNICHROME_K8M890:
  333. {
  334. viafb_write_reg_mask(CR99, VIACR, 0x03, BIT0 + BIT1);
  335. break;
  336. }
  337. case UNICHROME_P4M900:
  338. {
  339. viafb_write_reg_mask(CR99, VIACR, 0x08,
  340. BIT0 + BIT1 + BIT2 + BIT3);
  341. break;
  342. }
  343. case UNICHROME_P4M890:
  344. {
  345. viafb_write_reg_mask(CR99, VIACR, 0x0F,
  346. BIT0 + BIT1 + BIT2 + BIT3);
  347. break;
  348. }
  349. default:
  350. {
  351. break;
  352. }
  353. }
  354. }
  355. /* If Enable DVI, turn off pad */
  356. void viafb_dvi_enable(void)
  357. {
  358. u8 data;
  359. switch (viaparinfo->chip_info->tmds_chip_info.output_interface) {
  360. case INTERFACE_DVP0:
  361. viafb_write_reg_mask(CR6B, VIACR, 0x01, BIT0);
  362. viafb_write_reg_mask(CR6C, VIACR, 0x21, BIT0 + BIT5);
  363. dvi_patch_skew_dvp0();
  364. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
  365. tmds_register_write(0x88, 0x3b);
  366. else
  367. /*clear CR91[5] to direct on display period
  368. in the secondary diplay path */
  369. via_write_reg_mask(VIACR, 0x91, 0x00, 0x20);
  370. break;
  371. case INTERFACE_DVP1:
  372. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
  373. viafb_write_reg_mask(CR93, VIACR, 0x21, BIT0 + BIT5);
  374. /*fix dvi cann't be enabled with MB VT5718C4 - Al Zhang */
  375. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
  376. tmds_register_write(0x88, 0x3b);
  377. else
  378. /*clear CR91[5] to direct on display period
  379. in the secondary diplay path */
  380. via_write_reg_mask(VIACR, 0x91, 0x00, 0x20);
  381. /*fix DVI cannot enable on EPIA-M board */
  382. if (viafb_platform_epia_dvi == 1) {
  383. viafb_write_reg_mask(CR91, VIACR, 0x1f, 0x1f);
  384. viafb_write_reg_mask(CR88, VIACR, 0x00, BIT6 + BIT0);
  385. if (viafb_bus_width == 24) {
  386. if (viafb_device_lcd_dualedge == 1)
  387. data = 0x3F;
  388. else
  389. data = 0x37;
  390. viafb_i2c_writebyte(viaparinfo->chip_info->
  391. tmds_chip_info.i2c_port,
  392. viaparinfo->chip_info->
  393. tmds_chip_info.tmds_chip_slave_addr,
  394. 0x08, data);
  395. }
  396. }
  397. break;
  398. case INTERFACE_DFP_HIGH:
  399. if (viaparinfo->chip_info->gfx_chip_name != UNICHROME_CLE266)
  400. via_write_reg_mask(VIACR, CR97, 0x03, 0x03);
  401. via_write_reg_mask(VIACR, 0x91, 0x00, 0x20);
  402. break;
  403. case INTERFACE_DFP_LOW:
  404. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
  405. break;
  406. dvi_patch_skew_dvp_low();
  407. via_write_reg_mask(VIACR, 0x91, 0x00, 0x20);
  408. break;
  409. case INTERFACE_TMDS:
  410. /* Turn on Display period in the panel path. */
  411. viafb_write_reg_mask(CR91, VIACR, 0, BIT7);
  412. /* Turn on TMDS power. */
  413. viafb_write_reg_mask(CRD2, VIACR, 0, BIT3);
  414. break;
  415. }
  416. if (viaparinfo->tmds_setting_info->iga_path == IGA2) {
  417. /* Disable LCD Scaling */
  418. viafb_write_reg_mask(CR79, VIACR, 0x00, BIT0);
  419. }
  420. }