ffb.c 25 KB

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