atafb.c 89 KB

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