cyber2000fb.c 43 KB

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