cyber2000fb.c 42 KB

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