stifb.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420
  1. /*
  2. * linux/drivers/video/stifb.c -
  3. * Low level Frame buffer driver for HP workstations with
  4. * STI (standard text interface) video firmware.
  5. *
  6. * Copyright (C) 2001-2006 Helge Deller <deller@gmx.de>
  7. * Portions Copyright (C) 2001 Thomas Bogendoerfer <tsbogend@alpha.franken.de>
  8. *
  9. * Based on:
  10. * - linux/drivers/video/artistfb.c -- Artist frame buffer driver
  11. * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
  12. * - based on skeletonfb, which was
  13. * Created 28 Dec 1997 by Geert Uytterhoeven
  14. * - HP Xhp cfb-based X11 window driver for XFree86
  15. * (c)Copyright 1992 Hewlett-Packard Co.
  16. *
  17. *
  18. * The following graphics display devices (NGLE family) are supported by this driver:
  19. *
  20. * HPA4070A known as "HCRX", a 1280x1024 color device with 8 planes
  21. * HPA4071A known as "HCRX24", a 1280x1024 color device with 24 planes,
  22. * optionally available with a hardware accelerator as HPA4071A_Z
  23. * HPA1659A known as "CRX", a 1280x1024 color device with 8 planes
  24. * HPA1439A known as "CRX24", a 1280x1024 color device with 24 planes,
  25. * optionally available with a hardware accelerator.
  26. * HPA1924A known as "GRX", a 1280x1024 grayscale device with 8 planes
  27. * HPA2269A known as "Dual CRX", a 1280x1024 color device with 8 planes,
  28. * implements support for two displays on a single graphics card.
  29. * HP710C internal graphics support optionally available on the HP9000s710 SPU,
  30. * supports 1280x1024 color displays with 8 planes.
  31. * HP710G same as HP710C, 1280x1024 grayscale only
  32. * HP710L same as HP710C, 1024x768 color only
  33. * HP712 internal graphics support on HP9000s712 SPU, supports 640x480,
  34. * 1024x768 or 1280x1024 color displays on 8 planes (Artist)
  35. *
  36. * This file is subject to the terms and conditions of the GNU General Public
  37. * License. See the file COPYING in the main directory of this archive
  38. * for more details.
  39. */
  40. /* TODO:
  41. * - 1bpp mode is completely untested
  42. * - add support for h/w acceleration
  43. * - add hardware cursor
  44. * - automatically disable double buffering (e.g. on RDI precisionbook laptop)
  45. */
  46. /* on supported graphic devices you may:
  47. * #define FALLBACK_TO_1BPP to fall back to 1 bpp, or
  48. * #undef FALLBACK_TO_1BPP to reject support for unsupported cards */
  49. #undef FALLBACK_TO_1BPP
  50. #undef DEBUG_STIFB_REGS /* debug sti register accesses */
  51. #include <linux/module.h>
  52. #include <linux/kernel.h>
  53. #include <linux/errno.h>
  54. #include <linux/string.h>
  55. #include <linux/mm.h>
  56. #include <linux/slab.h>
  57. #include <linux/delay.h>
  58. #include <linux/fb.h>
  59. #include <linux/init.h>
  60. #include <linux/ioport.h>
  61. #include <asm/grfioctl.h> /* for HP-UX compatibility */
  62. #include <asm/uaccess.h>
  63. #include "sticore.h"
  64. /* REGION_BASE(fb_info, index) returns the virtual address for region <index> */
  65. #define REGION_BASE(fb_info, index) \
  66. F_EXTEND(fb_info->sti->glob_cfg->region_ptrs[index])
  67. #define NGLEDEVDEPROM_CRT_REGION 1
  68. #define NR_PALETTE 256
  69. typedef struct {
  70. __s32 video_config_reg;
  71. __s32 misc_video_start;
  72. __s32 horiz_timing_fmt;
  73. __s32 serr_timing_fmt;
  74. __s32 vert_timing_fmt;
  75. __s32 horiz_state;
  76. __s32 vert_state;
  77. __s32 vtg_state_elements;
  78. __s32 pipeline_delay;
  79. __s32 misc_video_end;
  80. } video_setup_t;
  81. typedef struct {
  82. __s16 sizeof_ngle_data;
  83. __s16 x_size_visible; /* visible screen dim in pixels */
  84. __s16 y_size_visible;
  85. __s16 pad2[15];
  86. __s16 cursor_pipeline_delay;
  87. __s16 video_interleaves;
  88. __s32 pad3[11];
  89. } ngle_rom_t;
  90. struct stifb_info {
  91. struct fb_info info;
  92. unsigned int id;
  93. ngle_rom_t ngle_rom;
  94. struct sti_struct *sti;
  95. int deviceSpecificConfig;
  96. u32 pseudo_palette[16];
  97. };
  98. static int __initdata stifb_bpp_pref[MAX_STI_ROMS];
  99. /* ------------------- chipset specific functions -------------------------- */
  100. /* offsets to graphic-chip internal registers */
  101. #define REG_1 0x000118
  102. #define REG_2 0x000480
  103. #define REG_3 0x0004a0
  104. #define REG_4 0x000600
  105. #define REG_6 0x000800
  106. #define REG_8 0x000820
  107. #define REG_9 0x000a04
  108. #define REG_10 0x018000
  109. #define REG_11 0x018004
  110. #define REG_12 0x01800c
  111. #define REG_13 0x018018
  112. #define REG_14 0x01801c
  113. #define REG_15 0x200000
  114. #define REG_15b0 0x200000
  115. #define REG_16b1 0x200005
  116. #define REG_16b3 0x200007
  117. #define REG_21 0x200218
  118. #define REG_22 0x0005a0
  119. #define REG_23 0x0005c0
  120. #define REG_26 0x200118
  121. #define REG_27 0x200308
  122. #define REG_32 0x21003c
  123. #define REG_33 0x210040
  124. #define REG_34 0x200008
  125. #define REG_35 0x018010
  126. #define REG_38 0x210020
  127. #define REG_39 0x210120
  128. #define REG_40 0x210130
  129. #define REG_42 0x210028
  130. #define REG_43 0x21002c
  131. #define REG_44 0x210030
  132. #define REG_45 0x210034
  133. #define READ_BYTE(fb,reg) gsc_readb((fb)->info.fix.mmio_start + (reg))
  134. #define READ_WORD(fb,reg) gsc_readl((fb)->info.fix.mmio_start + (reg))
  135. #ifndef DEBUG_STIFB_REGS
  136. # define DEBUG_OFF()
  137. # define DEBUG_ON()
  138. # define WRITE_BYTE(value,fb,reg) gsc_writeb((value),(fb)->info.fix.mmio_start + (reg))
  139. # define WRITE_WORD(value,fb,reg) gsc_writel((value),(fb)->info.fix.mmio_start + (reg))
  140. #else
  141. static int debug_on = 1;
  142. # define DEBUG_OFF() debug_on=0
  143. # define DEBUG_ON() debug_on=1
  144. # define WRITE_BYTE(value,fb,reg) do { if (debug_on) \
  145. printk(KERN_DEBUG "%30s: WRITE_BYTE(0x%06x) = 0x%02x (old=0x%02x)\n", \
  146. __func__, reg, value, READ_BYTE(fb,reg)); \
  147. gsc_writeb((value),(fb)->info.fix.mmio_start + (reg)); } while (0)
  148. # define WRITE_WORD(value,fb,reg) do { if (debug_on) \
  149. printk(KERN_DEBUG "%30s: WRITE_WORD(0x%06x) = 0x%08x (old=0x%08x)\n", \
  150. __func__, reg, value, READ_WORD(fb,reg)); \
  151. gsc_writel((value),(fb)->info.fix.mmio_start + (reg)); } while (0)
  152. #endif /* DEBUG_STIFB_REGS */
  153. #define ENABLE 1 /* for enabling/disabling screen */
  154. #define DISABLE 0
  155. #define NGLE_LOCK(fb_info) do { } while (0)
  156. #define NGLE_UNLOCK(fb_info) do { } while (0)
  157. static void
  158. SETUP_HW(struct stifb_info *fb)
  159. {
  160. char stat;
  161. do {
  162. stat = READ_BYTE(fb, REG_15b0);
  163. if (!stat)
  164. stat = READ_BYTE(fb, REG_15b0);
  165. } while (stat);
  166. }
  167. static void
  168. SETUP_FB(struct stifb_info *fb)
  169. {
  170. unsigned int reg10_value = 0;
  171. SETUP_HW(fb);
  172. switch (fb->id)
  173. {
  174. case CRT_ID_VISUALIZE_EG:
  175. case S9000_ID_ARTIST:
  176. case S9000_ID_A1659A:
  177. reg10_value = 0x13601000;
  178. break;
  179. case S9000_ID_A1439A:
  180. if (fb->info.var.bits_per_pixel == 32)
  181. reg10_value = 0xBBA0A000;
  182. else
  183. reg10_value = 0x13601000;
  184. break;
  185. case S9000_ID_HCRX:
  186. if (fb->info.var.bits_per_pixel == 32)
  187. reg10_value = 0xBBA0A000;
  188. else
  189. reg10_value = 0x13602000;
  190. break;
  191. case S9000_ID_TIMBER:
  192. case CRX24_OVERLAY_PLANES:
  193. reg10_value = 0x13602000;
  194. break;
  195. }
  196. if (reg10_value)
  197. WRITE_WORD(reg10_value, fb, REG_10);
  198. WRITE_WORD(0x83000300, fb, REG_14);
  199. SETUP_HW(fb);
  200. WRITE_BYTE(1, fb, REG_16b1);
  201. }
  202. static void
  203. START_IMAGE_COLORMAP_ACCESS(struct stifb_info *fb)
  204. {
  205. SETUP_HW(fb);
  206. WRITE_WORD(0xBBE0F000, fb, REG_10);
  207. WRITE_WORD(0x03000300, fb, REG_14);
  208. WRITE_WORD(~0, fb, REG_13);
  209. }
  210. static void
  211. WRITE_IMAGE_COLOR(struct stifb_info *fb, int index, int color)
  212. {
  213. SETUP_HW(fb);
  214. WRITE_WORD(((0x100+index)<<2), fb, REG_3);
  215. WRITE_WORD(color, fb, REG_4);
  216. }
  217. static void
  218. FINISH_IMAGE_COLORMAP_ACCESS(struct stifb_info *fb)
  219. {
  220. WRITE_WORD(0x400, fb, REG_2);
  221. if (fb->info.var.bits_per_pixel == 32) {
  222. WRITE_WORD(0x83000100, fb, REG_1);
  223. } else {
  224. if (fb->id == S9000_ID_ARTIST || fb->id == CRT_ID_VISUALIZE_EG)
  225. WRITE_WORD(0x80000100, fb, REG_26);
  226. else
  227. WRITE_WORD(0x80000100, fb, REG_1);
  228. }
  229. SETUP_FB(fb);
  230. }
  231. static void
  232. SETUP_RAMDAC(struct stifb_info *fb)
  233. {
  234. SETUP_HW(fb);
  235. WRITE_WORD(0x04000000, fb, 0x1020);
  236. WRITE_WORD(0xff000000, fb, 0x1028);
  237. }
  238. static void
  239. CRX24_SETUP_RAMDAC(struct stifb_info *fb)
  240. {
  241. SETUP_HW(fb);
  242. WRITE_WORD(0x04000000, fb, 0x1000);
  243. WRITE_WORD(0x02000000, fb, 0x1004);
  244. WRITE_WORD(0xff000000, fb, 0x1008);
  245. WRITE_WORD(0x05000000, fb, 0x1000);
  246. WRITE_WORD(0x02000000, fb, 0x1004);
  247. WRITE_WORD(0x03000000, fb, 0x1008);
  248. }
  249. #if 0
  250. static void
  251. HCRX_SETUP_RAMDAC(struct stifb_info *fb)
  252. {
  253. WRITE_WORD(0xffffffff, fb, REG_32);
  254. }
  255. #endif
  256. static void
  257. CRX24_SET_OVLY_MASK(struct stifb_info *fb)
  258. {
  259. SETUP_HW(fb);
  260. WRITE_WORD(0x13a02000, fb, REG_11);
  261. WRITE_WORD(0x03000300, fb, REG_14);
  262. WRITE_WORD(0x000017f0, fb, REG_3);
  263. WRITE_WORD(0xffffffff, fb, REG_13);
  264. WRITE_WORD(0xffffffff, fb, REG_22);
  265. WRITE_WORD(0x00000000, fb, REG_23);
  266. }
  267. static void
  268. ENABLE_DISABLE_DISPLAY(struct stifb_info *fb, int enable)
  269. {
  270. unsigned int value = enable ? 0x43000000 : 0x03000000;
  271. SETUP_HW(fb);
  272. WRITE_WORD(0x06000000, fb, 0x1030);
  273. WRITE_WORD(value, fb, 0x1038);
  274. }
  275. static void
  276. CRX24_ENABLE_DISABLE_DISPLAY(struct stifb_info *fb, int enable)
  277. {
  278. unsigned int value = enable ? 0x10000000 : 0x30000000;
  279. SETUP_HW(fb);
  280. WRITE_WORD(0x01000000, fb, 0x1000);
  281. WRITE_WORD(0x02000000, fb, 0x1004);
  282. WRITE_WORD(value, fb, 0x1008);
  283. }
  284. static void
  285. ARTIST_ENABLE_DISABLE_DISPLAY(struct stifb_info *fb, int enable)
  286. {
  287. u32 DregsMiscVideo = REG_21;
  288. u32 DregsMiscCtl = REG_27;
  289. SETUP_HW(fb);
  290. if (enable) {
  291. WRITE_WORD(READ_WORD(fb, DregsMiscVideo) | 0x0A000000, fb, DregsMiscVideo);
  292. WRITE_WORD(READ_WORD(fb, DregsMiscCtl) | 0x00800000, fb, DregsMiscCtl);
  293. } else {
  294. WRITE_WORD(READ_WORD(fb, DregsMiscVideo) & ~0x0A000000, fb, DregsMiscVideo);
  295. WRITE_WORD(READ_WORD(fb, DregsMiscCtl) & ~0x00800000, fb, DregsMiscCtl);
  296. }
  297. }
  298. #define GET_ROMTABLE_INDEX(fb) \
  299. (READ_BYTE(fb, REG_16b3) - 1)
  300. #define HYPER_CONFIG_PLANES_24 0x00000100
  301. #define IS_24_DEVICE(fb) \
  302. (fb->deviceSpecificConfig & HYPER_CONFIG_PLANES_24)
  303. #define IS_888_DEVICE(fb) \
  304. (!(IS_24_DEVICE(fb)))
  305. #define GET_FIFO_SLOTS(fb, cnt, numslots) \
  306. { while (cnt < numslots) \
  307. cnt = READ_WORD(fb, REG_34); \
  308. cnt -= numslots; \
  309. }
  310. #define IndexedDcd 0 /* Pixel data is indexed (pseudo) color */
  311. #define Otc04 2 /* Pixels in each longword transfer (4) */
  312. #define Otc32 5 /* Pixels in each longword transfer (32) */
  313. #define Ots08 3 /* Each pixel is size (8)d transfer (1) */
  314. #define OtsIndirect 6 /* Each bit goes through FG/BG color(8) */
  315. #define AddrLong 5 /* FB address is Long aligned (pixel) */
  316. #define BINovly 0x2 /* 8 bit overlay */
  317. #define BINapp0I 0x0 /* Application Buffer 0, Indexed */
  318. #define BINapp1I 0x1 /* Application Buffer 1, Indexed */
  319. #define BINapp0F8 0xa /* Application Buffer 0, Fractional 8-8-8 */
  320. #define BINattr 0xd /* Attribute Bitmap */
  321. #define RopSrc 0x3
  322. #define BitmapExtent08 3 /* Each write hits ( 8) bits in depth */
  323. #define BitmapExtent32 5 /* Each write hits (32) bits in depth */
  324. #define DataDynamic 0 /* Data register reloaded by direct access */
  325. #define MaskDynamic 1 /* Mask register reloaded by direct access */
  326. #define MaskOtc 0 /* Mask contains Object Count valid bits */
  327. #define MaskAddrOffset(offset) (offset)
  328. #define StaticReg(en) (en)
  329. #define BGx(en) (en)
  330. #define FGx(en) (en)
  331. #define BAJustPoint(offset) (offset)
  332. #define BAIndexBase(base) (base)
  333. #define BA(F,C,S,A,J,B,I) \
  334. (((F)<<31)|((C)<<27)|((S)<<24)|((A)<<21)|((J)<<16)|((B)<<12)|(I))
  335. #define IBOvals(R,M,X,S,D,L,B,F) \
  336. (((R)<<8)|((M)<<16)|((X)<<24)|((S)<<29)|((D)<<28)|((L)<<31)|((B)<<1)|(F))
  337. #define NGLE_QUICK_SET_IMAGE_BITMAP_OP(fb, val) \
  338. WRITE_WORD(val, fb, REG_14)
  339. #define NGLE_QUICK_SET_DST_BM_ACCESS(fb, val) \
  340. WRITE_WORD(val, fb, REG_11)
  341. #define NGLE_QUICK_SET_CTL_PLN_REG(fb, val) \
  342. WRITE_WORD(val, fb, REG_12)
  343. #define NGLE_REALLY_SET_IMAGE_PLANEMASK(fb, plnmsk32) \
  344. WRITE_WORD(plnmsk32, fb, REG_13)
  345. #define NGLE_REALLY_SET_IMAGE_FG_COLOR(fb, fg32) \
  346. WRITE_WORD(fg32, fb, REG_35)
  347. #define NGLE_SET_TRANSFERDATA(fb, val) \
  348. WRITE_WORD(val, fb, REG_8)
  349. #define NGLE_SET_DSTXY(fb, val) \
  350. WRITE_WORD(val, fb, REG_6)
  351. #define NGLE_LONG_FB_ADDRESS(fbaddrbase, x, y) ( \
  352. (u32) (fbaddrbase) + \
  353. ( (unsigned int) ( (y) << 13 ) | \
  354. (unsigned int) ( (x) << 2 ) ) \
  355. )
  356. #define NGLE_BINC_SET_DSTADDR(fb, addr) \
  357. WRITE_WORD(addr, fb, REG_3)
  358. #define NGLE_BINC_SET_SRCADDR(fb, addr) \
  359. WRITE_WORD(addr, fb, REG_2)
  360. #define NGLE_BINC_SET_DSTMASK(fb, mask) \
  361. WRITE_WORD(mask, fb, REG_22)
  362. #define NGLE_BINC_WRITE32(fb, data32) \
  363. WRITE_WORD(data32, fb, REG_23)
  364. #define START_COLORMAPLOAD(fb, cmapBltCtlData32) \
  365. WRITE_WORD((cmapBltCtlData32), fb, REG_38)
  366. #define SET_LENXY_START_RECFILL(fb, lenxy) \
  367. WRITE_WORD(lenxy, fb, REG_9)
  368. static void
  369. HYPER_ENABLE_DISABLE_DISPLAY(struct stifb_info *fb, int enable)
  370. {
  371. u32 DregsHypMiscVideo = REG_33;
  372. unsigned int value;
  373. SETUP_HW(fb);
  374. value = READ_WORD(fb, DregsHypMiscVideo);
  375. if (enable)
  376. value |= 0x0A000000;
  377. else
  378. value &= ~0x0A000000;
  379. WRITE_WORD(value, fb, DregsHypMiscVideo);
  380. }
  381. /* BufferNumbers used by SETUP_ATTR_ACCESS() */
  382. #define BUFF0_CMAP0 0x00001e02
  383. #define BUFF1_CMAP0 0x02001e02
  384. #define BUFF1_CMAP3 0x0c001e02
  385. #define ARTIST_CMAP0 0x00000102
  386. #define HYPER_CMAP8 0x00000100
  387. #define HYPER_CMAP24 0x00000800
  388. static void
  389. SETUP_ATTR_ACCESS(struct stifb_info *fb, unsigned BufferNumber)
  390. {
  391. SETUP_HW(fb);
  392. WRITE_WORD(0x2EA0D000, fb, REG_11);
  393. WRITE_WORD(0x23000302, fb, REG_14);
  394. WRITE_WORD(BufferNumber, fb, REG_12);
  395. WRITE_WORD(0xffffffff, fb, REG_8);
  396. }
  397. static void
  398. SET_ATTR_SIZE(struct stifb_info *fb, int width, int height)
  399. {
  400. /* REG_6 seems to have special values when run on a
  401. RDI precisionbook parisc laptop (INTERNAL_EG_DX1024 or
  402. INTERNAL_EG_X1024). The values are:
  403. 0x2f0: internal (LCD) & external display enabled
  404. 0x2a0: external display only
  405. 0x000: zero on standard artist graphic cards
  406. */
  407. WRITE_WORD(0x00000000, fb, REG_6);
  408. WRITE_WORD((width<<16) | height, fb, REG_9);
  409. WRITE_WORD(0x05000000, fb, REG_6);
  410. WRITE_WORD(0x00040001, fb, REG_9);
  411. }
  412. static void
  413. FINISH_ATTR_ACCESS(struct stifb_info *fb)
  414. {
  415. SETUP_HW(fb);
  416. WRITE_WORD(0x00000000, fb, REG_12);
  417. }
  418. static void
  419. elkSetupPlanes(struct stifb_info *fb)
  420. {
  421. SETUP_RAMDAC(fb);
  422. SETUP_FB(fb);
  423. }
  424. static void
  425. ngleSetupAttrPlanes(struct stifb_info *fb, int BufferNumber)
  426. {
  427. SETUP_ATTR_ACCESS(fb, BufferNumber);
  428. SET_ATTR_SIZE(fb, fb->info.var.xres, fb->info.var.yres);
  429. FINISH_ATTR_ACCESS(fb);
  430. SETUP_FB(fb);
  431. }
  432. static void
  433. rattlerSetupPlanes(struct stifb_info *fb)
  434. {
  435. int saved_id, y;
  436. /* Write RAMDAC pixel read mask register so all overlay
  437. * planes are display-enabled. (CRX24 uses Bt462 pixel
  438. * read mask register for overlay planes, not image planes).
  439. */
  440. CRX24_SETUP_RAMDAC(fb);
  441. /* change fb->id temporarily to fool SETUP_FB() */
  442. saved_id = fb->id;
  443. fb->id = CRX24_OVERLAY_PLANES;
  444. SETUP_FB(fb);
  445. fb->id = saved_id;
  446. for (y = 0; y < fb->info.var.yres; ++y)
  447. memset(fb->info.screen_base + y * fb->info.fix.line_length,
  448. 0xff, fb->info.var.xres * fb->info.var.bits_per_pixel/8);
  449. CRX24_SET_OVLY_MASK(fb);
  450. SETUP_FB(fb);
  451. }
  452. #define HYPER_CMAP_TYPE 0
  453. #define NGLE_CMAP_INDEXED0_TYPE 0
  454. #define NGLE_CMAP_OVERLAY_TYPE 3
  455. /* typedef of LUT (Colormap) BLT Control Register */
  456. typedef union /* Note assumption that fields are packed left-to-right */
  457. { u32 all;
  458. struct
  459. {
  460. unsigned enable : 1;
  461. unsigned waitBlank : 1;
  462. unsigned reserved1 : 4;
  463. unsigned lutOffset : 10; /* Within destination LUT */
  464. unsigned lutType : 2; /* Cursor, image, overlay */
  465. unsigned reserved2 : 4;
  466. unsigned length : 10;
  467. } fields;
  468. } NgleLutBltCtl;
  469. #if 0
  470. static NgleLutBltCtl
  471. setNgleLutBltCtl(struct stifb_info *fb, int offsetWithinLut, int length)
  472. {
  473. NgleLutBltCtl lutBltCtl;
  474. /* set enable, zero reserved fields */
  475. lutBltCtl.all = 0x80000000;
  476. lutBltCtl.fields.length = length;
  477. switch (fb->id)
  478. {
  479. case S9000_ID_A1439A: /* CRX24 */
  480. if (fb->var.bits_per_pixel == 8) {
  481. lutBltCtl.fields.lutType = NGLE_CMAP_OVERLAY_TYPE;
  482. lutBltCtl.fields.lutOffset = 0;
  483. } else {
  484. lutBltCtl.fields.lutType = NGLE_CMAP_INDEXED0_TYPE;
  485. lutBltCtl.fields.lutOffset = 0 * 256;
  486. }
  487. break;
  488. case S9000_ID_ARTIST:
  489. lutBltCtl.fields.lutType = NGLE_CMAP_INDEXED0_TYPE;
  490. lutBltCtl.fields.lutOffset = 0 * 256;
  491. break;
  492. default:
  493. lutBltCtl.fields.lutType = NGLE_CMAP_INDEXED0_TYPE;
  494. lutBltCtl.fields.lutOffset = 0;
  495. break;
  496. }
  497. /* Offset points to start of LUT. Adjust for within LUT */
  498. lutBltCtl.fields.lutOffset += offsetWithinLut;
  499. return lutBltCtl;
  500. }
  501. #endif
  502. static NgleLutBltCtl
  503. setHyperLutBltCtl(struct stifb_info *fb, int offsetWithinLut, int length)
  504. {
  505. NgleLutBltCtl lutBltCtl;
  506. /* set enable, zero reserved fields */
  507. lutBltCtl.all = 0x80000000;
  508. lutBltCtl.fields.length = length;
  509. lutBltCtl.fields.lutType = HYPER_CMAP_TYPE;
  510. /* Expect lutIndex to be 0 or 1 for image cmaps, 2 or 3 for overlay cmaps */
  511. if (fb->info.var.bits_per_pixel == 8)
  512. lutBltCtl.fields.lutOffset = 2 * 256;
  513. else
  514. lutBltCtl.fields.lutOffset = 0 * 256;
  515. /* Offset points to start of LUT. Adjust for within LUT */
  516. lutBltCtl.fields.lutOffset += offsetWithinLut;
  517. return lutBltCtl;
  518. }
  519. static void hyperUndoITE(struct stifb_info *fb)
  520. {
  521. int nFreeFifoSlots = 0;
  522. u32 fbAddr;
  523. NGLE_LOCK(fb);
  524. GET_FIFO_SLOTS(fb, nFreeFifoSlots, 1);
  525. WRITE_WORD(0xffffffff, fb, REG_32);
  526. /* Write overlay transparency mask so only entry 255 is transparent */
  527. /* Hardware setup for full-depth write to "magic" location */
  528. GET_FIFO_SLOTS(fb, nFreeFifoSlots, 7);
  529. NGLE_QUICK_SET_DST_BM_ACCESS(fb,
  530. BA(IndexedDcd, Otc04, Ots08, AddrLong,
  531. BAJustPoint(0), BINovly, BAIndexBase(0)));
  532. NGLE_QUICK_SET_IMAGE_BITMAP_OP(fb,
  533. IBOvals(RopSrc, MaskAddrOffset(0),
  534. BitmapExtent08, StaticReg(0),
  535. DataDynamic, MaskOtc, BGx(0), FGx(0)));
  536. /* Now prepare to write to the "magic" location */
  537. fbAddr = NGLE_LONG_FB_ADDRESS(0, 1532, 0);
  538. NGLE_BINC_SET_DSTADDR(fb, fbAddr);
  539. NGLE_REALLY_SET_IMAGE_PLANEMASK(fb, 0xffffff);
  540. NGLE_BINC_SET_DSTMASK(fb, 0xffffffff);
  541. /* Finally, write a zero to clear the mask */
  542. NGLE_BINC_WRITE32(fb, 0);
  543. NGLE_UNLOCK(fb);
  544. }
  545. static void
  546. ngleDepth8_ClearImagePlanes(struct stifb_info *fb)
  547. {
  548. /* FIXME! */
  549. }
  550. static void
  551. ngleDepth24_ClearImagePlanes(struct stifb_info *fb)
  552. {
  553. /* FIXME! */
  554. }
  555. static void
  556. ngleResetAttrPlanes(struct stifb_info *fb, unsigned int ctlPlaneReg)
  557. {
  558. int nFreeFifoSlots = 0;
  559. u32 packed_dst;
  560. u32 packed_len;
  561. NGLE_LOCK(fb);
  562. GET_FIFO_SLOTS(fb, nFreeFifoSlots, 4);
  563. NGLE_QUICK_SET_DST_BM_ACCESS(fb,
  564. BA(IndexedDcd, Otc32, OtsIndirect,
  565. AddrLong, BAJustPoint(0),
  566. BINattr, BAIndexBase(0)));
  567. NGLE_QUICK_SET_CTL_PLN_REG(fb, ctlPlaneReg);
  568. NGLE_SET_TRANSFERDATA(fb, 0xffffffff);
  569. NGLE_QUICK_SET_IMAGE_BITMAP_OP(fb,
  570. IBOvals(RopSrc, MaskAddrOffset(0),
  571. BitmapExtent08, StaticReg(1),
  572. DataDynamic, MaskOtc,
  573. BGx(0), FGx(0)));
  574. packed_dst = 0;
  575. packed_len = (fb->info.var.xres << 16) | fb->info.var.yres;
  576. GET_FIFO_SLOTS(fb, nFreeFifoSlots, 2);
  577. NGLE_SET_DSTXY(fb, packed_dst);
  578. SET_LENXY_START_RECFILL(fb, packed_len);
  579. /*
  580. * In order to work around an ELK hardware problem (Buffy doesn't
  581. * always flush it's buffers when writing to the attribute
  582. * planes), at least 4 pixels must be written to the attribute
  583. * planes starting at (X == 1280) and (Y != to the last Y written
  584. * by BIF):
  585. */
  586. if (fb->id == S9000_ID_A1659A) { /* ELK_DEVICE_ID */
  587. /* It's safe to use scanline zero: */
  588. packed_dst = (1280 << 16);
  589. GET_FIFO_SLOTS(fb, nFreeFifoSlots, 2);
  590. NGLE_SET_DSTXY(fb, packed_dst);
  591. packed_len = (4 << 16) | 1;
  592. SET_LENXY_START_RECFILL(fb, packed_len);
  593. } /* ELK Hardware Kludge */
  594. /**** Finally, set the Control Plane Register back to zero: ****/
  595. GET_FIFO_SLOTS(fb, nFreeFifoSlots, 1);
  596. NGLE_QUICK_SET_CTL_PLN_REG(fb, 0);
  597. NGLE_UNLOCK(fb);
  598. }
  599. static void
  600. ngleClearOverlayPlanes(struct stifb_info *fb, int mask, int data)
  601. {
  602. int nFreeFifoSlots = 0;
  603. u32 packed_dst;
  604. u32 packed_len;
  605. NGLE_LOCK(fb);
  606. /* Hardware setup */
  607. GET_FIFO_SLOTS(fb, nFreeFifoSlots, 8);
  608. NGLE_QUICK_SET_DST_BM_ACCESS(fb,
  609. BA(IndexedDcd, Otc04, Ots08, AddrLong,
  610. BAJustPoint(0), BINovly, BAIndexBase(0)));
  611. NGLE_SET_TRANSFERDATA(fb, 0xffffffff); /* Write foreground color */
  612. NGLE_REALLY_SET_IMAGE_FG_COLOR(fb, data);
  613. NGLE_REALLY_SET_IMAGE_PLANEMASK(fb, mask);
  614. packed_dst = 0;
  615. packed_len = (fb->info.var.xres << 16) | fb->info.var.yres;
  616. NGLE_SET_DSTXY(fb, packed_dst);
  617. /* Write zeroes to overlay planes */
  618. NGLE_QUICK_SET_IMAGE_BITMAP_OP(fb,
  619. IBOvals(RopSrc, MaskAddrOffset(0),
  620. BitmapExtent08, StaticReg(0),
  621. DataDynamic, MaskOtc, BGx(0), FGx(0)));
  622. SET_LENXY_START_RECFILL(fb, packed_len);
  623. NGLE_UNLOCK(fb);
  624. }
  625. static void
  626. hyperResetPlanes(struct stifb_info *fb, int enable)
  627. {
  628. unsigned int controlPlaneReg;
  629. NGLE_LOCK(fb);
  630. if (IS_24_DEVICE(fb))
  631. if (fb->info.var.bits_per_pixel == 32)
  632. controlPlaneReg = 0x04000F00;
  633. else
  634. controlPlaneReg = 0x00000F00; /* 0x00000800 should be enough, but lets clear all 4 bits */
  635. else
  636. controlPlaneReg = 0x00000F00; /* 0x00000100 should be enough, but lets clear all 4 bits */
  637. switch (enable) {
  638. case ENABLE:
  639. /* clear screen */
  640. if (IS_24_DEVICE(fb))
  641. ngleDepth24_ClearImagePlanes(fb);
  642. else
  643. ngleDepth8_ClearImagePlanes(fb);
  644. /* Paint attribute planes for default case.
  645. * On Hyperdrive, this means all windows using overlay cmap 0. */
  646. ngleResetAttrPlanes(fb, controlPlaneReg);
  647. /* clear overlay planes */
  648. ngleClearOverlayPlanes(fb, 0xff, 255);
  649. /**************************************************
  650. ** Also need to counteract ITE settings
  651. **************************************************/
  652. hyperUndoITE(fb);
  653. break;
  654. case DISABLE:
  655. /* clear screen */
  656. if (IS_24_DEVICE(fb))
  657. ngleDepth24_ClearImagePlanes(fb);
  658. else
  659. ngleDepth8_ClearImagePlanes(fb);
  660. ngleResetAttrPlanes(fb, controlPlaneReg);
  661. ngleClearOverlayPlanes(fb, 0xff, 0);
  662. break;
  663. case -1: /* RESET */
  664. hyperUndoITE(fb);
  665. ngleResetAttrPlanes(fb, controlPlaneReg);
  666. break;
  667. }
  668. NGLE_UNLOCK(fb);
  669. }
  670. /* Return pointer to in-memory structure holding ELK device-dependent ROM values. */
  671. static void
  672. ngleGetDeviceRomData(struct stifb_info *fb)
  673. {
  674. #if 0
  675. XXX: FIXME: !!!
  676. int *pBytePerLongDevDepData;/* data byte == LSB */
  677. int *pRomTable;
  678. NgleDevRomData *pPackedDevRomData;
  679. int sizePackedDevRomData = sizeof(*pPackedDevRomData);
  680. char *pCard8;
  681. int i;
  682. char *mapOrigin = NULL;
  683. int romTableIdx;
  684. pPackedDevRomData = fb->ngle_rom;
  685. SETUP_HW(fb);
  686. if (fb->id == S9000_ID_ARTIST) {
  687. pPackedDevRomData->cursor_pipeline_delay = 4;
  688. pPackedDevRomData->video_interleaves = 4;
  689. } else {
  690. /* Get pointer to unpacked byte/long data in ROM */
  691. pBytePerLongDevDepData = fb->sti->regions[NGLEDEVDEPROM_CRT_REGION];
  692. /* Tomcat supports several resolutions: 1280x1024, 1024x768, 640x480 */
  693. if (fb->id == S9000_ID_TOMCAT)
  694. {
  695. /* jump to the correct ROM table */
  696. GET_ROMTABLE_INDEX(romTableIdx);
  697. while (romTableIdx > 0)
  698. {
  699. pCard8 = (Card8 *) pPackedDevRomData;
  700. pRomTable = pBytePerLongDevDepData;
  701. /* Pack every fourth byte from ROM into structure */
  702. for (i = 0; i < sizePackedDevRomData; i++)
  703. {
  704. *pCard8++ = (Card8) (*pRomTable++);
  705. }
  706. pBytePerLongDevDepData = (Card32 *)
  707. ((Card8 *) pBytePerLongDevDepData +
  708. pPackedDevRomData->sizeof_ngle_data);
  709. romTableIdx--;
  710. }
  711. }
  712. pCard8 = (Card8 *) pPackedDevRomData;
  713. /* Pack every fourth byte from ROM into structure */
  714. for (i = 0; i < sizePackedDevRomData; i++)
  715. {
  716. *pCard8++ = (Card8) (*pBytePerLongDevDepData++);
  717. }
  718. }
  719. SETUP_FB(fb);
  720. #endif
  721. }
  722. #define HYPERBOWL_MODE_FOR_8_OVER_88_LUT0_NO_TRANSPARENCIES 4
  723. #define HYPERBOWL_MODE01_8_24_LUT0_TRANSPARENT_LUT1_OPAQUE 8
  724. #define HYPERBOWL_MODE01_8_24_LUT0_OPAQUE_LUT1_OPAQUE 10
  725. #define HYPERBOWL_MODE2_8_24 15
  726. /* HCRX specific boot-time initialization */
  727. static void __init
  728. SETUP_HCRX(struct stifb_info *fb)
  729. {
  730. int hyperbowl;
  731. int nFreeFifoSlots = 0;
  732. if (fb->id != S9000_ID_HCRX)
  733. return;
  734. /* Initialize Hyperbowl registers */
  735. GET_FIFO_SLOTS(fb, nFreeFifoSlots, 7);
  736. if (IS_24_DEVICE(fb)) {
  737. hyperbowl = (fb->info.var.bits_per_pixel == 32) ?
  738. HYPERBOWL_MODE01_8_24_LUT0_TRANSPARENT_LUT1_OPAQUE :
  739. HYPERBOWL_MODE01_8_24_LUT0_OPAQUE_LUT1_OPAQUE;
  740. /* First write to Hyperbowl must happen twice (bug) */
  741. WRITE_WORD(hyperbowl, fb, REG_40);
  742. WRITE_WORD(hyperbowl, fb, REG_40);
  743. WRITE_WORD(HYPERBOWL_MODE2_8_24, fb, REG_39);
  744. WRITE_WORD(0x014c0148, fb, REG_42); /* Set lut 0 to be the direct color */
  745. WRITE_WORD(0x404c4048, fb, REG_43);
  746. WRITE_WORD(0x034c0348, fb, REG_44);
  747. WRITE_WORD(0x444c4448, fb, REG_45);
  748. } else {
  749. hyperbowl = HYPERBOWL_MODE_FOR_8_OVER_88_LUT0_NO_TRANSPARENCIES;
  750. /* First write to Hyperbowl must happen twice (bug) */
  751. WRITE_WORD(hyperbowl, fb, REG_40);
  752. WRITE_WORD(hyperbowl, fb, REG_40);
  753. WRITE_WORD(0x00000000, fb, REG_42);
  754. WRITE_WORD(0x00000000, fb, REG_43);
  755. WRITE_WORD(0x00000000, fb, REG_44);
  756. WRITE_WORD(0x444c4048, fb, REG_45);
  757. }
  758. }
  759. /* ------------------- driver specific functions --------------------------- */
  760. static int
  761. stifb_setcolreg(u_int regno, u_int red, u_int green,
  762. u_int blue, u_int transp, struct fb_info *info)
  763. {
  764. struct stifb_info *fb = (struct stifb_info *) info;
  765. u32 color;
  766. if (regno >= NR_PALETTE)
  767. return 1;
  768. red >>= 8;
  769. green >>= 8;
  770. blue >>= 8;
  771. DEBUG_OFF();
  772. START_IMAGE_COLORMAP_ACCESS(fb);
  773. if (unlikely(fb->info.var.grayscale)) {
  774. /* gray = 0.30*R + 0.59*G + 0.11*B */
  775. color = ((red * 77) +
  776. (green * 151) +
  777. (blue * 28)) >> 8;
  778. } else {
  779. color = ((red << 16) |
  780. (green << 8) |
  781. (blue));
  782. }
  783. if (fb->info.fix.visual == FB_VISUAL_DIRECTCOLOR) {
  784. struct fb_var_screeninfo *var = &fb->info.var;
  785. if (regno < 16)
  786. ((u32 *)fb->info.pseudo_palette)[regno] =
  787. regno << var->red.offset |
  788. regno << var->green.offset |
  789. regno << var->blue.offset;
  790. }
  791. WRITE_IMAGE_COLOR(fb, regno, color);
  792. if (fb->id == S9000_ID_HCRX) {
  793. NgleLutBltCtl lutBltCtl;
  794. lutBltCtl = setHyperLutBltCtl(fb,
  795. 0, /* Offset w/i LUT */
  796. 256); /* Load entire LUT */
  797. NGLE_BINC_SET_SRCADDR(fb,
  798. NGLE_LONG_FB_ADDRESS(0, 0x100, 0));
  799. /* 0x100 is same as used in WRITE_IMAGE_COLOR() */
  800. START_COLORMAPLOAD(fb, lutBltCtl.all);
  801. SETUP_FB(fb);
  802. } else {
  803. /* cleanup colormap hardware */
  804. FINISH_IMAGE_COLORMAP_ACCESS(fb);
  805. }
  806. DEBUG_ON();
  807. return 0;
  808. }
  809. static int
  810. stifb_blank(int blank_mode, struct fb_info *info)
  811. {
  812. struct stifb_info *fb = (struct stifb_info *) info;
  813. int enable = (blank_mode == 0) ? ENABLE : DISABLE;
  814. switch (fb->id) {
  815. case S9000_ID_A1439A:
  816. CRX24_ENABLE_DISABLE_DISPLAY(fb, enable);
  817. break;
  818. case CRT_ID_VISUALIZE_EG:
  819. case S9000_ID_ARTIST:
  820. ARTIST_ENABLE_DISABLE_DISPLAY(fb, enable);
  821. break;
  822. case S9000_ID_HCRX:
  823. HYPER_ENABLE_DISABLE_DISPLAY(fb, enable);
  824. break;
  825. case S9000_ID_A1659A: /* fall through */
  826. case S9000_ID_TIMBER:
  827. case CRX24_OVERLAY_PLANES:
  828. default:
  829. ENABLE_DISABLE_DISPLAY(fb, enable);
  830. break;
  831. }
  832. SETUP_FB(fb);
  833. return 0;
  834. }
  835. static void __init
  836. stifb_init_display(struct stifb_info *fb)
  837. {
  838. int id = fb->id;
  839. SETUP_FB(fb);
  840. /* HCRX specific initialization */
  841. SETUP_HCRX(fb);
  842. /*
  843. if (id == S9000_ID_HCRX)
  844. hyperInitSprite(fb);
  845. else
  846. ngleInitSprite(fb);
  847. */
  848. /* Initialize the image planes. */
  849. switch (id) {
  850. case S9000_ID_HCRX:
  851. hyperResetPlanes(fb, ENABLE);
  852. break;
  853. case S9000_ID_A1439A:
  854. rattlerSetupPlanes(fb);
  855. break;
  856. case S9000_ID_A1659A:
  857. case S9000_ID_ARTIST:
  858. case CRT_ID_VISUALIZE_EG:
  859. elkSetupPlanes(fb);
  860. break;
  861. }
  862. /* Clear attribute planes on non HCRX devices. */
  863. switch (id) {
  864. case S9000_ID_A1659A:
  865. case S9000_ID_A1439A:
  866. if (fb->info.var.bits_per_pixel == 32)
  867. ngleSetupAttrPlanes(fb, BUFF1_CMAP3);
  868. else {
  869. ngleSetupAttrPlanes(fb, BUFF1_CMAP0);
  870. }
  871. if (id == S9000_ID_A1439A)
  872. ngleClearOverlayPlanes(fb, 0xff, 0);
  873. break;
  874. case S9000_ID_ARTIST:
  875. case CRT_ID_VISUALIZE_EG:
  876. if (fb->info.var.bits_per_pixel == 32)
  877. ngleSetupAttrPlanes(fb, BUFF1_CMAP3);
  878. else {
  879. ngleSetupAttrPlanes(fb, ARTIST_CMAP0);
  880. }
  881. break;
  882. }
  883. stifb_blank(0, (struct fb_info *)fb); /* 0=enable screen */
  884. SETUP_FB(fb);
  885. }
  886. /* ------------ Interfaces to hardware functions ------------ */
  887. static struct fb_ops stifb_ops = {
  888. .owner = THIS_MODULE,
  889. .fb_setcolreg = stifb_setcolreg,
  890. .fb_blank = stifb_blank,
  891. .fb_fillrect = cfb_fillrect,
  892. .fb_copyarea = cfb_copyarea,
  893. .fb_imageblit = cfb_imageblit,
  894. };
  895. /*
  896. * Initialization
  897. */
  898. static int __init stifb_init_fb(struct sti_struct *sti, int bpp_pref)
  899. {
  900. struct fb_fix_screeninfo *fix;
  901. struct fb_var_screeninfo *var;
  902. struct stifb_info *fb;
  903. struct fb_info *info;
  904. unsigned long sti_rom_address;
  905. char *dev_name;
  906. int bpp, xres, yres;
  907. fb = kzalloc(sizeof(*fb), GFP_ATOMIC);
  908. if (!fb) {
  909. printk(KERN_ERR "stifb: Could not allocate stifb structure\n");
  910. return -ENODEV;
  911. }
  912. info = &fb->info;
  913. /* set struct to a known state */
  914. fix = &info->fix;
  915. var = &info->var;
  916. fb->sti = sti;
  917. /* store upper 32bits of the graphics id */
  918. fb->id = fb->sti->graphics_id[0];
  919. /* only supported cards are allowed */
  920. switch (fb->id) {
  921. case CRT_ID_VISUALIZE_EG:
  922. /* Visualize cards can run either in "double buffer" or
  923. "standard" mode. Depending on the mode, the card reports
  924. a different device name, e.g. "INTERNAL_EG_DX1024" in double
  925. buffer mode and "INTERNAL_EG_X1024" in standard mode.
  926. Since this driver only supports standard mode, we check
  927. if the device name contains the string "DX" and tell the
  928. user how to reconfigure the card. */
  929. if (strstr(sti->outptr.dev_name, "DX")) {
  930. printk(KERN_WARNING
  931. "WARNING: stifb framebuffer driver does not support '%s' in double-buffer mode.\n"
  932. "WARNING: Please disable the double-buffer mode in IPL menu (the PARISC-BIOS).\n",
  933. sti->outptr.dev_name);
  934. goto out_err0;
  935. }
  936. /* fall though */
  937. case S9000_ID_ARTIST:
  938. case S9000_ID_HCRX:
  939. case S9000_ID_TIMBER:
  940. case S9000_ID_A1659A:
  941. case S9000_ID_A1439A:
  942. break;
  943. default:
  944. printk(KERN_WARNING "stifb: '%s' (id: 0x%08x) not supported.\n",
  945. sti->outptr.dev_name, fb->id);
  946. goto out_err0;
  947. }
  948. /* default to 8 bpp on most graphic chips */
  949. bpp = 8;
  950. xres = sti_onscreen_x(fb->sti);
  951. yres = sti_onscreen_y(fb->sti);
  952. ngleGetDeviceRomData(fb);
  953. /* get (virtual) io region base addr */
  954. fix->mmio_start = REGION_BASE(fb,2);
  955. fix->mmio_len = 0x400000;
  956. /* Reject any device not in the NGLE family */
  957. switch (fb->id) {
  958. case S9000_ID_A1659A: /* CRX/A1659A */
  959. break;
  960. case S9000_ID_ELM: /* GRX, grayscale but else same as A1659A */
  961. var->grayscale = 1;
  962. fb->id = S9000_ID_A1659A;
  963. break;
  964. case S9000_ID_TIMBER: /* HP9000/710 Any (may be a grayscale device) */
  965. dev_name = fb->sti->outptr.dev_name;
  966. if (strstr(dev_name, "GRAYSCALE") ||
  967. strstr(dev_name, "Grayscale") ||
  968. strstr(dev_name, "grayscale"))
  969. var->grayscale = 1;
  970. break;
  971. case S9000_ID_TOMCAT: /* Dual CRX, behaves else like a CRX */
  972. /* FIXME: TomCat supports two heads:
  973. * fb.iobase = REGION_BASE(fb_info,3);
  974. * fb.screen_base = ioremap_nocache(REGION_BASE(fb_info,2),xxx);
  975. * for now we only support the left one ! */
  976. xres = fb->ngle_rom.x_size_visible;
  977. yres = fb->ngle_rom.y_size_visible;
  978. fb->id = S9000_ID_A1659A;
  979. break;
  980. case S9000_ID_A1439A: /* CRX24/A1439A */
  981. bpp = 32;
  982. break;
  983. case S9000_ID_HCRX: /* Hyperdrive/HCRX */
  984. memset(&fb->ngle_rom, 0, sizeof(fb->ngle_rom));
  985. if ((fb->sti->regions_phys[0] & 0xfc000000) ==
  986. (fb->sti->regions_phys[2] & 0xfc000000))
  987. sti_rom_address = F_EXTEND(fb->sti->regions_phys[0]);
  988. else
  989. sti_rom_address = F_EXTEND(fb->sti->regions_phys[1]);
  990. fb->deviceSpecificConfig = gsc_readl(sti_rom_address);
  991. if (IS_24_DEVICE(fb)) {
  992. if (bpp_pref == 8 || bpp_pref == 32)
  993. bpp = bpp_pref;
  994. else
  995. bpp = 32;
  996. } else
  997. bpp = 8;
  998. READ_WORD(fb, REG_15);
  999. SETUP_HW(fb);
  1000. break;
  1001. case CRT_ID_VISUALIZE_EG:
  1002. case S9000_ID_ARTIST: /* Artist */
  1003. break;
  1004. default:
  1005. #ifdef FALLBACK_TO_1BPP
  1006. printk(KERN_WARNING
  1007. "stifb: Unsupported graphics card (id=0x%08x) "
  1008. "- now trying 1bpp mode instead\n",
  1009. fb->id);
  1010. bpp = 1; /* default to 1 bpp */
  1011. break;
  1012. #else
  1013. printk(KERN_WARNING
  1014. "stifb: Unsupported graphics card (id=0x%08x) "
  1015. "- skipping.\n",
  1016. fb->id);
  1017. goto out_err0;
  1018. #endif
  1019. }
  1020. /* get framebuffer physical and virtual base addr & len (64bit ready) */
  1021. fix->smem_start = F_EXTEND(fb->sti->regions_phys[1]);
  1022. fix->smem_len = fb->sti->regions[1].region_desc.length * 4096;
  1023. fix->line_length = (fb->sti->glob_cfg->total_x * bpp) / 8;
  1024. if (!fix->line_length)
  1025. fix->line_length = 2048; /* default */
  1026. /* limit fbsize to max visible screen size */
  1027. if (fix->smem_len > yres*fix->line_length)
  1028. fix->smem_len = yres*fix->line_length;
  1029. fix->accel = FB_ACCEL_NONE;
  1030. switch (bpp) {
  1031. case 1:
  1032. fix->type = FB_TYPE_PLANES; /* well, sort of */
  1033. fix->visual = FB_VISUAL_MONO10;
  1034. var->red.length = var->green.length = var->blue.length = 1;
  1035. break;
  1036. case 8:
  1037. fix->type = FB_TYPE_PACKED_PIXELS;
  1038. fix->visual = FB_VISUAL_PSEUDOCOLOR;
  1039. var->red.length = var->green.length = var->blue.length = 8;
  1040. break;
  1041. case 32:
  1042. fix->type = FB_TYPE_PACKED_PIXELS;
  1043. fix->visual = FB_VISUAL_DIRECTCOLOR;
  1044. var->red.length = var->green.length = var->blue.length = var->transp.length = 8;
  1045. var->blue.offset = 0;
  1046. var->green.offset = 8;
  1047. var->red.offset = 16;
  1048. var->transp.offset = 24;
  1049. break;
  1050. default:
  1051. break;
  1052. }
  1053. var->xres = var->xres_virtual = xres;
  1054. var->yres = var->yres_virtual = yres;
  1055. var->bits_per_pixel = bpp;
  1056. strcpy(fix->id, "stifb");
  1057. info->fbops = &stifb_ops;
  1058. info->screen_base = ioremap_nocache(REGION_BASE(fb,1), fix->smem_len);
  1059. info->screen_size = fix->smem_len;
  1060. info->flags = FBINFO_DEFAULT;
  1061. info->pseudo_palette = &fb->pseudo_palette;
  1062. /* This has to be done !!! */
  1063. if (fb_alloc_cmap(&info->cmap, NR_PALETTE, 0))
  1064. goto out_err1;
  1065. stifb_init_display(fb);
  1066. if (!request_mem_region(fix->smem_start, fix->smem_len, "stifb fb")) {
  1067. printk(KERN_ERR "stifb: cannot reserve fb region 0x%04lx-0x%04lx\n",
  1068. fix->smem_start, fix->smem_start+fix->smem_len);
  1069. goto out_err2;
  1070. }
  1071. if (!request_mem_region(fix->mmio_start, fix->mmio_len, "stifb mmio")) {
  1072. printk(KERN_ERR "stifb: cannot reserve sti mmio region 0x%04lx-0x%04lx\n",
  1073. fix->mmio_start, fix->mmio_start+fix->mmio_len);
  1074. goto out_err3;
  1075. }
  1076. if (register_framebuffer(&fb->info) < 0)
  1077. goto out_err4;
  1078. sti->info = info; /* save for unregister_framebuffer() */
  1079. printk(KERN_INFO
  1080. "fb%d: %s %dx%d-%d frame buffer device, %s, id: %04x, mmio: 0x%04lx\n",
  1081. fb->info.node,
  1082. fix->id,
  1083. var->xres,
  1084. var->yres,
  1085. var->bits_per_pixel,
  1086. sti->outptr.dev_name,
  1087. fb->id,
  1088. fix->mmio_start);
  1089. return 0;
  1090. out_err4:
  1091. release_mem_region(fix->mmio_start, fix->mmio_len);
  1092. out_err3:
  1093. release_mem_region(fix->smem_start, fix->smem_len);
  1094. out_err2:
  1095. fb_dealloc_cmap(&info->cmap);
  1096. out_err1:
  1097. iounmap(info->screen_base);
  1098. out_err0:
  1099. kfree(fb);
  1100. return -ENXIO;
  1101. }
  1102. static int stifb_disabled __initdata;
  1103. int __init
  1104. stifb_setup(char *options);
  1105. static int __init stifb_init(void)
  1106. {
  1107. struct sti_struct *sti;
  1108. struct sti_struct *def_sti;
  1109. int i;
  1110. #ifndef MODULE
  1111. char *option = NULL;
  1112. if (fb_get_options("stifb", &option))
  1113. return -ENODEV;
  1114. stifb_setup(option);
  1115. #endif
  1116. if (stifb_disabled) {
  1117. printk(KERN_INFO "stifb: disabled by \"stifb=off\" kernel parameter\n");
  1118. return -ENXIO;
  1119. }
  1120. def_sti = sti_get_rom(0);
  1121. if (def_sti) {
  1122. for (i = 1; i <= MAX_STI_ROMS; i++) {
  1123. sti = sti_get_rom(i);
  1124. if (!sti)
  1125. break;
  1126. if (sti == def_sti) {
  1127. stifb_init_fb(sti, stifb_bpp_pref[i - 1]);
  1128. break;
  1129. }
  1130. }
  1131. }
  1132. for (i = 1; i <= MAX_STI_ROMS; i++) {
  1133. sti = sti_get_rom(i);
  1134. if (!sti)
  1135. break;
  1136. if (sti == def_sti)
  1137. continue;
  1138. stifb_init_fb(sti, stifb_bpp_pref[i - 1]);
  1139. }
  1140. return 0;
  1141. }
  1142. /*
  1143. * Cleanup
  1144. */
  1145. static void __exit
  1146. stifb_cleanup(void)
  1147. {
  1148. struct sti_struct *sti;
  1149. int i;
  1150. for (i = 1; i <= MAX_STI_ROMS; i++) {
  1151. sti = sti_get_rom(i);
  1152. if (!sti)
  1153. break;
  1154. if (sti->info) {
  1155. struct fb_info *info = sti->info;
  1156. unregister_framebuffer(sti->info);
  1157. release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
  1158. release_mem_region(info->fix.smem_start, info->fix.smem_len);
  1159. if (info->screen_base)
  1160. iounmap(info->screen_base);
  1161. fb_dealloc_cmap(&info->cmap);
  1162. framebuffer_release(info);
  1163. }
  1164. sti->info = NULL;
  1165. }
  1166. }
  1167. int __init
  1168. stifb_setup(char *options)
  1169. {
  1170. int i;
  1171. if (!options || !*options)
  1172. return 1;
  1173. if (strncmp(options, "off", 3) == 0) {
  1174. stifb_disabled = 1;
  1175. options += 3;
  1176. }
  1177. if (strncmp(options, "bpp", 3) == 0) {
  1178. options += 3;
  1179. for (i = 0; i < MAX_STI_ROMS; i++) {
  1180. if (*options++ != ':')
  1181. break;
  1182. stifb_bpp_pref[i] = simple_strtoul(options, &options, 10);
  1183. }
  1184. }
  1185. return 1;
  1186. }
  1187. __setup("stifb=", stifb_setup);
  1188. module_init(stifb_init);
  1189. module_exit(stifb_cleanup);
  1190. MODULE_AUTHOR("Helge Deller <deller@gmx.de>, Thomas Bogendoerfer <tsbogend@alpha.franken.de>");
  1191. MODULE_DESCRIPTION("Framebuffer driver for HP's NGLE series graphics cards in HP PARISC machines");
  1192. MODULE_LICENSE("GPL v2");