ffb.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  1. /* ffb.c: Creator/Elite3D frame buffer driver
  2. *
  3. * Copyright (C) 2003 David S. Miller (davem@redhat.com)
  4. * Copyright (C) 1997,1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
  5. *
  6. * Driver layout based loosely on tgafb.c, see that file for credits.
  7. */
  8. #include <linux/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/errno.h>
  11. #include <linux/string.h>
  12. #include <linux/slab.h>
  13. #include <linux/delay.h>
  14. #include <linux/init.h>
  15. #include <linux/fb.h>
  16. #include <linux/mm.h>
  17. #include <linux/timer.h>
  18. #include <asm/io.h>
  19. #include <asm/upa.h>
  20. #include <asm/oplib.h>
  21. #include <asm/fbio.h>
  22. #include "sbuslib.h"
  23. /*
  24. * Local functions.
  25. */
  26. static int ffb_setcolreg(unsigned, unsigned, unsigned, unsigned,
  27. unsigned, struct fb_info *);
  28. static int ffb_blank(int, struct fb_info *);
  29. static void ffb_init_fix(struct fb_info *);
  30. static void ffb_imageblit(struct fb_info *, const struct fb_image *);
  31. static void ffb_fillrect(struct fb_info *, const struct fb_fillrect *);
  32. static void ffb_copyarea(struct fb_info *, const struct fb_copyarea *);
  33. static int ffb_sync(struct fb_info *);
  34. static int ffb_mmap(struct fb_info *, struct vm_area_struct *);
  35. static int ffb_ioctl(struct fb_info *, unsigned int, unsigned long);
  36. static int ffb_pan_display(struct fb_var_screeninfo *, struct fb_info *);
  37. /*
  38. * Frame buffer operations
  39. */
  40. static struct fb_ops ffb_ops = {
  41. .owner = THIS_MODULE,
  42. .fb_setcolreg = ffb_setcolreg,
  43. .fb_blank = ffb_blank,
  44. .fb_pan_display = ffb_pan_display,
  45. .fb_fillrect = ffb_fillrect,
  46. .fb_copyarea = ffb_copyarea,
  47. .fb_imageblit = ffb_imageblit,
  48. .fb_sync = ffb_sync,
  49. .fb_mmap = ffb_mmap,
  50. .fb_ioctl = ffb_ioctl,
  51. #ifdef CONFIG_COMPAT
  52. .fb_compat_ioctl = sbusfb_compat_ioctl,
  53. #endif
  54. };
  55. /* Register layout and definitions */
  56. #define FFB_SFB8R_VOFF 0x00000000
  57. #define FFB_SFB8G_VOFF 0x00400000
  58. #define FFB_SFB8B_VOFF 0x00800000
  59. #define FFB_SFB8X_VOFF 0x00c00000
  60. #define FFB_SFB32_VOFF 0x01000000
  61. #define FFB_SFB64_VOFF 0x02000000
  62. #define FFB_FBC_REGS_VOFF 0x04000000
  63. #define FFB_BM_FBC_REGS_VOFF 0x04002000
  64. #define FFB_DFB8R_VOFF 0x04004000
  65. #define FFB_DFB8G_VOFF 0x04404000
  66. #define FFB_DFB8B_VOFF 0x04804000
  67. #define FFB_DFB8X_VOFF 0x04c04000
  68. #define FFB_DFB24_VOFF 0x05004000
  69. #define FFB_DFB32_VOFF 0x06004000
  70. #define FFB_DFB422A_VOFF 0x07004000 /* DFB 422 mode write to A */
  71. #define FFB_DFB422AD_VOFF 0x07804000 /* DFB 422 mode with line doubling */
  72. #define FFB_DFB24B_VOFF 0x08004000 /* DFB 24bit mode write to B */
  73. #define FFB_DFB422B_VOFF 0x09004000 /* DFB 422 mode write to B */
  74. #define FFB_DFB422BD_VOFF 0x09804000 /* DFB 422 mode with line doubling */
  75. #define FFB_SFB16Z_VOFF 0x0a004000 /* 16bit mode Z planes */
  76. #define FFB_SFB8Z_VOFF 0x0a404000 /* 8bit mode Z planes */
  77. #define FFB_SFB422_VOFF 0x0ac04000 /* SFB 422 mode write to A/B */
  78. #define FFB_SFB422D_VOFF 0x0b404000 /* SFB 422 mode with line doubling */
  79. #define FFB_FBC_KREGS_VOFF 0x0bc04000
  80. #define FFB_DAC_VOFF 0x0bc06000
  81. #define FFB_PROM_VOFF 0x0bc08000
  82. #define FFB_EXP_VOFF 0x0bc18000
  83. #define FFB_SFB8R_POFF 0x04000000UL
  84. #define FFB_SFB8G_POFF 0x04400000UL
  85. #define FFB_SFB8B_POFF 0x04800000UL
  86. #define FFB_SFB8X_POFF 0x04c00000UL
  87. #define FFB_SFB32_POFF 0x05000000UL
  88. #define FFB_SFB64_POFF 0x06000000UL
  89. #define FFB_FBC_REGS_POFF 0x00600000UL
  90. #define FFB_BM_FBC_REGS_POFF 0x00600000UL
  91. #define FFB_DFB8R_POFF 0x01000000UL
  92. #define FFB_DFB8G_POFF 0x01400000UL
  93. #define FFB_DFB8B_POFF 0x01800000UL
  94. #define FFB_DFB8X_POFF 0x01c00000UL
  95. #define FFB_DFB24_POFF 0x02000000UL
  96. #define FFB_DFB32_POFF 0x03000000UL
  97. #define FFB_FBC_KREGS_POFF 0x00610000UL
  98. #define FFB_DAC_POFF 0x00400000UL
  99. #define FFB_PROM_POFF 0x00000000UL
  100. #define FFB_EXP_POFF 0x00200000UL
  101. #define FFB_DFB422A_POFF 0x09000000UL
  102. #define FFB_DFB422AD_POFF 0x09800000UL
  103. #define FFB_DFB24B_POFF 0x0a000000UL
  104. #define FFB_DFB422B_POFF 0x0b000000UL
  105. #define FFB_DFB422BD_POFF 0x0b800000UL
  106. #define FFB_SFB16Z_POFF 0x0c800000UL
  107. #define FFB_SFB8Z_POFF 0x0c000000UL
  108. #define FFB_SFB422_POFF 0x0d000000UL
  109. #define FFB_SFB422D_POFF 0x0d800000UL
  110. /* Draw operations */
  111. #define FFB_DRAWOP_DOT 0x00
  112. #define FFB_DRAWOP_AADOT 0x01
  113. #define FFB_DRAWOP_BRLINECAP 0x02
  114. #define FFB_DRAWOP_BRLINEOPEN 0x03
  115. #define FFB_DRAWOP_DDLINE 0x04
  116. #define FFB_DRAWOP_AALINE 0x05
  117. #define FFB_DRAWOP_TRIANGLE 0x06
  118. #define FFB_DRAWOP_POLYGON 0x07
  119. #define FFB_DRAWOP_RECTANGLE 0x08
  120. #define FFB_DRAWOP_FASTFILL 0x09
  121. #define FFB_DRAWOP_BCOPY 0x0a
  122. #define FFB_DRAWOP_VSCROLL 0x0b
  123. /* Pixel processor control */
  124. /* Force WID */
  125. #define FFB_PPC_FW_DISABLE 0x800000
  126. #define FFB_PPC_FW_ENABLE 0xc00000
  127. /* Auxiliary clip */
  128. #define FFB_PPC_ACE_DISABLE 0x040000
  129. #define FFB_PPC_ACE_AUX_SUB 0x080000
  130. #define FFB_PPC_ACE_AUX_ADD 0x0c0000
  131. /* Depth cue */
  132. #define FFB_PPC_DCE_DISABLE 0x020000
  133. #define FFB_PPC_DCE_ENABLE 0x030000
  134. /* Alpha blend */
  135. #define FFB_PPC_ABE_DISABLE 0x008000
  136. #define FFB_PPC_ABE_ENABLE 0x00c000
  137. /* View clip */
  138. #define FFB_PPC_VCE_DISABLE 0x001000
  139. #define FFB_PPC_VCE_2D 0x002000
  140. #define FFB_PPC_VCE_3D 0x003000
  141. /* Area pattern */
  142. #define FFB_PPC_APE_DISABLE 0x000800
  143. #define FFB_PPC_APE_ENABLE 0x000c00
  144. /* Transparent background */
  145. #define FFB_PPC_TBE_OPAQUE 0x000200
  146. #define FFB_PPC_TBE_TRANSPARENT 0x000300
  147. /* Z source */
  148. #define FFB_PPC_ZS_VAR 0x000080
  149. #define FFB_PPC_ZS_CONST 0x0000c0
  150. /* Y source */
  151. #define FFB_PPC_YS_VAR 0x000020
  152. #define FFB_PPC_YS_CONST 0x000030
  153. /* X source */
  154. #define FFB_PPC_XS_WID 0x000004
  155. #define FFB_PPC_XS_VAR 0x000008
  156. #define FFB_PPC_XS_CONST 0x00000c
  157. /* Color (BGR) source */
  158. #define FFB_PPC_CS_VAR 0x000002
  159. #define FFB_PPC_CS_CONST 0x000003
  160. #define FFB_ROP_NEW 0x83
  161. #define FFB_ROP_OLD 0x85
  162. #define FFB_ROP_NEW_XOR_OLD 0x86
  163. #define FFB_UCSR_FIFO_MASK 0x00000fff
  164. #define FFB_UCSR_FB_BUSY 0x01000000
  165. #define FFB_UCSR_RP_BUSY 0x02000000
  166. #define FFB_UCSR_ALL_BUSY (FFB_UCSR_RP_BUSY|FFB_UCSR_FB_BUSY)
  167. #define FFB_UCSR_READ_ERR 0x40000000
  168. #define FFB_UCSR_FIFO_OVFL 0x80000000
  169. #define FFB_UCSR_ALL_ERRORS (FFB_UCSR_READ_ERR|FFB_UCSR_FIFO_OVFL)
  170. struct ffb_fbc {
  171. /* Next vertex registers */
  172. u32 xxx1[3];
  173. volatile u32 alpha;
  174. volatile u32 red;
  175. volatile u32 green;
  176. volatile u32 blue;
  177. volatile u32 depth;
  178. volatile u32 y;
  179. volatile u32 x;
  180. u32 xxx2[2];
  181. volatile u32 ryf;
  182. volatile u32 rxf;
  183. u32 xxx3[2];
  184. volatile u32 dmyf;
  185. volatile u32 dmxf;
  186. u32 xxx4[2];
  187. volatile u32 ebyi;
  188. volatile u32 ebxi;
  189. u32 xxx5[2];
  190. volatile u32 by;
  191. volatile u32 bx;
  192. u32 dy;
  193. u32 dx;
  194. volatile u32 bh;
  195. volatile u32 bw;
  196. u32 xxx6[2];
  197. u32 xxx7[32];
  198. /* Setup unit vertex state register */
  199. volatile u32 suvtx;
  200. u32 xxx8[63];
  201. /* Control registers */
  202. volatile u32 ppc;
  203. volatile u32 wid;
  204. volatile u32 fg;
  205. volatile u32 bg;
  206. volatile u32 consty;
  207. volatile u32 constz;
  208. volatile u32 xclip;
  209. volatile u32 dcss;
  210. volatile u32 vclipmin;
  211. volatile u32 vclipmax;
  212. volatile u32 vclipzmin;
  213. volatile u32 vclipzmax;
  214. volatile u32 dcsf;
  215. volatile u32 dcsb;
  216. volatile u32 dczf;
  217. volatile u32 dczb;
  218. u32 xxx9;
  219. volatile u32 blendc;
  220. volatile u32 blendc1;
  221. volatile u32 blendc2;
  222. volatile u32 fbramitc;
  223. volatile u32 fbc;
  224. volatile u32 rop;
  225. volatile u32 cmp;
  226. volatile u32 matchab;
  227. volatile u32 matchc;
  228. volatile u32 magnab;
  229. volatile u32 magnc;
  230. volatile u32 fbcfg0;
  231. volatile u32 fbcfg1;
  232. volatile u32 fbcfg2;
  233. volatile u32 fbcfg3;
  234. u32 ppcfg;
  235. volatile u32 pick;
  236. volatile u32 fillmode;
  237. volatile u32 fbramwac;
  238. volatile u32 pmask;
  239. volatile u32 xpmask;
  240. volatile u32 ypmask;
  241. volatile u32 zpmask;
  242. volatile u32 clip0min;
  243. volatile u32 clip0max;
  244. volatile u32 clip1min;
  245. volatile u32 clip1max;
  246. volatile u32 clip2min;
  247. volatile u32 clip2max;
  248. volatile u32 clip3min;
  249. volatile u32 clip3max;
  250. /* New 3dRAM III support regs */
  251. volatile u32 rawblend2;
  252. volatile u32 rawpreblend;
  253. volatile u32 rawstencil;
  254. volatile u32 rawstencilctl;
  255. volatile u32 threedram1;
  256. volatile u32 threedram2;
  257. volatile u32 passin;
  258. volatile u32 rawclrdepth;
  259. volatile u32 rawpmask;
  260. volatile u32 rawcsrc;
  261. volatile u32 rawmatch;
  262. volatile u32 rawmagn;
  263. volatile u32 rawropblend;
  264. volatile u32 rawcmp;
  265. volatile u32 rawwac;
  266. volatile u32 fbramid;
  267. volatile u32 drawop;
  268. u32 xxx10[2];
  269. volatile u32 fontlpat;
  270. u32 xxx11;
  271. volatile u32 fontxy;
  272. volatile u32 fontw;
  273. volatile u32 fontinc;
  274. volatile u32 font;
  275. u32 xxx12[3];
  276. volatile u32 blend2;
  277. volatile u32 preblend;
  278. volatile u32 stencil;
  279. volatile u32 stencilctl;
  280. u32 xxx13[4];
  281. volatile u32 dcss1;
  282. volatile u32 dcss2;
  283. volatile u32 dcss3;
  284. volatile u32 widpmask;
  285. volatile u32 dcs2;
  286. volatile u32 dcs3;
  287. volatile u32 dcs4;
  288. u32 xxx14;
  289. volatile u32 dcd2;
  290. volatile u32 dcd3;
  291. volatile u32 dcd4;
  292. u32 xxx15;
  293. volatile u32 pattern[32];
  294. u32 xxx16[256];
  295. volatile u32 devid;
  296. u32 xxx17[63];
  297. volatile u32 ucsr;
  298. u32 xxx18[31];
  299. volatile u32 mer;
  300. };
  301. struct ffb_dac {
  302. volatile u32 type;
  303. volatile u32 value;
  304. volatile u32 type2;
  305. volatile u32 value2;
  306. };
  307. struct ffb_par {
  308. spinlock_t lock;
  309. struct ffb_fbc *fbc;
  310. struct ffb_dac *dac;
  311. u32 flags;
  312. #define FFB_FLAG_AFB 0x00000001
  313. #define FFB_FLAG_BLANKED 0x00000002
  314. u32 fg_cache __attribute__((aligned (8)));
  315. u32 bg_cache;
  316. u32 rop_cache;
  317. int fifo_cache;
  318. unsigned long physbase;
  319. unsigned long fbsize;
  320. char name[64];
  321. int prom_node;
  322. int prom_parent_node;
  323. int dac_rev;
  324. int board_type;
  325. };
  326. static void FFBFifo(struct ffb_par *par, int n)
  327. {
  328. struct ffb_fbc *fbc;
  329. int cache = par->fifo_cache;
  330. if (cache - n < 0) {
  331. fbc = par->fbc;
  332. do { cache = (upa_readl(&fbc->ucsr) & FFB_UCSR_FIFO_MASK) - 8;
  333. } while (cache - n < 0);
  334. }
  335. par->fifo_cache = cache - n;
  336. }
  337. static void FFBWait(struct ffb_par *par)
  338. {
  339. struct ffb_fbc *fbc;
  340. int limit = 10000;
  341. fbc = par->fbc;
  342. do {
  343. if ((upa_readl(&fbc->ucsr) & FFB_UCSR_ALL_BUSY) == 0)
  344. break;
  345. if ((upa_readl(&fbc->ucsr) & FFB_UCSR_ALL_ERRORS) != 0) {
  346. upa_writel(FFB_UCSR_ALL_ERRORS, &fbc->ucsr);
  347. }
  348. udelay(10);
  349. } while(--limit > 0);
  350. }
  351. static int ffb_sync(struct fb_info *p)
  352. {
  353. struct ffb_par *par = (struct ffb_par *) p->par;
  354. FFBWait(par);
  355. return 0;
  356. }
  357. static __inline__ void ffb_rop(struct ffb_par *par, u32 rop)
  358. {
  359. if (par->rop_cache != rop) {
  360. FFBFifo(par, 1);
  361. upa_writel(rop, &par->fbc->rop);
  362. par->rop_cache = rop;
  363. }
  364. }
  365. static void ffb_switch_from_graph(struct ffb_par *par)
  366. {
  367. struct ffb_fbc *fbc = par->fbc;
  368. struct ffb_dac *dac = par->dac;
  369. unsigned long flags;
  370. spin_lock_irqsave(&par->lock, flags);
  371. FFBWait(par);
  372. par->fifo_cache = 0;
  373. FFBFifo(par, 7);
  374. upa_writel(FFB_PPC_VCE_DISABLE|FFB_PPC_TBE_OPAQUE|
  375. FFB_PPC_APE_DISABLE|FFB_PPC_CS_CONST,
  376. &fbc->ppc);
  377. upa_writel(0x2000707f, &fbc->fbc);
  378. upa_writel(par->rop_cache, &fbc->rop);
  379. upa_writel(0xffffffff, &fbc->pmask);
  380. upa_writel((1 << 16) | (0 << 0), &fbc->fontinc);
  381. upa_writel(par->fg_cache, &fbc->fg);
  382. upa_writel(par->bg_cache, &fbc->bg);
  383. FFBWait(par);
  384. /* Disable cursor. */
  385. upa_writel(0x100, &dac->type2);
  386. if (par->dac_rev <= 2)
  387. upa_writel(0, &dac->value2);
  388. else
  389. upa_writel(3, &dac->value2);
  390. spin_unlock_irqrestore(&par->lock, flags);
  391. }
  392. static int ffb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  393. {
  394. struct ffb_par *par = (struct ffb_par *) info->par;
  395. /* We just use this to catch switches out of
  396. * graphics mode.
  397. */
  398. ffb_switch_from_graph(par);
  399. if (var->xoffset || var->yoffset || var->vmode)
  400. return -EINVAL;
  401. return 0;
  402. }
  403. /**
  404. * ffb_fillrect - REQUIRED function. Can use generic routines if
  405. * non acclerated hardware and packed pixel based.
  406. * Draws a rectangle on the screen.
  407. *
  408. * @info: frame buffer structure that represents a single frame buffer
  409. * @rect: structure defining the rectagle and operation.
  410. */
  411. static void ffb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  412. {
  413. struct ffb_par *par = (struct ffb_par *) info->par;
  414. struct ffb_fbc *fbc = par->fbc;
  415. unsigned long flags;
  416. u32 fg;
  417. if (rect->rop != ROP_COPY && rect->rop != ROP_XOR)
  418. BUG();
  419. fg = ((u32 *)info->pseudo_palette)[rect->color];
  420. spin_lock_irqsave(&par->lock, flags);
  421. if (fg != par->fg_cache) {
  422. FFBFifo(par, 1);
  423. upa_writel(fg, &fbc->fg);
  424. par->fg_cache = fg;
  425. }
  426. ffb_rop(par, (rect->rop == ROP_COPY ?
  427. FFB_ROP_NEW :
  428. FFB_ROP_NEW_XOR_OLD));
  429. FFBFifo(par, 5);
  430. upa_writel(FFB_DRAWOP_RECTANGLE, &fbc->drawop);
  431. upa_writel(rect->dy, &fbc->by);
  432. upa_writel(rect->dx, &fbc->bx);
  433. upa_writel(rect->height, &fbc->bh);
  434. upa_writel(rect->width, &fbc->bw);
  435. spin_unlock_irqrestore(&par->lock, flags);
  436. }
  437. /**
  438. * ffb_copyarea - REQUIRED function. Can use generic routines if
  439. * non acclerated hardware and packed pixel based.
  440. * Copies on area of the screen to another area.
  441. *
  442. * @info: frame buffer structure that represents a single frame buffer
  443. * @area: structure defining the source and destination.
  444. */
  445. static void
  446. ffb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
  447. {
  448. struct ffb_par *par = (struct ffb_par *) info->par;
  449. struct ffb_fbc *fbc = par->fbc;
  450. unsigned long flags;
  451. if (area->dx != area->sx ||
  452. area->dy == area->sy) {
  453. cfb_copyarea(info, area);
  454. return;
  455. }
  456. spin_lock_irqsave(&par->lock, flags);
  457. ffb_rop(par, FFB_ROP_OLD);
  458. FFBFifo(par, 7);
  459. upa_writel(FFB_DRAWOP_VSCROLL, &fbc->drawop);
  460. upa_writel(area->sy, &fbc->by);
  461. upa_writel(area->sx, &fbc->bx);
  462. upa_writel(area->dy, &fbc->dy);
  463. upa_writel(area->dx, &fbc->dx);
  464. upa_writel(area->height, &fbc->bh);
  465. upa_writel(area->width, &fbc->bw);
  466. spin_unlock_irqrestore(&par->lock, flags);
  467. }
  468. /**
  469. * ffb_imageblit - REQUIRED function. Can use generic routines if
  470. * non acclerated hardware and packed pixel based.
  471. * Copies a image from system memory to the screen.
  472. *
  473. * @info: frame buffer structure that represents a single frame buffer
  474. * @image: structure defining the image.
  475. */
  476. static void ffb_imageblit(struct fb_info *info, const struct fb_image *image)
  477. {
  478. struct ffb_par *par = (struct ffb_par *) info->par;
  479. struct ffb_fbc *fbc = par->fbc;
  480. const u8 *data = image->data;
  481. unsigned long flags;
  482. u32 fg, bg, xy;
  483. u64 fgbg;
  484. int i, width, stride;
  485. if (image->depth > 1) {
  486. cfb_imageblit(info, image);
  487. return;
  488. }
  489. fg = ((u32 *)info->pseudo_palette)[image->fg_color];
  490. bg = ((u32 *)info->pseudo_palette)[image->bg_color];
  491. fgbg = ((u64) fg << 32) | (u64) bg;
  492. xy = (image->dy << 16) | image->dx;
  493. width = image->width;
  494. stride = ((width + 7) >> 3);
  495. spin_lock_irqsave(&par->lock, flags);
  496. if (fgbg != *(u64 *)&par->fg_cache) {
  497. FFBFifo(par, 2);
  498. upa_writeq(fgbg, &fbc->fg);
  499. *(u64 *)&par->fg_cache = fgbg;
  500. }
  501. if (width >= 32) {
  502. FFBFifo(par, 1);
  503. upa_writel(32, &fbc->fontw);
  504. }
  505. while (width >= 32) {
  506. const u8 *next_data = data + 4;
  507. FFBFifo(par, 1);
  508. upa_writel(xy, &fbc->fontxy);
  509. xy += (32 << 0);
  510. for (i = 0; i < image->height; i++) {
  511. u32 val = (((u32)data[0] << 24) |
  512. ((u32)data[1] << 16) |
  513. ((u32)data[2] << 8) |
  514. ((u32)data[3] << 0));
  515. FFBFifo(par, 1);
  516. upa_writel(val, &fbc->font);
  517. data += stride;
  518. }
  519. data = next_data;
  520. width -= 32;
  521. }
  522. if (width) {
  523. FFBFifo(par, 2);
  524. upa_writel(width, &fbc->fontw);
  525. upa_writel(xy, &fbc->fontxy);
  526. for (i = 0; i < image->height; i++) {
  527. u32 val = (((u32)data[0] << 24) |
  528. ((u32)data[1] << 16) |
  529. ((u32)data[2] << 8) |
  530. ((u32)data[3] << 0));
  531. FFBFifo(par, 1);
  532. upa_writel(val, &fbc->font);
  533. data += stride;
  534. }
  535. }
  536. spin_unlock_irqrestore(&par->lock, flags);
  537. }
  538. static void ffb_fixup_var_rgb(struct fb_var_screeninfo *var)
  539. {
  540. var->red.offset = 0;
  541. var->red.length = 8;
  542. var->green.offset = 8;
  543. var->green.length = 8;
  544. var->blue.offset = 16;
  545. var->blue.length = 8;
  546. var->transp.offset = 0;
  547. var->transp.length = 0;
  548. }
  549. /**
  550. * ffb_setcolreg - Optional function. Sets a color register.
  551. * @regno: boolean, 0 copy local, 1 get_user() function
  552. * @red: frame buffer colormap structure
  553. * @green: The green value which can be up to 16 bits wide
  554. * @blue: The blue value which can be up to 16 bits wide.
  555. * @transp: If supported the alpha value which can be up to 16 bits wide.
  556. * @info: frame buffer info structure
  557. */
  558. static int ffb_setcolreg(unsigned regno,
  559. unsigned red, unsigned green, unsigned blue,
  560. unsigned transp, struct fb_info *info)
  561. {
  562. u32 value;
  563. if (regno >= 256)
  564. return 1;
  565. red >>= 8;
  566. green >>= 8;
  567. blue >>= 8;
  568. value = (blue << 16) | (green << 8) | red;
  569. ((u32 *)info->pseudo_palette)[regno] = value;
  570. return 0;
  571. }
  572. /**
  573. * ffb_blank - Optional function. Blanks the display.
  574. * @blank_mode: the blank mode we want.
  575. * @info: frame buffer structure that represents a single frame buffer
  576. */
  577. static int
  578. ffb_blank(int blank, struct fb_info *info)
  579. {
  580. struct ffb_par *par = (struct ffb_par *) info->par;
  581. struct ffb_dac *dac = par->dac;
  582. unsigned long flags;
  583. u32 tmp;
  584. spin_lock_irqsave(&par->lock, flags);
  585. FFBWait(par);
  586. switch (blank) {
  587. case FB_BLANK_UNBLANK: /* Unblanking */
  588. upa_writel(0x6000, &dac->type);
  589. tmp = (upa_readl(&dac->value) | 0x1);
  590. upa_writel(0x6000, &dac->type);
  591. upa_writel(tmp, &dac->value);
  592. par->flags &= ~FFB_FLAG_BLANKED;
  593. break;
  594. case FB_BLANK_NORMAL: /* Normal blanking */
  595. case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
  596. case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
  597. case FB_BLANK_POWERDOWN: /* Poweroff */
  598. upa_writel(0x6000, &dac->type);
  599. tmp = (upa_readl(&dac->value) & ~0x1);
  600. upa_writel(0x6000, &dac->type);
  601. upa_writel(tmp, &dac->value);
  602. par->flags |= FFB_FLAG_BLANKED;
  603. break;
  604. }
  605. spin_unlock_irqrestore(&par->lock, flags);
  606. return 0;
  607. }
  608. static struct sbus_mmap_map ffb_mmap_map[] = {
  609. {
  610. .voff = FFB_SFB8R_VOFF,
  611. .poff = FFB_SFB8R_POFF,
  612. .size = 0x0400000
  613. },
  614. {
  615. .voff = FFB_SFB8G_VOFF,
  616. .poff = FFB_SFB8G_POFF,
  617. .size = 0x0400000
  618. },
  619. {
  620. .voff = FFB_SFB8B_VOFF,
  621. .poff = FFB_SFB8B_POFF,
  622. .size = 0x0400000
  623. },
  624. {
  625. .voff = FFB_SFB8X_VOFF,
  626. .poff = FFB_SFB8X_POFF,
  627. .size = 0x0400000
  628. },
  629. {
  630. .voff = FFB_SFB32_VOFF,
  631. .poff = FFB_SFB32_POFF,
  632. .size = 0x1000000
  633. },
  634. {
  635. .voff = FFB_SFB64_VOFF,
  636. .poff = FFB_SFB64_POFF,
  637. .size = 0x2000000
  638. },
  639. {
  640. .voff = FFB_FBC_REGS_VOFF,
  641. .poff = FFB_FBC_REGS_POFF,
  642. .size = 0x0002000
  643. },
  644. {
  645. .voff = FFB_BM_FBC_REGS_VOFF,
  646. .poff = FFB_BM_FBC_REGS_POFF,
  647. .size = 0x0002000
  648. },
  649. {
  650. .voff = FFB_DFB8R_VOFF,
  651. .poff = FFB_DFB8R_POFF,
  652. .size = 0x0400000
  653. },
  654. {
  655. .voff = FFB_DFB8G_VOFF,
  656. .poff = FFB_DFB8G_POFF,
  657. .size = 0x0400000
  658. },
  659. {
  660. .voff = FFB_DFB8B_VOFF,
  661. .poff = FFB_DFB8B_POFF,
  662. .size = 0x0400000
  663. },
  664. {
  665. .voff = FFB_DFB8X_VOFF,
  666. .poff = FFB_DFB8X_POFF,
  667. .size = 0x0400000
  668. },
  669. {
  670. .voff = FFB_DFB24_VOFF,
  671. .poff = FFB_DFB24_POFF,
  672. .size = 0x1000000
  673. },
  674. {
  675. .voff = FFB_DFB32_VOFF,
  676. .poff = FFB_DFB32_POFF,
  677. .size = 0x1000000
  678. },
  679. {
  680. .voff = FFB_FBC_KREGS_VOFF,
  681. .poff = FFB_FBC_KREGS_POFF,
  682. .size = 0x0002000
  683. },
  684. {
  685. .voff = FFB_DAC_VOFF,
  686. .poff = FFB_DAC_POFF,
  687. .size = 0x0002000
  688. },
  689. {
  690. .voff = FFB_PROM_VOFF,
  691. .poff = FFB_PROM_POFF,
  692. .size = 0x0010000
  693. },
  694. {
  695. .voff = FFB_EXP_VOFF,
  696. .poff = FFB_EXP_POFF,
  697. .size = 0x0002000
  698. },
  699. {
  700. .voff = FFB_DFB422A_VOFF,
  701. .poff = FFB_DFB422A_POFF,
  702. .size = 0x0800000
  703. },
  704. {
  705. .voff = FFB_DFB422AD_VOFF,
  706. .poff = FFB_DFB422AD_POFF,
  707. .size = 0x0800000
  708. },
  709. {
  710. .voff = FFB_DFB24B_VOFF,
  711. .poff = FFB_DFB24B_POFF,
  712. .size = 0x1000000
  713. },
  714. {
  715. .voff = FFB_DFB422B_VOFF,
  716. .poff = FFB_DFB422B_POFF,
  717. .size = 0x0800000
  718. },
  719. {
  720. .voff = FFB_DFB422BD_VOFF,
  721. .poff = FFB_DFB422BD_POFF,
  722. .size = 0x0800000
  723. },
  724. {
  725. .voff = FFB_SFB16Z_VOFF,
  726. .poff = FFB_SFB16Z_POFF,
  727. .size = 0x0800000
  728. },
  729. {
  730. .voff = FFB_SFB8Z_VOFF,
  731. .poff = FFB_SFB8Z_POFF,
  732. .size = 0x0800000
  733. },
  734. {
  735. .voff = FFB_SFB422_VOFF,
  736. .poff = FFB_SFB422_POFF,
  737. .size = 0x0800000
  738. },
  739. {
  740. .voff = FFB_SFB422D_VOFF,
  741. .poff = FFB_SFB422D_POFF,
  742. .size = 0x0800000
  743. },
  744. { .size = 0 }
  745. };
  746. static int ffb_mmap(struct fb_info *info, struct vm_area_struct *vma)
  747. {
  748. struct ffb_par *par = (struct ffb_par *)info->par;
  749. return sbusfb_mmap_helper(ffb_mmap_map,
  750. par->physbase, par->fbsize,
  751. 0, vma);
  752. }
  753. static int ffb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
  754. {
  755. struct ffb_par *par = (struct ffb_par *) info->par;
  756. return sbusfb_ioctl_helper(cmd, arg, info,
  757. FBTYPE_CREATOR, 24, par->fbsize);
  758. }
  759. /*
  760. * Initialisation
  761. */
  762. static void
  763. ffb_init_fix(struct fb_info *info)
  764. {
  765. struct ffb_par *par = (struct ffb_par *)info->par;
  766. const char *ffb_type_name;
  767. if (!(par->flags & FFB_FLAG_AFB)) {
  768. if ((par->board_type & 0x7) == 0x3)
  769. ffb_type_name = "Creator 3D";
  770. else
  771. ffb_type_name = "Creator";
  772. } else
  773. ffb_type_name = "Elite 3D";
  774. strlcpy(info->fix.id, ffb_type_name, sizeof(info->fix.id));
  775. info->fix.type = FB_TYPE_PACKED_PIXELS;
  776. info->fix.visual = FB_VISUAL_TRUECOLOR;
  777. /* Framebuffer length is the same regardless of resolution. */
  778. info->fix.line_length = 8192;
  779. info->fix.accel = FB_ACCEL_SUN_CREATOR;
  780. }
  781. static int ffb_apply_upa_parent_ranges(int parent,
  782. struct linux_prom64_registers *regs)
  783. {
  784. struct linux_prom64_ranges ranges[PROMREG_MAX];
  785. char name[128];
  786. int len, i;
  787. prom_getproperty(parent, "name", name, sizeof(name));
  788. if (strcmp(name, "upa") != 0)
  789. return 0;
  790. len = prom_getproperty(parent, "ranges", (void *) ranges, sizeof(ranges));
  791. if (len <= 0)
  792. return 1;
  793. len /= sizeof(struct linux_prom64_ranges);
  794. for (i = 0; i < len; i++) {
  795. struct linux_prom64_ranges *rng = &ranges[i];
  796. u64 phys_addr = regs->phys_addr;
  797. if (phys_addr >= rng->ot_child_base &&
  798. phys_addr < (rng->ot_child_base + rng->or_size)) {
  799. regs->phys_addr -= rng->ot_child_base;
  800. regs->phys_addr += rng->ot_parent_base;
  801. return 0;
  802. }
  803. }
  804. return 1;
  805. }
  806. struct all_info {
  807. struct fb_info info;
  808. struct ffb_par par;
  809. u32 pseudo_palette[256];
  810. struct list_head list;
  811. };
  812. static LIST_HEAD(ffb_list);
  813. static void ffb_init_one(int node, int parent)
  814. {
  815. struct linux_prom64_registers regs[2*PROMREG_MAX];
  816. struct ffb_fbc *fbc;
  817. struct ffb_dac *dac;
  818. struct all_info *all;
  819. if (prom_getproperty(node, "reg", (void *) regs, sizeof(regs)) <= 0) {
  820. printk("ffb: Cannot get reg device node property.\n");
  821. return;
  822. }
  823. if (ffb_apply_upa_parent_ranges(parent, &regs[0])) {
  824. printk("ffb: Cannot apply parent ranges to regs.\n");
  825. return;
  826. }
  827. all = kmalloc(sizeof(*all), GFP_KERNEL);
  828. if (!all) {
  829. printk(KERN_ERR "ffb: Cannot allocate memory.\n");
  830. return;
  831. }
  832. memset(all, 0, sizeof(*all));
  833. INIT_LIST_HEAD(&all->list);
  834. spin_lock_init(&all->par.lock);
  835. all->par.fbc = (struct ffb_fbc *)(regs[0].phys_addr + FFB_FBC_REGS_POFF);
  836. all->par.dac = (struct ffb_dac *)(regs[0].phys_addr + FFB_DAC_POFF);
  837. all->par.rop_cache = FFB_ROP_NEW;
  838. all->par.physbase = regs[0].phys_addr;
  839. all->par.prom_node = node;
  840. all->par.prom_parent_node = parent;
  841. /* Don't mention copyarea, so SCROLL_REDRAW is always
  842. * used. It is the fastest on this chip.
  843. */
  844. all->info.flags = (FBINFO_DEFAULT |
  845. /* FBINFO_HWACCEL_COPYAREA | */
  846. FBINFO_HWACCEL_FILLRECT |
  847. FBINFO_HWACCEL_IMAGEBLIT);
  848. all->info.fbops = &ffb_ops;
  849. all->info.screen_base = (char *) all->par.physbase + FFB_DFB24_POFF;
  850. all->info.par = &all->par;
  851. all->info.pseudo_palette = all->pseudo_palette;
  852. sbusfb_fill_var(&all->info.var, all->par.prom_node, 32);
  853. all->par.fbsize = PAGE_ALIGN(all->info.var.xres *
  854. all->info.var.yres *
  855. 4);
  856. ffb_fixup_var_rgb(&all->info.var);
  857. all->info.var.accel_flags = FB_ACCELF_TEXT;
  858. prom_getstring(node, "name", all->par.name, sizeof(all->par.name));
  859. if (!strcmp(all->par.name, "SUNW,afb"))
  860. all->par.flags |= FFB_FLAG_AFB;
  861. all->par.board_type = prom_getintdefault(node, "board_type", 0);
  862. fbc = all->par.fbc;
  863. if((upa_readl(&fbc->ucsr) & FFB_UCSR_ALL_ERRORS) != 0)
  864. upa_writel(FFB_UCSR_ALL_ERRORS, &fbc->ucsr);
  865. ffb_switch_from_graph(&all->par);
  866. dac = all->par.dac;
  867. upa_writel(0x8000, &dac->type);
  868. all->par.dac_rev = upa_readl(&dac->value) >> 0x1c;
  869. /* Elite3D has different DAC revision numbering, and no DAC revisions
  870. * have the reversed meaning of cursor enable.
  871. */
  872. if (all->par.flags & FFB_FLAG_AFB)
  873. all->par.dac_rev = 10;
  874. /* Unblank it just to be sure. When there are multiple
  875. * FFB/AFB cards in the system, or it is not the OBP
  876. * chosen console, it will have video outputs off in
  877. * the DAC.
  878. */
  879. ffb_blank(0, &all->info);
  880. if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
  881. printk(KERN_ERR "ffb: Could not allocate color map.\n");
  882. kfree(all);
  883. return;
  884. }
  885. ffb_init_fix(&all->info);
  886. if (register_framebuffer(&all->info) < 0) {
  887. printk(KERN_ERR "ffb: Could not register framebuffer.\n");
  888. fb_dealloc_cmap(&all->info.cmap);
  889. kfree(all);
  890. return;
  891. }
  892. list_add(&all->list, &ffb_list);
  893. printk("ffb: %s at %016lx type %d DAC %d\n",
  894. ((all->par.flags & FFB_FLAG_AFB) ? "AFB" : "FFB"),
  895. regs[0].phys_addr, all->par.board_type, all->par.dac_rev);
  896. }
  897. static void ffb_scan_siblings(int root)
  898. {
  899. int node, child;
  900. child = prom_getchild(root);
  901. for (node = prom_searchsiblings(child, "SUNW,ffb"); node;
  902. node = prom_searchsiblings(prom_getsibling(node), "SUNW,ffb"))
  903. ffb_init_one(node, root);
  904. for (node = prom_searchsiblings(child, "SUNW,afb"); node;
  905. node = prom_searchsiblings(prom_getsibling(node), "SUNW,afb"))
  906. ffb_init_one(node, root);
  907. }
  908. int __init ffb_init(void)
  909. {
  910. int root;
  911. if (fb_get_options("ffb", NULL))
  912. return -ENODEV;
  913. ffb_scan_siblings(prom_root_node);
  914. root = prom_getchild(prom_root_node);
  915. for (root = prom_searchsiblings(root, "upa"); root;
  916. root = prom_searchsiblings(prom_getsibling(root), "upa"))
  917. ffb_scan_siblings(root);
  918. return 0;
  919. }
  920. void __exit ffb_exit(void)
  921. {
  922. struct list_head *pos, *tmp;
  923. list_for_each_safe(pos, tmp, &ffb_list) {
  924. struct all_info *all = list_entry(pos, typeof(*all), list);
  925. unregister_framebuffer(&all->info);
  926. fb_dealloc_cmap(&all->info.cmap);
  927. kfree(all);
  928. }
  929. }
  930. int __init
  931. ffb_setup(char *arg)
  932. {
  933. /* No cmdline options yet... */
  934. return 0;
  935. }
  936. module_init(ffb_init);
  937. #ifdef MODULE
  938. module_exit(ffb_exit);
  939. #endif
  940. MODULE_DESCRIPTION("framebuffer driver for Creator/Elite3D chipsets");
  941. MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
  942. MODULE_LICENSE("GPL");