atafb.c 89 KB

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