cg6.c 21 KB

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