ffb.c 24 KB

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