cyber2000fb.c 42 KB

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