tgafb.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778
  1. /*
  2. * linux/drivers/video/tgafb.c -- DEC 21030 TGA frame buffer device
  3. *
  4. * Copyright (C) 1995 Jay Estabrook
  5. * Copyright (C) 1997 Geert Uytterhoeven
  6. * Copyright (C) 1999,2000 Martin Lucina, Tom Zerucha
  7. * Copyright (C) 2002 Richard Henderson
  8. * Copyright (C) 2006, 2007 Maciej W. Rozycki
  9. *
  10. * This file is subject to the terms and conditions of the GNU General Public
  11. * License. See the file COPYING in the main directory of this archive for
  12. * more details.
  13. */
  14. #include <linux/bitrev.h>
  15. #include <linux/compiler.h>
  16. #include <linux/delay.h>
  17. #include <linux/device.h>
  18. #include <linux/errno.h>
  19. #include <linux/fb.h>
  20. #include <linux/init.h>
  21. #include <linux/ioport.h>
  22. #include <linux/kernel.h>
  23. #include <linux/mm.h>
  24. #include <linux/module.h>
  25. #include <linux/pci.h>
  26. #include <linux/selection.h>
  27. #include <linux/slab.h>
  28. #include <linux/string.h>
  29. #include <linux/tc.h>
  30. #include <asm/io.h>
  31. #include <video/tgafb.h>
  32. #ifdef CONFIG_PCI
  33. #define TGA_BUS_PCI(dev) (dev->bus == &pci_bus_type)
  34. #else
  35. #define TGA_BUS_PCI(dev) 0
  36. #endif
  37. #ifdef CONFIG_TC
  38. #define TGA_BUS_TC(dev) (dev->bus == &tc_bus_type)
  39. #else
  40. #define TGA_BUS_TC(dev) 0
  41. #endif
  42. /*
  43. * Local functions.
  44. */
  45. static int tgafb_check_var(struct fb_var_screeninfo *, struct fb_info *);
  46. static int tgafb_set_par(struct fb_info *);
  47. static void tgafb_set_pll(struct tga_par *, int);
  48. static int tgafb_setcolreg(unsigned, unsigned, unsigned, unsigned,
  49. unsigned, struct fb_info *);
  50. static int tgafb_blank(int, struct fb_info *);
  51. static void tgafb_init_fix(struct fb_info *);
  52. static void tgafb_imageblit(struct fb_info *, const struct fb_image *);
  53. static void tgafb_fillrect(struct fb_info *, const struct fb_fillrect *);
  54. static void tgafb_copyarea(struct fb_info *, const struct fb_copyarea *);
  55. static int tgafb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info);
  56. static int __devinit tgafb_register(struct device *dev);
  57. static void __devexit tgafb_unregister(struct device *dev);
  58. static const char *mode_option;
  59. static const char *mode_option_pci = "640x480@60";
  60. static const char *mode_option_tc = "1280x1024@72";
  61. static struct pci_driver tgafb_pci_driver;
  62. static struct tc_driver tgafb_tc_driver;
  63. /*
  64. * Frame buffer operations
  65. */
  66. static struct fb_ops tgafb_ops = {
  67. .owner = THIS_MODULE,
  68. .fb_check_var = tgafb_check_var,
  69. .fb_set_par = tgafb_set_par,
  70. .fb_setcolreg = tgafb_setcolreg,
  71. .fb_blank = tgafb_blank,
  72. .fb_pan_display = tgafb_pan_display,
  73. .fb_fillrect = tgafb_fillrect,
  74. .fb_copyarea = tgafb_copyarea,
  75. .fb_imageblit = tgafb_imageblit,
  76. };
  77. #ifdef CONFIG_PCI
  78. /*
  79. * PCI registration operations
  80. */
  81. static int __devinit tgafb_pci_register(struct pci_dev *,
  82. const struct pci_device_id *);
  83. static void __devexit tgafb_pci_unregister(struct pci_dev *);
  84. static struct pci_device_id const tgafb_pci_table[] = {
  85. { PCI_DEVICE(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TGA) },
  86. { }
  87. };
  88. MODULE_DEVICE_TABLE(pci, tgafb_pci_table);
  89. static struct pci_driver tgafb_pci_driver = {
  90. .name = "tgafb",
  91. .id_table = tgafb_pci_table,
  92. .probe = tgafb_pci_register,
  93. .remove = __devexit_p(tgafb_pci_unregister),
  94. };
  95. static int __devinit
  96. tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
  97. {
  98. return tgafb_register(&pdev->dev);
  99. }
  100. static void __devexit
  101. tgafb_pci_unregister(struct pci_dev *pdev)
  102. {
  103. tgafb_unregister(&pdev->dev);
  104. }
  105. #endif /* CONFIG_PCI */
  106. #ifdef CONFIG_TC
  107. /*
  108. * TC registration operations
  109. */
  110. static int __devinit tgafb_tc_register(struct device *);
  111. static int __devexit tgafb_tc_unregister(struct device *);
  112. static struct tc_device_id const tgafb_tc_table[] = {
  113. { "DEC ", "PMAGD-AA" },
  114. { "DEC ", "PMAGD " },
  115. { }
  116. };
  117. MODULE_DEVICE_TABLE(tc, tgafb_tc_table);
  118. static struct tc_driver tgafb_tc_driver = {
  119. .id_table = tgafb_tc_table,
  120. .driver = {
  121. .name = "tgafb",
  122. .bus = &tc_bus_type,
  123. .probe = tgafb_tc_register,
  124. .remove = __devexit_p(tgafb_tc_unregister),
  125. },
  126. };
  127. static int __devinit
  128. tgafb_tc_register(struct device *dev)
  129. {
  130. int status = tgafb_register(dev);
  131. if (!status)
  132. get_device(dev);
  133. return status;
  134. }
  135. static int __devexit
  136. tgafb_tc_unregister(struct device *dev)
  137. {
  138. put_device(dev);
  139. tgafb_unregister(dev);
  140. return 0;
  141. }
  142. #endif /* CONFIG_TC */
  143. /**
  144. * tgafb_check_var - Optional function. Validates a var passed in.
  145. * @var: frame buffer variable screen structure
  146. * @info: frame buffer structure that represents a single frame buffer
  147. */
  148. static int
  149. tgafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  150. {
  151. struct tga_par *par = (struct tga_par *)info->par;
  152. if (par->tga_type == TGA_TYPE_8PLANE) {
  153. if (var->bits_per_pixel != 8)
  154. return -EINVAL;
  155. } else {
  156. if (var->bits_per_pixel != 32)
  157. return -EINVAL;
  158. }
  159. var->red.length = var->green.length = var->blue.length = 8;
  160. if (var->bits_per_pixel == 32) {
  161. var->red.offset = 16;
  162. var->green.offset = 8;
  163. var->blue.offset = 0;
  164. }
  165. if (var->xres_virtual != var->xres || var->yres_virtual != var->yres)
  166. return -EINVAL;
  167. if (var->nonstd)
  168. return -EINVAL;
  169. if (1000000000 / var->pixclock > TGA_PLL_MAX_FREQ)
  170. return -EINVAL;
  171. if ((var->vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED)
  172. return -EINVAL;
  173. /* Some of the acceleration routines assume the line width is
  174. a multiple of 64 bytes. */
  175. if (var->xres * (par->tga_type == TGA_TYPE_8PLANE ? 1 : 4) % 64)
  176. return -EINVAL;
  177. return 0;
  178. }
  179. /**
  180. * tgafb_set_par - Optional function. Alters the hardware state.
  181. * @info: frame buffer structure that represents a single frame buffer
  182. */
  183. static int
  184. tgafb_set_par(struct fb_info *info)
  185. {
  186. static unsigned int const deep_presets[4] = {
  187. 0x00004000,
  188. 0x0000440d,
  189. 0xffffffff,
  190. 0x0000441d
  191. };
  192. static unsigned int const rasterop_presets[4] = {
  193. 0x00000003,
  194. 0x00000303,
  195. 0xffffffff,
  196. 0x00000303
  197. };
  198. static unsigned int const mode_presets[4] = {
  199. 0x00000000,
  200. 0x00000300,
  201. 0xffffffff,
  202. 0x00000300
  203. };
  204. static unsigned int const base_addr_presets[4] = {
  205. 0x00000000,
  206. 0x00000001,
  207. 0xffffffff,
  208. 0x00000001
  209. };
  210. struct tga_par *par = (struct tga_par *) info->par;
  211. int tga_bus_pci = TGA_BUS_PCI(par->dev);
  212. int tga_bus_tc = TGA_BUS_TC(par->dev);
  213. u32 htimings, vtimings, pll_freq;
  214. u8 tga_type;
  215. int i;
  216. /* Encode video timings. */
  217. htimings = (((info->var.xres/4) & TGA_HORIZ_ACT_LSB)
  218. | (((info->var.xres/4) & 0x600 << 19) & TGA_HORIZ_ACT_MSB));
  219. vtimings = (info->var.yres & TGA_VERT_ACTIVE);
  220. htimings |= ((info->var.right_margin/4) << 9) & TGA_HORIZ_FP;
  221. vtimings |= (info->var.lower_margin << 11) & TGA_VERT_FP;
  222. htimings |= ((info->var.hsync_len/4) << 14) & TGA_HORIZ_SYNC;
  223. vtimings |= (info->var.vsync_len << 16) & TGA_VERT_SYNC;
  224. htimings |= ((info->var.left_margin/4) << 21) & TGA_HORIZ_BP;
  225. vtimings |= (info->var.upper_margin << 22) & TGA_VERT_BP;
  226. if (info->var.sync & FB_SYNC_HOR_HIGH_ACT)
  227. htimings |= TGA_HORIZ_POLARITY;
  228. if (info->var.sync & FB_SYNC_VERT_HIGH_ACT)
  229. vtimings |= TGA_VERT_POLARITY;
  230. par->htimings = htimings;
  231. par->vtimings = vtimings;
  232. par->sync_on_green = !!(info->var.sync & FB_SYNC_ON_GREEN);
  233. /* Store other useful values in par. */
  234. par->xres = info->var.xres;
  235. par->yres = info->var.yres;
  236. par->pll_freq = pll_freq = 1000000000 / info->var.pixclock;
  237. par->bits_per_pixel = info->var.bits_per_pixel;
  238. tga_type = par->tga_type;
  239. /* First, disable video. */
  240. TGA_WRITE_REG(par, TGA_VALID_VIDEO | TGA_VALID_BLANK, TGA_VALID_REG);
  241. /* Write the DEEP register. */
  242. while (TGA_READ_REG(par, TGA_CMD_STAT_REG) & 1) /* wait for not busy */
  243. continue;
  244. mb();
  245. TGA_WRITE_REG(par, deep_presets[tga_type] |
  246. (par->sync_on_green ? 0x0 : 0x00010000),
  247. TGA_DEEP_REG);
  248. while (TGA_READ_REG(par, TGA_CMD_STAT_REG) & 1) /* wait for not busy */
  249. continue;
  250. mb();
  251. /* Write some more registers. */
  252. TGA_WRITE_REG(par, rasterop_presets[tga_type], TGA_RASTEROP_REG);
  253. TGA_WRITE_REG(par, mode_presets[tga_type], TGA_MODE_REG);
  254. TGA_WRITE_REG(par, base_addr_presets[tga_type], TGA_BASE_ADDR_REG);
  255. /* Calculate & write the PLL. */
  256. tgafb_set_pll(par, pll_freq);
  257. /* Write some more registers. */
  258. TGA_WRITE_REG(par, 0xffffffff, TGA_PLANEMASK_REG);
  259. TGA_WRITE_REG(par, 0xffffffff, TGA_PIXELMASK_REG);
  260. /* Init video timing regs. */
  261. TGA_WRITE_REG(par, htimings, TGA_HORIZ_REG);
  262. TGA_WRITE_REG(par, vtimings, TGA_VERT_REG);
  263. /* Initalise RAMDAC. */
  264. if (tga_type == TGA_TYPE_8PLANE && tga_bus_pci) {
  265. /* Init BT485 RAMDAC registers. */
  266. BT485_WRITE(par, 0xa2 | (par->sync_on_green ? 0x8 : 0x0),
  267. BT485_CMD_0);
  268. BT485_WRITE(par, 0x01, BT485_ADDR_PAL_WRITE);
  269. BT485_WRITE(par, 0x14, BT485_CMD_3); /* cursor 64x64 */
  270. BT485_WRITE(par, 0x40, BT485_CMD_1);
  271. BT485_WRITE(par, 0x20, BT485_CMD_2); /* cursor off, for now */
  272. BT485_WRITE(par, 0xff, BT485_PIXEL_MASK);
  273. /* Fill palette registers. */
  274. BT485_WRITE(par, 0x00, BT485_ADDR_PAL_WRITE);
  275. TGA_WRITE_REG(par, BT485_DATA_PAL, TGA_RAMDAC_SETUP_REG);
  276. for (i = 0; i < 256 * 3; i += 4) {
  277. TGA_WRITE_REG(par, 0x55 | (BT485_DATA_PAL << 8),
  278. TGA_RAMDAC_REG);
  279. TGA_WRITE_REG(par, 0x00 | (BT485_DATA_PAL << 8),
  280. TGA_RAMDAC_REG);
  281. TGA_WRITE_REG(par, 0x00 | (BT485_DATA_PAL << 8),
  282. TGA_RAMDAC_REG);
  283. TGA_WRITE_REG(par, 0x00 | (BT485_DATA_PAL << 8),
  284. TGA_RAMDAC_REG);
  285. }
  286. } else if (tga_type == TGA_TYPE_8PLANE && tga_bus_tc) {
  287. /* Init BT459 RAMDAC registers. */
  288. BT459_WRITE(par, BT459_REG_ACC, BT459_CMD_REG_0, 0x40);
  289. BT459_WRITE(par, BT459_REG_ACC, BT459_CMD_REG_1, 0x00);
  290. BT459_WRITE(par, BT459_REG_ACC, BT459_CMD_REG_2,
  291. (par->sync_on_green ? 0xc0 : 0x40));
  292. BT459_WRITE(par, BT459_REG_ACC, BT459_CUR_CMD_REG, 0x00);
  293. /* Fill the palette. */
  294. BT459_LOAD_ADDR(par, 0x0000);
  295. TGA_WRITE_REG(par, BT459_PALETTE << 2, TGA_RAMDAC_SETUP_REG);
  296. for (i = 0; i < 256 * 3; i += 4) {
  297. TGA_WRITE_REG(par, 0x55, TGA_RAMDAC_REG);
  298. TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
  299. TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
  300. TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
  301. }
  302. } else { /* 24-plane or 24plusZ */
  303. /* Init BT463 RAMDAC registers. */
  304. BT463_WRITE(par, BT463_REG_ACC, BT463_CMD_REG_0, 0x40);
  305. BT463_WRITE(par, BT463_REG_ACC, BT463_CMD_REG_1, 0x08);
  306. BT463_WRITE(par, BT463_REG_ACC, BT463_CMD_REG_2,
  307. (par->sync_on_green ? 0xc0 : 0x40));
  308. BT463_WRITE(par, BT463_REG_ACC, BT463_READ_MASK_0, 0xff);
  309. BT463_WRITE(par, BT463_REG_ACC, BT463_READ_MASK_1, 0xff);
  310. BT463_WRITE(par, BT463_REG_ACC, BT463_READ_MASK_2, 0xff);
  311. BT463_WRITE(par, BT463_REG_ACC, BT463_READ_MASK_3, 0x0f);
  312. BT463_WRITE(par, BT463_REG_ACC, BT463_BLINK_MASK_0, 0x00);
  313. BT463_WRITE(par, BT463_REG_ACC, BT463_BLINK_MASK_1, 0x00);
  314. BT463_WRITE(par, BT463_REG_ACC, BT463_BLINK_MASK_2, 0x00);
  315. BT463_WRITE(par, BT463_REG_ACC, BT463_BLINK_MASK_3, 0x00);
  316. /* Fill the palette. */
  317. BT463_LOAD_ADDR(par, 0x0000);
  318. TGA_WRITE_REG(par, BT463_PALETTE << 2, TGA_RAMDAC_SETUP_REG);
  319. #ifdef CONFIG_HW_CONSOLE
  320. for (i = 0; i < 16; i++) {
  321. int j = color_table[i];
  322. TGA_WRITE_REG(par, default_red[j], TGA_RAMDAC_REG);
  323. TGA_WRITE_REG(par, default_grn[j], TGA_RAMDAC_REG);
  324. TGA_WRITE_REG(par, default_blu[j], TGA_RAMDAC_REG);
  325. }
  326. for (i = 0; i < 512 * 3; i += 4) {
  327. #else
  328. for (i = 0; i < 528 * 3; i += 4) {
  329. #endif
  330. TGA_WRITE_REG(par, 0x55, TGA_RAMDAC_REG);
  331. TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
  332. TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
  333. TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
  334. }
  335. /* Fill window type table after start of vertical retrace. */
  336. while (!(TGA_READ_REG(par, TGA_INTR_STAT_REG) & 0x01))
  337. continue;
  338. TGA_WRITE_REG(par, 0x01, TGA_INTR_STAT_REG);
  339. mb();
  340. while (!(TGA_READ_REG(par, TGA_INTR_STAT_REG) & 0x01))
  341. continue;
  342. TGA_WRITE_REG(par, 0x01, TGA_INTR_STAT_REG);
  343. BT463_LOAD_ADDR(par, BT463_WINDOW_TYPE_BASE);
  344. TGA_WRITE_REG(par, BT463_REG_ACC << 2, TGA_RAMDAC_SETUP_REG);
  345. for (i = 0; i < 16; i++) {
  346. TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
  347. TGA_WRITE_REG(par, 0x01, TGA_RAMDAC_REG);
  348. TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
  349. }
  350. }
  351. /* Finally, enable video scan (and pray for the monitor... :-) */
  352. TGA_WRITE_REG(par, TGA_VALID_VIDEO, TGA_VALID_REG);
  353. return 0;
  354. }
  355. #define DIFFCHECK(X) \
  356. do { \
  357. if (m <= 0x3f) { \
  358. int delta = f - (TGA_PLL_BASE_FREQ * (X)) / (r << shift); \
  359. if (delta < 0) \
  360. delta = -delta; \
  361. if (delta < min_diff) \
  362. min_diff = delta, vm = m, va = a, vr = r; \
  363. } \
  364. } while (0)
  365. static void
  366. tgafb_set_pll(struct tga_par *par, int f)
  367. {
  368. int n, shift, base, min_diff, target;
  369. int r,a,m,vm = 34, va = 1, vr = 30;
  370. for (r = 0 ; r < 12 ; r++)
  371. TGA_WRITE_REG(par, !r, TGA_CLOCK_REG);
  372. if (f > TGA_PLL_MAX_FREQ)
  373. f = TGA_PLL_MAX_FREQ;
  374. if (f >= TGA_PLL_MAX_FREQ / 2)
  375. shift = 0;
  376. else if (f >= TGA_PLL_MAX_FREQ / 4)
  377. shift = 1;
  378. else
  379. shift = 2;
  380. TGA_WRITE_REG(par, shift & 1, TGA_CLOCK_REG);
  381. TGA_WRITE_REG(par, shift >> 1, TGA_CLOCK_REG);
  382. for (r = 0 ; r < 10 ; r++)
  383. TGA_WRITE_REG(par, 0, TGA_CLOCK_REG);
  384. if (f <= 120000) {
  385. TGA_WRITE_REG(par, 0, TGA_CLOCK_REG);
  386. TGA_WRITE_REG(par, 0, TGA_CLOCK_REG);
  387. }
  388. else if (f <= 200000) {
  389. TGA_WRITE_REG(par, 1, TGA_CLOCK_REG);
  390. TGA_WRITE_REG(par, 0, TGA_CLOCK_REG);
  391. }
  392. else {
  393. TGA_WRITE_REG(par, 0, TGA_CLOCK_REG);
  394. TGA_WRITE_REG(par, 1, TGA_CLOCK_REG);
  395. }
  396. TGA_WRITE_REG(par, 1, TGA_CLOCK_REG);
  397. TGA_WRITE_REG(par, 0, TGA_CLOCK_REG);
  398. TGA_WRITE_REG(par, 0, TGA_CLOCK_REG);
  399. TGA_WRITE_REG(par, 1, TGA_CLOCK_REG);
  400. TGA_WRITE_REG(par, 0, TGA_CLOCK_REG);
  401. TGA_WRITE_REG(par, 1, TGA_CLOCK_REG);
  402. target = (f << shift) / TGA_PLL_BASE_FREQ;
  403. min_diff = TGA_PLL_MAX_FREQ;
  404. r = 7 / target;
  405. if (!r) r = 1;
  406. base = target * r;
  407. while (base < 449) {
  408. for (n = base < 7 ? 7 : base; n < base + target && n < 449; n++) {
  409. m = ((n + 3) / 7) - 1;
  410. a = 0;
  411. DIFFCHECK((m + 1) * 7);
  412. m++;
  413. DIFFCHECK((m + 1) * 7);
  414. m = (n / 6) - 1;
  415. if ((a = n % 6))
  416. DIFFCHECK(n);
  417. }
  418. r++;
  419. base += target;
  420. }
  421. vr--;
  422. for (r = 0; r < 8; r++)
  423. TGA_WRITE_REG(par, (vm >> r) & 1, TGA_CLOCK_REG);
  424. for (r = 0; r < 8 ; r++)
  425. TGA_WRITE_REG(par, (va >> r) & 1, TGA_CLOCK_REG);
  426. for (r = 0; r < 7 ; r++)
  427. TGA_WRITE_REG(par, (vr >> r) & 1, TGA_CLOCK_REG);
  428. TGA_WRITE_REG(par, ((vr >> 7) & 1)|2, TGA_CLOCK_REG);
  429. }
  430. /**
  431. * tgafb_setcolreg - Optional function. Sets a color register.
  432. * @regno: boolean, 0 copy local, 1 get_user() function
  433. * @red: frame buffer colormap structure
  434. * @green: The green value which can be up to 16 bits wide
  435. * @blue: The blue value which can be up to 16 bits wide.
  436. * @transp: If supported the alpha value which can be up to 16 bits wide.
  437. * @info: frame buffer info structure
  438. */
  439. static int
  440. tgafb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue,
  441. unsigned transp, struct fb_info *info)
  442. {
  443. struct tga_par *par = (struct tga_par *) info->par;
  444. int tga_bus_pci = TGA_BUS_PCI(par->dev);
  445. int tga_bus_tc = TGA_BUS_TC(par->dev);
  446. if (regno > 255)
  447. return 1;
  448. red >>= 8;
  449. green >>= 8;
  450. blue >>= 8;
  451. if (par->tga_type == TGA_TYPE_8PLANE && tga_bus_pci) {
  452. BT485_WRITE(par, regno, BT485_ADDR_PAL_WRITE);
  453. TGA_WRITE_REG(par, BT485_DATA_PAL, TGA_RAMDAC_SETUP_REG);
  454. TGA_WRITE_REG(par, red|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG);
  455. TGA_WRITE_REG(par, green|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG);
  456. TGA_WRITE_REG(par, blue|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG);
  457. } else if (par->tga_type == TGA_TYPE_8PLANE && tga_bus_tc) {
  458. BT459_LOAD_ADDR(par, regno);
  459. TGA_WRITE_REG(par, BT459_PALETTE << 2, TGA_RAMDAC_SETUP_REG);
  460. TGA_WRITE_REG(par, red, TGA_RAMDAC_REG);
  461. TGA_WRITE_REG(par, green, TGA_RAMDAC_REG);
  462. TGA_WRITE_REG(par, blue, TGA_RAMDAC_REG);
  463. } else {
  464. if (regno < 16) {
  465. u32 value = (regno << 16) | (regno << 8) | regno;
  466. ((u32 *)info->pseudo_palette)[regno] = value;
  467. }
  468. BT463_LOAD_ADDR(par, regno);
  469. TGA_WRITE_REG(par, BT463_PALETTE << 2, TGA_RAMDAC_SETUP_REG);
  470. TGA_WRITE_REG(par, red, TGA_RAMDAC_REG);
  471. TGA_WRITE_REG(par, green, TGA_RAMDAC_REG);
  472. TGA_WRITE_REG(par, blue, TGA_RAMDAC_REG);
  473. }
  474. return 0;
  475. }
  476. /**
  477. * tgafb_blank - Optional function. Blanks the display.
  478. * @blank_mode: the blank mode we want.
  479. * @info: frame buffer structure that represents a single frame buffer
  480. */
  481. static int
  482. tgafb_blank(int blank, struct fb_info *info)
  483. {
  484. struct tga_par *par = (struct tga_par *) info->par;
  485. u32 vhcr, vvcr, vvvr;
  486. unsigned long flags;
  487. local_irq_save(flags);
  488. vhcr = TGA_READ_REG(par, TGA_HORIZ_REG);
  489. vvcr = TGA_READ_REG(par, TGA_VERT_REG);
  490. vvvr = TGA_READ_REG(par, TGA_VALID_REG);
  491. vvvr &= ~(TGA_VALID_VIDEO | TGA_VALID_BLANK);
  492. switch (blank) {
  493. case FB_BLANK_UNBLANK: /* Unblanking */
  494. if (par->vesa_blanked) {
  495. TGA_WRITE_REG(par, vhcr & 0xbfffffff, TGA_HORIZ_REG);
  496. TGA_WRITE_REG(par, vvcr & 0xbfffffff, TGA_VERT_REG);
  497. par->vesa_blanked = 0;
  498. }
  499. TGA_WRITE_REG(par, vvvr | TGA_VALID_VIDEO, TGA_VALID_REG);
  500. break;
  501. case FB_BLANK_NORMAL: /* Normal blanking */
  502. TGA_WRITE_REG(par, vvvr | TGA_VALID_VIDEO | TGA_VALID_BLANK,
  503. TGA_VALID_REG);
  504. break;
  505. case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
  506. TGA_WRITE_REG(par, vvcr | 0x40000000, TGA_VERT_REG);
  507. TGA_WRITE_REG(par, vvvr | TGA_VALID_BLANK, TGA_VALID_REG);
  508. par->vesa_blanked = 1;
  509. break;
  510. case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
  511. TGA_WRITE_REG(par, vhcr | 0x40000000, TGA_HORIZ_REG);
  512. TGA_WRITE_REG(par, vvvr | TGA_VALID_BLANK, TGA_VALID_REG);
  513. par->vesa_blanked = 1;
  514. break;
  515. case FB_BLANK_POWERDOWN: /* Poweroff */
  516. TGA_WRITE_REG(par, vhcr | 0x40000000, TGA_HORIZ_REG);
  517. TGA_WRITE_REG(par, vvcr | 0x40000000, TGA_VERT_REG);
  518. TGA_WRITE_REG(par, vvvr | TGA_VALID_BLANK, TGA_VALID_REG);
  519. par->vesa_blanked = 1;
  520. break;
  521. }
  522. local_irq_restore(flags);
  523. return 0;
  524. }
  525. /*
  526. * Acceleration.
  527. */
  528. static void
  529. tgafb_mono_imageblit(struct fb_info *info, const struct fb_image *image)
  530. {
  531. struct tga_par *par = (struct tga_par *) info->par;
  532. u32 fgcolor, bgcolor, dx, dy, width, height, vxres, vyres, pixelmask;
  533. unsigned long rincr, line_length, shift, pos, is8bpp;
  534. unsigned long i, j;
  535. const unsigned char *data;
  536. void __iomem *regs_base;
  537. void __iomem *fb_base;
  538. is8bpp = info->var.bits_per_pixel == 8;
  539. dx = image->dx;
  540. dy = image->dy;
  541. width = image->width;
  542. height = image->height;
  543. vxres = info->var.xres_virtual;
  544. vyres = info->var.yres_virtual;
  545. line_length = info->fix.line_length;
  546. rincr = (width + 7) / 8;
  547. /* A shift below cannot cope with. */
  548. if (unlikely(width == 0))
  549. return;
  550. /* Crop the image to the screen. */
  551. if (dx > vxres || dy > vyres)
  552. return;
  553. if (dx + width > vxres)
  554. width = vxres - dx;
  555. if (dy + height > vyres)
  556. height = vyres - dy;
  557. regs_base = par->tga_regs_base;
  558. fb_base = par->tga_fb_base;
  559. /* Expand the color values to fill 32-bits. */
  560. /* ??? Would be nice to notice colour changes elsewhere, so
  561. that we can do this only when necessary. */
  562. fgcolor = image->fg_color;
  563. bgcolor = image->bg_color;
  564. if (is8bpp) {
  565. fgcolor |= fgcolor << 8;
  566. fgcolor |= fgcolor << 16;
  567. bgcolor |= bgcolor << 8;
  568. bgcolor |= bgcolor << 16;
  569. } else {
  570. if (fgcolor < 16)
  571. fgcolor = ((u32 *)info->pseudo_palette)[fgcolor];
  572. if (bgcolor < 16)
  573. bgcolor = ((u32 *)info->pseudo_palette)[bgcolor];
  574. }
  575. __raw_writel(fgcolor, regs_base + TGA_FOREGROUND_REG);
  576. __raw_writel(bgcolor, regs_base + TGA_BACKGROUND_REG);
  577. /* Acquire proper alignment; set up the PIXELMASK register
  578. so that we only write the proper character cell. */
  579. pos = dy * line_length;
  580. if (is8bpp) {
  581. pos += dx;
  582. shift = pos & 3;
  583. pos &= -4;
  584. } else {
  585. pos += dx * 4;
  586. shift = (pos & 7) >> 2;
  587. pos &= -8;
  588. }
  589. data = (const unsigned char *) image->data;
  590. /* Enable opaque stipple mode. */
  591. __raw_writel((is8bpp
  592. ? TGA_MODE_SBM_8BPP | TGA_MODE_OPAQUE_STIPPLE
  593. : TGA_MODE_SBM_24BPP | TGA_MODE_OPAQUE_STIPPLE),
  594. regs_base + TGA_MODE_REG);
  595. if (width + shift <= 32) {
  596. unsigned long bwidth;
  597. /* Handle common case of imaging a single character, in
  598. a font less than or 32 pixels wide. */
  599. /* Avoid a shift by 32; width > 0 implied. */
  600. pixelmask = (2ul << (width - 1)) - 1;
  601. pixelmask <<= shift;
  602. __raw_writel(pixelmask, regs_base + TGA_PIXELMASK_REG);
  603. wmb();
  604. bwidth = (width + 7) / 8;
  605. for (i = 0; i < height; ++i) {
  606. u32 mask = 0;
  607. /* The image data is bit big endian; we need
  608. little endian. */
  609. for (j = 0; j < bwidth; ++j)
  610. mask |= bitrev8(data[j]) << (j * 8);
  611. __raw_writel(mask << shift, fb_base + pos);
  612. pos += line_length;
  613. data += rincr;
  614. }
  615. wmb();
  616. __raw_writel(0xffffffff, regs_base + TGA_PIXELMASK_REG);
  617. } else if (shift == 0) {
  618. unsigned long pos0 = pos;
  619. const unsigned char *data0 = data;
  620. unsigned long bincr = (is8bpp ? 8 : 8*4);
  621. unsigned long bwidth;
  622. /* Handle another common case in which accel_putcs
  623. generates a large bitmap, which happens to be aligned.
  624. Allow the tail to be misaligned. This case is
  625. interesting because we've not got to hold partial
  626. bytes across the words being written. */
  627. wmb();
  628. bwidth = (width / 8) & -4;
  629. for (i = 0; i < height; ++i) {
  630. for (j = 0; j < bwidth; j += 4) {
  631. u32 mask = 0;
  632. mask |= bitrev8(data[j+0]) << (0 * 8);
  633. mask |= bitrev8(data[j+1]) << (1 * 8);
  634. mask |= bitrev8(data[j+2]) << (2 * 8);
  635. mask |= bitrev8(data[j+3]) << (3 * 8);
  636. __raw_writel(mask, fb_base + pos + j*bincr);
  637. }
  638. pos += line_length;
  639. data += rincr;
  640. }
  641. wmb();
  642. pixelmask = (1ul << (width & 31)) - 1;
  643. if (pixelmask) {
  644. __raw_writel(pixelmask, regs_base + TGA_PIXELMASK_REG);
  645. wmb();
  646. pos = pos0 + bwidth*bincr;
  647. data = data0 + bwidth;
  648. bwidth = ((width & 31) + 7) / 8;
  649. for (i = 0; i < height; ++i) {
  650. u32 mask = 0;
  651. for (j = 0; j < bwidth; ++j)
  652. mask |= bitrev8(data[j]) << (j * 8);
  653. __raw_writel(mask, fb_base + pos);
  654. pos += line_length;
  655. data += rincr;
  656. }
  657. wmb();
  658. __raw_writel(0xffffffff, regs_base + TGA_PIXELMASK_REG);
  659. }
  660. } else {
  661. unsigned long pos0 = pos;
  662. const unsigned char *data0 = data;
  663. unsigned long bincr = (is8bpp ? 8 : 8*4);
  664. unsigned long bwidth;
  665. /* Finally, handle the generic case of misaligned start.
  666. Here we split the write into 16-bit spans. This allows
  667. us to use only one pixel mask, instead of four as would
  668. be required by writing 24-bit spans. */
  669. pixelmask = 0xffff << shift;
  670. __raw_writel(pixelmask, regs_base + TGA_PIXELMASK_REG);
  671. wmb();
  672. bwidth = (width / 8) & -2;
  673. for (i = 0; i < height; ++i) {
  674. for (j = 0; j < bwidth; j += 2) {
  675. u32 mask = 0;
  676. mask |= bitrev8(data[j+0]) << (0 * 8);
  677. mask |= bitrev8(data[j+1]) << (1 * 8);
  678. mask <<= shift;
  679. __raw_writel(mask, fb_base + pos + j*bincr);
  680. }
  681. pos += line_length;
  682. data += rincr;
  683. }
  684. wmb();
  685. pixelmask = ((1ul << (width & 15)) - 1) << shift;
  686. if (pixelmask) {
  687. __raw_writel(pixelmask, regs_base + TGA_PIXELMASK_REG);
  688. wmb();
  689. pos = pos0 + bwidth*bincr;
  690. data = data0 + bwidth;
  691. bwidth = (width & 15) > 8;
  692. for (i = 0; i < height; ++i) {
  693. u32 mask = bitrev8(data[0]);
  694. if (bwidth)
  695. mask |= bitrev8(data[1]) << 8;
  696. mask <<= shift;
  697. __raw_writel(mask, fb_base + pos);
  698. pos += line_length;
  699. data += rincr;
  700. }
  701. wmb();
  702. }
  703. __raw_writel(0xffffffff, regs_base + TGA_PIXELMASK_REG);
  704. }
  705. /* Disable opaque stipple mode. */
  706. __raw_writel((is8bpp
  707. ? TGA_MODE_SBM_8BPP | TGA_MODE_SIMPLE
  708. : TGA_MODE_SBM_24BPP | TGA_MODE_SIMPLE),
  709. regs_base + TGA_MODE_REG);
  710. }
  711. static void
  712. tgafb_clut_imageblit(struct fb_info *info, const struct fb_image *image)
  713. {
  714. struct tga_par *par = (struct tga_par *) info->par;
  715. u32 color, dx, dy, width, height, vxres, vyres;
  716. u32 *palette = ((u32 *)info->pseudo_palette);
  717. unsigned long pos, line_length, i, j;
  718. const unsigned char *data;
  719. void __iomem *regs_base, *fb_base;
  720. dx = image->dx;
  721. dy = image->dy;
  722. width = image->width;
  723. height = image->height;
  724. vxres = info->var.xres_virtual;
  725. vyres = info->var.yres_virtual;
  726. line_length = info->fix.line_length;
  727. /* Crop the image to the screen. */
  728. if (dx > vxres || dy > vyres)
  729. return;
  730. if (dx + width > vxres)
  731. width = vxres - dx;
  732. if (dy + height > vyres)
  733. height = vyres - dy;
  734. regs_base = par->tga_regs_base;
  735. fb_base = par->tga_fb_base;
  736. pos = dy * line_length + (dx * 4);
  737. data = image->data;
  738. /* Now copy the image, color_expanding via the palette. */
  739. for (i = 0; i < height; i++) {
  740. for (j = 0; j < width; j++) {
  741. color = palette[*data++];
  742. __raw_writel(color, fb_base + pos + j*4);
  743. }
  744. pos += line_length;
  745. }
  746. }
  747. /**
  748. * tgafb_imageblit - REQUIRED function. Can use generic routines if
  749. * non acclerated hardware and packed pixel based.
  750. * Copies a image from system memory to the screen.
  751. *
  752. * @info: frame buffer structure that represents a single frame buffer
  753. * @image: structure defining the image.
  754. */
  755. static void
  756. tgafb_imageblit(struct fb_info *info, const struct fb_image *image)
  757. {
  758. unsigned int is8bpp = info->var.bits_per_pixel == 8;
  759. /* If a mono image, regardless of FB depth, go do it. */
  760. if (image->depth == 1) {
  761. tgafb_mono_imageblit(info, image);
  762. return;
  763. }
  764. /* For copies that aren't pixel expansion, there's little we
  765. can do better than the generic code. */
  766. /* ??? There is a DMA write mode; I wonder if that could be
  767. made to pull the data from the image buffer... */
  768. if (image->depth == info->var.bits_per_pixel) {
  769. cfb_imageblit(info, image);
  770. return;
  771. }
  772. /* If 24-plane FB and the image is 8-plane with CLUT, we can do it. */
  773. if (!is8bpp && image->depth == 8) {
  774. tgafb_clut_imageblit(info, image);
  775. return;
  776. }
  777. /* Silently return... */
  778. }
  779. /**
  780. * tgafb_fillrect - REQUIRED function. Can use generic routines if
  781. * non acclerated hardware and packed pixel based.
  782. * Draws a rectangle on the screen.
  783. *
  784. * @info: frame buffer structure that represents a single frame buffer
  785. * @rect: structure defining the rectagle and operation.
  786. */
  787. static void
  788. tgafb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  789. {
  790. struct tga_par *par = (struct tga_par *) info->par;
  791. int is8bpp = info->var.bits_per_pixel == 8;
  792. u32 dx, dy, width, height, vxres, vyres, color;
  793. unsigned long pos, align, line_length, i, j;
  794. void __iomem *regs_base;
  795. void __iomem *fb_base;
  796. dx = rect->dx;
  797. dy = rect->dy;
  798. width = rect->width;
  799. height = rect->height;
  800. vxres = info->var.xres_virtual;
  801. vyres = info->var.yres_virtual;
  802. line_length = info->fix.line_length;
  803. regs_base = par->tga_regs_base;
  804. fb_base = par->tga_fb_base;
  805. /* Crop the rectangle to the screen. */
  806. if (dx > vxres || dy > vyres || !width || !height)
  807. return;
  808. if (dx + width > vxres)
  809. width = vxres - dx;
  810. if (dy + height > vyres)
  811. height = vyres - dy;
  812. pos = dy * line_length + dx * (is8bpp ? 1 : 4);
  813. /* ??? We could implement ROP_XOR with opaque fill mode
  814. and a RasterOp setting of GXxor, but as far as I can
  815. tell, this mode is not actually used in the kernel.
  816. Thus I am ignoring it for now. */
  817. if (rect->rop != ROP_COPY) {
  818. cfb_fillrect(info, rect);
  819. return;
  820. }
  821. /* Expand the color value to fill 8 pixels. */
  822. color = rect->color;
  823. if (is8bpp) {
  824. color |= color << 8;
  825. color |= color << 16;
  826. __raw_writel(color, regs_base + TGA_BLOCK_COLOR0_REG);
  827. __raw_writel(color, regs_base + TGA_BLOCK_COLOR1_REG);
  828. } else {
  829. if (color < 16)
  830. color = ((u32 *)info->pseudo_palette)[color];
  831. __raw_writel(color, regs_base + TGA_BLOCK_COLOR0_REG);
  832. __raw_writel(color, regs_base + TGA_BLOCK_COLOR1_REG);
  833. __raw_writel(color, regs_base + TGA_BLOCK_COLOR2_REG);
  834. __raw_writel(color, regs_base + TGA_BLOCK_COLOR3_REG);
  835. __raw_writel(color, regs_base + TGA_BLOCK_COLOR4_REG);
  836. __raw_writel(color, regs_base + TGA_BLOCK_COLOR5_REG);
  837. __raw_writel(color, regs_base + TGA_BLOCK_COLOR6_REG);
  838. __raw_writel(color, regs_base + TGA_BLOCK_COLOR7_REG);
  839. }
  840. /* The DATA register holds the fill mask for block fill mode.
  841. Since we're not stippling, this is all ones. */
  842. __raw_writel(0xffffffff, regs_base + TGA_DATA_REG);
  843. /* Enable block fill mode. */
  844. __raw_writel((is8bpp
  845. ? TGA_MODE_SBM_8BPP | TGA_MODE_BLOCK_FILL
  846. : TGA_MODE_SBM_24BPP | TGA_MODE_BLOCK_FILL),
  847. regs_base + TGA_MODE_REG);
  848. wmb();
  849. /* We can fill 2k pixels per operation. Notice blocks that fit
  850. the width of the screen so that we can take advantage of this
  851. and fill more than one line per write. */
  852. if (width == line_length)
  853. width *= height, height = 1;
  854. /* The write into the frame buffer must be aligned to 4 bytes,
  855. but we are allowed to encode the offset within the word in
  856. the data word written. */
  857. align = (pos & 3) << 16;
  858. pos &= -4;
  859. if (width <= 2048) {
  860. u32 data;
  861. data = (width - 1) | align;
  862. for (i = 0; i < height; ++i) {
  863. __raw_writel(data, fb_base + pos);
  864. pos += line_length;
  865. }
  866. } else {
  867. unsigned long Bpp = (is8bpp ? 1 : 4);
  868. unsigned long nwidth = width & -2048;
  869. u32 fdata, ldata;
  870. fdata = (2048 - 1) | align;
  871. ldata = ((width & 2047) - 1) | align;
  872. for (i = 0; i < height; ++i) {
  873. for (j = 0; j < nwidth; j += 2048)
  874. __raw_writel(fdata, fb_base + pos + j*Bpp);
  875. if (j < width)
  876. __raw_writel(ldata, fb_base + pos + j*Bpp);
  877. pos += line_length;
  878. }
  879. }
  880. wmb();
  881. /* Disable block fill mode. */
  882. __raw_writel((is8bpp
  883. ? TGA_MODE_SBM_8BPP | TGA_MODE_SIMPLE
  884. : TGA_MODE_SBM_24BPP | TGA_MODE_SIMPLE),
  885. regs_base + TGA_MODE_REG);
  886. }
  887. /**
  888. * tgafb_copyarea - REQUIRED function. Can use generic routines if
  889. * non acclerated hardware and packed pixel based.
  890. * Copies on area of the screen to another area.
  891. *
  892. * @info: frame buffer structure that represents a single frame buffer
  893. * @area: structure defining the source and destination.
  894. */
  895. /* Handle the special case of copying entire lines, e.g. during scrolling.
  896. We can avoid a lot of needless computation in this case. In the 8bpp
  897. case we need to use the COPY64 registers instead of mask writes into
  898. the frame buffer to achieve maximum performance. */
  899. static inline void
  900. copyarea_line_8bpp(struct fb_info *info, u32 dy, u32 sy,
  901. u32 height, u32 width)
  902. {
  903. struct tga_par *par = (struct tga_par *) info->par;
  904. void __iomem *tga_regs = par->tga_regs_base;
  905. unsigned long dpos, spos, i, n64;
  906. /* Set up the MODE and PIXELSHIFT registers. */
  907. __raw_writel(TGA_MODE_SBM_8BPP | TGA_MODE_COPY, tga_regs+TGA_MODE_REG);
  908. __raw_writel(0, tga_regs+TGA_PIXELSHIFT_REG);
  909. wmb();
  910. n64 = (height * width) / 64;
  911. if (sy < dy) {
  912. spos = (sy + height) * width;
  913. dpos = (dy + height) * width;
  914. for (i = 0; i < n64; ++i) {
  915. spos -= 64;
  916. dpos -= 64;
  917. __raw_writel(spos, tga_regs+TGA_COPY64_SRC);
  918. wmb();
  919. __raw_writel(dpos, tga_regs+TGA_COPY64_DST);
  920. wmb();
  921. }
  922. } else {
  923. spos = sy * width;
  924. dpos = dy * width;
  925. for (i = 0; i < n64; ++i) {
  926. __raw_writel(spos, tga_regs+TGA_COPY64_SRC);
  927. wmb();
  928. __raw_writel(dpos, tga_regs+TGA_COPY64_DST);
  929. wmb();
  930. spos += 64;
  931. dpos += 64;
  932. }
  933. }
  934. /* Reset the MODE register to normal. */
  935. __raw_writel(TGA_MODE_SBM_8BPP|TGA_MODE_SIMPLE, tga_regs+TGA_MODE_REG);
  936. }
  937. static inline void
  938. copyarea_line_32bpp(struct fb_info *info, u32 dy, u32 sy,
  939. u32 height, u32 width)
  940. {
  941. struct tga_par *par = (struct tga_par *) info->par;
  942. void __iomem *tga_regs = par->tga_regs_base;
  943. void __iomem *tga_fb = par->tga_fb_base;
  944. void __iomem *src;
  945. void __iomem *dst;
  946. unsigned long i, n16;
  947. /* Set up the MODE and PIXELSHIFT registers. */
  948. __raw_writel(TGA_MODE_SBM_24BPP | TGA_MODE_COPY, tga_regs+TGA_MODE_REG);
  949. __raw_writel(0, tga_regs+TGA_PIXELSHIFT_REG);
  950. wmb();
  951. n16 = (height * width) / 16;
  952. if (sy < dy) {
  953. src = tga_fb + (sy + height) * width * 4;
  954. dst = tga_fb + (dy + height) * width * 4;
  955. for (i = 0; i < n16; ++i) {
  956. src -= 64;
  957. dst -= 64;
  958. __raw_writel(0xffff, src);
  959. wmb();
  960. __raw_writel(0xffff, dst);
  961. wmb();
  962. }
  963. } else {
  964. src = tga_fb + sy * width * 4;
  965. dst = tga_fb + dy * width * 4;
  966. for (i = 0; i < n16; ++i) {
  967. __raw_writel(0xffff, src);
  968. wmb();
  969. __raw_writel(0xffff, dst);
  970. wmb();
  971. src += 64;
  972. dst += 64;
  973. }
  974. }
  975. /* Reset the MODE register to normal. */
  976. __raw_writel(TGA_MODE_SBM_24BPP|TGA_MODE_SIMPLE, tga_regs+TGA_MODE_REG);
  977. }
  978. /* The general case of forward copy in 8bpp mode. */
  979. static inline void
  980. copyarea_foreward_8bpp(struct fb_info *info, u32 dx, u32 dy, u32 sx, u32 sy,
  981. u32 height, u32 width, u32 line_length)
  982. {
  983. struct tga_par *par = (struct tga_par *) info->par;
  984. unsigned long i, copied, left;
  985. unsigned long dpos, spos, dalign, salign, yincr;
  986. u32 smask_first, dmask_first, dmask_last;
  987. int pixel_shift, need_prime, need_second;
  988. unsigned long n64, n32, xincr_first;
  989. void __iomem *tga_regs;
  990. void __iomem *tga_fb;
  991. yincr = line_length;
  992. if (dy > sy) {
  993. dy += height - 1;
  994. sy += height - 1;
  995. yincr = -yincr;
  996. }
  997. /* Compute the offsets and alignments in the frame buffer.
  998. More than anything else, these control how we do copies. */
  999. dpos = dy * line_length + dx;
  1000. spos = sy * line_length + sx;
  1001. dalign = dpos & 7;
  1002. salign = spos & 7;
  1003. dpos &= -8;
  1004. spos &= -8;
  1005. /* Compute the value for the PIXELSHIFT register. This controls
  1006. both non-co-aligned source and destination and copy direction. */
  1007. if (dalign >= salign)
  1008. pixel_shift = dalign - salign;
  1009. else
  1010. pixel_shift = 8 - (salign - dalign);
  1011. /* Figure out if we need an additional priming step for the
  1012. residue register. */
  1013. need_prime = (salign > dalign);
  1014. if (need_prime)
  1015. dpos -= 8;
  1016. /* Begin by copying the leading unaligned destination. Copy enough
  1017. to make the next destination address 32-byte aligned. */
  1018. copied = 32 - (dalign + (dpos & 31));
  1019. if (copied == 32)
  1020. copied = 0;
  1021. xincr_first = (copied + 7) & -8;
  1022. smask_first = dmask_first = (1ul << copied) - 1;
  1023. smask_first <<= salign;
  1024. dmask_first <<= dalign + need_prime*8;
  1025. if (need_prime && copied > 24)
  1026. copied -= 8;
  1027. left = width - copied;
  1028. /* Care for small copies. */
  1029. if (copied > width) {
  1030. u32 t;
  1031. t = (1ul << width) - 1;
  1032. t <<= dalign + need_prime*8;
  1033. dmask_first &= t;
  1034. left = 0;
  1035. }
  1036. /* Attempt to use 64-byte copies. This is only possible if the
  1037. source and destination are co-aligned at 64 bytes. */
  1038. n64 = need_second = 0;
  1039. if ((dpos & 63) == (spos & 63)
  1040. && (height == 1 || line_length % 64 == 0)) {
  1041. /* We may need a 32-byte copy to ensure 64 byte alignment. */
  1042. need_second = (dpos + xincr_first) & 63;
  1043. if ((need_second & 32) != need_second)
  1044. printk(KERN_ERR "tgafb: need_second wrong\n");
  1045. if (left >= need_second + 64) {
  1046. left -= need_second;
  1047. n64 = left / 64;
  1048. left %= 64;
  1049. } else
  1050. need_second = 0;
  1051. }
  1052. /* Copy trailing full 32-byte sections. This will be the main
  1053. loop if the 64 byte loop can't be used. */
  1054. n32 = left / 32;
  1055. left %= 32;
  1056. /* Copy the trailing unaligned destination. */
  1057. dmask_last = (1ul << left) - 1;
  1058. tga_regs = par->tga_regs_base;
  1059. tga_fb = par->tga_fb_base;
  1060. /* Set up the MODE and PIXELSHIFT registers. */
  1061. __raw_writel(TGA_MODE_SBM_8BPP|TGA_MODE_COPY, tga_regs+TGA_MODE_REG);
  1062. __raw_writel(pixel_shift, tga_regs+TGA_PIXELSHIFT_REG);
  1063. wmb();
  1064. for (i = 0; i < height; ++i) {
  1065. unsigned long j;
  1066. void __iomem *sfb;
  1067. void __iomem *dfb;
  1068. sfb = tga_fb + spos;
  1069. dfb = tga_fb + dpos;
  1070. if (dmask_first) {
  1071. __raw_writel(smask_first, sfb);
  1072. wmb();
  1073. __raw_writel(dmask_first, dfb);
  1074. wmb();
  1075. sfb += xincr_first;
  1076. dfb += xincr_first;
  1077. }
  1078. if (need_second) {
  1079. __raw_writel(0xffffffff, sfb);
  1080. wmb();
  1081. __raw_writel(0xffffffff, dfb);
  1082. wmb();
  1083. sfb += 32;
  1084. dfb += 32;
  1085. }
  1086. if (n64 && (((unsigned long)sfb | (unsigned long)dfb) & 63))
  1087. printk(KERN_ERR
  1088. "tgafb: misaligned copy64 (s:%p, d:%p)\n",
  1089. sfb, dfb);
  1090. for (j = 0; j < n64; ++j) {
  1091. __raw_writel(sfb - tga_fb, tga_regs+TGA_COPY64_SRC);
  1092. wmb();
  1093. __raw_writel(dfb - tga_fb, tga_regs+TGA_COPY64_DST);
  1094. wmb();
  1095. sfb += 64;
  1096. dfb += 64;
  1097. }
  1098. for (j = 0; j < n32; ++j) {
  1099. __raw_writel(0xffffffff, sfb);
  1100. wmb();
  1101. __raw_writel(0xffffffff, dfb);
  1102. wmb();
  1103. sfb += 32;
  1104. dfb += 32;
  1105. }
  1106. if (dmask_last) {
  1107. __raw_writel(0xffffffff, sfb);
  1108. wmb();
  1109. __raw_writel(dmask_last, dfb);
  1110. wmb();
  1111. }
  1112. spos += yincr;
  1113. dpos += yincr;
  1114. }
  1115. /* Reset the MODE register to normal. */
  1116. __raw_writel(TGA_MODE_SBM_8BPP|TGA_MODE_SIMPLE, tga_regs+TGA_MODE_REG);
  1117. }
  1118. /* The (almost) general case of backward copy in 8bpp mode. */
  1119. static inline void
  1120. copyarea_backward_8bpp(struct fb_info *info, u32 dx, u32 dy, u32 sx, u32 sy,
  1121. u32 height, u32 width, u32 line_length,
  1122. const struct fb_copyarea *area)
  1123. {
  1124. struct tga_par *par = (struct tga_par *) info->par;
  1125. unsigned long i, left, yincr;
  1126. unsigned long depos, sepos, dealign, sealign;
  1127. u32 mask_first, mask_last;
  1128. unsigned long n32;
  1129. void __iomem *tga_regs;
  1130. void __iomem *tga_fb;
  1131. yincr = line_length;
  1132. if (dy > sy) {
  1133. dy += height - 1;
  1134. sy += height - 1;
  1135. yincr = -yincr;
  1136. }
  1137. /* Compute the offsets and alignments in the frame buffer.
  1138. More than anything else, these control how we do copies. */
  1139. depos = dy * line_length + dx + width;
  1140. sepos = sy * line_length + sx + width;
  1141. dealign = depos & 7;
  1142. sealign = sepos & 7;
  1143. /* ??? The documentation appears to be incorrect (or very
  1144. misleading) wrt how pixel shifting works in backward copy
  1145. mode, i.e. when PIXELSHIFT is negative. I give up for now.
  1146. Do handle the common case of co-aligned backward copies,
  1147. but frob everything else back on generic code. */
  1148. if (dealign != sealign) {
  1149. cfb_copyarea(info, area);
  1150. return;
  1151. }
  1152. /* We begin the copy with the trailing pixels of the
  1153. unaligned destination. */
  1154. mask_first = (1ul << dealign) - 1;
  1155. left = width - dealign;
  1156. /* Care for small copies. */
  1157. if (dealign > width) {
  1158. mask_first ^= (1ul << (dealign - width)) - 1;
  1159. left = 0;
  1160. }
  1161. /* Next copy full words at a time. */
  1162. n32 = left / 32;
  1163. left %= 32;
  1164. /* Finally copy the unaligned head of the span. */
  1165. mask_last = -1 << (32 - left);
  1166. tga_regs = par->tga_regs_base;
  1167. tga_fb = par->tga_fb_base;
  1168. /* Set up the MODE and PIXELSHIFT registers. */
  1169. __raw_writel(TGA_MODE_SBM_8BPP|TGA_MODE_COPY, tga_regs+TGA_MODE_REG);
  1170. __raw_writel(0, tga_regs+TGA_PIXELSHIFT_REG);
  1171. wmb();
  1172. for (i = 0; i < height; ++i) {
  1173. unsigned long j;
  1174. void __iomem *sfb;
  1175. void __iomem *dfb;
  1176. sfb = tga_fb + sepos;
  1177. dfb = tga_fb + depos;
  1178. if (mask_first) {
  1179. __raw_writel(mask_first, sfb);
  1180. wmb();
  1181. __raw_writel(mask_first, dfb);
  1182. wmb();
  1183. }
  1184. for (j = 0; j < n32; ++j) {
  1185. sfb -= 32;
  1186. dfb -= 32;
  1187. __raw_writel(0xffffffff, sfb);
  1188. wmb();
  1189. __raw_writel(0xffffffff, dfb);
  1190. wmb();
  1191. }
  1192. if (mask_last) {
  1193. sfb -= 32;
  1194. dfb -= 32;
  1195. __raw_writel(mask_last, sfb);
  1196. wmb();
  1197. __raw_writel(mask_last, dfb);
  1198. wmb();
  1199. }
  1200. sepos += yincr;
  1201. depos += yincr;
  1202. }
  1203. /* Reset the MODE register to normal. */
  1204. __raw_writel(TGA_MODE_SBM_8BPP|TGA_MODE_SIMPLE, tga_regs+TGA_MODE_REG);
  1205. }
  1206. static void
  1207. tgafb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
  1208. {
  1209. unsigned long dx, dy, width, height, sx, sy, vxres, vyres;
  1210. unsigned long line_length, bpp;
  1211. dx = area->dx;
  1212. dy = area->dy;
  1213. width = area->width;
  1214. height = area->height;
  1215. sx = area->sx;
  1216. sy = area->sy;
  1217. vxres = info->var.xres_virtual;
  1218. vyres = info->var.yres_virtual;
  1219. line_length = info->fix.line_length;
  1220. /* The top left corners must be in the virtual screen. */
  1221. if (dx > vxres || sx > vxres || dy > vyres || sy > vyres)
  1222. return;
  1223. /* Clip the destination. */
  1224. if (dx + width > vxres)
  1225. width = vxres - dx;
  1226. if (dy + height > vyres)
  1227. height = vyres - dy;
  1228. /* The source must be completely inside the virtual screen. */
  1229. if (sx + width > vxres || sy + height > vyres)
  1230. return;
  1231. bpp = info->var.bits_per_pixel;
  1232. /* Detect copies of the entire line. */
  1233. if (width * (bpp >> 3) == line_length) {
  1234. if (bpp == 8)
  1235. copyarea_line_8bpp(info, dy, sy, height, width);
  1236. else
  1237. copyarea_line_32bpp(info, dy, sy, height, width);
  1238. }
  1239. /* ??? The documentation is unclear to me exactly how the pixelshift
  1240. register works in 32bpp mode. Since I don't have hardware to test,
  1241. give up for now and fall back on the generic routines. */
  1242. else if (bpp == 32)
  1243. cfb_copyarea(info, area);
  1244. /* Detect overlapping source and destination that requires
  1245. a backward copy. */
  1246. else if (dy == sy && dx > sx && dx < sx + width)
  1247. copyarea_backward_8bpp(info, dx, dy, sx, sy, height,
  1248. width, line_length, area);
  1249. else
  1250. copyarea_foreward_8bpp(info, dx, dy, sx, sy, height,
  1251. width, line_length);
  1252. }
  1253. /*
  1254. * Initialisation
  1255. */
  1256. static void
  1257. tgafb_init_fix(struct fb_info *info)
  1258. {
  1259. struct tga_par *par = (struct tga_par *)info->par;
  1260. int tga_bus_pci = TGA_BUS_PCI(par->dev);
  1261. int tga_bus_tc = TGA_BUS_TC(par->dev);
  1262. u8 tga_type = par->tga_type;
  1263. const char *tga_type_name = NULL;
  1264. switch (tga_type) {
  1265. case TGA_TYPE_8PLANE:
  1266. if (tga_bus_pci)
  1267. tga_type_name = "Digital ZLXp-E1";
  1268. if (tga_bus_tc)
  1269. tga_type_name = "Digital ZLX-E1";
  1270. break;
  1271. case TGA_TYPE_24PLANE:
  1272. if (tga_bus_pci)
  1273. tga_type_name = "Digital ZLXp-E2";
  1274. if (tga_bus_tc)
  1275. tga_type_name = "Digital ZLX-E2";
  1276. break;
  1277. case TGA_TYPE_24PLUSZ:
  1278. if (tga_bus_pci)
  1279. tga_type_name = "Digital ZLXp-E3";
  1280. if (tga_bus_tc)
  1281. tga_type_name = "Digital ZLX-E3";
  1282. break;
  1283. default:
  1284. tga_type_name = "Unknown";
  1285. break;
  1286. }
  1287. strlcpy(info->fix.id, tga_type_name, sizeof(info->fix.id));
  1288. info->fix.type = FB_TYPE_PACKED_PIXELS;
  1289. info->fix.type_aux = 0;
  1290. info->fix.visual = (tga_type == TGA_TYPE_8PLANE
  1291. ? FB_VISUAL_PSEUDOCOLOR
  1292. : FB_VISUAL_DIRECTCOLOR);
  1293. info->fix.line_length = par->xres * (par->bits_per_pixel >> 3);
  1294. info->fix.smem_start = (size_t) par->tga_fb_base;
  1295. info->fix.smem_len = info->fix.line_length * par->yres;
  1296. info->fix.mmio_start = (size_t) par->tga_regs_base;
  1297. info->fix.mmio_len = 512;
  1298. info->fix.xpanstep = 0;
  1299. info->fix.ypanstep = 0;
  1300. info->fix.ywrapstep = 0;
  1301. info->fix.accel = FB_ACCEL_DEC_TGA;
  1302. /*
  1303. * These are needed by fb_set_logo_truepalette(), so we
  1304. * set them here for 24-plane cards.
  1305. */
  1306. if (tga_type != TGA_TYPE_8PLANE) {
  1307. info->var.red.length = 8;
  1308. info->var.green.length = 8;
  1309. info->var.blue.length = 8;
  1310. info->var.red.offset = 16;
  1311. info->var.green.offset = 8;
  1312. info->var.blue.offset = 0;
  1313. }
  1314. }
  1315. static int tgafb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  1316. {
  1317. /* We just use this to catch switches out of graphics mode. */
  1318. tgafb_set_par(info); /* A bit of overkill for BASE_ADDR reset. */
  1319. return 0;
  1320. }
  1321. static int __devinit
  1322. tgafb_register(struct device *dev)
  1323. {
  1324. static const struct fb_videomode modedb_tc = {
  1325. /* 1280x1024 @ 72 Hz, 76.8 kHz hsync */
  1326. "1280x1024@72", 0, 1280, 1024, 7645, 224, 28, 33, 3, 160, 3,
  1327. FB_SYNC_ON_GREEN, FB_VMODE_NONINTERLACED
  1328. };
  1329. static unsigned int const fb_offset_presets[4] = {
  1330. TGA_8PLANE_FB_OFFSET,
  1331. TGA_24PLANE_FB_OFFSET,
  1332. 0xffffffff,
  1333. TGA_24PLUSZ_FB_OFFSET
  1334. };
  1335. const struct fb_videomode *modedb_tga = NULL;
  1336. resource_size_t bar0_start = 0, bar0_len = 0;
  1337. const char *mode_option_tga = NULL;
  1338. int tga_bus_pci = TGA_BUS_PCI(dev);
  1339. int tga_bus_tc = TGA_BUS_TC(dev);
  1340. unsigned int modedbsize_tga = 0;
  1341. void __iomem *mem_base;
  1342. struct fb_info *info;
  1343. struct tga_par *par;
  1344. u8 tga_type;
  1345. int ret = 0;
  1346. /* Enable device in PCI config. */
  1347. if (tga_bus_pci && pci_enable_device(to_pci_dev(dev))) {
  1348. printk(KERN_ERR "tgafb: Cannot enable PCI device\n");
  1349. return -ENODEV;
  1350. }
  1351. /* Allocate the fb and par structures. */
  1352. info = framebuffer_alloc(sizeof(struct tga_par), dev);
  1353. if (!info) {
  1354. printk(KERN_ERR "tgafb: Cannot allocate memory\n");
  1355. return -ENOMEM;
  1356. }
  1357. par = info->par;
  1358. dev_set_drvdata(dev, info);
  1359. /* Request the mem regions. */
  1360. ret = -ENODEV;
  1361. if (tga_bus_pci) {
  1362. bar0_start = pci_resource_start(to_pci_dev(dev), 0);
  1363. bar0_len = pci_resource_len(to_pci_dev(dev), 0);
  1364. }
  1365. if (tga_bus_tc) {
  1366. bar0_start = to_tc_dev(dev)->resource.start;
  1367. bar0_len = to_tc_dev(dev)->resource.end - bar0_start + 1;
  1368. }
  1369. if (!request_mem_region (bar0_start, bar0_len, "tgafb")) {
  1370. printk(KERN_ERR "tgafb: cannot reserve FB region\n");
  1371. goto err0;
  1372. }
  1373. /* Map the framebuffer. */
  1374. mem_base = ioremap_nocache(bar0_start, bar0_len);
  1375. if (!mem_base) {
  1376. printk(KERN_ERR "tgafb: Cannot map MMIO\n");
  1377. goto err1;
  1378. }
  1379. /* Grab info about the card. */
  1380. tga_type = (readl(mem_base) >> 12) & 0x0f;
  1381. par->dev = dev;
  1382. par->tga_mem_base = mem_base;
  1383. par->tga_fb_base = mem_base + fb_offset_presets[tga_type];
  1384. par->tga_regs_base = mem_base + TGA_REGS_OFFSET;
  1385. par->tga_type = tga_type;
  1386. if (tga_bus_pci)
  1387. par->tga_chip_rev = (to_pci_dev(dev))->revision;
  1388. if (tga_bus_tc)
  1389. par->tga_chip_rev = TGA_READ_REG(par, TGA_START_REG) & 0xff;
  1390. /* Setup framebuffer. */
  1391. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_COPYAREA |
  1392. FBINFO_HWACCEL_IMAGEBLIT | FBINFO_HWACCEL_FILLRECT;
  1393. info->fbops = &tgafb_ops;
  1394. info->screen_base = par->tga_fb_base;
  1395. info->pseudo_palette = par->palette;
  1396. /* This should give a reasonable default video mode. */
  1397. if (tga_bus_pci) {
  1398. mode_option_tga = mode_option_pci;
  1399. }
  1400. if (tga_bus_tc) {
  1401. mode_option_tga = mode_option_tc;
  1402. modedb_tga = &modedb_tc;
  1403. modedbsize_tga = 1;
  1404. }
  1405. ret = fb_find_mode(&info->var, info,
  1406. mode_option ? mode_option : mode_option_tga,
  1407. modedb_tga, modedbsize_tga, NULL,
  1408. tga_type == TGA_TYPE_8PLANE ? 8 : 32);
  1409. if (ret == 0 || ret == 4) {
  1410. printk(KERN_ERR "tgafb: Could not find valid video mode\n");
  1411. ret = -EINVAL;
  1412. goto err1;
  1413. }
  1414. if (fb_alloc_cmap(&info->cmap, 256, 0)) {
  1415. printk(KERN_ERR "tgafb: Could not allocate color map\n");
  1416. ret = -ENOMEM;
  1417. goto err1;
  1418. }
  1419. tgafb_set_par(info);
  1420. tgafb_init_fix(info);
  1421. if (register_framebuffer(info) < 0) {
  1422. printk(KERN_ERR "tgafb: Could not register framebuffer\n");
  1423. ret = -EINVAL;
  1424. goto err1;
  1425. }
  1426. if (tga_bus_pci) {
  1427. pr_info("tgafb: DC21030 [TGA] detected, rev=0x%02x\n",
  1428. par->tga_chip_rev);
  1429. pr_info("tgafb: at PCI bus %d, device %d, function %d\n",
  1430. to_pci_dev(dev)->bus->number,
  1431. PCI_SLOT(to_pci_dev(dev)->devfn),
  1432. PCI_FUNC(to_pci_dev(dev)->devfn));
  1433. }
  1434. if (tga_bus_tc)
  1435. pr_info("tgafb: SFB+ detected, rev=0x%02x\n",
  1436. par->tga_chip_rev);
  1437. pr_info("fb%d: %s frame buffer device at 0x%lx\n",
  1438. info->node, info->fix.id, (long)bar0_start);
  1439. return 0;
  1440. err1:
  1441. if (mem_base)
  1442. iounmap(mem_base);
  1443. release_mem_region(bar0_start, bar0_len);
  1444. err0:
  1445. framebuffer_release(info);
  1446. return ret;
  1447. }
  1448. static void __devexit
  1449. tgafb_unregister(struct device *dev)
  1450. {
  1451. resource_size_t bar0_start = 0, bar0_len = 0;
  1452. int tga_bus_pci = TGA_BUS_PCI(dev);
  1453. int tga_bus_tc = TGA_BUS_TC(dev);
  1454. struct fb_info *info = NULL;
  1455. struct tga_par *par;
  1456. info = dev_get_drvdata(dev);
  1457. if (!info)
  1458. return;
  1459. par = info->par;
  1460. unregister_framebuffer(info);
  1461. fb_dealloc_cmap(&info->cmap);
  1462. iounmap(par->tga_mem_base);
  1463. if (tga_bus_pci) {
  1464. bar0_start = pci_resource_start(to_pci_dev(dev), 0);
  1465. bar0_len = pci_resource_len(to_pci_dev(dev), 0);
  1466. }
  1467. if (tga_bus_tc) {
  1468. bar0_start = to_tc_dev(dev)->resource.start;
  1469. bar0_len = to_tc_dev(dev)->resource.end - bar0_start + 1;
  1470. }
  1471. release_mem_region(bar0_start, bar0_len);
  1472. framebuffer_release(info);
  1473. }
  1474. static void __devexit
  1475. tgafb_exit(void)
  1476. {
  1477. tc_unregister_driver(&tgafb_tc_driver);
  1478. pci_unregister_driver(&tgafb_pci_driver);
  1479. }
  1480. #ifndef MODULE
  1481. static int __devinit
  1482. tgafb_setup(char *arg)
  1483. {
  1484. char *this_opt;
  1485. if (arg && *arg) {
  1486. while ((this_opt = strsep(&arg, ","))) {
  1487. if (!*this_opt)
  1488. continue;
  1489. if (!strncmp(this_opt, "mode:", 5))
  1490. mode_option = this_opt+5;
  1491. else
  1492. printk(KERN_ERR
  1493. "tgafb: unknown parameter %s\n",
  1494. this_opt);
  1495. }
  1496. }
  1497. return 0;
  1498. }
  1499. #endif /* !MODULE */
  1500. static int __devinit
  1501. tgafb_init(void)
  1502. {
  1503. int status;
  1504. #ifndef MODULE
  1505. char *option = NULL;
  1506. if (fb_get_options("tgafb", &option))
  1507. return -ENODEV;
  1508. tgafb_setup(option);
  1509. #endif
  1510. status = pci_register_driver(&tgafb_pci_driver);
  1511. if (!status)
  1512. status = tc_register_driver(&tgafb_tc_driver);
  1513. return status;
  1514. }
  1515. /*
  1516. * Modularisation
  1517. */
  1518. module_init(tgafb_init);
  1519. module_exit(tgafb_exit);
  1520. MODULE_DESCRIPTION("Framebuffer driver for TGA/SFB+ chipset");
  1521. MODULE_LICENSE("GPL");