ct69000.c 39 KB

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