ffb.c 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  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 {
  345. cache = (upa_readl(&fbc->ucsr) & FFB_UCSR_FIFO_MASK);
  346. cache -= 8;
  347. } while (cache - n < 0);
  348. }
  349. par->fifo_cache = cache - n;
  350. }
  351. static void FFBWait(struct ffb_par *par)
  352. {
  353. struct ffb_fbc __iomem *fbc;
  354. int limit = 10000;
  355. fbc = par->fbc;
  356. do {
  357. if ((upa_readl(&fbc->ucsr) & FFB_UCSR_ALL_BUSY) == 0)
  358. break;
  359. if ((upa_readl(&fbc->ucsr) & FFB_UCSR_ALL_ERRORS) != 0) {
  360. upa_writel(FFB_UCSR_ALL_ERRORS, &fbc->ucsr);
  361. }
  362. udelay(10);
  363. } while (--limit > 0);
  364. }
  365. static int ffb_sync(struct fb_info *p)
  366. {
  367. struct ffb_par *par = (struct ffb_par *)p->par;
  368. FFBWait(par);
  369. return 0;
  370. }
  371. static __inline__ void ffb_rop(struct ffb_par *par, u32 rop)
  372. {
  373. if (par->rop_cache != rop) {
  374. FFBFifo(par, 1);
  375. upa_writel(rop, &par->fbc->rop);
  376. par->rop_cache = rop;
  377. }
  378. }
  379. static void ffb_switch_from_graph(struct ffb_par *par)
  380. {
  381. struct ffb_fbc __iomem *fbc = par->fbc;
  382. struct ffb_dac __iomem *dac = par->dac;
  383. unsigned long flags;
  384. spin_lock_irqsave(&par->lock, flags);
  385. FFBWait(par);
  386. par->fifo_cache = 0;
  387. FFBFifo(par, 7);
  388. upa_writel(FFB_PPC_VCE_DISABLE | FFB_PPC_TBE_OPAQUE |
  389. FFB_PPC_APE_DISABLE | FFB_PPC_CS_CONST,
  390. &fbc->ppc);
  391. upa_writel(0x2000707f, &fbc->fbc);
  392. upa_writel(par->rop_cache, &fbc->rop);
  393. upa_writel(0xffffffff, &fbc->pmask);
  394. upa_writel((1 << 16) | (0 << 0), &fbc->fontinc);
  395. upa_writel(par->fg_cache, &fbc->fg);
  396. upa_writel(par->bg_cache, &fbc->bg);
  397. FFBWait(par);
  398. /* Disable cursor. */
  399. upa_writel(FFB_DAC_CUR_CTRL, &dac->type2);
  400. if (par->flags & FFB_FLAG_INVCURSOR)
  401. upa_writel(0, &dac->value2);
  402. else
  403. upa_writel((FFB_DAC_CUR_CTRL_P0 |
  404. FFB_DAC_CUR_CTRL_P1), &dac->value2);
  405. spin_unlock_irqrestore(&par->lock, flags);
  406. }
  407. static int ffb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  408. {
  409. struct ffb_par *par = (struct ffb_par *)info->par;
  410. /* We just use this to catch switches out of
  411. * graphics mode.
  412. */
  413. ffb_switch_from_graph(par);
  414. if (var->xoffset || var->yoffset || var->vmode)
  415. return -EINVAL;
  416. return 0;
  417. }
  418. /**
  419. * ffb_fillrect - 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 - Copies on area of the screen to another area.
  451. *
  452. * @info: frame buffer structure that represents a single frame buffer
  453. * @area: structure defining the source and destination.
  454. */
  455. static void ffb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
  456. {
  457. struct ffb_par *par = (struct ffb_par *)info->par;
  458. struct ffb_fbc __iomem *fbc = par->fbc;
  459. unsigned long flags;
  460. if (area->dx != area->sx ||
  461. area->dy == area->sy) {
  462. cfb_copyarea(info, area);
  463. return;
  464. }
  465. spin_lock_irqsave(&par->lock, flags);
  466. ffb_rop(par, FFB_ROP_OLD);
  467. FFBFifo(par, 7);
  468. upa_writel(FFB_DRAWOP_VSCROLL, &fbc->drawop);
  469. upa_writel(area->sy, &fbc->by);
  470. upa_writel(area->sx, &fbc->bx);
  471. upa_writel(area->dy, &fbc->dy);
  472. upa_writel(area->dx, &fbc->dx);
  473. upa_writel(area->height, &fbc->bh);
  474. upa_writel(area->width, &fbc->bw);
  475. spin_unlock_irqrestore(&par->lock, flags);
  476. }
  477. /**
  478. * ffb_imageblit - Copies a image from system memory to the screen.
  479. *
  480. * @info: frame buffer structure that represents a single frame buffer
  481. * @image: structure defining the image.
  482. */
  483. static void ffb_imageblit(struct fb_info *info, const struct fb_image *image)
  484. {
  485. struct ffb_par *par = (struct ffb_par *)info->par;
  486. struct ffb_fbc __iomem *fbc = par->fbc;
  487. const u8 *data = image->data;
  488. unsigned long flags;
  489. u32 fg, bg, xy;
  490. u64 fgbg;
  491. int i, width, stride;
  492. if (image->depth > 1) {
  493. cfb_imageblit(info, image);
  494. return;
  495. }
  496. fg = ((u32 *)info->pseudo_palette)[image->fg_color];
  497. bg = ((u32 *)info->pseudo_palette)[image->bg_color];
  498. fgbg = ((u64) fg << 32) | (u64) bg;
  499. xy = (image->dy << 16) | image->dx;
  500. width = image->width;
  501. stride = ((width + 7) >> 3);
  502. spin_lock_irqsave(&par->lock, flags);
  503. if (fgbg != *(u64 *)&par->fg_cache) {
  504. FFBFifo(par, 2);
  505. upa_writeq(fgbg, &fbc->fg);
  506. *(u64 *)&par->fg_cache = fgbg;
  507. }
  508. if (width >= 32) {
  509. FFBFifo(par, 1);
  510. upa_writel(32, &fbc->fontw);
  511. }
  512. while (width >= 32) {
  513. const u8 *next_data = data + 4;
  514. FFBFifo(par, 1);
  515. upa_writel(xy, &fbc->fontxy);
  516. xy += (32 << 0);
  517. for (i = 0; i < image->height; i++) {
  518. u32 val = (((u32)data[0] << 24) |
  519. ((u32)data[1] << 16) |
  520. ((u32)data[2] << 8) |
  521. ((u32)data[3] << 0));
  522. FFBFifo(par, 1);
  523. upa_writel(val, &fbc->font);
  524. data += stride;
  525. }
  526. data = next_data;
  527. width -= 32;
  528. }
  529. if (width) {
  530. FFBFifo(par, 2);
  531. upa_writel(width, &fbc->fontw);
  532. upa_writel(xy, &fbc->fontxy);
  533. for (i = 0; i < image->height; i++) {
  534. u32 val = (((u32)data[0] << 24) |
  535. ((u32)data[1] << 16) |
  536. ((u32)data[2] << 8) |
  537. ((u32)data[3] << 0));
  538. FFBFifo(par, 1);
  539. upa_writel(val, &fbc->font);
  540. data += stride;
  541. }
  542. }
  543. spin_unlock_irqrestore(&par->lock, flags);
  544. }
  545. static void ffb_fixup_var_rgb(struct fb_var_screeninfo *var)
  546. {
  547. var->red.offset = 0;
  548. var->red.length = 8;
  549. var->green.offset = 8;
  550. var->green.length = 8;
  551. var->blue.offset = 16;
  552. var->blue.length = 8;
  553. var->transp.offset = 0;
  554. var->transp.length = 0;
  555. }
  556. /**
  557. * ffb_setcolreg - Sets a color register.
  558. *
  559. * @regno: boolean, 0 copy local, 1 get_user() function
  560. * @red: frame buffer colormap structure
  561. * @green: The green value which can be up to 16 bits wide
  562. * @blue: The blue value which can be up to 16 bits wide.
  563. * @transp: If supported the alpha value which can be up to 16 bits wide.
  564. * @info: frame buffer info structure
  565. */
  566. static int ffb_setcolreg(unsigned regno,
  567. unsigned red, unsigned green, unsigned blue,
  568. unsigned transp, struct fb_info *info)
  569. {
  570. u32 value;
  571. if (regno >= 16)
  572. return 1;
  573. red >>= 8;
  574. green >>= 8;
  575. blue >>= 8;
  576. value = (blue << 16) | (green << 8) | red;
  577. ((u32 *)info->pseudo_palette)[regno] = value;
  578. return 0;
  579. }
  580. /**
  581. * ffb_blank - Optional function. Blanks the display.
  582. * @blank_mode: the blank mode we want.
  583. * @info: frame buffer structure that represents a single frame buffer
  584. */
  585. static int ffb_blank(int blank, struct fb_info *info)
  586. {
  587. struct ffb_par *par = (struct ffb_par *)info->par;
  588. struct ffb_dac __iomem *dac = par->dac;
  589. unsigned long flags;
  590. u32 val;
  591. int i;
  592. spin_lock_irqsave(&par->lock, flags);
  593. FFBWait(par);
  594. upa_writel(FFB_DAC_TGEN, &dac->type);
  595. val = upa_readl(&dac->value);
  596. switch (blank) {
  597. case FB_BLANK_UNBLANK: /* Unblanking */
  598. val |= FFB_DAC_TGEN_VIDE;
  599. par->flags &= ~FFB_FLAG_BLANKED;
  600. break;
  601. case FB_BLANK_NORMAL: /* Normal blanking */
  602. case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
  603. case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
  604. case FB_BLANK_POWERDOWN: /* Poweroff */
  605. val &= ~FFB_DAC_TGEN_VIDE;
  606. par->flags |= FFB_FLAG_BLANKED;
  607. break;
  608. }
  609. upa_writel(FFB_DAC_TGEN, &dac->type);
  610. upa_writel(val, &dac->value);
  611. for (i = 0; i < 10; i++) {
  612. upa_writel(FFB_DAC_TGEN, &dac->type);
  613. upa_readl(&dac->value);
  614. }
  615. spin_unlock_irqrestore(&par->lock, flags);
  616. return 0;
  617. }
  618. static struct sbus_mmap_map ffb_mmap_map[] = {
  619. {
  620. .voff = FFB_SFB8R_VOFF,
  621. .poff = FFB_SFB8R_POFF,
  622. .size = 0x0400000
  623. },
  624. {
  625. .voff = FFB_SFB8G_VOFF,
  626. .poff = FFB_SFB8G_POFF,
  627. .size = 0x0400000
  628. },
  629. {
  630. .voff = FFB_SFB8B_VOFF,
  631. .poff = FFB_SFB8B_POFF,
  632. .size = 0x0400000
  633. },
  634. {
  635. .voff = FFB_SFB8X_VOFF,
  636. .poff = FFB_SFB8X_POFF,
  637. .size = 0x0400000
  638. },
  639. {
  640. .voff = FFB_SFB32_VOFF,
  641. .poff = FFB_SFB32_POFF,
  642. .size = 0x1000000
  643. },
  644. {
  645. .voff = FFB_SFB64_VOFF,
  646. .poff = FFB_SFB64_POFF,
  647. .size = 0x2000000
  648. },
  649. {
  650. .voff = FFB_FBC_REGS_VOFF,
  651. .poff = FFB_FBC_REGS_POFF,
  652. .size = 0x0002000
  653. },
  654. {
  655. .voff = FFB_BM_FBC_REGS_VOFF,
  656. .poff = FFB_BM_FBC_REGS_POFF,
  657. .size = 0x0002000
  658. },
  659. {
  660. .voff = FFB_DFB8R_VOFF,
  661. .poff = FFB_DFB8R_POFF,
  662. .size = 0x0400000
  663. },
  664. {
  665. .voff = FFB_DFB8G_VOFF,
  666. .poff = FFB_DFB8G_POFF,
  667. .size = 0x0400000
  668. },
  669. {
  670. .voff = FFB_DFB8B_VOFF,
  671. .poff = FFB_DFB8B_POFF,
  672. .size = 0x0400000
  673. },
  674. {
  675. .voff = FFB_DFB8X_VOFF,
  676. .poff = FFB_DFB8X_POFF,
  677. .size = 0x0400000
  678. },
  679. {
  680. .voff = FFB_DFB24_VOFF,
  681. .poff = FFB_DFB24_POFF,
  682. .size = 0x1000000
  683. },
  684. {
  685. .voff = FFB_DFB32_VOFF,
  686. .poff = FFB_DFB32_POFF,
  687. .size = 0x1000000
  688. },
  689. {
  690. .voff = FFB_FBC_KREGS_VOFF,
  691. .poff = FFB_FBC_KREGS_POFF,
  692. .size = 0x0002000
  693. },
  694. {
  695. .voff = FFB_DAC_VOFF,
  696. .poff = FFB_DAC_POFF,
  697. .size = 0x0002000
  698. },
  699. {
  700. .voff = FFB_PROM_VOFF,
  701. .poff = FFB_PROM_POFF,
  702. .size = 0x0010000
  703. },
  704. {
  705. .voff = FFB_EXP_VOFF,
  706. .poff = FFB_EXP_POFF,
  707. .size = 0x0002000
  708. },
  709. {
  710. .voff = FFB_DFB422A_VOFF,
  711. .poff = FFB_DFB422A_POFF,
  712. .size = 0x0800000
  713. },
  714. {
  715. .voff = FFB_DFB422AD_VOFF,
  716. .poff = FFB_DFB422AD_POFF,
  717. .size = 0x0800000
  718. },
  719. {
  720. .voff = FFB_DFB24B_VOFF,
  721. .poff = FFB_DFB24B_POFF,
  722. .size = 0x1000000
  723. },
  724. {
  725. .voff = FFB_DFB422B_VOFF,
  726. .poff = FFB_DFB422B_POFF,
  727. .size = 0x0800000
  728. },
  729. {
  730. .voff = FFB_DFB422BD_VOFF,
  731. .poff = FFB_DFB422BD_POFF,
  732. .size = 0x0800000
  733. },
  734. {
  735. .voff = FFB_SFB16Z_VOFF,
  736. .poff = FFB_SFB16Z_POFF,
  737. .size = 0x0800000
  738. },
  739. {
  740. .voff = FFB_SFB8Z_VOFF,
  741. .poff = FFB_SFB8Z_POFF,
  742. .size = 0x0800000
  743. },
  744. {
  745. .voff = FFB_SFB422_VOFF,
  746. .poff = FFB_SFB422_POFF,
  747. .size = 0x0800000
  748. },
  749. {
  750. .voff = FFB_SFB422D_VOFF,
  751. .poff = FFB_SFB422D_POFF,
  752. .size = 0x0800000
  753. },
  754. { .size = 0 }
  755. };
  756. static int ffb_mmap(struct fb_info *info, struct vm_area_struct *vma)
  757. {
  758. struct ffb_par *par = (struct ffb_par *)info->par;
  759. return sbusfb_mmap_helper(ffb_mmap_map,
  760. par->physbase, par->fbsize,
  761. 0, vma);
  762. }
  763. static int ffb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
  764. {
  765. struct ffb_par *par = (struct ffb_par *)info->par;
  766. return sbusfb_ioctl_helper(cmd, arg, info,
  767. FBTYPE_CREATOR, 24, par->fbsize);
  768. }
  769. /*
  770. * Initialisation
  771. */
  772. static void ffb_init_fix(struct fb_info *info)
  773. {
  774. struct ffb_par *par = (struct ffb_par *)info->par;
  775. const char *ffb_type_name;
  776. if (!(par->flags & FFB_FLAG_AFB)) {
  777. if ((par->board_type & 0x7) == 0x3)
  778. ffb_type_name = "Creator 3D";
  779. else
  780. ffb_type_name = "Creator";
  781. } else
  782. ffb_type_name = "Elite 3D";
  783. strlcpy(info->fix.id, ffb_type_name, sizeof(info->fix.id));
  784. info->fix.type = FB_TYPE_PACKED_PIXELS;
  785. info->fix.visual = FB_VISUAL_TRUECOLOR;
  786. /* Framebuffer length is the same regardless of resolution. */
  787. info->fix.line_length = 8192;
  788. info->fix.accel = FB_ACCEL_SUN_CREATOR;
  789. }
  790. static int __devinit ffb_probe(struct of_device *op,
  791. const struct of_device_id *match)
  792. {
  793. struct device_node *dp = op->node;
  794. struct ffb_fbc __iomem *fbc;
  795. struct ffb_dac __iomem *dac;
  796. struct fb_info *info;
  797. struct ffb_par *par;
  798. u32 dac_pnum, dac_rev, dac_mrev;
  799. int err;
  800. info = framebuffer_alloc(sizeof(struct ffb_par), &op->dev);
  801. err = -ENOMEM;
  802. if (!info)
  803. goto out_err;
  804. par = info->par;
  805. spin_lock_init(&par->lock);
  806. par->fbc = of_ioremap(&op->resource[2], 0,
  807. sizeof(struct ffb_fbc), "ffb fbc");
  808. if (!par->fbc)
  809. goto out_release_fb;
  810. par->dac = of_ioremap(&op->resource[1], 0,
  811. sizeof(struct ffb_dac), "ffb dac");
  812. if (!par->dac)
  813. goto out_unmap_fbc;
  814. par->rop_cache = FFB_ROP_NEW;
  815. par->physbase = op->resource[0].start;
  816. /* Don't mention copyarea, so SCROLL_REDRAW is always
  817. * used. It is the fastest on this chip.
  818. */
  819. info->flags = (FBINFO_DEFAULT |
  820. /* FBINFO_HWACCEL_COPYAREA | */
  821. FBINFO_HWACCEL_FILLRECT |
  822. FBINFO_HWACCEL_IMAGEBLIT);
  823. info->fbops = &ffb_ops;
  824. info->screen_base = (char *) par->physbase + FFB_DFB24_POFF;
  825. info->pseudo_palette = par->pseudo_palette;
  826. sbusfb_fill_var(&info->var, dp->node, 32);
  827. par->fbsize = PAGE_ALIGN(info->var.xres * info->var.yres * 4);
  828. ffb_fixup_var_rgb(&info->var);
  829. info->var.accel_flags = FB_ACCELF_TEXT;
  830. if (!strcmp(dp->name, "SUNW,afb"))
  831. par->flags |= FFB_FLAG_AFB;
  832. par->board_type = of_getintprop_default(dp, "board_type", 0);
  833. fbc = par->fbc;
  834. if ((upa_readl(&fbc->ucsr) & FFB_UCSR_ALL_ERRORS) != 0)
  835. upa_writel(FFB_UCSR_ALL_ERRORS, &fbc->ucsr);
  836. dac = par->dac;
  837. upa_writel(FFB_DAC_DID, &dac->type);
  838. dac_pnum = upa_readl(&dac->value);
  839. dac_rev = (dac_pnum & FFB_DAC_DID_REV) >> FFB_DAC_DID_REV_SHIFT;
  840. dac_pnum = (dac_pnum & FFB_DAC_DID_PNUM) >> FFB_DAC_DID_PNUM_SHIFT;
  841. upa_writel(FFB_DAC_UCTRL, &dac->type);
  842. dac_mrev = upa_readl(&dac->value);
  843. dac_mrev = (dac_mrev & FFB_DAC_UCTRL_MANREV) >>
  844. FFB_DAC_UCTRL_MANREV_SHIFT;
  845. /* Elite3D has different DAC revision numbering, and no DAC revisions
  846. * have the reversed meaning of cursor enable. Otherwise, Pacifica 1
  847. * ramdacs with manufacturing revision less than 3 have inverted
  848. * cursor logic. We identify Pacifica 1 as not Pacifica 2, the
  849. * latter having a part number value of 0x236e.
  850. */
  851. if ((par->flags & FFB_FLAG_AFB) || dac_pnum == 0x236e) {
  852. par->flags &= ~FFB_FLAG_INVCURSOR;
  853. } else {
  854. if (dac_mrev < 3)
  855. par->flags |= FFB_FLAG_INVCURSOR;
  856. }
  857. ffb_switch_from_graph(par);
  858. /* Unblank it just to be sure. When there are multiple
  859. * FFB/AFB cards in the system, or it is not the OBP
  860. * chosen console, it will have video outputs off in
  861. * the DAC.
  862. */
  863. ffb_blank(0, info);
  864. if (fb_alloc_cmap(&info->cmap, 256, 0))
  865. goto out_unmap_dac;
  866. ffb_init_fix(info);
  867. err = register_framebuffer(info);
  868. if (err < 0)
  869. goto out_dealloc_cmap;
  870. dev_set_drvdata(&op->dev, info);
  871. printk("%s: %s at %016lx, type %d, "
  872. "DAC pnum[%x] rev[%d] manuf_rev[%d]\n",
  873. dp->full_name,
  874. ((par->flags & FFB_FLAG_AFB) ? "AFB" : "FFB"),
  875. par->physbase, par->board_type,
  876. dac_pnum, dac_rev, dac_mrev);
  877. return 0;
  878. out_dealloc_cmap:
  879. fb_dealloc_cmap(&info->cmap);
  880. out_unmap_dac:
  881. of_iounmap(&op->resource[2], par->fbc, sizeof(struct ffb_fbc));
  882. out_unmap_fbc:
  883. of_iounmap(&op->resource[2], par->fbc, sizeof(struct ffb_fbc));
  884. out_release_fb:
  885. framebuffer_release(info);
  886. out_err:
  887. return err;
  888. }
  889. static int __devexit ffb_remove(struct of_device *op)
  890. {
  891. struct fb_info *info = dev_get_drvdata(&op->dev);
  892. struct ffb_par *par = info->par;
  893. unregister_framebuffer(info);
  894. fb_dealloc_cmap(&info->cmap);
  895. of_iounmap(&op->resource[2], par->fbc, sizeof(struct ffb_fbc));
  896. of_iounmap(&op->resource[1], par->dac, sizeof(struct ffb_dac));
  897. framebuffer_release(info);
  898. dev_set_drvdata(&op->dev, NULL);
  899. return 0;
  900. }
  901. static struct of_device_id ffb_match[] = {
  902. {
  903. .name = "SUNW,ffb",
  904. },
  905. {
  906. .name = "SUNW,afb",
  907. },
  908. {},
  909. };
  910. MODULE_DEVICE_TABLE(of, ffb_match);
  911. static struct of_platform_driver ffb_driver = {
  912. .name = "ffb",
  913. .match_table = ffb_match,
  914. .probe = ffb_probe,
  915. .remove = __devexit_p(ffb_remove),
  916. };
  917. int __init ffb_init(void)
  918. {
  919. if (fb_get_options("ffb", NULL))
  920. return -ENODEV;
  921. return of_register_driver(&ffb_driver, &of_bus_type);
  922. }
  923. void __exit ffb_exit(void)
  924. {
  925. of_unregister_driver(&ffb_driver);
  926. }
  927. module_init(ffb_init);
  928. module_exit(ffb_exit);
  929. MODULE_DESCRIPTION("framebuffer driver for Creator/Elite3D chipsets");
  930. MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
  931. MODULE_VERSION("2.0");
  932. MODULE_LICENSE("GPL");