cyber2000fb.c 42 KB

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