dvi.c 13 KB

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