atafb.c 89 KB

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