dvi.c 13 KB

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