ffb.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  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 file *, struct vm_area_struct *);
  35. static int ffb_ioctl(struct inode *, struct file *, unsigned int,
  36. unsigned long, struct fb_info *);
  37. static int ffb_pan_display(struct fb_var_screeninfo *, struct fb_info *);
  38. /*
  39. * Frame buffer operations
  40. */
  41. static struct fb_ops ffb_ops = {
  42. .owner = THIS_MODULE,
  43. .fb_setcolreg = ffb_setcolreg,
  44. .fb_blank = ffb_blank,
  45. .fb_pan_display = ffb_pan_display,
  46. .fb_fillrect = ffb_fillrect,
  47. .fb_copyarea = ffb_copyarea,
  48. .fb_imageblit = ffb_imageblit,
  49. .fb_sync = ffb_sync,
  50. .fb_mmap = ffb_mmap,
  51. .fb_ioctl = ffb_ioctl,
  52. /* XXX Use FFB hw cursor once fb cursor API is better understood... */
  53. .fb_cursor = soft_cursor,
  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. struct list_head list;
  326. };
  327. static void FFBFifo(struct ffb_par *par, int n)
  328. {
  329. struct ffb_fbc *fbc;
  330. int cache = par->fifo_cache;
  331. if (cache - n < 0) {
  332. fbc = par->fbc;
  333. do { cache = (upa_readl(&fbc->ucsr) & FFB_UCSR_FIFO_MASK) - 8;
  334. } while (cache - n < 0);
  335. }
  336. par->fifo_cache = cache - n;
  337. }
  338. static void FFBWait(struct ffb_par *par)
  339. {
  340. struct ffb_fbc *fbc;
  341. int limit = 10000;
  342. fbc = par->fbc;
  343. do {
  344. if ((upa_readl(&fbc->ucsr) & FFB_UCSR_ALL_BUSY) == 0)
  345. break;
  346. if ((upa_readl(&fbc->ucsr) & FFB_UCSR_ALL_ERRORS) != 0) {
  347. upa_writel(FFB_UCSR_ALL_ERRORS, &fbc->ucsr);
  348. }
  349. udelay(10);
  350. } while(--limit > 0);
  351. }
  352. static int ffb_sync(struct fb_info *p)
  353. {
  354. struct ffb_par *par = (struct ffb_par *) p->par;
  355. FFBWait(par);
  356. return 0;
  357. }
  358. static __inline__ void ffb_rop(struct ffb_par *par, u32 rop)
  359. {
  360. if (par->rop_cache != rop) {
  361. FFBFifo(par, 1);
  362. upa_writel(rop, &par->fbc->rop);
  363. par->rop_cache = rop;
  364. }
  365. }
  366. static void ffb_switch_from_graph(struct ffb_par *par)
  367. {
  368. struct ffb_fbc *fbc = par->fbc;
  369. struct ffb_dac *dac = par->dac;
  370. unsigned long flags;
  371. spin_lock_irqsave(&par->lock, flags);
  372. FFBWait(par);
  373. par->fifo_cache = 0;
  374. FFBFifo(par, 7);
  375. upa_writel(FFB_PPC_VCE_DISABLE|FFB_PPC_TBE_OPAQUE|
  376. FFB_PPC_APE_DISABLE|FFB_PPC_CS_CONST,
  377. &fbc->ppc);
  378. upa_writel(0x2000707f, &fbc->fbc);
  379. upa_writel(par->rop_cache, &fbc->rop);
  380. upa_writel(0xffffffff, &fbc->pmask);
  381. upa_writel((1 << 16) | (0 << 0), &fbc->fontinc);
  382. upa_writel(par->fg_cache, &fbc->fg);
  383. upa_writel(par->bg_cache, &fbc->bg);
  384. FFBWait(par);
  385. /* Disable cursor. */
  386. upa_writel(0x100, &dac->type2);
  387. if (par->dac_rev <= 2)
  388. upa_writel(0, &dac->value2);
  389. else
  390. upa_writel(3, &dac->value2);
  391. spin_unlock_irqrestore(&par->lock, flags);
  392. }
  393. static int ffb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  394. {
  395. struct ffb_par *par = (struct ffb_par *) info->par;
  396. /* We just use this to catch switches out of
  397. * graphics mode.
  398. */
  399. ffb_switch_from_graph(par);
  400. if (var->xoffset || var->yoffset || var->vmode)
  401. return -EINVAL;
  402. return 0;
  403. }
  404. /**
  405. * ffb_fillrect - REQUIRED function. Can use generic routines if
  406. * non acclerated hardware and packed pixel based.
  407. * Draws a rectangle on the screen.
  408. *
  409. * @info: frame buffer structure that represents a single frame buffer
  410. * @rect: structure defining the rectagle and operation.
  411. */
  412. static void ffb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  413. {
  414. struct ffb_par *par = (struct ffb_par *) info->par;
  415. struct ffb_fbc *fbc = par->fbc;
  416. unsigned long flags;
  417. u32 fg;
  418. if (rect->rop != ROP_COPY && rect->rop != ROP_XOR)
  419. BUG();
  420. fg = ((u32 *)info->pseudo_palette)[rect->color];
  421. spin_lock_irqsave(&par->lock, flags);
  422. if (fg != par->fg_cache) {
  423. FFBFifo(par, 1);
  424. upa_writel(fg, &fbc->fg);
  425. par->fg_cache = fg;
  426. }
  427. ffb_rop(par, (rect->rop == ROP_COPY ?
  428. FFB_ROP_NEW :
  429. FFB_ROP_NEW_XOR_OLD));
  430. FFBFifo(par, 5);
  431. upa_writel(FFB_DRAWOP_RECTANGLE, &fbc->drawop);
  432. upa_writel(rect->dy, &fbc->by);
  433. upa_writel(rect->dx, &fbc->bx);
  434. upa_writel(rect->height, &fbc->bh);
  435. upa_writel(rect->width, &fbc->bw);
  436. spin_unlock_irqrestore(&par->lock, flags);
  437. }
  438. /**
  439. * ffb_copyarea - REQUIRED function. Can use generic routines if
  440. * non acclerated hardware and packed pixel based.
  441. * Copies on area of the screen to another area.
  442. *
  443. * @info: frame buffer structure that represents a single frame buffer
  444. * @area: structure defining the source and destination.
  445. */
  446. static void
  447. ffb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
  448. {
  449. struct ffb_par *par = (struct ffb_par *) info->par;
  450. struct ffb_fbc *fbc = par->fbc;
  451. unsigned long flags;
  452. if (area->dx != area->sx ||
  453. area->dy == area->sy) {
  454. cfb_copyarea(info, area);
  455. return;
  456. }
  457. spin_lock_irqsave(&par->lock, flags);
  458. ffb_rop(par, FFB_ROP_OLD);
  459. FFBFifo(par, 7);
  460. upa_writel(FFB_DRAWOP_VSCROLL, &fbc->drawop);
  461. upa_writel(area->sy, &fbc->by);
  462. upa_writel(area->sx, &fbc->bx);
  463. upa_writel(area->dy, &fbc->dy);
  464. upa_writel(area->dx, &fbc->dx);
  465. upa_writel(area->height, &fbc->bh);
  466. upa_writel(area->width, &fbc->bw);
  467. spin_unlock_irqrestore(&par->lock, flags);
  468. }
  469. /**
  470. * ffb_imageblit - REQUIRED function. Can use generic routines if
  471. * non acclerated hardware and packed pixel based.
  472. * Copies a image from system memory to the screen.
  473. *
  474. * @info: frame buffer structure that represents a single frame buffer
  475. * @image: structure defining the image.
  476. */
  477. static void ffb_imageblit(struct fb_info *info, const struct fb_image *image)
  478. {
  479. struct ffb_par *par = (struct ffb_par *) info->par;
  480. struct ffb_fbc *fbc = par->fbc;
  481. const u8 *data = image->data;
  482. unsigned long flags;
  483. u32 fg, bg, xy;
  484. u64 fgbg;
  485. int i, width, stride;
  486. if (image->depth > 1) {
  487. cfb_imageblit(info, image);
  488. return;
  489. }
  490. fg = ((u32 *)info->pseudo_palette)[image->fg_color];
  491. bg = ((u32 *)info->pseudo_palette)[image->bg_color];
  492. fgbg = ((u64) fg << 32) | (u64) bg;
  493. xy = (image->dy << 16) | image->dx;
  494. width = image->width;
  495. stride = ((width + 7) >> 3);
  496. spin_lock_irqsave(&par->lock, flags);
  497. if (fgbg != *(u64 *)&par->fg_cache) {
  498. FFBFifo(par, 2);
  499. upa_writeq(fgbg, &fbc->fg);
  500. *(u64 *)&par->fg_cache = fgbg;
  501. }
  502. if (width >= 32) {
  503. FFBFifo(par, 1);
  504. upa_writel(32, &fbc->fontw);
  505. }
  506. while (width >= 32) {
  507. const u8 *next_data = data + 4;
  508. FFBFifo(par, 1);
  509. upa_writel(xy, &fbc->fontxy);
  510. xy += (32 << 0);
  511. for (i = 0; i < image->height; i++) {
  512. u32 val = (((u32)data[0] << 24) |
  513. ((u32)data[1] << 16) |
  514. ((u32)data[2] << 8) |
  515. ((u32)data[3] << 0));
  516. FFBFifo(par, 1);
  517. upa_writel(val, &fbc->font);
  518. data += stride;
  519. }
  520. data = next_data;
  521. width -= 32;
  522. }
  523. if (width) {
  524. FFBFifo(par, 2);
  525. upa_writel(width, &fbc->fontw);
  526. upa_writel(xy, &fbc->fontxy);
  527. for (i = 0; i < image->height; i++) {
  528. u32 val = (((u32)data[0] << 24) |
  529. ((u32)data[1] << 16) |
  530. ((u32)data[2] << 8) |
  531. ((u32)data[3] << 0));
  532. FFBFifo(par, 1);
  533. upa_writel(val, &fbc->font);
  534. data += stride;
  535. }
  536. }
  537. spin_unlock_irqrestore(&par->lock, flags);
  538. }
  539. static void ffb_fixup_var_rgb(struct fb_var_screeninfo *var)
  540. {
  541. var->red.offset = 0;
  542. var->red.length = 8;
  543. var->green.offset = 8;
  544. var->green.length = 8;
  545. var->blue.offset = 16;
  546. var->blue.length = 8;
  547. var->transp.offset = 0;
  548. var->transp.length = 0;
  549. }
  550. /**
  551. * ffb_setcolreg - Optional function. Sets a color register.
  552. * @regno: boolean, 0 copy local, 1 get_user() function
  553. * @red: frame buffer colormap structure
  554. * @green: The green value which can be up to 16 bits wide
  555. * @blue: The blue value which can be up to 16 bits wide.
  556. * @transp: If supported the alpha value which can be up to 16 bits wide.
  557. * @info: frame buffer info structure
  558. */
  559. static int ffb_setcolreg(unsigned regno,
  560. unsigned red, unsigned green, unsigned blue,
  561. unsigned transp, struct fb_info *info)
  562. {
  563. u32 value;
  564. if (regno >= 256)
  565. return 1;
  566. red >>= 8;
  567. green >>= 8;
  568. blue >>= 8;
  569. value = (blue << 16) | (green << 8) | red;
  570. ((u32 *)info->pseudo_palette)[regno] = value;
  571. return 0;
  572. }
  573. /**
  574. * ffb_blank - Optional function. Blanks the display.
  575. * @blank_mode: the blank mode we want.
  576. * @info: frame buffer structure that represents a single frame buffer
  577. */
  578. static int
  579. ffb_blank(int blank, struct fb_info *info)
  580. {
  581. struct ffb_par *par = (struct ffb_par *) info->par;
  582. struct ffb_dac *dac = par->dac;
  583. unsigned long flags;
  584. u32 tmp;
  585. spin_lock_irqsave(&par->lock, flags);
  586. FFBWait(par);
  587. switch (blank) {
  588. case FB_BLANK_UNBLANK: /* Unblanking */
  589. upa_writel(0x6000, &dac->type);
  590. tmp = (upa_readl(&dac->value) | 0x1);
  591. upa_writel(0x6000, &dac->type);
  592. upa_writel(tmp, &dac->value);
  593. par->flags &= ~FFB_FLAG_BLANKED;
  594. break;
  595. case FB_BLANK_NORMAL: /* Normal blanking */
  596. case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
  597. case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
  598. case FB_BLANK_POWERDOWN: /* Poweroff */
  599. upa_writel(0x6000, &dac->type);
  600. tmp = (upa_readl(&dac->value) & ~0x1);
  601. upa_writel(0x6000, &dac->type);
  602. upa_writel(tmp, &dac->value);
  603. par->flags |= FFB_FLAG_BLANKED;
  604. break;
  605. }
  606. spin_unlock_irqrestore(&par->lock, flags);
  607. return 0;
  608. }
  609. static struct sbus_mmap_map ffb_mmap_map[] = {
  610. {
  611. .voff = FFB_SFB8R_VOFF,
  612. .poff = FFB_SFB8R_POFF,
  613. .size = 0x0400000
  614. },
  615. {
  616. .voff = FFB_SFB8G_VOFF,
  617. .poff = FFB_SFB8G_POFF,
  618. .size = 0x0400000
  619. },
  620. {
  621. .voff = FFB_SFB8B_VOFF,
  622. .poff = FFB_SFB8B_POFF,
  623. .size = 0x0400000
  624. },
  625. {
  626. .voff = FFB_SFB8X_VOFF,
  627. .poff = FFB_SFB8X_POFF,
  628. .size = 0x0400000
  629. },
  630. {
  631. .voff = FFB_SFB32_VOFF,
  632. .poff = FFB_SFB32_POFF,
  633. .size = 0x1000000
  634. },
  635. {
  636. .voff = FFB_SFB64_VOFF,
  637. .poff = FFB_SFB64_POFF,
  638. .size = 0x2000000
  639. },
  640. {
  641. .voff = FFB_FBC_REGS_VOFF,
  642. .poff = FFB_FBC_REGS_POFF,
  643. .size = 0x0002000
  644. },
  645. {
  646. .voff = FFB_BM_FBC_REGS_VOFF,
  647. .poff = FFB_BM_FBC_REGS_POFF,
  648. .size = 0x0002000
  649. },
  650. {
  651. .voff = FFB_DFB8R_VOFF,
  652. .poff = FFB_DFB8R_POFF,
  653. .size = 0x0400000
  654. },
  655. {
  656. .voff = FFB_DFB8G_VOFF,
  657. .poff = FFB_DFB8G_POFF,
  658. .size = 0x0400000
  659. },
  660. {
  661. .voff = FFB_DFB8B_VOFF,
  662. .poff = FFB_DFB8B_POFF,
  663. .size = 0x0400000
  664. },
  665. {
  666. .voff = FFB_DFB8X_VOFF,
  667. .poff = FFB_DFB8X_POFF,
  668. .size = 0x0400000
  669. },
  670. {
  671. .voff = FFB_DFB24_VOFF,
  672. .poff = FFB_DFB24_POFF,
  673. .size = 0x1000000
  674. },
  675. {
  676. .voff = FFB_DFB32_VOFF,
  677. .poff = FFB_DFB32_POFF,
  678. .size = 0x1000000
  679. },
  680. {
  681. .voff = FFB_FBC_KREGS_VOFF,
  682. .poff = FFB_FBC_KREGS_POFF,
  683. .size = 0x0002000
  684. },
  685. {
  686. .voff = FFB_DAC_VOFF,
  687. .poff = FFB_DAC_POFF,
  688. .size = 0x0002000
  689. },
  690. {
  691. .voff = FFB_PROM_VOFF,
  692. .poff = FFB_PROM_POFF,
  693. .size = 0x0010000
  694. },
  695. {
  696. .voff = FFB_EXP_VOFF,
  697. .poff = FFB_EXP_POFF,
  698. .size = 0x0002000
  699. },
  700. {
  701. .voff = FFB_DFB422A_VOFF,
  702. .poff = FFB_DFB422A_POFF,
  703. .size = 0x0800000
  704. },
  705. {
  706. .voff = FFB_DFB422AD_VOFF,
  707. .poff = FFB_DFB422AD_POFF,
  708. .size = 0x0800000
  709. },
  710. {
  711. .voff = FFB_DFB24B_VOFF,
  712. .poff = FFB_DFB24B_POFF,
  713. .size = 0x1000000
  714. },
  715. {
  716. .voff = FFB_DFB422B_VOFF,
  717. .poff = FFB_DFB422B_POFF,
  718. .size = 0x0800000
  719. },
  720. {
  721. .voff = FFB_DFB422BD_VOFF,
  722. .poff = FFB_DFB422BD_POFF,
  723. .size = 0x0800000
  724. },
  725. {
  726. .voff = FFB_SFB16Z_VOFF,
  727. .poff = FFB_SFB16Z_POFF,
  728. .size = 0x0800000
  729. },
  730. {
  731. .voff = FFB_SFB8Z_VOFF,
  732. .poff = FFB_SFB8Z_POFF,
  733. .size = 0x0800000
  734. },
  735. {
  736. .voff = FFB_SFB422_VOFF,
  737. .poff = FFB_SFB422_POFF,
  738. .size = 0x0800000
  739. },
  740. {
  741. .voff = FFB_SFB422D_VOFF,
  742. .poff = FFB_SFB422D_POFF,
  743. .size = 0x0800000
  744. },
  745. { .size = 0 }
  746. };
  747. static int ffb_mmap(struct fb_info *info, struct file *file, struct vm_area_struct *vma)
  748. {
  749. struct ffb_par *par = (struct ffb_par *)info->par;
  750. return sbusfb_mmap_helper(ffb_mmap_map,
  751. par->physbase, par->fbsize,
  752. 0, vma);
  753. }
  754. static int ffb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
  755. unsigned long arg, struct fb_info *info)
  756. {
  757. struct ffb_par *par = (struct ffb_par *) info->par;
  758. return sbusfb_ioctl_helper(cmd, arg, info,
  759. FBTYPE_CREATOR, 24, par->fbsize);
  760. }
  761. /*
  762. * Initialisation
  763. */
  764. static void
  765. ffb_init_fix(struct fb_info *info)
  766. {
  767. struct ffb_par *par = (struct ffb_par *)info->par;
  768. const char *ffb_type_name;
  769. if (!(par->flags & FFB_FLAG_AFB)) {
  770. if ((par->board_type & 0x7) == 0x3)
  771. ffb_type_name = "Creator 3D";
  772. else
  773. ffb_type_name = "Creator";
  774. } else
  775. ffb_type_name = "Elite 3D";
  776. strlcpy(info->fix.id, ffb_type_name, sizeof(info->fix.id));
  777. info->fix.type = FB_TYPE_PACKED_PIXELS;
  778. info->fix.visual = FB_VISUAL_TRUECOLOR;
  779. /* Framebuffer length is the same regardless of resolution. */
  780. info->fix.line_length = 8192;
  781. info->fix.accel = FB_ACCEL_SUN_CREATOR;
  782. }
  783. static int ffb_apply_upa_parent_ranges(int parent,
  784. struct linux_prom64_registers *regs)
  785. {
  786. struct linux_prom64_ranges ranges[PROMREG_MAX];
  787. char name[128];
  788. int len, i;
  789. prom_getproperty(parent, "name", name, sizeof(name));
  790. if (strcmp(name, "upa") != 0)
  791. return 0;
  792. len = prom_getproperty(parent, "ranges", (void *) ranges, sizeof(ranges));
  793. if (len <= 0)
  794. return 1;
  795. len /= sizeof(struct linux_prom64_ranges);
  796. for (i = 0; i < len; i++) {
  797. struct linux_prom64_ranges *rng = &ranges[i];
  798. u64 phys_addr = regs->phys_addr;
  799. if (phys_addr >= rng->ot_child_base &&
  800. phys_addr < (rng->ot_child_base + rng->or_size)) {
  801. regs->phys_addr -= rng->ot_child_base;
  802. regs->phys_addr += rng->ot_parent_base;
  803. return 0;
  804. }
  805. }
  806. return 1;
  807. }
  808. struct all_info {
  809. struct fb_info info;
  810. struct ffb_par par;
  811. u32 pseudo_palette[256];
  812. struct list_head list;
  813. };
  814. static LIST_HEAD(ffb_list);
  815. static void ffb_init_one(int node, int parent)
  816. {
  817. struct linux_prom64_registers regs[2*PROMREG_MAX];
  818. struct ffb_fbc *fbc;
  819. struct ffb_dac *dac;
  820. struct all_info *all;
  821. if (prom_getproperty(node, "reg", (void *) regs, sizeof(regs)) <= 0) {
  822. printk("ffb: Cannot get reg device node property.\n");
  823. return;
  824. }
  825. if (ffb_apply_upa_parent_ranges(parent, &regs[0])) {
  826. printk("ffb: Cannot apply parent ranges to regs.\n");
  827. return;
  828. }
  829. all = kmalloc(sizeof(*all), GFP_KERNEL);
  830. if (!all) {
  831. printk(KERN_ERR "ffb: Cannot allocate memory.\n");
  832. return;
  833. }
  834. memset(all, 0, sizeof(*all));
  835. INIT_LIST_HEAD(&all->list);
  836. spin_lock_init(&all->par.lock);
  837. all->par.fbc = (struct ffb_fbc *)(regs[0].phys_addr + FFB_FBC_REGS_POFF);
  838. all->par.dac = (struct ffb_dac *)(regs[0].phys_addr + FFB_DAC_POFF);
  839. all->par.rop_cache = FFB_ROP_NEW;
  840. all->par.physbase = regs[0].phys_addr;
  841. all->par.prom_node = node;
  842. all->par.prom_parent_node = parent;
  843. /* Don't mention copyarea, so SCROLL_REDRAW is always
  844. * used. It is the fastest on this chip.
  845. */
  846. all->info.flags = (FBINFO_DEFAULT |
  847. /* FBINFO_HWACCEL_COPYAREA | */
  848. FBINFO_HWACCEL_FILLRECT |
  849. FBINFO_HWACCEL_IMAGEBLIT);
  850. all->info.fbops = &ffb_ops;
  851. all->info.screen_base = (char *) all->par.physbase + FFB_DFB24_POFF;
  852. all->info.par = &all->par;
  853. all->info.pseudo_palette = all->pseudo_palette;
  854. sbusfb_fill_var(&all->info.var, all->par.prom_node, 32);
  855. all->par.fbsize = PAGE_ALIGN(all->info.var.xres *
  856. all->info.var.yres *
  857. 4);
  858. ffb_fixup_var_rgb(&all->info.var);
  859. all->info.var.accel_flags = FB_ACCELF_TEXT;
  860. prom_getstring(node, "name", all->par.name, sizeof(all->par.name));
  861. if (!strcmp(all->par.name, "SUNW,afb"))
  862. all->par.flags |= FFB_FLAG_AFB;
  863. all->par.board_type = prom_getintdefault(node, "board_type", 0);
  864. fbc = all->par.fbc;
  865. if((upa_readl(&fbc->ucsr) & FFB_UCSR_ALL_ERRORS) != 0)
  866. upa_writel(FFB_UCSR_ALL_ERRORS, &fbc->ucsr);
  867. ffb_switch_from_graph(&all->par);
  868. dac = all->par.dac;
  869. upa_writel(0x8000, &dac->type);
  870. all->par.dac_rev = upa_readl(&dac->value) >> 0x1c;
  871. /* Elite3D has different DAC revision numbering, and no DAC revisions
  872. * have the reversed meaning of cursor enable.
  873. */
  874. if (all->par.flags & FFB_FLAG_AFB)
  875. all->par.dac_rev = 10;
  876. /* Unblank it just to be sure. When there are multiple
  877. * FFB/AFB cards in the system, or it is not the OBP
  878. * chosen console, it will have video outputs off in
  879. * the DAC.
  880. */
  881. ffb_blank(0, &all->info);
  882. if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
  883. printk(KERN_ERR "ffb: Could not allocate color map.\n");
  884. kfree(all);
  885. return;
  886. }
  887. ffb_init_fix(&all->info);
  888. if (register_framebuffer(&all->info) < 0) {
  889. printk(KERN_ERR "ffb: Could not register framebuffer.\n");
  890. fb_dealloc_cmap(&all->info.cmap);
  891. kfree(all);
  892. return;
  893. }
  894. list_add(&all->list, &ffb_list);
  895. printk("ffb: %s at %016lx type %d DAC %d\n",
  896. ((all->par.flags & FFB_FLAG_AFB) ? "AFB" : "FFB"),
  897. regs[0].phys_addr, all->par.board_type, all->par.dac_rev);
  898. }
  899. static void ffb_scan_siblings(int root)
  900. {
  901. int node, child;
  902. child = prom_getchild(root);
  903. for (node = prom_searchsiblings(child, "SUNW,ffb"); node;
  904. node = prom_searchsiblings(prom_getsibling(node), "SUNW,ffb"))
  905. ffb_init_one(node, root);
  906. for (node = prom_searchsiblings(child, "SUNW,afb"); node;
  907. node = prom_searchsiblings(prom_getsibling(node), "SUNW,afb"))
  908. ffb_init_one(node, root);
  909. }
  910. int __init ffb_init(void)
  911. {
  912. int root;
  913. if (fb_get_options("ffb", NULL))
  914. return -ENODEV;
  915. ffb_scan_siblings(prom_root_node);
  916. root = prom_getchild(prom_root_node);
  917. for (root = prom_searchsiblings(root, "upa"); root;
  918. root = prom_searchsiblings(prom_getsibling(root), "upa"))
  919. ffb_scan_siblings(root);
  920. return 0;
  921. }
  922. void __exit ffb_exit(void)
  923. {
  924. struct list_head *pos, *tmp;
  925. list_for_each_safe(pos, tmp, &ffb_list) {
  926. struct all_info *all = list_entry(pos, typeof(*all), list);
  927. unregister_framebuffer(&all->info);
  928. fb_dealloc_cmap(&all->info.cmap);
  929. kfree(all);
  930. }
  931. }
  932. int __init
  933. ffb_setup(char *arg)
  934. {
  935. /* No cmdline options yet... */
  936. return 0;
  937. }
  938. module_init(ffb_init);
  939. #ifdef MODULE
  940. module_exit(ffb_exit);
  941. #endif
  942. MODULE_DESCRIPTION("framebuffer driver for Creator/Elite3D chipsets");
  943. MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
  944. MODULE_LICENSE("GPL");