dvi.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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. }
  169. viafb_fill_crtc_timing(mode, mode_bpp / 8, set_iga);
  170. }
  171. /* Sense DVI Connector */
  172. int viafb_dvi_sense(void)
  173. {
  174. u8 RegSR1E = 0, RegSR3E = 0, RegCR6B = 0, RegCR91 = 0,
  175. RegCR93 = 0, RegCR9B = 0, data;
  176. int ret = false;
  177. DEBUG_MSG(KERN_INFO "viafb_dvi_sense!!\n");
  178. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266) {
  179. /* DI1 Pad on */
  180. RegSR1E = viafb_read_reg(VIASR, SR1E);
  181. viafb_write_reg(SR1E, VIASR, RegSR1E | 0x30);
  182. /* CR6B[0]VCK Input Selection: 1 = External clock. */
  183. RegCR6B = viafb_read_reg(VIACR, CR6B);
  184. viafb_write_reg(CR6B, VIACR, RegCR6B | 0x08);
  185. /* CR91[4] VDD On [3] Data On [2] VEE On [1] Back Light Off
  186. [0] Software Control Power Sequence */
  187. RegCR91 = viafb_read_reg(VIACR, CR91);
  188. viafb_write_reg(CR91, VIACR, 0x1D);
  189. /* CR93[7] DI1 Data Source Selection: 1 = DSP2.
  190. CR93[5] DI1 Clock Source: 1 = internal.
  191. CR93[4] DI1 Clock Polarity.
  192. CR93[3:1] DI1 Clock Adjust. CR93[0] DI1 enable */
  193. RegCR93 = viafb_read_reg(VIACR, CR93);
  194. viafb_write_reg(CR93, VIACR, 0x01);
  195. } else {
  196. /* DVP0/DVP1 Pad on */
  197. RegSR1E = viafb_read_reg(VIASR, SR1E);
  198. viafb_write_reg(SR1E, VIASR, RegSR1E | 0xF0);
  199. /* SR3E[1]Multi-function selection:
  200. 0 = Emulate I2C and DDC bus by GPIO2/3/4. */
  201. RegSR3E = viafb_read_reg(VIASR, SR3E);
  202. viafb_write_reg(SR3E, VIASR, RegSR3E & (~0x20));
  203. /* CR91[4] VDD On [3] Data On [2] VEE On [1] Back Light Off
  204. [0] Software Control Power Sequence */
  205. RegCR91 = viafb_read_reg(VIACR, CR91);
  206. viafb_write_reg(CR91, VIACR, 0x1D);
  207. /*CR9B[4] DVP1 Data Source Selection: 1 = From secondary
  208. display.CR9B[2:0] DVP1 Clock Adjust */
  209. RegCR9B = viafb_read_reg(VIACR, CR9B);
  210. viafb_write_reg(CR9B, VIACR, 0x01);
  211. }
  212. data = (u8) tmds_register_read(0x09);
  213. if (data & 0x04)
  214. ret = true;
  215. if (ret == false) {
  216. if (viafb_dvi_query_EDID())
  217. ret = true;
  218. }
  219. /* Restore status */
  220. viafb_write_reg(SR1E, VIASR, RegSR1E);
  221. viafb_write_reg(CR91, VIACR, RegCR91);
  222. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266) {
  223. viafb_write_reg(CR6B, VIACR, RegCR6B);
  224. viafb_write_reg(CR93, VIACR, RegCR93);
  225. } else {
  226. viafb_write_reg(SR3E, VIASR, RegSR3E);
  227. viafb_write_reg(CR9B, VIACR, RegCR9B);
  228. }
  229. return ret;
  230. }
  231. /* Query Flat Panel's EDID Table Version Through DVI Connector */
  232. static int viafb_dvi_query_EDID(void)
  233. {
  234. u8 data0, data1;
  235. int restore;
  236. DEBUG_MSG(KERN_INFO "viafb_dvi_query_EDID!!\n");
  237. restore = viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr;
  238. viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr = 0xA0;
  239. data0 = (u8) tmds_register_read(0x00);
  240. data1 = (u8) tmds_register_read(0x01);
  241. if ((data0 == 0) && (data1 == 0xFF)) {
  242. viaparinfo->chip_info->
  243. tmds_chip_info.tmds_chip_slave_addr = restore;
  244. return EDID_VERSION_1; /* Found EDID1 Table */
  245. }
  246. return false;
  247. }
  248. /* Get Panel Size Using EDID1 Table */
  249. static void __devinit dvi_get_panel_size_from_DDCv1(
  250. struct tmds_chip_information *tmds_chip,
  251. struct tmds_setting_information *tmds_setting)
  252. {
  253. int i, restore;
  254. unsigned char EDID_DATA[18];
  255. DEBUG_MSG(KERN_INFO "\n dvi_get_panel_size_from_DDCv1 \n");
  256. restore = tmds_chip->tmds_chip_slave_addr;
  257. tmds_chip->tmds_chip_slave_addr = 0xA0;
  258. for (i = 0x25; i < 0x6D; i++) {
  259. switch (i) {
  260. case 0x36:
  261. case 0x48:
  262. case 0x5A:
  263. case 0x6C:
  264. tmds_register_read_bytes(i, EDID_DATA, 10);
  265. if (!(EDID_DATA[0] || EDID_DATA[1])) {
  266. /* The first two byte must be zero. */
  267. if (EDID_DATA[3] == 0xFD) {
  268. /* To get max pixel clock. */
  269. tmds_setting->max_pixel_clock =
  270. EDID_DATA[9] * 10;
  271. }
  272. }
  273. break;
  274. default:
  275. break;
  276. }
  277. }
  278. DEBUG_MSG(KERN_INFO "DVI max pixelclock = %d\n",
  279. tmds_setting->max_pixel_clock);
  280. tmds_chip->tmds_chip_slave_addr = restore;
  281. }
  282. /* If Disable DVI, turn off pad */
  283. void viafb_dvi_disable(void)
  284. {
  285. if (viaparinfo->chip_info->
  286. tmds_chip_info.output_interface == INTERFACE_TMDS)
  287. /* Turn off TMDS power. */
  288. viafb_write_reg(CRD2, VIACR,
  289. viafb_read_reg(VIACR, CRD2) | 0x08);
  290. }
  291. static void dvi_patch_skew_dvp0(void)
  292. {
  293. /* Reset data driving first: */
  294. viafb_write_reg_mask(SR1B, VIASR, 0, BIT1);
  295. viafb_write_reg_mask(SR2A, VIASR, 0, BIT4);
  296. switch (viaparinfo->chip_info->gfx_chip_name) {
  297. case UNICHROME_P4M890:
  298. {
  299. if ((viaparinfo->tmds_setting_info->h_active == 1600) &&
  300. (viaparinfo->tmds_setting_info->v_active ==
  301. 1200))
  302. viafb_write_reg_mask(CR96, VIACR, 0x03,
  303. BIT0 + BIT1 + BIT2);
  304. else
  305. viafb_write_reg_mask(CR96, VIACR, 0x07,
  306. BIT0 + BIT1 + BIT2);
  307. break;
  308. }
  309. case UNICHROME_P4M900:
  310. {
  311. viafb_write_reg_mask(CR96, VIACR, 0x07,
  312. BIT0 + BIT1 + BIT2 + BIT3);
  313. viafb_write_reg_mask(SR1B, VIASR, 0x02, BIT1);
  314. viafb_write_reg_mask(SR2A, VIASR, 0x10, BIT4);
  315. break;
  316. }
  317. default:
  318. {
  319. break;
  320. }
  321. }
  322. }
  323. static void dvi_patch_skew_dvp_low(void)
  324. {
  325. switch (viaparinfo->chip_info->gfx_chip_name) {
  326. case UNICHROME_K8M890:
  327. {
  328. viafb_write_reg_mask(CR99, VIACR, 0x03, BIT0 + BIT1);
  329. break;
  330. }
  331. case UNICHROME_P4M900:
  332. {
  333. viafb_write_reg_mask(CR99, VIACR, 0x08,
  334. BIT0 + BIT1 + BIT2 + BIT3);
  335. break;
  336. }
  337. case UNICHROME_P4M890:
  338. {
  339. viafb_write_reg_mask(CR99, VIACR, 0x0F,
  340. BIT0 + BIT1 + BIT2 + BIT3);
  341. break;
  342. }
  343. default:
  344. {
  345. break;
  346. }
  347. }
  348. }
  349. /* If Enable DVI, turn off pad */
  350. void viafb_dvi_enable(void)
  351. {
  352. u8 data;
  353. switch (viaparinfo->chip_info->tmds_chip_info.output_interface) {
  354. case INTERFACE_DVP0:
  355. viafb_write_reg_mask(CR6B, VIACR, 0x01, BIT0);
  356. viafb_write_reg_mask(CR6C, VIACR, 0x21, BIT0 + BIT5);
  357. dvi_patch_skew_dvp0();
  358. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
  359. tmds_register_write(0x88, 0x3b);
  360. else
  361. /*clear CR91[5] to direct on display period
  362. in the secondary diplay path */
  363. via_write_reg_mask(VIACR, 0x91, 0x00, 0x20);
  364. break;
  365. case INTERFACE_DVP1:
  366. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
  367. viafb_write_reg_mask(CR93, VIACR, 0x21, BIT0 + BIT5);
  368. /*fix dvi cann't be enabled with MB VT5718C4 - Al Zhang */
  369. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
  370. tmds_register_write(0x88, 0x3b);
  371. else
  372. /*clear CR91[5] to direct on display period
  373. in the secondary diplay path */
  374. via_write_reg_mask(VIACR, 0x91, 0x00, 0x20);
  375. /*fix DVI cannot enable on EPIA-M board */
  376. if (viafb_platform_epia_dvi == 1) {
  377. viafb_write_reg_mask(CR91, VIACR, 0x1f, 0x1f);
  378. viafb_write_reg_mask(CR88, VIACR, 0x00, BIT6 + BIT0);
  379. if (viafb_bus_width == 24) {
  380. if (viafb_device_lcd_dualedge == 1)
  381. data = 0x3F;
  382. else
  383. data = 0x37;
  384. viafb_i2c_writebyte(viaparinfo->chip_info->
  385. tmds_chip_info.i2c_port,
  386. viaparinfo->chip_info->
  387. tmds_chip_info.tmds_chip_slave_addr,
  388. 0x08, data);
  389. }
  390. }
  391. break;
  392. case INTERFACE_DFP_HIGH:
  393. if (viaparinfo->chip_info->gfx_chip_name != UNICHROME_CLE266)
  394. via_write_reg_mask(VIACR, CR97, 0x03, 0x03);
  395. via_write_reg_mask(VIACR, 0x91, 0x00, 0x20);
  396. break;
  397. case INTERFACE_DFP_LOW:
  398. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
  399. break;
  400. dvi_patch_skew_dvp_low();
  401. via_write_reg_mask(VIACR, 0x91, 0x00, 0x20);
  402. break;
  403. case INTERFACE_TMDS:
  404. /* Turn on Display period in the panel path. */
  405. viafb_write_reg_mask(CR91, VIACR, 0, BIT7);
  406. /* Turn on TMDS power. */
  407. viafb_write_reg_mask(CRD2, VIACR, 0, BIT3);
  408. break;
  409. }
  410. if (viaparinfo->tmds_setting_info->iga_path == IGA2) {
  411. /* Disable LCD Scaling */
  412. viafb_write_reg_mask(CR79, VIACR, 0x00, BIT0);
  413. }
  414. }