cyber2000fb.c 42 KB

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