atafb.c 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275
  1. /*
  2. * linux/drivers/video/atafb.c -- Atari builtin chipset frame buffer device
  3. *
  4. * Copyright (C) 1994 Martin Schaller & Roman Hodek
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive
  8. * for more details.
  9. *
  10. * History:
  11. * - 03 Jan 95: Original version by Martin Schaller: The TT driver and
  12. * all the device independent stuff
  13. * - 09 Jan 95: Roman: I've added the hardware abstraction (hw_switch)
  14. * and wrote the Falcon, ST(E), and External drivers
  15. * based on the original TT driver.
  16. * - 07 May 95: Martin: Added colormap operations for the external driver
  17. * - 21 May 95: Martin: Added support for overscan
  18. * Andreas: some bug fixes for this
  19. * - Jul 95: Guenther Kelleter <guenther@pool.informatik.rwth-aachen.de>:
  20. * Programmable Falcon video modes
  21. * (thanks to Christian Cartus for documentation
  22. * of VIDEL registers).
  23. * - 27 Dec 95: Guenther: Implemented user definable video modes "user[0-7]"
  24. * on minor 24...31. "user0" may be set on commandline by
  25. * "R<x>;<y>;<depth>". (Makes sense only on Falcon)
  26. * Video mode switch on Falcon now done at next VBL interrupt
  27. * to avoid the annoying right shift of the screen.
  28. * - 23 Sep 97: Juergen: added xres_virtual for cards like ProMST
  29. * The external-part is legacy, therefore hardware-specific
  30. * functions like panning/hardwarescrolling/blanking isn't
  31. * supported.
  32. * - 29 Sep 97: Juergen: added Romans suggestion for pan_display
  33. * (var->xoffset was changed even if no set_screen_base avail.)
  34. * - 05 Oct 97: Juergen: extfb (PACKED_PIXEL) is FB_PSEUDOCOLOR 'cause
  35. * we know how to set the colors
  36. * ext_*palette: read from ext_colors (former MV300_colors)
  37. * write to ext_colors and RAMDAC
  38. *
  39. * To do:
  40. * - For the Falcon it is not possible to set random video modes on
  41. * SM124 and SC/TV, only the bootup resolution is supported.
  42. *
  43. */
  44. #define ATAFB_TT
  45. #define ATAFB_STE
  46. #define ATAFB_EXT
  47. #define ATAFB_FALCON
  48. #include <linux/module.h>
  49. #include <linux/kernel.h>
  50. #include <linux/errno.h>
  51. #include <linux/string.h>
  52. #include <linux/mm.h>
  53. #include <linux/slab.h>
  54. #include <linux/delay.h>
  55. #include <linux/init.h>
  56. #include <linux/interrupt.h>
  57. #include <asm/setup.h>
  58. #include <linux/uaccess.h>
  59. #include <asm/pgtable.h>
  60. #include <asm/irq.h>
  61. #include <asm/io.h>
  62. #include <asm/atarihw.h>
  63. #include <asm/atariints.h>
  64. #include <asm/atari_stram.h>
  65. #include <linux/fb.h>
  66. #include <asm/atarikb.h>
  67. #include "c2p.h"
  68. #include "atafb.h"
  69. #define SWITCH_ACIA 0x01 /* modes for switch on OverScan */
  70. #define SWITCH_SND6 0x40
  71. #define SWITCH_SND7 0x80
  72. #define SWITCH_NONE 0x00
  73. #define up(x, r) (((x) + (r) - 1) & ~((r)-1))
  74. /*
  75. * Interface to the world
  76. */
  77. static int atafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info);
  78. static int atafb_set_par(struct fb_info *info);
  79. static int atafb_setcolreg(unsigned int regno, unsigned int red, unsigned int green,
  80. unsigned int blue, unsigned int transp,
  81. struct fb_info *info);
  82. static int atafb_blank(int blank, struct fb_info *info);
  83. static int atafb_pan_display(struct fb_var_screeninfo *var,
  84. struct fb_info *info);
  85. static void atafb_fillrect(struct fb_info *info,
  86. const struct fb_fillrect *rect);
  87. static void atafb_copyarea(struct fb_info *info,
  88. const struct fb_copyarea *region);
  89. static void atafb_imageblit(struct fb_info *info, const struct fb_image *image);
  90. static int atafb_ioctl(struct fb_info *info, unsigned int cmd,
  91. unsigned long arg);
  92. static int default_par; /* default resolution (0=none) */
  93. static unsigned long default_mem_req;
  94. static int hwscroll = -1;
  95. static int use_hwscroll = 1;
  96. static int sttt_xres = 640, st_yres = 400, tt_yres = 480;
  97. static int sttt_xres_virtual = 640, sttt_yres_virtual = 400;
  98. static int ovsc_offset, ovsc_addlen;
  99. /*
  100. * Hardware parameters for current mode
  101. */
  102. static struct atafb_par {
  103. void *screen_base;
  104. int yres_virtual;
  105. u_long next_line;
  106. u_long next_plane;
  107. #if defined ATAFB_TT || defined ATAFB_STE
  108. union {
  109. struct {
  110. int mode;
  111. int sync;
  112. } tt, st;
  113. #endif
  114. #ifdef ATAFB_FALCON
  115. struct falcon_hw {
  116. /* Here are fields for storing a video mode, as direct
  117. * parameters for the hardware.
  118. */
  119. short sync;
  120. short line_width;
  121. short line_offset;
  122. short st_shift;
  123. short f_shift;
  124. short vid_control;
  125. short vid_mode;
  126. short xoffset;
  127. short hht, hbb, hbe, hdb, hde, hss;
  128. short vft, vbb, vbe, vdb, vde, vss;
  129. /* auxiliary information */
  130. short mono;
  131. short ste_mode;
  132. short bpp;
  133. u32 pseudo_palette[16];
  134. } falcon;
  135. #endif
  136. /* Nothing needed for external mode */
  137. } hw;
  138. } current_par;
  139. /* Don't calculate an own resolution, and thus don't change the one found when
  140. * booting (currently used for the Falcon to keep settings for internal video
  141. * hardware extensions (e.g. ScreenBlaster) */
  142. static int DontCalcRes = 0;
  143. #ifdef ATAFB_FALCON
  144. #define HHT hw.falcon.hht
  145. #define HBB hw.falcon.hbb
  146. #define HBE hw.falcon.hbe
  147. #define HDB hw.falcon.hdb
  148. #define HDE hw.falcon.hde
  149. #define HSS hw.falcon.hss
  150. #define VFT hw.falcon.vft
  151. #define VBB hw.falcon.vbb
  152. #define VBE hw.falcon.vbe
  153. #define VDB hw.falcon.vdb
  154. #define VDE hw.falcon.vde
  155. #define VSS hw.falcon.vss
  156. #define VCO_CLOCK25 0x04
  157. #define VCO_CSYPOS 0x10
  158. #define VCO_VSYPOS 0x20
  159. #define VCO_HSYPOS 0x40
  160. #define VCO_SHORTOFFS 0x100
  161. #define VMO_DOUBLE 0x01
  162. #define VMO_INTER 0x02
  163. #define VMO_PREMASK 0x0c
  164. #endif
  165. static struct fb_info fb_info = {
  166. .fix = {
  167. .id = "Atari ",
  168. .visual = FB_VISUAL_PSEUDOCOLOR,
  169. .accel = FB_ACCEL_NONE,
  170. }
  171. };
  172. static void *screen_base; /* base address of screen */
  173. static void *real_screen_base; /* (only for Overscan) */
  174. static int screen_len;
  175. static int current_par_valid;
  176. static int mono_moni;
  177. #ifdef ATAFB_EXT
  178. /* external video handling */
  179. static unsigned int external_xres;
  180. static unsigned int external_xres_virtual;
  181. static unsigned int external_yres;
  182. /*
  183. * not needed - atafb will never support panning/hardwarescroll with external
  184. * static unsigned int external_yres_virtual;
  185. */
  186. static unsigned int external_depth;
  187. static int external_pmode;
  188. static void *external_addr;
  189. static unsigned long external_len;
  190. static unsigned long external_vgaiobase;
  191. static unsigned int external_bitspercol = 6;
  192. /*
  193. * JOE <joe@amber.dinoco.de>:
  194. * added card type for external driver, is only needed for
  195. * colormap handling.
  196. */
  197. enum cardtype { IS_VGA, IS_MV300 };
  198. static enum cardtype external_card_type = IS_VGA;
  199. /*
  200. * The MV300 mixes the color registers. So we need an array of munged
  201. * indices in order to access the correct reg.
  202. */
  203. static int MV300_reg_1bit[2] = {
  204. 0, 1
  205. };
  206. static int MV300_reg_4bit[16] = {
  207. 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15
  208. };
  209. static int MV300_reg_8bit[256] = {
  210. 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240,
  211. 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248,
  212. 4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244,
  213. 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252,
  214. 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242,
  215. 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250,
  216. 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246,
  217. 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254,
  218. 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241,
  219. 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249,
  220. 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245,
  221. 13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253,
  222. 3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243,
  223. 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251,
  224. 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247,
  225. 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255
  226. };
  227. static int *MV300_reg = MV300_reg_8bit;
  228. #endif /* ATAFB_EXT */
  229. static int inverse;
  230. extern int fontheight_8x8;
  231. extern int fontwidth_8x8;
  232. extern unsigned char fontdata_8x8[];
  233. extern int fontheight_8x16;
  234. extern int fontwidth_8x16;
  235. extern unsigned char fontdata_8x16[];
  236. /*
  237. * struct fb_ops {
  238. * * open/release and usage marking
  239. * struct module *owner;
  240. * int (*fb_open)(struct fb_info *info, int user);
  241. * int (*fb_release)(struct fb_info *info, int user);
  242. *
  243. * * For framebuffers with strange non linear layouts or that do not
  244. * * work with normal memory mapped access
  245. * ssize_t (*fb_read)(struct file *file, char __user *buf, size_t count, loff_t *ppos);
  246. * ssize_t (*fb_write)(struct file *file, const char __user *buf, size_t count, loff_t *ppos);
  247. *
  248. * * checks var and eventually tweaks it to something supported,
  249. * * DOES NOT MODIFY PAR *
  250. * int (*fb_check_var)(struct fb_var_screeninfo *var, struct fb_info *info);
  251. *
  252. * * set the video mode according to info->var *
  253. * int (*fb_set_par)(struct fb_info *info);
  254. *
  255. * * set color register *
  256. * int (*fb_setcolreg)(unsigned int regno, unsigned int red, unsigned int green,
  257. * unsigned int blue, unsigned int transp, struct fb_info *info);
  258. *
  259. * * set color registers in batch *
  260. * int (*fb_setcmap)(struct fb_cmap *cmap, struct fb_info *info);
  261. *
  262. * * blank display *
  263. * int (*fb_blank)(int blank, struct fb_info *info);
  264. *
  265. * * pan display *
  266. * int (*fb_pan_display)(struct fb_var_screeninfo *var, struct fb_info *info);
  267. *
  268. * *** The meat of the drawing engine ***
  269. * * Draws a rectangle *
  270. * void (*fb_fillrect) (struct fb_info *info, const struct fb_fillrect *rect);
  271. * * Copy data from area to another *
  272. * void (*fb_copyarea) (struct fb_info *info, const struct fb_copyarea *region);
  273. * * Draws a image to the display *
  274. * void (*fb_imageblit) (struct fb_info *info, const struct fb_image *image);
  275. *
  276. * * Draws cursor *
  277. * int (*fb_cursor) (struct fb_info *info, struct fb_cursor *cursor);
  278. *
  279. * * Rotates the display *
  280. * void (*fb_rotate)(struct fb_info *info, int angle);
  281. *
  282. * * wait for blit idle, optional *
  283. * int (*fb_sync)(struct fb_info *info);
  284. *
  285. * * perform fb specific ioctl (optional) *
  286. * int (*fb_ioctl)(struct fb_info *info, unsigned int cmd,
  287. * unsigned long arg);
  288. *
  289. * * Handle 32bit compat ioctl (optional) *
  290. * int (*fb_compat_ioctl)(struct fb_info *info, unsigned int cmd,
  291. * unsigned long arg);
  292. *
  293. * * perform fb specific mmap *
  294. * int (*fb_mmap)(struct fb_info *info, struct vm_area_struct *vma);
  295. *
  296. * * save current hardware state *
  297. * void (*fb_save_state)(struct fb_info *info);
  298. *
  299. * * restore saved state *
  300. * void (*fb_restore_state)(struct fb_info *info);
  301. * } ;
  302. */
  303. /* ++roman: This structure abstracts from the underlying hardware (ST(e),
  304. * TT, or Falcon.
  305. *
  306. * int (*detect)(void)
  307. * This function should detect the current video mode settings and
  308. * store them in atafb_predefined[0] for later reference by the
  309. * user. Return the index+1 of an equivalent predefined mode or 0
  310. * if there is no such.
  311. *
  312. * int (*encode_fix)(struct fb_fix_screeninfo *fix,
  313. * struct atafb_par *par)
  314. * This function should fill in the 'fix' structure based on the
  315. * values in the 'par' structure.
  316. * !!! Obsolete, perhaps !!!
  317. *
  318. * int (*decode_var)(struct fb_var_screeninfo *var,
  319. * struct atafb_par *par)
  320. * Get the video params out of 'var'. If a value doesn't fit, round
  321. * it up, if it's too big, return EINVAL.
  322. * Round up in the following order: bits_per_pixel, xres, yres,
  323. * xres_virtual, yres_virtual, xoffset, yoffset, grayscale, bitfields,
  324. * horizontal timing, vertical timing.
  325. *
  326. * int (*encode_var)(struct fb_var_screeninfo *var,
  327. * struct atafb_par *par);
  328. * Fill the 'var' structure based on the values in 'par' and maybe
  329. * other values read out of the hardware.
  330. *
  331. * void (*get_par)(struct atafb_par *par)
  332. * Fill the hardware's 'par' structure.
  333. * !!! Used only by detect() !!!
  334. *
  335. * void (*set_par)(struct atafb_par *par)
  336. * Set the hardware according to 'par'.
  337. *
  338. * void (*set_screen_base)(void *s_base)
  339. * Set the base address of the displayed frame buffer. Only called
  340. * if yres_virtual > yres or xres_virtual > xres.
  341. *
  342. * int (*blank)(int blank_mode)
  343. * Blank the screen if blank_mode != 0, else unblank. If blank == NULL then
  344. * the caller blanks by setting the CLUT to all black. Return 0 if blanking
  345. * succeeded, !=0 if un-/blanking failed due to e.g. a video mode which
  346. * doesn't support it. Implements VESA suspend and powerdown modes on
  347. * hardware that supports disabling hsync/vsync:
  348. * blank_mode == 2: suspend vsync, 3:suspend hsync, 4: powerdown.
  349. */
  350. static struct fb_hwswitch {
  351. int (*detect)(void);
  352. int (*encode_fix)(struct fb_fix_screeninfo *fix,
  353. struct atafb_par *par);
  354. int (*decode_var)(struct fb_var_screeninfo *var,
  355. struct atafb_par *par);
  356. int (*encode_var)(struct fb_var_screeninfo *var,
  357. struct atafb_par *par);
  358. void (*get_par)(struct atafb_par *par);
  359. void (*set_par)(struct atafb_par *par);
  360. void (*set_screen_base)(void *s_base);
  361. int (*blank)(int blank_mode);
  362. int (*pan_display)(struct fb_var_screeninfo *var,
  363. struct fb_info *info);
  364. } *fbhw;
  365. static char *autodetect_names[] = { "autodetect", NULL };
  366. static char *stlow_names[] = { "stlow", NULL };
  367. static char *stmid_names[] = { "stmid", "default5", NULL };
  368. static char *sthigh_names[] = { "sthigh", "default4", NULL };
  369. static char *ttlow_names[] = { "ttlow", NULL };
  370. static char *ttmid_names[] = { "ttmid", "default1", NULL };
  371. static char *tthigh_names[] = { "tthigh", "default2", NULL };
  372. static char *vga2_names[] = { "vga2", NULL };
  373. static char *vga4_names[] = { "vga4", NULL };
  374. static char *vga16_names[] = { "vga16", "default3", NULL };
  375. static char *vga256_names[] = { "vga256", NULL };
  376. static char *falh2_names[] = { "falh2", NULL };
  377. static char *falh16_names[] = { "falh16", NULL };
  378. static char **fb_var_names[] = {
  379. autodetect_names,
  380. stlow_names,
  381. stmid_names,
  382. sthigh_names,
  383. ttlow_names,
  384. ttmid_names,
  385. tthigh_names,
  386. vga2_names,
  387. vga4_names,
  388. vga16_names,
  389. vga256_names,
  390. falh2_names,
  391. falh16_names,
  392. NULL
  393. };
  394. static struct fb_var_screeninfo atafb_predefined[] = {
  395. /*
  396. * yres_virtual == 0 means use hw-scrolling if possible, else yres
  397. */
  398. { /* autodetect */
  399. 0, 0, 0, 0, 0, 0, 0, 0, /* xres-grayscale */
  400. {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, /* red green blue tran*/
  401. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  402. { /* st low */
  403. 320, 200, 320, 0, 0, 0, 4, 0,
  404. {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
  405. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  406. { /* st mid */
  407. 640, 200, 640, 0, 0, 0, 2, 0,
  408. {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
  409. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  410. { /* st high */
  411. 640, 400, 640, 0, 0, 0, 1, 0,
  412. {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
  413. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  414. { /* tt low */
  415. 320, 480, 320, 0, 0, 0, 8, 0,
  416. {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
  417. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  418. { /* tt mid */
  419. 640, 480, 640, 0, 0, 0, 4, 0,
  420. {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
  421. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  422. { /* tt high */
  423. 1280, 960, 1280, 0, 0, 0, 1, 0,
  424. {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
  425. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  426. { /* vga2 */
  427. 640, 480, 640, 0, 0, 0, 1, 0,
  428. {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
  429. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  430. { /* vga4 */
  431. 640, 480, 640, 0, 0, 0, 2, 0,
  432. {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
  433. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  434. { /* vga16 */
  435. 640, 480, 640, 0, 0, 0, 4, 0,
  436. {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
  437. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  438. { /* vga256 */
  439. 640, 480, 640, 0, 0, 0, 8, 0,
  440. {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
  441. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  442. { /* falh2 */
  443. 896, 608, 896, 0, 0, 0, 1, 0,
  444. {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
  445. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  446. { /* falh16 */
  447. 896, 608, 896, 0, 0, 0, 4, 0,
  448. {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
  449. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  450. };
  451. static int num_atafb_predefined = ARRAY_SIZE(atafb_predefined);
  452. static struct fb_videomode atafb_modedb[] __initdata = {
  453. /*
  454. * Atari Video Modes
  455. *
  456. * If you change these, make sure to update DEFMODE_* as well!
  457. */
  458. /*
  459. * ST/TT Video Modes
  460. */
  461. {
  462. /* 320x200, 15 kHz, 60 Hz (ST low) */
  463. "st-low", 60, 320, 200, 32000, 32, 16, 31, 14, 96, 4,
  464. 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  465. }, {
  466. /* 640x200, 15 kHz, 60 Hz (ST medium) */
  467. "st-mid", 60, 640, 200, 32000, 32, 16, 31, 14, 96, 4,
  468. 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  469. }, {
  470. /* 640x400, 30.25 kHz, 63.5 Hz (ST high) */
  471. "st-high", 63, 640, 400, 32000, 128, 0, 40, 14, 128, 4,
  472. 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  473. }, {
  474. /* 320x480, 15 kHz, 60 Hz (TT low) */
  475. "tt-low", 60, 320, 480, 31041, 120, 100, 8, 16, 140, 30,
  476. 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  477. }, {
  478. /* 640x480, 29 kHz, 57 Hz (TT medium) */
  479. "tt-mid", 60, 640, 480, 31041, 120, 100, 8, 16, 140, 30,
  480. 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  481. }, {
  482. /* 1280x960, 29 kHz, 60 Hz (TT high) */
  483. "tt-high", 57, 640, 960, 31041, 120, 100, 8, 16, 140, 30,
  484. 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  485. },
  486. /*
  487. * VGA Video Modes
  488. */
  489. {
  490. /* 640x480, 31 kHz, 60 Hz (VGA) */
  491. "vga", 63.5, 640, 480, 32000, 18, 42, 31, 11, 96, 3,
  492. 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  493. }, {
  494. /* 640x400, 31 kHz, 70 Hz (VGA) */
  495. "vga70", 70, 640, 400, 32000, 18, 42, 31, 11, 96, 3,
  496. FB_SYNC_VERT_HIGH_ACT | FB_SYNC_COMP_HIGH_ACT, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  497. },
  498. /*
  499. * Falcon HiRes Video Modes
  500. */
  501. {
  502. /* 896x608, 31 kHz, 60 Hz (Falcon High) */
  503. "falh", 60, 896, 608, 32000, 18, 42, 31, 1, 96,3,
  504. 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  505. },
  506. };
  507. #define NUM_TOTAL_MODES ARRAY_SIZE(atafb_modedb)
  508. static char *mode_option __initdata = NULL;
  509. /* default modes */
  510. #define DEFMODE_TT 5 /* "tt-high" for TT */
  511. #define DEFMODE_F30 7 /* "vga70" for Falcon */
  512. #define DEFMODE_STE 2 /* "st-high" for ST/E */
  513. #define DEFMODE_EXT 6 /* "vga" for external */
  514. static int get_video_mode(char *vname)
  515. {
  516. char ***name_list;
  517. char **name;
  518. int i;
  519. name_list = fb_var_names;
  520. for (i = 0; i < num_atafb_predefined; i++) {
  521. name = *name_list++;
  522. if (!name || !*name)
  523. break;
  524. while (*name) {
  525. if (!strcmp(vname, *name))
  526. return i + 1;
  527. name++;
  528. }
  529. }
  530. return 0;
  531. }
  532. /* ------------------- TT specific functions ---------------------- */
  533. #ifdef ATAFB_TT
  534. static int tt_encode_fix(struct fb_fix_screeninfo *fix, struct atafb_par *par)
  535. {
  536. int mode;
  537. strcpy(fix->id, "Atari Builtin");
  538. fix->smem_start = (unsigned long)real_screen_base;
  539. fix->smem_len = screen_len;
  540. fix->type = FB_TYPE_INTERLEAVED_PLANES;
  541. fix->type_aux = 2;
  542. fix->visual = FB_VISUAL_PSEUDOCOLOR;
  543. mode = par->hw.tt.mode & TT_SHIFTER_MODEMASK;
  544. if (mode == TT_SHIFTER_TTHIGH || mode == TT_SHIFTER_STHIGH) {
  545. fix->type = FB_TYPE_PACKED_PIXELS;
  546. fix->type_aux = 0;
  547. if (mode == TT_SHIFTER_TTHIGH)
  548. fix->visual = FB_VISUAL_MONO01;
  549. }
  550. fix->xpanstep = 0;
  551. fix->ypanstep = 1;
  552. fix->ywrapstep = 0;
  553. fix->line_length = par->next_line;
  554. fix->accel = FB_ACCEL_ATARIBLITT;
  555. return 0;
  556. }
  557. static int tt_decode_var(struct fb_var_screeninfo *var, struct atafb_par *par)
  558. {
  559. int xres = var->xres;
  560. int yres = var->yres;
  561. int bpp = var->bits_per_pixel;
  562. int linelen;
  563. int yres_virtual = var->yres_virtual;
  564. if (mono_moni) {
  565. if (bpp > 1 || xres > sttt_xres * 2 || yres > tt_yres * 2)
  566. return -EINVAL;
  567. par->hw.tt.mode = TT_SHIFTER_TTHIGH;
  568. xres = sttt_xres * 2;
  569. yres = tt_yres * 2;
  570. bpp = 1;
  571. } else {
  572. if (bpp > 8 || xres > sttt_xres || yres > tt_yres)
  573. return -EINVAL;
  574. if (bpp > 4) {
  575. if (xres > sttt_xres / 2 || yres > tt_yres)
  576. return -EINVAL;
  577. par->hw.tt.mode = TT_SHIFTER_TTLOW;
  578. xres = sttt_xres / 2;
  579. yres = tt_yres;
  580. bpp = 8;
  581. } else if (bpp > 2) {
  582. if (xres > sttt_xres || yres > tt_yres)
  583. return -EINVAL;
  584. if (xres > sttt_xres / 2 || yres > st_yres / 2) {
  585. par->hw.tt.mode = TT_SHIFTER_TTMID;
  586. xres = sttt_xres;
  587. yres = tt_yres;
  588. bpp = 4;
  589. } else {
  590. par->hw.tt.mode = TT_SHIFTER_STLOW;
  591. xres = sttt_xres / 2;
  592. yres = st_yres / 2;
  593. bpp = 4;
  594. }
  595. } else if (bpp > 1) {
  596. if (xres > sttt_xres || yres > st_yres / 2)
  597. return -EINVAL;
  598. par->hw.tt.mode = TT_SHIFTER_STMID;
  599. xres = sttt_xres;
  600. yres = st_yres / 2;
  601. bpp = 2;
  602. } else if (var->xres > sttt_xres || var->yres > st_yres) {
  603. return -EINVAL;
  604. } else {
  605. par->hw.tt.mode = TT_SHIFTER_STHIGH;
  606. xres = sttt_xres;
  607. yres = st_yres;
  608. bpp = 1;
  609. }
  610. }
  611. if (yres_virtual <= 0)
  612. yres_virtual = 0;
  613. else if (yres_virtual < yres)
  614. yres_virtual = yres;
  615. if (var->sync & FB_SYNC_EXT)
  616. par->hw.tt.sync = 0;
  617. else
  618. par->hw.tt.sync = 1;
  619. linelen = xres * bpp / 8;
  620. if (yres_virtual * linelen > screen_len && screen_len)
  621. return -EINVAL;
  622. if (yres * linelen > screen_len && screen_len)
  623. return -EINVAL;
  624. if (var->yoffset + yres > yres_virtual && yres_virtual)
  625. return -EINVAL;
  626. par->yres_virtual = yres_virtual;
  627. par->screen_base = screen_base + var->yoffset * linelen;
  628. par->next_line = linelen;
  629. return 0;
  630. }
  631. static int tt_encode_var(struct fb_var_screeninfo *var, struct atafb_par *par)
  632. {
  633. int linelen;
  634. memset(var, 0, sizeof(struct fb_var_screeninfo));
  635. var->red.offset = 0;
  636. var->red.length = 4;
  637. var->red.msb_right = 0;
  638. var->grayscale = 0;
  639. var->pixclock = 31041;
  640. var->left_margin = 120; /* these may be incorrect */
  641. var->right_margin = 100;
  642. var->upper_margin = 8;
  643. var->lower_margin = 16;
  644. var->hsync_len = 140;
  645. var->vsync_len = 30;
  646. var->height = -1;
  647. var->width = -1;
  648. if (par->hw.tt.sync & 1)
  649. var->sync = 0;
  650. else
  651. var->sync = FB_SYNC_EXT;
  652. switch (par->hw.tt.mode & TT_SHIFTER_MODEMASK) {
  653. case TT_SHIFTER_STLOW:
  654. var->xres = sttt_xres / 2;
  655. var->xres_virtual = sttt_xres_virtual / 2;
  656. var->yres = st_yres / 2;
  657. var->bits_per_pixel = 4;
  658. break;
  659. case TT_SHIFTER_STMID:
  660. var->xres = sttt_xres;
  661. var->xres_virtual = sttt_xres_virtual;
  662. var->yres = st_yres / 2;
  663. var->bits_per_pixel = 2;
  664. break;
  665. case TT_SHIFTER_STHIGH:
  666. var->xres = sttt_xres;
  667. var->xres_virtual = sttt_xres_virtual;
  668. var->yres = st_yres;
  669. var->bits_per_pixel = 1;
  670. break;
  671. case TT_SHIFTER_TTLOW:
  672. var->xres = sttt_xres / 2;
  673. var->xres_virtual = sttt_xres_virtual / 2;
  674. var->yres = tt_yres;
  675. var->bits_per_pixel = 8;
  676. break;
  677. case TT_SHIFTER_TTMID:
  678. var->xres = sttt_xres;
  679. var->xres_virtual = sttt_xres_virtual;
  680. var->yres = tt_yres;
  681. var->bits_per_pixel = 4;
  682. break;
  683. case TT_SHIFTER_TTHIGH:
  684. var->red.length = 0;
  685. var->xres = sttt_xres * 2;
  686. var->xres_virtual = sttt_xres_virtual * 2;
  687. var->yres = tt_yres * 2;
  688. var->bits_per_pixel = 1;
  689. break;
  690. }
  691. var->blue = var->green = var->red;
  692. var->transp.offset = 0;
  693. var->transp.length = 0;
  694. var->transp.msb_right = 0;
  695. linelen = var->xres_virtual * var->bits_per_pixel / 8;
  696. if (!use_hwscroll)
  697. var->yres_virtual = var->yres;
  698. else if (screen_len) {
  699. if (par->yres_virtual)
  700. var->yres_virtual = par->yres_virtual;
  701. else
  702. /* yres_virtual == 0 means use maximum */
  703. var->yres_virtual = screen_len / linelen;
  704. } else {
  705. if (hwscroll < 0)
  706. var->yres_virtual = 2 * var->yres;
  707. else
  708. var->yres_virtual = var->yres + hwscroll * 16;
  709. }
  710. var->xoffset = 0;
  711. if (screen_base)
  712. var->yoffset = (par->screen_base - screen_base) / linelen;
  713. else
  714. var->yoffset = 0;
  715. var->nonstd = 0;
  716. var->activate = 0;
  717. var->vmode = FB_VMODE_NONINTERLACED;
  718. return 0;
  719. }
  720. static void tt_get_par(struct atafb_par *par)
  721. {
  722. unsigned long addr;
  723. par->hw.tt.mode = shifter_tt.tt_shiftmode;
  724. par->hw.tt.sync = shifter.syncmode;
  725. addr = ((shifter.bas_hi & 0xff) << 16) |
  726. ((shifter.bas_md & 0xff) << 8) |
  727. ((shifter.bas_lo & 0xff));
  728. par->screen_base = phys_to_virt(addr);
  729. }
  730. static void tt_set_par(struct atafb_par *par)
  731. {
  732. shifter_tt.tt_shiftmode = par->hw.tt.mode;
  733. shifter.syncmode = par->hw.tt.sync;
  734. /* only set screen_base if really necessary */
  735. if (current_par.screen_base != par->screen_base)
  736. fbhw->set_screen_base(par->screen_base);
  737. }
  738. static int tt_setcolreg(unsigned int regno, unsigned int red,
  739. unsigned int green, unsigned int blue,
  740. unsigned int transp, struct fb_info *info)
  741. {
  742. if ((shifter_tt.tt_shiftmode & TT_SHIFTER_MODEMASK) == TT_SHIFTER_STHIGH)
  743. regno += 254;
  744. if (regno > 255)
  745. return 1;
  746. tt_palette[regno] = (((red >> 12) << 8) | ((green >> 12) << 4) |
  747. (blue >> 12));
  748. if ((shifter_tt.tt_shiftmode & TT_SHIFTER_MODEMASK) ==
  749. TT_SHIFTER_STHIGH && regno == 254)
  750. tt_palette[0] = 0;
  751. return 0;
  752. }
  753. static int tt_detect(void)
  754. {
  755. struct atafb_par par;
  756. /* Determine the connected monitor: The DMA sound must be
  757. * disabled before reading the MFP GPIP, because the Sound
  758. * Done Signal and the Monochrome Detect are XORed together!
  759. *
  760. * Even on a TT, we should look if there is a DMA sound. It was
  761. * announced that the Eagle is TT compatible, but only the PCM is
  762. * missing...
  763. */
  764. if (ATARIHW_PRESENT(PCM_8BIT)) {
  765. tt_dmasnd.ctrl = DMASND_CTRL_OFF;
  766. udelay(20); /* wait a while for things to settle down */
  767. }
  768. mono_moni = (mfp.par_dt_reg & 0x80) == 0;
  769. tt_get_par(&par);
  770. tt_encode_var(&atafb_predefined[0], &par);
  771. return 1;
  772. }
  773. #endif /* ATAFB_TT */
  774. /* ------------------- Falcon specific functions ---------------------- */
  775. #ifdef ATAFB_FALCON
  776. static int mon_type; /* Falcon connected monitor */
  777. static int f030_bus_width; /* Falcon ram bus width (for vid_control) */
  778. #define F_MON_SM 0
  779. #define F_MON_SC 1
  780. #define F_MON_VGA 2
  781. #define F_MON_TV 3
  782. static struct pixel_clock {
  783. unsigned long f; /* f/[Hz] */
  784. unsigned long t; /* t/[ps] (=1/f) */
  785. int right, hsync, left; /* standard timing in clock cycles, not pixel */
  786. /* hsync initialized in falcon_detect() */
  787. int sync_mask; /* or-mask for hw.falcon.sync to set this clock */
  788. int control_mask; /* ditto, for hw.falcon.vid_control */
  789. } f25 = {
  790. 25175000, 39721, 18, 0, 42, 0x0, VCO_CLOCK25
  791. }, f32 = {
  792. 32000000, 31250, 18, 0, 42, 0x0, 0
  793. }, fext = {
  794. 0, 0, 18, 0, 42, 0x1, 0
  795. };
  796. /* VIDEL-prescale values [mon_type][pixel_length from VCO] */
  797. static int vdl_prescale[4][3] = {
  798. { 4,2,1 }, { 4,2,1 }, { 4,2,2 }, { 4,2,1 }
  799. };
  800. /* Default hsync timing [mon_type] in picoseconds */
  801. static long h_syncs[4] = { 3000000, 4875000, 4000000, 4875000 };
  802. static inline int hxx_prescale(struct falcon_hw *hw)
  803. {
  804. return hw->ste_mode ? 16
  805. : vdl_prescale[mon_type][hw->vid_mode >> 2 & 0x3];
  806. }
  807. static int falcon_encode_fix(struct fb_fix_screeninfo *fix,
  808. struct atafb_par *par)
  809. {
  810. strcpy(fix->id, "Atari Builtin");
  811. fix->smem_start = (unsigned long)real_screen_base;
  812. fix->smem_len = screen_len;
  813. fix->type = FB_TYPE_INTERLEAVED_PLANES;
  814. fix->type_aux = 2;
  815. fix->visual = FB_VISUAL_PSEUDOCOLOR;
  816. fix->xpanstep = 1;
  817. fix->ypanstep = 1;
  818. fix->ywrapstep = 0;
  819. if (par->hw.falcon.mono) {
  820. fix->type = FB_TYPE_PACKED_PIXELS;
  821. fix->type_aux = 0;
  822. /* no smooth scrolling with longword aligned video mem */
  823. fix->xpanstep = 32;
  824. } else if (par->hw.falcon.f_shift & 0x100) {
  825. fix->type = FB_TYPE_PACKED_PIXELS;
  826. fix->type_aux = 0;
  827. /* Is this ok or should it be DIRECTCOLOR? */
  828. fix->visual = FB_VISUAL_TRUECOLOR;
  829. fix->xpanstep = 2;
  830. }
  831. fix->line_length = par->next_line;
  832. fix->accel = FB_ACCEL_ATARIBLITT;
  833. return 0;
  834. }
  835. static int falcon_decode_var(struct fb_var_screeninfo *var,
  836. struct atafb_par *par)
  837. {
  838. int bpp = var->bits_per_pixel;
  839. int xres = var->xres;
  840. int yres = var->yres;
  841. int xres_virtual = var->xres_virtual;
  842. int yres_virtual = var->yres_virtual;
  843. int left_margin, right_margin, hsync_len;
  844. int upper_margin, lower_margin, vsync_len;
  845. int linelen;
  846. int interlace = 0, doubleline = 0;
  847. struct pixel_clock *pclock;
  848. int plen; /* width of pixel in clock cycles */
  849. int xstretch;
  850. int prescale;
  851. int longoffset = 0;
  852. int hfreq, vfreq;
  853. int hdb_off, hde_off, base_off;
  854. int gstart, gend1, gend2, align;
  855. /*
  856. Get the video params out of 'var'. If a value doesn't fit, round
  857. it up, if it's too big, return EINVAL.
  858. Round up in the following order: bits_per_pixel, xres, yres,
  859. xres_virtual, yres_virtual, xoffset, yoffset, grayscale, bitfields,
  860. horizontal timing, vertical timing.
  861. There is a maximum of screen resolution determined by pixelclock
  862. and minimum frame rate -- (X+hmarg.)*(Y+vmarg.)*vfmin <= pixelclock.
  863. In interlace mode this is " * " *vfmin <= pixelclock.
  864. Additional constraints: hfreq.
  865. Frequency range for multisync monitors is given via command line.
  866. For TV and SM124 both frequencies are fixed.
  867. X % 16 == 0 to fit 8x?? font (except 1 bitplane modes must use X%32 == 0)
  868. Y % 16 == 0 to fit 8x16 font
  869. Y % 8 == 0 if Y<400
  870. Currently interlace and doubleline mode in var are ignored.
  871. On SM124 and TV only the standard resolutions can be used.
  872. */
  873. /* Reject uninitialized mode */
  874. if (!xres || !yres || !bpp)
  875. return -EINVAL;
  876. if (mon_type == F_MON_SM && bpp != 1)
  877. return -EINVAL;
  878. if (bpp <= 1) {
  879. bpp = 1;
  880. par->hw.falcon.f_shift = 0x400;
  881. par->hw.falcon.st_shift = 0x200;
  882. } else if (bpp <= 2) {
  883. bpp = 2;
  884. par->hw.falcon.f_shift = 0x000;
  885. par->hw.falcon.st_shift = 0x100;
  886. } else if (bpp <= 4) {
  887. bpp = 4;
  888. par->hw.falcon.f_shift = 0x000;
  889. par->hw.falcon.st_shift = 0x000;
  890. } else if (bpp <= 8) {
  891. bpp = 8;
  892. par->hw.falcon.f_shift = 0x010;
  893. } else if (bpp <= 16) {
  894. bpp = 16; /* packed pixel mode */
  895. par->hw.falcon.f_shift = 0x100; /* hicolor, no overlay */
  896. } else
  897. return -EINVAL;
  898. par->hw.falcon.bpp = bpp;
  899. if (mon_type == F_MON_SM || DontCalcRes) {
  900. /* Skip all calculations. VGA/TV/SC1224 only supported. */
  901. struct fb_var_screeninfo *myvar = &atafb_predefined[0];
  902. if (bpp > myvar->bits_per_pixel ||
  903. var->xres > myvar->xres ||
  904. var->yres > myvar->yres)
  905. return -EINVAL;
  906. fbhw->get_par(par); /* Current par will be new par */
  907. goto set_screen_base; /* Don't forget this */
  908. }
  909. /* Only some fixed resolutions < 640x400 */
  910. if (xres <= 320)
  911. xres = 320;
  912. else if (xres <= 640 && bpp != 16)
  913. xres = 640;
  914. if (yres <= 200)
  915. yres = 200;
  916. else if (yres <= 240)
  917. yres = 240;
  918. else if (yres <= 400)
  919. yres = 400;
  920. /* 2 planes must use STE compatibility mode */
  921. par->hw.falcon.ste_mode = bpp == 2;
  922. par->hw.falcon.mono = bpp == 1;
  923. /* Total and visible scanline length must be a multiple of one longword,
  924. * this and the console fontwidth yields the alignment for xres and
  925. * xres_virtual.
  926. * TODO: this way "odd" fontheights are not supported
  927. *
  928. * Special case in STE mode: blank and graphic positions don't align,
  929. * avoid trash at right margin
  930. */
  931. if (par->hw.falcon.ste_mode)
  932. xres = (xres + 63) & ~63;
  933. else if (bpp == 1)
  934. xres = (xres + 31) & ~31;
  935. else
  936. xres = (xres + 15) & ~15;
  937. if (yres >= 400)
  938. yres = (yres + 15) & ~15;
  939. else
  940. yres = (yres + 7) & ~7;
  941. if (xres_virtual < xres)
  942. xres_virtual = xres;
  943. else if (bpp == 1)
  944. xres_virtual = (xres_virtual + 31) & ~31;
  945. else
  946. xres_virtual = (xres_virtual + 15) & ~15;
  947. if (yres_virtual <= 0)
  948. yres_virtual = 0;
  949. else if (yres_virtual < yres)
  950. yres_virtual = yres;
  951. /* backward bug-compatibility */
  952. if (var->pixclock > 1)
  953. var->pixclock -= 1;
  954. par->hw.falcon.line_width = bpp * xres / 16;
  955. par->hw.falcon.line_offset = bpp * (xres_virtual - xres) / 16;
  956. /* single or double pixel width */
  957. xstretch = (xres < 640) ? 2 : 1;
  958. #if 0 /* SM124 supports only 640x400, this is rejected above */
  959. if (mon_type == F_MON_SM) {
  960. if (xres != 640 && yres != 400)
  961. return -EINVAL;
  962. plen = 1;
  963. pclock = &f32;
  964. /* SM124-mode is special */
  965. par->hw.falcon.ste_mode = 1;
  966. par->hw.falcon.f_shift = 0x000;
  967. par->hw.falcon.st_shift = 0x200;
  968. left_margin = hsync_len = 128 / plen;
  969. right_margin = 0;
  970. /* TODO set all margins */
  971. } else
  972. #endif
  973. if (mon_type == F_MON_SC || mon_type == F_MON_TV) {
  974. plen = 2 * xstretch;
  975. if (var->pixclock > f32.t * plen)
  976. return -EINVAL;
  977. pclock = &f32;
  978. if (yres > 240)
  979. interlace = 1;
  980. if (var->pixclock == 0) {
  981. /* set some minimal margins which center the screen */
  982. left_margin = 32;
  983. right_margin = 18;
  984. hsync_len = pclock->hsync / plen;
  985. upper_margin = 31;
  986. lower_margin = 14;
  987. vsync_len = interlace ? 3 : 4;
  988. } else {
  989. left_margin = var->left_margin;
  990. right_margin = var->right_margin;
  991. hsync_len = var->hsync_len;
  992. upper_margin = var->upper_margin;
  993. lower_margin = var->lower_margin;
  994. vsync_len = var->vsync_len;
  995. if (var->vmode & FB_VMODE_INTERLACED) {
  996. upper_margin = (upper_margin + 1) / 2;
  997. lower_margin = (lower_margin + 1) / 2;
  998. vsync_len = (vsync_len + 1) / 2;
  999. } else if (var->vmode & FB_VMODE_DOUBLE) {
  1000. upper_margin *= 2;
  1001. lower_margin *= 2;
  1002. vsync_len *= 2;
  1003. }
  1004. }
  1005. } else { /* F_MON_VGA */
  1006. if (bpp == 16)
  1007. xstretch = 2; /* Double pixel width only for hicolor */
  1008. /* Default values are used for vert./hor. timing if no pixelclock given. */
  1009. if (var->pixclock == 0) {
  1010. int linesize;
  1011. /* Choose master pixelclock depending on hor. timing */
  1012. plen = 1 * xstretch;
  1013. if ((plen * xres + f25.right + f25.hsync + f25.left) *
  1014. fb_info.monspecs.hfmin < f25.f)
  1015. pclock = &f25;
  1016. else if ((plen * xres + f32.right + f32.hsync +
  1017. f32.left) * fb_info.monspecs.hfmin < f32.f)
  1018. pclock = &f32;
  1019. else if ((plen * xres + fext.right + fext.hsync +
  1020. fext.left) * fb_info.monspecs.hfmin < fext.f &&
  1021. fext.f)
  1022. pclock = &fext;
  1023. else
  1024. return -EINVAL;
  1025. left_margin = pclock->left / plen;
  1026. right_margin = pclock->right / plen;
  1027. hsync_len = pclock->hsync / plen;
  1028. linesize = left_margin + xres + right_margin + hsync_len;
  1029. upper_margin = 31;
  1030. lower_margin = 11;
  1031. vsync_len = 3;
  1032. } else {
  1033. /* Choose largest pixelclock <= wanted clock */
  1034. int i;
  1035. unsigned long pcl = ULONG_MAX;
  1036. pclock = 0;
  1037. for (i = 1; i <= 4; i *= 2) {
  1038. if (f25.t * i >= var->pixclock &&
  1039. f25.t * i < pcl) {
  1040. pcl = f25.t * i;
  1041. pclock = &f25;
  1042. }
  1043. if (f32.t * i >= var->pixclock &&
  1044. f32.t * i < pcl) {
  1045. pcl = f32.t * i;
  1046. pclock = &f32;
  1047. }
  1048. if (fext.t && fext.t * i >= var->pixclock &&
  1049. fext.t * i < pcl) {
  1050. pcl = fext.t * i;
  1051. pclock = &fext;
  1052. }
  1053. }
  1054. if (!pclock)
  1055. return -EINVAL;
  1056. plen = pcl / pclock->t;
  1057. left_margin = var->left_margin;
  1058. right_margin = var->right_margin;
  1059. hsync_len = var->hsync_len;
  1060. upper_margin = var->upper_margin;
  1061. lower_margin = var->lower_margin;
  1062. vsync_len = var->vsync_len;
  1063. /* Internal unit is [single lines per (half-)frame] */
  1064. if (var->vmode & FB_VMODE_INTERLACED) {
  1065. /* # lines in half frame */
  1066. /* External unit is [lines per full frame] */
  1067. upper_margin = (upper_margin + 1) / 2;
  1068. lower_margin = (lower_margin + 1) / 2;
  1069. vsync_len = (vsync_len + 1) / 2;
  1070. } else if (var->vmode & FB_VMODE_DOUBLE) {
  1071. /* External unit is [double lines per frame] */
  1072. upper_margin *= 2;
  1073. lower_margin *= 2;
  1074. vsync_len *= 2;
  1075. }
  1076. }
  1077. if (pclock == &fext)
  1078. longoffset = 1; /* VIDEL doesn't synchronize on short offset */
  1079. }
  1080. /* Is video bus bandwidth (32MB/s) too low for this resolution? */
  1081. /* this is definitely wrong if bus clock != 32MHz */
  1082. if (pclock->f / plen / 8 * bpp > 32000000L)
  1083. return -EINVAL;
  1084. if (vsync_len < 1)
  1085. vsync_len = 1;
  1086. /* include sync lengths in right/lower margin for all calculations */
  1087. right_margin += hsync_len;
  1088. lower_margin += vsync_len;
  1089. /* ! In all calculations of margins we use # of lines in half frame
  1090. * (which is a full frame in non-interlace mode), so we can switch
  1091. * between interlace and non-interlace without messing around
  1092. * with these.
  1093. */
  1094. again:
  1095. /* Set base_offset 128 and video bus width */
  1096. par->hw.falcon.vid_control = mon_type | f030_bus_width;
  1097. if (!longoffset)
  1098. par->hw.falcon.vid_control |= VCO_SHORTOFFS; /* base_offset 64 */
  1099. if (var->sync & FB_SYNC_HOR_HIGH_ACT)
  1100. par->hw.falcon.vid_control |= VCO_HSYPOS;
  1101. if (var->sync & FB_SYNC_VERT_HIGH_ACT)
  1102. par->hw.falcon.vid_control |= VCO_VSYPOS;
  1103. /* Pixelclock */
  1104. par->hw.falcon.vid_control |= pclock->control_mask;
  1105. /* External or internal clock */
  1106. par->hw.falcon.sync = pclock->sync_mask | 0x2;
  1107. /* Pixellength and prescale */
  1108. par->hw.falcon.vid_mode = (2 / plen) << 2;
  1109. if (doubleline)
  1110. par->hw.falcon.vid_mode |= VMO_DOUBLE;
  1111. if (interlace)
  1112. par->hw.falcon.vid_mode |= VMO_INTER;
  1113. /*********************
  1114. * Horizontal timing: unit = [master clock cycles]
  1115. * unit of hxx-registers: [master clock cycles * prescale]
  1116. * Hxx-registers are 9 bit wide
  1117. *
  1118. * 1 line = ((hht + 2) * 2 * prescale) clock cycles
  1119. *
  1120. * graphic output = hdb & 0x200 ?
  1121. * ((hht + 2) * 2 - hdb + hde) * prescale - hdboff + hdeoff:
  1122. * (hht + 2 - hdb + hde) * prescale - hdboff + hdeoff
  1123. * (this must be a multiple of plen*128/bpp, on VGA pixels
  1124. * to the right may be cut off with a bigger right margin)
  1125. *
  1126. * start of graphics relative to start of 1st halfline = hdb & 0x200 ?
  1127. * (hdb - hht - 2) * prescale + hdboff :
  1128. * hdb * prescale + hdboff
  1129. *
  1130. * end of graphics relative to start of 1st halfline =
  1131. * (hde + hht + 2) * prescale + hdeoff
  1132. *********************/
  1133. /* Calculate VIDEL registers */
  1134. {
  1135. prescale = hxx_prescale(&par->hw.falcon);
  1136. base_off = par->hw.falcon.vid_control & VCO_SHORTOFFS ? 64 : 128;
  1137. /* Offsets depend on video mode */
  1138. /* Offsets are in clock cycles, divide by prescale to
  1139. * calculate hd[be]-registers
  1140. */
  1141. if (par->hw.falcon.f_shift & 0x100) {
  1142. align = 1;
  1143. hde_off = 0;
  1144. hdb_off = (base_off + 16 * plen) + prescale;
  1145. } else {
  1146. align = 128 / bpp;
  1147. hde_off = ((128 / bpp + 2) * plen);
  1148. if (par->hw.falcon.ste_mode)
  1149. hdb_off = (64 + base_off + (128 / bpp + 2) * plen) + prescale;
  1150. else
  1151. hdb_off = (base_off + (128 / bpp + 18) * plen) + prescale;
  1152. }
  1153. gstart = (prescale / 2 + plen * left_margin) / prescale;
  1154. /* gend1 is for hde (gend-gstart multiple of align), shifter's xres */
  1155. gend1 = gstart + roundup(xres, align) * plen / prescale;
  1156. /* gend2 is for hbb, visible xres (rest to gend1 is cut off by hblank) */
  1157. gend2 = gstart + xres * plen / prescale;
  1158. par->HHT = plen * (left_margin + xres + right_margin) /
  1159. (2 * prescale) - 2;
  1160. /* par->HHT = (gend2 + plen * right_margin / prescale) / 2 - 2;*/
  1161. par->HDB = gstart - hdb_off / prescale;
  1162. par->HBE = gstart;
  1163. if (par->HDB < 0)
  1164. par->HDB += par->HHT + 2 + 0x200;
  1165. par->HDE = gend1 - par->HHT - 2 - hde_off / prescale;
  1166. par->HBB = gend2 - par->HHT - 2;
  1167. #if 0
  1168. /* One more Videl constraint: data fetch of two lines must not overlap */
  1169. if ((par->HDB & 0x200) && (par->HDB & ~0x200) - par->HDE <= 5) {
  1170. /* if this happens increase margins, decrease hfreq. */
  1171. }
  1172. #endif
  1173. if (hde_off % prescale)
  1174. par->HBB++; /* compensate for non matching hde and hbb */
  1175. par->HSS = par->HHT + 2 - plen * hsync_len / prescale;
  1176. if (par->HSS < par->HBB)
  1177. par->HSS = par->HBB;
  1178. }
  1179. /* check hor. frequency */
  1180. hfreq = pclock->f / ((par->HHT + 2) * prescale * 2);
  1181. if (hfreq > fb_info.monspecs.hfmax && mon_type != F_MON_VGA) {
  1182. /* ++guenther: ^^^^^^^^^^^^^^^^^^^ can't remember why I did this */
  1183. /* Too high -> enlarge margin */
  1184. left_margin += 1;
  1185. right_margin += 1;
  1186. goto again;
  1187. }
  1188. if (hfreq > fb_info.monspecs.hfmax || hfreq < fb_info.monspecs.hfmin)
  1189. return -EINVAL;
  1190. /* Vxx-registers */
  1191. /* All Vxx must be odd in non-interlace, since frame starts in the middle
  1192. * of the first displayed line!
  1193. * One frame consists of VFT+1 half lines. VFT+1 must be even in
  1194. * non-interlace, odd in interlace mode for synchronisation.
  1195. * Vxx-registers are 11 bit wide
  1196. */
  1197. par->VBE = (upper_margin * 2 + 1); /* must begin on odd halfline */
  1198. par->VDB = par->VBE;
  1199. par->VDE = yres;
  1200. if (!interlace)
  1201. par->VDE <<= 1;
  1202. if (doubleline)
  1203. par->VDE <<= 1; /* VDE now half lines per (half-)frame */
  1204. par->VDE += par->VDB;
  1205. par->VBB = par->VDE;
  1206. par->VFT = par->VBB + (lower_margin * 2 - 1) - 1;
  1207. par->VSS = par->VFT + 1 - (vsync_len * 2 - 1);
  1208. /* vbb,vss,vft must be even in interlace mode */
  1209. if (interlace) {
  1210. par->VBB++;
  1211. par->VSS++;
  1212. par->VFT++;
  1213. }
  1214. /* V-frequency check, hope I didn't create any loop here. */
  1215. /* Interlace and doubleline are mutually exclusive. */
  1216. vfreq = (hfreq * 2) / (par->VFT + 1);
  1217. if (vfreq > fb_info.monspecs.vfmax && !doubleline && !interlace) {
  1218. /* Too high -> try again with doubleline */
  1219. doubleline = 1;
  1220. goto again;
  1221. } else if (vfreq < fb_info.monspecs.vfmin && !interlace && !doubleline) {
  1222. /* Too low -> try again with interlace */
  1223. interlace = 1;
  1224. goto again;
  1225. } else if (vfreq < fb_info.monspecs.vfmin && doubleline) {
  1226. /* Doubleline too low -> clear doubleline and enlarge margins */
  1227. int lines;
  1228. doubleline = 0;
  1229. for (lines = 0;
  1230. (hfreq * 2) / (par->VFT + 1 + 4 * lines - 2 * yres) >
  1231. fb_info.monspecs.vfmax;
  1232. lines++)
  1233. ;
  1234. upper_margin += lines;
  1235. lower_margin += lines;
  1236. goto again;
  1237. } else if (vfreq > fb_info.monspecs.vfmax && doubleline) {
  1238. /* Doubleline too high -> enlarge margins */
  1239. int lines;
  1240. for (lines = 0;
  1241. (hfreq * 2) / (par->VFT + 1 + 4 * lines) >
  1242. fb_info.monspecs.vfmax;
  1243. lines += 2)
  1244. ;
  1245. upper_margin += lines;
  1246. lower_margin += lines;
  1247. goto again;
  1248. } else if (vfreq > fb_info.monspecs.vfmax && interlace) {
  1249. /* Interlace, too high -> enlarge margins */
  1250. int lines;
  1251. for (lines = 0;
  1252. (hfreq * 2) / (par->VFT + 1 + 4 * lines) >
  1253. fb_info.monspecs.vfmax;
  1254. lines++)
  1255. ;
  1256. upper_margin += lines;
  1257. lower_margin += lines;
  1258. goto again;
  1259. } else if (vfreq < fb_info.monspecs.vfmin ||
  1260. vfreq > fb_info.monspecs.vfmax)
  1261. return -EINVAL;
  1262. set_screen_base:
  1263. linelen = xres_virtual * bpp / 8;
  1264. if (yres_virtual * linelen > screen_len && screen_len)
  1265. return -EINVAL;
  1266. if (yres * linelen > screen_len && screen_len)
  1267. return -EINVAL;
  1268. if (var->yoffset + yres > yres_virtual && yres_virtual)
  1269. return -EINVAL;
  1270. par->yres_virtual = yres_virtual;
  1271. par->screen_base = screen_base + var->yoffset * linelen;
  1272. par->hw.falcon.xoffset = 0;
  1273. // FIXME!!! sort of works, no crash
  1274. //par->next_line = linelen;
  1275. //par->next_plane = yres_virtual * linelen;
  1276. par->next_line = linelen;
  1277. par->next_plane = 2;
  1278. // crashes
  1279. //par->next_plane = linelen;
  1280. //par->next_line = yres_virtual * linelen;
  1281. return 0;
  1282. }
  1283. static int falcon_encode_var(struct fb_var_screeninfo *var,
  1284. struct atafb_par *par)
  1285. {
  1286. /* !!! only for VGA !!! */
  1287. int linelen;
  1288. int prescale, plen;
  1289. int hdb_off, hde_off, base_off;
  1290. struct falcon_hw *hw = &par->hw.falcon;
  1291. memset(var, 0, sizeof(struct fb_var_screeninfo));
  1292. /* possible frequencies: 25.175 or 32MHz */
  1293. var->pixclock = hw->sync & 0x1 ? fext.t :
  1294. hw->vid_control & VCO_CLOCK25 ? f25.t : f32.t;
  1295. var->height = -1;
  1296. var->width = -1;
  1297. var->sync = 0;
  1298. if (hw->vid_control & VCO_HSYPOS)
  1299. var->sync |= FB_SYNC_HOR_HIGH_ACT;
  1300. if (hw->vid_control & VCO_VSYPOS)
  1301. var->sync |= FB_SYNC_VERT_HIGH_ACT;
  1302. var->vmode = FB_VMODE_NONINTERLACED;
  1303. if (hw->vid_mode & VMO_INTER)
  1304. var->vmode |= FB_VMODE_INTERLACED;
  1305. if (hw->vid_mode & VMO_DOUBLE)
  1306. var->vmode |= FB_VMODE_DOUBLE;
  1307. /* visible y resolution:
  1308. * Graphics display starts at line VDB and ends at line
  1309. * VDE. If interlace mode off unit of VC-registers is
  1310. * half lines, else lines.
  1311. */
  1312. var->yres = hw->vde - hw->vdb;
  1313. if (!(var->vmode & FB_VMODE_INTERLACED))
  1314. var->yres >>= 1;
  1315. if (var->vmode & FB_VMODE_DOUBLE)
  1316. var->yres >>= 1;
  1317. /*
  1318. * to get bpp, we must examine f_shift and st_shift.
  1319. * f_shift is valid if any of bits no. 10, 8 or 4
  1320. * is set. Priority in f_shift is: 10 ">" 8 ">" 4, i.e.
  1321. * if bit 10 set then bit 8 and bit 4 don't care...
  1322. * If all these bits are 0 get display depth from st_shift
  1323. * (as for ST and STE)
  1324. */
  1325. if (hw->f_shift & 0x400) /* 2 colors */
  1326. var->bits_per_pixel = 1;
  1327. else if (hw->f_shift & 0x100) /* hicolor */
  1328. var->bits_per_pixel = 16;
  1329. else if (hw->f_shift & 0x010) /* 8 bitplanes */
  1330. var->bits_per_pixel = 8;
  1331. else if (hw->st_shift == 0)
  1332. var->bits_per_pixel = 4;
  1333. else if (hw->st_shift == 0x100)
  1334. var->bits_per_pixel = 2;
  1335. else /* if (hw->st_shift == 0x200) */
  1336. var->bits_per_pixel = 1;
  1337. var->xres = hw->line_width * 16 / var->bits_per_pixel;
  1338. var->xres_virtual = var->xres + hw->line_offset * 16 / var->bits_per_pixel;
  1339. if (hw->xoffset)
  1340. var->xres_virtual += 16;
  1341. if (var->bits_per_pixel == 16) {
  1342. var->red.offset = 11;
  1343. var->red.length = 5;
  1344. var->red.msb_right = 0;
  1345. var->green.offset = 5;
  1346. var->green.length = 6;
  1347. var->green.msb_right = 0;
  1348. var->blue.offset = 0;
  1349. var->blue.length = 5;
  1350. var->blue.msb_right = 0;
  1351. } else {
  1352. var->red.offset = 0;
  1353. var->red.length = hw->ste_mode ? 4 : 6;
  1354. if (var->red.length > var->bits_per_pixel)
  1355. var->red.length = var->bits_per_pixel;
  1356. var->red.msb_right = 0;
  1357. var->grayscale = 0;
  1358. var->blue = var->green = var->red;
  1359. }
  1360. var->transp.offset = 0;
  1361. var->transp.length = 0;
  1362. var->transp.msb_right = 0;
  1363. linelen = var->xres_virtual * var->bits_per_pixel / 8;
  1364. if (screen_len) {
  1365. if (par->yres_virtual)
  1366. var->yres_virtual = par->yres_virtual;
  1367. else
  1368. /* yres_virtual == 0 means use maximum */
  1369. var->yres_virtual = screen_len / linelen;
  1370. } else {
  1371. if (hwscroll < 0)
  1372. var->yres_virtual = 2 * var->yres;
  1373. else
  1374. var->yres_virtual = var->yres + hwscroll * 16;
  1375. }
  1376. var->xoffset = 0; /* TODO change this */
  1377. /* hdX-offsets */
  1378. prescale = hxx_prescale(hw);
  1379. plen = 4 >> (hw->vid_mode >> 2 & 0x3);
  1380. base_off = hw->vid_control & VCO_SHORTOFFS ? 64 : 128;
  1381. if (hw->f_shift & 0x100) {
  1382. hde_off = 0;
  1383. hdb_off = (base_off + 16 * plen) + prescale;
  1384. } else {
  1385. hde_off = ((128 / var->bits_per_pixel + 2) * plen);
  1386. if (hw->ste_mode)
  1387. hdb_off = (64 + base_off + (128 / var->bits_per_pixel + 2) * plen)
  1388. + prescale;
  1389. else
  1390. hdb_off = (base_off + (128 / var->bits_per_pixel + 18) * plen)
  1391. + prescale;
  1392. }
  1393. /* Right margin includes hsync */
  1394. var->left_margin = hdb_off + prescale * ((hw->hdb & 0x1ff) -
  1395. (hw->hdb & 0x200 ? 2 + hw->hht : 0));
  1396. if (hw->ste_mode || mon_type != F_MON_VGA)
  1397. var->right_margin = prescale * (hw->hht + 2 - hw->hde) - hde_off;
  1398. else
  1399. /* can't use this in ste_mode, because hbb is +1 off */
  1400. var->right_margin = prescale * (hw->hht + 2 - hw->hbb);
  1401. var->hsync_len = prescale * (hw->hht + 2 - hw->hss);
  1402. /* Lower margin includes vsync */
  1403. var->upper_margin = hw->vdb / 2; /* round down to full lines */
  1404. var->lower_margin = (hw->vft + 1 - hw->vde + 1) / 2; /* round up */
  1405. var->vsync_len = (hw->vft + 1 - hw->vss + 1) / 2; /* round up */
  1406. if (var->vmode & FB_VMODE_INTERLACED) {
  1407. var->upper_margin *= 2;
  1408. var->lower_margin *= 2;
  1409. var->vsync_len *= 2;
  1410. } else if (var->vmode & FB_VMODE_DOUBLE) {
  1411. var->upper_margin = (var->upper_margin + 1) / 2;
  1412. var->lower_margin = (var->lower_margin + 1) / 2;
  1413. var->vsync_len = (var->vsync_len + 1) / 2;
  1414. }
  1415. var->pixclock *= plen;
  1416. var->left_margin /= plen;
  1417. var->right_margin /= plen;
  1418. var->hsync_len /= plen;
  1419. var->right_margin -= var->hsync_len;
  1420. var->lower_margin -= var->vsync_len;
  1421. if (screen_base)
  1422. var->yoffset = (par->screen_base - screen_base) / linelen;
  1423. else
  1424. var->yoffset = 0;
  1425. var->nonstd = 0; /* what is this for? */
  1426. var->activate = 0;
  1427. return 0;
  1428. }
  1429. static int f_change_mode;
  1430. static struct falcon_hw f_new_mode;
  1431. static int f_pan_display;
  1432. static void falcon_get_par(struct atafb_par *par)
  1433. {
  1434. unsigned long addr;
  1435. struct falcon_hw *hw = &par->hw.falcon;
  1436. hw->line_width = shifter_f030.scn_width;
  1437. hw->line_offset = shifter_f030.off_next;
  1438. hw->st_shift = videl.st_shift & 0x300;
  1439. hw->f_shift = videl.f_shift;
  1440. hw->vid_control = videl.control;
  1441. hw->vid_mode = videl.mode;
  1442. hw->sync = shifter.syncmode & 0x1;
  1443. hw->xoffset = videl.xoffset & 0xf;
  1444. hw->hht = videl.hht;
  1445. hw->hbb = videl.hbb;
  1446. hw->hbe = videl.hbe;
  1447. hw->hdb = videl.hdb;
  1448. hw->hde = videl.hde;
  1449. hw->hss = videl.hss;
  1450. hw->vft = videl.vft;
  1451. hw->vbb = videl.vbb;
  1452. hw->vbe = videl.vbe;
  1453. hw->vdb = videl.vdb;
  1454. hw->vde = videl.vde;
  1455. hw->vss = videl.vss;
  1456. addr = (shifter.bas_hi & 0xff) << 16 |
  1457. (shifter.bas_md & 0xff) << 8 |
  1458. (shifter.bas_lo & 0xff);
  1459. par->screen_base = phys_to_virt(addr);
  1460. /* derived parameters */
  1461. hw->ste_mode = (hw->f_shift & 0x510) == 0 && hw->st_shift == 0x100;
  1462. hw->mono = (hw->f_shift & 0x400) ||
  1463. ((hw->f_shift & 0x510) == 0 && hw->st_shift == 0x200);
  1464. }
  1465. static void falcon_set_par(struct atafb_par *par)
  1466. {
  1467. f_change_mode = 0;
  1468. /* only set screen_base if really necessary */
  1469. if (current_par.screen_base != par->screen_base)
  1470. fbhw->set_screen_base(par->screen_base);
  1471. /* Don't touch any other registers if we keep the default resolution */
  1472. if (DontCalcRes)
  1473. return;
  1474. /* Tell vbl-handler to change video mode.
  1475. * We change modes only on next VBL, to avoid desynchronisation
  1476. * (a shift to the right and wrap around by a random number of pixels
  1477. * in all monochrome modes).
  1478. * This seems to work on my Falcon.
  1479. */
  1480. f_new_mode = par->hw.falcon;
  1481. f_change_mode = 1;
  1482. }
  1483. static irqreturn_t falcon_vbl_switcher(int irq, void *dummy)
  1484. {
  1485. struct falcon_hw *hw = &f_new_mode;
  1486. if (f_change_mode) {
  1487. f_change_mode = 0;
  1488. if (hw->sync & 0x1) {
  1489. /* Enable external pixelclock. This code only for ScreenWonder */
  1490. *(volatile unsigned short *)0xffff9202 = 0xffbf;
  1491. } else {
  1492. /* Turn off external clocks. Read sets all output bits to 1. */
  1493. *(volatile unsigned short *)0xffff9202;
  1494. }
  1495. shifter.syncmode = hw->sync;
  1496. videl.hht = hw->hht;
  1497. videl.hbb = hw->hbb;
  1498. videl.hbe = hw->hbe;
  1499. videl.hdb = hw->hdb;
  1500. videl.hde = hw->hde;
  1501. videl.hss = hw->hss;
  1502. videl.vft = hw->vft;
  1503. videl.vbb = hw->vbb;
  1504. videl.vbe = hw->vbe;
  1505. videl.vdb = hw->vdb;
  1506. videl.vde = hw->vde;
  1507. videl.vss = hw->vss;
  1508. videl.f_shift = 0; /* write enables Falcon palette, 0: 4 planes */
  1509. if (hw->ste_mode) {
  1510. videl.st_shift = hw->st_shift; /* write enables STE palette */
  1511. } else {
  1512. /* IMPORTANT:
  1513. * set st_shift 0, so we can tell the screen-depth if f_shift == 0.
  1514. * Writing 0 to f_shift enables 4 plane Falcon mode but
  1515. * doesn't set st_shift. st_shift != 0 (!= 4planes) is impossible
  1516. * with Falcon palette.
  1517. */
  1518. videl.st_shift = 0;
  1519. /* now back to Falcon palette mode */
  1520. videl.f_shift = hw->f_shift;
  1521. }
  1522. /* writing to st_shift changed scn_width and vid_mode */
  1523. videl.xoffset = hw->xoffset;
  1524. shifter_f030.scn_width = hw->line_width;
  1525. shifter_f030.off_next = hw->line_offset;
  1526. videl.control = hw->vid_control;
  1527. videl.mode = hw->vid_mode;
  1528. }
  1529. if (f_pan_display) {
  1530. f_pan_display = 0;
  1531. videl.xoffset = current_par.hw.falcon.xoffset;
  1532. shifter_f030.off_next = current_par.hw.falcon.line_offset;
  1533. }
  1534. return IRQ_HANDLED;
  1535. }
  1536. static int falcon_pan_display(struct fb_var_screeninfo *var,
  1537. struct fb_info *info)
  1538. {
  1539. struct atafb_par *par = (struct atafb_par *)info->par;
  1540. int xoffset;
  1541. int bpp = info->var.bits_per_pixel;
  1542. if (bpp == 1)
  1543. var->xoffset = up(var->xoffset, 32);
  1544. if (bpp != 16)
  1545. par->hw.falcon.xoffset = var->xoffset & 15;
  1546. else {
  1547. par->hw.falcon.xoffset = 0;
  1548. var->xoffset = up(var->xoffset, 2);
  1549. }
  1550. par->hw.falcon.line_offset = bpp *
  1551. (info->var.xres_virtual - info->var.xres) / 16;
  1552. if (par->hw.falcon.xoffset)
  1553. par->hw.falcon.line_offset -= bpp;
  1554. xoffset = var->xoffset - par->hw.falcon.xoffset;
  1555. par->screen_base = screen_base +
  1556. (var->yoffset * info->var.xres_virtual + xoffset) * bpp / 8;
  1557. if (fbhw->set_screen_base)
  1558. fbhw->set_screen_base(par->screen_base);
  1559. else
  1560. return -EINVAL; /* shouldn't happen */
  1561. f_pan_display = 1;
  1562. return 0;
  1563. }
  1564. static int falcon_setcolreg(unsigned int regno, unsigned int red,
  1565. unsigned int green, unsigned int blue,
  1566. unsigned int transp, struct fb_info *info)
  1567. {
  1568. if (regno > 255)
  1569. return 1;
  1570. f030_col[regno] = (((red & 0xfc00) << 16) |
  1571. ((green & 0xfc00) << 8) |
  1572. ((blue & 0xfc00) >> 8));
  1573. if (regno < 16) {
  1574. shifter_tt.color_reg[regno] =
  1575. (((red & 0xe000) >> 13) | ((red & 0x1000) >> 12) << 8) |
  1576. (((green & 0xe000) >> 13) | ((green & 0x1000) >> 12) << 4) |
  1577. ((blue & 0xe000) >> 13) | ((blue & 0x1000) >> 12);
  1578. #ifdef ATAFB_FALCON
  1579. ((u32 *)info->pseudo_palette)[regno] = ((red & 0xf800) |
  1580. ((green & 0xfc00) >> 5) |
  1581. ((blue & 0xf800) >> 11));
  1582. #endif
  1583. }
  1584. return 0;
  1585. }
  1586. static int falcon_blank(int blank_mode)
  1587. {
  1588. /* ++guenther: we can switch off graphics by changing VDB and VDE,
  1589. * so VIDEL doesn't hog the bus while saving.
  1590. * (this may affect usleep()).
  1591. */
  1592. int vdb, vss, hbe, hss;
  1593. if (mon_type == F_MON_SM) /* this doesn't work on SM124 */
  1594. return 1;
  1595. vdb = current_par.VDB;
  1596. vss = current_par.VSS;
  1597. hbe = current_par.HBE;
  1598. hss = current_par.HSS;
  1599. if (blank_mode >= 1) {
  1600. /* disable graphics output (this speeds up the CPU) ... */
  1601. vdb = current_par.VFT + 1;
  1602. /* ... and blank all lines */
  1603. hbe = current_par.HHT + 2;
  1604. }
  1605. /* use VESA suspend modes on VGA monitors */
  1606. if (mon_type == F_MON_VGA) {
  1607. if (blank_mode == 2 || blank_mode == 4)
  1608. vss = current_par.VFT + 1;
  1609. if (blank_mode == 3 || blank_mode == 4)
  1610. hss = current_par.HHT + 2;
  1611. }
  1612. videl.vdb = vdb;
  1613. videl.vss = vss;
  1614. videl.hbe = hbe;
  1615. videl.hss = hss;
  1616. return 0;
  1617. }
  1618. static int falcon_detect(void)
  1619. {
  1620. struct atafb_par par;
  1621. unsigned char fhw;
  1622. /* Determine connected monitor and set monitor parameters */
  1623. fhw = *(unsigned char *)0xffff8006;
  1624. mon_type = fhw >> 6 & 0x3;
  1625. /* bit 1 of fhw: 1=32 bit ram bus, 0=16 bit */
  1626. f030_bus_width = fhw << 6 & 0x80;
  1627. switch (mon_type) {
  1628. case F_MON_SM:
  1629. fb_info.monspecs.vfmin = 70;
  1630. fb_info.monspecs.vfmax = 72;
  1631. fb_info.monspecs.hfmin = 35713;
  1632. fb_info.monspecs.hfmax = 35715;
  1633. break;
  1634. case F_MON_SC:
  1635. case F_MON_TV:
  1636. /* PAL...NTSC */
  1637. fb_info.monspecs.vfmin = 49; /* not 50, since TOS defaults to 49.9x Hz */
  1638. fb_info.monspecs.vfmax = 60;
  1639. fb_info.monspecs.hfmin = 15620;
  1640. fb_info.monspecs.hfmax = 15755;
  1641. break;
  1642. }
  1643. /* initialize hsync-len */
  1644. f25.hsync = h_syncs[mon_type] / f25.t;
  1645. f32.hsync = h_syncs[mon_type] / f32.t;
  1646. if (fext.t)
  1647. fext.hsync = h_syncs[mon_type] / fext.t;
  1648. falcon_get_par(&par);
  1649. falcon_encode_var(&atafb_predefined[0], &par);
  1650. /* Detected mode is always the "autodetect" slot */
  1651. return 1;
  1652. }
  1653. #endif /* ATAFB_FALCON */
  1654. /* ------------------- ST(E) specific functions ---------------------- */
  1655. #ifdef ATAFB_STE
  1656. static int stste_encode_fix(struct fb_fix_screeninfo *fix,
  1657. struct atafb_par *par)
  1658. {
  1659. int mode;
  1660. strcpy(fix->id, "Atari Builtin");
  1661. fix->smem_start = (unsigned long)real_screen_base;
  1662. fix->smem_len = screen_len;
  1663. fix->type = FB_TYPE_INTERLEAVED_PLANES;
  1664. fix->type_aux = 2;
  1665. fix->visual = FB_VISUAL_PSEUDOCOLOR;
  1666. mode = par->hw.st.mode & 3;
  1667. if (mode == ST_HIGH) {
  1668. fix->type = FB_TYPE_PACKED_PIXELS;
  1669. fix->type_aux = 0;
  1670. fix->visual = FB_VISUAL_MONO10;
  1671. }
  1672. if (ATARIHW_PRESENT(EXTD_SHIFTER)) {
  1673. fix->xpanstep = 16;
  1674. fix->ypanstep = 1;
  1675. } else {
  1676. fix->xpanstep = 0;
  1677. fix->ypanstep = 0;
  1678. }
  1679. fix->ywrapstep = 0;
  1680. fix->line_length = par->next_line;
  1681. fix->accel = FB_ACCEL_ATARIBLITT;
  1682. return 0;
  1683. }
  1684. static int stste_decode_var(struct fb_var_screeninfo *var,
  1685. struct atafb_par *par)
  1686. {
  1687. int xres = var->xres;
  1688. int yres = var->yres;
  1689. int bpp = var->bits_per_pixel;
  1690. int linelen;
  1691. int yres_virtual = var->yres_virtual;
  1692. if (mono_moni) {
  1693. if (bpp > 1 || xres > sttt_xres || yres > st_yres)
  1694. return -EINVAL;
  1695. par->hw.st.mode = ST_HIGH;
  1696. xres = sttt_xres;
  1697. yres = st_yres;
  1698. bpp = 1;
  1699. } else {
  1700. if (bpp > 4 || xres > sttt_xres || yres > st_yres)
  1701. return -EINVAL;
  1702. if (bpp > 2) {
  1703. if (xres > sttt_xres / 2 || yres > st_yres / 2)
  1704. return -EINVAL;
  1705. par->hw.st.mode = ST_LOW;
  1706. xres = sttt_xres / 2;
  1707. yres = st_yres / 2;
  1708. bpp = 4;
  1709. } else if (bpp > 1) {
  1710. if (xres > sttt_xres || yres > st_yres / 2)
  1711. return -EINVAL;
  1712. par->hw.st.mode = ST_MID;
  1713. xres = sttt_xres;
  1714. yres = st_yres / 2;
  1715. bpp = 2;
  1716. } else
  1717. return -EINVAL;
  1718. }
  1719. if (yres_virtual <= 0)
  1720. yres_virtual = 0;
  1721. else if (yres_virtual < yres)
  1722. yres_virtual = yres;
  1723. if (var->sync & FB_SYNC_EXT)
  1724. par->hw.st.sync = (par->hw.st.sync & ~1) | 1;
  1725. else
  1726. par->hw.st.sync = (par->hw.st.sync & ~1);
  1727. linelen = xres * bpp / 8;
  1728. if (yres_virtual * linelen > screen_len && screen_len)
  1729. return -EINVAL;
  1730. if (yres * linelen > screen_len && screen_len)
  1731. return -EINVAL;
  1732. if (var->yoffset + yres > yres_virtual && yres_virtual)
  1733. return -EINVAL;
  1734. par->yres_virtual = yres_virtual;
  1735. par->screen_base = screen_base + var->yoffset * linelen;
  1736. par->next_line = linelen;
  1737. return 0;
  1738. }
  1739. static int stste_encode_var(struct fb_var_screeninfo *var,
  1740. struct atafb_par *par)
  1741. {
  1742. int linelen;
  1743. memset(var, 0, sizeof(struct fb_var_screeninfo));
  1744. var->red.offset = 0;
  1745. var->red.length = ATARIHW_PRESENT(EXTD_SHIFTER) ? 4 : 3;
  1746. var->red.msb_right = 0;
  1747. var->grayscale = 0;
  1748. var->pixclock = 31041;
  1749. var->left_margin = 120; /* these are incorrect */
  1750. var->right_margin = 100;
  1751. var->upper_margin = 8;
  1752. var->lower_margin = 16;
  1753. var->hsync_len = 140;
  1754. var->vsync_len = 30;
  1755. var->height = -1;
  1756. var->width = -1;
  1757. if (!(par->hw.st.sync & 1))
  1758. var->sync = 0;
  1759. else
  1760. var->sync = FB_SYNC_EXT;
  1761. switch (par->hw.st.mode & 3) {
  1762. case ST_LOW:
  1763. var->xres = sttt_xres / 2;
  1764. var->yres = st_yres / 2;
  1765. var->bits_per_pixel = 4;
  1766. break;
  1767. case ST_MID:
  1768. var->xres = sttt_xres;
  1769. var->yres = st_yres / 2;
  1770. var->bits_per_pixel = 2;
  1771. break;
  1772. case ST_HIGH:
  1773. var->xres = sttt_xres;
  1774. var->yres = st_yres;
  1775. var->bits_per_pixel = 1;
  1776. break;
  1777. }
  1778. var->blue = var->green = var->red;
  1779. var->transp.offset = 0;
  1780. var->transp.length = 0;
  1781. var->transp.msb_right = 0;
  1782. var->xres_virtual = sttt_xres_virtual;
  1783. linelen = var->xres_virtual * var->bits_per_pixel / 8;
  1784. ovsc_addlen = linelen * (sttt_yres_virtual - st_yres);
  1785. if (!use_hwscroll)
  1786. var->yres_virtual = var->yres;
  1787. else if (screen_len) {
  1788. if (par->yres_virtual)
  1789. var->yres_virtual = par->yres_virtual;
  1790. else
  1791. /* yres_virtual == 0 means use maximum */
  1792. var->yres_virtual = screen_len / linelen;
  1793. } else {
  1794. if (hwscroll < 0)
  1795. var->yres_virtual = 2 * var->yres;
  1796. else
  1797. var->yres_virtual = var->yres + hwscroll * 16;
  1798. }
  1799. var->xoffset = 0;
  1800. if (screen_base)
  1801. var->yoffset = (par->screen_base - screen_base) / linelen;
  1802. else
  1803. var->yoffset = 0;
  1804. var->nonstd = 0;
  1805. var->activate = 0;
  1806. var->vmode = FB_VMODE_NONINTERLACED;
  1807. return 0;
  1808. }
  1809. static void stste_get_par(struct atafb_par *par)
  1810. {
  1811. unsigned long addr;
  1812. par->hw.st.mode = shifter_tt.st_shiftmode;
  1813. par->hw.st.sync = shifter.syncmode;
  1814. addr = ((shifter.bas_hi & 0xff) << 16) |
  1815. ((shifter.bas_md & 0xff) << 8);
  1816. if (ATARIHW_PRESENT(EXTD_SHIFTER))
  1817. addr |= (shifter.bas_lo & 0xff);
  1818. par->screen_base = phys_to_virt(addr);
  1819. }
  1820. static void stste_set_par(struct atafb_par *par)
  1821. {
  1822. shifter_tt.st_shiftmode = par->hw.st.mode;
  1823. shifter.syncmode = par->hw.st.sync;
  1824. /* only set screen_base if really necessary */
  1825. if (current_par.screen_base != par->screen_base)
  1826. fbhw->set_screen_base(par->screen_base);
  1827. }
  1828. static int stste_setcolreg(unsigned int regno, unsigned int red,
  1829. unsigned int green, unsigned int blue,
  1830. unsigned int transp, struct fb_info *info)
  1831. {
  1832. if (regno > 15)
  1833. return 1;
  1834. red >>= 12;
  1835. blue >>= 12;
  1836. green >>= 12;
  1837. if (ATARIHW_PRESENT(EXTD_SHIFTER))
  1838. shifter_tt.color_reg[regno] =
  1839. (((red & 0xe) >> 1) | ((red & 1) << 3) << 8) |
  1840. (((green & 0xe) >> 1) | ((green & 1) << 3) << 4) |
  1841. ((blue & 0xe) >> 1) | ((blue & 1) << 3);
  1842. else
  1843. shifter_tt.color_reg[regno] =
  1844. ((red & 0xe) << 7) |
  1845. ((green & 0xe) << 3) |
  1846. ((blue & 0xe) >> 1);
  1847. return 0;
  1848. }
  1849. static int stste_detect(void)
  1850. {
  1851. struct atafb_par par;
  1852. /* Determine the connected monitor: The DMA sound must be
  1853. * disabled before reading the MFP GPIP, because the Sound
  1854. * Done Signal and the Monochrome Detect are XORed together!
  1855. */
  1856. if (ATARIHW_PRESENT(PCM_8BIT)) {
  1857. tt_dmasnd.ctrl = DMASND_CTRL_OFF;
  1858. udelay(20); /* wait a while for things to settle down */
  1859. }
  1860. mono_moni = (mfp.par_dt_reg & 0x80) == 0;
  1861. stste_get_par(&par);
  1862. stste_encode_var(&atafb_predefined[0], &par);
  1863. if (!ATARIHW_PRESENT(EXTD_SHIFTER))
  1864. use_hwscroll = 0;
  1865. return 1;
  1866. }
  1867. static void stste_set_screen_base(void *s_base)
  1868. {
  1869. unsigned long addr;
  1870. addr = virt_to_phys(s_base);
  1871. /* Setup Screen Memory */
  1872. shifter.bas_hi = (unsigned char)((addr & 0xff0000) >> 16);
  1873. shifter.bas_md = (unsigned char)((addr & 0x00ff00) >> 8);
  1874. if (ATARIHW_PRESENT(EXTD_SHIFTER))
  1875. shifter.bas_lo = (unsigned char)(addr & 0x0000ff);
  1876. }
  1877. #endif /* ATAFB_STE */
  1878. /* Switching the screen size should be done during vsync, otherwise
  1879. * the margins may get messed up. This is a well known problem of
  1880. * the ST's video system.
  1881. *
  1882. * Unfortunately there is hardly any way to find the vsync, as the
  1883. * vertical blank interrupt is no longer in time on machines with
  1884. * overscan type modifications.
  1885. *
  1886. * We can, however, use Timer B to safely detect the black shoulder,
  1887. * but then we've got to guess an appropriate delay to find the vsync.
  1888. * This might not work on every machine.
  1889. *
  1890. * martin_rogge @ ki.maus.de, 8th Aug 1995
  1891. */
  1892. #define LINE_DELAY (mono_moni ? 30 : 70)
  1893. #define SYNC_DELAY (mono_moni ? 1500 : 2000)
  1894. /* SWITCH_ACIA may be used for Falcon (ScreenBlaster III internal!) */
  1895. static void st_ovsc_switch(void)
  1896. {
  1897. unsigned long flags;
  1898. register unsigned char old, new;
  1899. if (!(atari_switches & ATARI_SWITCH_OVSC_MASK))
  1900. return;
  1901. local_irq_save(flags);
  1902. mfp.tim_ct_b = 0x10;
  1903. mfp.active_edge |= 8;
  1904. mfp.tim_ct_b = 0;
  1905. mfp.tim_dt_b = 0xf0;
  1906. mfp.tim_ct_b = 8;
  1907. while (mfp.tim_dt_b > 1) /* TOS does it this way, don't ask why */
  1908. ;
  1909. new = mfp.tim_dt_b;
  1910. do {
  1911. udelay(LINE_DELAY);
  1912. old = new;
  1913. new = mfp.tim_dt_b;
  1914. } while (old != new);
  1915. mfp.tim_ct_b = 0x10;
  1916. udelay(SYNC_DELAY);
  1917. if (atari_switches & ATARI_SWITCH_OVSC_IKBD)
  1918. acia.key_ctrl = ACIA_DIV64 | ACIA_D8N1S | ACIA_RHTID | ACIA_RIE;
  1919. if (atari_switches & ATARI_SWITCH_OVSC_MIDI)
  1920. acia.mid_ctrl = ACIA_DIV16 | ACIA_D8N1S | ACIA_RHTID;
  1921. if (atari_switches & (ATARI_SWITCH_OVSC_SND6|ATARI_SWITCH_OVSC_SND7)) {
  1922. sound_ym.rd_data_reg_sel = 14;
  1923. sound_ym.wd_data = sound_ym.rd_data_reg_sel |
  1924. ((atari_switches & ATARI_SWITCH_OVSC_SND6) ? 0x40:0) |
  1925. ((atari_switches & ATARI_SWITCH_OVSC_SND7) ? 0x80:0);
  1926. }
  1927. local_irq_restore(flags);
  1928. }
  1929. /* ------------------- External Video ---------------------- */
  1930. #ifdef ATAFB_EXT
  1931. static int ext_encode_fix(struct fb_fix_screeninfo *fix, struct atafb_par *par)
  1932. {
  1933. strcpy(fix->id, "Unknown Extern");
  1934. fix->smem_start = (unsigned long)external_addr;
  1935. fix->smem_len = PAGE_ALIGN(external_len);
  1936. if (external_depth == 1) {
  1937. fix->type = FB_TYPE_PACKED_PIXELS;
  1938. /* The letters 'n' and 'i' in the "atavideo=external:" stand
  1939. * for "normal" and "inverted", rsp., in the monochrome case */
  1940. fix->visual =
  1941. (external_pmode == FB_TYPE_INTERLEAVED_PLANES ||
  1942. external_pmode == FB_TYPE_PACKED_PIXELS) ?
  1943. FB_VISUAL_MONO10 : FB_VISUAL_MONO01;
  1944. } else {
  1945. /* Use STATIC if we don't know how to access color registers */
  1946. int visual = external_vgaiobase ?
  1947. FB_VISUAL_PSEUDOCOLOR :
  1948. FB_VISUAL_STATIC_PSEUDOCOLOR;
  1949. switch (external_pmode) {
  1950. case -1: /* truecolor */
  1951. fix->type = FB_TYPE_PACKED_PIXELS;
  1952. fix->visual = FB_VISUAL_TRUECOLOR;
  1953. break;
  1954. case FB_TYPE_PACKED_PIXELS:
  1955. fix->type = FB_TYPE_PACKED_PIXELS;
  1956. fix->visual = visual;
  1957. break;
  1958. case FB_TYPE_PLANES:
  1959. fix->type = FB_TYPE_PLANES;
  1960. fix->visual = visual;
  1961. break;
  1962. case FB_TYPE_INTERLEAVED_PLANES:
  1963. fix->type = FB_TYPE_INTERLEAVED_PLANES;
  1964. fix->type_aux = 2;
  1965. fix->visual = visual;
  1966. break;
  1967. }
  1968. }
  1969. fix->xpanstep = 0;
  1970. fix->ypanstep = 0;
  1971. fix->ywrapstep = 0;
  1972. fix->line_length = par->next_line;
  1973. return 0;
  1974. }
  1975. static int ext_decode_var(struct fb_var_screeninfo *var, struct atafb_par *par)
  1976. {
  1977. struct fb_var_screeninfo *myvar = &atafb_predefined[0];
  1978. if (var->bits_per_pixel > myvar->bits_per_pixel ||
  1979. var->xres > myvar->xres ||
  1980. var->xres_virtual > myvar->xres_virtual ||
  1981. var->yres > myvar->yres ||
  1982. var->xoffset > 0 ||
  1983. var->yoffset > 0)
  1984. return -EINVAL;
  1985. par->next_line = external_xres_virtual * external_depth / 8;
  1986. return 0;
  1987. }
  1988. static int ext_encode_var(struct fb_var_screeninfo *var, struct atafb_par *par)
  1989. {
  1990. memset(var, 0, sizeof(struct fb_var_screeninfo));
  1991. var->red.offset = 0;
  1992. var->red.length = (external_pmode == -1) ? external_depth / 3 :
  1993. (external_vgaiobase ? external_bitspercol : 0);
  1994. var->red.msb_right = 0;
  1995. var->grayscale = 0;
  1996. var->pixclock = 31041;
  1997. var->left_margin = 120; /* these are surely incorrect */
  1998. var->right_margin = 100;
  1999. var->upper_margin = 8;
  2000. var->lower_margin = 16;
  2001. var->hsync_len = 140;
  2002. var->vsync_len = 30;
  2003. var->height = -1;
  2004. var->width = -1;
  2005. var->sync = 0;
  2006. var->xres = external_xres;
  2007. var->yres = external_yres;
  2008. var->xres_virtual = external_xres_virtual;
  2009. var->bits_per_pixel = external_depth;
  2010. var->blue = var->green = var->red;
  2011. var->transp.offset = 0;
  2012. var->transp.length = 0;
  2013. var->transp.msb_right = 0;
  2014. var->yres_virtual = var->yres;
  2015. var->xoffset = 0;
  2016. var->yoffset = 0;
  2017. var->nonstd = 0;
  2018. var->activate = 0;
  2019. var->vmode = FB_VMODE_NONINTERLACED;
  2020. return 0;
  2021. }
  2022. static void ext_get_par(struct atafb_par *par)
  2023. {
  2024. par->screen_base = external_addr;
  2025. }
  2026. static void ext_set_par(struct atafb_par *par)
  2027. {
  2028. }
  2029. #define OUTB(port,val) \
  2030. *((unsigned volatile char *) ((port)+external_vgaiobase)) = (val)
  2031. #define INB(port) \
  2032. (*((unsigned volatile char *) ((port)+external_vgaiobase)))
  2033. #define DACDelay \
  2034. do { \
  2035. unsigned char tmp = INB(0x3da); \
  2036. tmp = INB(0x3da); \
  2037. } while (0)
  2038. static int ext_setcolreg(unsigned int regno, unsigned int red,
  2039. unsigned int green, unsigned int blue,
  2040. unsigned int transp, struct fb_info *info)
  2041. {
  2042. unsigned char colmask = (1 << external_bitspercol) - 1;
  2043. if (!external_vgaiobase)
  2044. return 1;
  2045. switch (external_card_type) {
  2046. case IS_VGA:
  2047. OUTB(0x3c8, regno);
  2048. DACDelay;
  2049. OUTB(0x3c9, red & colmask);
  2050. DACDelay;
  2051. OUTB(0x3c9, green & colmask);
  2052. DACDelay;
  2053. OUTB(0x3c9, blue & colmask);
  2054. DACDelay;
  2055. return 0;
  2056. case IS_MV300:
  2057. OUTB((MV300_reg[regno] << 2) + 1, red);
  2058. OUTB((MV300_reg[regno] << 2) + 1, green);
  2059. OUTB((MV300_reg[regno] << 2) + 1, blue);
  2060. return 0;
  2061. default:
  2062. return 1;
  2063. }
  2064. }
  2065. static int ext_detect(void)
  2066. {
  2067. struct fb_var_screeninfo *myvar = &atafb_predefined[0];
  2068. struct atafb_par dummy_par;
  2069. myvar->xres = external_xres;
  2070. myvar->xres_virtual = external_xres_virtual;
  2071. myvar->yres = external_yres;
  2072. myvar->bits_per_pixel = external_depth;
  2073. ext_encode_var(myvar, &dummy_par);
  2074. return 1;
  2075. }
  2076. #endif /* ATAFB_EXT */
  2077. /* ------ This is the same for most hardware types -------- */
  2078. static void set_screen_base(void *s_base)
  2079. {
  2080. unsigned long addr;
  2081. addr = virt_to_phys(s_base);
  2082. /* Setup Screen Memory */
  2083. shifter.bas_hi = (unsigned char)((addr & 0xff0000) >> 16);
  2084. shifter.bas_md = (unsigned char)((addr & 0x00ff00) >> 8);
  2085. shifter.bas_lo = (unsigned char)(addr & 0x0000ff);
  2086. }
  2087. static int pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  2088. {
  2089. struct atafb_par *par = (struct atafb_par *)info->par;
  2090. if (!fbhw->set_screen_base ||
  2091. (!ATARIHW_PRESENT(EXTD_SHIFTER) && var->xoffset))
  2092. return -EINVAL;
  2093. var->xoffset = up(var->xoffset, 16);
  2094. par->screen_base = screen_base +
  2095. (var->yoffset * info->var.xres_virtual + var->xoffset)
  2096. * info->var.bits_per_pixel / 8;
  2097. fbhw->set_screen_base(par->screen_base);
  2098. return 0;
  2099. }
  2100. /* ------------ Interfaces to hardware functions ------------ */
  2101. #ifdef ATAFB_TT
  2102. static struct fb_hwswitch tt_switch = {
  2103. .detect = tt_detect,
  2104. .encode_fix = tt_encode_fix,
  2105. .decode_var = tt_decode_var,
  2106. .encode_var = tt_encode_var,
  2107. .get_par = tt_get_par,
  2108. .set_par = tt_set_par,
  2109. .set_screen_base = set_screen_base,
  2110. .pan_display = pan_display,
  2111. };
  2112. #endif
  2113. #ifdef ATAFB_FALCON
  2114. static struct fb_hwswitch falcon_switch = {
  2115. .detect = falcon_detect,
  2116. .encode_fix = falcon_encode_fix,
  2117. .decode_var = falcon_decode_var,
  2118. .encode_var = falcon_encode_var,
  2119. .get_par = falcon_get_par,
  2120. .set_par = falcon_set_par,
  2121. .set_screen_base = set_screen_base,
  2122. .blank = falcon_blank,
  2123. .pan_display = falcon_pan_display,
  2124. };
  2125. #endif
  2126. #ifdef ATAFB_STE
  2127. static struct fb_hwswitch st_switch = {
  2128. .detect = stste_detect,
  2129. .encode_fix = stste_encode_fix,
  2130. .decode_var = stste_decode_var,
  2131. .encode_var = stste_encode_var,
  2132. .get_par = stste_get_par,
  2133. .set_par = stste_set_par,
  2134. .set_screen_base = stste_set_screen_base,
  2135. .pan_display = pan_display
  2136. };
  2137. #endif
  2138. #ifdef ATAFB_EXT
  2139. static struct fb_hwswitch ext_switch = {
  2140. .detect = ext_detect,
  2141. .encode_fix = ext_encode_fix,
  2142. .decode_var = ext_decode_var,
  2143. .encode_var = ext_encode_var,
  2144. .get_par = ext_get_par,
  2145. .set_par = ext_set_par,
  2146. };
  2147. #endif
  2148. static void ata_get_par(struct atafb_par *par)
  2149. {
  2150. if (current_par_valid)
  2151. *par = current_par;
  2152. else
  2153. fbhw->get_par(par);
  2154. }
  2155. static void ata_set_par(struct atafb_par *par)
  2156. {
  2157. fbhw->set_par(par);
  2158. current_par = *par;
  2159. current_par_valid = 1;
  2160. }
  2161. /* =========================================================== */
  2162. /* ============== Hardware Independent Functions ============= */
  2163. /* =========================================================== */
  2164. /* used for hardware scrolling */
  2165. static int do_fb_set_var(struct fb_var_screeninfo *var, int isactive)
  2166. {
  2167. int err, activate;
  2168. struct atafb_par par;
  2169. err = fbhw->decode_var(var, &par);
  2170. if (err)
  2171. return err;
  2172. activate = var->activate;
  2173. if (((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) && isactive)
  2174. ata_set_par(&par);
  2175. fbhw->encode_var(var, &par);
  2176. var->activate = activate;
  2177. return 0;
  2178. }
  2179. static int atafb_get_fix(struct fb_fix_screeninfo *fix, struct fb_info *info)
  2180. {
  2181. struct atafb_par par;
  2182. int err;
  2183. // Get fix directly (case con == -1 before)??
  2184. err = fbhw->decode_var(&info->var, &par);
  2185. if (err)
  2186. return err;
  2187. memset(fix, 0, sizeof(struct fb_fix_screeninfo));
  2188. return fbhw->encode_fix(fix, &par);
  2189. }
  2190. static int atafb_get_var(struct fb_var_screeninfo *var, struct fb_info *info)
  2191. {
  2192. struct atafb_par par;
  2193. ata_get_par(&par);
  2194. fbhw->encode_var(var, &par);
  2195. return 0;
  2196. }
  2197. // No longer called by fbcon!
  2198. // Still called by set_var internally
  2199. static void atafb_set_disp(struct fb_info *info)
  2200. {
  2201. atafb_get_var(&info->var, info);
  2202. atafb_get_fix(&info->fix, info);
  2203. info->screen_base = (void *)info->fix.smem_start;
  2204. }
  2205. static int atafb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  2206. u_int transp, struct fb_info *info)
  2207. {
  2208. red >>= 8;
  2209. green >>= 8;
  2210. blue >>= 8;
  2211. return info->fbops->fb_setcolreg(regno, red, green, blue, transp, info);
  2212. }
  2213. static int
  2214. atafb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  2215. {
  2216. int xoffset = var->xoffset;
  2217. int yoffset = var->yoffset;
  2218. int err;
  2219. if (var->vmode & FB_VMODE_YWRAP) {
  2220. if (yoffset < 0 || yoffset >= info->var.yres_virtual || xoffset)
  2221. return -EINVAL;
  2222. } else {
  2223. if (xoffset + info->var.xres > info->var.xres_virtual ||
  2224. yoffset + info->var.yres > info->var.yres_virtual)
  2225. return -EINVAL;
  2226. }
  2227. if (fbhw->pan_display) {
  2228. err = fbhw->pan_display(var, info);
  2229. if (err)
  2230. return err;
  2231. } else
  2232. return -EINVAL;
  2233. info->var.xoffset = xoffset;
  2234. info->var.yoffset = yoffset;
  2235. if (var->vmode & FB_VMODE_YWRAP)
  2236. info->var.vmode |= FB_VMODE_YWRAP;
  2237. else
  2238. info->var.vmode &= ~FB_VMODE_YWRAP;
  2239. return 0;
  2240. }
  2241. /*
  2242. * generic drawing routines; imageblit needs updating for image depth > 1
  2243. */
  2244. #if BITS_PER_LONG == 32
  2245. #define BYTES_PER_LONG 4
  2246. #define SHIFT_PER_LONG 5
  2247. #elif BITS_PER_LONG == 64
  2248. #define BYTES_PER_LONG 8
  2249. #define SHIFT_PER_LONG 6
  2250. #else
  2251. #define Please update me
  2252. #endif
  2253. static void atafb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  2254. {
  2255. struct atafb_par *par = (struct atafb_par *)info->par;
  2256. int x2, y2;
  2257. u32 width, height;
  2258. if (!rect->width || !rect->height)
  2259. return;
  2260. #ifdef ATAFB_FALCON
  2261. if (info->var.bits_per_pixel == 16) {
  2262. cfb_fillrect(info, rect);
  2263. return;
  2264. }
  2265. #endif
  2266. /*
  2267. * We could use hardware clipping but on many cards you get around
  2268. * hardware clipping by writing to framebuffer directly.
  2269. * */
  2270. x2 = rect->dx + rect->width;
  2271. y2 = rect->dy + rect->height;
  2272. x2 = x2 < info->var.xres_virtual ? x2 : info->var.xres_virtual;
  2273. y2 = y2 < info->var.yres_virtual ? y2 : info->var.yres_virtual;
  2274. width = x2 - rect->dx;
  2275. height = y2 - rect->dy;
  2276. if (info->var.bits_per_pixel == 1)
  2277. atafb_mfb_fillrect(info, par->next_line, rect->color,
  2278. rect->dy, rect->dx, height, width);
  2279. else if (info->var.bits_per_pixel == 2)
  2280. atafb_iplan2p2_fillrect(info, par->next_line, rect->color,
  2281. rect->dy, rect->dx, height, width);
  2282. else if (info->var.bits_per_pixel == 4)
  2283. atafb_iplan2p4_fillrect(info, par->next_line, rect->color,
  2284. rect->dy, rect->dx, height, width);
  2285. else
  2286. atafb_iplan2p8_fillrect(info, par->next_line, rect->color,
  2287. rect->dy, rect->dx, height, width);
  2288. return;
  2289. }
  2290. static void atafb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
  2291. {
  2292. struct atafb_par *par = (struct atafb_par *)info->par;
  2293. int x2, y2;
  2294. u32 dx, dy, sx, sy, width, height;
  2295. int rev_copy = 0;
  2296. #ifdef ATAFB_FALCON
  2297. if (info->var.bits_per_pixel == 16) {
  2298. cfb_copyarea(info, area);
  2299. return;
  2300. }
  2301. #endif
  2302. /* clip the destination */
  2303. x2 = area->dx + area->width;
  2304. y2 = area->dy + area->height;
  2305. dx = area->dx > 0 ? area->dx : 0;
  2306. dy = area->dy > 0 ? area->dy : 0;
  2307. x2 = x2 < info->var.xres_virtual ? x2 : info->var.xres_virtual;
  2308. y2 = y2 < info->var.yres_virtual ? y2 : info->var.yres_virtual;
  2309. width = x2 - dx;
  2310. height = y2 - dy;
  2311. if (area->sx + dx < area->dx || area->sy + dy < area->dy)
  2312. return;
  2313. /* update sx,sy */
  2314. sx = area->sx + (dx - area->dx);
  2315. sy = area->sy + (dy - area->dy);
  2316. /* the source must be completely inside the virtual screen */
  2317. if (sx + width > info->var.xres_virtual ||
  2318. sy + height > info->var.yres_virtual)
  2319. return;
  2320. if (dy > sy || (dy == sy && dx > sx)) {
  2321. dy += height;
  2322. sy += height;
  2323. rev_copy = 1;
  2324. }
  2325. if (info->var.bits_per_pixel == 1)
  2326. atafb_mfb_copyarea(info, par->next_line, sy, sx, dy, dx, height, width);
  2327. else if (info->var.bits_per_pixel == 2)
  2328. atafb_iplan2p2_copyarea(info, par->next_line, sy, sx, dy, dx, height, width);
  2329. else if (info->var.bits_per_pixel == 4)
  2330. atafb_iplan2p4_copyarea(info, par->next_line, sy, sx, dy, dx, height, width);
  2331. else
  2332. atafb_iplan2p8_copyarea(info, par->next_line, sy, sx, dy, dx, height, width);
  2333. return;
  2334. }
  2335. static void atafb_imageblit(struct fb_info *info, const struct fb_image *image)
  2336. {
  2337. struct atafb_par *par = (struct atafb_par *)info->par;
  2338. int x2, y2;
  2339. unsigned long *dst;
  2340. int dst_idx;
  2341. const char *src;
  2342. u32 dx, dy, width, height, pitch;
  2343. #ifdef ATAFB_FALCON
  2344. if (info->var.bits_per_pixel == 16) {
  2345. cfb_imageblit(info, image);
  2346. return;
  2347. }
  2348. #endif
  2349. /*
  2350. * We could use hardware clipping but on many cards you get around
  2351. * hardware clipping by writing to framebuffer directly like we are
  2352. * doing here.
  2353. */
  2354. x2 = image->dx + image->width;
  2355. y2 = image->dy + image->height;
  2356. dx = image->dx;
  2357. dy = image->dy;
  2358. x2 = x2 < info->var.xres_virtual ? x2 : info->var.xres_virtual;
  2359. y2 = y2 < info->var.yres_virtual ? y2 : info->var.yres_virtual;
  2360. width = x2 - dx;
  2361. height = y2 - dy;
  2362. if (image->depth == 1) {
  2363. // used for font data
  2364. dst = (unsigned long *)
  2365. ((unsigned long)info->screen_base & ~(BYTES_PER_LONG - 1));
  2366. dst_idx = ((unsigned long)info->screen_base & (BYTES_PER_LONG - 1)) * 8;
  2367. dst_idx += dy * par->next_line * 8 + dx;
  2368. src = image->data;
  2369. pitch = (image->width + 7) / 8;
  2370. while (height--) {
  2371. if (info->var.bits_per_pixel == 1)
  2372. atafb_mfb_linefill(info, par->next_line,
  2373. dy, dx, width, src,
  2374. image->bg_color, image->fg_color);
  2375. else if (info->var.bits_per_pixel == 2)
  2376. atafb_iplan2p2_linefill(info, par->next_line,
  2377. dy, dx, width, src,
  2378. image->bg_color, image->fg_color);
  2379. else if (info->var.bits_per_pixel == 4)
  2380. atafb_iplan2p4_linefill(info, par->next_line,
  2381. dy, dx, width, src,
  2382. image->bg_color, image->fg_color);
  2383. else
  2384. atafb_iplan2p8_linefill(info, par->next_line,
  2385. dy, dx, width, src,
  2386. image->bg_color, image->fg_color);
  2387. dy++;
  2388. src += pitch;
  2389. }
  2390. } else {
  2391. // only used for logo; broken
  2392. c2p(info->screen_base, image->data, dx, dy, width, height,
  2393. par->next_line, par->next_plane, image->width,
  2394. info->var.bits_per_pixel);
  2395. }
  2396. }
  2397. static int
  2398. atafb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
  2399. {
  2400. switch (cmd) {
  2401. #ifdef FBCMD_GET_CURRENTPAR
  2402. case FBCMD_GET_CURRENTPAR:
  2403. if (copy_to_user((void *)arg, (void *)&current_par,
  2404. sizeof(struct atafb_par)))
  2405. return -EFAULT;
  2406. return 0;
  2407. #endif
  2408. #ifdef FBCMD_SET_CURRENTPAR
  2409. case FBCMD_SET_CURRENTPAR:
  2410. if (copy_from_user((void *)&current_par, (void *)arg,
  2411. sizeof(struct atafb_par)))
  2412. return -EFAULT;
  2413. ata_set_par(&current_par);
  2414. return 0;
  2415. #endif
  2416. }
  2417. return -EINVAL;
  2418. }
  2419. /* (un)blank/poweroff
  2420. * 0 = unblank
  2421. * 1 = blank
  2422. * 2 = suspend vsync
  2423. * 3 = suspend hsync
  2424. * 4 = off
  2425. */
  2426. static int atafb_blank(int blank, struct fb_info *info)
  2427. {
  2428. unsigned short black[16];
  2429. struct fb_cmap cmap;
  2430. if (fbhw->blank && !fbhw->blank(blank))
  2431. return 1;
  2432. if (blank) {
  2433. memset(black, 0, 16 * sizeof(unsigned short));
  2434. cmap.red = black;
  2435. cmap.green = black;
  2436. cmap.blue = black;
  2437. cmap.transp = NULL;
  2438. cmap.start = 0;
  2439. cmap.len = 16;
  2440. fb_set_cmap(&cmap, info);
  2441. }
  2442. #if 0
  2443. else
  2444. do_install_cmap(info);
  2445. #endif
  2446. return 0;
  2447. }
  2448. /*
  2449. * New fbcon interface ...
  2450. */
  2451. /* check var by decoding var into hw par, rounding if necessary,
  2452. * then encoding hw par back into new, validated var */
  2453. static int atafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  2454. {
  2455. int err;
  2456. struct atafb_par par;
  2457. /* Validate wanted screen parameters */
  2458. // if ((err = ata_decode_var(var, &par)))
  2459. err = fbhw->decode_var(var, &par);
  2460. if (err)
  2461. return err;
  2462. /* Encode (possibly rounded) screen parameters */
  2463. fbhw->encode_var(var, &par);
  2464. return 0;
  2465. }
  2466. /* actually set hw par by decoding var, then setting hardware from
  2467. * hw par just decoded */
  2468. static int atafb_set_par(struct fb_info *info)
  2469. {
  2470. struct atafb_par *par = (struct atafb_par *)info->par;
  2471. /* Decode wanted screen parameters */
  2472. fbhw->decode_var(&info->var, par);
  2473. fbhw->encode_fix(&info->fix, par);
  2474. /* Set new videomode */
  2475. ata_set_par(par);
  2476. return 0;
  2477. }
  2478. static struct fb_ops atafb_ops = {
  2479. .owner = THIS_MODULE,
  2480. .fb_check_var = atafb_check_var,
  2481. .fb_set_par = atafb_set_par,
  2482. .fb_setcolreg = atafb_setcolreg,
  2483. .fb_blank = atafb_blank,
  2484. .fb_pan_display = atafb_pan_display,
  2485. .fb_fillrect = atafb_fillrect,
  2486. .fb_copyarea = atafb_copyarea,
  2487. .fb_imageblit = atafb_imageblit,
  2488. .fb_ioctl = atafb_ioctl,
  2489. };
  2490. static void check_default_par(int detected_mode)
  2491. {
  2492. char default_name[10];
  2493. int i;
  2494. struct fb_var_screeninfo var;
  2495. unsigned long min_mem;
  2496. /* First try the user supplied mode */
  2497. if (default_par) {
  2498. var = atafb_predefined[default_par - 1];
  2499. var.activate = FB_ACTIVATE_TEST;
  2500. if (do_fb_set_var(&var, 1))
  2501. default_par = 0; /* failed */
  2502. }
  2503. /* Next is the autodetected one */
  2504. if (!default_par) {
  2505. var = atafb_predefined[detected_mode - 1]; /* autodetect */
  2506. var.activate = FB_ACTIVATE_TEST;
  2507. if (!do_fb_set_var(&var, 1))
  2508. default_par = detected_mode;
  2509. }
  2510. /* If that also failed, try some default modes... */
  2511. if (!default_par) {
  2512. /* try default1, default2... */
  2513. for (i = 1; i < 10; i++) {
  2514. sprintf(default_name,"default%d", i);
  2515. default_par = get_video_mode(default_name);
  2516. if (!default_par)
  2517. panic("can't set default video mode");
  2518. var = atafb_predefined[default_par - 1];
  2519. var.activate = FB_ACTIVATE_TEST;
  2520. if (!do_fb_set_var(&var,1))
  2521. break; /* ok */
  2522. }
  2523. }
  2524. min_mem = var.xres_virtual * var.yres_virtual * var.bits_per_pixel / 8;
  2525. if (default_mem_req < min_mem)
  2526. default_mem_req = min_mem;
  2527. }
  2528. #ifdef ATAFB_EXT
  2529. static void __init atafb_setup_ext(char *spec)
  2530. {
  2531. int xres, xres_virtual, yres, depth, planes;
  2532. unsigned long addr, len;
  2533. char *p;
  2534. /* Format is: <xres>;<yres>;<depth>;<plane organ.>;
  2535. * <screen mem addr>
  2536. * [;<screen mem length>[;<vgaiobase>[;<bits-per-col>[;<colorreg-type>
  2537. * [;<xres-virtual>]]]]]
  2538. *
  2539. * 09/23/97 Juergen
  2540. * <xres_virtual>: hardware's x-resolution (f.e. ProMST)
  2541. *
  2542. * Even xres_virtual is available, we neither support panning nor hw-scrolling!
  2543. */
  2544. p = strsep(&spec, ";");
  2545. if (!p || !*p)
  2546. return;
  2547. xres_virtual = xres = simple_strtoul(p, NULL, 10);
  2548. if (xres <= 0)
  2549. return;
  2550. p = strsep(&spec, ";");
  2551. if (!p || !*p)
  2552. return;
  2553. yres = simple_strtoul(p, NULL, 10);
  2554. if (yres <= 0)
  2555. return;
  2556. p = strsep(&spec, ";");
  2557. if (!p || !*p)
  2558. return;
  2559. depth = simple_strtoul(p, NULL, 10);
  2560. if (depth != 1 && depth != 2 && depth != 4 && depth != 8 &&
  2561. depth != 16 && depth != 24)
  2562. return;
  2563. p = strsep(&spec, ";");
  2564. if (!p || !*p)
  2565. return;
  2566. if (*p == 'i')
  2567. planes = FB_TYPE_INTERLEAVED_PLANES;
  2568. else if (*p == 'p')
  2569. planes = FB_TYPE_PACKED_PIXELS;
  2570. else if (*p == 'n')
  2571. planes = FB_TYPE_PLANES;
  2572. else if (*p == 't')
  2573. planes = -1; /* true color */
  2574. else
  2575. return;
  2576. p = strsep(&spec, ";");
  2577. if (!p || !*p)
  2578. return;
  2579. addr = simple_strtoul(p, NULL, 0);
  2580. p = strsep(&spec, ";");
  2581. if (!p || !*p)
  2582. len = xres * yres * depth / 8;
  2583. else
  2584. len = simple_strtoul(p, NULL, 0);
  2585. p = strsep(&spec, ";");
  2586. if (p && *p)
  2587. external_vgaiobase = simple_strtoul(p, NULL, 0);
  2588. p = strsep(&spec, ";");
  2589. if (p && *p) {
  2590. external_bitspercol = simple_strtoul(p, NULL, 0);
  2591. if (external_bitspercol > 8)
  2592. external_bitspercol = 8;
  2593. else if (external_bitspercol < 1)
  2594. external_bitspercol = 1;
  2595. }
  2596. p = strsep(&spec, ";");
  2597. if (p && *p) {
  2598. if (!strcmp(p, "vga"))
  2599. external_card_type = IS_VGA;
  2600. if (!strcmp(p, "mv300"))
  2601. external_card_type = IS_MV300;
  2602. }
  2603. p = strsep(&spec, ";");
  2604. if (p && *p) {
  2605. xres_virtual = simple_strtoul(p, NULL, 10);
  2606. if (xres_virtual < xres)
  2607. xres_virtual = xres;
  2608. if (xres_virtual * yres * depth / 8 > len)
  2609. len = xres_virtual * yres * depth / 8;
  2610. }
  2611. external_xres = xres;
  2612. external_xres_virtual = xres_virtual;
  2613. external_yres = yres;
  2614. external_depth = depth;
  2615. external_pmode = planes;
  2616. external_addr = (void *)addr;
  2617. external_len = len;
  2618. if (external_card_type == IS_MV300) {
  2619. switch (external_depth) {
  2620. case 1:
  2621. MV300_reg = MV300_reg_1bit;
  2622. break;
  2623. case 4:
  2624. MV300_reg = MV300_reg_4bit;
  2625. break;
  2626. case 8:
  2627. MV300_reg = MV300_reg_8bit;
  2628. break;
  2629. }
  2630. }
  2631. }
  2632. #endif /* ATAFB_EXT */
  2633. static void __init atafb_setup_int(char *spec)
  2634. {
  2635. /* Format to config extended internal video hardware like OverScan:
  2636. * "internal:<xres>;<yres>;<xres_max>;<yres_max>;<offset>"
  2637. * Explanation:
  2638. * <xres>: x-resolution
  2639. * <yres>: y-resolution
  2640. * The following are only needed if you have an overscan which
  2641. * needs a black border:
  2642. * <xres_max>: max. length of a line in pixels your OverScan hardware would allow
  2643. * <yres_max>: max. number of lines your OverScan hardware would allow
  2644. * <offset>: Offset from physical beginning to visible beginning
  2645. * of screen in bytes
  2646. */
  2647. int xres;
  2648. char *p;
  2649. if (!(p = strsep(&spec, ";")) || !*p)
  2650. return;
  2651. xres = simple_strtoul(p, NULL, 10);
  2652. if (!(p = strsep(&spec, ";")) || !*p)
  2653. return;
  2654. sttt_xres = xres;
  2655. tt_yres = st_yres = simple_strtoul(p, NULL, 10);
  2656. if ((p = strsep(&spec, ";")) && *p)
  2657. sttt_xres_virtual = simple_strtoul(p, NULL, 10);
  2658. if ((p = strsep(&spec, ";")) && *p)
  2659. sttt_yres_virtual = simple_strtoul(p, NULL, 0);
  2660. if ((p = strsep(&spec, ";")) && *p)
  2661. ovsc_offset = simple_strtoul(p, NULL, 0);
  2662. if (ovsc_offset || (sttt_yres_virtual != st_yres))
  2663. use_hwscroll = 0;
  2664. }
  2665. #ifdef ATAFB_FALCON
  2666. static void __init atafb_setup_mcap(char *spec)
  2667. {
  2668. char *p;
  2669. int vmin, vmax, hmin, hmax;
  2670. /* Format for monitor capabilities is: <Vmin>;<Vmax>;<Hmin>;<Hmax>
  2671. * <V*> vertical freq. in Hz
  2672. * <H*> horizontal freq. in kHz
  2673. */
  2674. if (!(p = strsep(&spec, ";")) || !*p)
  2675. return;
  2676. vmin = simple_strtoul(p, NULL, 10);
  2677. if (vmin <= 0)
  2678. return;
  2679. if (!(p = strsep(&spec, ";")) || !*p)
  2680. return;
  2681. vmax = simple_strtoul(p, NULL, 10);
  2682. if (vmax <= 0 || vmax <= vmin)
  2683. return;
  2684. if (!(p = strsep(&spec, ";")) || !*p)
  2685. return;
  2686. hmin = 1000 * simple_strtoul(p, NULL, 10);
  2687. if (hmin <= 0)
  2688. return;
  2689. if (!(p = strsep(&spec, "")) || !*p)
  2690. return;
  2691. hmax = 1000 * simple_strtoul(p, NULL, 10);
  2692. if (hmax <= 0 || hmax <= hmin)
  2693. return;
  2694. fb_info.monspecs.vfmin = vmin;
  2695. fb_info.monspecs.vfmax = vmax;
  2696. fb_info.monspecs.hfmin = hmin;
  2697. fb_info.monspecs.hfmax = hmax;
  2698. }
  2699. #endif /* ATAFB_FALCON */
  2700. static void __init atafb_setup_user(char *spec)
  2701. {
  2702. /* Format of user defined video mode is: <xres>;<yres>;<depth>
  2703. */
  2704. char *p;
  2705. int xres, yres, depth, temp;
  2706. p = strsep(&spec, ";");
  2707. if (!p || !*p)
  2708. return;
  2709. xres = simple_strtoul(p, NULL, 10);
  2710. p = strsep(&spec, ";");
  2711. if (!p || !*p)
  2712. return;
  2713. yres = simple_strtoul(p, NULL, 10);
  2714. p = strsep(&spec, "");
  2715. if (!p || !*p)
  2716. return;
  2717. depth = simple_strtoul(p, NULL, 10);
  2718. temp = get_video_mode("user0");
  2719. if (temp) {
  2720. default_par = temp;
  2721. atafb_predefined[default_par - 1].xres = xres;
  2722. atafb_predefined[default_par - 1].yres = yres;
  2723. atafb_predefined[default_par - 1].bits_per_pixel = depth;
  2724. }
  2725. }
  2726. int __init atafb_setup(char *options)
  2727. {
  2728. char *this_opt;
  2729. int temp;
  2730. if (!options || !*options)
  2731. return 0;
  2732. while ((this_opt = strsep(&options, ",")) != NULL) {
  2733. if (!*this_opt)
  2734. continue;
  2735. if ((temp = get_video_mode(this_opt))) {
  2736. default_par = temp;
  2737. mode_option = this_opt;
  2738. } else if (!strcmp(this_opt, "inverse"))
  2739. inverse = 1;
  2740. else if (!strncmp(this_opt, "hwscroll_", 9)) {
  2741. hwscroll = simple_strtoul(this_opt + 9, NULL, 10);
  2742. if (hwscroll < 0)
  2743. hwscroll = 0;
  2744. if (hwscroll > 200)
  2745. hwscroll = 200;
  2746. }
  2747. #ifdef ATAFB_EXT
  2748. else if (!strcmp(this_opt, "mv300")) {
  2749. external_bitspercol = 8;
  2750. external_card_type = IS_MV300;
  2751. } else if (!strncmp(this_opt, "external:", 9))
  2752. atafb_setup_ext(this_opt + 9);
  2753. #endif
  2754. else if (!strncmp(this_opt, "internal:", 9))
  2755. atafb_setup_int(this_opt + 9);
  2756. #ifdef ATAFB_FALCON
  2757. else if (!strncmp(this_opt, "eclock:", 7)) {
  2758. fext.f = simple_strtoul(this_opt + 7, NULL, 10);
  2759. /* external pixelclock in kHz --> ps */
  2760. fext.t = 1000000000 / fext.f;
  2761. fext.f *= 1000;
  2762. } else if (!strncmp(this_opt, "monitorcap:", 11))
  2763. atafb_setup_mcap(this_opt + 11);
  2764. #endif
  2765. else if (!strcmp(this_opt, "keep"))
  2766. DontCalcRes = 1;
  2767. else if (!strncmp(this_opt, "R", 1))
  2768. atafb_setup_user(this_opt + 1);
  2769. }
  2770. return 0;
  2771. }
  2772. int __init atafb_init(void)
  2773. {
  2774. int pad;
  2775. int detected_mode;
  2776. unsigned int defmode = 0;
  2777. unsigned long mem_req;
  2778. #ifndef MODULE
  2779. char *option = NULL;
  2780. if (fb_get_options("atafb", &option))
  2781. return -ENODEV;
  2782. atafb_setup(option);
  2783. #endif
  2784. printk("atafb_init: start\n");
  2785. if (!MACH_IS_ATARI)
  2786. return -ENODEV;
  2787. do {
  2788. #ifdef ATAFB_EXT
  2789. if (external_addr) {
  2790. printk("atafb_init: initializing external hw\n");
  2791. fbhw = &ext_switch;
  2792. atafb_ops.fb_setcolreg = &ext_setcolreg;
  2793. defmode = DEFMODE_EXT;
  2794. break;
  2795. }
  2796. #endif
  2797. #ifdef ATAFB_TT
  2798. if (ATARIHW_PRESENT(TT_SHIFTER)) {
  2799. printk("atafb_init: initializing TT hw\n");
  2800. fbhw = &tt_switch;
  2801. atafb_ops.fb_setcolreg = &tt_setcolreg;
  2802. defmode = DEFMODE_TT;
  2803. break;
  2804. }
  2805. #endif
  2806. #ifdef ATAFB_FALCON
  2807. if (ATARIHW_PRESENT(VIDEL_SHIFTER)) {
  2808. printk("atafb_init: initializing Falcon hw\n");
  2809. fbhw = &falcon_switch;
  2810. atafb_ops.fb_setcolreg = &falcon_setcolreg;
  2811. request_irq(IRQ_AUTO_4, falcon_vbl_switcher, IRQ_TYPE_PRIO,
  2812. "framebuffer/modeswitch", falcon_vbl_switcher);
  2813. defmode = DEFMODE_F30;
  2814. break;
  2815. }
  2816. #endif
  2817. #ifdef ATAFB_STE
  2818. if (ATARIHW_PRESENT(STND_SHIFTER) ||
  2819. ATARIHW_PRESENT(EXTD_SHIFTER)) {
  2820. printk("atafb_init: initializing ST/E hw\n");
  2821. fbhw = &st_switch;
  2822. atafb_ops.fb_setcolreg = &stste_setcolreg;
  2823. defmode = DEFMODE_STE;
  2824. break;
  2825. }
  2826. fbhw = &st_switch;
  2827. atafb_ops.fb_setcolreg = &stste_setcolreg;
  2828. printk("Cannot determine video hardware; defaulting to ST(e)\n");
  2829. #else /* ATAFB_STE */
  2830. /* no default driver included */
  2831. /* Nobody will ever see this message :-) */
  2832. panic("Cannot initialize video hardware");
  2833. #endif
  2834. } while (0);
  2835. /* Multisync monitor capabilities */
  2836. /* Atari-TOS defaults if no boot option present */
  2837. if (fb_info.monspecs.hfmin == 0) {
  2838. fb_info.monspecs.hfmin = 31000;
  2839. fb_info.monspecs.hfmax = 32000;
  2840. fb_info.monspecs.vfmin = 58;
  2841. fb_info.monspecs.vfmax = 62;
  2842. }
  2843. detected_mode = fbhw->detect();
  2844. check_default_par(detected_mode);
  2845. #ifdef ATAFB_EXT
  2846. if (!external_addr) {
  2847. #endif /* ATAFB_EXT */
  2848. mem_req = default_mem_req + ovsc_offset + ovsc_addlen;
  2849. mem_req = PAGE_ALIGN(mem_req) + PAGE_SIZE;
  2850. screen_base = atari_stram_alloc(mem_req, "atafb");
  2851. if (!screen_base)
  2852. panic("Cannot allocate screen memory");
  2853. memset(screen_base, 0, mem_req);
  2854. pad = -(unsigned long)screen_base & (PAGE_SIZE - 1);
  2855. screen_base += pad;
  2856. real_screen_base = screen_base + ovsc_offset;
  2857. screen_len = (mem_req - pad - ovsc_offset) & PAGE_MASK;
  2858. st_ovsc_switch();
  2859. if (CPU_IS_040_OR_060) {
  2860. /* On a '040+, the cache mode of video RAM must be set to
  2861. * write-through also for internal video hardware! */
  2862. cache_push(virt_to_phys(screen_base), screen_len);
  2863. kernel_set_cachemode(screen_base, screen_len,
  2864. IOMAP_WRITETHROUGH);
  2865. }
  2866. printk("atafb: screen_base %p real_screen_base %p screen_len %d\n",
  2867. screen_base, real_screen_base, screen_len);
  2868. #ifdef ATAFB_EXT
  2869. } else {
  2870. /* Map the video memory (physical address given) to somewhere
  2871. * in the kernel address space.
  2872. */
  2873. external_addr = ioremap_writethrough((unsigned long)external_addr,
  2874. external_len);
  2875. if (external_vgaiobase)
  2876. external_vgaiobase =
  2877. (unsigned long)ioremap(external_vgaiobase, 0x10000);
  2878. screen_base =
  2879. real_screen_base = external_addr;
  2880. screen_len = external_len & PAGE_MASK;
  2881. memset (screen_base, 0, external_len);
  2882. }
  2883. #endif /* ATAFB_EXT */
  2884. // strcpy(fb_info.mode->name, "Atari Builtin ");
  2885. fb_info.fbops = &atafb_ops;
  2886. // try to set default (detected; requested) var
  2887. do_fb_set_var(&atafb_predefined[default_par - 1], 1);
  2888. // reads hw state into current par, which may not be sane yet
  2889. ata_get_par(&current_par);
  2890. fb_info.par = &current_par;
  2891. // tries to read from HW which may not be initialized yet
  2892. // so set sane var first, then call atafb_set_par
  2893. atafb_get_var(&fb_info.var, &fb_info);
  2894. #ifdef ATAFB_FALCON
  2895. fb_info.pseudo_palette = current_par.hw.falcon.pseudo_palette;
  2896. #endif
  2897. fb_info.flags = FBINFO_FLAG_DEFAULT;
  2898. if (!fb_find_mode(&fb_info.var, &fb_info, mode_option, atafb_modedb,
  2899. NUM_TOTAL_MODES, &atafb_modedb[defmode],
  2900. fb_info.var.bits_per_pixel)) {
  2901. return -EINVAL;
  2902. }
  2903. fb_videomode_to_modelist(atafb_modedb, NUM_TOTAL_MODES,
  2904. &fb_info.modelist);
  2905. atafb_set_disp(&fb_info);
  2906. fb_alloc_cmap(&(fb_info.cmap), 1 << fb_info.var.bits_per_pixel, 0);
  2907. printk("Determined %dx%d, depth %d\n",
  2908. fb_info.var.xres, fb_info.var.yres, fb_info.var.bits_per_pixel);
  2909. if ((fb_info.var.xres != fb_info.var.xres_virtual) ||
  2910. (fb_info.var.yres != fb_info.var.yres_virtual))
  2911. printk(" virtual %dx%d\n", fb_info.var.xres_virtual,
  2912. fb_info.var.yres_virtual);
  2913. if (register_framebuffer(&fb_info) < 0) {
  2914. #ifdef ATAFB_EXT
  2915. if (external_addr) {
  2916. iounmap(external_addr);
  2917. external_addr = NULL;
  2918. }
  2919. if (external_vgaiobase) {
  2920. iounmap((void*)external_vgaiobase);
  2921. external_vgaiobase = 0;
  2922. }
  2923. #endif
  2924. return -EINVAL;
  2925. }
  2926. // FIXME: mode needs setting!
  2927. //printk("fb%d: %s frame buffer device, using %dK of video memory\n",
  2928. // fb_info.node, fb_info.mode->name, screen_len>>10);
  2929. printk("fb%d: frame buffer device, using %dK of video memory\n",
  2930. fb_info.node, screen_len >> 10);
  2931. /* TODO: This driver cannot be unloaded yet */
  2932. return 0;
  2933. }
  2934. module_init(atafb_init);
  2935. #ifdef MODULE
  2936. MODULE_LICENSE("GPL");
  2937. int cleanup_module(void)
  2938. {
  2939. unregister_framebuffer(&fb_info);
  2940. return atafb_deinit();
  2941. }
  2942. #endif /* MODULE */