ffb.c 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* ffb.c: Creator/Elite3D frame buffer driver
  3. *
  4. * Copyright (C) 2003, 2006 David S. Miller (davem@davemloft.net)
  5. * Copyright (C) 1997,1998,1999 Jakub Jelinek (jj@ultra.linux.cz)
  6. *
  7. * Driver layout based loosely on tgafb.c, see that file for credits.
  8. */
  9. #include <linux/module.h>
  10. #include <linux/kernel.h>
  11. #include <linux/errno.h>
  12. #include <linux/string.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 <linux/of.h>
  19. #include <linux/platform_device.h>
  20. #include <asm/io.h>
  21. #include <asm/upa.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_imageblit(struct fb_info *, const struct fb_image *);
  31. static void ffb_fillrect(struct fb_info *, const struct fb_fillrect *);
  32. static void ffb_copyarea(struct fb_info *, const struct fb_copyarea *);
  33. static int ffb_sync(struct fb_info *);
  34. static int ffb_pan_display(struct fb_var_screeninfo *, struct fb_info *);
  35. static int ffb_sbusfb_mmap(struct fb_info *info, struct vm_area_struct *vma);
  36. static int ffb_sbusfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg);
  37. /*
  38. * Frame buffer operations
  39. */
  40. static const struct fb_ops ffb_ops = {
  41. .owner = THIS_MODULE,
  42. __FB_DEFAULT_SBUS_OPS_RDWR(ffb),
  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_DEFAULT_SBUS_OPS_IOCTL(ffb),
  51. __FB_DEFAULT_SBUS_OPS_MMAP(ffb),
  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_OVENAB 0x00000008 /* Overlay Enable */
  307. #define FFB_DAC_UCTRL_WMODE 0x00000030 /* Window Mode */
  308. #define FFB_DAC_UCTRL_WM_COMB 0x00000000 /* Window Mode = Combined */
  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, uctrl;
  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. /* Disable overlay and window modes. */
  406. upa_writel(FFB_DAC_UCTRL, &dac->type);
  407. uctrl = upa_readl(&dac->value);
  408. uctrl &= ~FFB_DAC_UCTRL_WMODE;
  409. uctrl |= FFB_DAC_UCTRL_WM_COMB;
  410. uctrl &= ~FFB_DAC_UCTRL_OVENAB;
  411. upa_writel(FFB_DAC_UCTRL, &dac->type);
  412. upa_writel(uctrl, &dac->value);
  413. spin_unlock_irqrestore(&par->lock, flags);
  414. }
  415. static int ffb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  416. {
  417. struct ffb_par *par = (struct ffb_par *)info->par;
  418. /* We just use this to catch switches out of
  419. * graphics mode.
  420. */
  421. ffb_switch_from_graph(par);
  422. if (var->xoffset || var->yoffset || var->vmode)
  423. return -EINVAL;
  424. return 0;
  425. }
  426. /**
  427. * ffb_fillrect - Draws a rectangle on the screen.
  428. *
  429. * @info: frame buffer structure that represents a single frame buffer
  430. * @rect: structure defining the rectagle and operation.
  431. */
  432. static void ffb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  433. {
  434. struct ffb_par *par = (struct ffb_par *)info->par;
  435. struct ffb_fbc __iomem *fbc = par->fbc;
  436. unsigned long flags;
  437. u32 fg;
  438. BUG_ON(rect->rop != ROP_COPY && rect->rop != ROP_XOR);
  439. fg = ((u32 *)info->pseudo_palette)[rect->color];
  440. spin_lock_irqsave(&par->lock, flags);
  441. if (fg != par->fg_cache) {
  442. FFBFifo(par, 1);
  443. upa_writel(fg, &fbc->fg);
  444. par->fg_cache = fg;
  445. }
  446. ffb_rop(par, rect->rop == ROP_COPY ?
  447. FFB_ROP_NEW :
  448. FFB_ROP_NEW_XOR_OLD);
  449. FFBFifo(par, 5);
  450. upa_writel(FFB_DRAWOP_RECTANGLE, &fbc->drawop);
  451. upa_writel(rect->dy, &fbc->by);
  452. upa_writel(rect->dx, &fbc->bx);
  453. upa_writel(rect->height, &fbc->bh);
  454. upa_writel(rect->width, &fbc->bw);
  455. spin_unlock_irqrestore(&par->lock, flags);
  456. }
  457. /**
  458. * ffb_copyarea - Copies on area of the screen to another area.
  459. *
  460. * @info: frame buffer structure that represents a single frame buffer
  461. * @area: structure defining the source and destination.
  462. */
  463. static void ffb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
  464. {
  465. struct ffb_par *par = (struct ffb_par *)info->par;
  466. struct ffb_fbc __iomem *fbc = par->fbc;
  467. unsigned long flags;
  468. if (area->dx != area->sx ||
  469. area->dy == area->sy) {
  470. cfb_copyarea(info, area);
  471. return;
  472. }
  473. spin_lock_irqsave(&par->lock, flags);
  474. ffb_rop(par, FFB_ROP_OLD);
  475. FFBFifo(par, 7);
  476. upa_writel(FFB_DRAWOP_VSCROLL, &fbc->drawop);
  477. upa_writel(area->sy, &fbc->by);
  478. upa_writel(area->sx, &fbc->bx);
  479. upa_writel(area->dy, &fbc->dy);
  480. upa_writel(area->dx, &fbc->dx);
  481. upa_writel(area->height, &fbc->bh);
  482. upa_writel(area->width, &fbc->bw);
  483. spin_unlock_irqrestore(&par->lock, flags);
  484. }
  485. /**
  486. * ffb_imageblit - Copies a image from system memory to the screen.
  487. *
  488. * @info: frame buffer structure that represents a single frame buffer
  489. * @image: structure defining the image.
  490. */
  491. static void ffb_imageblit(struct fb_info *info, const struct fb_image *image)
  492. {
  493. struct ffb_par *par = (struct ffb_par *)info->par;
  494. struct ffb_fbc __iomem *fbc = par->fbc;
  495. const u8 *data = image->data;
  496. unsigned long flags;
  497. u32 fg, bg, xy;
  498. u64 fgbg;
  499. int i, width, stride;
  500. if (image->depth > 1) {
  501. cfb_imageblit(info, image);
  502. return;
  503. }
  504. fg = ((u32 *)info->pseudo_palette)[image->fg_color];
  505. bg = ((u32 *)info->pseudo_palette)[image->bg_color];
  506. fgbg = ((u64) fg << 32) | (u64) bg;
  507. xy = (image->dy << 16) | image->dx;
  508. width = image->width;
  509. stride = ((width + 7) >> 3);
  510. spin_lock_irqsave(&par->lock, flags);
  511. if (fgbg != *(u64 *)&par->fg_cache) {
  512. FFBFifo(par, 2);
  513. upa_writeq(fgbg, &fbc->fg);
  514. *(u64 *)&par->fg_cache = fgbg;
  515. }
  516. if (width >= 32) {
  517. FFBFifo(par, 1);
  518. upa_writel(32, &fbc->fontw);
  519. }
  520. while (width >= 32) {
  521. const u8 *next_data = data + 4;
  522. FFBFifo(par, 1);
  523. upa_writel(xy, &fbc->fontxy);
  524. xy += (32 << 0);
  525. for (i = 0; i < image->height; i++) {
  526. u32 val = (((u32)data[0] << 24) |
  527. ((u32)data[1] << 16) |
  528. ((u32)data[2] << 8) |
  529. ((u32)data[3] << 0));
  530. FFBFifo(par, 1);
  531. upa_writel(val, &fbc->font);
  532. data += stride;
  533. }
  534. data = next_data;
  535. width -= 32;
  536. }
  537. if (width) {
  538. FFBFifo(par, 2);
  539. upa_writel(width, &fbc->fontw);
  540. upa_writel(xy, &fbc->fontxy);
  541. for (i = 0; i < image->height; i++) {
  542. u32 val = (((u32)data[0] << 24) |
  543. ((u32)data[1] << 16) |
  544. ((u32)data[2] << 8) |
  545. ((u32)data[3] << 0));
  546. FFBFifo(par, 1);
  547. upa_writel(val, &fbc->font);
  548. data += stride;
  549. }
  550. }
  551. spin_unlock_irqrestore(&par->lock, flags);
  552. }
  553. static void ffb_fixup_var_rgb(struct fb_var_screeninfo *var)
  554. {
  555. var->red.offset = 0;
  556. var->red.length = 8;
  557. var->green.offset = 8;
  558. var->green.length = 8;
  559. var->blue.offset = 16;
  560. var->blue.length = 8;
  561. var->transp.offset = 0;
  562. var->transp.length = 0;
  563. }
  564. /**
  565. * ffb_setcolreg - Sets a color register.
  566. *
  567. * @regno: boolean, 0 copy local, 1 get_user() function
  568. * @red: frame buffer colormap structure
  569. * @green: The green value which can be up to 16 bits wide
  570. * @blue: The blue value which can be up to 16 bits wide.
  571. * @transp: If supported the alpha value which can be up to 16 bits wide.
  572. * @info: frame buffer info structure
  573. */
  574. static int ffb_setcolreg(unsigned regno,
  575. unsigned red, unsigned green, unsigned blue,
  576. unsigned transp, struct fb_info *info)
  577. {
  578. u32 value;
  579. if (regno >= 16)
  580. return 1;
  581. red >>= 8;
  582. green >>= 8;
  583. blue >>= 8;
  584. value = (blue << 16) | (green << 8) | red;
  585. ((u32 *)info->pseudo_palette)[regno] = value;
  586. return 0;
  587. }
  588. /**
  589. * ffb_blank - Optional function. Blanks the display.
  590. * @blank: the blank mode we want.
  591. * @info: frame buffer structure that represents a single frame buffer
  592. */
  593. static int ffb_blank(int blank, struct fb_info *info)
  594. {
  595. struct ffb_par *par = (struct ffb_par *)info->par;
  596. struct ffb_dac __iomem *dac = par->dac;
  597. unsigned long flags;
  598. u32 val;
  599. int i;
  600. spin_lock_irqsave(&par->lock, flags);
  601. FFBWait(par);
  602. upa_writel(FFB_DAC_TGEN, &dac->type);
  603. val = upa_readl(&dac->value);
  604. switch (blank) {
  605. case FB_BLANK_UNBLANK: /* Unblanking */
  606. val |= FFB_DAC_TGEN_VIDE;
  607. par->flags &= ~FFB_FLAG_BLANKED;
  608. break;
  609. case FB_BLANK_NORMAL: /* Normal blanking */
  610. case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
  611. case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
  612. case FB_BLANK_POWERDOWN: /* Poweroff */
  613. val &= ~FFB_DAC_TGEN_VIDE;
  614. par->flags |= FFB_FLAG_BLANKED;
  615. break;
  616. }
  617. upa_writel(FFB_DAC_TGEN, &dac->type);
  618. upa_writel(val, &dac->value);
  619. for (i = 0; i < 10; i++) {
  620. upa_writel(FFB_DAC_TGEN, &dac->type);
  621. upa_readl(&dac->value);
  622. }
  623. spin_unlock_irqrestore(&par->lock, flags);
  624. return 0;
  625. }
  626. static const struct sbus_mmap_map ffb_mmap_map[] = {
  627. {
  628. .voff = FFB_SFB8R_VOFF,
  629. .poff = FFB_SFB8R_POFF,
  630. .size = 0x0400000
  631. },
  632. {
  633. .voff = FFB_SFB8G_VOFF,
  634. .poff = FFB_SFB8G_POFF,
  635. .size = 0x0400000
  636. },
  637. {
  638. .voff = FFB_SFB8B_VOFF,
  639. .poff = FFB_SFB8B_POFF,
  640. .size = 0x0400000
  641. },
  642. {
  643. .voff = FFB_SFB8X_VOFF,
  644. .poff = FFB_SFB8X_POFF,
  645. .size = 0x0400000
  646. },
  647. {
  648. .voff = FFB_SFB32_VOFF,
  649. .poff = FFB_SFB32_POFF,
  650. .size = 0x1000000
  651. },
  652. {
  653. .voff = FFB_SFB64_VOFF,
  654. .poff = FFB_SFB64_POFF,
  655. .size = 0x2000000
  656. },
  657. {
  658. .voff = FFB_FBC_REGS_VOFF,
  659. .poff = FFB_FBC_REGS_POFF,
  660. .size = 0x0002000
  661. },
  662. {
  663. .voff = FFB_BM_FBC_REGS_VOFF,
  664. .poff = FFB_BM_FBC_REGS_POFF,
  665. .size = 0x0002000
  666. },
  667. {
  668. .voff = FFB_DFB8R_VOFF,
  669. .poff = FFB_DFB8R_POFF,
  670. .size = 0x0400000
  671. },
  672. {
  673. .voff = FFB_DFB8G_VOFF,
  674. .poff = FFB_DFB8G_POFF,
  675. .size = 0x0400000
  676. },
  677. {
  678. .voff = FFB_DFB8B_VOFF,
  679. .poff = FFB_DFB8B_POFF,
  680. .size = 0x0400000
  681. },
  682. {
  683. .voff = FFB_DFB8X_VOFF,
  684. .poff = FFB_DFB8X_POFF,
  685. .size = 0x0400000
  686. },
  687. {
  688. .voff = FFB_DFB24_VOFF,
  689. .poff = FFB_DFB24_POFF,
  690. .size = 0x1000000
  691. },
  692. {
  693. .voff = FFB_DFB32_VOFF,
  694. .poff = FFB_DFB32_POFF,
  695. .size = 0x1000000
  696. },
  697. {
  698. .voff = FFB_FBC_KREGS_VOFF,
  699. .poff = FFB_FBC_KREGS_POFF,
  700. .size = 0x0002000
  701. },
  702. {
  703. .voff = FFB_DAC_VOFF,
  704. .poff = FFB_DAC_POFF,
  705. .size = 0x0002000
  706. },
  707. {
  708. .voff = FFB_PROM_VOFF,
  709. .poff = FFB_PROM_POFF,
  710. .size = 0x0010000
  711. },
  712. {
  713. .voff = FFB_EXP_VOFF,
  714. .poff = FFB_EXP_POFF,
  715. .size = 0x0002000
  716. },
  717. {
  718. .voff = FFB_DFB422A_VOFF,
  719. .poff = FFB_DFB422A_POFF,
  720. .size = 0x0800000
  721. },
  722. {
  723. .voff = FFB_DFB422AD_VOFF,
  724. .poff = FFB_DFB422AD_POFF,
  725. .size = 0x0800000
  726. },
  727. {
  728. .voff = FFB_DFB24B_VOFF,
  729. .poff = FFB_DFB24B_POFF,
  730. .size = 0x1000000
  731. },
  732. {
  733. .voff = FFB_DFB422B_VOFF,
  734. .poff = FFB_DFB422B_POFF,
  735. .size = 0x0800000
  736. },
  737. {
  738. .voff = FFB_DFB422BD_VOFF,
  739. .poff = FFB_DFB422BD_POFF,
  740. .size = 0x0800000
  741. },
  742. {
  743. .voff = FFB_SFB16Z_VOFF,
  744. .poff = FFB_SFB16Z_POFF,
  745. .size = 0x0800000
  746. },
  747. {
  748. .voff = FFB_SFB8Z_VOFF,
  749. .poff = FFB_SFB8Z_POFF,
  750. .size = 0x0800000
  751. },
  752. {
  753. .voff = FFB_SFB422_VOFF,
  754. .poff = FFB_SFB422_POFF,
  755. .size = 0x0800000
  756. },
  757. {
  758. .voff = FFB_SFB422D_VOFF,
  759. .poff = FFB_SFB422D_POFF,
  760. .size = 0x0800000
  761. },
  762. { .size = 0 }
  763. };
  764. static int ffb_sbusfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
  765. {
  766. struct ffb_par *par = (struct ffb_par *)info->par;
  767. return sbusfb_mmap_helper(ffb_mmap_map,
  768. par->physbase, par->fbsize,
  769. 0, vma);
  770. }
  771. static int ffb_sbusfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
  772. {
  773. struct ffb_par *par = (struct ffb_par *)info->par;
  774. return sbusfb_ioctl_helper(cmd, arg, info,
  775. FBTYPE_CREATOR, 24, par->fbsize);
  776. }
  777. /*
  778. * Initialisation
  779. */
  780. static void ffb_init_fix(struct fb_info *info)
  781. {
  782. struct ffb_par *par = (struct ffb_par *)info->par;
  783. const char *ffb_type_name;
  784. if (!(par->flags & FFB_FLAG_AFB)) {
  785. if ((par->board_type & 0x7) == 0x3)
  786. ffb_type_name = "Creator 3D";
  787. else
  788. ffb_type_name = "Creator";
  789. } else
  790. ffb_type_name = "Elite 3D";
  791. strscpy(info->fix.id, ffb_type_name, sizeof(info->fix.id));
  792. info->fix.type = FB_TYPE_PACKED_PIXELS;
  793. info->fix.visual = FB_VISUAL_TRUECOLOR;
  794. /* Framebuffer length is the same regardless of resolution. */
  795. info->fix.line_length = 8192;
  796. info->fix.accel = FB_ACCEL_SUN_CREATOR;
  797. }
  798. static int ffb_probe(struct platform_device *op)
  799. {
  800. struct device_node *dp = op->dev.of_node;
  801. struct ffb_fbc __iomem *fbc;
  802. struct ffb_dac __iomem *dac;
  803. struct fb_info *info;
  804. struct ffb_par *par;
  805. u32 dac_pnum, dac_rev, dac_mrev;
  806. int err;
  807. info = framebuffer_alloc(sizeof(struct ffb_par), &op->dev);
  808. err = -ENOMEM;
  809. if (!info)
  810. goto out_err;
  811. par = info->par;
  812. spin_lock_init(&par->lock);
  813. par->fbc = of_ioremap(&op->resource[2], 0,
  814. sizeof(struct ffb_fbc), "ffb fbc");
  815. if (!par->fbc)
  816. goto out_release_fb;
  817. par->dac = of_ioremap(&op->resource[1], 0,
  818. sizeof(struct ffb_dac), "ffb dac");
  819. if (!par->dac)
  820. goto out_unmap_fbc;
  821. par->rop_cache = FFB_ROP_NEW;
  822. par->physbase = op->resource[0].start;
  823. /* Don't mention copyarea, so SCROLL_REDRAW is always
  824. * used. It is the fastest on this chip.
  825. */
  826. info->flags = (/* FBINFO_HWACCEL_COPYAREA | */
  827. FBINFO_HWACCEL_FILLRECT |
  828. FBINFO_HWACCEL_IMAGEBLIT);
  829. info->fbops = &ffb_ops;
  830. info->screen_base = (char *) par->physbase + FFB_DFB24_POFF;
  831. info->pseudo_palette = par->pseudo_palette;
  832. sbusfb_fill_var(&info->var, dp, 32);
  833. par->fbsize = PAGE_ALIGN(info->var.xres * info->var.yres * 4);
  834. ffb_fixup_var_rgb(&info->var);
  835. info->var.accel_flags = FB_ACCELF_TEXT;
  836. if (of_node_name_eq(dp, "SUNW,afb"))
  837. par->flags |= FFB_FLAG_AFB;
  838. par->board_type = of_getintprop_default(dp, "board_type", 0);
  839. fbc = par->fbc;
  840. if ((upa_readl(&fbc->ucsr) & FFB_UCSR_ALL_ERRORS) != 0)
  841. upa_writel(FFB_UCSR_ALL_ERRORS, &fbc->ucsr);
  842. dac = par->dac;
  843. upa_writel(FFB_DAC_DID, &dac->type);
  844. dac_pnum = upa_readl(&dac->value);
  845. dac_rev = (dac_pnum & FFB_DAC_DID_REV) >> FFB_DAC_DID_REV_SHIFT;
  846. dac_pnum = (dac_pnum & FFB_DAC_DID_PNUM) >> FFB_DAC_DID_PNUM_SHIFT;
  847. upa_writel(FFB_DAC_UCTRL, &dac->type);
  848. dac_mrev = upa_readl(&dac->value);
  849. dac_mrev = (dac_mrev & FFB_DAC_UCTRL_MANREV) >>
  850. FFB_DAC_UCTRL_MANREV_SHIFT;
  851. /* Elite3D has different DAC revision numbering, and no DAC revisions
  852. * have the reversed meaning of cursor enable. Otherwise, Pacifica 1
  853. * ramdacs with manufacturing revision less than 3 have inverted
  854. * cursor logic. We identify Pacifica 1 as not Pacifica 2, the
  855. * latter having a part number value of 0x236e.
  856. */
  857. if ((par->flags & FFB_FLAG_AFB) || dac_pnum == 0x236e) {
  858. par->flags &= ~FFB_FLAG_INVCURSOR;
  859. } else {
  860. if (dac_mrev < 3)
  861. par->flags |= FFB_FLAG_INVCURSOR;
  862. }
  863. ffb_switch_from_graph(par);
  864. /* Unblank it just to be sure. When there are multiple
  865. * FFB/AFB cards in the system, or it is not the OBP
  866. * chosen console, it will have video outputs off in
  867. * the DAC.
  868. */
  869. ffb_blank(FB_BLANK_UNBLANK, info);
  870. if (fb_alloc_cmap(&info->cmap, 256, 0))
  871. goto out_unmap_dac;
  872. ffb_init_fix(info);
  873. err = register_framebuffer(info);
  874. if (err < 0)
  875. goto out_dealloc_cmap;
  876. dev_set_drvdata(&op->dev, info);
  877. printk(KERN_INFO "%pOF: %s at %016lx, type %d, "
  878. "DAC pnum[%x] rev[%d] manuf_rev[%d]\n",
  879. dp,
  880. ((par->flags & FFB_FLAG_AFB) ? "AFB" : "FFB"),
  881. par->physbase, par->board_type,
  882. dac_pnum, dac_rev, dac_mrev);
  883. return 0;
  884. out_dealloc_cmap:
  885. fb_dealloc_cmap(&info->cmap);
  886. out_unmap_dac:
  887. of_iounmap(&op->resource[1], par->dac, sizeof(struct ffb_dac));
  888. out_unmap_fbc:
  889. of_iounmap(&op->resource[2], par->fbc, sizeof(struct ffb_fbc));
  890. out_release_fb:
  891. framebuffer_release(info);
  892. out_err:
  893. return err;
  894. }
  895. static void ffb_remove(struct platform_device *op)
  896. {
  897. struct fb_info *info = dev_get_drvdata(&op->dev);
  898. struct ffb_par *par = info->par;
  899. unregister_framebuffer(info);
  900. fb_dealloc_cmap(&info->cmap);
  901. of_iounmap(&op->resource[2], par->fbc, sizeof(struct ffb_fbc));
  902. of_iounmap(&op->resource[1], par->dac, sizeof(struct ffb_dac));
  903. framebuffer_release(info);
  904. }
  905. static const struct of_device_id ffb_match[] = {
  906. {
  907. .name = "SUNW,ffb",
  908. },
  909. {
  910. .name = "SUNW,afb",
  911. },
  912. {},
  913. };
  914. MODULE_DEVICE_TABLE(of, ffb_match);
  915. static struct platform_driver ffb_driver = {
  916. .driver = {
  917. .name = "ffb",
  918. .of_match_table = ffb_match,
  919. },
  920. .probe = ffb_probe,
  921. .remove = ffb_remove,
  922. };
  923. static int __init ffb_init(void)
  924. {
  925. if (fb_get_options("ffb", NULL))
  926. return -ENODEV;
  927. return platform_driver_register(&ffb_driver);
  928. }
  929. static void __exit ffb_exit(void)
  930. {
  931. platform_driver_unregister(&ffb_driver);
  932. }
  933. module_init(ffb_init);
  934. module_exit(ffb_exit);
  935. MODULE_DESCRIPTION("framebuffer driver for Creator/Elite3D chipsets");
  936. MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
  937. MODULE_VERSION("2.0");
  938. MODULE_LICENSE("GPL");