stifb.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  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 = container_of(info, 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 = container_of(info, 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. dev_name = sti->sti_data->inq_outptr.dev_name;
  918. /* store upper 32bits of the graphics id */
  919. fb->id = fb->sti->graphics_id[0];
  920. /* only supported cards are allowed */
  921. switch (fb->id) {
  922. case CRT_ID_VISUALIZE_EG:
  923. /* Visualize cards can run either in "double buffer" or
  924. "standard" mode. Depending on the mode, the card reports
  925. a different device name, e.g. "INTERNAL_EG_DX1024" in double
  926. buffer mode and "INTERNAL_EG_X1024" in standard mode.
  927. Since this driver only supports standard mode, we check
  928. if the device name contains the string "DX" and tell the
  929. user how to reconfigure the card. */
  930. if (strstr(dev_name, "DX")) {
  931. printk(KERN_WARNING
  932. "WARNING: stifb framebuffer driver does not support '%s' in double-buffer mode.\n"
  933. "WARNING: Please disable the double-buffer mode in IPL menu (the PARISC-BIOS).\n",
  934. dev_name);
  935. goto out_err0;
  936. }
  937. /* fall though */
  938. case S9000_ID_ARTIST:
  939. case S9000_ID_HCRX:
  940. case S9000_ID_TIMBER:
  941. case S9000_ID_A1659A:
  942. case S9000_ID_A1439A:
  943. break;
  944. default:
  945. printk(KERN_WARNING "stifb: '%s' (id: 0x%08x) not supported.\n",
  946. dev_name, fb->id);
  947. goto out_err0;
  948. }
  949. /* default to 8 bpp on most graphic chips */
  950. bpp = 8;
  951. xres = sti_onscreen_x(fb->sti);
  952. yres = sti_onscreen_y(fb->sti);
  953. ngleGetDeviceRomData(fb);
  954. /* get (virtual) io region base addr */
  955. fix->mmio_start = REGION_BASE(fb,2);
  956. fix->mmio_len = 0x400000;
  957. /* Reject any device not in the NGLE family */
  958. switch (fb->id) {
  959. case S9000_ID_A1659A: /* CRX/A1659A */
  960. break;
  961. case S9000_ID_ELM: /* GRX, grayscale but else same as A1659A */
  962. var->grayscale = 1;
  963. fb->id = S9000_ID_A1659A;
  964. break;
  965. case S9000_ID_TIMBER: /* HP9000/710 Any (may be a grayscale device) */
  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. fb_info(&fb->info, "%s %dx%d-%d frame buffer device, %s, id: %04x, mmio: 0x%04lx\n",
  1080. fix->id,
  1081. var->xres,
  1082. var->yres,
  1083. var->bits_per_pixel,
  1084. dev_name,
  1085. fb->id,
  1086. fix->mmio_start);
  1087. return 0;
  1088. out_err4:
  1089. release_mem_region(fix->mmio_start, fix->mmio_len);
  1090. out_err3:
  1091. release_mem_region(fix->smem_start, fix->smem_len);
  1092. out_err2:
  1093. fb_dealloc_cmap(&info->cmap);
  1094. out_err1:
  1095. iounmap(info->screen_base);
  1096. out_err0:
  1097. kfree(fb);
  1098. return -ENXIO;
  1099. }
  1100. static int stifb_disabled __initdata;
  1101. int __init
  1102. stifb_setup(char *options);
  1103. static int __init stifb_init(void)
  1104. {
  1105. struct sti_struct *sti;
  1106. struct sti_struct *def_sti;
  1107. int i;
  1108. #ifndef MODULE
  1109. char *option = NULL;
  1110. if (fb_get_options("stifb", &option))
  1111. return -ENODEV;
  1112. stifb_setup(option);
  1113. #endif
  1114. if (stifb_disabled) {
  1115. printk(KERN_INFO "stifb: disabled by \"stifb=off\" kernel parameter\n");
  1116. return -ENXIO;
  1117. }
  1118. def_sti = sti_get_rom(0);
  1119. if (def_sti) {
  1120. for (i = 1; i <= MAX_STI_ROMS; i++) {
  1121. sti = sti_get_rom(i);
  1122. if (!sti)
  1123. break;
  1124. if (sti == def_sti) {
  1125. stifb_init_fb(sti, stifb_bpp_pref[i - 1]);
  1126. break;
  1127. }
  1128. }
  1129. }
  1130. for (i = 1; i <= MAX_STI_ROMS; i++) {
  1131. sti = sti_get_rom(i);
  1132. if (!sti)
  1133. break;
  1134. if (sti == def_sti)
  1135. continue;
  1136. stifb_init_fb(sti, stifb_bpp_pref[i - 1]);
  1137. }
  1138. return 0;
  1139. }
  1140. /*
  1141. * Cleanup
  1142. */
  1143. static void __exit
  1144. stifb_cleanup(void)
  1145. {
  1146. struct sti_struct *sti;
  1147. int i;
  1148. for (i = 1; i <= MAX_STI_ROMS; i++) {
  1149. sti = sti_get_rom(i);
  1150. if (!sti)
  1151. break;
  1152. if (sti->info) {
  1153. struct fb_info *info = sti->info;
  1154. unregister_framebuffer(sti->info);
  1155. release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
  1156. release_mem_region(info->fix.smem_start, info->fix.smem_len);
  1157. if (info->screen_base)
  1158. iounmap(info->screen_base);
  1159. fb_dealloc_cmap(&info->cmap);
  1160. framebuffer_release(info);
  1161. }
  1162. sti->info = NULL;
  1163. }
  1164. }
  1165. int __init
  1166. stifb_setup(char *options)
  1167. {
  1168. int i;
  1169. if (!options || !*options)
  1170. return 1;
  1171. if (strncmp(options, "off", 3) == 0) {
  1172. stifb_disabled = 1;
  1173. options += 3;
  1174. }
  1175. if (strncmp(options, "bpp", 3) == 0) {
  1176. options += 3;
  1177. for (i = 0; i < MAX_STI_ROMS; i++) {
  1178. if (*options++ != ':')
  1179. break;
  1180. stifb_bpp_pref[i] = simple_strtoul(options, &options, 10);
  1181. }
  1182. }
  1183. return 1;
  1184. }
  1185. __setup("stifb=", stifb_setup);
  1186. module_init(stifb_init);
  1187. module_exit(stifb_cleanup);
  1188. MODULE_AUTHOR("Helge Deller <deller@gmx.de>, Thomas Bogendoerfer <tsbogend@alpha.franken.de>");
  1189. MODULE_DESCRIPTION("Framebuffer driver for HP's NGLE series graphics cards in HP PARISC machines");
  1190. MODULE_LICENSE("GPL v2");