ffb.c 24 KB

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