ct69000.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  1. /* ported from ctfb.c (linux kernel):
  2. * Created in Jan - July 2000 by Thomas Höhenleitner <th@visuelle-maschinen.de>
  3. *
  4. * Ported to U-Boot:
  5. * (C) Copyright 2002 Denis Peter, MPL AG Switzerland
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #ifdef CONFIG_VIDEO
  11. #include <pci.h>
  12. #include <video_fb.h>
  13. #include "videomodes.h"
  14. /* debug */
  15. #undef VGA_DEBUG
  16. #undef VGA_DUMP_REG
  17. #ifdef VGA_DEBUG
  18. #undef _DEBUG
  19. #define _DEBUG 1
  20. #else
  21. #undef _DEBUG
  22. #define _DEBUG 0
  23. #endif
  24. /* Macros */
  25. #ifndef min
  26. #define min( a, b ) ( ( a ) < ( b ) ) ? ( a ) : ( b )
  27. #endif
  28. #ifndef max
  29. #define max( a, b ) ( ( a ) > ( b ) ) ? ( a ) : ( b )
  30. #endif
  31. #ifdef minmax
  32. #error "term minmax already used."
  33. #endif
  34. #define minmax( a, x, b ) max( ( a ), min( ( x ), ( b ) ) )
  35. #define N_ELTS( x ) ( sizeof( x ) / sizeof( x[ 0 ] ) )
  36. /* CT Register Offsets */
  37. #define CT_AR_O 0x3c0 /* Index and Data write port of the attribute Registers */
  38. #define CT_GR_O 0x3ce /* Index port of the Graphic Controller Registers */
  39. #define CT_SR_O 0x3c4 /* Index port of the Sequencer Controller */
  40. #define CT_CR_O 0x3d4 /* Index port of the CRT Controller */
  41. #define CT_XR_O 0x3d6 /* Extended Register index */
  42. #define CT_MSR_W_O 0x3c2 /* Misc. Output Register (write only) */
  43. #define CT_LUT_MASK_O 0x3c6 /* Color Palette Mask */
  44. #define CT_LUT_START_O 0x3c8 /* Color Palette Write Mode Index */
  45. #define CT_LUT_RGB_O 0x3c9 /* Color Palette Data Port */
  46. #define CT_STATUS_REG0_O 0x3c2 /* Status Register 0 (read only) */
  47. #define CT_STATUS_REG1_O 0x3da /* Input Status Register 1 (read only) */
  48. #define CT_FP_O 0x3d0 /* Index port of the Flat panel Registers */
  49. #define CT_MR_O 0x3d2 /* Index Port of the Multimedia Extension */
  50. /* defines for the memory mapped registers */
  51. #define BR00_o 0x400000 /* Source and Destination Span Register */
  52. #define BR01_o 0x400004 /* Pattern/Source Expansion Background Color & Transparency Key Register */
  53. #define BR02_o 0x400008 /* Pattern/Source Expansion Foreground Color Register */
  54. #define BR03_o 0x40000C /* Monochrome Source Control Register */
  55. #define BR04_o 0x400010 /* BitBLT Control Register */
  56. #define BR05_o 0x400014 /* Pattern Address Registe */
  57. #define BR06_o 0x400018 /* Source Address Register */
  58. #define BR07_o 0x40001C /* Destination Address Register */
  59. #define BR08_o 0x400020 /* Destination Width & Height Register */
  60. #define BR09_o 0x400024 /* Source Expansion Background Color & Transparency Key Register */
  61. #define BR0A_o 0x400028 /* Source Expansion Foreground Color Register */
  62. #define CURSOR_SIZE 0x1000 /* in KByte for HW Cursor */
  63. #define PATTERN_ADR (pGD->dprBase + CURSOR_SIZE) /* pattern Memory after Cursor Memory */
  64. #define PATTERN_SIZE 8*8*4 /* 4 Bytes per Pixel 8 x 8 Pixel */
  65. #define ACCELMEMORY (CURSOR_SIZE + PATTERN_SIZE) /* reserved Memory for BITBlt and hw cursor */
  66. /* Some Mode definitions */
  67. #define FB_SYNC_HOR_HIGH_ACT 1 /* horizontal sync high active */
  68. #define FB_SYNC_VERT_HIGH_ACT 2 /* vertical sync high active */
  69. #define FB_SYNC_EXT 4 /* external sync */
  70. #define FB_SYNC_COMP_HIGH_ACT 8 /* composite sync high active */
  71. #define FB_SYNC_BROADCAST 16 /* broadcast video timings */
  72. /* vtotal = 144d/288n/576i => PAL */
  73. /* vtotal = 121d/242n/484i => NTSC */
  74. #define FB_SYNC_ON_GREEN 32 /* sync on green */
  75. #define FB_VMODE_NONINTERLACED 0 /* non interlaced */
  76. #define FB_VMODE_INTERLACED 1 /* interlaced */
  77. #define FB_VMODE_DOUBLE 2 /* double scan */
  78. #define FB_VMODE_MASK 255
  79. #define FB_VMODE_YWRAP 256 /* ywrap instead of panning */
  80. #define FB_VMODE_SMOOTH_XPAN 512 /* smooth xpan possible (internally used) */
  81. #define FB_VMODE_CONUPDATE 512 /* don't update x/yoffset */
  82. #define text 0
  83. #define fntwidth 8
  84. /* table for VGA Initialization */
  85. typedef struct {
  86. const unsigned char reg;
  87. const unsigned char val;
  88. } CT_CFG_TABLE;
  89. /* this table provides some basic initialisations such as Memory Clock etc */
  90. static CT_CFG_TABLE xreg[] = {
  91. {0x09, 0x01}, /* CRT Controller Extensions Enable */
  92. {0x0A, 0x02}, /* Frame Buffer Mapping */
  93. {0x0B, 0x01}, /* PCI Write Burst support */
  94. {0x20, 0x00}, /* BitBLT Configuration */
  95. {0x40, 0x03}, /* Memory Access Control */
  96. {0x60, 0x00}, /* Video Pin Control */
  97. {0x61, 0x00}, /* DPMS Synch control */
  98. {0x62, 0x00}, /* GPIO Pin Control */
  99. {0x63, 0xBD}, /* GPIO Pin Data */
  100. {0x67, 0x00}, /* Pin Tri-State */
  101. {0x80, 0x80}, /* Pixel Pipeline Config 0 register */
  102. {0xA0, 0x00}, /* Cursor 1 Control Reg */
  103. {0xA1, 0x00}, /* Cursor 1 Vertical Extension Reg */
  104. {0xA2, 0x00}, /* Cursor 1 Base Address Low */
  105. {0xA3, 0x00}, /* Cursor 1 Base Address High */
  106. {0xA4, 0x00}, /* Cursor 1 X-Position Low */
  107. {0xA5, 0x00}, /* Cursor 1 X-Position High */
  108. {0xA6, 0x00}, /* Cursor 1 Y-Position Low */
  109. {0xA7, 0x00}, /* Cursor 1 Y-Position High */
  110. {0xA8, 0x00}, /* Cursor 2 Control Reg */
  111. {0xA9, 0x00}, /* Cursor 2 Vertical Extension Reg */
  112. {0xAA, 0x00}, /* Cursor 2 Base Address Low */
  113. {0xAB, 0x00}, /* Cursor 2 Base Address High */
  114. {0xAC, 0x00}, /* Cursor 2 X-Position Low */
  115. {0xAD, 0x00}, /* Cursor 2 X-Position High */
  116. {0xAE, 0x00}, /* Cursor 2 Y-Position Low */
  117. {0xAF, 0x00}, /* Cursor 2 Y-Position High */
  118. {0xC0, 0x7D}, /* Dot Clock 0 VCO M-Divisor */
  119. {0xC1, 0x07}, /* Dot Clock 0 VCO N-Divisor */
  120. {0xC3, 0x34}, /* Dot Clock 0 Divisor select */
  121. {0xC4, 0x55}, /* Dot Clock 1 VCO M-Divisor */
  122. {0xC5, 0x09}, /* Dot Clock 1 VCO N-Divisor */
  123. {0xC7, 0x24}, /* Dot Clock 1 Divisor select */
  124. {0xC8, 0x7D}, /* Dot Clock 2 VCO M-Divisor */
  125. {0xC9, 0x07}, /* Dot Clock 2 VCO N-Divisor */
  126. {0xCB, 0x34}, /* Dot Clock 2 Divisor select */
  127. {0xCC, 0x38}, /* Memory Clock 0 VCO M-Divisor */
  128. {0xCD, 0x03}, /* Memory Clock 0 VCO N-Divisor */
  129. {0xCE, 0x90}, /* Memory Clock 0 Divisor select */
  130. {0xCF, 0x06}, /* Clock Config */
  131. {0xD0, 0x0F}, /* Power Down */
  132. {0xD1, 0x01}, /* Power Down BitBLT */
  133. {0xFF, 0xFF} /* end of table */
  134. };
  135. /* Clock Config:
  136. * =============
  137. *
  138. * PD Registers:
  139. * -------------
  140. * Bit2 and Bit4..6 are used for the Loop Divisor and Post Divisor.
  141. * They are encoded as follows:
  142. *
  143. * +---+--------------+
  144. * | 2 | Loop Divisor |
  145. * +---+--------------+
  146. * | 1 | 1 |
  147. * +---+--------------+
  148. * | 0 | 4 |
  149. * +---+--------------+
  150. * Note: The Memory Clock does not have a Loop Divisor.
  151. * +---+---+---+--------------+
  152. * | 6 | 5 | 4 | Post Divisor |
  153. * +---+---+---+--------------+
  154. * | 0 | 0 | 0 | 1 |
  155. * +---+---+---+--------------+
  156. * | 0 | 0 | 1 | 2 |
  157. * +---+---+---+--------------+
  158. * | 0 | 1 | 0 | 4 |
  159. * +---+---+---+--------------+
  160. * | 0 | 1 | 1 | 8 |
  161. * +---+---+---+--------------+
  162. * | 1 | 0 | 0 | 16 |
  163. * +---+---+---+--------------+
  164. * | 1 | 0 | 1 | 32 |
  165. * +---+---+---+--------------+
  166. * | 1 | 1 | X | reserved |
  167. * +---+---+---+--------------+
  168. *
  169. * All other bits are reserved in these registers.
  170. *
  171. * Clock VCO M Registers:
  172. * ----------------------
  173. * These Registers contain the M Value -2.
  174. *
  175. * Clock VCO N Registers:
  176. * ----------------------
  177. * These Registers contain the N Value -2.
  178. *
  179. * Formulas:
  180. * ---------
  181. * Fvco = (Fref * Loop Divisor * M/N), whereas 100MHz < Fvco < 220MHz
  182. * Fout = Fvco / Post Divisor
  183. *
  184. * Dot Clk0 (default 25MHz):
  185. * -------------------------
  186. * Fvco = 14.318 * 127 / 9 = 202.045MHz
  187. * Fout = 202.045MHz / 8 = 25.25MHz
  188. * Post Divisor = 8
  189. * Loop Divisor = 1
  190. * XRC0 = (M - 2) = 125 = 0x7D
  191. * XRC1 = (N - 2) = 7 = 0x07
  192. * XRC3 = 0x34
  193. *
  194. * Dot Clk1 (default 28MHz):
  195. * -------------------------
  196. * Fvco = 14.318 * 87 / 11 = 113.24MHz
  197. * Fout = 113.24MHz / 4 = 28.31MHz
  198. * Post Divisor = 4
  199. * Loop Divisor = 1
  200. * XRC4 = (M - 2) = 85 = 0x55
  201. * XRC5 = (N - 2) = 9 = 0x09
  202. * XRC7 = 0x24
  203. *
  204. * Dot Clk2 (variable for extended modes set to 25MHz):
  205. * ----------------------------------------------------
  206. * Fvco = 14.318 * 127 / 9 = 202.045MHz
  207. * Fout = 202.045MHz / 8 = 25.25MHz
  208. * Post Divisor = 8
  209. * Loop Divisor = 1
  210. * XRC8 = (M - 2) = 125 = 0x7D
  211. * XRC9 = (N - 2) = 7 = 0x07
  212. * XRCB = 0x34
  213. *
  214. * Memory Clk for most modes >50MHz:
  215. * ----------------------------------
  216. * Fvco = 14.318 * 58 / 5 = 166MHz
  217. * Fout = 166MHz / 2 = 83MHz
  218. * Post Divisor = 2
  219. * XRCC = (M - 2) = 57 = 0x38
  220. * XRCD = (N - 2) = 3 = 0x03
  221. * XRCE = 0x90
  222. *
  223. * Note Bit7 enables the clock source from the VCO
  224. *
  225. */
  226. /*******************************************************************
  227. * Chips struct
  228. *******************************************************************/
  229. struct ctfb_chips_properties {
  230. int device_id; /* PCI Device ID */
  231. unsigned long max_mem; /* memory for frame buffer */
  232. int vld_set; /* value of VLD if bit2 in clock control is set */
  233. int vld_not_set; /* value of VLD if bit2 in clock control is set */
  234. int mn_diff; /* difference between M/N Value + mn_diff = M/N Register */
  235. int mn_min; /* min value of M/N Value */
  236. int mn_max; /* max value of M/N Value */
  237. int vco_min; /* VCO Min in MHz */
  238. int vco_max; /* VCO Max in MHz */
  239. };
  240. static const struct ctfb_chips_properties chips[] = {
  241. {PCI_DEVICE_ID_CT_69000, 0x200000, 1, 4, -2, 3, 257, 100, 220},
  242. {PCI_DEVICE_ID_CT_65555, 0x100000, 16, 4, 0, 1, 255, 48, 220}, /* NOT TESTED */
  243. {0, 0, 0, 0, 0, 0, 0, 0, 0} /* Terminator */
  244. };
  245. /*
  246. * The Graphic Device
  247. */
  248. GraphicDevice ctfb;
  249. /*******************************************************************************
  250. *
  251. * Low Level Routines
  252. */
  253. /*******************************************************************************
  254. *
  255. * Read CT ISA register
  256. */
  257. #ifdef VGA_DEBUG
  258. static unsigned char
  259. ctRead (unsigned short index)
  260. {
  261. GraphicDevice *pGD = (GraphicDevice *) & ctfb;
  262. if (index == CT_AR_O)
  263. /* synch the Flip Flop */
  264. in8 (pGD->isaBase + CT_STATUS_REG1_O);
  265. return (in8 (pGD->isaBase + index));
  266. }
  267. #endif
  268. /*******************************************************************************
  269. *
  270. * Write CT ISA register
  271. */
  272. static void
  273. ctWrite (unsigned short index, unsigned char val)
  274. {
  275. GraphicDevice *pGD = (GraphicDevice *) & ctfb;
  276. out8 ((pGD->isaBase + index), val);
  277. }
  278. /*******************************************************************************
  279. *
  280. * Read CT ISA register indexed
  281. */
  282. static unsigned char
  283. ctRead_i (unsigned short index, char reg)
  284. {
  285. GraphicDevice *pGD = (GraphicDevice *) & ctfb;
  286. if (index == CT_AR_O)
  287. /* synch the Flip Flop */
  288. in8 (pGD->isaBase + CT_STATUS_REG1_O);
  289. out8 ((pGD->isaBase + index), reg);
  290. return (in8 (pGD->isaBase + index + 1));
  291. }
  292. /*******************************************************************************
  293. *
  294. * Write CT ISA register indexed
  295. */
  296. static void
  297. ctWrite_i (unsigned short index, char reg, char val)
  298. {
  299. GraphicDevice *pGD = (GraphicDevice *) & ctfb;
  300. if (index == CT_AR_O) {
  301. /* synch the Flip Flop */
  302. in8 (pGD->isaBase + CT_STATUS_REG1_O);
  303. out8 ((pGD->isaBase + index), reg);
  304. out8 ((pGD->isaBase + index), val);
  305. } else {
  306. out8 ((pGD->isaBase + index), reg);
  307. out8 ((pGD->isaBase + index + 1), val);
  308. }
  309. }
  310. /*******************************************************************************
  311. *
  312. * Write a table of CT ISA register
  313. */
  314. static void
  315. ctLoadRegs (unsigned short index, CT_CFG_TABLE * regTab)
  316. {
  317. while (regTab->reg != 0xFF) {
  318. ctWrite_i (index, regTab->reg, regTab->val);
  319. regTab++;
  320. }
  321. }
  322. /*****************************************************************************/
  323. static void
  324. SetArRegs (void)
  325. {
  326. int i, tmp;
  327. for (i = 0; i < 0x10; i++)
  328. ctWrite_i (CT_AR_O, i, i);
  329. if (text)
  330. tmp = 0x04;
  331. else
  332. tmp = 0x41;
  333. ctWrite_i (CT_AR_O, 0x10, tmp); /* Mode Control Register */
  334. ctWrite_i (CT_AR_O, 0x11, 0x00); /* Overscan Color Register */
  335. ctWrite_i (CT_AR_O, 0x12, 0x0f); /* Memory Plane Enable Register */
  336. if (fntwidth == 9)
  337. tmp = 0x08;
  338. else
  339. tmp = 0x00;
  340. ctWrite_i (CT_AR_O, 0x13, tmp); /* Horizontal Pixel Panning */
  341. ctWrite_i (CT_AR_O, 0x14, 0x00); /* Color Select Register */
  342. ctWrite (CT_AR_O, 0x20); /* enable video */
  343. }
  344. /*****************************************************************************/
  345. static void
  346. SetGrRegs (void)
  347. { /* Set Graphics Mode */
  348. int i;
  349. for (i = 0; i < 0x05; i++)
  350. ctWrite_i (CT_GR_O, i, 0);
  351. if (text) {
  352. ctWrite_i (CT_GR_O, 0x05, 0x10);
  353. ctWrite_i (CT_GR_O, 0x06, 0x02);
  354. } else {
  355. ctWrite_i (CT_GR_O, 0x05, 0x40);
  356. ctWrite_i (CT_GR_O, 0x06, 0x05);
  357. }
  358. ctWrite_i (CT_GR_O, 0x07, 0x0f);
  359. ctWrite_i (CT_GR_O, 0x08, 0xff);
  360. }
  361. /*****************************************************************************/
  362. static void
  363. SetSrRegs (void)
  364. {
  365. int tmp = 0;
  366. ctWrite_i (CT_SR_O, 0x00, 0x00); /* reset */
  367. /*rr( sr, 0x01, tmp );
  368. if( fntwidth == 8 ) tmp |= 0x01; else tmp &= ~0x01;
  369. wr( sr, 0x01, tmp ); */
  370. if (fntwidth == 8)
  371. ctWrite_i (CT_SR_O, 0x01, 0x01); /* Clocking Mode Register */
  372. else
  373. ctWrite_i (CT_SR_O, 0x01, 0x00); /* Clocking Mode Register */
  374. ctWrite_i (CT_SR_O, 0x02, 0x0f); /* Enable CPU wr access to given memory plane */
  375. ctWrite_i (CT_SR_O, 0x03, 0x00); /* Character Map Select Register */
  376. if (text)
  377. tmp = 0x02;
  378. else
  379. tmp = 0x0e;
  380. ctWrite_i (CT_SR_O, 0x04, tmp); /* Enable CPU accesses to the rest of the 256KB
  381. total VGA memory beyond the first 64KB and set
  382. fb mapping mode. */
  383. ctWrite_i (CT_SR_O, 0x00, 0x03); /* enable */
  384. }
  385. /*****************************************************************************/
  386. static void
  387. SetBitsPerPixelIntoXrRegs (int bpp)
  388. {
  389. unsigned int n = (bpp >> 3), tmp; /* only for 15, 8, 16, 24 bpp */
  390. static char md[4] = { 0x04, 0x02, 0x05, 0x06 }; /* DisplayColorMode */
  391. static char off[4] = { ~0x20, ~0x30, ~0x20, ~0x10 }; /* mask */
  392. static char on[4] = { 0x10, 0x00, 0x10, 0x20 }; /* mask */
  393. if (bpp == 15)
  394. n = 0;
  395. tmp = ctRead_i (CT_XR_O, 0x20);
  396. tmp &= off[n];
  397. tmp |= on[n];
  398. ctWrite_i (CT_XR_O, 0x20, tmp); /* BitBLT Configuration */
  399. ctWrite_i (CT_XR_O, 0x81, md[n]);
  400. }
  401. /*****************************************************************************/
  402. static void
  403. SetCrRegs (struct ctfb_res_modes *var, int bits_per_pixel)
  404. { /* he -le- ht|0 hd -ri- hs -h- he */
  405. unsigned char cr[0x7a];
  406. int i, tmp;
  407. unsigned int hd, hs, he, ht, hbe; /* Horizontal. */
  408. unsigned int vd, vs, ve, vt; /* vertical */
  409. unsigned int bpp, wd, dblscan, interlaced, bcast, CrtHalfLine;
  410. unsigned int CompSyncCharClkDelay, CompSyncPixelClkDelay;
  411. unsigned int NTSC_PAL_HorizontalPulseWidth, BlDelayCtrl;
  412. unsigned int HorizontalEqualizationPulses;
  413. unsigned int HorizontalSerration1Start, HorizontalSerration2Start;
  414. const int LineCompare = 0x3ff;
  415. unsigned int TextScanLines = 1; /* this is in fact a vertical zoom factor */
  416. unsigned int RAMDAC_BlankPedestalEnable = 0; /* 1=en-, 0=disable, see XR82 */
  417. hd = (var->xres) / 8; /* HDisp. */
  418. hs = (var->xres + var->right_margin) / 8; /* HsStrt */
  419. he = (var->xres + var->right_margin + var->hsync_len) / 8; /* HsEnd */
  420. ht = (var->left_margin + var->xres + var->right_margin + var->hsync_len) / 8; /* HTotal */
  421. hbe = ht - 1; /* HBlankEnable todo docu wants ht here, but it does not work */
  422. /* ve -up- vt|0 vd -lo- vs -v- ve */
  423. vd = var->yres; /* VDisplay */
  424. vs = var->yres + var->lower_margin; /* VSyncStart */
  425. ve = var->yres + var->lower_margin + var->vsync_len; /* VSyncEnd */
  426. vt = var->upper_margin + var->yres + var->lower_margin + var->vsync_len; /* VTotal */
  427. bpp = bits_per_pixel;
  428. dblscan = (var->vmode & FB_VMODE_DOUBLE) ? 1 : 0;
  429. interlaced = var->vmode & FB_VMODE_INTERLACED;
  430. bcast = var->sync & FB_SYNC_BROADCAST;
  431. CrtHalfLine = bcast ? (hd >> 1) : 0;
  432. BlDelayCtrl = bcast ? 1 : 0;
  433. CompSyncCharClkDelay = 0; /* 2 bit */
  434. CompSyncPixelClkDelay = 0; /* 3 bit */
  435. if (bcast) {
  436. NTSC_PAL_HorizontalPulseWidth = 7; /*( var->hsync_len >> 1 ) + 1 */
  437. HorizontalEqualizationPulses = 0; /* inverse value */
  438. HorizontalSerration1Start = 31; /* ( ht >> 1 ) */
  439. HorizontalSerration2Start = 89; /* ( ht >> 1 ) */
  440. } else {
  441. NTSC_PAL_HorizontalPulseWidth = 0;
  442. /* 4 bit: hsync pulse width = ( ( CR74[4:0] - CR74[5] )
  443. * / 2 ) + 1 --> CR74[4:0] = 2*(hs-1) + CR74[5] */
  444. HorizontalEqualizationPulses = 1; /* inverse value */
  445. HorizontalSerration1Start = 0; /* ( ht >> 1 ) */
  446. HorizontalSerration2Start = 0; /* ( ht >> 1 ) */
  447. }
  448. if (bpp == 15)
  449. bpp = 16;
  450. wd = var->xres * bpp / 64; /* double words per line */
  451. if (interlaced) { /* we divide all vertical timings, exept vd */
  452. vs >>= 1;
  453. ve >>= 1;
  454. vt >>= 1;
  455. }
  456. memset (cr, 0, sizeof (cr));
  457. cr[0x00] = 0xff & (ht - 5);
  458. cr[0x01] = hd - 1; /* soll:4f ist 59 */
  459. cr[0x02] = hd;
  460. cr[0x03] = (hbe & 0x1F) | 0x80; /* hd + ht - hd */
  461. cr[0x04] = hs;
  462. cr[0x05] = ((hbe & 0x20) << 2) | (he & 0x1f);
  463. cr[0x06] = (vt - 2) & 0xFF;
  464. cr[0x30] = (vt - 2) >> 8;
  465. cr[0x07] = ((vt & 0x100) >> 8)
  466. | ((vd & 0x100) >> 7)
  467. | ((vs & 0x100) >> 6)
  468. | ((vs & 0x100) >> 5)
  469. | ((LineCompare & 0x100) >> 4)
  470. | ((vt & 0x200) >> 4)
  471. | ((vd & 0x200) >> 3)
  472. | ((vs & 0x200) >> 2);
  473. cr[0x08] = 0x00;
  474. cr[0x09] = (dblscan << 7)
  475. | ((LineCompare & 0x200) >> 3)
  476. | ((vs & 0x200) >> 4)
  477. | (TextScanLines - 1);
  478. cr[0x10] = vs & 0xff; /* VSyncPulseStart */
  479. cr[0x32] = (vs & 0xf00) >> 8; /* VSyncPulseStart */
  480. cr[0x11] = (ve & 0x0f); /* | 0x20; */
  481. cr[0x12] = (vd - 1) & 0xff; /* LineCount */
  482. cr[0x31] = ((vd - 1) & 0xf00) >> 8; /* LineCount */
  483. cr[0x13] = wd & 0xff;
  484. cr[0x41] = (wd & 0xf00) >> 8;
  485. cr[0x15] = vs & 0xff;
  486. cr[0x33] = (vs & 0xf00) >> 8;
  487. cr[0x38] = (0x100 & (ht - 5)) >> 8;
  488. cr[0x3C] = 0xc0 & hbe;
  489. cr[0x16] = (vt - 1) & 0xff; /* vbe - docu wants vt here, */
  490. cr[0x17] = 0xe3; /* but it does not work */
  491. cr[0x18] = 0xff & LineCompare;
  492. cr[0x22] = 0xff; /* todo? */
  493. cr[0x70] = interlaced ? (0x80 | CrtHalfLine) : 0x00; /* check:0xa6 */
  494. cr[0x71] = 0x80 | (RAMDAC_BlankPedestalEnable << 6)
  495. | (BlDelayCtrl << 5)
  496. | ((0x03 & CompSyncCharClkDelay) << 3)
  497. | (0x07 & CompSyncPixelClkDelay); /* todo: see XR82 */
  498. cr[0x72] = HorizontalSerration1Start;
  499. cr[0x73] = HorizontalSerration2Start;
  500. cr[0x74] = (HorizontalEqualizationPulses << 5)
  501. | NTSC_PAL_HorizontalPulseWidth;
  502. /* todo: ct69000 has also 0x75-79 */
  503. /* now set the registers */
  504. for (i = 0; i <= 0x0d; i++) { /*CR00 .. CR0D */
  505. ctWrite_i (CT_CR_O, i, cr[i]);
  506. }
  507. for (i = 0x10; i <= 0x18; i++) { /*CR10 .. CR18 */
  508. ctWrite_i (CT_CR_O, i, cr[i]);
  509. }
  510. i = 0x22; /*CR22 */
  511. ctWrite_i (CT_CR_O, i, cr[i]);
  512. for (i = 0x30; i <= 0x33; i++) { /*CR30 .. CR33 */
  513. ctWrite_i (CT_CR_O, i, cr[i]);
  514. }
  515. i = 0x38; /*CR38 */
  516. ctWrite_i (CT_CR_O, i, cr[i]);
  517. i = 0x3C; /*CR3C */
  518. ctWrite_i (CT_CR_O, i, cr[i]);
  519. for (i = 0x40; i <= 0x41; i++) { /*CR40 .. CR41 */
  520. ctWrite_i (CT_CR_O, i, cr[i]);
  521. }
  522. for (i = 0x70; i <= 0x74; i++) { /*CR70 .. CR74 */
  523. ctWrite_i (CT_CR_O, i, cr[i]);
  524. }
  525. tmp = ctRead_i (CT_CR_O, 0x40);
  526. tmp &= 0x0f;
  527. tmp |= 0x80;
  528. ctWrite_i (CT_CR_O, 0x40, tmp); /* StartAddressEnable */
  529. }
  530. /* pixelclock control */
  531. /*****************************************************************************
  532. We have a rational number p/q and need an m/n which is very close to p/q
  533. but has m and n within mnmin and mnmax. We have no floating point in the
  534. kernel. We can use long long without divide. And we have time to compute...
  535. ******************************************************************************/
  536. static unsigned int
  537. FindBestPQFittingMN (unsigned int p, unsigned int q, unsigned int mnmin,
  538. unsigned int mnmax, unsigned int *pm, unsigned int *pn)
  539. {
  540. /* this code is not for general purpose usable but good for our number ranges */
  541. unsigned int n = mnmin, m = 0;
  542. long long int L = 0, P = p, Q = q, H = P >> 1;
  543. long long int D = 0x7ffffffffffffffLL;
  544. for (n = mnmin; n <= mnmax; n++) {
  545. m = mnmin; /* p/q ~ m/n -> p*n ~ m*q -> p*n-x*q ~ 0 */
  546. L = P * n - m * Q; /* n * vco - m * fref should be near 0 */
  547. while (L > 0 && m < mnmax) {
  548. L -= q; /* difference is greater as 0 subtract fref */
  549. m++; /* and increment m */
  550. }
  551. /* difference is less or equal than 0 or m > maximum */
  552. if (m > mnmax)
  553. break; /* no solution: if we increase n we get the same situation */
  554. /* L is <= 0 now */
  555. if (-L > H && m > mnmin) { /* if difference > the half fref */
  556. L += q; /* we take the situation before */
  557. m--; /* because its closer to 0 */
  558. }
  559. L = (L < 0) ? -L : +L; /* absolute value */
  560. if (D < L) /* if last difference was better take next n */
  561. continue;
  562. D = L;
  563. *pm = m;
  564. *pn = n; /* keep improved data */
  565. if (D == 0)
  566. break; /* best result we can get */
  567. }
  568. return (unsigned int) (0xffffffff & D);
  569. }
  570. /* that is the hardware < 69000 we have to manage
  571. +---------+ +-------------------+ +----------------------+ +--+
  572. | REFCLK |__|NTSC Divisor Select|__|FVCO Reference Divisor|__|÷N|__
  573. | 14.3MHz | |(NTSCDS) (÷1, ÷5) | |Select (RDS) (÷1, ÷4) | | | |
  574. +---------+ +-------------------+ +----------------------+ +--+ |
  575. ___________________________________________________________________|
  576. |
  577. | fvco fout
  578. | +--------+ +------------+ +-----+ +-------------------+ +----+
  579. +-| Phase |__|Charge Pump |__| VCO |_____|Post Divisor (PD) |___|CLK |--->
  580. +-| Detect | |& Filter VCO| | | | |÷1, 2, 4, 8, 16, 32| | |
  581. | +--------+ +------------+ +-----+ | +-------------------+ +----+
  582. | |
  583. | +--+ +---------------+ |
  584. |____|÷M|___|VCO Loop Divide|__________|
  585. | | |(VLD)(÷4, ÷16) |
  586. +--+ +---------------+
  587. ****************************************************************************
  588. that is the hardware >= 69000 we have to manage
  589. +---------+ +--+
  590. | REFCLK |__|÷N|__
  591. | 14.3MHz | | | |
  592. +---------+ +--+ |
  593. __________________|
  594. |
  595. | fvco fout
  596. | +--------+ +------------+ +-----+ +-------------------+ +----+
  597. +-| Phase |__|Charge Pump |__| VCO |_____|Post Divisor (PD) |___|CLK |--->
  598. +-| Detect | |& Filter VCO| | | | |÷1, 2, 4, 8, 16, 32| | |
  599. | +--------+ +------------+ +-----+ | +-------------------+ +----+
  600. | |
  601. | +--+ +---------------+ |
  602. |____|÷M|___|VCO Loop Divide|__________|
  603. | | |(VLD)(÷1, ÷4) |
  604. +--+ +---------------+
  605. */
  606. #define VIDEO_FREF 14318180; /* Hz */
  607. /*****************************************************************************/
  608. static int
  609. ReadPixClckFromXrRegsBack (struct ctfb_chips_properties *param)
  610. {
  611. unsigned int m, n, vld, pd, PD, fref, xr_cb, i, pixclock;
  612. i = 0;
  613. pixclock = -1;
  614. fref = VIDEO_FREF;
  615. m = ctRead_i (CT_XR_O, 0xc8);
  616. n = ctRead_i (CT_XR_O, 0xc9);
  617. m -= param->mn_diff;
  618. n -= param->mn_diff;
  619. xr_cb = ctRead_i (CT_XR_O, 0xcb);
  620. PD = (0x70 & xr_cb) >> 4;
  621. pd = 1;
  622. for (i = 0; i < PD; i++) {
  623. pd *= 2;
  624. }
  625. vld = (0x04 & xr_cb) ? param->vld_set : param->vld_not_set;
  626. if (n * vld * m) {
  627. unsigned long long p = 1000000000000LL * pd * n;
  628. unsigned long long q = (long long) fref * vld * m;
  629. while ((p > 0xffffffffLL) || (q > 0xffffffffLL)) {
  630. p >>= 1; /* can't divide with long long so we scale down */
  631. q >>= 1;
  632. }
  633. pixclock = (unsigned) p / (unsigned) q;
  634. } else
  635. printf ("Invalid data in xr regs.\n");
  636. return pixclock;
  637. }
  638. /*****************************************************************************/
  639. static void
  640. FindAndSetPllParamIntoXrRegs (unsigned int pixelclock,
  641. struct ctfb_chips_properties *param)
  642. {
  643. unsigned int m, n, vld, pd, PD, fref, xr_cb;
  644. unsigned int fvcomin, fvcomax, pclckmin, pclckmax, pclk;
  645. unsigned int pfreq, fvco, new_pixclock;
  646. unsigned int D,nback,mback;
  647. fref = VIDEO_FREF;
  648. pd = 1;
  649. PD = 0;
  650. fvcomin = param->vco_min;
  651. fvcomax = param->vco_max; /* MHz */
  652. pclckmin = 1000000 / fvcomax + 1; /* 4546 */
  653. pclckmax = 32000000 / fvcomin - 1; /* 666665 */
  654. pclk = minmax (pclckmin, pixelclock, pclckmax); /* ps pp */
  655. pfreq = 250 * (4000000000U / pclk);
  656. fvco = pfreq; /* Hz */
  657. new_pixclock = 0;
  658. while (fvco < fvcomin * 1000000) {
  659. /* double VCO starting with the pixelclock frequency
  660. * as long as it is lower than the minimal VCO frequency */
  661. fvco *= 2;
  662. pd *= 2;
  663. PD++;
  664. }
  665. /* fvco is exactly pd * pixelclock and higher than the ninmal VCO frequency */
  666. /* first try */
  667. vld = param->vld_set;
  668. D=FindBestPQFittingMN (fvco / vld, fref, param->mn_min, param->mn_max, &m, &n); /* rds = 1 */
  669. mback=m;
  670. nback=n;
  671. /* second try */
  672. vld = param->vld_not_set;
  673. if(D<FindBestPQFittingMN (fvco / vld, fref, param->mn_min, param->mn_max, &m, &n)) { /* rds = 1 */
  674. /* first try was better */
  675. m=mback;
  676. n=nback;
  677. vld = param->vld_set;
  678. }
  679. m += param->mn_diff;
  680. n += param->mn_diff;
  681. debug("VCO %d, pd %d, m %d n %d vld %d\n", fvco, pd, m, n, vld);
  682. xr_cb = ((0x7 & PD) << 4) | (vld == param->vld_set ? 0x04 : 0);
  683. /* All four of the registers used for dot clock 2 (XRC8 - XRCB) must be
  684. * written, and in order from XRC8 to XRCB, before the hardware will
  685. * update the synthesizer s settings.
  686. */
  687. ctWrite_i (CT_XR_O, 0xc8, m);
  688. ctWrite_i (CT_XR_O, 0xc9, n); /* xrca does not exist in CT69000 and CT69030 */
  689. ctWrite_i (CT_XR_O, 0xca, 0); /* because of a hw bug I guess, but we write */
  690. ctWrite_i (CT_XR_O, 0xcb, xr_cb); /* 0 to it for savety */
  691. new_pixclock = ReadPixClckFromXrRegsBack (param);
  692. debug("pixelclock.set = %d, pixelclock.real = %d\n",
  693. pixelclock, new_pixclock);
  694. }
  695. /*****************************************************************************/
  696. static void
  697. SetMsrRegs (struct ctfb_res_modes *mode)
  698. {
  699. unsigned char h_synch_high, v_synch_high;
  700. h_synch_high = (mode->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : 0x40; /* horizontal Synch High active */
  701. v_synch_high = (mode->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : 0x80; /* vertical Synch High active */
  702. ctWrite (CT_MSR_W_O, (h_synch_high | v_synch_high | 0x29));
  703. /* upper64K==0x20, CLC2select==0x08, RAMenable==0x02!(todo), CGA==0x01
  704. * Selects the upper 64KB page.Bit5=1
  705. * CLK2 (left reserved in standard VGA) Bit3|2=1|0
  706. * Disables CPU access to frame buffer. Bit1=0
  707. * Sets the I/O address decode for ST01, FCR, and all CR registers
  708. * to the 3Dx I/O address range (CGA emulation). Bit0=1
  709. */
  710. }
  711. /************************************************************************************/
  712. #ifdef VGA_DUMP_REG
  713. static void
  714. ctDispRegs (unsigned short index, int from, int to)
  715. {
  716. unsigned char status;
  717. int i;
  718. for (i = from; i < to; i++) {
  719. status = ctRead_i (index, i);
  720. printf ("%02X: is %02X\n", i, status);
  721. }
  722. }
  723. void
  724. video_dump_reg (void)
  725. {
  726. int i;
  727. printf ("Extended Regs:\n");
  728. ctDispRegs (CT_XR_O, 0, 0xC);
  729. ctDispRegs (CT_XR_O, 0xe, 0xf);
  730. ctDispRegs (CT_XR_O, 0x20, 0x21);
  731. ctDispRegs (CT_XR_O, 0x40, 0x50);
  732. ctDispRegs (CT_XR_O, 0x60, 0x64);
  733. ctDispRegs (CT_XR_O, 0x67, 0x68);
  734. ctDispRegs (CT_XR_O, 0x70, 0x72);
  735. ctDispRegs (CT_XR_O, 0x80, 0x83);
  736. ctDispRegs (CT_XR_O, 0xA0, 0xB0);
  737. ctDispRegs (CT_XR_O, 0xC0, 0xD3);
  738. printf ("Sequencer Regs:\n");
  739. ctDispRegs (CT_SR_O, 0, 0x8);
  740. printf ("Graphic Regs:\n");
  741. ctDispRegs (CT_GR_O, 0, 0x9);
  742. printf ("CRT Regs:\n");
  743. ctDispRegs (CT_CR_O, 0, 0x19);
  744. ctDispRegs (CT_CR_O, 0x22, 0x23);
  745. ctDispRegs (CT_CR_O, 0x30, 0x34);
  746. ctDispRegs (CT_CR_O, 0x38, 0x39);
  747. ctDispRegs (CT_CR_O, 0x3C, 0x3D);
  748. ctDispRegs (CT_CR_O, 0x40, 0x42);
  749. ctDispRegs (CT_CR_O, 0x70, 0x80);
  750. /* don't display the attributes */
  751. }
  752. #endif
  753. /***************************************************************
  754. * Wait for BitBlt ready
  755. */
  756. static int
  757. video_wait_bitblt (unsigned long addr)
  758. {
  759. unsigned long br04;
  760. int i = 0;
  761. br04 = in32r (addr);
  762. while (br04 & 0x80000000) {
  763. udelay (1);
  764. br04 = in32r (addr);
  765. if (i++ > 1000000) {
  766. printf ("ERROR Timeout %lx\n", br04);
  767. return 1;
  768. }
  769. }
  770. return 0;
  771. }
  772. /***************************************************************
  773. * Set up BitBlt Registrs
  774. */
  775. static void
  776. SetDrawingEngine (int bits_per_pixel)
  777. {
  778. unsigned long br04, br00;
  779. unsigned char tmp;
  780. GraphicDevice *pGD = (GraphicDevice *) & ctfb;
  781. tmp = ctRead_i (CT_XR_O, 0x20); /* BitBLT Configuration */
  782. tmp |= 0x02; /* reset BitBLT */
  783. ctWrite_i (CT_XR_O, 0x20, tmp); /* BitBLT Configuration */
  784. udelay (10);
  785. tmp &= 0xfd; /* release reset BitBLT */
  786. ctWrite_i (CT_XR_O, 0x20, tmp); /* BitBLT Configuration */
  787. video_wait_bitblt (pGD->pciBase + BR04_o);
  788. /* set pattern Address */
  789. out32r (pGD->pciBase + BR05_o, PATTERN_ADR & 0x003ffff8);
  790. br04 = 0;
  791. if (bits_per_pixel == 1) {
  792. br04 |= 0x00040000; /* monochome Pattern */
  793. br04 |= 0x00001000; /* monochome source */
  794. }
  795. br00 = ((pGD->winSizeX * pGD->gdfBytesPP) << 16) + (pGD->winSizeX * pGD->gdfBytesPP); /* bytes per scanline */
  796. out32r (pGD->pciBase + BR00_o, br00); /* */
  797. out32r (pGD->pciBase + BR08_o, (10 << 16) + 10); /* dummy */
  798. out32r (pGD->pciBase + BR04_o, br04); /* write all 0 */
  799. out32r (pGD->pciBase + BR07_o, 0); /* destination */
  800. video_wait_bitblt (pGD->pciBase + BR04_o);
  801. }
  802. /****************************************************************************
  803. * supported Video Chips
  804. */
  805. static struct pci_device_id supported[] = {
  806. {PCI_VENDOR_ID_CT, PCI_DEVICE_ID_CT_69000},
  807. {}
  808. };
  809. /*******************************************************************************
  810. *
  811. * Init video chip
  812. */
  813. void *
  814. video_hw_init (void)
  815. {
  816. GraphicDevice *pGD = (GraphicDevice *) & ctfb;
  817. unsigned short device_id;
  818. pci_dev_t devbusfn;
  819. int videomode;
  820. unsigned long t1, hsynch, vsynch;
  821. unsigned int pci_mem_base, *vm;
  822. int tmp, i, bits_per_pixel;
  823. char *penv;
  824. struct ctfb_res_modes *res_mode;
  825. struct ctfb_res_modes var_mode;
  826. struct ctfb_chips_properties *chips_param;
  827. /* Search for video chip */
  828. if ((devbusfn = pci_find_devices (supported, 0)) < 0) {
  829. #ifdef CONFIG_VIDEO_ONBOARD
  830. printf ("Video: Controller not found !\n");
  831. #endif
  832. return (NULL);
  833. }
  834. /* PCI setup */
  835. pci_write_config_dword (devbusfn, PCI_COMMAND,
  836. (PCI_COMMAND_MEMORY | PCI_COMMAND_IO));
  837. pci_read_config_word (devbusfn, PCI_DEVICE_ID, &device_id);
  838. pci_read_config_dword (devbusfn, PCI_BASE_ADDRESS_0, &pci_mem_base);
  839. pci_mem_base = pci_mem_to_phys (devbusfn, pci_mem_base);
  840. /* get chips params */
  841. for (chips_param = (struct ctfb_chips_properties *) &chips[0];
  842. chips_param->device_id != 0; chips_param++) {
  843. if (chips_param->device_id == device_id)
  844. break;
  845. }
  846. if (chips_param->device_id == 0) {
  847. #ifdef CONFIG_VIDEO_ONBOARD
  848. printf ("Video: controller 0x%X not supported\n", device_id);
  849. #endif
  850. return NULL;
  851. }
  852. /* supported Video controller found */
  853. printf ("Video: ");
  854. tmp = 0;
  855. videomode = 0x301;
  856. /* get video mode via environment */
  857. if ((penv = getenv ("videomode")) != NULL) {
  858. /* deceide if it is a string */
  859. if (penv[0] <= '9') {
  860. videomode = (int) simple_strtoul (penv, NULL, 16);
  861. tmp = 1;
  862. }
  863. } else {
  864. tmp = 1;
  865. }
  866. if (tmp) {
  867. /* parameter are vesa modes */
  868. /* search params */
  869. for (i = 0; i < VESA_MODES_COUNT; i++) {
  870. if (vesa_modes[i].vesanr == videomode)
  871. break;
  872. }
  873. if (i == VESA_MODES_COUNT) {
  874. printf ("no VESA Mode found, switching to mode 0x301 ");
  875. i = 0;
  876. }
  877. res_mode =
  878. (struct ctfb_res_modes *) &res_mode_init[vesa_modes[i].
  879. resindex];
  880. bits_per_pixel = vesa_modes[i].bits_per_pixel;
  881. } else {
  882. res_mode = (struct ctfb_res_modes *) &var_mode;
  883. bits_per_pixel = video_get_params (res_mode, penv);
  884. }
  885. /* calculate available color depth for controller memory */
  886. if (bits_per_pixel == 15)
  887. tmp = 2;
  888. else
  889. tmp = bits_per_pixel >> 3; /* /8 */
  890. if (((chips_param->max_mem -
  891. ACCELMEMORY) / (res_mode->xres * res_mode->yres)) < tmp) {
  892. tmp =
  893. ((chips_param->max_mem -
  894. ACCELMEMORY) / (res_mode->xres * res_mode->yres));
  895. if (tmp == 0) {
  896. printf
  897. ("No matching videomode found .-> reduce resolution\n");
  898. return NULL;
  899. } else {
  900. printf ("Switching back to %d Bits per Pixel ",
  901. tmp << 3);
  902. bits_per_pixel = tmp << 3;
  903. }
  904. }
  905. /* calculate hsynch and vsynch freq (info only) */
  906. t1 = (res_mode->left_margin + res_mode->xres +
  907. res_mode->right_margin + res_mode->hsync_len) / 8;
  908. t1 *= 8;
  909. t1 *= res_mode->pixclock;
  910. t1 /= 1000;
  911. hsynch = 1000000000L / t1;
  912. t1 *=
  913. (res_mode->upper_margin + res_mode->yres +
  914. res_mode->lower_margin + res_mode->vsync_len);
  915. t1 /= 1000;
  916. vsynch = 1000000000L / t1;
  917. /* fill in Graphic device struct */
  918. sprintf (pGD->modeIdent, "%dx%dx%d %ldkHz %ldHz", res_mode->xres,
  919. res_mode->yres, bits_per_pixel, (hsynch / 1000),
  920. (vsynch / 1000));
  921. printf ("%s\n", pGD->modeIdent);
  922. pGD->winSizeX = res_mode->xres;
  923. pGD->winSizeY = res_mode->yres;
  924. pGD->plnSizeX = res_mode->xres;
  925. pGD->plnSizeY = res_mode->yres;
  926. switch (bits_per_pixel) {
  927. case 8:
  928. pGD->gdfBytesPP = 1;
  929. pGD->gdfIndex = GDF__8BIT_INDEX;
  930. break;
  931. case 15:
  932. pGD->gdfBytesPP = 2;
  933. pGD->gdfIndex = GDF_15BIT_555RGB;
  934. break;
  935. case 16:
  936. pGD->gdfBytesPP = 2;
  937. pGD->gdfIndex = GDF_16BIT_565RGB;
  938. break;
  939. case 24:
  940. pGD->gdfBytesPP = 3;
  941. pGD->gdfIndex = GDF_24BIT_888RGB;
  942. break;
  943. }
  944. pGD->isaBase = CONFIG_SYS_ISA_IO_BASE_ADDRESS;
  945. pGD->pciBase = pci_mem_base;
  946. pGD->frameAdrs = pci_mem_base;
  947. pGD->memSize = chips_param->max_mem;
  948. /* Cursor Start Address */
  949. pGD->dprBase =
  950. (pGD->winSizeX * pGD->winSizeY * pGD->gdfBytesPP) + pci_mem_base;
  951. if ((pGD->dprBase & 0x0fff) != 0) {
  952. /* allign it */
  953. pGD->dprBase &= 0xfffff000;
  954. pGD->dprBase += 0x00001000;
  955. }
  956. debug("Cursor Start %x Pattern Start %x\n", pGD->dprBase,
  957. PATTERN_ADR);
  958. pGD->vprBase = pci_mem_base; /* Dummy */
  959. pGD->cprBase = pci_mem_base; /* Dummy */
  960. /* set up Hardware */
  961. ctWrite (CT_MSR_W_O, 0x01);
  962. /* set the extended Registers */
  963. ctLoadRegs (CT_XR_O, xreg);
  964. /* set atribute registers */
  965. SetArRegs ();
  966. /* set Graphics register */
  967. SetGrRegs ();
  968. /* set sequencer */
  969. SetSrRegs ();
  970. /* set msr */
  971. SetMsrRegs (res_mode);
  972. /* set CRT Registers */
  973. SetCrRegs (res_mode, bits_per_pixel);
  974. /* set color mode */
  975. SetBitsPerPixelIntoXrRegs (bits_per_pixel);
  976. /* set PLL */
  977. FindAndSetPllParamIntoXrRegs (res_mode->pixclock, chips_param);
  978. ctWrite_i (CT_SR_O, 0, 0x03); /* clear synchronous reset */
  979. /* Clear video memory */
  980. i = pGD->memSize / 4;
  981. vm = (unsigned int *) pGD->pciBase;
  982. while (i--)
  983. *vm++ = 0;
  984. SetDrawingEngine (bits_per_pixel);
  985. #ifdef VGA_DUMP_REG
  986. video_dump_reg ();
  987. #endif
  988. return ((void *) &ctfb);
  989. }
  990. /*******************************************************************************
  991. *
  992. * Set a RGB color in the LUT (8 bit index)
  993. */
  994. void
  995. video_set_lut (unsigned int index, /* color number */
  996. unsigned char r, /* red */
  997. unsigned char g, /* green */
  998. unsigned char b /* blue */
  999. )
  1000. {
  1001. ctWrite (CT_LUT_MASK_O, 0xff);
  1002. ctWrite (CT_LUT_START_O, (char) index);
  1003. ctWrite (CT_LUT_RGB_O, r); /* red */
  1004. ctWrite (CT_LUT_RGB_O, g); /* green */
  1005. ctWrite (CT_LUT_RGB_O, b); /* blue */
  1006. udelay (1);
  1007. ctWrite (CT_LUT_MASK_O, 0xff);
  1008. }
  1009. /*******************************************************************************
  1010. *
  1011. * Drawing engine fill on screen region
  1012. */
  1013. void
  1014. video_hw_rectfill (unsigned int bpp, /* bytes per pixel */
  1015. unsigned int dst_x, /* dest pos x */
  1016. unsigned int dst_y, /* dest pos y */
  1017. unsigned int dim_x, /* frame width */
  1018. unsigned int dim_y, /* frame height */
  1019. unsigned int color /* fill color */
  1020. )
  1021. {
  1022. GraphicDevice *pGD = (GraphicDevice *) & ctfb;
  1023. unsigned long *p, br04;
  1024. video_wait_bitblt (pGD->pciBase + BR04_o);
  1025. p = (unsigned long *) PATTERN_ADR;
  1026. dim_x *= bpp;
  1027. if (bpp == 3)
  1028. bpp++; /* 24Bit needs a 32bit pattern */
  1029. memset (p, color, (bpp * sizeof (unsigned char) * 8 * 8)); /* 8 x 8 pattern data */
  1030. out32r (pGD->pciBase + BR07_o, ((pGD->winSizeX * dst_y) + dst_x) * pGD->gdfBytesPP); /* destination */
  1031. br04 = in32r (pGD->pciBase + BR04_o) & 0xffffff00;
  1032. br04 |= 0xF0; /* write Pattern P -> D */
  1033. out32r (pGD->pciBase + BR04_o, br04); /* */
  1034. out32r (pGD->pciBase + BR08_o, (dim_y << 16) + dim_x); /* starts the BITBlt */
  1035. video_wait_bitblt (pGD->pciBase + BR04_o);
  1036. }
  1037. /*******************************************************************************
  1038. *
  1039. * Drawing engine bitblt with screen region
  1040. */
  1041. void
  1042. video_hw_bitblt (unsigned int bpp, /* bytes per pixel */
  1043. unsigned int src_x, /* source pos x */
  1044. unsigned int src_y, /* source pos y */
  1045. unsigned int dst_x, /* dest pos x */
  1046. unsigned int dst_y, /* dest pos y */
  1047. unsigned int dim_x, /* frame width */
  1048. unsigned int dim_y /* frame height */
  1049. )
  1050. {
  1051. GraphicDevice *pGD = (GraphicDevice *) & ctfb;
  1052. unsigned long br04;
  1053. br04 = in32r (pGD->pciBase + BR04_o);
  1054. /* to prevent data corruption due to overlap, we have to
  1055. * find out if, and how the frames overlaps */
  1056. if (src_x < dst_x) {
  1057. /* src is more left than dest
  1058. * the frame may overlap -> start from right to left */
  1059. br04 |= 0x00000100; /* set bit 8 */
  1060. src_x += dim_x;
  1061. dst_x += dim_x;
  1062. } else {
  1063. br04 &= 0xfffffeff; /* clear bit 8 left to right */
  1064. }
  1065. if (src_y < dst_y) {
  1066. /* src is higher than dst
  1067. * the frame may overlap => start from bottom */
  1068. br04 |= 0x00000200; /* set bit 9 */
  1069. src_y += dim_y;
  1070. dst_y += dim_y;
  1071. } else {
  1072. br04 &= 0xfffffdff; /* clear bit 9 top to bottom */
  1073. }
  1074. dim_x *= bpp;
  1075. out32r (pGD->pciBase + BR06_o, ((pGD->winSizeX * src_y) + src_x) * pGD->gdfBytesPP); /* source */
  1076. out32r (pGD->pciBase + BR07_o, ((pGD->winSizeX * dst_y) + dst_x) * pGD->gdfBytesPP); /* destination */
  1077. br04 &= 0xffffff00;
  1078. br04 |= 0x000000CC; /* S -> D */
  1079. out32r (pGD->pciBase + BR04_o, br04); /* */
  1080. out32r (pGD->pciBase + BR08_o, (dim_y << 16) + dim_x); /* start the BITBlt */
  1081. video_wait_bitblt (pGD->pciBase + BR04_o);
  1082. }
  1083. #endif /* CONFIG_VIDEO */