cyber2000fb.c 43 KB

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