cyber2000fb.c 43 KB

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