cyber2000fb.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763
  1. /*
  2. * linux/drivers/video/cyber2000fb.c
  3. *
  4. * Copyright (C) 1998-2002 Russell King
  5. *
  6. * MIPS and 50xx clock support
  7. * Copyright (C) 2001 Bradley D. LaRonde <brad@ltc.com>
  8. *
  9. * 32 bit support, text color and panning fixes for modes != 8 bit
  10. * Copyright (C) 2002 Denis Oliver Kropp <dok@directfb.org>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. *
  16. * Integraphics CyberPro 2000, 2010 and 5000 frame buffer device
  17. *
  18. * Based on cyberfb.c.
  19. *
  20. * Note that we now use the new fbcon fix, var and cmap scheme. We do
  21. * still have to check which console is the currently displayed one
  22. * however, especially for the colourmap stuff.
  23. *
  24. * We also use the new hotplug PCI subsystem. I'm not sure if there
  25. * are any such cards, but I'm erring on the side of caution. We don't
  26. * want to go pop just because someone does have one.
  27. *
  28. * Note that this doesn't work fully in the case of multiple CyberPro
  29. * cards with grabbers. We currently can only attach to the first
  30. * CyberPro card found.
  31. *
  32. * When we're in truecolour mode, we power down the LUT RAM as a power
  33. * saving feature. Also, when we enter any of the powersaving modes
  34. * (except soft blanking) we power down the RAMDACs. This saves about
  35. * 1W, which is roughly 8% of the power consumption of a NetWinder
  36. * (which, incidentally, is about the same saving as a 2.5in hard disk
  37. * entering standby mode.)
  38. */
  39. #include <linux/module.h>
  40. #include <linux/kernel.h>
  41. #include <linux/errno.h>
  42. #include <linux/string.h>
  43. #include <linux/mm.h>
  44. #include <linux/slab.h>
  45. #include <linux/delay.h>
  46. #include <linux/fb.h>
  47. #include <linux/pci.h>
  48. #include <linux/init.h>
  49. #include <linux/io.h>
  50. #include <asm/pgtable.h>
  51. #include <asm/system.h>
  52. #ifdef __arm__
  53. #include <asm/mach-types.h>
  54. #endif
  55. #include "cyber2000fb.h"
  56. struct cfb_info {
  57. struct fb_info fb;
  58. struct display_switch *dispsw;
  59. struct display *display;
  60. struct pci_dev *dev;
  61. unsigned char __iomem *region;
  62. unsigned char __iomem *regs;
  63. u_int id;
  64. int func_use_count;
  65. u_long ref_ps;
  66. /*
  67. * Clock divisors
  68. */
  69. u_int divisors[4];
  70. struct {
  71. u8 red, green, blue;
  72. } palette[NR_PALETTE];
  73. u_char mem_ctl1;
  74. u_char mem_ctl2;
  75. u_char mclk_mult;
  76. u_char mclk_div;
  77. /*
  78. * RAMDAC control register is both of these or'ed together
  79. */
  80. u_char ramdac_ctrl;
  81. u_char ramdac_powerdown;
  82. u32 pseudo_palette[16];
  83. };
  84. static char *default_font = "Acorn8x8";
  85. module_param(default_font, charp, 0);
  86. MODULE_PARM_DESC(default_font, "Default font name");
  87. /*
  88. * Our access methods.
  89. */
  90. #define cyber2000fb_writel(val, reg, cfb) writel(val, (cfb)->regs + (reg))
  91. #define cyber2000fb_writew(val, reg, cfb) writew(val, (cfb)->regs + (reg))
  92. #define cyber2000fb_writeb(val, reg, cfb) writeb(val, (cfb)->regs + (reg))
  93. #define cyber2000fb_readb(reg, cfb) readb((cfb)->regs + (reg))
  94. static inline void
  95. cyber2000_crtcw(unsigned int reg, unsigned int val, struct cfb_info *cfb)
  96. {
  97. cyber2000fb_writew((reg & 255) | val << 8, 0x3d4, cfb);
  98. }
  99. static inline void
  100. cyber2000_grphw(unsigned int reg, unsigned int val, struct cfb_info *cfb)
  101. {
  102. cyber2000fb_writew((reg & 255) | val << 8, 0x3ce, cfb);
  103. }
  104. static inline unsigned int
  105. cyber2000_grphr(unsigned int reg, struct cfb_info *cfb)
  106. {
  107. cyber2000fb_writeb(reg, 0x3ce, cfb);
  108. return cyber2000fb_readb(0x3cf, cfb);
  109. }
  110. static inline void
  111. cyber2000_attrw(unsigned int reg, unsigned int val, struct cfb_info *cfb)
  112. {
  113. cyber2000fb_readb(0x3da, cfb);
  114. cyber2000fb_writeb(reg, 0x3c0, cfb);
  115. cyber2000fb_readb(0x3c1, cfb);
  116. cyber2000fb_writeb(val, 0x3c0, cfb);
  117. }
  118. static inline void
  119. cyber2000_seqw(unsigned int reg, unsigned int val, struct cfb_info *cfb)
  120. {
  121. cyber2000fb_writew((reg & 255) | val << 8, 0x3c4, cfb);
  122. }
  123. /* -------------------- Hardware specific routines ------------------------- */
  124. /*
  125. * Hardware Cyber2000 Acceleration
  126. */
  127. static void
  128. cyber2000fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  129. {
  130. struct cfb_info *cfb = (struct cfb_info *)info;
  131. unsigned long dst, col;
  132. if (!(cfb->fb.var.accel_flags & FB_ACCELF_TEXT)) {
  133. cfb_fillrect(info, rect);
  134. return;
  135. }
  136. cyber2000fb_writeb(0, CO_REG_CONTROL, cfb);
  137. cyber2000fb_writew(rect->width - 1, CO_REG_PIXWIDTH, cfb);
  138. cyber2000fb_writew(rect->height - 1, CO_REG_PIXHEIGHT, cfb);
  139. col = rect->color;
  140. if (cfb->fb.var.bits_per_pixel > 8)
  141. col = ((u32 *)cfb->fb.pseudo_palette)[col];
  142. cyber2000fb_writel(col, CO_REG_FGCOLOUR, cfb);
  143. dst = rect->dx + rect->dy * cfb->fb.var.xres_virtual;
  144. if (cfb->fb.var.bits_per_pixel == 24) {
  145. cyber2000fb_writeb(dst, CO_REG_X_PHASE, cfb);
  146. dst *= 3;
  147. }
  148. cyber2000fb_writel(dst, CO_REG_DEST_PTR, cfb);
  149. cyber2000fb_writeb(CO_FG_MIX_SRC, CO_REG_FGMIX, cfb);
  150. cyber2000fb_writew(CO_CMD_L_PATTERN_FGCOL, CO_REG_CMD_L, cfb);
  151. cyber2000fb_writew(CO_CMD_H_BLITTER, CO_REG_CMD_H, cfb);
  152. }
  153. static void
  154. cyber2000fb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
  155. {
  156. struct cfb_info *cfb = (struct cfb_info *)info;
  157. unsigned int cmd = CO_CMD_L_PATTERN_FGCOL;
  158. unsigned long src, dst;
  159. if (!(cfb->fb.var.accel_flags & FB_ACCELF_TEXT)) {
  160. cfb_copyarea(info, region);
  161. return;
  162. }
  163. cyber2000fb_writeb(0, CO_REG_CONTROL, cfb);
  164. cyber2000fb_writew(region->width - 1, CO_REG_PIXWIDTH, cfb);
  165. cyber2000fb_writew(region->height - 1, CO_REG_PIXHEIGHT, cfb);
  166. src = region->sx + region->sy * cfb->fb.var.xres_virtual;
  167. dst = region->dx + region->dy * cfb->fb.var.xres_virtual;
  168. if (region->sx < region->dx) {
  169. src += region->width - 1;
  170. dst += region->width - 1;
  171. cmd |= CO_CMD_L_INC_LEFT;
  172. }
  173. if (region->sy < region->dy) {
  174. src += (region->height - 1) * cfb->fb.var.xres_virtual;
  175. dst += (region->height - 1) * cfb->fb.var.xres_virtual;
  176. cmd |= CO_CMD_L_INC_UP;
  177. }
  178. if (cfb->fb.var.bits_per_pixel == 24) {
  179. cyber2000fb_writeb(dst, CO_REG_X_PHASE, cfb);
  180. src *= 3;
  181. dst *= 3;
  182. }
  183. cyber2000fb_writel(src, CO_REG_SRC1_PTR, cfb);
  184. cyber2000fb_writel(dst, CO_REG_DEST_PTR, cfb);
  185. cyber2000fb_writew(CO_FG_MIX_SRC, CO_REG_FGMIX, cfb);
  186. cyber2000fb_writew(cmd, CO_REG_CMD_L, cfb);
  187. cyber2000fb_writew(CO_CMD_H_FGSRCMAP | CO_CMD_H_BLITTER,
  188. CO_REG_CMD_H, cfb);
  189. }
  190. static void
  191. cyber2000fb_imageblit(struct fb_info *info, const struct fb_image *image)
  192. {
  193. cfb_imageblit(info, image);
  194. return;
  195. }
  196. static int cyber2000fb_sync(struct fb_info *info)
  197. {
  198. struct cfb_info *cfb = (struct cfb_info *)info;
  199. int count = 100000;
  200. if (!(cfb->fb.var.accel_flags & FB_ACCELF_TEXT))
  201. return 0;
  202. while (cyber2000fb_readb(CO_REG_CONTROL, cfb) & CO_CTRL_BUSY) {
  203. if (!count--) {
  204. debug_printf("accel_wait timed out\n");
  205. cyber2000fb_writeb(0, CO_REG_CONTROL, cfb);
  206. break;
  207. }
  208. udelay(1);
  209. }
  210. return 0;
  211. }
  212. /*
  213. * ===========================================================================
  214. */
  215. static inline u32 convert_bitfield(u_int val, struct fb_bitfield *bf)
  216. {
  217. u_int mask = (1 << bf->length) - 1;
  218. return (val >> (16 - bf->length) & mask) << bf->offset;
  219. }
  220. /*
  221. * Set a single color register. Return != 0 for invalid regno.
  222. */
  223. static int
  224. cyber2000fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  225. u_int transp, struct fb_info *info)
  226. {
  227. struct cfb_info *cfb = (struct cfb_info *)info;
  228. struct fb_var_screeninfo *var = &cfb->fb.var;
  229. u32 pseudo_val;
  230. int ret = 1;
  231. switch (cfb->fb.fix.visual) {
  232. default:
  233. return 1;
  234. /*
  235. * Pseudocolour:
  236. * 8 8
  237. * pixel --/--+--/--> red lut --> red dac
  238. * | 8
  239. * +--/--> green lut --> green dac
  240. * | 8
  241. * +--/--> blue lut --> blue dac
  242. */
  243. case FB_VISUAL_PSEUDOCOLOR:
  244. if (regno >= NR_PALETTE)
  245. return 1;
  246. red >>= 8;
  247. green >>= 8;
  248. blue >>= 8;
  249. cfb->palette[regno].red = red;
  250. cfb->palette[regno].green = green;
  251. cfb->palette[regno].blue = blue;
  252. cyber2000fb_writeb(regno, 0x3c8, cfb);
  253. cyber2000fb_writeb(red, 0x3c9, cfb);
  254. cyber2000fb_writeb(green, 0x3c9, cfb);
  255. cyber2000fb_writeb(blue, 0x3c9, cfb);
  256. return 0;
  257. /*
  258. * Direct colour:
  259. * n rl
  260. * pixel --/--+--/--> red lut --> red dac
  261. * | gl
  262. * +--/--> green lut --> green dac
  263. * | bl
  264. * +--/--> blue lut --> blue dac
  265. * n = bpp, rl = red length, gl = green length, bl = blue length
  266. */
  267. case FB_VISUAL_DIRECTCOLOR:
  268. red >>= 8;
  269. green >>= 8;
  270. blue >>= 8;
  271. if (var->green.length == 6 && regno < 64) {
  272. cfb->palette[regno << 2].green = green;
  273. /*
  274. * The 6 bits of the green component are applied
  275. * to the high 6 bits of the LUT.
  276. */
  277. cyber2000fb_writeb(regno << 2, 0x3c8, cfb);
  278. cyber2000fb_writeb(cfb->palette[regno >> 1].red,
  279. 0x3c9, cfb);
  280. cyber2000fb_writeb(green, 0x3c9, cfb);
  281. cyber2000fb_writeb(cfb->palette[regno >> 1].blue,
  282. 0x3c9, cfb);
  283. green = cfb->palette[regno << 3].green;
  284. ret = 0;
  285. }
  286. if (var->green.length >= 5 && regno < 32) {
  287. cfb->palette[regno << 3].red = red;
  288. cfb->palette[regno << 3].green = green;
  289. cfb->palette[regno << 3].blue = blue;
  290. /*
  291. * The 5 bits of each colour component are
  292. * applied to the high 5 bits of the LUT.
  293. */
  294. cyber2000fb_writeb(regno << 3, 0x3c8, cfb);
  295. cyber2000fb_writeb(red, 0x3c9, cfb);
  296. cyber2000fb_writeb(green, 0x3c9, cfb);
  297. cyber2000fb_writeb(blue, 0x3c9, cfb);
  298. ret = 0;
  299. }
  300. if (var->green.length == 4 && regno < 16) {
  301. cfb->palette[regno << 4].red = red;
  302. cfb->palette[regno << 4].green = green;
  303. cfb->palette[regno << 4].blue = blue;
  304. /*
  305. * The 5 bits of each colour component are
  306. * applied to the high 5 bits of the LUT.
  307. */
  308. cyber2000fb_writeb(regno << 4, 0x3c8, cfb);
  309. cyber2000fb_writeb(red, 0x3c9, cfb);
  310. cyber2000fb_writeb(green, 0x3c9, cfb);
  311. cyber2000fb_writeb(blue, 0x3c9, cfb);
  312. ret = 0;
  313. }
  314. /*
  315. * Since this is only used for the first 16 colours, we
  316. * don't have to care about overflowing for regno >= 32
  317. */
  318. pseudo_val = regno << var->red.offset |
  319. regno << var->green.offset |
  320. regno << var->blue.offset;
  321. break;
  322. /*
  323. * True colour:
  324. * n rl
  325. * pixel --/--+--/--> red dac
  326. * | gl
  327. * +--/--> green dac
  328. * | bl
  329. * +--/--> blue dac
  330. * n = bpp, rl = red length, gl = green length, bl = blue length
  331. */
  332. case FB_VISUAL_TRUECOLOR:
  333. pseudo_val = convert_bitfield(transp ^ 0xffff, &var->transp);
  334. pseudo_val |= convert_bitfield(red, &var->red);
  335. pseudo_val |= convert_bitfield(green, &var->green);
  336. pseudo_val |= convert_bitfield(blue, &var->blue);
  337. break;
  338. }
  339. /*
  340. * Now set our pseudo palette for the CFB16/24/32 drivers.
  341. */
  342. if (regno < 16)
  343. ((u32 *)cfb->fb.pseudo_palette)[regno] = pseudo_val;
  344. return ret;
  345. }
  346. struct par_info {
  347. /*
  348. * Hardware
  349. */
  350. u_char clock_mult;
  351. u_char clock_div;
  352. u_char extseqmisc;
  353. u_char co_pixfmt;
  354. u_char crtc_ofl;
  355. u_char crtc[19];
  356. u_int width;
  357. u_int pitch;
  358. u_int fetch;
  359. /*
  360. * Other
  361. */
  362. u_char ramdac;
  363. };
  364. static const u_char crtc_idx[] = {
  365. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  366. 0x08, 0x09,
  367. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18
  368. };
  369. static void cyber2000fb_write_ramdac_ctrl(struct cfb_info *cfb)
  370. {
  371. unsigned int i;
  372. unsigned int val = cfb->ramdac_ctrl | cfb->ramdac_powerdown;
  373. cyber2000fb_writeb(0x56, 0x3ce, cfb);
  374. i = cyber2000fb_readb(0x3cf, cfb);
  375. cyber2000fb_writeb(i | 4, 0x3cf, cfb);
  376. cyber2000fb_writeb(val, 0x3c6, cfb);
  377. cyber2000fb_writeb(i, 0x3cf, cfb);
  378. }
  379. static void cyber2000fb_set_timing(struct cfb_info *cfb, struct par_info *hw)
  380. {
  381. u_int i;
  382. /*
  383. * Blank palette
  384. */
  385. for (i = 0; i < NR_PALETTE; i++) {
  386. cyber2000fb_writeb(i, 0x3c8, cfb);
  387. cyber2000fb_writeb(0, 0x3c9, cfb);
  388. cyber2000fb_writeb(0, 0x3c9, cfb);
  389. cyber2000fb_writeb(0, 0x3c9, cfb);
  390. }
  391. cyber2000fb_writeb(0xef, 0x3c2, cfb);
  392. cyber2000_crtcw(0x11, 0x0b, cfb);
  393. cyber2000_attrw(0x11, 0x00, cfb);
  394. cyber2000_seqw(0x00, 0x01, cfb);
  395. cyber2000_seqw(0x01, 0x01, cfb);
  396. cyber2000_seqw(0x02, 0x0f, cfb);
  397. cyber2000_seqw(0x03, 0x00, cfb);
  398. cyber2000_seqw(0x04, 0x0e, cfb);
  399. cyber2000_seqw(0x00, 0x03, cfb);
  400. for (i = 0; i < sizeof(crtc_idx); i++)
  401. cyber2000_crtcw(crtc_idx[i], hw->crtc[i], cfb);
  402. for (i = 0x0a; i < 0x10; i++)
  403. cyber2000_crtcw(i, 0, cfb);
  404. cyber2000_grphw(EXT_CRT_VRTOFL, hw->crtc_ofl, cfb);
  405. cyber2000_grphw(0x00, 0x00, cfb);
  406. cyber2000_grphw(0x01, 0x00, cfb);
  407. cyber2000_grphw(0x02, 0x00, cfb);
  408. cyber2000_grphw(0x03, 0x00, cfb);
  409. cyber2000_grphw(0x04, 0x00, cfb);
  410. cyber2000_grphw(0x05, 0x60, cfb);
  411. cyber2000_grphw(0x06, 0x05, cfb);
  412. cyber2000_grphw(0x07, 0x0f, cfb);
  413. cyber2000_grphw(0x08, 0xff, cfb);
  414. /* Attribute controller registers */
  415. for (i = 0; i < 16; i++)
  416. cyber2000_attrw(i, i, cfb);
  417. cyber2000_attrw(0x10, 0x01, cfb);
  418. cyber2000_attrw(0x11, 0x00, cfb);
  419. cyber2000_attrw(0x12, 0x0f, cfb);
  420. cyber2000_attrw(0x13, 0x00, cfb);
  421. cyber2000_attrw(0x14, 0x00, cfb);
  422. /* PLL registers */
  423. cyber2000_grphw(EXT_DCLK_MULT, hw->clock_mult, cfb);
  424. cyber2000_grphw(EXT_DCLK_DIV, hw->clock_div, cfb);
  425. cyber2000_grphw(EXT_MCLK_MULT, cfb->mclk_mult, cfb);
  426. cyber2000_grphw(EXT_MCLK_DIV, cfb->mclk_div, cfb);
  427. cyber2000_grphw(0x90, 0x01, cfb);
  428. cyber2000_grphw(0xb9, 0x80, cfb);
  429. cyber2000_grphw(0xb9, 0x00, cfb);
  430. cfb->ramdac_ctrl = hw->ramdac;
  431. cyber2000fb_write_ramdac_ctrl(cfb);
  432. cyber2000fb_writeb(0x20, 0x3c0, cfb);
  433. cyber2000fb_writeb(0xff, 0x3c6, cfb);
  434. cyber2000_grphw(0x14, hw->fetch, cfb);
  435. cyber2000_grphw(0x15, ((hw->fetch >> 8) & 0x03) |
  436. ((hw->pitch >> 4) & 0x30), cfb);
  437. cyber2000_grphw(EXT_SEQ_MISC, hw->extseqmisc, cfb);
  438. /*
  439. * Set up accelerator registers
  440. */
  441. cyber2000fb_writew(hw->width, CO_REG_SRC_WIDTH, cfb);
  442. cyber2000fb_writew(hw->width, CO_REG_DEST_WIDTH, cfb);
  443. cyber2000fb_writeb(hw->co_pixfmt, CO_REG_PIXFMT, cfb);
  444. }
  445. static inline int
  446. cyber2000fb_update_start(struct cfb_info *cfb, struct fb_var_screeninfo *var)
  447. {
  448. u_int base = var->yoffset * var->xres_virtual + var->xoffset;
  449. base *= var->bits_per_pixel;
  450. /*
  451. * Convert to bytes and shift two extra bits because DAC
  452. * can only start on 4 byte aligned data.
  453. */
  454. base >>= 5;
  455. if (base >= 1 << 20)
  456. return -EINVAL;
  457. cyber2000_grphw(0x10, base >> 16 | 0x10, cfb);
  458. cyber2000_crtcw(0x0c, base >> 8, cfb);
  459. cyber2000_crtcw(0x0d, base, cfb);
  460. return 0;
  461. }
  462. static int
  463. cyber2000fb_decode_crtc(struct par_info *hw, struct cfb_info *cfb,
  464. struct fb_var_screeninfo *var)
  465. {
  466. u_int Htotal, Hblankend, Hsyncend;
  467. u_int Vtotal, Vdispend, Vblankstart, Vblankend, Vsyncstart, Vsyncend;
  468. #define ENCODE_BIT(v, b1, m, b2) ((((v) >> (b1)) & (m)) << (b2))
  469. hw->crtc[13] = hw->pitch;
  470. hw->crtc[17] = 0xe3;
  471. hw->crtc[14] = 0;
  472. hw->crtc[8] = 0;
  473. Htotal = var->xres + var->right_margin +
  474. var->hsync_len + var->left_margin;
  475. if (Htotal > 2080)
  476. return -EINVAL;
  477. hw->crtc[0] = (Htotal >> 3) - 5;
  478. hw->crtc[1] = (var->xres >> 3) - 1;
  479. hw->crtc[2] = var->xres >> 3;
  480. hw->crtc[4] = (var->xres + var->right_margin) >> 3;
  481. Hblankend = (Htotal - 4 * 8) >> 3;
  482. hw->crtc[3] = ENCODE_BIT(Hblankend, 0, 0x1f, 0) |
  483. ENCODE_BIT(1, 0, 0x01, 7);
  484. Hsyncend = (var->xres + var->right_margin + var->hsync_len) >> 3;
  485. hw->crtc[5] = ENCODE_BIT(Hsyncend, 0, 0x1f, 0) |
  486. ENCODE_BIT(Hblankend, 5, 0x01, 7);
  487. Vdispend = var->yres - 1;
  488. Vsyncstart = var->yres + var->lower_margin;
  489. Vsyncend = var->yres + var->lower_margin + var->vsync_len;
  490. Vtotal = var->yres + var->lower_margin + var->vsync_len +
  491. var->upper_margin - 2;
  492. if (Vtotal > 2047)
  493. return -EINVAL;
  494. Vblankstart = var->yres + 6;
  495. Vblankend = Vtotal - 10;
  496. hw->crtc[6] = Vtotal;
  497. hw->crtc[7] = ENCODE_BIT(Vtotal, 8, 0x01, 0) |
  498. ENCODE_BIT(Vdispend, 8, 0x01, 1) |
  499. ENCODE_BIT(Vsyncstart, 8, 0x01, 2) |
  500. ENCODE_BIT(Vblankstart, 8, 0x01, 3) |
  501. ENCODE_BIT(1, 0, 0x01, 4) |
  502. ENCODE_BIT(Vtotal, 9, 0x01, 5) |
  503. ENCODE_BIT(Vdispend, 9, 0x01, 6) |
  504. ENCODE_BIT(Vsyncstart, 9, 0x01, 7);
  505. hw->crtc[9] = ENCODE_BIT(0, 0, 0x1f, 0) |
  506. ENCODE_BIT(Vblankstart, 9, 0x01, 5) |
  507. ENCODE_BIT(1, 0, 0x01, 6);
  508. hw->crtc[10] = Vsyncstart;
  509. hw->crtc[11] = ENCODE_BIT(Vsyncend, 0, 0x0f, 0) |
  510. ENCODE_BIT(1, 0, 0x01, 7);
  511. hw->crtc[12] = Vdispend;
  512. hw->crtc[15] = Vblankstart;
  513. hw->crtc[16] = Vblankend;
  514. hw->crtc[18] = 0xff;
  515. /*
  516. * overflow - graphics reg 0x11
  517. * 0=VTOTAL:10 1=VDEND:10 2=VRSTART:10 3=VBSTART:10
  518. * 4=LINECOMP:10 5-IVIDEO 6=FIXCNT
  519. */
  520. hw->crtc_ofl =
  521. ENCODE_BIT(Vtotal, 10, 0x01, 0) |
  522. ENCODE_BIT(Vdispend, 10, 0x01, 1) |
  523. ENCODE_BIT(Vsyncstart, 10, 0x01, 2) |
  524. ENCODE_BIT(Vblankstart, 10, 0x01, 3) |
  525. EXT_CRT_VRTOFL_LINECOMP10;
  526. /* woody: set the interlaced bit... */
  527. /* FIXME: what about doublescan? */
  528. if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED)
  529. hw->crtc_ofl |= EXT_CRT_VRTOFL_INTERLACE;
  530. return 0;
  531. }
  532. /*
  533. * The following was discovered by a good monitor, bit twiddling, theorising
  534. * and but mostly luck. Strangely, it looks like everyone elses' PLL!
  535. *
  536. * Clock registers:
  537. * fclock = fpll / div2
  538. * fpll = fref * mult / div1
  539. * where:
  540. * fref = 14.318MHz (69842ps)
  541. * mult = reg0xb0.7:0
  542. * div1 = (reg0xb1.5:0 + 1)
  543. * div2 = 2^(reg0xb1.7:6)
  544. * fpll should be between 115 and 260 MHz
  545. * (8696ps and 3846ps)
  546. */
  547. static int
  548. cyber2000fb_decode_clock(struct par_info *hw, struct cfb_info *cfb,
  549. struct fb_var_screeninfo *var)
  550. {
  551. u_long pll_ps = var->pixclock;
  552. const u_long ref_ps = cfb->ref_ps;
  553. u_int div2, t_div1, best_div1, best_mult;
  554. int best_diff;
  555. int vco;
  556. /*
  557. * Step 1:
  558. * find div2 such that 115MHz < fpll < 260MHz
  559. * and 0 <= div2 < 4
  560. */
  561. for (div2 = 0; div2 < 4; div2++) {
  562. u_long new_pll;
  563. new_pll = pll_ps / cfb->divisors[div2];
  564. if (8696 > new_pll && new_pll > 3846) {
  565. pll_ps = new_pll;
  566. break;
  567. }
  568. }
  569. if (div2 == 4)
  570. return -EINVAL;
  571. /*
  572. * Step 2:
  573. * Given pll_ps and ref_ps, find:
  574. * pll_ps * 0.995 < pll_ps_calc < pll_ps * 1.005
  575. * where { 1 < best_div1 < 32, 1 < best_mult < 256 }
  576. * pll_ps_calc = best_div1 / (ref_ps * best_mult)
  577. */
  578. best_diff = 0x7fffffff;
  579. best_mult = 32;
  580. best_div1 = 255;
  581. for (t_div1 = 32; t_div1 > 1; t_div1 -= 1) {
  582. u_int rr, t_mult, t_pll_ps;
  583. int diff;
  584. /*
  585. * Find the multiplier for this divisor
  586. */
  587. rr = ref_ps * t_div1;
  588. t_mult = (rr + pll_ps / 2) / pll_ps;
  589. /*
  590. * Is the multiplier within the correct range?
  591. */
  592. if (t_mult > 256 || t_mult < 2)
  593. continue;
  594. /*
  595. * Calculate the actual clock period from this multiplier
  596. * and divisor, and estimate the error.
  597. */
  598. t_pll_ps = (rr + t_mult / 2) / t_mult;
  599. diff = pll_ps - t_pll_ps;
  600. if (diff < 0)
  601. diff = -diff;
  602. if (diff < best_diff) {
  603. best_diff = diff;
  604. best_mult = t_mult;
  605. best_div1 = t_div1;
  606. }
  607. /*
  608. * If we hit an exact value, there is no point in continuing.
  609. */
  610. if (diff == 0)
  611. break;
  612. }
  613. /*
  614. * Step 3:
  615. * combine values
  616. */
  617. hw->clock_mult = best_mult - 1;
  618. hw->clock_div = div2 << 6 | (best_div1 - 1);
  619. vco = ref_ps * best_div1 / best_mult;
  620. if ((ref_ps == 40690) && (vco < 5556))
  621. /* Set VFSEL when VCO > 180MHz (5.556 ps). */
  622. hw->clock_div |= EXT_DCLK_DIV_VFSEL;
  623. return 0;
  624. }
  625. /*
  626. * Set the User Defined Part of the Display
  627. */
  628. static int
  629. cyber2000fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  630. {
  631. struct cfb_info *cfb = (struct cfb_info *)info;
  632. struct par_info hw;
  633. unsigned int mem;
  634. int err;
  635. var->transp.msb_right = 0;
  636. var->red.msb_right = 0;
  637. var->green.msb_right = 0;
  638. var->blue.msb_right = 0;
  639. var->transp.offset = 0;
  640. var->transp.length = 0;
  641. switch (var->bits_per_pixel) {
  642. case 8: /* PSEUDOCOLOUR, 256 */
  643. var->red.offset = 0;
  644. var->red.length = 8;
  645. var->green.offset = 0;
  646. var->green.length = 8;
  647. var->blue.offset = 0;
  648. var->blue.length = 8;
  649. break;
  650. case 16:/* DIRECTCOLOUR, 64k or 32k */
  651. switch (var->green.length) {
  652. case 6: /* RGB565, 64k */
  653. var->red.offset = 11;
  654. var->red.length = 5;
  655. var->green.offset = 5;
  656. var->green.length = 6;
  657. var->blue.offset = 0;
  658. var->blue.length = 5;
  659. break;
  660. default:
  661. case 5: /* RGB555, 32k */
  662. var->red.offset = 10;
  663. var->red.length = 5;
  664. var->green.offset = 5;
  665. var->green.length = 5;
  666. var->blue.offset = 0;
  667. var->blue.length = 5;
  668. break;
  669. case 4: /* RGB444, 4k + transparency? */
  670. var->transp.offset = 12;
  671. var->transp.length = 4;
  672. var->red.offset = 8;
  673. var->red.length = 4;
  674. var->green.offset = 4;
  675. var->green.length = 4;
  676. var->blue.offset = 0;
  677. var->blue.length = 4;
  678. break;
  679. }
  680. break;
  681. case 24:/* TRUECOLOUR, 16m */
  682. var->red.offset = 16;
  683. var->red.length = 8;
  684. var->green.offset = 8;
  685. var->green.length = 8;
  686. var->blue.offset = 0;
  687. var->blue.length = 8;
  688. break;
  689. case 32:/* TRUECOLOUR, 16m */
  690. var->transp.offset = 24;
  691. var->transp.length = 8;
  692. var->red.offset = 16;
  693. var->red.length = 8;
  694. var->green.offset = 8;
  695. var->green.length = 8;
  696. var->blue.offset = 0;
  697. var->blue.length = 8;
  698. break;
  699. default:
  700. return -EINVAL;
  701. }
  702. mem = var->xres_virtual * var->yres_virtual * (var->bits_per_pixel / 8);
  703. if (mem > cfb->fb.fix.smem_len)
  704. var->yres_virtual = cfb->fb.fix.smem_len * 8 /
  705. (var->bits_per_pixel * var->xres_virtual);
  706. if (var->yres > var->yres_virtual)
  707. var->yres = var->yres_virtual;
  708. if (var->xres > var->xres_virtual)
  709. var->xres = var->xres_virtual;
  710. err = cyber2000fb_decode_clock(&hw, cfb, var);
  711. if (err)
  712. return err;
  713. err = cyber2000fb_decode_crtc(&hw, cfb, var);
  714. if (err)
  715. return err;
  716. return 0;
  717. }
  718. static int cyber2000fb_set_par(struct fb_info *info)
  719. {
  720. struct cfb_info *cfb = (struct cfb_info *)info;
  721. struct fb_var_screeninfo *var = &cfb->fb.var;
  722. struct par_info hw;
  723. unsigned int mem;
  724. hw.width = var->xres_virtual;
  725. hw.ramdac = RAMDAC_VREFEN | RAMDAC_DAC8BIT;
  726. switch (var->bits_per_pixel) {
  727. case 8:
  728. hw.co_pixfmt = CO_PIXFMT_8BPP;
  729. hw.pitch = hw.width >> 3;
  730. hw.extseqmisc = EXT_SEQ_MISC_8;
  731. break;
  732. case 16:
  733. hw.co_pixfmt = CO_PIXFMT_16BPP;
  734. hw.pitch = hw.width >> 2;
  735. switch (var->green.length) {
  736. case 6: /* RGB565, 64k */
  737. hw.extseqmisc = EXT_SEQ_MISC_16_RGB565;
  738. break;
  739. case 5: /* RGB555, 32k */
  740. hw.extseqmisc = EXT_SEQ_MISC_16_RGB555;
  741. break;
  742. case 4: /* RGB444, 4k + transparency? */
  743. hw.extseqmisc = EXT_SEQ_MISC_16_RGB444;
  744. break;
  745. default:
  746. BUG();
  747. }
  748. break;
  749. case 24:/* TRUECOLOUR, 16m */
  750. hw.co_pixfmt = CO_PIXFMT_24BPP;
  751. hw.width *= 3;
  752. hw.pitch = hw.width >> 3;
  753. hw.ramdac |= (RAMDAC_BYPASS | RAMDAC_RAMPWRDN);
  754. hw.extseqmisc = EXT_SEQ_MISC_24_RGB888;
  755. break;
  756. case 32:/* TRUECOLOUR, 16m */
  757. hw.co_pixfmt = CO_PIXFMT_32BPP;
  758. hw.pitch = hw.width >> 1;
  759. hw.ramdac |= (RAMDAC_BYPASS | RAMDAC_RAMPWRDN);
  760. hw.extseqmisc = EXT_SEQ_MISC_32;
  761. break;
  762. default:
  763. BUG();
  764. }
  765. /*
  766. * Sigh, this is absolutely disgusting, but caused by
  767. * the way the fbcon developers want to separate out
  768. * the "checking" and the "setting" of the video mode.
  769. *
  770. * If the mode is not suitable for the hardware here,
  771. * we can't prevent it being set by returning an error.
  772. *
  773. * In theory, since NetWinders contain just one VGA card,
  774. * we should never end up hitting this problem.
  775. */
  776. BUG_ON(cyber2000fb_decode_clock(&hw, cfb, var) != 0);
  777. BUG_ON(cyber2000fb_decode_crtc(&hw, cfb, var) != 0);
  778. hw.width -= 1;
  779. hw.fetch = hw.pitch;
  780. if (!(cfb->mem_ctl2 & MEM_CTL2_64BIT))
  781. hw.fetch <<= 1;
  782. hw.fetch += 1;
  783. cfb->fb.fix.line_length = var->xres_virtual * var->bits_per_pixel / 8;
  784. /*
  785. * Same here - if the size of the video mode exceeds the
  786. * available RAM, we can't prevent this mode being set.
  787. *
  788. * In theory, since NetWinders contain just one VGA card,
  789. * we should never end up hitting this problem.
  790. */
  791. mem = cfb->fb.fix.line_length * var->yres_virtual;
  792. BUG_ON(mem > cfb->fb.fix.smem_len);
  793. /*
  794. * 8bpp displays are always pseudo colour. 16bpp and above
  795. * are direct colour or true colour, depending on whether
  796. * the RAMDAC palettes are bypassed. (Direct colour has
  797. * palettes, true colour does not.)
  798. */
  799. if (var->bits_per_pixel == 8)
  800. cfb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  801. else if (hw.ramdac & RAMDAC_BYPASS)
  802. cfb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  803. else
  804. cfb->fb.fix.visual = FB_VISUAL_DIRECTCOLOR;
  805. cyber2000fb_set_timing(cfb, &hw);
  806. cyber2000fb_update_start(cfb, var);
  807. return 0;
  808. }
  809. /*
  810. * Pan or Wrap the Display
  811. */
  812. static int
  813. cyber2000fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  814. {
  815. struct cfb_info *cfb = (struct cfb_info *)info;
  816. if (cyber2000fb_update_start(cfb, var))
  817. return -EINVAL;
  818. cfb->fb.var.xoffset = var->xoffset;
  819. cfb->fb.var.yoffset = var->yoffset;
  820. if (var->vmode & FB_VMODE_YWRAP) {
  821. cfb->fb.var.vmode |= FB_VMODE_YWRAP;
  822. } else {
  823. cfb->fb.var.vmode &= ~FB_VMODE_YWRAP;
  824. }
  825. return 0;
  826. }
  827. /*
  828. * (Un)Blank the display.
  829. *
  830. * Blank the screen if blank_mode != 0, else unblank. If
  831. * blank == NULL then the caller blanks by setting the CLUT
  832. * (Color Look Up Table) to all black. Return 0 if blanking
  833. * succeeded, != 0 if un-/blanking failed due to e.g. a
  834. * video mode which doesn't support it. Implements VESA
  835. * suspend and powerdown modes on hardware that supports
  836. * disabling hsync/vsync:
  837. * blank_mode == 2: suspend vsync
  838. * blank_mode == 3: suspend hsync
  839. * blank_mode == 4: powerdown
  840. *
  841. * wms...Enable VESA DMPS compatible powerdown mode
  842. * run "setterm -powersave powerdown" to take advantage
  843. */
  844. static int cyber2000fb_blank(int blank, struct fb_info *info)
  845. {
  846. struct cfb_info *cfb = (struct cfb_info *)info;
  847. unsigned int sync = 0;
  848. int i;
  849. switch (blank) {
  850. case FB_BLANK_POWERDOWN: /* powerdown - both sync lines down */
  851. sync = EXT_SYNC_CTL_VS_0 | EXT_SYNC_CTL_HS_0;
  852. break;
  853. case FB_BLANK_HSYNC_SUSPEND: /* hsync off */
  854. sync = EXT_SYNC_CTL_VS_NORMAL | EXT_SYNC_CTL_HS_0;
  855. break;
  856. case FB_BLANK_VSYNC_SUSPEND: /* vsync off */
  857. sync = EXT_SYNC_CTL_VS_0 | EXT_SYNC_CTL_HS_NORMAL;
  858. break;
  859. case FB_BLANK_NORMAL: /* soft blank */
  860. default: /* unblank */
  861. break;
  862. }
  863. cyber2000_grphw(EXT_SYNC_CTL, sync, cfb);
  864. if (blank <= 1) {
  865. /* turn on ramdacs */
  866. cfb->ramdac_powerdown &= ~(RAMDAC_DACPWRDN | RAMDAC_BYPASS |
  867. RAMDAC_RAMPWRDN);
  868. cyber2000fb_write_ramdac_ctrl(cfb);
  869. }
  870. /*
  871. * Soft blank/unblank the display.
  872. */
  873. if (blank) { /* soft blank */
  874. for (i = 0; i < NR_PALETTE; i++) {
  875. cyber2000fb_writeb(i, 0x3c8, cfb);
  876. cyber2000fb_writeb(0, 0x3c9, cfb);
  877. cyber2000fb_writeb(0, 0x3c9, cfb);
  878. cyber2000fb_writeb(0, 0x3c9, cfb);
  879. }
  880. } else { /* unblank */
  881. for (i = 0; i < NR_PALETTE; i++) {
  882. cyber2000fb_writeb(i, 0x3c8, cfb);
  883. cyber2000fb_writeb(cfb->palette[i].red, 0x3c9, cfb);
  884. cyber2000fb_writeb(cfb->palette[i].green, 0x3c9, cfb);
  885. cyber2000fb_writeb(cfb->palette[i].blue, 0x3c9, cfb);
  886. }
  887. }
  888. if (blank >= 2) {
  889. /* turn off ramdacs */
  890. cfb->ramdac_powerdown |= RAMDAC_DACPWRDN | RAMDAC_BYPASS |
  891. RAMDAC_RAMPWRDN;
  892. cyber2000fb_write_ramdac_ctrl(cfb);
  893. }
  894. return 0;
  895. }
  896. static struct fb_ops cyber2000fb_ops = {
  897. .owner = THIS_MODULE,
  898. .fb_check_var = cyber2000fb_check_var,
  899. .fb_set_par = cyber2000fb_set_par,
  900. .fb_setcolreg = cyber2000fb_setcolreg,
  901. .fb_blank = cyber2000fb_blank,
  902. .fb_pan_display = cyber2000fb_pan_display,
  903. .fb_fillrect = cyber2000fb_fillrect,
  904. .fb_copyarea = cyber2000fb_copyarea,
  905. .fb_imageblit = cyber2000fb_imageblit,
  906. .fb_sync = cyber2000fb_sync,
  907. };
  908. /*
  909. * This is the only "static" reference to the internal data structures
  910. * of this driver. It is here solely at the moment to support the other
  911. * CyberPro modules external to this driver.
  912. */
  913. static struct cfb_info *int_cfb_info;
  914. /*
  915. * Enable access to the extended registers
  916. */
  917. void cyber2000fb_enable_extregs(struct cfb_info *cfb)
  918. {
  919. cfb->func_use_count += 1;
  920. if (cfb->func_use_count == 1) {
  921. int old;
  922. old = cyber2000_grphr(EXT_FUNC_CTL, cfb);
  923. old |= EXT_FUNC_CTL_EXTREGENBL;
  924. cyber2000_grphw(EXT_FUNC_CTL, old, cfb);
  925. }
  926. }
  927. EXPORT_SYMBOL(cyber2000fb_enable_extregs);
  928. /*
  929. * Disable access to the extended registers
  930. */
  931. void cyber2000fb_disable_extregs(struct cfb_info *cfb)
  932. {
  933. if (cfb->func_use_count == 1) {
  934. int old;
  935. old = cyber2000_grphr(EXT_FUNC_CTL, cfb);
  936. old &= ~EXT_FUNC_CTL_EXTREGENBL;
  937. cyber2000_grphw(EXT_FUNC_CTL, old, cfb);
  938. }
  939. if (cfb->func_use_count == 0)
  940. printk(KERN_ERR "disable_extregs: count = 0\n");
  941. else
  942. cfb->func_use_count -= 1;
  943. }
  944. EXPORT_SYMBOL(cyber2000fb_disable_extregs);
  945. void cyber2000fb_get_fb_var(struct cfb_info *cfb, struct fb_var_screeninfo *var)
  946. {
  947. memcpy(var, &cfb->fb.var, sizeof(struct fb_var_screeninfo));
  948. }
  949. EXPORT_SYMBOL(cyber2000fb_get_fb_var);
  950. /*
  951. * Attach a capture/tv driver to the core CyberX0X0 driver.
  952. */
  953. int cyber2000fb_attach(struct cyberpro_info *info, int idx)
  954. {
  955. if (int_cfb_info != NULL) {
  956. info->dev = int_cfb_info->dev;
  957. info->regs = int_cfb_info->regs;
  958. info->fb = int_cfb_info->fb.screen_base;
  959. info->fb_size = int_cfb_info->fb.fix.smem_len;
  960. info->enable_extregs = cyber2000fb_enable_extregs;
  961. info->disable_extregs = cyber2000fb_disable_extregs;
  962. info->info = int_cfb_info;
  963. strlcpy(info->dev_name, int_cfb_info->fb.fix.id,
  964. sizeof(info->dev_name));
  965. }
  966. return int_cfb_info != NULL;
  967. }
  968. EXPORT_SYMBOL(cyber2000fb_attach);
  969. /*
  970. * Detach a capture/tv driver from the core CyberX0X0 driver.
  971. */
  972. void cyber2000fb_detach(int idx)
  973. {
  974. }
  975. EXPORT_SYMBOL(cyber2000fb_detach);
  976. /*
  977. * These parameters give
  978. * 640x480, hsync 31.5kHz, vsync 60Hz
  979. */
  980. static struct fb_videomode __devinitdata cyber2000fb_default_mode = {
  981. .refresh = 60,
  982. .xres = 640,
  983. .yres = 480,
  984. .pixclock = 39722,
  985. .left_margin = 56,
  986. .right_margin = 16,
  987. .upper_margin = 34,
  988. .lower_margin = 9,
  989. .hsync_len = 88,
  990. .vsync_len = 2,
  991. .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  992. .vmode = FB_VMODE_NONINTERLACED
  993. };
  994. static char igs_regs[] = {
  995. EXT_CRT_IRQ, 0,
  996. EXT_CRT_TEST, 0,
  997. EXT_SYNC_CTL, 0,
  998. EXT_SEG_WRITE_PTR, 0,
  999. EXT_SEG_READ_PTR, 0,
  1000. EXT_BIU_MISC, EXT_BIU_MISC_LIN_ENABLE |
  1001. EXT_BIU_MISC_COP_ENABLE |
  1002. EXT_BIU_MISC_COP_BFC,
  1003. EXT_FUNC_CTL, 0,
  1004. CURS_H_START, 0,
  1005. CURS_H_START + 1, 0,
  1006. CURS_H_PRESET, 0,
  1007. CURS_V_START, 0,
  1008. CURS_V_START + 1, 0,
  1009. CURS_V_PRESET, 0,
  1010. CURS_CTL, 0,
  1011. EXT_ATTRIB_CTL, EXT_ATTRIB_CTL_EXT,
  1012. EXT_OVERSCAN_RED, 0,
  1013. EXT_OVERSCAN_GREEN, 0,
  1014. EXT_OVERSCAN_BLUE, 0,
  1015. /* some of these are questionable when we have a BIOS */
  1016. EXT_MEM_CTL0, EXT_MEM_CTL0_7CLK |
  1017. EXT_MEM_CTL0_RAS_1 |
  1018. EXT_MEM_CTL0_MULTCAS,
  1019. EXT_HIDDEN_CTL1, 0x30,
  1020. EXT_FIFO_CTL, 0x0b,
  1021. EXT_FIFO_CTL + 1, 0x17,
  1022. 0x76, 0x00,
  1023. EXT_HIDDEN_CTL4, 0xc8
  1024. };
  1025. /*
  1026. * Initialise the CyberPro hardware. On the CyberPro5XXXX,
  1027. * ensure that we're using the correct PLL (5XXX's may be
  1028. * programmed to use an additional set of PLLs.)
  1029. */
  1030. static void cyberpro_init_hw(struct cfb_info *cfb)
  1031. {
  1032. int i;
  1033. for (i = 0; i < sizeof(igs_regs); i += 2)
  1034. cyber2000_grphw(igs_regs[i], igs_regs[i + 1], cfb);
  1035. if (cfb->id == ID_CYBERPRO_5000) {
  1036. unsigned char val;
  1037. cyber2000fb_writeb(0xba, 0x3ce, cfb);
  1038. val = cyber2000fb_readb(0x3cf, cfb) & 0x80;
  1039. cyber2000fb_writeb(val, 0x3cf, cfb);
  1040. }
  1041. }
  1042. static struct cfb_info __devinit *cyberpro_alloc_fb_info(unsigned int id,
  1043. char *name)
  1044. {
  1045. struct cfb_info *cfb;
  1046. cfb = kzalloc(sizeof(struct cfb_info), GFP_KERNEL);
  1047. if (!cfb)
  1048. return NULL;
  1049. cfb->id = id;
  1050. if (id == ID_CYBERPRO_5000)
  1051. cfb->ref_ps = 40690; /* 24.576 MHz */
  1052. else
  1053. cfb->ref_ps = 69842; /* 14.31818 MHz (69841?) */
  1054. cfb->divisors[0] = 1;
  1055. cfb->divisors[1] = 2;
  1056. cfb->divisors[2] = 4;
  1057. if (id == ID_CYBERPRO_2000)
  1058. cfb->divisors[3] = 8;
  1059. else
  1060. cfb->divisors[3] = 6;
  1061. strcpy(cfb->fb.fix.id, name);
  1062. cfb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  1063. cfb->fb.fix.type_aux = 0;
  1064. cfb->fb.fix.xpanstep = 0;
  1065. cfb->fb.fix.ypanstep = 1;
  1066. cfb->fb.fix.ywrapstep = 0;
  1067. switch (id) {
  1068. case ID_IGA_1682:
  1069. cfb->fb.fix.accel = 0;
  1070. break;
  1071. case ID_CYBERPRO_2000:
  1072. cfb->fb.fix.accel = FB_ACCEL_IGS_CYBER2000;
  1073. break;
  1074. case ID_CYBERPRO_2010:
  1075. cfb->fb.fix.accel = FB_ACCEL_IGS_CYBER2010;
  1076. break;
  1077. case ID_CYBERPRO_5000:
  1078. cfb->fb.fix.accel = FB_ACCEL_IGS_CYBER5000;
  1079. break;
  1080. }
  1081. cfb->fb.var.nonstd = 0;
  1082. cfb->fb.var.activate = FB_ACTIVATE_NOW;
  1083. cfb->fb.var.height = -1;
  1084. cfb->fb.var.width = -1;
  1085. cfb->fb.var.accel_flags = FB_ACCELF_TEXT;
  1086. cfb->fb.fbops = &cyber2000fb_ops;
  1087. cfb->fb.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  1088. cfb->fb.pseudo_palette = cfb->pseudo_palette;
  1089. fb_alloc_cmap(&cfb->fb.cmap, NR_PALETTE, 0);
  1090. return cfb;
  1091. }
  1092. static void cyberpro_free_fb_info(struct cfb_info *cfb)
  1093. {
  1094. if (cfb) {
  1095. /*
  1096. * Free the colourmap
  1097. */
  1098. fb_alloc_cmap(&cfb->fb.cmap, 0, 0);
  1099. kfree(cfb);
  1100. }
  1101. }
  1102. /*
  1103. * Parse Cyber2000fb options. Usage:
  1104. * video=cyber2000:font:fontname
  1105. */
  1106. #ifndef MODULE
  1107. static int cyber2000fb_setup(char *options)
  1108. {
  1109. char *opt;
  1110. if (!options || !*options)
  1111. return 0;
  1112. while ((opt = strsep(&options, ",")) != NULL) {
  1113. if (!*opt)
  1114. continue;
  1115. if (strncmp(opt, "font:", 5) == 0) {
  1116. static char default_font_storage[40];
  1117. strlcpy(default_font_storage, opt + 5,
  1118. sizeof(default_font_storage));
  1119. default_font = default_font_storage;
  1120. continue;
  1121. }
  1122. printk(KERN_ERR "CyberPro20x0: unknown parameter: %s\n", opt);
  1123. }
  1124. return 0;
  1125. }
  1126. #endif /* MODULE */
  1127. /*
  1128. * The CyberPro chips can be placed on many different bus types.
  1129. * This probe function is common to all bus types. The bus-specific
  1130. * probe function is expected to have:
  1131. * - enabled access to the linear memory region
  1132. * - memory mapped access to the registers
  1133. * - initialised mem_ctl1 and mem_ctl2 appropriately.
  1134. */
  1135. static int __devinit cyberpro_common_probe(struct cfb_info *cfb)
  1136. {
  1137. u_long smem_size;
  1138. u_int h_sync, v_sync;
  1139. int err;
  1140. cyberpro_init_hw(cfb);
  1141. /*
  1142. * Get the video RAM size and width from the VGA register.
  1143. * This should have been already initialised by the BIOS,
  1144. * but if it's garbage, claim default 1MB VRAM (woody)
  1145. */
  1146. cfb->mem_ctl1 = cyber2000_grphr(EXT_MEM_CTL1, cfb);
  1147. cfb->mem_ctl2 = cyber2000_grphr(EXT_MEM_CTL2, cfb);
  1148. /*
  1149. * Determine the size of the memory.
  1150. */
  1151. switch (cfb->mem_ctl2 & MEM_CTL2_SIZE_MASK) {
  1152. case MEM_CTL2_SIZE_4MB:
  1153. smem_size = 0x00400000;
  1154. break;
  1155. case MEM_CTL2_SIZE_2MB:
  1156. smem_size = 0x00200000;
  1157. break;
  1158. case MEM_CTL2_SIZE_1MB:
  1159. smem_size = 0x00100000;
  1160. break;
  1161. default:
  1162. smem_size = 0x00100000;
  1163. break;
  1164. }
  1165. cfb->fb.fix.smem_len = smem_size;
  1166. cfb->fb.fix.mmio_len = MMIO_SIZE;
  1167. cfb->fb.screen_base = cfb->region;
  1168. err = -EINVAL;
  1169. if (!fb_find_mode(&cfb->fb.var, &cfb->fb, NULL, NULL, 0,
  1170. &cyber2000fb_default_mode, 8)) {
  1171. printk(KERN_ERR "%s: no valid mode found\n", cfb->fb.fix.id);
  1172. goto failed;
  1173. }
  1174. cfb->fb.var.yres_virtual = cfb->fb.fix.smem_len * 8 /
  1175. (cfb->fb.var.bits_per_pixel * cfb->fb.var.xres_virtual);
  1176. if (cfb->fb.var.yres_virtual < cfb->fb.var.yres)
  1177. cfb->fb.var.yres_virtual = cfb->fb.var.yres;
  1178. /* fb_set_var(&cfb->fb.var, -1, &cfb->fb); */
  1179. /*
  1180. * Calculate the hsync and vsync frequencies. Note that
  1181. * we split the 1e12 constant up so that we can preserve
  1182. * the precision and fit the results into 32-bit registers.
  1183. * (1953125000 * 512 = 1e12)
  1184. */
  1185. h_sync = 1953125000 / cfb->fb.var.pixclock;
  1186. h_sync = h_sync * 512 / (cfb->fb.var.xres + cfb->fb.var.left_margin +
  1187. cfb->fb.var.right_margin + cfb->fb.var.hsync_len);
  1188. v_sync = h_sync / (cfb->fb.var.yres + cfb->fb.var.upper_margin +
  1189. cfb->fb.var.lower_margin + cfb->fb.var.vsync_len);
  1190. printk(KERN_INFO "%s: %dKiB VRAM, using %dx%d, %d.%03dkHz, %dHz\n",
  1191. cfb->fb.fix.id, cfb->fb.fix.smem_len >> 10,
  1192. cfb->fb.var.xres, cfb->fb.var.yres,
  1193. h_sync / 1000, h_sync % 1000, v_sync);
  1194. if (cfb->dev)
  1195. cfb->fb.device = &cfb->dev->dev;
  1196. err = register_framebuffer(&cfb->fb);
  1197. failed:
  1198. return err;
  1199. }
  1200. static void cyberpro_common_resume(struct cfb_info *cfb)
  1201. {
  1202. cyberpro_init_hw(cfb);
  1203. /*
  1204. * Reprogram the MEM_CTL1 and MEM_CTL2 registers
  1205. */
  1206. cyber2000_grphw(EXT_MEM_CTL1, cfb->mem_ctl1, cfb);
  1207. cyber2000_grphw(EXT_MEM_CTL2, cfb->mem_ctl2, cfb);
  1208. /*
  1209. * Restore the old video mode and the palette.
  1210. * We also need to tell fbcon to redraw the console.
  1211. */
  1212. cyber2000fb_set_par(&cfb->fb);
  1213. }
  1214. #ifdef CONFIG_ARCH_SHARK
  1215. #include <mach/framebuffer.h>
  1216. static int __devinit cyberpro_vl_probe(void)
  1217. {
  1218. struct cfb_info *cfb;
  1219. int err = -ENOMEM;
  1220. if (!request_mem_region(FB_START, FB_SIZE, "CyberPro2010"))
  1221. return err;
  1222. cfb = cyberpro_alloc_fb_info(ID_CYBERPRO_2010, "CyberPro2010");
  1223. if (!cfb)
  1224. goto failed_release;
  1225. cfb->dev = NULL;
  1226. cfb->region = ioremap(FB_START, FB_SIZE);
  1227. if (!cfb->region)
  1228. goto failed_ioremap;
  1229. cfb->regs = cfb->region + MMIO_OFFSET;
  1230. cfb->fb.fix.mmio_start = FB_START + MMIO_OFFSET;
  1231. cfb->fb.fix.smem_start = FB_START;
  1232. /*
  1233. * Bring up the hardware. This is expected to enable access
  1234. * to the linear memory region, and allow access to the memory
  1235. * mapped registers. Also, mem_ctl1 and mem_ctl2 must be
  1236. * initialised.
  1237. */
  1238. cyber2000fb_writeb(0x18, 0x46e8, cfb);
  1239. cyber2000fb_writeb(0x01, 0x102, cfb);
  1240. cyber2000fb_writeb(0x08, 0x46e8, cfb);
  1241. cyber2000fb_writeb(EXT_BIU_MISC, 0x3ce, cfb);
  1242. cyber2000fb_writeb(EXT_BIU_MISC_LIN_ENABLE, 0x3cf, cfb);
  1243. cfb->mclk_mult = 0xdb;
  1244. cfb->mclk_div = 0x54;
  1245. err = cyberpro_common_probe(cfb);
  1246. if (err)
  1247. goto failed;
  1248. if (int_cfb_info == NULL)
  1249. int_cfb_info = cfb;
  1250. return 0;
  1251. failed:
  1252. iounmap(cfb->region);
  1253. failed_ioremap:
  1254. cyberpro_free_fb_info(cfb);
  1255. failed_release:
  1256. release_mem_region(FB_START, FB_SIZE);
  1257. return err;
  1258. }
  1259. #endif /* CONFIG_ARCH_SHARK */
  1260. /*
  1261. * PCI specific support.
  1262. */
  1263. #ifdef CONFIG_PCI
  1264. /*
  1265. * We need to wake up the CyberPro, and make sure its in linear memory
  1266. * mode. Unfortunately, this is specific to the platform and card that
  1267. * we are running on.
  1268. *
  1269. * On x86 and ARM, should we be initialising the CyberPro first via the
  1270. * IO registers, and then the MMIO registers to catch all cases? Can we
  1271. * end up in the situation where the chip is in MMIO mode, but not awake
  1272. * on an x86 system?
  1273. */
  1274. static int cyberpro_pci_enable_mmio(struct cfb_info *cfb)
  1275. {
  1276. unsigned char val;
  1277. #if defined(__sparc_v9__)
  1278. #error "You lose, consult DaveM."
  1279. #elif defined(__sparc__)
  1280. /*
  1281. * SPARC does not have an "outb" instruction, so we generate
  1282. * I/O cycles storing into a reserved memory space at
  1283. * physical address 0x3000000
  1284. */
  1285. unsigned char __iomem *iop;
  1286. iop = ioremap(0x3000000, 0x5000);
  1287. if (iop == NULL) {
  1288. printk(KERN_ERR "iga5000: cannot map I/O\n");
  1289. return -ENOMEM;
  1290. }
  1291. writeb(0x18, iop + 0x46e8);
  1292. writeb(0x01, iop + 0x102);
  1293. writeb(0x08, iop + 0x46e8);
  1294. writeb(EXT_BIU_MISC, iop + 0x3ce);
  1295. writeb(EXT_BIU_MISC_LIN_ENABLE, iop + 0x3cf);
  1296. iounmap(iop);
  1297. #else
  1298. /*
  1299. * Most other machine types are "normal", so
  1300. * we use the standard IO-based wakeup.
  1301. */
  1302. outb(0x18, 0x46e8);
  1303. outb(0x01, 0x102);
  1304. outb(0x08, 0x46e8);
  1305. outb(EXT_BIU_MISC, 0x3ce);
  1306. outb(EXT_BIU_MISC_LIN_ENABLE, 0x3cf);
  1307. #endif
  1308. /*
  1309. * Allow the CyberPro to accept PCI burst accesses
  1310. */
  1311. if (cfb->id == ID_CYBERPRO_2010) {
  1312. printk(KERN_INFO "%s: NOT enabling PCI bursts\n",
  1313. cfb->fb.fix.id);
  1314. } else {
  1315. val = cyber2000_grphr(EXT_BUS_CTL, cfb);
  1316. if (!(val & EXT_BUS_CTL_PCIBURST_WRITE)) {
  1317. printk(KERN_INFO "%s: enabling PCI bursts\n",
  1318. cfb->fb.fix.id);
  1319. val |= EXT_BUS_CTL_PCIBURST_WRITE;
  1320. if (cfb->id == ID_CYBERPRO_5000)
  1321. val |= EXT_BUS_CTL_PCIBURST_READ;
  1322. cyber2000_grphw(EXT_BUS_CTL, val, cfb);
  1323. }
  1324. }
  1325. return 0;
  1326. }
  1327. static int __devinit
  1328. cyberpro_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
  1329. {
  1330. struct cfb_info *cfb;
  1331. char name[16];
  1332. int err;
  1333. sprintf(name, "CyberPro%4X", id->device);
  1334. err = pci_enable_device(dev);
  1335. if (err)
  1336. return err;
  1337. err = pci_request_regions(dev, name);
  1338. if (err)
  1339. return err;
  1340. err = -ENOMEM;
  1341. cfb = cyberpro_alloc_fb_info(id->driver_data, name);
  1342. if (!cfb)
  1343. goto failed_release;
  1344. cfb->dev = dev;
  1345. cfb->region = pci_ioremap_bar(dev, 0);
  1346. if (!cfb->region)
  1347. goto failed_ioremap;
  1348. cfb->regs = cfb->region + MMIO_OFFSET;
  1349. cfb->fb.fix.mmio_start = pci_resource_start(dev, 0) + MMIO_OFFSET;
  1350. cfb->fb.fix.smem_start = pci_resource_start(dev, 0);
  1351. /*
  1352. * Bring up the hardware. This is expected to enable access
  1353. * to the linear memory region, and allow access to the memory
  1354. * mapped registers. Also, mem_ctl1 and mem_ctl2 must be
  1355. * initialised.
  1356. */
  1357. err = cyberpro_pci_enable_mmio(cfb);
  1358. if (err)
  1359. goto failed;
  1360. /*
  1361. * Use MCLK from BIOS. FIXME: what about hotplug?
  1362. */
  1363. cfb->mclk_mult = cyber2000_grphr(EXT_MCLK_MULT, cfb);
  1364. cfb->mclk_div = cyber2000_grphr(EXT_MCLK_DIV, cfb);
  1365. #ifdef __arm__
  1366. /*
  1367. * MCLK on the NetWinder and the Shark is fixed at 75MHz
  1368. */
  1369. if (machine_is_netwinder()) {
  1370. cfb->mclk_mult = 0xdb;
  1371. cfb->mclk_div = 0x54;
  1372. }
  1373. #endif
  1374. err = cyberpro_common_probe(cfb);
  1375. if (err)
  1376. goto failed;
  1377. /*
  1378. * Our driver data
  1379. */
  1380. pci_set_drvdata(dev, cfb);
  1381. if (int_cfb_info == NULL)
  1382. int_cfb_info = cfb;
  1383. return 0;
  1384. failed:
  1385. iounmap(cfb->region);
  1386. failed_ioremap:
  1387. cyberpro_free_fb_info(cfb);
  1388. failed_release:
  1389. pci_release_regions(dev);
  1390. return err;
  1391. }
  1392. static void __devexit cyberpro_pci_remove(struct pci_dev *dev)
  1393. {
  1394. struct cfb_info *cfb = pci_get_drvdata(dev);
  1395. if (cfb) {
  1396. /*
  1397. * If unregister_framebuffer fails, then
  1398. * we will be leaving hooks that could cause
  1399. * oopsen laying around.
  1400. */
  1401. if (unregister_framebuffer(&cfb->fb))
  1402. printk(KERN_WARNING "%s: danger Will Robinson, "
  1403. "danger danger! Oopsen imminent!\n",
  1404. cfb->fb.fix.id);
  1405. iounmap(cfb->region);
  1406. cyberpro_free_fb_info(cfb);
  1407. /*
  1408. * Ensure that the driver data is no longer
  1409. * valid.
  1410. */
  1411. pci_set_drvdata(dev, NULL);
  1412. if (cfb == int_cfb_info)
  1413. int_cfb_info = NULL;
  1414. pci_release_regions(dev);
  1415. }
  1416. }
  1417. static int cyberpro_pci_suspend(struct pci_dev *dev, pm_message_t state)
  1418. {
  1419. return 0;
  1420. }
  1421. /*
  1422. * Re-initialise the CyberPro hardware
  1423. */
  1424. static int cyberpro_pci_resume(struct pci_dev *dev)
  1425. {
  1426. struct cfb_info *cfb = pci_get_drvdata(dev);
  1427. if (cfb) {
  1428. cyberpro_pci_enable_mmio(cfb);
  1429. cyberpro_common_resume(cfb);
  1430. }
  1431. return 0;
  1432. }
  1433. static struct pci_device_id cyberpro_pci_table[] = {
  1434. /* Not yet
  1435. * { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_1682,
  1436. * PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_IGA_1682 },
  1437. */
  1438. { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_2000,
  1439. PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_CYBERPRO_2000 },
  1440. { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_2010,
  1441. PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_CYBERPRO_2010 },
  1442. { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_5000,
  1443. PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_CYBERPRO_5000 },
  1444. { 0, }
  1445. };
  1446. MODULE_DEVICE_TABLE(pci, cyberpro_pci_table);
  1447. static struct pci_driver cyberpro_driver = {
  1448. .name = "CyberPro",
  1449. .probe = cyberpro_pci_probe,
  1450. .remove = __devexit_p(cyberpro_pci_remove),
  1451. .suspend = cyberpro_pci_suspend,
  1452. .resume = cyberpro_pci_resume,
  1453. .id_table = cyberpro_pci_table
  1454. };
  1455. #endif
  1456. /*
  1457. * I don't think we can use the "module_init" stuff here because
  1458. * the fbcon stuff may not be initialised yet. Hence the #ifdef
  1459. * around module_init.
  1460. *
  1461. * Tony: "module_init" is now required
  1462. */
  1463. static int __init cyber2000fb_init(void)
  1464. {
  1465. int ret = -1, err;
  1466. #ifndef MODULE
  1467. char *option = NULL;
  1468. if (fb_get_options("cyber2000fb", &option))
  1469. return -ENODEV;
  1470. cyber2000fb_setup(option);
  1471. #endif
  1472. #ifdef CONFIG_ARCH_SHARK
  1473. err = cyberpro_vl_probe();
  1474. if (!err) {
  1475. ret = 0;
  1476. __module_get(THIS_MODULE);
  1477. }
  1478. #endif
  1479. #ifdef CONFIG_PCI
  1480. err = pci_register_driver(&cyberpro_driver);
  1481. if (!err)
  1482. ret = 0;
  1483. #endif
  1484. return ret ? err : 0;
  1485. }
  1486. static void __exit cyberpro_exit(void)
  1487. {
  1488. pci_unregister_driver(&cyberpro_driver);
  1489. }
  1490. module_init(cyber2000fb_init);
  1491. module_exit(cyberpro_exit);
  1492. MODULE_AUTHOR("Russell King");
  1493. MODULE_DESCRIPTION("CyberPro 2000, 2010 and 5000 framebuffer driver");
  1494. MODULE_LICENSE("GPL");