cg6.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. /* cg6.c: CGSIX (GX, GXplus, TGX) frame buffer driver
  2. *
  3. * Copyright (C) 2003 David S. Miller (davem@redhat.com)
  4. * Copyright (C) 1996,1998 Jakub Jelinek (jj@ultra.linux.cz)
  5. * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
  6. * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
  7. *
  8. * Driver layout based loosely on tgafb.c, see that file for credits.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/errno.h>
  13. #include <linux/string.h>
  14. #include <linux/slab.h>
  15. #include <linux/delay.h>
  16. #include <linux/init.h>
  17. #include <linux/fb.h>
  18. #include <linux/mm.h>
  19. #include <asm/io.h>
  20. #include <asm/sbus.h>
  21. #include <asm/oplib.h>
  22. #include <asm/fbio.h>
  23. #include "sbuslib.h"
  24. /*
  25. * Local functions.
  26. */
  27. static int cg6_setcolreg(unsigned, unsigned, unsigned, unsigned,
  28. unsigned, struct fb_info *);
  29. static int cg6_blank(int, struct fb_info *);
  30. static void cg6_imageblit(struct fb_info *, const struct fb_image *);
  31. static void cg6_fillrect(struct fb_info *, const struct fb_fillrect *);
  32. static int cg6_sync(struct fb_info *);
  33. static int cg6_mmap(struct fb_info *, struct file *, struct vm_area_struct *);
  34. static int cg6_ioctl(struct inode *, struct file *, unsigned int,
  35. unsigned long, struct fb_info *);
  36. /*
  37. * Frame buffer operations
  38. */
  39. static struct fb_ops cg6_ops = {
  40. .owner = THIS_MODULE,
  41. .fb_setcolreg = cg6_setcolreg,
  42. .fb_blank = cg6_blank,
  43. .fb_fillrect = cg6_fillrect,
  44. .fb_copyarea = cfb_copyarea,
  45. .fb_imageblit = cg6_imageblit,
  46. .fb_sync = cg6_sync,
  47. .fb_mmap = cg6_mmap,
  48. .fb_ioctl = cg6_ioctl,
  49. #ifdef CONFIG_COMPAT
  50. .fb_compat_ioctl = sbusfb_compat_ioctl,
  51. #endif
  52. };
  53. /* Offset of interesting structures in the OBIO space */
  54. /*
  55. * Brooktree is the video dac and is funny to program on the cg6.
  56. * (it's even funnier on the cg3)
  57. * The FBC could be the frame buffer control
  58. * The FHC could is the frame buffer hardware control.
  59. */
  60. #define CG6_ROM_OFFSET 0x0UL
  61. #define CG6_BROOKTREE_OFFSET 0x200000UL
  62. #define CG6_DHC_OFFSET 0x240000UL
  63. #define CG6_ALT_OFFSET 0x280000UL
  64. #define CG6_FHC_OFFSET 0x300000UL
  65. #define CG6_THC_OFFSET 0x301000UL
  66. #define CG6_FBC_OFFSET 0x700000UL
  67. #define CG6_TEC_OFFSET 0x701000UL
  68. #define CG6_RAM_OFFSET 0x800000UL
  69. /* FHC definitions */
  70. #define CG6_FHC_FBID_SHIFT 24
  71. #define CG6_FHC_FBID_MASK 255
  72. #define CG6_FHC_REV_SHIFT 20
  73. #define CG6_FHC_REV_MASK 15
  74. #define CG6_FHC_FROP_DISABLE (1 << 19)
  75. #define CG6_FHC_ROW_DISABLE (1 << 18)
  76. #define CG6_FHC_SRC_DISABLE (1 << 17)
  77. #define CG6_FHC_DST_DISABLE (1 << 16)
  78. #define CG6_FHC_RESET (1 << 15)
  79. #define CG6_FHC_LITTLE_ENDIAN (1 << 13)
  80. #define CG6_FHC_RES_MASK (3 << 11)
  81. #define CG6_FHC_1024 (0 << 11)
  82. #define CG6_FHC_1152 (1 << 11)
  83. #define CG6_FHC_1280 (2 << 11)
  84. #define CG6_FHC_1600 (3 << 11)
  85. #define CG6_FHC_CPU_MASK (3 << 9)
  86. #define CG6_FHC_CPU_SPARC (0 << 9)
  87. #define CG6_FHC_CPU_68020 (1 << 9)
  88. #define CG6_FHC_CPU_386 (2 << 9)
  89. #define CG6_FHC_TEST (1 << 8)
  90. #define CG6_FHC_TEST_X_SHIFT 4
  91. #define CG6_FHC_TEST_X_MASK 15
  92. #define CG6_FHC_TEST_Y_SHIFT 0
  93. #define CG6_FHC_TEST_Y_MASK 15
  94. /* FBC mode definitions */
  95. #define CG6_FBC_BLIT_IGNORE 0x00000000
  96. #define CG6_FBC_BLIT_NOSRC 0x00100000
  97. #define CG6_FBC_BLIT_SRC 0x00200000
  98. #define CG6_FBC_BLIT_ILLEGAL 0x00300000
  99. #define CG6_FBC_BLIT_MASK 0x00300000
  100. #define CG6_FBC_VBLANK 0x00080000
  101. #define CG6_FBC_MODE_IGNORE 0x00000000
  102. #define CG6_FBC_MODE_COLOR8 0x00020000
  103. #define CG6_FBC_MODE_COLOR1 0x00040000
  104. #define CG6_FBC_MODE_HRMONO 0x00060000
  105. #define CG6_FBC_MODE_MASK 0x00060000
  106. #define CG6_FBC_DRAW_IGNORE 0x00000000
  107. #define CG6_FBC_DRAW_RENDER 0x00008000
  108. #define CG6_FBC_DRAW_PICK 0x00010000
  109. #define CG6_FBC_DRAW_ILLEGAL 0x00018000
  110. #define CG6_FBC_DRAW_MASK 0x00018000
  111. #define CG6_FBC_BWRITE0_IGNORE 0x00000000
  112. #define CG6_FBC_BWRITE0_ENABLE 0x00002000
  113. #define CG6_FBC_BWRITE0_DISABLE 0x00004000
  114. #define CG6_FBC_BWRITE0_ILLEGAL 0x00006000
  115. #define CG6_FBC_BWRITE0_MASK 0x00006000
  116. #define CG6_FBC_BWRITE1_IGNORE 0x00000000
  117. #define CG6_FBC_BWRITE1_ENABLE 0x00000800
  118. #define CG6_FBC_BWRITE1_DISABLE 0x00001000
  119. #define CG6_FBC_BWRITE1_ILLEGAL 0x00001800
  120. #define CG6_FBC_BWRITE1_MASK 0x00001800
  121. #define CG6_FBC_BREAD_IGNORE 0x00000000
  122. #define CG6_FBC_BREAD_0 0x00000200
  123. #define CG6_FBC_BREAD_1 0x00000400
  124. #define CG6_FBC_BREAD_ILLEGAL 0x00000600
  125. #define CG6_FBC_BREAD_MASK 0x00000600
  126. #define CG6_FBC_BDISP_IGNORE 0x00000000
  127. #define CG6_FBC_BDISP_0 0x00000080
  128. #define CG6_FBC_BDISP_1 0x00000100
  129. #define CG6_FBC_BDISP_ILLEGAL 0x00000180
  130. #define CG6_FBC_BDISP_MASK 0x00000180
  131. #define CG6_FBC_INDEX_MOD 0x00000040
  132. #define CG6_FBC_INDEX_MASK 0x00000030
  133. /* THC definitions */
  134. #define CG6_THC_MISC_REV_SHIFT 16
  135. #define CG6_THC_MISC_REV_MASK 15
  136. #define CG6_THC_MISC_RESET (1 << 12)
  137. #define CG6_THC_MISC_VIDEO (1 << 10)
  138. #define CG6_THC_MISC_SYNC (1 << 9)
  139. #define CG6_THC_MISC_VSYNC (1 << 8)
  140. #define CG6_THC_MISC_SYNC_ENAB (1 << 7)
  141. #define CG6_THC_MISC_CURS_RES (1 << 6)
  142. #define CG6_THC_MISC_INT_ENAB (1 << 5)
  143. #define CG6_THC_MISC_INT (1 << 4)
  144. #define CG6_THC_MISC_INIT 0x9f
  145. /* The contents are unknown */
  146. struct cg6_tec {
  147. volatile int tec_matrix;
  148. volatile int tec_clip;
  149. volatile int tec_vdc;
  150. };
  151. struct cg6_thc {
  152. uint thc_pad0[512];
  153. volatile uint thc_hs; /* hsync timing */
  154. volatile uint thc_hsdvs;
  155. volatile uint thc_hd;
  156. volatile uint thc_vs; /* vsync timing */
  157. volatile uint thc_vd;
  158. volatile uint thc_refresh;
  159. volatile uint thc_misc;
  160. uint thc_pad1[56];
  161. volatile uint thc_cursxy; /* cursor x,y position (16 bits each) */
  162. volatile uint thc_cursmask[32]; /* cursor mask bits */
  163. volatile uint thc_cursbits[32]; /* what to show where mask enabled */
  164. };
  165. struct cg6_fbc {
  166. u32 xxx0[1];
  167. volatile u32 mode;
  168. volatile u32 clip;
  169. u32 xxx1[1];
  170. volatile u32 s;
  171. volatile u32 draw;
  172. volatile u32 blit;
  173. volatile u32 font;
  174. u32 xxx2[24];
  175. volatile u32 x0, y0, z0, color0;
  176. volatile u32 x1, y1, z1, color1;
  177. volatile u32 x2, y2, z2, color2;
  178. volatile u32 x3, y3, z3, color3;
  179. volatile u32 offx, offy;
  180. u32 xxx3[2];
  181. volatile u32 incx, incy;
  182. u32 xxx4[2];
  183. volatile u32 clipminx, clipminy;
  184. u32 xxx5[2];
  185. volatile u32 clipmaxx, clipmaxy;
  186. u32 xxx6[2];
  187. volatile u32 fg;
  188. volatile u32 bg;
  189. volatile u32 alu;
  190. volatile u32 pm;
  191. volatile u32 pixelm;
  192. u32 xxx7[2];
  193. volatile u32 patalign;
  194. volatile u32 pattern[8];
  195. u32 xxx8[432];
  196. volatile u32 apointx, apointy, apointz;
  197. u32 xxx9[1];
  198. volatile u32 rpointx, rpointy, rpointz;
  199. u32 xxx10[5];
  200. volatile u32 pointr, pointg, pointb, pointa;
  201. volatile u32 alinex, aliney, alinez;
  202. u32 xxx11[1];
  203. volatile u32 rlinex, rliney, rlinez;
  204. u32 xxx12[5];
  205. volatile u32 liner, lineg, lineb, linea;
  206. volatile u32 atrix, atriy, atriz;
  207. u32 xxx13[1];
  208. volatile u32 rtrix, rtriy, rtriz;
  209. u32 xxx14[5];
  210. volatile u32 trir, trig, trib, tria;
  211. volatile u32 aquadx, aquady, aquadz;
  212. u32 xxx15[1];
  213. volatile u32 rquadx, rquady, rquadz;
  214. u32 xxx16[5];
  215. volatile u32 quadr, quadg, quadb, quada;
  216. volatile u32 arectx, arecty, arectz;
  217. u32 xxx17[1];
  218. volatile u32 rrectx, rrecty, rrectz;
  219. u32 xxx18[5];
  220. volatile u32 rectr, rectg, rectb, recta;
  221. };
  222. struct bt_regs {
  223. volatile u32 addr;
  224. volatile u32 color_map;
  225. volatile u32 control;
  226. volatile u32 cursor;
  227. };
  228. struct cg6_par {
  229. spinlock_t lock;
  230. struct bt_regs __iomem *bt;
  231. struct cg6_fbc __iomem *fbc;
  232. struct cg6_thc __iomem *thc;
  233. struct cg6_tec __iomem *tec;
  234. volatile u32 __iomem *fhc;
  235. u32 flags;
  236. #define CG6_FLAG_BLANKED 0x00000001
  237. unsigned long physbase;
  238. unsigned long fbsize;
  239. struct sbus_dev *sdev;
  240. struct list_head list;
  241. };
  242. static int cg6_sync(struct fb_info *info)
  243. {
  244. struct cg6_par *par = (struct cg6_par *) info->par;
  245. struct cg6_fbc __iomem *fbc = par->fbc;
  246. int limit = 10000;
  247. do {
  248. if (!(sbus_readl(&fbc->s) & 0x10000000))
  249. break;
  250. udelay(10);
  251. } while (--limit > 0);
  252. return 0;
  253. }
  254. /**
  255. * cg6_fillrect - REQUIRED function. Can use generic routines if
  256. * non acclerated hardware and packed pixel based.
  257. * Draws a rectangle on the screen.
  258. *
  259. * @info: frame buffer structure that represents a single frame buffer
  260. * @rect: structure defining the rectagle and operation.
  261. */
  262. static void cg6_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  263. {
  264. struct cg6_par *par = (struct cg6_par *) info->par;
  265. struct cg6_fbc __iomem *fbc = par->fbc;
  266. unsigned long flags;
  267. s32 val;
  268. /* XXX doesn't handle ROP_XOR */
  269. spin_lock_irqsave(&par->lock, flags);
  270. cg6_sync(info);
  271. sbus_writel(rect->color, &fbc->fg);
  272. sbus_writel(~(u32)0, &fbc->pixelm);
  273. sbus_writel(0xea80ff00, &fbc->alu);
  274. sbus_writel(0, &fbc->s);
  275. sbus_writel(0, &fbc->clip);
  276. sbus_writel(~(u32)0, &fbc->pm);
  277. sbus_writel(rect->dy, &fbc->arecty);
  278. sbus_writel(rect->dx, &fbc->arectx);
  279. sbus_writel(rect->dy + rect->height, &fbc->arecty);
  280. sbus_writel(rect->dx + rect->width, &fbc->arectx);
  281. do {
  282. val = sbus_readl(&fbc->draw);
  283. } while (val < 0 && (val & 0x20000000));
  284. spin_unlock_irqrestore(&par->lock, flags);
  285. }
  286. /**
  287. * cg6_imageblit - REQUIRED function. Can use generic routines if
  288. * non acclerated hardware and packed pixel based.
  289. * Copies a image from system memory to the screen.
  290. *
  291. * @info: frame buffer structure that represents a single frame buffer
  292. * @image: structure defining the image.
  293. */
  294. static void cg6_imageblit(struct fb_info *info, const struct fb_image *image)
  295. {
  296. struct cg6_par *par = (struct cg6_par *) info->par;
  297. struct cg6_fbc __iomem *fbc = par->fbc;
  298. const u8 *data = image->data;
  299. unsigned long flags;
  300. u32 x, y;
  301. int i, width;
  302. if (image->depth > 1) {
  303. cfb_imageblit(info, image);
  304. return;
  305. }
  306. spin_lock_irqsave(&par->lock, flags);
  307. cg6_sync(info);
  308. sbus_writel(image->fg_color, &fbc->fg);
  309. sbus_writel(image->bg_color, &fbc->bg);
  310. sbus_writel(0x140000, &fbc->mode);
  311. sbus_writel(0xe880fc30, &fbc->alu);
  312. sbus_writel(~(u32)0, &fbc->pixelm);
  313. sbus_writel(0, &fbc->s);
  314. sbus_writel(0, &fbc->clip);
  315. sbus_writel(0xff, &fbc->pm);
  316. sbus_writel(32, &fbc->incx);
  317. sbus_writel(0, &fbc->incy);
  318. x = image->dx;
  319. y = image->dy;
  320. for (i = 0; i < image->height; i++) {
  321. width = image->width;
  322. while (width >= 32) {
  323. u32 val;
  324. sbus_writel(y, &fbc->y0);
  325. sbus_writel(x, &fbc->x0);
  326. sbus_writel(x + 32 - 1, &fbc->x1);
  327. val = ((u32)data[0] << 24) |
  328. ((u32)data[1] << 16) |
  329. ((u32)data[2] << 8) |
  330. ((u32)data[3] << 0);
  331. sbus_writel(val, &fbc->font);
  332. data += 4;
  333. x += 32;
  334. width -= 32;
  335. }
  336. if (width) {
  337. u32 val;
  338. sbus_writel(y, &fbc->y0);
  339. sbus_writel(x, &fbc->x0);
  340. sbus_writel(x + width - 1, &fbc->x1);
  341. if (width <= 8) {
  342. val = (u32) data[0] << 24;
  343. data += 1;
  344. } else if (width <= 16) {
  345. val = ((u32) data[0] << 24) |
  346. ((u32) data[1] << 16);
  347. data += 2;
  348. } else {
  349. val = ((u32) data[0] << 24) |
  350. ((u32) data[1] << 16) |
  351. ((u32) data[2] << 8);
  352. data += 3;
  353. }
  354. sbus_writel(val, &fbc->font);
  355. }
  356. y += 1;
  357. x = image->dx;
  358. }
  359. spin_unlock_irqrestore(&par->lock, flags);
  360. }
  361. /**
  362. * cg6_setcolreg - Optional function. Sets a color register.
  363. * @regno: boolean, 0 copy local, 1 get_user() function
  364. * @red: frame buffer colormap structure
  365. * @green: The green value which can be up to 16 bits wide
  366. * @blue: The blue value which can be up to 16 bits wide.
  367. * @transp: If supported the alpha value which can be up to 16 bits wide.
  368. * @info: frame buffer info structure
  369. */
  370. static int cg6_setcolreg(unsigned regno,
  371. unsigned red, unsigned green, unsigned blue,
  372. unsigned transp, struct fb_info *info)
  373. {
  374. struct cg6_par *par = (struct cg6_par *) info->par;
  375. struct bt_regs __iomem *bt = par->bt;
  376. unsigned long flags;
  377. if (regno >= 256)
  378. return 1;
  379. red >>= 8;
  380. green >>= 8;
  381. blue >>= 8;
  382. spin_lock_irqsave(&par->lock, flags);
  383. sbus_writel((u32)regno << 24, &bt->addr);
  384. sbus_writel((u32)red << 24, &bt->color_map);
  385. sbus_writel((u32)green << 24, &bt->color_map);
  386. sbus_writel((u32)blue << 24, &bt->color_map);
  387. spin_unlock_irqrestore(&par->lock, flags);
  388. return 0;
  389. }
  390. /**
  391. * cg6_blank - Optional function. Blanks the display.
  392. * @blank_mode: the blank mode we want.
  393. * @info: frame buffer structure that represents a single frame buffer
  394. */
  395. static int
  396. cg6_blank(int blank, struct fb_info *info)
  397. {
  398. struct cg6_par *par = (struct cg6_par *) info->par;
  399. struct cg6_thc __iomem *thc = par->thc;
  400. unsigned long flags;
  401. u32 val;
  402. spin_lock_irqsave(&par->lock, flags);
  403. switch (blank) {
  404. case FB_BLANK_UNBLANK: /* Unblanking */
  405. val = sbus_readl(&thc->thc_misc);
  406. val |= CG6_THC_MISC_VIDEO;
  407. sbus_writel(val, &thc->thc_misc);
  408. par->flags &= ~CG6_FLAG_BLANKED;
  409. break;
  410. case FB_BLANK_NORMAL: /* Normal blanking */
  411. case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
  412. case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
  413. case FB_BLANK_POWERDOWN: /* Poweroff */
  414. val = sbus_readl(&thc->thc_misc);
  415. val &= ~CG6_THC_MISC_VIDEO;
  416. sbus_writel(val, &thc->thc_misc);
  417. par->flags |= CG6_FLAG_BLANKED;
  418. break;
  419. }
  420. spin_unlock_irqrestore(&par->lock, flags);
  421. return 0;
  422. }
  423. static struct sbus_mmap_map cg6_mmap_map[] = {
  424. {
  425. .voff = CG6_FBC,
  426. .poff = CG6_FBC_OFFSET,
  427. .size = PAGE_SIZE
  428. },
  429. {
  430. .voff = CG6_TEC,
  431. .poff = CG6_TEC_OFFSET,
  432. .size = PAGE_SIZE
  433. },
  434. {
  435. .voff = CG6_BTREGS,
  436. .poff = CG6_BROOKTREE_OFFSET,
  437. .size = PAGE_SIZE
  438. },
  439. {
  440. .voff = CG6_FHC,
  441. .poff = CG6_FHC_OFFSET,
  442. .size = PAGE_SIZE
  443. },
  444. {
  445. .voff = CG6_THC,
  446. .poff = CG6_THC_OFFSET,
  447. .size = PAGE_SIZE
  448. },
  449. {
  450. .voff = CG6_ROM,
  451. .poff = CG6_ROM_OFFSET,
  452. .size = 0x10000
  453. },
  454. {
  455. .voff = CG6_RAM,
  456. .poff = CG6_RAM_OFFSET,
  457. .size = SBUS_MMAP_FBSIZE(1)
  458. },
  459. {
  460. .voff = CG6_DHC,
  461. .poff = CG6_DHC_OFFSET,
  462. .size = 0x40000
  463. },
  464. { .size = 0 }
  465. };
  466. static int cg6_mmap(struct fb_info *info, struct file *file, struct vm_area_struct *vma)
  467. {
  468. struct cg6_par *par = (struct cg6_par *)info->par;
  469. return sbusfb_mmap_helper(cg6_mmap_map,
  470. par->physbase, par->fbsize,
  471. par->sdev->reg_addrs[0].which_io,
  472. vma);
  473. }
  474. static int cg6_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
  475. unsigned long arg, struct fb_info *info)
  476. {
  477. struct cg6_par *par = (struct cg6_par *) info->par;
  478. return sbusfb_ioctl_helper(cmd, arg, info,
  479. FBTYPE_SUNFAST_COLOR, 8, par->fbsize);
  480. }
  481. /*
  482. * Initialisation
  483. */
  484. static void
  485. cg6_init_fix(struct fb_info *info, int linebytes)
  486. {
  487. struct cg6_par *par = (struct cg6_par *)info->par;
  488. const char *cg6_cpu_name, *cg6_card_name;
  489. u32 conf;
  490. conf = sbus_readl(par->fhc);
  491. switch(conf & CG6_FHC_CPU_MASK) {
  492. case CG6_FHC_CPU_SPARC:
  493. cg6_cpu_name = "sparc";
  494. break;
  495. case CG6_FHC_CPU_68020:
  496. cg6_cpu_name = "68020";
  497. break;
  498. default:
  499. cg6_cpu_name = "i386";
  500. break;
  501. };
  502. if (((conf >> CG6_FHC_REV_SHIFT) & CG6_FHC_REV_MASK) >= 11) {
  503. if (par->fbsize <= 0x100000) {
  504. cg6_card_name = "TGX";
  505. } else {
  506. cg6_card_name = "TGX+";
  507. }
  508. } else {
  509. if (par->fbsize <= 0x100000) {
  510. cg6_card_name = "GX";
  511. } else {
  512. cg6_card_name = "GX+";
  513. }
  514. }
  515. sprintf(info->fix.id, "%s %s", cg6_card_name, cg6_cpu_name);
  516. info->fix.id[sizeof(info->fix.id)-1] = 0;
  517. info->fix.type = FB_TYPE_PACKED_PIXELS;
  518. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  519. info->fix.line_length = linebytes;
  520. info->fix.accel = FB_ACCEL_SUN_CGSIX;
  521. }
  522. /* Initialize Brooktree DAC */
  523. static void cg6_bt_init(struct cg6_par *par)
  524. {
  525. struct bt_regs __iomem *bt = par->bt;
  526. sbus_writel(0x04 << 24, &bt->addr); /* color planes */
  527. sbus_writel(0xff << 24, &bt->control);
  528. sbus_writel(0x05 << 24, &bt->addr);
  529. sbus_writel(0x00 << 24, &bt->control);
  530. sbus_writel(0x06 << 24, &bt->addr); /* overlay plane */
  531. sbus_writel(0x73 << 24, &bt->control);
  532. sbus_writel(0x07 << 24, &bt->addr);
  533. sbus_writel(0x00 << 24, &bt->control);
  534. }
  535. static void cg6_chip_init(struct fb_info *info)
  536. {
  537. struct cg6_par *par = (struct cg6_par *) info->par;
  538. struct cg6_tec __iomem *tec = par->tec;
  539. struct cg6_fbc __iomem *fbc = par->fbc;
  540. u32 rev, conf, mode, tmp;
  541. int i;
  542. /* Turn off stuff in the Transform Engine. */
  543. sbus_writel(0, &tec->tec_matrix);
  544. sbus_writel(0, &tec->tec_clip);
  545. sbus_writel(0, &tec->tec_vdc);
  546. /* Take care of bugs in old revisions. */
  547. rev = (sbus_readl(par->fhc) >> CG6_FHC_REV_SHIFT) & CG6_FHC_REV_MASK;
  548. if (rev < 5) {
  549. conf = (sbus_readl(par->fhc) & CG6_FHC_RES_MASK) |
  550. CG6_FHC_CPU_68020 | CG6_FHC_TEST |
  551. (11 << CG6_FHC_TEST_X_SHIFT) |
  552. (11 << CG6_FHC_TEST_Y_SHIFT);
  553. if (rev < 2)
  554. conf |= CG6_FHC_DST_DISABLE;
  555. sbus_writel(conf, par->fhc);
  556. }
  557. /* Set things in the FBC. Bad things appear to happen if we do
  558. * back to back store/loads on the mode register, so copy it
  559. * out instead. */
  560. mode = sbus_readl(&fbc->mode);
  561. do {
  562. i = sbus_readl(&fbc->s);
  563. } while (i & 0x10000000);
  564. mode &= ~(CG6_FBC_BLIT_MASK | CG6_FBC_MODE_MASK |
  565. CG6_FBC_DRAW_MASK | CG6_FBC_BWRITE0_MASK |
  566. CG6_FBC_BWRITE1_MASK | CG6_FBC_BREAD_MASK |
  567. CG6_FBC_BDISP_MASK);
  568. mode |= (CG6_FBC_BLIT_SRC | CG6_FBC_MODE_COLOR8 |
  569. CG6_FBC_DRAW_RENDER | CG6_FBC_BWRITE0_ENABLE |
  570. CG6_FBC_BWRITE1_DISABLE | CG6_FBC_BREAD_0 |
  571. CG6_FBC_BDISP_0);
  572. sbus_writel(mode, &fbc->mode);
  573. sbus_writel(0, &fbc->clip);
  574. sbus_writel(0, &fbc->offx);
  575. sbus_writel(0, &fbc->offy);
  576. sbus_writel(0, &fbc->clipminx);
  577. sbus_writel(0, &fbc->clipminy);
  578. sbus_writel(info->var.xres - 1, &fbc->clipmaxx);
  579. sbus_writel(info->var.yres - 1, &fbc->clipmaxy);
  580. }
  581. struct all_info {
  582. struct fb_info info;
  583. struct cg6_par par;
  584. struct list_head list;
  585. };
  586. static LIST_HEAD(cg6_list);
  587. static void cg6_init_one(struct sbus_dev *sdev)
  588. {
  589. struct all_info *all;
  590. int linebytes;
  591. all = kmalloc(sizeof(*all), GFP_KERNEL);
  592. if (!all) {
  593. printk(KERN_ERR "cg6: Cannot allocate memory.\n");
  594. return;
  595. }
  596. memset(all, 0, sizeof(*all));
  597. INIT_LIST_HEAD(&all->list);
  598. spin_lock_init(&all->par.lock);
  599. all->par.sdev = sdev;
  600. all->par.physbase = sdev->reg_addrs[0].phys_addr;
  601. sbusfb_fill_var(&all->info.var, sdev->prom_node, 8);
  602. all->info.var.red.length = 8;
  603. all->info.var.green.length = 8;
  604. all->info.var.blue.length = 8;
  605. linebytes = prom_getintdefault(sdev->prom_node, "linebytes",
  606. all->info.var.xres);
  607. all->par.fbsize = PAGE_ALIGN(linebytes * all->info.var.yres);
  608. if (prom_getbool(sdev->prom_node, "dblbuf"))
  609. all->par.fbsize *= 4;
  610. all->par.fbc = sbus_ioremap(&sdev->resource[0], CG6_FBC_OFFSET,
  611. 4096, "cgsix fbc");
  612. all->par.tec = sbus_ioremap(&sdev->resource[0], CG6_TEC_OFFSET,
  613. sizeof(struct cg6_tec), "cgsix tec");
  614. all->par.thc = sbus_ioremap(&sdev->resource[0], CG6_THC_OFFSET,
  615. sizeof(struct cg6_thc), "cgsix thc");
  616. all->par.bt = sbus_ioremap(&sdev->resource[0], CG6_BROOKTREE_OFFSET,
  617. sizeof(struct bt_regs), "cgsix dac");
  618. all->par.fhc = sbus_ioremap(&sdev->resource[0], CG6_FHC_OFFSET,
  619. sizeof(u32), "cgsix fhc");
  620. all->info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_IMAGEBLIT |
  621. FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT;
  622. all->info.fbops = &cg6_ops;
  623. #ifdef CONFIG_SPARC32
  624. all->info.screen_base = (char __iomem *)
  625. prom_getintdefault(sdev->prom_node, "address", 0);
  626. #endif
  627. if (!all->info.screen_base)
  628. all->info.screen_base =
  629. sbus_ioremap(&sdev->resource[0], CG6_RAM_OFFSET,
  630. all->par.fbsize, "cgsix ram");
  631. all->info.par = &all->par;
  632. all->info.var.accel_flags = FB_ACCELF_TEXT;
  633. cg6_bt_init(&all->par);
  634. cg6_chip_init(&all->info);
  635. cg6_blank(0, &all->info);
  636. if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
  637. printk(KERN_ERR "cg6: Could not allocate color map.\n");
  638. kfree(all);
  639. return;
  640. }
  641. fb_set_cmap(&all->info.cmap, &all->info);
  642. cg6_init_fix(&all->info, linebytes);
  643. if (register_framebuffer(&all->info) < 0) {
  644. printk(KERN_ERR "cg6: Could not register framebuffer.\n");
  645. fb_dealloc_cmap(&all->info.cmap);
  646. kfree(all);
  647. return;
  648. }
  649. list_add(&all->list, &cg6_list);
  650. printk("cg6: CGsix [%s] at %lx:%lx\n",
  651. all->info.fix.id,
  652. (long) sdev->reg_addrs[0].which_io,
  653. (long) sdev->reg_addrs[0].phys_addr);
  654. }
  655. int __init cg6_init(void)
  656. {
  657. struct sbus_bus *sbus;
  658. struct sbus_dev *sdev;
  659. if (fb_get_options("cg6fb", NULL))
  660. return -ENODEV;
  661. for_all_sbusdev(sdev, sbus) {
  662. if (!strcmp(sdev->prom_name, "cgsix") ||
  663. !strcmp(sdev->prom_name, "cgthree+"))
  664. cg6_init_one(sdev);
  665. }
  666. return 0;
  667. }
  668. void __exit cg6_exit(void)
  669. {
  670. struct list_head *pos, *tmp;
  671. list_for_each_safe(pos, tmp, &cg6_list) {
  672. struct all_info *all = list_entry(pos, typeof(*all), list);
  673. unregister_framebuffer(&all->info);
  674. fb_dealloc_cmap(&all->info.cmap);
  675. kfree(all);
  676. }
  677. }
  678. int __init
  679. cg6_setup(char *arg)
  680. {
  681. /* No cmdline options yet... */
  682. return 0;
  683. }
  684. module_init(cg6_init);
  685. #ifdef MODULE
  686. module_exit(cg6_exit);
  687. #endif
  688. MODULE_DESCRIPTION("framebuffer driver for CGsix chipsets");
  689. MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
  690. MODULE_LICENSE("GPL");