atafb.c 89 KB

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