ffb.c 26 KB

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