dvi.c 13 KB

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