lcd.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  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. #define viafb_compact_res(x, y) (((x)<<16)|(y))
  22. /* CLE266 Software Power Sequence */
  23. /* {Mask}, {Data}, {Delay} */
  24. static const int PowerSequenceOn[3][3] = {
  25. {0x10, 0x08, 0x06}, {0x10, 0x08, 0x06}, {0x19, 0x1FE, 0x01}
  26. };
  27. static const int PowerSequenceOff[3][3] = {
  28. {0x06, 0x08, 0x10}, {0x00, 0x00, 0x00}, {0xD2, 0x19, 0x01}
  29. };
  30. static struct _lcd_scaling_factor lcd_scaling_factor = {
  31. /* LCD Horizontal Scaling Factor Register */
  32. {LCD_HOR_SCALING_FACTOR_REG_NUM,
  33. {{CR9F, 0, 1}, {CR77, 0, 7}, {CR79, 4, 5} } },
  34. /* LCD Vertical Scaling Factor Register */
  35. {LCD_VER_SCALING_FACTOR_REG_NUM,
  36. {{CR79, 3, 3}, {CR78, 0, 7}, {CR79, 6, 7} } }
  37. };
  38. static struct _lcd_scaling_factor lcd_scaling_factor_CLE = {
  39. /* LCD Horizontal Scaling Factor Register */
  40. {LCD_HOR_SCALING_FACTOR_REG_NUM_CLE, {{CR77, 0, 7}, {CR79, 4, 5} } },
  41. /* LCD Vertical Scaling Factor Register */
  42. {LCD_VER_SCALING_FACTOR_REG_NUM_CLE, {{CR78, 0, 7}, {CR79, 6, 7} } }
  43. };
  44. static bool lvds_identify_integratedlvds(void);
  45. static void __devinit fp_id_to_vindex(int panel_id);
  46. static int lvds_register_read(int index);
  47. static void load_lcd_scaling(int set_hres, int set_vres, int panel_hres,
  48. int panel_vres);
  49. static void via_pitch_alignment_patch_lcd(
  50. struct lvds_setting_information *plvds_setting_info,
  51. struct lvds_chip_information
  52. *plvds_chip_info);
  53. static void lcd_patch_skew_dvp0(struct lvds_setting_information
  54. *plvds_setting_info,
  55. struct lvds_chip_information *plvds_chip_info);
  56. static void lcd_patch_skew_dvp1(struct lvds_setting_information
  57. *plvds_setting_info,
  58. struct lvds_chip_information *plvds_chip_info);
  59. static void lcd_patch_skew(struct lvds_setting_information
  60. *plvds_setting_info, struct lvds_chip_information *plvds_chip_info);
  61. static void integrated_lvds_disable(struct lvds_setting_information
  62. *plvds_setting_info,
  63. struct lvds_chip_information *plvds_chip_info);
  64. static void integrated_lvds_enable(struct lvds_setting_information
  65. *plvds_setting_info,
  66. struct lvds_chip_information *plvds_chip_info);
  67. static void lcd_powersequence_off(void);
  68. static void lcd_powersequence_on(void);
  69. static void fill_lcd_format(void);
  70. static void check_diport_of_integrated_lvds(
  71. struct lvds_chip_information *plvds_chip_info,
  72. struct lvds_setting_information
  73. *plvds_setting_info);
  74. static struct display_timing lcd_centering_timging(struct display_timing
  75. mode_crt_reg,
  76. struct display_timing panel_crt_reg);
  77. static inline bool check_lvds_chip(int device_id_subaddr, int device_id)
  78. {
  79. return lvds_register_read(device_id_subaddr) == device_id;
  80. }
  81. void __devinit viafb_init_lcd_size(void)
  82. {
  83. DEBUG_MSG(KERN_INFO "viafb_init_lcd_size()\n");
  84. fp_id_to_vindex(viafb_lcd_panel_id);
  85. viaparinfo->lvds_setting_info2->lcd_panel_hres =
  86. viaparinfo->lvds_setting_info->lcd_panel_hres;
  87. viaparinfo->lvds_setting_info2->lcd_panel_vres =
  88. viaparinfo->lvds_setting_info->lcd_panel_vres;
  89. viaparinfo->lvds_setting_info2->device_lcd_dualedge =
  90. viaparinfo->lvds_setting_info->device_lcd_dualedge;
  91. viaparinfo->lvds_setting_info2->LCDDithering =
  92. viaparinfo->lvds_setting_info->LCDDithering;
  93. }
  94. static bool lvds_identify_integratedlvds(void)
  95. {
  96. if (viafb_display_hardware_layout == HW_LAYOUT_LCD_EXTERNAL_LCD2) {
  97. /* Two dual channel LCD (Internal LVDS + External LVDS): */
  98. /* If we have an external LVDS, such as VT1636, we should
  99. have its chip ID already. */
  100. if (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
  101. viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name =
  102. INTEGRATED_LVDS;
  103. DEBUG_MSG(KERN_INFO "Support two dual channel LVDS! "
  104. "(Internal LVDS + External LVDS)\n");
  105. } else {
  106. viaparinfo->chip_info->lvds_chip_info.lvds_chip_name =
  107. INTEGRATED_LVDS;
  108. DEBUG_MSG(KERN_INFO "Not found external LVDS, "
  109. "so can't support two dual channel LVDS!\n");
  110. }
  111. } else if (viafb_display_hardware_layout == HW_LAYOUT_LCD1_LCD2) {
  112. /* Two single channel LCD (Internal LVDS + Internal LVDS): */
  113. viaparinfo->chip_info->lvds_chip_info.lvds_chip_name =
  114. INTEGRATED_LVDS;
  115. viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name =
  116. INTEGRATED_LVDS;
  117. DEBUG_MSG(KERN_INFO "Support two single channel LVDS! "
  118. "(Internal LVDS + Internal LVDS)\n");
  119. } else if (viafb_display_hardware_layout != HW_LAYOUT_DVI_ONLY) {
  120. /* If we have found external LVDS, just use it,
  121. otherwise, we will use internal LVDS as default. */
  122. if (!viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
  123. viaparinfo->chip_info->lvds_chip_info.lvds_chip_name =
  124. INTEGRATED_LVDS;
  125. DEBUG_MSG(KERN_INFO "Found Integrated LVDS!\n");
  126. }
  127. } else {
  128. viaparinfo->chip_info->lvds_chip_info.lvds_chip_name =
  129. NON_LVDS_TRANSMITTER;
  130. DEBUG_MSG(KERN_INFO "Do not support LVDS!\n");
  131. return false;
  132. }
  133. return true;
  134. }
  135. bool __devinit viafb_lvds_trasmitter_identify(void)
  136. {
  137. if (viafb_lvds_identify_vt1636(VIA_PORT_31)) {
  138. viaparinfo->chip_info->lvds_chip_info.i2c_port = VIA_PORT_31;
  139. DEBUG_MSG(KERN_INFO
  140. "Found VIA VT1636 LVDS on port i2c 0x31\n");
  141. } else {
  142. if (viafb_lvds_identify_vt1636(VIA_PORT_2C)) {
  143. viaparinfo->chip_info->lvds_chip_info.i2c_port =
  144. VIA_PORT_2C;
  145. DEBUG_MSG(KERN_INFO
  146. "Found VIA VT1636 LVDS on port gpio 0x2c\n");
  147. }
  148. }
  149. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700)
  150. lvds_identify_integratedlvds();
  151. if (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name)
  152. return true;
  153. /* Check for VT1631: */
  154. viaparinfo->chip_info->lvds_chip_info.lvds_chip_name = VT1631_LVDS;
  155. viaparinfo->chip_info->lvds_chip_info.lvds_chip_slave_addr =
  156. VT1631_LVDS_I2C_ADDR;
  157. if (check_lvds_chip(VT1631_DEVICE_ID_REG, VT1631_DEVICE_ID)) {
  158. DEBUG_MSG(KERN_INFO "\n VT1631 LVDS ! \n");
  159. DEBUG_MSG(KERN_INFO "\n %2d",
  160. viaparinfo->chip_info->lvds_chip_info.lvds_chip_name);
  161. DEBUG_MSG(KERN_INFO "\n %2d",
  162. viaparinfo->chip_info->lvds_chip_info.lvds_chip_name);
  163. return true;
  164. }
  165. viaparinfo->chip_info->lvds_chip_info.lvds_chip_name =
  166. NON_LVDS_TRANSMITTER;
  167. viaparinfo->chip_info->lvds_chip_info.lvds_chip_slave_addr =
  168. VT1631_LVDS_I2C_ADDR;
  169. return false;
  170. }
  171. static void __devinit fp_id_to_vindex(int panel_id)
  172. {
  173. DEBUG_MSG(KERN_INFO "fp_get_panel_id()\n");
  174. if (panel_id > LCD_PANEL_ID_MAXIMUM)
  175. viafb_lcd_panel_id = panel_id =
  176. viafb_read_reg(VIACR, CR3F) & 0x0F;
  177. switch (panel_id) {
  178. case 0x0:
  179. viaparinfo->lvds_setting_info->lcd_panel_hres = 640;
  180. viaparinfo->lvds_setting_info->lcd_panel_vres = 480;
  181. viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
  182. viaparinfo->lvds_setting_info->LCDDithering = 1;
  183. break;
  184. case 0x1:
  185. viaparinfo->lvds_setting_info->lcd_panel_hres = 800;
  186. viaparinfo->lvds_setting_info->lcd_panel_vres = 600;
  187. viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
  188. viaparinfo->lvds_setting_info->LCDDithering = 1;
  189. break;
  190. case 0x2:
  191. viaparinfo->lvds_setting_info->lcd_panel_hres = 1024;
  192. viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
  193. viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
  194. viaparinfo->lvds_setting_info->LCDDithering = 1;
  195. break;
  196. case 0x3:
  197. viaparinfo->lvds_setting_info->lcd_panel_hres = 1280;
  198. viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
  199. viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
  200. viaparinfo->lvds_setting_info->LCDDithering = 1;
  201. break;
  202. case 0x4:
  203. viaparinfo->lvds_setting_info->lcd_panel_hres = 1280;
  204. viaparinfo->lvds_setting_info->lcd_panel_vres = 1024;
  205. viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
  206. viaparinfo->lvds_setting_info->LCDDithering = 1;
  207. break;
  208. case 0x5:
  209. viaparinfo->lvds_setting_info->lcd_panel_hres = 1400;
  210. viaparinfo->lvds_setting_info->lcd_panel_vres = 1050;
  211. viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
  212. viaparinfo->lvds_setting_info->LCDDithering = 1;
  213. break;
  214. case 0x6:
  215. viaparinfo->lvds_setting_info->lcd_panel_hres = 1600;
  216. viaparinfo->lvds_setting_info->lcd_panel_vres = 1200;
  217. viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
  218. viaparinfo->lvds_setting_info->LCDDithering = 1;
  219. break;
  220. case 0x8:
  221. viaparinfo->lvds_setting_info->lcd_panel_hres = 800;
  222. viaparinfo->lvds_setting_info->lcd_panel_vres = 480;
  223. viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
  224. viaparinfo->lvds_setting_info->LCDDithering = 1;
  225. break;
  226. case 0x9:
  227. viaparinfo->lvds_setting_info->lcd_panel_hres = 1024;
  228. viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
  229. viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
  230. viaparinfo->lvds_setting_info->LCDDithering = 1;
  231. break;
  232. case 0xA:
  233. viaparinfo->lvds_setting_info->lcd_panel_hres = 1024;
  234. viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
  235. viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
  236. viaparinfo->lvds_setting_info->LCDDithering = 0;
  237. break;
  238. case 0xB:
  239. viaparinfo->lvds_setting_info->lcd_panel_hres = 1024;
  240. viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
  241. viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
  242. viaparinfo->lvds_setting_info->LCDDithering = 0;
  243. break;
  244. case 0xC:
  245. viaparinfo->lvds_setting_info->lcd_panel_hres = 1280;
  246. viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
  247. viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
  248. viaparinfo->lvds_setting_info->LCDDithering = 0;
  249. break;
  250. case 0xD:
  251. viaparinfo->lvds_setting_info->lcd_panel_hres = 1280;
  252. viaparinfo->lvds_setting_info->lcd_panel_vres = 1024;
  253. viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
  254. viaparinfo->lvds_setting_info->LCDDithering = 0;
  255. break;
  256. case 0xE:
  257. viaparinfo->lvds_setting_info->lcd_panel_hres = 1400;
  258. viaparinfo->lvds_setting_info->lcd_panel_vres = 1050;
  259. viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
  260. viaparinfo->lvds_setting_info->LCDDithering = 0;
  261. break;
  262. case 0xF:
  263. viaparinfo->lvds_setting_info->lcd_panel_hres = 1600;
  264. viaparinfo->lvds_setting_info->lcd_panel_vres = 1200;
  265. viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
  266. viaparinfo->lvds_setting_info->LCDDithering = 0;
  267. break;
  268. case 0x10:
  269. viaparinfo->lvds_setting_info->lcd_panel_hres = 1366;
  270. viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
  271. viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
  272. viaparinfo->lvds_setting_info->LCDDithering = 0;
  273. break;
  274. case 0x11:
  275. viaparinfo->lvds_setting_info->lcd_panel_hres = 1024;
  276. viaparinfo->lvds_setting_info->lcd_panel_vres = 600;
  277. viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
  278. viaparinfo->lvds_setting_info->LCDDithering = 1;
  279. break;
  280. case 0x12:
  281. viaparinfo->lvds_setting_info->lcd_panel_hres = 1280;
  282. viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
  283. viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
  284. viaparinfo->lvds_setting_info->LCDDithering = 1;
  285. break;
  286. case 0x13:
  287. viaparinfo->lvds_setting_info->lcd_panel_hres = 1280;
  288. viaparinfo->lvds_setting_info->lcd_panel_vres = 800;
  289. viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
  290. viaparinfo->lvds_setting_info->LCDDithering = 1;
  291. break;
  292. case 0x14:
  293. viaparinfo->lvds_setting_info->lcd_panel_hres = 1360;
  294. viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
  295. viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
  296. viaparinfo->lvds_setting_info->LCDDithering = 0;
  297. break;
  298. case 0x15:
  299. viaparinfo->lvds_setting_info->lcd_panel_hres = 1280;
  300. viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
  301. viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
  302. viaparinfo->lvds_setting_info->LCDDithering = 0;
  303. break;
  304. case 0x16:
  305. viaparinfo->lvds_setting_info->lcd_panel_hres = 480;
  306. viaparinfo->lvds_setting_info->lcd_panel_vres = 640;
  307. viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
  308. viaparinfo->lvds_setting_info->LCDDithering = 1;
  309. break;
  310. case 0x17:
  311. /* OLPC XO-1.5 panel */
  312. viaparinfo->lvds_setting_info->lcd_panel_hres = 1200;
  313. viaparinfo->lvds_setting_info->lcd_panel_vres = 900;
  314. viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
  315. viaparinfo->lvds_setting_info->LCDDithering = 0;
  316. break;
  317. default:
  318. viaparinfo->lvds_setting_info->lcd_panel_hres = 800;
  319. viaparinfo->lvds_setting_info->lcd_panel_vres = 600;
  320. viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
  321. viaparinfo->lvds_setting_info->LCDDithering = 1;
  322. }
  323. }
  324. static int lvds_register_read(int index)
  325. {
  326. u8 data;
  327. viafb_i2c_readbyte(VIA_PORT_2C,
  328. (u8) viaparinfo->chip_info->lvds_chip_info.lvds_chip_slave_addr,
  329. (u8) index, &data);
  330. return data;
  331. }
  332. static void load_lcd_scaling(int set_hres, int set_vres, int panel_hres,
  333. int panel_vres)
  334. {
  335. int reg_value = 0;
  336. int viafb_load_reg_num;
  337. struct io_register *reg = NULL;
  338. DEBUG_MSG(KERN_INFO "load_lcd_scaling()!!\n");
  339. /* LCD Scaling Enable */
  340. viafb_write_reg_mask(CR79, VIACR, 0x07, BIT0 + BIT1 + BIT2);
  341. /* Check if expansion for horizontal */
  342. if (set_hres < panel_hres) {
  343. /* Load Horizontal Scaling Factor */
  344. switch (viaparinfo->chip_info->gfx_chip_name) {
  345. case UNICHROME_CLE266:
  346. case UNICHROME_K400:
  347. reg_value =
  348. CLE266_LCD_HOR_SCF_FORMULA(set_hres, panel_hres);
  349. viafb_load_reg_num =
  350. lcd_scaling_factor_CLE.lcd_hor_scaling_factor.
  351. reg_num;
  352. reg = lcd_scaling_factor_CLE.lcd_hor_scaling_factor.reg;
  353. viafb_load_reg(reg_value,
  354. viafb_load_reg_num, reg, VIACR);
  355. break;
  356. case UNICHROME_K800:
  357. case UNICHROME_PM800:
  358. case UNICHROME_CN700:
  359. case UNICHROME_CX700:
  360. case UNICHROME_K8M890:
  361. case UNICHROME_P4M890:
  362. case UNICHROME_P4M900:
  363. case UNICHROME_CN750:
  364. case UNICHROME_VX800:
  365. case UNICHROME_VX855:
  366. case UNICHROME_VX900:
  367. reg_value =
  368. K800_LCD_HOR_SCF_FORMULA(set_hres, panel_hres);
  369. /* Horizontal scaling enabled */
  370. viafb_write_reg_mask(CRA2, VIACR, 0xC0, BIT7 + BIT6);
  371. viafb_load_reg_num =
  372. lcd_scaling_factor.lcd_hor_scaling_factor.reg_num;
  373. reg = lcd_scaling_factor.lcd_hor_scaling_factor.reg;
  374. viafb_load_reg(reg_value,
  375. viafb_load_reg_num, reg, VIACR);
  376. break;
  377. }
  378. DEBUG_MSG(KERN_INFO "Horizontal Scaling value = %d", reg_value);
  379. } else {
  380. /* Horizontal scaling disabled */
  381. viafb_write_reg_mask(CRA2, VIACR, 0x00, BIT7);
  382. }
  383. /* Check if expansion for vertical */
  384. if (set_vres < panel_vres) {
  385. /* Load Vertical Scaling Factor */
  386. switch (viaparinfo->chip_info->gfx_chip_name) {
  387. case UNICHROME_CLE266:
  388. case UNICHROME_K400:
  389. reg_value =
  390. CLE266_LCD_VER_SCF_FORMULA(set_vres, panel_vres);
  391. viafb_load_reg_num =
  392. lcd_scaling_factor_CLE.lcd_ver_scaling_factor.
  393. reg_num;
  394. reg = lcd_scaling_factor_CLE.lcd_ver_scaling_factor.reg;
  395. viafb_load_reg(reg_value,
  396. viafb_load_reg_num, reg, VIACR);
  397. break;
  398. case UNICHROME_K800:
  399. case UNICHROME_PM800:
  400. case UNICHROME_CN700:
  401. case UNICHROME_CX700:
  402. case UNICHROME_K8M890:
  403. case UNICHROME_P4M890:
  404. case UNICHROME_P4M900:
  405. case UNICHROME_CN750:
  406. case UNICHROME_VX800:
  407. case UNICHROME_VX855:
  408. case UNICHROME_VX900:
  409. reg_value =
  410. K800_LCD_VER_SCF_FORMULA(set_vres, panel_vres);
  411. /* Vertical scaling enabled */
  412. viafb_write_reg_mask(CRA2, VIACR, 0x08, BIT3);
  413. viafb_load_reg_num =
  414. lcd_scaling_factor.lcd_ver_scaling_factor.reg_num;
  415. reg = lcd_scaling_factor.lcd_ver_scaling_factor.reg;
  416. viafb_load_reg(reg_value,
  417. viafb_load_reg_num, reg, VIACR);
  418. break;
  419. }
  420. DEBUG_MSG(KERN_INFO "Vertical Scaling value = %d", reg_value);
  421. } else {
  422. /* Vertical scaling disabled */
  423. viafb_write_reg_mask(CRA2, VIACR, 0x00, BIT3);
  424. }
  425. }
  426. static void via_pitch_alignment_patch_lcd(
  427. struct lvds_setting_information *plvds_setting_info,
  428. struct lvds_chip_information
  429. *plvds_chip_info)
  430. {
  431. unsigned char cr13, cr35, cr65, cr66, cr67;
  432. unsigned long dwScreenPitch = 0;
  433. unsigned long dwPitch;
  434. dwPitch = plvds_setting_info->h_active * (plvds_setting_info->bpp >> 3);
  435. if (dwPitch & 0x1F) {
  436. dwScreenPitch = ((dwPitch + 31) & ~31) >> 3;
  437. if (plvds_setting_info->iga_path == IGA2) {
  438. if (plvds_setting_info->bpp > 8) {
  439. cr66 = (unsigned char)(dwScreenPitch & 0xFF);
  440. viafb_write_reg(CR66, VIACR, cr66);
  441. cr67 = viafb_read_reg(VIACR, CR67) & 0xFC;
  442. cr67 |=
  443. (unsigned
  444. char)((dwScreenPitch & 0x300) >> 8);
  445. viafb_write_reg(CR67, VIACR, cr67);
  446. }
  447. /* Fetch Count */
  448. cr67 = viafb_read_reg(VIACR, CR67) & 0xF3;
  449. cr67 |= (unsigned char)((dwScreenPitch & 0x600) >> 7);
  450. viafb_write_reg(CR67, VIACR, cr67);
  451. cr65 = (unsigned char)((dwScreenPitch >> 1) & 0xFF);
  452. cr65 += 2;
  453. viafb_write_reg(CR65, VIACR, cr65);
  454. } else {
  455. if (plvds_setting_info->bpp > 8) {
  456. cr13 = (unsigned char)(dwScreenPitch & 0xFF);
  457. viafb_write_reg(CR13, VIACR, cr13);
  458. cr35 = viafb_read_reg(VIACR, CR35) & 0x1F;
  459. cr35 |=
  460. (unsigned
  461. char)((dwScreenPitch & 0x700) >> 3);
  462. viafb_write_reg(CR35, VIACR, cr35);
  463. }
  464. }
  465. }
  466. }
  467. static void lcd_patch_skew_dvp0(struct lvds_setting_information
  468. *plvds_setting_info,
  469. struct lvds_chip_information *plvds_chip_info)
  470. {
  471. if (VT1636_LVDS == plvds_chip_info->lvds_chip_name) {
  472. switch (viaparinfo->chip_info->gfx_chip_name) {
  473. case UNICHROME_P4M900:
  474. viafb_vt1636_patch_skew_on_vt3364(plvds_setting_info,
  475. plvds_chip_info);
  476. break;
  477. case UNICHROME_P4M890:
  478. viafb_vt1636_patch_skew_on_vt3327(plvds_setting_info,
  479. plvds_chip_info);
  480. break;
  481. }
  482. }
  483. }
  484. static void lcd_patch_skew_dvp1(struct lvds_setting_information
  485. *plvds_setting_info,
  486. struct lvds_chip_information *plvds_chip_info)
  487. {
  488. if (VT1636_LVDS == plvds_chip_info->lvds_chip_name) {
  489. switch (viaparinfo->chip_info->gfx_chip_name) {
  490. case UNICHROME_CX700:
  491. viafb_vt1636_patch_skew_on_vt3324(plvds_setting_info,
  492. plvds_chip_info);
  493. break;
  494. }
  495. }
  496. }
  497. static void lcd_patch_skew(struct lvds_setting_information
  498. *plvds_setting_info, struct lvds_chip_information *plvds_chip_info)
  499. {
  500. DEBUG_MSG(KERN_INFO "lcd_patch_skew\n");
  501. switch (plvds_chip_info->output_interface) {
  502. case INTERFACE_DVP0:
  503. lcd_patch_skew_dvp0(plvds_setting_info, plvds_chip_info);
  504. break;
  505. case INTERFACE_DVP1:
  506. lcd_patch_skew_dvp1(plvds_setting_info, plvds_chip_info);
  507. break;
  508. case INTERFACE_DFP_LOW:
  509. if (UNICHROME_P4M900 == viaparinfo->chip_info->gfx_chip_name) {
  510. viafb_write_reg_mask(CR99, VIACR, 0x08,
  511. BIT0 + BIT1 + BIT2 + BIT3);
  512. }
  513. break;
  514. }
  515. }
  516. /* LCD Set Mode */
  517. void viafb_lcd_set_mode(struct crt_mode_table *mode_crt_table,
  518. struct lvds_setting_information *plvds_setting_info,
  519. struct lvds_chip_information *plvds_chip_info)
  520. {
  521. int set_iga = plvds_setting_info->iga_path;
  522. int mode_bpp = plvds_setting_info->bpp;
  523. int set_hres = plvds_setting_info->h_active;
  524. int set_vres = plvds_setting_info->v_active;
  525. int panel_hres = plvds_setting_info->lcd_panel_hres;
  526. int panel_vres = plvds_setting_info->lcd_panel_vres;
  527. u32 clock;
  528. struct display_timing mode_crt_reg, panel_crt_reg;
  529. struct crt_mode_table *panel_crt_table = NULL;
  530. struct VideoModeTable *vmode_tbl = viafb_get_mode(panel_hres,
  531. panel_vres);
  532. DEBUG_MSG(KERN_INFO "viafb_lcd_set_mode!!\n");
  533. /* Get mode table */
  534. mode_crt_reg = mode_crt_table->crtc;
  535. /* Get panel table Pointer */
  536. panel_crt_table = vmode_tbl->crtc;
  537. panel_crt_reg = panel_crt_table->crtc;
  538. DEBUG_MSG(KERN_INFO "bellow viafb_lcd_set_mode!!\n");
  539. if (VT1636_LVDS == plvds_chip_info->lvds_chip_name)
  540. viafb_init_lvds_vt1636(plvds_setting_info, plvds_chip_info);
  541. clock = panel_crt_reg.hor_total * panel_crt_reg.ver_total
  542. * panel_crt_table->refresh_rate;
  543. plvds_setting_info->vclk = clock;
  544. if (set_iga == IGA1) {
  545. /* IGA1 doesn't have LCD scaling, so set it as centering. */
  546. viafb_load_crtc_timing(lcd_centering_timging
  547. (mode_crt_reg, panel_crt_reg), IGA1);
  548. } else {
  549. /* Expansion */
  550. if (plvds_setting_info->display_method == LCD_EXPANDSION
  551. && (set_hres < panel_hres || set_vres < panel_vres)) {
  552. /* expansion timing IGA2 loaded panel set timing*/
  553. viafb_load_crtc_timing(panel_crt_reg, IGA2);
  554. DEBUG_MSG(KERN_INFO "viafb_load_crtc_timing!!\n");
  555. load_lcd_scaling(set_hres, set_vres, panel_hres,
  556. panel_vres);
  557. DEBUG_MSG(KERN_INFO "load_lcd_scaling!!\n");
  558. } else { /* Centering */
  559. /* centering timing IGA2 always loaded panel
  560. and mode releative timing */
  561. viafb_load_crtc_timing(lcd_centering_timging
  562. (mode_crt_reg, panel_crt_reg), IGA2);
  563. viafb_write_reg_mask(CR79, VIACR, 0x00,
  564. BIT0 + BIT1 + BIT2);
  565. /* LCD scaling disabled */
  566. }
  567. }
  568. /* Fetch count for IGA2 only */
  569. viafb_load_fetch_count_reg(set_hres, mode_bpp / 8, set_iga);
  570. if ((viaparinfo->chip_info->gfx_chip_name != UNICHROME_CLE266)
  571. && (viaparinfo->chip_info->gfx_chip_name != UNICHROME_K400))
  572. viafb_load_FIFO_reg(set_iga, set_hres, set_vres);
  573. fill_lcd_format();
  574. viafb_set_vclock(clock, set_iga);
  575. lcd_patch_skew(plvds_setting_info, plvds_chip_info);
  576. /* If K8M800, enable LCD Prefetch Mode. */
  577. if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_K800)
  578. || (UNICHROME_K8M890 == viaparinfo->chip_info->gfx_chip_name))
  579. viafb_write_reg_mask(CR6A, VIACR, 0x01, BIT0);
  580. /* Patch for non 32bit alignment mode */
  581. via_pitch_alignment_patch_lcd(plvds_setting_info, plvds_chip_info);
  582. }
  583. static void integrated_lvds_disable(struct lvds_setting_information
  584. *plvds_setting_info,
  585. struct lvds_chip_information *plvds_chip_info)
  586. {
  587. bool turn_off_first_powersequence = false;
  588. bool turn_off_second_powersequence = false;
  589. if (INTERFACE_LVDS0LVDS1 == plvds_chip_info->output_interface)
  590. turn_off_first_powersequence = true;
  591. if (INTERFACE_LVDS0 == plvds_chip_info->output_interface)
  592. turn_off_first_powersequence = true;
  593. if (INTERFACE_LVDS1 == plvds_chip_info->output_interface)
  594. turn_off_second_powersequence = true;
  595. if (turn_off_second_powersequence) {
  596. /* Use second power sequence control: */
  597. /* Turn off power sequence. */
  598. viafb_write_reg_mask(CRD4, VIACR, 0, BIT1);
  599. /* Turn off back light. */
  600. viafb_write_reg_mask(CRD3, VIACR, 0xC0, BIT6 + BIT7);
  601. }
  602. if (turn_off_first_powersequence) {
  603. /* Use first power sequence control: */
  604. /* Turn off power sequence. */
  605. viafb_write_reg_mask(CR6A, VIACR, 0, BIT3);
  606. /* Turn off back light. */
  607. viafb_write_reg_mask(CR91, VIACR, 0xC0, BIT6 + BIT7);
  608. }
  609. /* Power off LVDS channel. */
  610. switch (plvds_chip_info->output_interface) {
  611. case INTERFACE_LVDS0:
  612. {
  613. viafb_write_reg_mask(CRD2, VIACR, 0x80, BIT7);
  614. break;
  615. }
  616. case INTERFACE_LVDS1:
  617. {
  618. viafb_write_reg_mask(CRD2, VIACR, 0x40, BIT6);
  619. break;
  620. }
  621. case INTERFACE_LVDS0LVDS1:
  622. {
  623. viafb_write_reg_mask(CRD2, VIACR, 0xC0, BIT6 + BIT7);
  624. break;
  625. }
  626. }
  627. }
  628. static void integrated_lvds_enable(struct lvds_setting_information
  629. *plvds_setting_info,
  630. struct lvds_chip_information *plvds_chip_info)
  631. {
  632. DEBUG_MSG(KERN_INFO "integrated_lvds_enable, out_interface:%d\n",
  633. plvds_chip_info->output_interface);
  634. if (plvds_setting_info->lcd_mode == LCD_SPWG)
  635. viafb_write_reg_mask(CRD2, VIACR, 0x00, BIT0 + BIT1);
  636. else
  637. viafb_write_reg_mask(CRD2, VIACR, 0x03, BIT0 + BIT1);
  638. switch (plvds_chip_info->output_interface) {
  639. case INTERFACE_LVDS0LVDS1:
  640. case INTERFACE_LVDS0:
  641. /* Use first power sequence control: */
  642. /* Use hardware control power sequence. */
  643. viafb_write_reg_mask(CR91, VIACR, 0, BIT0);
  644. /* Turn on back light. */
  645. viafb_write_reg_mask(CR91, VIACR, 0, BIT6 + BIT7);
  646. /* Turn on hardware power sequence. */
  647. viafb_write_reg_mask(CR6A, VIACR, 0x08, BIT3);
  648. break;
  649. case INTERFACE_LVDS1:
  650. /* Use second power sequence control: */
  651. /* Use hardware control power sequence. */
  652. viafb_write_reg_mask(CRD3, VIACR, 0, BIT0);
  653. /* Turn on back light. */
  654. viafb_write_reg_mask(CRD3, VIACR, 0, BIT6 + BIT7);
  655. /* Turn on hardware power sequence. */
  656. viafb_write_reg_mask(CRD4, VIACR, 0x02, BIT1);
  657. break;
  658. }
  659. /* Power on LVDS channel. */
  660. switch (plvds_chip_info->output_interface) {
  661. case INTERFACE_LVDS0:
  662. {
  663. viafb_write_reg_mask(CRD2, VIACR, 0, BIT7);
  664. break;
  665. }
  666. case INTERFACE_LVDS1:
  667. {
  668. viafb_write_reg_mask(CRD2, VIACR, 0, BIT6);
  669. break;
  670. }
  671. case INTERFACE_LVDS0LVDS1:
  672. {
  673. viafb_write_reg_mask(CRD2, VIACR, 0, BIT6 + BIT7);
  674. break;
  675. }
  676. }
  677. }
  678. void viafb_lcd_disable(void)
  679. {
  680. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266) {
  681. lcd_powersequence_off();
  682. /* DI1 pad off */
  683. viafb_write_reg_mask(SR1E, VIASR, 0x00, 0x30);
  684. } else if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700) {
  685. if (viafb_LCD2_ON
  686. && (INTEGRATED_LVDS ==
  687. viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name))
  688. integrated_lvds_disable(viaparinfo->lvds_setting_info,
  689. &viaparinfo->chip_info->lvds_chip_info2);
  690. if (INTEGRATED_LVDS ==
  691. viaparinfo->chip_info->lvds_chip_info.lvds_chip_name)
  692. integrated_lvds_disable(viaparinfo->lvds_setting_info,
  693. &viaparinfo->chip_info->lvds_chip_info);
  694. if (VT1636_LVDS == viaparinfo->chip_info->
  695. lvds_chip_info.lvds_chip_name)
  696. viafb_disable_lvds_vt1636(viaparinfo->lvds_setting_info,
  697. &viaparinfo->chip_info->lvds_chip_info);
  698. } else if (VT1636_LVDS ==
  699. viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
  700. viafb_disable_lvds_vt1636(viaparinfo->lvds_setting_info,
  701. &viaparinfo->chip_info->lvds_chip_info);
  702. } else {
  703. /* Backlight off */
  704. viafb_write_reg_mask(SR3D, VIASR, 0x00, 0x20);
  705. /* 24 bit DI data paht off */
  706. viafb_write_reg_mask(CR91, VIACR, 0x80, 0x80);
  707. }
  708. /* Disable expansion bit */
  709. viafb_write_reg_mask(CR79, VIACR, 0x00, 0x01);
  710. /* Simultaneout disabled */
  711. viafb_write_reg_mask(CR6B, VIACR, 0x00, 0x08);
  712. }
  713. static void set_lcd_output_path(int set_iga, int output_interface)
  714. {
  715. switch (output_interface) {
  716. case INTERFACE_DFP:
  717. if ((UNICHROME_K8M890 == viaparinfo->chip_info->gfx_chip_name)
  718. || (UNICHROME_P4M890 ==
  719. viaparinfo->chip_info->gfx_chip_name))
  720. viafb_write_reg_mask(CR97, VIACR, 0x84,
  721. BIT7 + BIT2 + BIT1 + BIT0);
  722. case INTERFACE_DVP0:
  723. case INTERFACE_DVP1:
  724. case INTERFACE_DFP_HIGH:
  725. case INTERFACE_DFP_LOW:
  726. if (set_iga == IGA2)
  727. viafb_write_reg(CR91, VIACR, 0x00);
  728. break;
  729. }
  730. }
  731. void viafb_lcd_enable(void)
  732. {
  733. viafb_write_reg_mask(CR6B, VIACR, 0x00, BIT3);
  734. viafb_write_reg_mask(CR6A, VIACR, 0x08, BIT3);
  735. set_lcd_output_path(viaparinfo->lvds_setting_info->iga_path,
  736. viaparinfo->chip_info->lvds_chip_info.output_interface);
  737. if (viafb_LCD2_ON)
  738. set_lcd_output_path(viaparinfo->lvds_setting_info2->iga_path,
  739. viaparinfo->chip_info->
  740. lvds_chip_info2.output_interface);
  741. if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266) {
  742. /* DI1 pad on */
  743. viafb_write_reg_mask(SR1E, VIASR, 0x30, 0x30);
  744. lcd_powersequence_on();
  745. } else if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700) {
  746. if (viafb_LCD2_ON && (INTEGRATED_LVDS ==
  747. viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name))
  748. integrated_lvds_enable(viaparinfo->lvds_setting_info2, \
  749. &viaparinfo->chip_info->lvds_chip_info2);
  750. if (INTEGRATED_LVDS ==
  751. viaparinfo->chip_info->lvds_chip_info.lvds_chip_name)
  752. integrated_lvds_enable(viaparinfo->lvds_setting_info,
  753. &viaparinfo->chip_info->lvds_chip_info);
  754. if (VT1636_LVDS == viaparinfo->chip_info->
  755. lvds_chip_info.lvds_chip_name)
  756. viafb_enable_lvds_vt1636(viaparinfo->
  757. lvds_setting_info, &viaparinfo->chip_info->
  758. lvds_chip_info);
  759. } else if (VT1636_LVDS ==
  760. viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
  761. viafb_enable_lvds_vt1636(viaparinfo->lvds_setting_info,
  762. &viaparinfo->chip_info->lvds_chip_info);
  763. } else {
  764. /* Backlight on */
  765. viafb_write_reg_mask(SR3D, VIASR, 0x20, 0x20);
  766. /* 24 bit DI data paht on */
  767. viafb_write_reg_mask(CR91, VIACR, 0x00, 0x80);
  768. /* LCD enabled */
  769. viafb_write_reg_mask(CR6A, VIACR, 0x48, 0x48);
  770. }
  771. }
  772. static void lcd_powersequence_off(void)
  773. {
  774. int i, mask, data;
  775. /* Software control power sequence */
  776. viafb_write_reg_mask(CR91, VIACR, 0x11, 0x11);
  777. for (i = 0; i < 3; i++) {
  778. mask = PowerSequenceOff[0][i];
  779. data = PowerSequenceOff[1][i] & mask;
  780. viafb_write_reg_mask(CR91, VIACR, (u8) data, (u8) mask);
  781. udelay(PowerSequenceOff[2][i]);
  782. }
  783. /* Disable LCD */
  784. viafb_write_reg_mask(CR6A, VIACR, 0x00, 0x08);
  785. }
  786. static void lcd_powersequence_on(void)
  787. {
  788. int i, mask, data;
  789. /* Software control power sequence */
  790. viafb_write_reg_mask(CR91, VIACR, 0x11, 0x11);
  791. /* Enable LCD */
  792. viafb_write_reg_mask(CR6A, VIACR, 0x08, 0x08);
  793. for (i = 0; i < 3; i++) {
  794. mask = PowerSequenceOn[0][i];
  795. data = PowerSequenceOn[1][i] & mask;
  796. viafb_write_reg_mask(CR91, VIACR, (u8) data, (u8) mask);
  797. udelay(PowerSequenceOn[2][i]);
  798. }
  799. udelay(1);
  800. }
  801. static void fill_lcd_format(void)
  802. {
  803. u8 bdithering = 0, bdual = 0;
  804. if (viaparinfo->lvds_setting_info->device_lcd_dualedge)
  805. bdual = BIT4;
  806. if (viaparinfo->lvds_setting_info->LCDDithering)
  807. bdithering = BIT0;
  808. /* Dual & Dithering */
  809. viafb_write_reg_mask(CR88, VIACR, (bdithering | bdual), BIT4 + BIT0);
  810. }
  811. static void check_diport_of_integrated_lvds(
  812. struct lvds_chip_information *plvds_chip_info,
  813. struct lvds_setting_information
  814. *plvds_setting_info)
  815. {
  816. /* Determine LCD DI Port by hardware layout. */
  817. switch (viafb_display_hardware_layout) {
  818. case HW_LAYOUT_LCD_ONLY:
  819. {
  820. if (plvds_setting_info->device_lcd_dualedge) {
  821. plvds_chip_info->output_interface =
  822. INTERFACE_LVDS0LVDS1;
  823. } else {
  824. plvds_chip_info->output_interface =
  825. INTERFACE_LVDS0;
  826. }
  827. break;
  828. }
  829. case HW_LAYOUT_DVI_ONLY:
  830. {
  831. plvds_chip_info->output_interface = INTERFACE_NONE;
  832. break;
  833. }
  834. case HW_LAYOUT_LCD1_LCD2:
  835. case HW_LAYOUT_LCD_EXTERNAL_LCD2:
  836. {
  837. plvds_chip_info->output_interface =
  838. INTERFACE_LVDS0LVDS1;
  839. break;
  840. }
  841. case HW_LAYOUT_LCD_DVI:
  842. {
  843. plvds_chip_info->output_interface = INTERFACE_LVDS1;
  844. break;
  845. }
  846. default:
  847. {
  848. plvds_chip_info->output_interface = INTERFACE_LVDS1;
  849. break;
  850. }
  851. }
  852. DEBUG_MSG(KERN_INFO
  853. "Display Hardware Layout: 0x%x, LCD DI Port: 0x%x\n",
  854. viafb_display_hardware_layout,
  855. plvds_chip_info->output_interface);
  856. }
  857. void __devinit viafb_init_lvds_output_interface(struct lvds_chip_information
  858. *plvds_chip_info,
  859. struct lvds_setting_information
  860. *plvds_setting_info)
  861. {
  862. if (INTERFACE_NONE != plvds_chip_info->output_interface) {
  863. /*Do nothing, lcd port is specified by module parameter */
  864. return;
  865. }
  866. switch (plvds_chip_info->lvds_chip_name) {
  867. case VT1636_LVDS:
  868. switch (viaparinfo->chip_info->gfx_chip_name) {
  869. case UNICHROME_CX700:
  870. plvds_chip_info->output_interface = INTERFACE_DVP1;
  871. break;
  872. case UNICHROME_CN700:
  873. plvds_chip_info->output_interface = INTERFACE_DFP_LOW;
  874. break;
  875. default:
  876. plvds_chip_info->output_interface = INTERFACE_DVP0;
  877. break;
  878. }
  879. break;
  880. case INTEGRATED_LVDS:
  881. check_diport_of_integrated_lvds(plvds_chip_info,
  882. plvds_setting_info);
  883. break;
  884. default:
  885. switch (viaparinfo->chip_info->gfx_chip_name) {
  886. case UNICHROME_K8M890:
  887. case UNICHROME_P4M900:
  888. case UNICHROME_P4M890:
  889. plvds_chip_info->output_interface = INTERFACE_DFP_LOW;
  890. break;
  891. default:
  892. plvds_chip_info->output_interface = INTERFACE_DFP;
  893. break;
  894. }
  895. break;
  896. }
  897. }
  898. static struct display_timing lcd_centering_timging(struct display_timing
  899. mode_crt_reg,
  900. struct display_timing panel_crt_reg)
  901. {
  902. struct display_timing crt_reg;
  903. crt_reg.hor_total = panel_crt_reg.hor_total;
  904. crt_reg.hor_addr = mode_crt_reg.hor_addr;
  905. crt_reg.hor_blank_start =
  906. (panel_crt_reg.hor_addr - mode_crt_reg.hor_addr) / 2 +
  907. crt_reg.hor_addr;
  908. crt_reg.hor_blank_end = panel_crt_reg.hor_blank_end;
  909. crt_reg.hor_sync_start =
  910. (panel_crt_reg.hor_sync_start -
  911. panel_crt_reg.hor_blank_start) + crt_reg.hor_blank_start;
  912. crt_reg.hor_sync_end = panel_crt_reg.hor_sync_end;
  913. crt_reg.ver_total = panel_crt_reg.ver_total;
  914. crt_reg.ver_addr = mode_crt_reg.ver_addr;
  915. crt_reg.ver_blank_start =
  916. (panel_crt_reg.ver_addr - mode_crt_reg.ver_addr) / 2 +
  917. crt_reg.ver_addr;
  918. crt_reg.ver_blank_end = panel_crt_reg.ver_blank_end;
  919. crt_reg.ver_sync_start =
  920. (panel_crt_reg.ver_sync_start -
  921. panel_crt_reg.ver_blank_start) + crt_reg.ver_blank_start;
  922. crt_reg.ver_sync_end = panel_crt_reg.ver_sync_end;
  923. return crt_reg;
  924. }
  925. bool viafb_lcd_get_mobile_state(bool *mobile)
  926. {
  927. unsigned char __iomem *romptr, *tableptr, *biosptr;
  928. u8 core_base;
  929. /* Rom address */
  930. const u32 romaddr = 0x000C0000;
  931. u16 start_pattern;
  932. biosptr = ioremap(romaddr, 0x10000);
  933. start_pattern = readw(biosptr);
  934. /* Compare pattern */
  935. if (start_pattern == 0xAA55) {
  936. /* Get the start of Table */
  937. /* 0x1B means BIOS offset position */
  938. romptr = biosptr + 0x1B;
  939. tableptr = biosptr + readw(romptr);
  940. /* Get the start of biosver structure */
  941. /* 18 means BIOS version position. */
  942. romptr = tableptr + 18;
  943. romptr = biosptr + readw(romptr);
  944. /* The offset should be 44, but the
  945. actual image is less three char. */
  946. /* pRom += 44; */
  947. romptr += 41;
  948. core_base = readb(romptr);
  949. if (core_base & 0x8)
  950. *mobile = false;
  951. else
  952. *mobile = true;
  953. /* release memory */
  954. iounmap(biosptr);
  955. return true;
  956. } else {
  957. iounmap(biosptr);
  958. return false;
  959. }
  960. }