cg6.c 22 KB

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