atafb.c 89 KB

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