amifb.c 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807
  1. /*
  2. * linux/drivers/video/amifb.c -- Amiga builtin chipset frame buffer device
  3. *
  4. * Copyright (C) 1995-2003 Geert Uytterhoeven
  5. *
  6. * with work by Roman Zippel
  7. *
  8. *
  9. * This file is based on the Atari frame buffer device (atafb.c):
  10. *
  11. * Copyright (C) 1994 Martin Schaller
  12. * Roman Hodek
  13. *
  14. * with work by Andreas Schwab
  15. * Guenther Kelleter
  16. *
  17. * and on the original Amiga console driver (amicon.c):
  18. *
  19. * Copyright (C) 1993 Hamish Macdonald
  20. * Greg Harp
  21. * Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
  22. *
  23. * with work by William Rucklidge (wjr@cs.cornell.edu)
  24. * Geert Uytterhoeven
  25. * Jes Sorensen (jds@kom.auc.dk)
  26. *
  27. *
  28. * History:
  29. *
  30. * - 24 Jul 96: Copper generates now vblank interrupt and
  31. * VESA Power Saving Protocol is fully implemented
  32. * - 14 Jul 96: Rework and hopefully last ECS bugs fixed
  33. * - 7 Mar 96: Hardware sprite support by Roman Zippel
  34. * - 18 Feb 96: OCS and ECS support by Roman Zippel
  35. * Hardware functions completely rewritten
  36. * - 2 Dec 95: AGA version by Geert Uytterhoeven
  37. *
  38. * This file is subject to the terms and conditions of the GNU General Public
  39. * License. See the file COPYING in the main directory of this archive
  40. * for more details.
  41. */
  42. #include <linux/module.h>
  43. #include <linux/kernel.h>
  44. #include <linux/errno.h>
  45. #include <linux/string.h>
  46. #include <linux/mm.h>
  47. #include <linux/delay.h>
  48. #include <linux/interrupt.h>
  49. #include <linux/fb.h>
  50. #include <linux/init.h>
  51. #include <linux/ioport.h>
  52. #include <linux/uaccess.h>
  53. #include <asm/system.h>
  54. #include <asm/irq.h>
  55. #include <asm/amigahw.h>
  56. #include <asm/amigaints.h>
  57. #include <asm/setup.h>
  58. #include "c2p.h"
  59. #define DEBUG
  60. #if !defined(CONFIG_FB_AMIGA_OCS) && !defined(CONFIG_FB_AMIGA_ECS) && !defined(CONFIG_FB_AMIGA_AGA)
  61. #define CONFIG_FB_AMIGA_OCS /* define at least one fb driver, this will change later */
  62. #endif
  63. #if !defined(CONFIG_FB_AMIGA_OCS)
  64. # define IS_OCS (0)
  65. #elif defined(CONFIG_FB_AMIGA_ECS) || defined(CONFIG_FB_AMIGA_AGA)
  66. # define IS_OCS (chipset == TAG_OCS)
  67. #else
  68. # define CONFIG_FB_AMIGA_OCS_ONLY
  69. # define IS_OCS (1)
  70. #endif
  71. #if !defined(CONFIG_FB_AMIGA_ECS)
  72. # define IS_ECS (0)
  73. #elif defined(CONFIG_FB_AMIGA_OCS) || defined(CONFIG_FB_AMIGA_AGA)
  74. # define IS_ECS (chipset == TAG_ECS)
  75. #else
  76. # define CONFIG_FB_AMIGA_ECS_ONLY
  77. # define IS_ECS (1)
  78. #endif
  79. #if !defined(CONFIG_FB_AMIGA_AGA)
  80. # define IS_AGA (0)
  81. #elif defined(CONFIG_FB_AMIGA_OCS) || defined(CONFIG_FB_AMIGA_ECS)
  82. # define IS_AGA (chipset == TAG_AGA)
  83. #else
  84. # define CONFIG_FB_AMIGA_AGA_ONLY
  85. # define IS_AGA (1)
  86. #endif
  87. #ifdef DEBUG
  88. # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
  89. #else
  90. # define DPRINTK(fmt, args...)
  91. #endif
  92. /*******************************************************************************
  93. Generic video timings
  94. ---------------------
  95. Timings used by the frame buffer interface:
  96. +----------+---------------------------------------------+----------+-------+
  97. | | ^ | | |
  98. | | |upper_margin | | |
  99. | | v | | |
  100. +----------###############################################----------+-------+
  101. | # ^ # | |
  102. | # | # | |
  103. | # | # | |
  104. | # | # | |
  105. | left # | # right | hsync |
  106. | margin # | xres # margin | len |
  107. |<-------->#<---------------+--------------------------->#<-------->|<----->|
  108. | # | # | |
  109. | # | # | |
  110. | # | # | |
  111. | # |yres # | |
  112. | # | # | |
  113. | # | # | |
  114. | # | # | |
  115. | # | # | |
  116. | # | # | |
  117. | # | # | |
  118. | # | # | |
  119. | # | # | |
  120. | # v # | |
  121. +----------###############################################----------+-------+
  122. | | ^ | | |
  123. | | |lower_margin | | |
  124. | | v | | |
  125. +----------+---------------------------------------------+----------+-------+
  126. | | ^ | | |
  127. | | |vsync_len | | |
  128. | | v | | |
  129. +----------+---------------------------------------------+----------+-------+
  130. Amiga video timings
  131. -------------------
  132. The Amiga native chipsets uses another timing scheme:
  133. - hsstrt: Start of horizontal synchronization pulse
  134. - hsstop: End of horizontal synchronization pulse
  135. - htotal: Last value on the line (i.e. line length = htotal+1)
  136. - vsstrt: Start of vertical synchronization pulse
  137. - vsstop: End of vertical synchronization pulse
  138. - vtotal: Last line value (i.e. number of lines = vtotal+1)
  139. - hcenter: Start of vertical retrace for interlace
  140. You can specify the blanking timings independently. Currently I just set
  141. them equal to the respective synchronization values:
  142. - hbstrt: Start of horizontal blank
  143. - hbstop: End of horizontal blank
  144. - vbstrt: Start of vertical blank
  145. - vbstop: End of vertical blank
  146. Horizontal values are in color clock cycles (280 ns), vertical values are in
  147. scanlines.
  148. (0, 0) is somewhere in the upper-left corner :-)
  149. Amiga visible window definitions
  150. --------------------------------
  151. Currently I only have values for AGA, SHRES (28 MHz dotclock). Feel free to
  152. make corrections and/or additions.
  153. Within the above synchronization specifications, the visible window is
  154. defined by the following parameters (actual register resolutions may be
  155. different; all horizontal values are normalized with respect to the pixel
  156. clock):
  157. - diwstrt_h: Horizontal start of the visible window
  158. - diwstop_h: Horizontal stop+1(*) of the visible window
  159. - diwstrt_v: Vertical start of the visible window
  160. - diwstop_v: Vertical stop of the visible window
  161. - ddfstrt: Horizontal start of display DMA
  162. - ddfstop: Horizontal stop of display DMA
  163. - hscroll: Horizontal display output delay
  164. Sprite positioning:
  165. - sprstrt_h: Horizontal start-4 of sprite
  166. - sprstrt_v: Vertical start of sprite
  167. (*) Even Commodore did it wrong in the AGA monitor drivers by not adding 1.
  168. Horizontal values are in dotclock cycles (35 ns), vertical values are in
  169. scanlines.
  170. (0, 0) is somewhere in the upper-left corner :-)
  171. Dependencies (AGA, SHRES (35 ns dotclock))
  172. -------------------------------------------
  173. Since there are much more parameters for the Amiga display than for the
  174. frame buffer interface, there must be some dependencies among the Amiga
  175. display parameters. Here's what I found out:
  176. - ddfstrt and ddfstop are best aligned to 64 pixels.
  177. - the chipset needs 64+4 horizontal pixels after the DMA start before the
  178. first pixel is output, so diwstrt_h = ddfstrt+64+4 if you want to
  179. display the first pixel on the line too. Increase diwstrt_h for virtual
  180. screen panning.
  181. - the display DMA always fetches 64 pixels at a time (fmode = 3).
  182. - ddfstop is ddfstrt+#pixels-64.
  183. - diwstop_h = diwstrt_h+xres+1. Because of the additional 1 this can be 1
  184. more than htotal.
  185. - hscroll simply adds a delay to the display output. Smooth horizontal
  186. panning needs an extra 64 pixels on the left to prefetch the pixels that
  187. `fall off' on the left.
  188. - if ddfstrt < 192, the sprite DMA cycles are all stolen by the bitplane
  189. DMA, so it's best to make the DMA start as late as possible.
  190. - you really don't want to make ddfstrt < 128, since this will steal DMA
  191. cycles from the other DMA channels (audio, floppy and Chip RAM refresh).
  192. - I make diwstop_h and diwstop_v as large as possible.
  193. General dependencies
  194. --------------------
  195. - all values are SHRES pixel (35ns)
  196. table 1:fetchstart table 2:prefetch table 3:fetchsize
  197. ------------------ ---------------- -----------------
  198. Pixclock # SHRES|HIRES|LORES # SHRES|HIRES|LORES # SHRES|HIRES|LORES
  199. -------------#------+-----+------#------+-----+------#------+-----+------
  200. Bus width 1x # 16 | 32 | 64 # 16 | 32 | 64 # 64 | 64 | 64
  201. Bus width 2x # 32 | 64 | 128 # 32 | 64 | 64 # 64 | 64 | 128
  202. Bus width 4x # 64 | 128 | 256 # 64 | 64 | 64 # 64 | 128 | 256
  203. - chipset needs 4 pixels before the first pixel is output
  204. - ddfstrt must be aligned to fetchstart (table 1)
  205. - chipset needs also prefetch (table 2) to get first pixel data, so
  206. ddfstrt = ((diwstrt_h-4) & -fetchstart) - prefetch
  207. - for horizontal panning decrease diwstrt_h
  208. - the length of a fetchline must be aligned to fetchsize (table 3)
  209. - if fetchstart is smaller than fetchsize, then ddfstrt can a little bit
  210. moved to optimize use of dma (useful for OCS/ECS overscan displays)
  211. - ddfstop is ddfstrt+ddfsize-fetchsize
  212. - If C= didn't change anything for AGA, then at following positions the
  213. dma bus is already used:
  214. ddfstrt < 48 -> memory refresh
  215. < 96 -> disk dma
  216. < 160 -> audio dma
  217. < 192 -> sprite 0 dma
  218. < 416 -> sprite dma (32 per sprite)
  219. - in accordance with the hardware reference manual a hardware stop is at
  220. 192, but AGA (ECS?) can go below this.
  221. DMA priorities
  222. --------------
  223. Since there are limits on the earliest start value for display DMA and the
  224. display of sprites, I use the following policy on horizontal panning and
  225. the hardware cursor:
  226. - if you want to start display DMA too early, you lose the ability to
  227. do smooth horizontal panning (xpanstep 1 -> 64).
  228. - if you want to go even further, you lose the hardware cursor too.
  229. IMHO a hardware cursor is more important for X than horizontal scrolling,
  230. so that's my motivation.
  231. Implementation
  232. --------------
  233. ami_decode_var() converts the frame buffer values to the Amiga values. It's
  234. just a `straightforward' implementation of the above rules.
  235. Standard VGA timings
  236. --------------------
  237. xres yres left right upper lower hsync vsync
  238. ---- ---- ---- ----- ----- ----- ----- -----
  239. 80x25 720 400 27 45 35 12 108 2
  240. 80x30 720 480 27 45 30 9 108 2
  241. These were taken from a XFree86 configuration file, recalculated for a 28 MHz
  242. dotclock (Amigas don't have a 25 MHz dotclock) and converted to frame buffer
  243. generic timings.
  244. As a comparison, graphics/monitor.h suggests the following:
  245. xres yres left right upper lower hsync vsync
  246. ---- ---- ---- ----- ----- ----- ----- -----
  247. VGA 640 480 52 112 24 19 112 - 2 +
  248. VGA70 640 400 52 112 27 21 112 - 2 -
  249. Sync polarities
  250. ---------------
  251. VSYNC HSYNC Vertical size Vertical total
  252. ----- ----- ------------- --------------
  253. + + Reserved Reserved
  254. + - 400 414
  255. - + 350 362
  256. - - 480 496
  257. Source: CL-GD542X Technical Reference Manual, Cirrus Logic, Oct 1992
  258. Broadcast video timings
  259. -----------------------
  260. According to the CCIR and RETMA specifications, we have the following values:
  261. CCIR -> PAL
  262. -----------
  263. - a scanline is 64 µs long, of which 52.48 µs are visible. This is about
  264. 736 visible 70 ns pixels per line.
  265. - we have 625 scanlines, of which 575 are visible (interlaced); after
  266. rounding this becomes 576.
  267. RETMA -> NTSC
  268. -------------
  269. - a scanline is 63.5 µs long, of which 53.5 µs are visible. This is about
  270. 736 visible 70 ns pixels per line.
  271. - we have 525 scanlines, of which 485 are visible (interlaced); after
  272. rounding this becomes 484.
  273. Thus if you want a PAL compatible display, you have to do the following:
  274. - set the FB_SYNC_BROADCAST flag to indicate that standard broadcast
  275. timings are to be used.
  276. - make sure upper_margin+yres+lower_margin+vsync_len = 625 for an
  277. interlaced, 312 for a non-interlaced and 156 for a doublescanned
  278. display.
  279. - make sure left_margin+xres+right_margin+hsync_len = 1816 for a SHRES,
  280. 908 for a HIRES and 454 for a LORES display.
  281. - the left visible part begins at 360 (SHRES; HIRES:180, LORES:90),
  282. left_margin+2*hsync_len must be greater or equal.
  283. - the upper visible part begins at 48 (interlaced; non-interlaced:24,
  284. doublescanned:12), upper_margin+2*vsync_len must be greater or equal.
  285. - ami_encode_var() calculates margins with a hsync of 5320 ns and a vsync
  286. of 4 scanlines
  287. The settings for a NTSC compatible display are straightforward.
  288. Note that in a strict sense the PAL and NTSC standards only define the
  289. encoding of the color part (chrominance) of the video signal and don't say
  290. anything about horizontal/vertical synchronization nor refresh rates.
  291. -- Geert --
  292. *******************************************************************************/
  293. /*
  294. * Custom Chipset Definitions
  295. */
  296. #define CUSTOM_OFS(fld) ((long)&((struct CUSTOM*)0)->fld)
  297. /*
  298. * BPLCON0 -- Bitplane Control Register 0
  299. */
  300. #define BPC0_HIRES (0x8000)
  301. #define BPC0_BPU2 (0x4000) /* Bit plane used count */
  302. #define BPC0_BPU1 (0x2000)
  303. #define BPC0_BPU0 (0x1000)
  304. #define BPC0_HAM (0x0800) /* HAM mode */
  305. #define BPC0_DPF (0x0400) /* Double playfield */
  306. #define BPC0_COLOR (0x0200) /* Enable colorburst */
  307. #define BPC0_GAUD (0x0100) /* Genlock audio enable */
  308. #define BPC0_UHRES (0x0080) /* Ultrahi res enable */
  309. #define BPC0_SHRES (0x0040) /* Super hi res mode */
  310. #define BPC0_BYPASS (0x0020) /* Bypass LUT - AGA */
  311. #define BPC0_BPU3 (0x0010) /* AGA */
  312. #define BPC0_LPEN (0x0008) /* Light pen enable */
  313. #define BPC0_LACE (0x0004) /* Interlace */
  314. #define BPC0_ERSY (0x0002) /* External resync */
  315. #define BPC0_ECSENA (0x0001) /* ECS enable */
  316. /*
  317. * BPLCON2 -- Bitplane Control Register 2
  318. */
  319. #define BPC2_ZDBPSEL2 (0x4000) /* Bitplane to be used for ZD - AGA */
  320. #define BPC2_ZDBPSEL1 (0x2000)
  321. #define BPC2_ZDBPSEL0 (0x1000)
  322. #define BPC2_ZDBPEN (0x0800) /* Enable ZD with ZDBPSELx - AGA */
  323. #define BPC2_ZDCTEN (0x0400) /* Enable ZD with palette bit #31 - AGA */
  324. #define BPC2_KILLEHB (0x0200) /* Kill EHB mode - AGA */
  325. #define BPC2_RDRAM (0x0100) /* Color table accesses read, not write - AGA */
  326. #define BPC2_SOGEN (0x0080) /* SOG output pin high - AGA */
  327. #define BPC2_PF2PRI (0x0040) /* PF2 priority over PF1 */
  328. #define BPC2_PF2P2 (0x0020) /* PF2 priority wrt sprites */
  329. #define BPC2_PF2P1 (0x0010)
  330. #define BPC2_PF2P0 (0x0008)
  331. #define BPC2_PF1P2 (0x0004) /* ditto PF1 */
  332. #define BPC2_PF1P1 (0x0002)
  333. #define BPC2_PF1P0 (0x0001)
  334. /*
  335. * BPLCON3 -- Bitplane Control Register 3 (AGA)
  336. */
  337. #define BPC3_BANK2 (0x8000) /* Bits to select color register bank */
  338. #define BPC3_BANK1 (0x4000)
  339. #define BPC3_BANK0 (0x2000)
  340. #define BPC3_PF2OF2 (0x1000) /* Bits for color table offset when PF2 */
  341. #define BPC3_PF2OF1 (0x0800)
  342. #define BPC3_PF2OF0 (0x0400)
  343. #define BPC3_LOCT (0x0200) /* Color register writes go to low bits */
  344. #define BPC3_SPRES1 (0x0080) /* Sprite resolution bits */
  345. #define BPC3_SPRES0 (0x0040)
  346. #define BPC3_BRDRBLNK (0x0020) /* Border blanked? */
  347. #define BPC3_BRDRTRAN (0x0010) /* Border transparent? */
  348. #define BPC3_ZDCLKEN (0x0004) /* ZD pin is 14 MHz (HIRES) clock output */
  349. #define BPC3_BRDRSPRT (0x0002) /* Sprites in border? */
  350. #define BPC3_EXTBLKEN (0x0001) /* BLANK programmable */
  351. /*
  352. * BPLCON4 -- Bitplane Control Register 4 (AGA)
  353. */
  354. #define BPC4_BPLAM7 (0x8000) /* bitplane color XOR field */
  355. #define BPC4_BPLAM6 (0x4000)
  356. #define BPC4_BPLAM5 (0x2000)
  357. #define BPC4_BPLAM4 (0x1000)
  358. #define BPC4_BPLAM3 (0x0800)
  359. #define BPC4_BPLAM2 (0x0400)
  360. #define BPC4_BPLAM1 (0x0200)
  361. #define BPC4_BPLAM0 (0x0100)
  362. #define BPC4_ESPRM7 (0x0080) /* 4 high bits for even sprite colors */
  363. #define BPC4_ESPRM6 (0x0040)
  364. #define BPC4_ESPRM5 (0x0020)
  365. #define BPC4_ESPRM4 (0x0010)
  366. #define BPC4_OSPRM7 (0x0008) /* 4 high bits for odd sprite colors */
  367. #define BPC4_OSPRM6 (0x0004)
  368. #define BPC4_OSPRM5 (0x0002)
  369. #define BPC4_OSPRM4 (0x0001)
  370. /*
  371. * BEAMCON0 -- Beam Control Register
  372. */
  373. #define BMC0_HARDDIS (0x4000) /* Disable hardware limits */
  374. #define BMC0_LPENDIS (0x2000) /* Disable light pen latch */
  375. #define BMC0_VARVBEN (0x1000) /* Enable variable vertical blank */
  376. #define BMC0_LOLDIS (0x0800) /* Disable long/short line toggle */
  377. #define BMC0_CSCBEN (0x0400) /* Composite sync/blank */
  378. #define BMC0_VARVSYEN (0x0200) /* Enable variable vertical sync */
  379. #define BMC0_VARHSYEN (0x0100) /* Enable variable horizontal sync */
  380. #define BMC0_VARBEAMEN (0x0080) /* Enable variable beam counters */
  381. #define BMC0_DUAL (0x0040) /* Enable alternate horizontal beam counter */
  382. #define BMC0_PAL (0x0020) /* Set decodes for PAL */
  383. #define BMC0_VARCSYEN (0x0010) /* Enable variable composite sync */
  384. #define BMC0_BLANKEN (0x0008) /* Blank enable (no longer used on AGA) */
  385. #define BMC0_CSYTRUE (0x0004) /* CSY polarity */
  386. #define BMC0_VSYTRUE (0x0002) /* VSY polarity */
  387. #define BMC0_HSYTRUE (0x0001) /* HSY polarity */
  388. /*
  389. * FMODE -- Fetch Mode Control Register (AGA)
  390. */
  391. #define FMODE_SSCAN2 (0x8000) /* Sprite scan-doubling */
  392. #define FMODE_BSCAN2 (0x4000) /* Use PF2 modulus every other line */
  393. #define FMODE_SPAGEM (0x0008) /* Sprite page mode */
  394. #define FMODE_SPR32 (0x0004) /* Sprite 32 bit fetch */
  395. #define FMODE_BPAGEM (0x0002) /* Bitplane page mode */
  396. #define FMODE_BPL32 (0x0001) /* Bitplane 32 bit fetch */
  397. /*
  398. * Tags used to indicate a specific Pixel Clock
  399. *
  400. * clk_shift is the shift value to get the timings in 35 ns units
  401. */
  402. enum { TAG_SHRES, TAG_HIRES, TAG_LORES };
  403. /*
  404. * Tags used to indicate the specific chipset
  405. */
  406. enum { TAG_OCS, TAG_ECS, TAG_AGA };
  407. /*
  408. * Tags used to indicate the memory bandwidth
  409. */
  410. enum { TAG_FMODE_1, TAG_FMODE_2, TAG_FMODE_4 };
  411. /*
  412. * Clock Definitions, Maximum Display Depth
  413. *
  414. * These depend on the E-Clock or the Chipset, so they are filled in
  415. * dynamically
  416. */
  417. static u_long pixclock[3]; /* SHRES/HIRES/LORES: index = clk_shift */
  418. static u_short maxdepth[3]; /* SHRES/HIRES/LORES: index = clk_shift */
  419. static u_short maxfmode, chipset;
  420. /*
  421. * Broadcast Video Timings
  422. *
  423. * Horizontal values are in 35 ns (SHRES) units
  424. * Vertical values are in interlaced scanlines
  425. */
  426. #define PAL_DIWSTRT_H (360) /* PAL Window Limits */
  427. #define PAL_DIWSTRT_V (48)
  428. #define PAL_HTOTAL (1816)
  429. #define PAL_VTOTAL (625)
  430. #define NTSC_DIWSTRT_H (360) /* NTSC Window Limits */
  431. #define NTSC_DIWSTRT_V (40)
  432. #define NTSC_HTOTAL (1816)
  433. #define NTSC_VTOTAL (525)
  434. /*
  435. * Various macros
  436. */
  437. #define up2(v) (((v)+1) & -2)
  438. #define down2(v) ((v) & -2)
  439. #define div2(v) ((v)>>1)
  440. #define mod2(v) ((v) & 1)
  441. #define up4(v) (((v)+3) & -4)
  442. #define down4(v) ((v) & -4)
  443. #define mul4(v) ((v)<<2)
  444. #define div4(v) ((v)>>2)
  445. #define mod4(v) ((v) & 3)
  446. #define up8(v) (((v)+7) & -8)
  447. #define down8(v) ((v) & -8)
  448. #define div8(v) ((v)>>3)
  449. #define mod8(v) ((v) & 7)
  450. #define up16(v) (((v)+15) & -16)
  451. #define down16(v) ((v) & -16)
  452. #define div16(v) ((v)>>4)
  453. #define mod16(v) ((v) & 15)
  454. #define up32(v) (((v)+31) & -32)
  455. #define down32(v) ((v) & -32)
  456. #define div32(v) ((v)>>5)
  457. #define mod32(v) ((v) & 31)
  458. #define up64(v) (((v)+63) & -64)
  459. #define down64(v) ((v) & -64)
  460. #define div64(v) ((v)>>6)
  461. #define mod64(v) ((v) & 63)
  462. #define upx(x,v) (((v)+(x)-1) & -(x))
  463. #define downx(x,v) ((v) & -(x))
  464. #define modx(x,v) ((v) & ((x)-1))
  465. /* if x1 is not a constant, this macro won't make real sense :-) */
  466. #ifdef __mc68000__
  467. #define DIVUL(x1, x2) ({int res; asm("divul %1,%2,%3": "=d" (res): \
  468. "d" (x2), "d" ((long)((x1)/0x100000000ULL)), "0" ((long)(x1))); res;})
  469. #else
  470. /* We know a bit about the numbers, so we can do it this way */
  471. #define DIVUL(x1, x2) ((((long)((unsigned long long)x1 >> 8) / x2) << 8) + \
  472. ((((long)((unsigned long long)x1 >> 8) % x2) << 8) / x2))
  473. #endif
  474. #define highw(x) ((u_long)(x)>>16 & 0xffff)
  475. #define loww(x) ((u_long)(x) & 0xffff)
  476. #define custom amiga_custom
  477. #define VBlankOn() custom.intena = IF_SETCLR|IF_COPER
  478. #define VBlankOff() custom.intena = IF_COPER
  479. /*
  480. * Chip RAM we reserve for the Frame Buffer
  481. *
  482. * This defines the Maximum Virtual Screen Size
  483. * (Setable per kernel options?)
  484. */
  485. #define VIDEOMEMSIZE_AGA_2M (1310720) /* AGA (2MB) : max 1280*1024*256 */
  486. #define VIDEOMEMSIZE_AGA_1M (786432) /* AGA (1MB) : max 1024*768*256 */
  487. #define VIDEOMEMSIZE_ECS_2M (655360) /* ECS (2MB) : max 1280*1024*16 */
  488. #define VIDEOMEMSIZE_ECS_1M (393216) /* ECS (1MB) : max 1024*768*16 */
  489. #define VIDEOMEMSIZE_OCS (262144) /* OCS : max ca. 800*600*16 */
  490. #define SPRITEMEMSIZE (64*64/4) /* max 64*64*4 */
  491. #define DUMMYSPRITEMEMSIZE (8)
  492. static u_long spritememory;
  493. #define CHIPRAM_SAFETY_LIMIT (16384)
  494. static u_long videomemory;
  495. /*
  496. * This is the earliest allowed start of fetching display data.
  497. * Only if you really want no hardware cursor and audio,
  498. * set this to 128, but let it better at 192
  499. */
  500. static u_long min_fstrt = 192;
  501. #define assignchunk(name, type, ptr, size) \
  502. { \
  503. (name) = (type)(ptr); \
  504. ptr += size; \
  505. }
  506. /*
  507. * Copper Instructions
  508. */
  509. #define CMOVE(val, reg) (CUSTOM_OFS(reg)<<16 | (val))
  510. #define CMOVE2(val, reg) ((CUSTOM_OFS(reg)+2)<<16 | (val))
  511. #define CWAIT(x, y) (((y) & 0x1fe)<<23 | ((x) & 0x7f0)<<13 | 0x0001fffe)
  512. #define CEND (0xfffffffe)
  513. typedef union {
  514. u_long l;
  515. u_short w[2];
  516. } copins;
  517. static struct copdisplay {
  518. copins *init;
  519. copins *wait;
  520. copins *list[2][2];
  521. copins *rebuild[2];
  522. } copdisplay;
  523. static u_short currentcop = 0;
  524. /*
  525. * Hardware Cursor API Definitions
  526. * These used to be in linux/fb.h, but were preliminary and used by
  527. * amifb only anyway
  528. */
  529. #define FBIOGET_FCURSORINFO 0x4607
  530. #define FBIOGET_VCURSORINFO 0x4608
  531. #define FBIOPUT_VCURSORINFO 0x4609
  532. #define FBIOGET_CURSORSTATE 0x460A
  533. #define FBIOPUT_CURSORSTATE 0x460B
  534. struct fb_fix_cursorinfo {
  535. __u16 crsr_width; /* width and height of the cursor in */
  536. __u16 crsr_height; /* pixels (zero if no cursor) */
  537. __u16 crsr_xsize; /* cursor size in display pixels */
  538. __u16 crsr_ysize;
  539. __u16 crsr_color1; /* colormap entry for cursor color1 */
  540. __u16 crsr_color2; /* colormap entry for cursor color2 */
  541. };
  542. struct fb_var_cursorinfo {
  543. __u16 width;
  544. __u16 height;
  545. __u16 xspot;
  546. __u16 yspot;
  547. __u8 data[1]; /* field with [height][width] */
  548. };
  549. struct fb_cursorstate {
  550. __s16 xoffset;
  551. __s16 yoffset;
  552. __u16 mode;
  553. };
  554. #define FB_CURSOR_OFF 0
  555. #define FB_CURSOR_ON 1
  556. #define FB_CURSOR_FLASH 2
  557. /*
  558. * Hardware Cursor
  559. */
  560. static int cursorrate = 20; /* Number of frames/flash toggle */
  561. static u_short cursorstate = -1;
  562. static u_short cursormode = FB_CURSOR_OFF;
  563. static u_short *lofsprite, *shfsprite, *dummysprite;
  564. /*
  565. * Current Video Mode
  566. */
  567. static struct amifb_par {
  568. /* General Values */
  569. int xres; /* vmode */
  570. int yres; /* vmode */
  571. int vxres; /* vmode */
  572. int vyres; /* vmode */
  573. int xoffset; /* vmode */
  574. int yoffset; /* vmode */
  575. u_short bpp; /* vmode */
  576. u_short clk_shift; /* vmode */
  577. u_short line_shift; /* vmode */
  578. int vmode; /* vmode */
  579. u_short diwstrt_h; /* vmode */
  580. u_short diwstop_h; /* vmode */
  581. u_short diwstrt_v; /* vmode */
  582. u_short diwstop_v; /* vmode */
  583. u_long next_line; /* modulo for next line */
  584. u_long next_plane; /* modulo for next plane */
  585. /* Cursor Values */
  586. struct {
  587. short crsr_x; /* movecursor */
  588. short crsr_y; /* movecursor */
  589. short spot_x;
  590. short spot_y;
  591. u_short height;
  592. u_short width;
  593. u_short fmode;
  594. } crsr;
  595. /* OCS Hardware Registers */
  596. u_long bplpt0; /* vmode, pan (Note: physical address) */
  597. u_long bplpt0wrap; /* vmode, pan (Note: physical address) */
  598. u_short ddfstrt;
  599. u_short ddfstop;
  600. u_short bpl1mod;
  601. u_short bpl2mod;
  602. u_short bplcon0; /* vmode */
  603. u_short bplcon1; /* vmode */
  604. u_short htotal; /* vmode */
  605. u_short vtotal; /* vmode */
  606. /* Additional ECS Hardware Registers */
  607. u_short bplcon3; /* vmode */
  608. u_short beamcon0; /* vmode */
  609. u_short hsstrt; /* vmode */
  610. u_short hsstop; /* vmode */
  611. u_short hbstrt; /* vmode */
  612. u_short hbstop; /* vmode */
  613. u_short vsstrt; /* vmode */
  614. u_short vsstop; /* vmode */
  615. u_short vbstrt; /* vmode */
  616. u_short vbstop; /* vmode */
  617. u_short hcenter; /* vmode */
  618. /* Additional AGA Hardware Registers */
  619. u_short fmode; /* vmode */
  620. } currentpar;
  621. static struct fb_info fb_info = {
  622. .fix = {
  623. .id = "Amiga ",
  624. .visual = FB_VISUAL_PSEUDOCOLOR,
  625. .accel = FB_ACCEL_AMIGABLITT
  626. }
  627. };
  628. /*
  629. * Saved color entry 0 so we can restore it when unblanking
  630. */
  631. static u_char red0, green0, blue0;
  632. #if defined(CONFIG_FB_AMIGA_ECS)
  633. static u_short ecs_palette[32];
  634. #endif
  635. /*
  636. * Latches for Display Changes during VBlank
  637. */
  638. static u_short do_vmode_full = 0; /* Change the Video Mode */
  639. static u_short do_vmode_pan = 0; /* Update the Video Mode */
  640. static short do_blank = 0; /* (Un)Blank the Screen (±1) */
  641. static u_short do_cursor = 0; /* Move the Cursor */
  642. /*
  643. * Various Flags
  644. */
  645. static u_short is_blanked = 0; /* Screen is Blanked */
  646. static u_short is_lace = 0; /* Screen is laced */
  647. /*
  648. * Predefined Video Modes
  649. *
  650. */
  651. static struct fb_videomode ami_modedb[] __initdata = {
  652. /*
  653. * AmigaOS Video Modes
  654. *
  655. * If you change these, make sure to update DEFMODE_* as well!
  656. */
  657. {
  658. /* 640x200, 15 kHz, 60 Hz (NTSC) */
  659. "ntsc", 60, 640, 200, TAG_HIRES, 106, 86, 44, 16, 76, 2,
  660. FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  661. }, {
  662. /* 640x400, 15 kHz, 60 Hz interlaced (NTSC) */
  663. "ntsc-lace", 60, 640, 400, TAG_HIRES, 106, 86, 88, 33, 76, 4,
  664. FB_SYNC_BROADCAST, FB_VMODE_INTERLACED | FB_VMODE_YWRAP
  665. }, {
  666. /* 640x256, 15 kHz, 50 Hz (PAL) */
  667. "pal", 50, 640, 256, TAG_HIRES, 106, 86, 40, 14, 76, 2,
  668. FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  669. }, {
  670. /* 640x512, 15 kHz, 50 Hz interlaced (PAL) */
  671. "pal-lace", 50, 640, 512, TAG_HIRES, 106, 86, 80, 29, 76, 4,
  672. FB_SYNC_BROADCAST, FB_VMODE_INTERLACED | FB_VMODE_YWRAP
  673. }, {
  674. /* 640x480, 29 kHz, 57 Hz */
  675. "multiscan", 57, 640, 480, TAG_SHRES, 96, 112, 29, 8, 72, 8,
  676. 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  677. }, {
  678. /* 640x960, 29 kHz, 57 Hz interlaced */
  679. "multiscan-lace", 57, 640, 960, TAG_SHRES, 96, 112, 58, 16, 72, 16,
  680. 0, FB_VMODE_INTERLACED | FB_VMODE_YWRAP
  681. }, {
  682. /* 640x200, 15 kHz, 72 Hz */
  683. "euro36", 72, 640, 200, TAG_HIRES, 92, 124, 6, 6, 52, 5,
  684. 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  685. }, {
  686. /* 640x400, 15 kHz, 72 Hz interlaced */
  687. "euro36-lace", 72, 640, 400, TAG_HIRES, 92, 124, 12, 12, 52, 10,
  688. 0, FB_VMODE_INTERLACED | FB_VMODE_YWRAP
  689. }, {
  690. /* 640x400, 29 kHz, 68 Hz */
  691. "euro72", 68, 640, 400, TAG_SHRES, 164, 92, 9, 9, 80, 8,
  692. 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  693. }, {
  694. /* 640x800, 29 kHz, 68 Hz interlaced */
  695. "euro72-lace", 68, 640, 800, TAG_SHRES, 164, 92, 18, 18, 80, 16,
  696. 0, FB_VMODE_INTERLACED | FB_VMODE_YWRAP
  697. }, {
  698. /* 800x300, 23 kHz, 70 Hz */
  699. "super72", 70, 800, 300, TAG_SHRES, 212, 140, 10, 11, 80, 7,
  700. 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  701. }, {
  702. /* 800x600, 23 kHz, 70 Hz interlaced */
  703. "super72-lace", 70, 800, 600, TAG_SHRES, 212, 140, 20, 22, 80, 14,
  704. 0, FB_VMODE_INTERLACED | FB_VMODE_YWRAP
  705. }, {
  706. /* 640x200, 27 kHz, 57 Hz doublescan */
  707. "dblntsc", 57, 640, 200, TAG_SHRES, 196, 124, 18, 17, 80, 4,
  708. 0, FB_VMODE_DOUBLE | FB_VMODE_YWRAP
  709. }, {
  710. /* 640x400, 27 kHz, 57 Hz */
  711. "dblntsc-ff", 57, 640, 400, TAG_SHRES, 196, 124, 36, 35, 80, 7,
  712. 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  713. }, {
  714. /* 640x800, 27 kHz, 57 Hz interlaced */
  715. "dblntsc-lace", 57, 640, 800, TAG_SHRES, 196, 124, 72, 70, 80, 14,
  716. 0, FB_VMODE_INTERLACED | FB_VMODE_YWRAP
  717. }, {
  718. /* 640x256, 27 kHz, 47 Hz doublescan */
  719. "dblpal", 47, 640, 256, TAG_SHRES, 196, 124, 14, 13, 80, 4,
  720. 0, FB_VMODE_DOUBLE | FB_VMODE_YWRAP
  721. }, {
  722. /* 640x512, 27 kHz, 47 Hz */
  723. "dblpal-ff", 47, 640, 512, TAG_SHRES, 196, 124, 28, 27, 80, 7,
  724. 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  725. }, {
  726. /* 640x1024, 27 kHz, 47 Hz interlaced */
  727. "dblpal-lace", 47, 640, 1024, TAG_SHRES, 196, 124, 56, 54, 80, 14,
  728. 0, FB_VMODE_INTERLACED | FB_VMODE_YWRAP
  729. },
  730. /*
  731. * VGA Video Modes
  732. */
  733. {
  734. /* 640x480, 31 kHz, 60 Hz (VGA) */
  735. "vga", 60, 640, 480, TAG_SHRES, 64, 96, 30, 9, 112, 2,
  736. 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  737. }, {
  738. /* 640x400, 31 kHz, 70 Hz (VGA) */
  739. "vga70", 70, 640, 400, TAG_SHRES, 64, 96, 35, 12, 112, 2,
  740. FB_SYNC_VERT_HIGH_ACT | FB_SYNC_COMP_HIGH_ACT, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  741. },
  742. #if 0
  743. /*
  744. * A2024 video modes
  745. * These modes don't work yet because there's no A2024 driver.
  746. */
  747. {
  748. /* 1024x800, 10 Hz */
  749. "a2024-10", 10, 1024, 800, TAG_HIRES, 0, 0, 0, 0, 0, 0,
  750. 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  751. }, {
  752. /* 1024x800, 15 Hz */
  753. "a2024-15", 15, 1024, 800, TAG_HIRES, 0, 0, 0, 0, 0, 0,
  754. 0, FB_VMODE_NONINTERLACED | FB_VMODE_YWRAP
  755. }
  756. #endif
  757. };
  758. #define NUM_TOTAL_MODES ARRAY_SIZE(ami_modedb)
  759. static char *mode_option __initdata = NULL;
  760. static int round_down_bpp = 1; /* for mode probing */
  761. /*
  762. * Some default modes
  763. */
  764. #define DEFMODE_PAL 2 /* "pal" for PAL OCS/ECS */
  765. #define DEFMODE_NTSC 0 /* "ntsc" for NTSC OCS/ECS */
  766. #define DEFMODE_AMBER_PAL 3 /* "pal-lace" for flicker fixed PAL (A3000) */
  767. #define DEFMODE_AMBER_NTSC 1 /* "ntsc-lace" for flicker fixed NTSC (A3000) */
  768. #define DEFMODE_AGA 19 /* "vga70" for AGA */
  769. static int amifb_ilbm = 0; /* interleaved or normal bitplanes */
  770. static int amifb_inverse = 0;
  771. /*
  772. * Macros for the conversion from real world values to hardware register
  773. * values
  774. *
  775. * This helps us to keep our attention on the real stuff...
  776. *
  777. * Hardware limits for AGA:
  778. *
  779. * parameter min max step
  780. * --------- --- ---- ----
  781. * diwstrt_h 0 2047 1
  782. * diwstrt_v 0 2047 1
  783. * diwstop_h 0 4095 1
  784. * diwstop_v 0 4095 1
  785. *
  786. * ddfstrt 0 2032 16
  787. * ddfstop 0 2032 16
  788. *
  789. * htotal 8 2048 8
  790. * hsstrt 0 2040 8
  791. * hsstop 0 2040 8
  792. * vtotal 1 4096 1
  793. * vsstrt 0 4095 1
  794. * vsstop 0 4095 1
  795. * hcenter 0 2040 8
  796. *
  797. * hbstrt 0 2047 1
  798. * hbstop 0 2047 1
  799. * vbstrt 0 4095 1
  800. * vbstop 0 4095 1
  801. *
  802. * Horizontal values are in 35 ns (SHRES) pixels
  803. * Vertical values are in half scanlines
  804. */
  805. /* bplcon1 (smooth scrolling) */
  806. #define hscroll2hw(hscroll) \
  807. (((hscroll)<<12 & 0x3000) | ((hscroll)<<8 & 0xc300) | \
  808. ((hscroll)<<4 & 0x0c00) | ((hscroll)<<2 & 0x00f0) | ((hscroll)>>2 & 0x000f))
  809. /* diwstrt/diwstop/diwhigh (visible display window) */
  810. #define diwstrt2hw(diwstrt_h, diwstrt_v) \
  811. (((diwstrt_v)<<7 & 0xff00) | ((diwstrt_h)>>2 & 0x00ff))
  812. #define diwstop2hw(diwstop_h, diwstop_v) \
  813. (((diwstop_v)<<7 & 0xff00) | ((diwstop_h)>>2 & 0x00ff))
  814. #define diwhigh2hw(diwstrt_h, diwstrt_v, diwstop_h, diwstop_v) \
  815. (((diwstop_h)<<3 & 0x2000) | ((diwstop_h)<<11 & 0x1800) | \
  816. ((diwstop_v)>>1 & 0x0700) | ((diwstrt_h)>>5 & 0x0020) | \
  817. ((diwstrt_h)<<3 & 0x0018) | ((diwstrt_v)>>9 & 0x0007))
  818. /* ddfstrt/ddfstop (display DMA) */
  819. #define ddfstrt2hw(ddfstrt) div8(ddfstrt)
  820. #define ddfstop2hw(ddfstop) div8(ddfstop)
  821. /* hsstrt/hsstop/htotal/vsstrt/vsstop/vtotal/hcenter (sync timings) */
  822. #define hsstrt2hw(hsstrt) (div8(hsstrt))
  823. #define hsstop2hw(hsstop) (div8(hsstop))
  824. #define htotal2hw(htotal) (div8(htotal)-1)
  825. #define vsstrt2hw(vsstrt) (div2(vsstrt))
  826. #define vsstop2hw(vsstop) (div2(vsstop))
  827. #define vtotal2hw(vtotal) (div2(vtotal)-1)
  828. #define hcenter2hw(htotal) (div8(htotal))
  829. /* hbstrt/hbstop/vbstrt/vbstop (blanking timings) */
  830. #define hbstrt2hw(hbstrt) (((hbstrt)<<8 & 0x0700) | ((hbstrt)>>3 & 0x00ff))
  831. #define hbstop2hw(hbstop) (((hbstop)<<8 & 0x0700) | ((hbstop)>>3 & 0x00ff))
  832. #define vbstrt2hw(vbstrt) (div2(vbstrt))
  833. #define vbstop2hw(vbstop) (div2(vbstop))
  834. /* colour */
  835. #define rgb2hw8_high(red, green, blue) \
  836. (((red & 0xf0)<<4) | (green & 0xf0) | ((blue & 0xf0)>>4))
  837. #define rgb2hw8_low(red, green, blue) \
  838. (((red & 0x0f)<<8) | ((green & 0x0f)<<4) | (blue & 0x0f))
  839. #define rgb2hw4(red, green, blue) \
  840. (((red & 0xf0)<<4) | (green & 0xf0) | ((blue & 0xf0)>>4))
  841. #define rgb2hw2(red, green, blue) \
  842. (((red & 0xc0)<<4) | (green & 0xc0) | ((blue & 0xc0)>>4))
  843. /* sprpos/sprctl (sprite positioning) */
  844. #define spr2hw_pos(start_v, start_h) \
  845. (((start_v)<<7&0xff00) | ((start_h)>>3&0x00ff))
  846. #define spr2hw_ctl(start_v, start_h, stop_v) \
  847. (((stop_v)<<7&0xff00) | ((start_v)>>4&0x0040) | ((stop_v)>>5&0x0020) | \
  848. ((start_h)<<3&0x0018) | ((start_v)>>7&0x0004) | ((stop_v)>>8&0x0002) | \
  849. ((start_h)>>2&0x0001))
  850. /* get current vertical position of beam */
  851. #define get_vbpos() ((u_short)((*(u_long volatile *)&custom.vposr >> 7) & 0xffe))
  852. /*
  853. * Copper Initialisation List
  854. */
  855. #define COPINITSIZE (sizeof(copins)*40)
  856. enum {
  857. cip_bplcon0
  858. };
  859. /*
  860. * Long Frame/Short Frame Copper List
  861. * Don't change the order, build_copper()/rebuild_copper() rely on this
  862. */
  863. #define COPLISTSIZE (sizeof(copins)*64)
  864. enum {
  865. cop_wait, cop_bplcon0,
  866. cop_spr0ptrh, cop_spr0ptrl,
  867. cop_diwstrt, cop_diwstop,
  868. cop_diwhigh,
  869. };
  870. /*
  871. * Pixel modes for Bitplanes and Sprites
  872. */
  873. static u_short bplpixmode[3] = {
  874. BPC0_SHRES, /* 35 ns */
  875. BPC0_HIRES, /* 70 ns */
  876. 0 /* 140 ns */
  877. };
  878. static u_short sprpixmode[3] = {
  879. BPC3_SPRES1 | BPC3_SPRES0, /* 35 ns */
  880. BPC3_SPRES1, /* 70 ns */
  881. BPC3_SPRES0 /* 140 ns */
  882. };
  883. /*
  884. * Fetch modes for Bitplanes and Sprites
  885. */
  886. static u_short bplfetchmode[3] = {
  887. 0, /* 1x */
  888. FMODE_BPL32, /* 2x */
  889. FMODE_BPAGEM | FMODE_BPL32 /* 4x */
  890. };
  891. static u_short sprfetchmode[3] = {
  892. 0, /* 1x */
  893. FMODE_SPR32, /* 2x */
  894. FMODE_SPAGEM | FMODE_SPR32 /* 4x */
  895. };
  896. /*
  897. * Interface used by the world
  898. */
  899. int amifb_setup(char*);
  900. static int amifb_check_var(struct fb_var_screeninfo *var,
  901. struct fb_info *info);
  902. static int amifb_set_par(struct fb_info *info);
  903. static int amifb_setcolreg(unsigned regno, unsigned red, unsigned green,
  904. unsigned blue, unsigned transp,
  905. struct fb_info *info);
  906. static int amifb_blank(int blank, struct fb_info *info);
  907. static int amifb_pan_display(struct fb_var_screeninfo *var,
  908. struct fb_info *info);
  909. static void amifb_fillrect(struct fb_info *info,
  910. const struct fb_fillrect *rect);
  911. static void amifb_copyarea(struct fb_info *info,
  912. const struct fb_copyarea *region);
  913. static void amifb_imageblit(struct fb_info *info,
  914. const struct fb_image *image);
  915. static int amifb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg);
  916. /*
  917. * Interface to the low level console driver
  918. */
  919. static void amifb_deinit(void);
  920. /*
  921. * Internal routines
  922. */
  923. static int flash_cursor(void);
  924. static irqreturn_t amifb_interrupt(int irq, void *dev_id);
  925. static u_long chipalloc(u_long size);
  926. static void chipfree(void);
  927. /*
  928. * Hardware routines
  929. */
  930. static int ami_decode_var(struct fb_var_screeninfo *var,
  931. struct amifb_par *par);
  932. static int ami_encode_var(struct fb_var_screeninfo *var,
  933. struct amifb_par *par);
  934. static void ami_pan_var(struct fb_var_screeninfo *var);
  935. static int ami_update_par(void);
  936. static void ami_update_display(void);
  937. static void ami_init_display(void);
  938. static void ami_do_blank(void);
  939. static int ami_get_fix_cursorinfo(struct fb_fix_cursorinfo *fix);
  940. static int ami_get_var_cursorinfo(struct fb_var_cursorinfo *var, u_char __user *data);
  941. static int ami_set_var_cursorinfo(struct fb_var_cursorinfo *var, u_char __user *data);
  942. static int ami_get_cursorstate(struct fb_cursorstate *state);
  943. static int ami_set_cursorstate(struct fb_cursorstate *state);
  944. static void ami_set_sprite(void);
  945. static void ami_init_copper(void);
  946. static void ami_reinit_copper(void);
  947. static void ami_build_copper(void);
  948. static void ami_rebuild_copper(void);
  949. static struct fb_ops amifb_ops = {
  950. .owner = THIS_MODULE,
  951. .fb_check_var = amifb_check_var,
  952. .fb_set_par = amifb_set_par,
  953. .fb_setcolreg = amifb_setcolreg,
  954. .fb_blank = amifb_blank,
  955. .fb_pan_display = amifb_pan_display,
  956. .fb_fillrect = amifb_fillrect,
  957. .fb_copyarea = amifb_copyarea,
  958. .fb_imageblit = amifb_imageblit,
  959. .fb_ioctl = amifb_ioctl,
  960. };
  961. static void __init amifb_setup_mcap(char *spec)
  962. {
  963. char *p;
  964. int vmin, vmax, hmin, hmax;
  965. /* Format for monitor capabilities is: <Vmin>;<Vmax>;<Hmin>;<Hmax>
  966. * <V*> vertical freq. in Hz
  967. * <H*> horizontal freq. in kHz
  968. */
  969. if (!(p = strsep(&spec, ";")) || !*p)
  970. return;
  971. vmin = simple_strtoul(p, NULL, 10);
  972. if (vmin <= 0)
  973. return;
  974. if (!(p = strsep(&spec, ";")) || !*p)
  975. return;
  976. vmax = simple_strtoul(p, NULL, 10);
  977. if (vmax <= 0 || vmax <= vmin)
  978. return;
  979. if (!(p = strsep(&spec, ";")) || !*p)
  980. return;
  981. hmin = 1000 * simple_strtoul(p, NULL, 10);
  982. if (hmin <= 0)
  983. return;
  984. if (!(p = strsep(&spec, "")) || !*p)
  985. return;
  986. hmax = 1000 * simple_strtoul(p, NULL, 10);
  987. if (hmax <= 0 || hmax <= hmin)
  988. return;
  989. fb_info.monspecs.vfmin = vmin;
  990. fb_info.monspecs.vfmax = vmax;
  991. fb_info.monspecs.hfmin = hmin;
  992. fb_info.monspecs.hfmax = hmax;
  993. }
  994. int __init amifb_setup(char *options)
  995. {
  996. char *this_opt;
  997. if (!options || !*options)
  998. return 0;
  999. while ((this_opt = strsep(&options, ",")) != NULL) {
  1000. if (!*this_opt)
  1001. continue;
  1002. if (!strcmp(this_opt, "inverse")) {
  1003. amifb_inverse = 1;
  1004. fb_invert_cmaps();
  1005. } else if (!strcmp(this_opt, "ilbm"))
  1006. amifb_ilbm = 1;
  1007. else if (!strncmp(this_opt, "monitorcap:", 11))
  1008. amifb_setup_mcap(this_opt+11);
  1009. else if (!strncmp(this_opt, "fstart:", 7))
  1010. min_fstrt = simple_strtoul(this_opt+7, NULL, 0);
  1011. else
  1012. mode_option = this_opt;
  1013. }
  1014. if (min_fstrt < 48)
  1015. min_fstrt = 48;
  1016. return 0;
  1017. }
  1018. static int amifb_check_var(struct fb_var_screeninfo *var,
  1019. struct fb_info *info)
  1020. {
  1021. int err;
  1022. struct amifb_par par;
  1023. /* Validate wanted screen parameters */
  1024. if ((err = ami_decode_var(var, &par)))
  1025. return err;
  1026. /* Encode (possibly rounded) screen parameters */
  1027. ami_encode_var(var, &par);
  1028. return 0;
  1029. }
  1030. static int amifb_set_par(struct fb_info *info)
  1031. {
  1032. struct amifb_par *par = (struct amifb_par *)info->par;
  1033. do_vmode_pan = 0;
  1034. do_vmode_full = 0;
  1035. /* Decode wanted screen parameters */
  1036. ami_decode_var(&info->var, par);
  1037. /* Set new videomode */
  1038. ami_build_copper();
  1039. /* Set VBlank trigger */
  1040. do_vmode_full = 1;
  1041. /* Update fix for new screen parameters */
  1042. if (par->bpp == 1) {
  1043. info->fix.type = FB_TYPE_PACKED_PIXELS;
  1044. info->fix.type_aux = 0;
  1045. } else if (amifb_ilbm) {
  1046. info->fix.type = FB_TYPE_INTERLEAVED_PLANES;
  1047. info->fix.type_aux = par->next_line;
  1048. } else {
  1049. info->fix.type = FB_TYPE_PLANES;
  1050. info->fix.type_aux = 0;
  1051. }
  1052. info->fix.line_length = div8(upx(16<<maxfmode, par->vxres));
  1053. if (par->vmode & FB_VMODE_YWRAP) {
  1054. info->fix.ywrapstep = 1;
  1055. info->fix.xpanstep = 0;
  1056. info->fix.ypanstep = 0;
  1057. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YWRAP |
  1058. FBINFO_READS_FAST; /* override SCROLL_REDRAW */
  1059. } else {
  1060. info->fix.ywrapstep = 0;
  1061. if (par->vmode & FB_VMODE_SMOOTH_XPAN)
  1062. info->fix.xpanstep = 1;
  1063. else
  1064. info->fix.xpanstep = 16<<maxfmode;
  1065. info->fix.ypanstep = 1;
  1066. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  1067. }
  1068. return 0;
  1069. }
  1070. /*
  1071. * Pan or Wrap the Display
  1072. *
  1073. * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
  1074. */
  1075. static int amifb_pan_display(struct fb_var_screeninfo *var,
  1076. struct fb_info *info)
  1077. {
  1078. if (var->vmode & FB_VMODE_YWRAP) {
  1079. if (var->yoffset < 0 ||
  1080. var->yoffset >= info->var.yres_virtual || var->xoffset)
  1081. return -EINVAL;
  1082. } else {
  1083. /*
  1084. * TODO: There will be problems when xpan!=1, so some columns
  1085. * on the right side will never be seen
  1086. */
  1087. if (var->xoffset+info->var.xres > upx(16<<maxfmode, info->var.xres_virtual) ||
  1088. var->yoffset+info->var.yres > info->var.yres_virtual)
  1089. return -EINVAL;
  1090. }
  1091. ami_pan_var(var);
  1092. info->var.xoffset = var->xoffset;
  1093. info->var.yoffset = var->yoffset;
  1094. if (var->vmode & FB_VMODE_YWRAP)
  1095. info->var.vmode |= FB_VMODE_YWRAP;
  1096. else
  1097. info->var.vmode &= ~FB_VMODE_YWRAP;
  1098. return 0;
  1099. }
  1100. #if BITS_PER_LONG == 32
  1101. #define BYTES_PER_LONG 4
  1102. #define SHIFT_PER_LONG 5
  1103. #elif BITS_PER_LONG == 64
  1104. #define BYTES_PER_LONG 8
  1105. #define SHIFT_PER_LONG 6
  1106. #else
  1107. #define Please update me
  1108. #endif
  1109. /*
  1110. * Compose two values, using a bitmask as decision value
  1111. * This is equivalent to (a & mask) | (b & ~mask)
  1112. */
  1113. static inline unsigned long comp(unsigned long a, unsigned long b,
  1114. unsigned long mask)
  1115. {
  1116. return ((a ^ b) & mask) ^ b;
  1117. }
  1118. static inline unsigned long xor(unsigned long a, unsigned long b,
  1119. unsigned long mask)
  1120. {
  1121. return (a & mask) ^ b;
  1122. }
  1123. /*
  1124. * Unaligned forward bit copy using 32-bit or 64-bit memory accesses
  1125. */
  1126. static void bitcpy(unsigned long *dst, int dst_idx, const unsigned long *src,
  1127. int src_idx, u32 n)
  1128. {
  1129. unsigned long first, last;
  1130. int shift = dst_idx-src_idx, left, right;
  1131. unsigned long d0, d1;
  1132. int m;
  1133. if (!n)
  1134. return;
  1135. shift = dst_idx-src_idx;
  1136. first = ~0UL >> dst_idx;
  1137. last = ~(~0UL >> ((dst_idx+n) % BITS_PER_LONG));
  1138. if (!shift) {
  1139. // Same alignment for source and dest
  1140. if (dst_idx+n <= BITS_PER_LONG) {
  1141. // Single word
  1142. if (last)
  1143. first &= last;
  1144. *dst = comp(*src, *dst, first);
  1145. } else {
  1146. // Multiple destination words
  1147. // Leading bits
  1148. if (first) {
  1149. *dst = comp(*src, *dst, first);
  1150. dst++;
  1151. src++;
  1152. n -= BITS_PER_LONG-dst_idx;
  1153. }
  1154. // Main chunk
  1155. n /= BITS_PER_LONG;
  1156. while (n >= 8) {
  1157. *dst++ = *src++;
  1158. *dst++ = *src++;
  1159. *dst++ = *src++;
  1160. *dst++ = *src++;
  1161. *dst++ = *src++;
  1162. *dst++ = *src++;
  1163. *dst++ = *src++;
  1164. *dst++ = *src++;
  1165. n -= 8;
  1166. }
  1167. while (n--)
  1168. *dst++ = *src++;
  1169. // Trailing bits
  1170. if (last)
  1171. *dst = comp(*src, *dst, last);
  1172. }
  1173. } else {
  1174. // Different alignment for source and dest
  1175. right = shift & (BITS_PER_LONG-1);
  1176. left = -shift & (BITS_PER_LONG-1);
  1177. if (dst_idx+n <= BITS_PER_LONG) {
  1178. // Single destination word
  1179. if (last)
  1180. first &= last;
  1181. if (shift > 0) {
  1182. // Single source word
  1183. *dst = comp(*src >> right, *dst, first);
  1184. } else if (src_idx+n <= BITS_PER_LONG) {
  1185. // Single source word
  1186. *dst = comp(*src << left, *dst, first);
  1187. } else {
  1188. // 2 source words
  1189. d0 = *src++;
  1190. d1 = *src;
  1191. *dst = comp(d0 << left | d1 >> right, *dst,
  1192. first);
  1193. }
  1194. } else {
  1195. // Multiple destination words
  1196. d0 = *src++;
  1197. // Leading bits
  1198. if (shift > 0) {
  1199. // Single source word
  1200. *dst = comp(d0 >> right, *dst, first);
  1201. dst++;
  1202. n -= BITS_PER_LONG-dst_idx;
  1203. } else {
  1204. // 2 source words
  1205. d1 = *src++;
  1206. *dst = comp(d0 << left | d1 >> right, *dst,
  1207. first);
  1208. d0 = d1;
  1209. dst++;
  1210. n -= BITS_PER_LONG-dst_idx;
  1211. }
  1212. // Main chunk
  1213. m = n % BITS_PER_LONG;
  1214. n /= BITS_PER_LONG;
  1215. while (n >= 4) {
  1216. d1 = *src++;
  1217. *dst++ = d0 << left | d1 >> right;
  1218. d0 = d1;
  1219. d1 = *src++;
  1220. *dst++ = d0 << left | d1 >> right;
  1221. d0 = d1;
  1222. d1 = *src++;
  1223. *dst++ = d0 << left | d1 >> right;
  1224. d0 = d1;
  1225. d1 = *src++;
  1226. *dst++ = d0 << left | d1 >> right;
  1227. d0 = d1;
  1228. n -= 4;
  1229. }
  1230. while (n--) {
  1231. d1 = *src++;
  1232. *dst++ = d0 << left | d1 >> right;
  1233. d0 = d1;
  1234. }
  1235. // Trailing bits
  1236. if (last) {
  1237. if (m <= right) {
  1238. // Single source word
  1239. *dst = comp(d0 << left, *dst, last);
  1240. } else {
  1241. // 2 source words
  1242. d1 = *src;
  1243. *dst = comp(d0 << left | d1 >> right,
  1244. *dst, last);
  1245. }
  1246. }
  1247. }
  1248. }
  1249. }
  1250. /*
  1251. * Unaligned reverse bit copy using 32-bit or 64-bit memory accesses
  1252. */
  1253. static void bitcpy_rev(unsigned long *dst, int dst_idx,
  1254. const unsigned long *src, int src_idx, u32 n)
  1255. {
  1256. unsigned long first, last;
  1257. int shift = dst_idx-src_idx, left, right;
  1258. unsigned long d0, d1;
  1259. int m;
  1260. if (!n)
  1261. return;
  1262. dst += (n-1)/BITS_PER_LONG;
  1263. src += (n-1)/BITS_PER_LONG;
  1264. if ((n-1) % BITS_PER_LONG) {
  1265. dst_idx += (n-1) % BITS_PER_LONG;
  1266. dst += dst_idx >> SHIFT_PER_LONG;
  1267. dst_idx &= BITS_PER_LONG-1;
  1268. src_idx += (n-1) % BITS_PER_LONG;
  1269. src += src_idx >> SHIFT_PER_LONG;
  1270. src_idx &= BITS_PER_LONG-1;
  1271. }
  1272. shift = dst_idx-src_idx;
  1273. first = ~0UL << (BITS_PER_LONG-1-dst_idx);
  1274. last = ~(~0UL << (BITS_PER_LONG-1-((dst_idx-n) % BITS_PER_LONG)));
  1275. if (!shift) {
  1276. // Same alignment for source and dest
  1277. if ((unsigned long)dst_idx+1 >= n) {
  1278. // Single word
  1279. if (last)
  1280. first &= last;
  1281. *dst = comp(*src, *dst, first);
  1282. } else {
  1283. // Multiple destination words
  1284. // Leading bits
  1285. if (first) {
  1286. *dst = comp(*src, *dst, first);
  1287. dst--;
  1288. src--;
  1289. n -= dst_idx+1;
  1290. }
  1291. // Main chunk
  1292. n /= BITS_PER_LONG;
  1293. while (n >= 8) {
  1294. *dst-- = *src--;
  1295. *dst-- = *src--;
  1296. *dst-- = *src--;
  1297. *dst-- = *src--;
  1298. *dst-- = *src--;
  1299. *dst-- = *src--;
  1300. *dst-- = *src--;
  1301. *dst-- = *src--;
  1302. n -= 8;
  1303. }
  1304. while (n--)
  1305. *dst-- = *src--;
  1306. // Trailing bits
  1307. if (last)
  1308. *dst = comp(*src, *dst, last);
  1309. }
  1310. } else {
  1311. // Different alignment for source and dest
  1312. right = shift & (BITS_PER_LONG-1);
  1313. left = -shift & (BITS_PER_LONG-1);
  1314. if ((unsigned long)dst_idx+1 >= n) {
  1315. // Single destination word
  1316. if (last)
  1317. first &= last;
  1318. if (shift < 0) {
  1319. // Single source word
  1320. *dst = comp(*src << left, *dst, first);
  1321. } else if (1+(unsigned long)src_idx >= n) {
  1322. // Single source word
  1323. *dst = comp(*src >> right, *dst, first);
  1324. } else {
  1325. // 2 source words
  1326. d0 = *src--;
  1327. d1 = *src;
  1328. *dst = comp(d0 >> right | d1 << left, *dst,
  1329. first);
  1330. }
  1331. } else {
  1332. // Multiple destination words
  1333. d0 = *src--;
  1334. // Leading bits
  1335. if (shift < 0) {
  1336. // Single source word
  1337. *dst = comp(d0 << left, *dst, first);
  1338. dst--;
  1339. n -= dst_idx+1;
  1340. } else {
  1341. // 2 source words
  1342. d1 = *src--;
  1343. *dst = comp(d0 >> right | d1 << left, *dst,
  1344. first);
  1345. d0 = d1;
  1346. dst--;
  1347. n -= dst_idx+1;
  1348. }
  1349. // Main chunk
  1350. m = n % BITS_PER_LONG;
  1351. n /= BITS_PER_LONG;
  1352. while (n >= 4) {
  1353. d1 = *src--;
  1354. *dst-- = d0 >> right | d1 << left;
  1355. d0 = d1;
  1356. d1 = *src--;
  1357. *dst-- = d0 >> right | d1 << left;
  1358. d0 = d1;
  1359. d1 = *src--;
  1360. *dst-- = d0 >> right | d1 << left;
  1361. d0 = d1;
  1362. d1 = *src--;
  1363. *dst-- = d0 >> right | d1 << left;
  1364. d0 = d1;
  1365. n -= 4;
  1366. }
  1367. while (n--) {
  1368. d1 = *src--;
  1369. *dst-- = d0 >> right | d1 << left;
  1370. d0 = d1;
  1371. }
  1372. // Trailing bits
  1373. if (last) {
  1374. if (m <= left) {
  1375. // Single source word
  1376. *dst = comp(d0 >> right, *dst, last);
  1377. } else {
  1378. // 2 source words
  1379. d1 = *src;
  1380. *dst = comp(d0 >> right | d1 << left,
  1381. *dst, last);
  1382. }
  1383. }
  1384. }
  1385. }
  1386. }
  1387. /*
  1388. * Unaligned forward inverting bit copy using 32-bit or 64-bit memory
  1389. * accesses
  1390. */
  1391. static void bitcpy_not(unsigned long *dst, int dst_idx,
  1392. const unsigned long *src, int src_idx, u32 n)
  1393. {
  1394. unsigned long first, last;
  1395. int shift = dst_idx-src_idx, left, right;
  1396. unsigned long d0, d1;
  1397. int m;
  1398. if (!n)
  1399. return;
  1400. shift = dst_idx-src_idx;
  1401. first = ~0UL >> dst_idx;
  1402. last = ~(~0UL >> ((dst_idx+n) % BITS_PER_LONG));
  1403. if (!shift) {
  1404. // Same alignment for source and dest
  1405. if (dst_idx+n <= BITS_PER_LONG) {
  1406. // Single word
  1407. if (last)
  1408. first &= last;
  1409. *dst = comp(~*src, *dst, first);
  1410. } else {
  1411. // Multiple destination words
  1412. // Leading bits
  1413. if (first) {
  1414. *dst = comp(~*src, *dst, first);
  1415. dst++;
  1416. src++;
  1417. n -= BITS_PER_LONG-dst_idx;
  1418. }
  1419. // Main chunk
  1420. n /= BITS_PER_LONG;
  1421. while (n >= 8) {
  1422. *dst++ = ~*src++;
  1423. *dst++ = ~*src++;
  1424. *dst++ = ~*src++;
  1425. *dst++ = ~*src++;
  1426. *dst++ = ~*src++;
  1427. *dst++ = ~*src++;
  1428. *dst++ = ~*src++;
  1429. *dst++ = ~*src++;
  1430. n -= 8;
  1431. }
  1432. while (n--)
  1433. *dst++ = ~*src++;
  1434. // Trailing bits
  1435. if (last)
  1436. *dst = comp(~*src, *dst, last);
  1437. }
  1438. } else {
  1439. // Different alignment for source and dest
  1440. right = shift & (BITS_PER_LONG-1);
  1441. left = -shift & (BITS_PER_LONG-1);
  1442. if (dst_idx+n <= BITS_PER_LONG) {
  1443. // Single destination word
  1444. if (last)
  1445. first &= last;
  1446. if (shift > 0) {
  1447. // Single source word
  1448. *dst = comp(~*src >> right, *dst, first);
  1449. } else if (src_idx+n <= BITS_PER_LONG) {
  1450. // Single source word
  1451. *dst = comp(~*src << left, *dst, first);
  1452. } else {
  1453. // 2 source words
  1454. d0 = ~*src++;
  1455. d1 = ~*src;
  1456. *dst = comp(d0 << left | d1 >> right, *dst,
  1457. first);
  1458. }
  1459. } else {
  1460. // Multiple destination words
  1461. d0 = ~*src++;
  1462. // Leading bits
  1463. if (shift > 0) {
  1464. // Single source word
  1465. *dst = comp(d0 >> right, *dst, first);
  1466. dst++;
  1467. n -= BITS_PER_LONG-dst_idx;
  1468. } else {
  1469. // 2 source words
  1470. d1 = ~*src++;
  1471. *dst = comp(d0 << left | d1 >> right, *dst,
  1472. first);
  1473. d0 = d1;
  1474. dst++;
  1475. n -= BITS_PER_LONG-dst_idx;
  1476. }
  1477. // Main chunk
  1478. m = n % BITS_PER_LONG;
  1479. n /= BITS_PER_LONG;
  1480. while (n >= 4) {
  1481. d1 = ~*src++;
  1482. *dst++ = d0 << left | d1 >> right;
  1483. d0 = d1;
  1484. d1 = ~*src++;
  1485. *dst++ = d0 << left | d1 >> right;
  1486. d0 = d1;
  1487. d1 = ~*src++;
  1488. *dst++ = d0 << left | d1 >> right;
  1489. d0 = d1;
  1490. d1 = ~*src++;
  1491. *dst++ = d0 << left | d1 >> right;
  1492. d0 = d1;
  1493. n -= 4;
  1494. }
  1495. while (n--) {
  1496. d1 = ~*src++;
  1497. *dst++ = d0 << left | d1 >> right;
  1498. d0 = d1;
  1499. }
  1500. // Trailing bits
  1501. if (last) {
  1502. if (m <= right) {
  1503. // Single source word
  1504. *dst = comp(d0 << left, *dst, last);
  1505. } else {
  1506. // 2 source words
  1507. d1 = ~*src;
  1508. *dst = comp(d0 << left | d1 >> right,
  1509. *dst, last);
  1510. }
  1511. }
  1512. }
  1513. }
  1514. }
  1515. /*
  1516. * Unaligned 32-bit pattern fill using 32/64-bit memory accesses
  1517. */
  1518. static void bitfill32(unsigned long *dst, int dst_idx, u32 pat, u32 n)
  1519. {
  1520. unsigned long val = pat;
  1521. unsigned long first, last;
  1522. if (!n)
  1523. return;
  1524. #if BITS_PER_LONG == 64
  1525. val |= val << 32;
  1526. #endif
  1527. first = ~0UL >> dst_idx;
  1528. last = ~(~0UL >> ((dst_idx+n) % BITS_PER_LONG));
  1529. if (dst_idx+n <= BITS_PER_LONG) {
  1530. // Single word
  1531. if (last)
  1532. first &= last;
  1533. *dst = comp(val, *dst, first);
  1534. } else {
  1535. // Multiple destination words
  1536. // Leading bits
  1537. if (first) {
  1538. *dst = comp(val, *dst, first);
  1539. dst++;
  1540. n -= BITS_PER_LONG-dst_idx;
  1541. }
  1542. // Main chunk
  1543. n /= BITS_PER_LONG;
  1544. while (n >= 8) {
  1545. *dst++ = val;
  1546. *dst++ = val;
  1547. *dst++ = val;
  1548. *dst++ = val;
  1549. *dst++ = val;
  1550. *dst++ = val;
  1551. *dst++ = val;
  1552. *dst++ = val;
  1553. n -= 8;
  1554. }
  1555. while (n--)
  1556. *dst++ = val;
  1557. // Trailing bits
  1558. if (last)
  1559. *dst = comp(val, *dst, last);
  1560. }
  1561. }
  1562. /*
  1563. * Unaligned 32-bit pattern xor using 32/64-bit memory accesses
  1564. */
  1565. static void bitxor32(unsigned long *dst, int dst_idx, u32 pat, u32 n)
  1566. {
  1567. unsigned long val = pat;
  1568. unsigned long first, last;
  1569. if (!n)
  1570. return;
  1571. #if BITS_PER_LONG == 64
  1572. val |= val << 32;
  1573. #endif
  1574. first = ~0UL >> dst_idx;
  1575. last = ~(~0UL >> ((dst_idx+n) % BITS_PER_LONG));
  1576. if (dst_idx+n <= BITS_PER_LONG) {
  1577. // Single word
  1578. if (last)
  1579. first &= last;
  1580. *dst = xor(val, *dst, first);
  1581. } else {
  1582. // Multiple destination words
  1583. // Leading bits
  1584. if (first) {
  1585. *dst = xor(val, *dst, first);
  1586. dst++;
  1587. n -= BITS_PER_LONG-dst_idx;
  1588. }
  1589. // Main chunk
  1590. n /= BITS_PER_LONG;
  1591. while (n >= 4) {
  1592. *dst++ ^= val;
  1593. *dst++ ^= val;
  1594. *dst++ ^= val;
  1595. *dst++ ^= val;
  1596. n -= 4;
  1597. }
  1598. while (n--)
  1599. *dst++ ^= val;
  1600. // Trailing bits
  1601. if (last)
  1602. *dst = xor(val, *dst, last);
  1603. }
  1604. }
  1605. static inline void fill_one_line(int bpp, unsigned long next_plane,
  1606. unsigned long *dst, int dst_idx, u32 n,
  1607. u32 color)
  1608. {
  1609. while (1) {
  1610. dst += dst_idx >> SHIFT_PER_LONG;
  1611. dst_idx &= (BITS_PER_LONG-1);
  1612. bitfill32(dst, dst_idx, color & 1 ? ~0 : 0, n);
  1613. if (!--bpp)
  1614. break;
  1615. color >>= 1;
  1616. dst_idx += next_plane*8;
  1617. }
  1618. }
  1619. static inline void xor_one_line(int bpp, unsigned long next_plane,
  1620. unsigned long *dst, int dst_idx, u32 n,
  1621. u32 color)
  1622. {
  1623. while (color) {
  1624. dst += dst_idx >> SHIFT_PER_LONG;
  1625. dst_idx &= (BITS_PER_LONG-1);
  1626. bitxor32(dst, dst_idx, color & 1 ? ~0 : 0, n);
  1627. if (!--bpp)
  1628. break;
  1629. color >>= 1;
  1630. dst_idx += next_plane*8;
  1631. }
  1632. }
  1633. static void amifb_fillrect(struct fb_info *info,
  1634. const struct fb_fillrect *rect)
  1635. {
  1636. struct amifb_par *par = (struct amifb_par *)info->par;
  1637. int dst_idx, x2, y2;
  1638. unsigned long *dst;
  1639. u32 width, height;
  1640. if (!rect->width || !rect->height)
  1641. return;
  1642. /*
  1643. * We could use hardware clipping but on many cards you get around
  1644. * hardware clipping by writing to framebuffer directly.
  1645. * */
  1646. x2 = rect->dx + rect->width;
  1647. y2 = rect->dy + rect->height;
  1648. x2 = x2 < info->var.xres_virtual ? x2 : info->var.xres_virtual;
  1649. y2 = y2 < info->var.yres_virtual ? y2 : info->var.yres_virtual;
  1650. width = x2 - rect->dx;
  1651. height = y2 - rect->dy;
  1652. dst = (unsigned long *)
  1653. ((unsigned long)info->screen_base & ~(BYTES_PER_LONG-1));
  1654. dst_idx = ((unsigned long)info->screen_base & (BYTES_PER_LONG-1))*8;
  1655. dst_idx += rect->dy*par->next_line*8+rect->dx;
  1656. while (height--) {
  1657. switch (rect->rop) {
  1658. case ROP_COPY:
  1659. fill_one_line(info->var.bits_per_pixel,
  1660. par->next_plane, dst, dst_idx, width,
  1661. rect->color);
  1662. break;
  1663. case ROP_XOR:
  1664. xor_one_line(info->var.bits_per_pixel, par->next_plane,
  1665. dst, dst_idx, width, rect->color);
  1666. break;
  1667. }
  1668. dst_idx += par->next_line*8;
  1669. }
  1670. }
  1671. static inline void copy_one_line(int bpp, unsigned long next_plane,
  1672. unsigned long *dst, int dst_idx,
  1673. unsigned long *src, int src_idx, u32 n)
  1674. {
  1675. while (1) {
  1676. dst += dst_idx >> SHIFT_PER_LONG;
  1677. dst_idx &= (BITS_PER_LONG-1);
  1678. src += src_idx >> SHIFT_PER_LONG;
  1679. src_idx &= (BITS_PER_LONG-1);
  1680. bitcpy(dst, dst_idx, src, src_idx, n);
  1681. if (!--bpp)
  1682. break;
  1683. dst_idx += next_plane*8;
  1684. src_idx += next_plane*8;
  1685. }
  1686. }
  1687. static inline void copy_one_line_rev(int bpp, unsigned long next_plane,
  1688. unsigned long *dst, int dst_idx,
  1689. unsigned long *src, int src_idx, u32 n)
  1690. {
  1691. while (1) {
  1692. dst += dst_idx >> SHIFT_PER_LONG;
  1693. dst_idx &= (BITS_PER_LONG-1);
  1694. src += src_idx >> SHIFT_PER_LONG;
  1695. src_idx &= (BITS_PER_LONG-1);
  1696. bitcpy_rev(dst, dst_idx, src, src_idx, n);
  1697. if (!--bpp)
  1698. break;
  1699. dst_idx += next_plane*8;
  1700. src_idx += next_plane*8;
  1701. }
  1702. }
  1703. static void amifb_copyarea(struct fb_info *info,
  1704. const struct fb_copyarea *area)
  1705. {
  1706. struct amifb_par *par = (struct amifb_par *)info->par;
  1707. int x2, y2;
  1708. u32 dx, dy, sx, sy, width, height;
  1709. unsigned long *dst, *src;
  1710. int dst_idx, src_idx;
  1711. int rev_copy = 0;
  1712. /* clip the destination */
  1713. x2 = area->dx + area->width;
  1714. y2 = area->dy + area->height;
  1715. dx = area->dx > 0 ? area->dx : 0;
  1716. dy = area->dy > 0 ? area->dy : 0;
  1717. x2 = x2 < info->var.xres_virtual ? x2 : info->var.xres_virtual;
  1718. y2 = y2 < info->var.yres_virtual ? y2 : info->var.yres_virtual;
  1719. width = x2 - dx;
  1720. height = y2 - dy;
  1721. if (area->sx + dx < area->dx || area->sy + dy < area->dy)
  1722. return;
  1723. /* update sx,sy */
  1724. sx = area->sx + (dx - area->dx);
  1725. sy = area->sy + (dy - area->dy);
  1726. /* the source must be completely inside the virtual screen */
  1727. if (sx + width > info->var.xres_virtual ||
  1728. sy + height > info->var.yres_virtual)
  1729. return;
  1730. if (dy > sy || (dy == sy && dx > sx)) {
  1731. dy += height;
  1732. sy += height;
  1733. rev_copy = 1;
  1734. }
  1735. dst = (unsigned long *)
  1736. ((unsigned long)info->screen_base & ~(BYTES_PER_LONG-1));
  1737. src = dst;
  1738. dst_idx = ((unsigned long)info->screen_base & (BYTES_PER_LONG-1))*8;
  1739. src_idx = dst_idx;
  1740. dst_idx += dy*par->next_line*8+dx;
  1741. src_idx += sy*par->next_line*8+sx;
  1742. if (rev_copy) {
  1743. while (height--) {
  1744. dst_idx -= par->next_line*8;
  1745. src_idx -= par->next_line*8;
  1746. copy_one_line_rev(info->var.bits_per_pixel,
  1747. par->next_plane, dst, dst_idx, src,
  1748. src_idx, width);
  1749. }
  1750. } else {
  1751. while (height--) {
  1752. copy_one_line(info->var.bits_per_pixel,
  1753. par->next_plane, dst, dst_idx, src,
  1754. src_idx, width);
  1755. dst_idx += par->next_line*8;
  1756. src_idx += par->next_line*8;
  1757. }
  1758. }
  1759. }
  1760. static inline void expand_one_line(int bpp, unsigned long next_plane,
  1761. unsigned long *dst, int dst_idx, u32 n,
  1762. const u8 *data, u32 bgcolor, u32 fgcolor)
  1763. {
  1764. const unsigned long *src;
  1765. int src_idx;
  1766. while (1) {
  1767. dst += dst_idx >> SHIFT_PER_LONG;
  1768. dst_idx &= (BITS_PER_LONG-1);
  1769. if ((bgcolor ^ fgcolor) & 1) {
  1770. src = (unsigned long *)((unsigned long)data & ~(BYTES_PER_LONG-1));
  1771. src_idx = ((unsigned long)data & (BYTES_PER_LONG-1))*8;
  1772. if (fgcolor & 1)
  1773. bitcpy(dst, dst_idx, src, src_idx, n);
  1774. else
  1775. bitcpy_not(dst, dst_idx, src, src_idx, n);
  1776. /* set or clear */
  1777. } else
  1778. bitfill32(dst, dst_idx, fgcolor & 1 ? ~0 : 0, n);
  1779. if (!--bpp)
  1780. break;
  1781. bgcolor >>= 1;
  1782. fgcolor >>= 1;
  1783. dst_idx += next_plane*8;
  1784. }
  1785. }
  1786. static void amifb_imageblit(struct fb_info *info, const struct fb_image *image)
  1787. {
  1788. struct amifb_par *par = (struct amifb_par *)info->par;
  1789. int x2, y2;
  1790. unsigned long *dst;
  1791. int dst_idx;
  1792. const char *src;
  1793. u32 dx, dy, width, height, pitch;
  1794. /*
  1795. * We could use hardware clipping but on many cards you get around
  1796. * hardware clipping by writing to framebuffer directly like we are
  1797. * doing here.
  1798. */
  1799. x2 = image->dx + image->width;
  1800. y2 = image->dy + image->height;
  1801. dx = image->dx;
  1802. dy = image->dy;
  1803. x2 = x2 < info->var.xres_virtual ? x2 : info->var.xres_virtual;
  1804. y2 = y2 < info->var.yres_virtual ? y2 : info->var.yres_virtual;
  1805. width = x2 - dx;
  1806. height = y2 - dy;
  1807. if (image->depth == 1) {
  1808. dst = (unsigned long *)
  1809. ((unsigned long)info->screen_base & ~(BYTES_PER_LONG-1));
  1810. dst_idx = ((unsigned long)info->screen_base & (BYTES_PER_LONG-1))*8;
  1811. dst_idx += dy*par->next_line*8+dx;
  1812. src = image->data;
  1813. pitch = (image->width+7)/8;
  1814. while (height--) {
  1815. expand_one_line(info->var.bits_per_pixel,
  1816. par->next_plane, dst, dst_idx, width,
  1817. src, image->bg_color,
  1818. image->fg_color);
  1819. dst_idx += par->next_line*8;
  1820. src += pitch;
  1821. }
  1822. } else {
  1823. c2p_planar(info->screen_base, image->data, dx, dy, width,
  1824. height, par->next_line, par->next_plane,
  1825. image->width, info->var.bits_per_pixel);
  1826. }
  1827. }
  1828. /*
  1829. * Amiga Frame Buffer Specific ioctls
  1830. */
  1831. static int amifb_ioctl(struct fb_info *info,
  1832. unsigned int cmd, unsigned long arg)
  1833. {
  1834. union {
  1835. struct fb_fix_cursorinfo fix;
  1836. struct fb_var_cursorinfo var;
  1837. struct fb_cursorstate state;
  1838. } crsr;
  1839. void __user *argp = (void __user *)arg;
  1840. int i;
  1841. switch (cmd) {
  1842. case FBIOGET_FCURSORINFO:
  1843. i = ami_get_fix_cursorinfo(&crsr.fix);
  1844. if (i)
  1845. return i;
  1846. return copy_to_user(argp, &crsr.fix,
  1847. sizeof(crsr.fix)) ? -EFAULT : 0;
  1848. case FBIOGET_VCURSORINFO:
  1849. i = ami_get_var_cursorinfo(&crsr.var,
  1850. ((struct fb_var_cursorinfo __user *)arg)->data);
  1851. if (i)
  1852. return i;
  1853. return copy_to_user(argp, &crsr.var,
  1854. sizeof(crsr.var)) ? -EFAULT : 0;
  1855. case FBIOPUT_VCURSORINFO:
  1856. if (copy_from_user(&crsr.var, argp, sizeof(crsr.var)))
  1857. return -EFAULT;
  1858. return ami_set_var_cursorinfo(&crsr.var,
  1859. ((struct fb_var_cursorinfo __user *)arg)->data);
  1860. case FBIOGET_CURSORSTATE:
  1861. i = ami_get_cursorstate(&crsr.state);
  1862. if (i)
  1863. return i;
  1864. return copy_to_user(argp, &crsr.state,
  1865. sizeof(crsr.state)) ? -EFAULT : 0;
  1866. case FBIOPUT_CURSORSTATE:
  1867. if (copy_from_user(&crsr.state, argp,
  1868. sizeof(crsr.state)))
  1869. return -EFAULT;
  1870. return ami_set_cursorstate(&crsr.state);
  1871. }
  1872. return -EINVAL;
  1873. }
  1874. /*
  1875. * Allocate, Clear and Align a Block of Chip Memory
  1876. */
  1877. static u_long unaligned_chipptr = 0;
  1878. static inline u_long __init chipalloc(u_long size)
  1879. {
  1880. size += PAGE_SIZE-1;
  1881. if (!(unaligned_chipptr = (u_long)amiga_chip_alloc(size,
  1882. "amifb [RAM]")))
  1883. panic("No Chip RAM for frame buffer");
  1884. memset((void *)unaligned_chipptr, 0, size);
  1885. return PAGE_ALIGN(unaligned_chipptr);
  1886. }
  1887. static inline void chipfree(void)
  1888. {
  1889. if (unaligned_chipptr)
  1890. amiga_chip_free((void *)unaligned_chipptr);
  1891. }
  1892. /*
  1893. * Initialisation
  1894. */
  1895. static int __init amifb_init(void)
  1896. {
  1897. int tag, i, err = 0;
  1898. u_long chipptr;
  1899. u_int defmode;
  1900. #ifndef MODULE
  1901. char *option = NULL;
  1902. if (fb_get_options("amifb", &option)) {
  1903. amifb_video_off();
  1904. return -ENODEV;
  1905. }
  1906. amifb_setup(option);
  1907. #endif
  1908. if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_VIDEO))
  1909. return -ENODEV;
  1910. /*
  1911. * We request all registers starting from bplpt[0]
  1912. */
  1913. if (!request_mem_region(CUSTOM_PHYSADDR+0xe0, 0x120,
  1914. "amifb [Denise/Lisa]"))
  1915. return -EBUSY;
  1916. custom.dmacon = DMAF_ALL | DMAF_MASTER;
  1917. switch (amiga_chipset) {
  1918. #ifdef CONFIG_FB_AMIGA_OCS
  1919. case CS_OCS:
  1920. strcat(fb_info.fix.id, "OCS");
  1921. default_chipset:
  1922. chipset = TAG_OCS;
  1923. maxdepth[TAG_SHRES] = 0; /* OCS means no SHRES */
  1924. maxdepth[TAG_HIRES] = 4;
  1925. maxdepth[TAG_LORES] = 6;
  1926. maxfmode = TAG_FMODE_1;
  1927. defmode = amiga_vblank == 50 ? DEFMODE_PAL
  1928. : DEFMODE_NTSC;
  1929. fb_info.fix.smem_len = VIDEOMEMSIZE_OCS;
  1930. break;
  1931. #endif /* CONFIG_FB_AMIGA_OCS */
  1932. #ifdef CONFIG_FB_AMIGA_ECS
  1933. case CS_ECS:
  1934. strcat(fb_info.fix.id, "ECS");
  1935. chipset = TAG_ECS;
  1936. maxdepth[TAG_SHRES] = 2;
  1937. maxdepth[TAG_HIRES] = 4;
  1938. maxdepth[TAG_LORES] = 6;
  1939. maxfmode = TAG_FMODE_1;
  1940. if (AMIGAHW_PRESENT(AMBER_FF))
  1941. defmode = amiga_vblank == 50 ? DEFMODE_AMBER_PAL
  1942. : DEFMODE_AMBER_NTSC;
  1943. else
  1944. defmode = amiga_vblank == 50 ? DEFMODE_PAL
  1945. : DEFMODE_NTSC;
  1946. if (amiga_chip_avail()-CHIPRAM_SAFETY_LIMIT >
  1947. VIDEOMEMSIZE_ECS_1M)
  1948. fb_info.fix.smem_len = VIDEOMEMSIZE_ECS_2M;
  1949. else
  1950. fb_info.fix.smem_len = VIDEOMEMSIZE_ECS_1M;
  1951. break;
  1952. #endif /* CONFIG_FB_AMIGA_ECS */
  1953. #ifdef CONFIG_FB_AMIGA_AGA
  1954. case CS_AGA:
  1955. strcat(fb_info.fix.id, "AGA");
  1956. chipset = TAG_AGA;
  1957. maxdepth[TAG_SHRES] = 8;
  1958. maxdepth[TAG_HIRES] = 8;
  1959. maxdepth[TAG_LORES] = 8;
  1960. maxfmode = TAG_FMODE_4;
  1961. defmode = DEFMODE_AGA;
  1962. if (amiga_chip_avail()-CHIPRAM_SAFETY_LIMIT >
  1963. VIDEOMEMSIZE_AGA_1M)
  1964. fb_info.fix.smem_len = VIDEOMEMSIZE_AGA_2M;
  1965. else
  1966. fb_info.fix.smem_len = VIDEOMEMSIZE_AGA_1M;
  1967. break;
  1968. #endif /* CONFIG_FB_AMIGA_AGA */
  1969. default:
  1970. #ifdef CONFIG_FB_AMIGA_OCS
  1971. printk("Unknown graphics chipset, defaulting to OCS\n");
  1972. strcat(fb_info.fix.id, "Unknown");
  1973. goto default_chipset;
  1974. #else /* CONFIG_FB_AMIGA_OCS */
  1975. err = -ENODEV;
  1976. goto amifb_error;
  1977. #endif /* CONFIG_FB_AMIGA_OCS */
  1978. break;
  1979. }
  1980. /*
  1981. * Calculate the Pixel Clock Values for this Machine
  1982. */
  1983. {
  1984. u_long tmp = DIVUL(200000000000ULL, amiga_eclock);
  1985. pixclock[TAG_SHRES] = (tmp + 4) / 8; /* SHRES: 35 ns / 28 MHz */
  1986. pixclock[TAG_HIRES] = (tmp + 2) / 4; /* HIRES: 70 ns / 14 MHz */
  1987. pixclock[TAG_LORES] = (tmp + 1) / 2; /* LORES: 140 ns / 7 MHz */
  1988. }
  1989. /*
  1990. * Replace the Tag Values with the Real Pixel Clock Values
  1991. */
  1992. for (i = 0; i < NUM_TOTAL_MODES; i++) {
  1993. struct fb_videomode *mode = &ami_modedb[i];
  1994. tag = mode->pixclock;
  1995. if (tag == TAG_SHRES || tag == TAG_HIRES || tag == TAG_LORES) {
  1996. mode->pixclock = pixclock[tag];
  1997. }
  1998. }
  1999. /*
  2000. * These monitor specs are for a typical Amiga monitor (e.g. A1960)
  2001. */
  2002. if (fb_info.monspecs.hfmin == 0) {
  2003. fb_info.monspecs.hfmin = 15000;
  2004. fb_info.monspecs.hfmax = 38000;
  2005. fb_info.monspecs.vfmin = 49;
  2006. fb_info.monspecs.vfmax = 90;
  2007. }
  2008. fb_info.fbops = &amifb_ops;
  2009. fb_info.par = &currentpar;
  2010. fb_info.flags = FBINFO_DEFAULT;
  2011. if (!fb_find_mode(&fb_info.var, &fb_info, mode_option, ami_modedb,
  2012. NUM_TOTAL_MODES, &ami_modedb[defmode], 4)) {
  2013. err = -EINVAL;
  2014. goto amifb_error;
  2015. }
  2016. fb_videomode_to_modelist(ami_modedb, NUM_TOTAL_MODES,
  2017. &fb_info.modelist);
  2018. round_down_bpp = 0;
  2019. chipptr = chipalloc(fb_info.fix.smem_len+
  2020. SPRITEMEMSIZE+
  2021. DUMMYSPRITEMEMSIZE+
  2022. COPINITSIZE+
  2023. 4*COPLISTSIZE);
  2024. assignchunk(videomemory, u_long, chipptr, fb_info.fix.smem_len);
  2025. assignchunk(spritememory, u_long, chipptr, SPRITEMEMSIZE);
  2026. assignchunk(dummysprite, u_short *, chipptr, DUMMYSPRITEMEMSIZE);
  2027. assignchunk(copdisplay.init, copins *, chipptr, COPINITSIZE);
  2028. assignchunk(copdisplay.list[0][0], copins *, chipptr, COPLISTSIZE);
  2029. assignchunk(copdisplay.list[0][1], copins *, chipptr, COPLISTSIZE);
  2030. assignchunk(copdisplay.list[1][0], copins *, chipptr, COPLISTSIZE);
  2031. assignchunk(copdisplay.list[1][1], copins *, chipptr, COPLISTSIZE);
  2032. /*
  2033. * access the videomem with writethrough cache
  2034. */
  2035. fb_info.fix.smem_start = (u_long)ZTWO_PADDR(videomemory);
  2036. videomemory = (u_long)ioremap_writethrough(fb_info.fix.smem_start,
  2037. fb_info.fix.smem_len);
  2038. if (!videomemory) {
  2039. printk("amifb: WARNING! unable to map videomem cached writethrough\n");
  2040. fb_info.screen_base = (char *)ZTWO_VADDR(fb_info.fix.smem_start);
  2041. } else
  2042. fb_info.screen_base = (char *)videomemory;
  2043. memset(dummysprite, 0, DUMMYSPRITEMEMSIZE);
  2044. /*
  2045. * Enable Display DMA
  2046. */
  2047. custom.dmacon = DMAF_SETCLR | DMAF_MASTER | DMAF_RASTER | DMAF_COPPER |
  2048. DMAF_BLITTER | DMAF_SPRITE;
  2049. /*
  2050. * Make sure the Copper has something to do
  2051. */
  2052. ami_init_copper();
  2053. if (request_irq(IRQ_AMIGA_COPPER, amifb_interrupt, 0,
  2054. "fb vertb handler", &currentpar)) {
  2055. err = -EBUSY;
  2056. goto amifb_error;
  2057. }
  2058. err = fb_alloc_cmap(&fb_info.cmap, 1<<fb_info.var.bits_per_pixel, 0);
  2059. if (err)
  2060. goto amifb_error;
  2061. if (register_framebuffer(&fb_info) < 0) {
  2062. err = -EINVAL;
  2063. goto amifb_error;
  2064. }
  2065. printk("fb%d: %s frame buffer device, using %dK of video memory\n",
  2066. fb_info.node, fb_info.fix.id, fb_info.fix.smem_len>>10);
  2067. return 0;
  2068. amifb_error:
  2069. amifb_deinit();
  2070. return err;
  2071. }
  2072. static void amifb_deinit(void)
  2073. {
  2074. if (fb_info.cmap.len)
  2075. fb_dealloc_cmap(&fb_info.cmap);
  2076. chipfree();
  2077. if (videomemory)
  2078. iounmap((void*)videomemory);
  2079. release_mem_region(CUSTOM_PHYSADDR+0xe0, 0x120);
  2080. custom.dmacon = DMAF_ALL | DMAF_MASTER;
  2081. }
  2082. /*
  2083. * Blank the display.
  2084. */
  2085. static int amifb_blank(int blank, struct fb_info *info)
  2086. {
  2087. do_blank = blank ? blank : -1;
  2088. return 0;
  2089. }
  2090. /*
  2091. * Flash the cursor (called by VBlank interrupt)
  2092. */
  2093. static int flash_cursor(void)
  2094. {
  2095. static int cursorcount = 1;
  2096. if (cursormode == FB_CURSOR_FLASH) {
  2097. if (!--cursorcount) {
  2098. cursorstate = -cursorstate;
  2099. cursorcount = cursorrate;
  2100. if (!is_blanked)
  2101. return 1;
  2102. }
  2103. }
  2104. return 0;
  2105. }
  2106. /*
  2107. * VBlank Display Interrupt
  2108. */
  2109. static irqreturn_t amifb_interrupt(int irq, void *dev_id)
  2110. {
  2111. if (do_vmode_pan || do_vmode_full)
  2112. ami_update_display();
  2113. if (do_vmode_full)
  2114. ami_init_display();
  2115. if (do_vmode_pan) {
  2116. flash_cursor();
  2117. ami_rebuild_copper();
  2118. do_cursor = do_vmode_pan = 0;
  2119. } else if (do_cursor) {
  2120. flash_cursor();
  2121. ami_set_sprite();
  2122. do_cursor = 0;
  2123. } else {
  2124. if (flash_cursor())
  2125. ami_set_sprite();
  2126. }
  2127. if (do_blank) {
  2128. ami_do_blank();
  2129. do_blank = 0;
  2130. }
  2131. if (do_vmode_full) {
  2132. ami_reinit_copper();
  2133. do_vmode_full = 0;
  2134. }
  2135. return IRQ_HANDLED;
  2136. }
  2137. /* --------------------------- Hardware routines --------------------------- */
  2138. /*
  2139. * Get the video params out of `var'. If a value doesn't fit, round
  2140. * it up, if it's too big, return -EINVAL.
  2141. */
  2142. static int ami_decode_var(struct fb_var_screeninfo *var,
  2143. struct amifb_par *par)
  2144. {
  2145. u_short clk_shift, line_shift;
  2146. u_long maxfetchstop, fstrt, fsize, fconst, xres_n, yres_n;
  2147. u_int htotal, vtotal;
  2148. /*
  2149. * Find a matching Pixel Clock
  2150. */
  2151. for (clk_shift = TAG_SHRES; clk_shift <= TAG_LORES; clk_shift++)
  2152. if (var->pixclock <= pixclock[clk_shift])
  2153. break;
  2154. if (clk_shift > TAG_LORES) {
  2155. DPRINTK("pixclock too high\n");
  2156. return -EINVAL;
  2157. }
  2158. par->clk_shift = clk_shift;
  2159. /*
  2160. * Check the Geometry Values
  2161. */
  2162. if ((par->xres = var->xres) < 64)
  2163. par->xres = 64;
  2164. if ((par->yres = var->yres) < 64)
  2165. par->yres = 64;
  2166. if ((par->vxres = var->xres_virtual) < par->xres)
  2167. par->vxres = par->xres;
  2168. if ((par->vyres = var->yres_virtual) < par->yres)
  2169. par->vyres = par->yres;
  2170. par->bpp = var->bits_per_pixel;
  2171. if (!var->nonstd) {
  2172. if (par->bpp < 1)
  2173. par->bpp = 1;
  2174. if (par->bpp > maxdepth[clk_shift]) {
  2175. if (round_down_bpp && maxdepth[clk_shift])
  2176. par->bpp = maxdepth[clk_shift];
  2177. else {
  2178. DPRINTK("invalid bpp\n");
  2179. return -EINVAL;
  2180. }
  2181. }
  2182. } else if (var->nonstd == FB_NONSTD_HAM) {
  2183. if (par->bpp < 6)
  2184. par->bpp = 6;
  2185. if (par->bpp != 6) {
  2186. if (par->bpp < 8)
  2187. par->bpp = 8;
  2188. if (par->bpp != 8 || !IS_AGA) {
  2189. DPRINTK("invalid bpp for ham mode\n");
  2190. return -EINVAL;
  2191. }
  2192. }
  2193. } else {
  2194. DPRINTK("unknown nonstd mode\n");
  2195. return -EINVAL;
  2196. }
  2197. /*
  2198. * FB_VMODE_SMOOTH_XPAN will be cleared, if one of the folloing
  2199. * checks failed and smooth scrolling is not possible
  2200. */
  2201. par->vmode = var->vmode | FB_VMODE_SMOOTH_XPAN;
  2202. switch (par->vmode & FB_VMODE_MASK) {
  2203. case FB_VMODE_INTERLACED:
  2204. line_shift = 0;
  2205. break;
  2206. case FB_VMODE_NONINTERLACED:
  2207. line_shift = 1;
  2208. break;
  2209. case FB_VMODE_DOUBLE:
  2210. if (!IS_AGA) {
  2211. DPRINTK("double mode only possible with aga\n");
  2212. return -EINVAL;
  2213. }
  2214. line_shift = 2;
  2215. break;
  2216. default:
  2217. DPRINTK("unknown video mode\n");
  2218. return -EINVAL;
  2219. break;
  2220. }
  2221. par->line_shift = line_shift;
  2222. /*
  2223. * Vertical and Horizontal Timings
  2224. */
  2225. xres_n = par->xres<<clk_shift;
  2226. yres_n = par->yres<<line_shift;
  2227. par->htotal = down8((var->left_margin+par->xres+var->right_margin+var->hsync_len)<<clk_shift);
  2228. par->vtotal = down2(((var->upper_margin+par->yres+var->lower_margin+var->vsync_len)<<line_shift)+1);
  2229. if (IS_AGA)
  2230. par->bplcon3 = sprpixmode[clk_shift];
  2231. else
  2232. par->bplcon3 = 0;
  2233. if (var->sync & FB_SYNC_BROADCAST) {
  2234. par->diwstop_h = par->htotal-((var->right_margin-var->hsync_len)<<clk_shift);
  2235. if (IS_AGA)
  2236. par->diwstop_h += mod4(var->hsync_len);
  2237. else
  2238. par->diwstop_h = down4(par->diwstop_h);
  2239. par->diwstrt_h = par->diwstop_h - xres_n;
  2240. par->diwstop_v = par->vtotal-((var->lower_margin-var->vsync_len)<<line_shift);
  2241. par->diwstrt_v = par->diwstop_v - yres_n;
  2242. if (par->diwstop_h >= par->htotal+8) {
  2243. DPRINTK("invalid diwstop_h\n");
  2244. return -EINVAL;
  2245. }
  2246. if (par->diwstop_v > par->vtotal) {
  2247. DPRINTK("invalid diwstop_v\n");
  2248. return -EINVAL;
  2249. }
  2250. if (!IS_OCS) {
  2251. /* Initialize sync with some reasonable values for pwrsave */
  2252. par->hsstrt = 160;
  2253. par->hsstop = 320;
  2254. par->vsstrt = 30;
  2255. par->vsstop = 34;
  2256. } else {
  2257. par->hsstrt = 0;
  2258. par->hsstop = 0;
  2259. par->vsstrt = 0;
  2260. par->vsstop = 0;
  2261. }
  2262. if (par->vtotal > (PAL_VTOTAL+NTSC_VTOTAL)/2) {
  2263. /* PAL video mode */
  2264. if (par->htotal != PAL_HTOTAL) {
  2265. DPRINTK("htotal invalid for pal\n");
  2266. return -EINVAL;
  2267. }
  2268. if (par->diwstrt_h < PAL_DIWSTRT_H) {
  2269. DPRINTK("diwstrt_h too low for pal\n");
  2270. return -EINVAL;
  2271. }
  2272. if (par->diwstrt_v < PAL_DIWSTRT_V) {
  2273. DPRINTK("diwstrt_v too low for pal\n");
  2274. return -EINVAL;
  2275. }
  2276. htotal = PAL_HTOTAL>>clk_shift;
  2277. vtotal = PAL_VTOTAL>>1;
  2278. if (!IS_OCS) {
  2279. par->beamcon0 = BMC0_PAL;
  2280. par->bplcon3 |= BPC3_BRDRBLNK;
  2281. } else if (AMIGAHW_PRESENT(AGNUS_HR_PAL) ||
  2282. AMIGAHW_PRESENT(AGNUS_HR_NTSC)) {
  2283. par->beamcon0 = BMC0_PAL;
  2284. par->hsstop = 1;
  2285. } else if (amiga_vblank != 50) {
  2286. DPRINTK("pal not supported by this chipset\n");
  2287. return -EINVAL;
  2288. }
  2289. } else {
  2290. /* NTSC video mode
  2291. * In the AGA chipset seems to be hardware bug with BPC3_BRDRBLNK
  2292. * and NTSC activated, so than better let diwstop_h <= 1812
  2293. */
  2294. if (par->htotal != NTSC_HTOTAL) {
  2295. DPRINTK("htotal invalid for ntsc\n");
  2296. return -EINVAL;
  2297. }
  2298. if (par->diwstrt_h < NTSC_DIWSTRT_H) {
  2299. DPRINTK("diwstrt_h too low for ntsc\n");
  2300. return -EINVAL;
  2301. }
  2302. if (par->diwstrt_v < NTSC_DIWSTRT_V) {
  2303. DPRINTK("diwstrt_v too low for ntsc\n");
  2304. return -EINVAL;
  2305. }
  2306. htotal = NTSC_HTOTAL>>clk_shift;
  2307. vtotal = NTSC_VTOTAL>>1;
  2308. if (!IS_OCS) {
  2309. par->beamcon0 = 0;
  2310. par->bplcon3 |= BPC3_BRDRBLNK;
  2311. } else if (AMIGAHW_PRESENT(AGNUS_HR_PAL) ||
  2312. AMIGAHW_PRESENT(AGNUS_HR_NTSC)) {
  2313. par->beamcon0 = 0;
  2314. par->hsstop = 1;
  2315. } else if (amiga_vblank != 60) {
  2316. DPRINTK("ntsc not supported by this chipset\n");
  2317. return -EINVAL;
  2318. }
  2319. }
  2320. if (IS_OCS) {
  2321. if (par->diwstrt_h >= 1024 || par->diwstop_h < 1024 ||
  2322. par->diwstrt_v >= 512 || par->diwstop_v < 256) {
  2323. DPRINTK("invalid position for display on ocs\n");
  2324. return -EINVAL;
  2325. }
  2326. }
  2327. } else if (!IS_OCS) {
  2328. /* Programmable video mode */
  2329. par->hsstrt = var->right_margin<<clk_shift;
  2330. par->hsstop = (var->right_margin+var->hsync_len)<<clk_shift;
  2331. par->diwstop_h = par->htotal - mod8(par->hsstrt) + 8 - (1 << clk_shift);
  2332. if (!IS_AGA)
  2333. par->diwstop_h = down4(par->diwstop_h) - 16;
  2334. par->diwstrt_h = par->diwstop_h - xres_n;
  2335. par->hbstop = par->diwstrt_h + 4;
  2336. par->hbstrt = par->diwstop_h + 4;
  2337. if (par->hbstrt >= par->htotal + 8)
  2338. par->hbstrt -= par->htotal;
  2339. par->hcenter = par->hsstrt + (par->htotal >> 1);
  2340. par->vsstrt = var->lower_margin<<line_shift;
  2341. par->vsstop = (var->lower_margin+var->vsync_len)<<line_shift;
  2342. par->diwstop_v = par->vtotal;
  2343. if ((par->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED)
  2344. par->diwstop_v -= 2;
  2345. par->diwstrt_v = par->diwstop_v - yres_n;
  2346. par->vbstop = par->diwstrt_v - 2;
  2347. par->vbstrt = par->diwstop_v - 2;
  2348. if (par->vtotal > 2048) {
  2349. DPRINTK("vtotal too high\n");
  2350. return -EINVAL;
  2351. }
  2352. if (par->htotal > 2048) {
  2353. DPRINTK("htotal too high\n");
  2354. return -EINVAL;
  2355. }
  2356. par->bplcon3 |= BPC3_EXTBLKEN;
  2357. par->beamcon0 = BMC0_HARDDIS | BMC0_VARVBEN | BMC0_LOLDIS |
  2358. BMC0_VARVSYEN | BMC0_VARHSYEN | BMC0_VARBEAMEN |
  2359. BMC0_PAL | BMC0_VARCSYEN;
  2360. if (var->sync & FB_SYNC_HOR_HIGH_ACT)
  2361. par->beamcon0 |= BMC0_HSYTRUE;
  2362. if (var->sync & FB_SYNC_VERT_HIGH_ACT)
  2363. par->beamcon0 |= BMC0_VSYTRUE;
  2364. if (var->sync & FB_SYNC_COMP_HIGH_ACT)
  2365. par->beamcon0 |= BMC0_CSYTRUE;
  2366. htotal = par->htotal>>clk_shift;
  2367. vtotal = par->vtotal>>1;
  2368. } else {
  2369. DPRINTK("only broadcast modes possible for ocs\n");
  2370. return -EINVAL;
  2371. }
  2372. /*
  2373. * Checking the DMA timing
  2374. */
  2375. fconst = 16<<maxfmode<<clk_shift;
  2376. /*
  2377. * smallest window start value without turn off other dma cycles
  2378. * than sprite1-7, unless you change min_fstrt
  2379. */
  2380. fsize = ((maxfmode+clk_shift <= 1) ? fconst : 64);
  2381. fstrt = downx(fconst, par->diwstrt_h-4) - fsize;
  2382. if (fstrt < min_fstrt) {
  2383. DPRINTK("fetch start too low\n");
  2384. return -EINVAL;
  2385. }
  2386. /*
  2387. * smallest window start value where smooth scrolling is possible
  2388. */
  2389. fstrt = downx(fconst, par->diwstrt_h-fconst+(1<<clk_shift)-4) - fsize;
  2390. if (fstrt < min_fstrt)
  2391. par->vmode &= ~FB_VMODE_SMOOTH_XPAN;
  2392. maxfetchstop = down16(par->htotal - 80);
  2393. fstrt = downx(fconst, par->diwstrt_h-4) - 64 - fconst;
  2394. fsize = upx(fconst, xres_n + modx(fconst, downx(1<<clk_shift, par->diwstrt_h-4)));
  2395. if (fstrt + fsize > maxfetchstop)
  2396. par->vmode &= ~FB_VMODE_SMOOTH_XPAN;
  2397. fsize = upx(fconst, xres_n);
  2398. if (fstrt + fsize > maxfetchstop) {
  2399. DPRINTK("fetch stop too high\n");
  2400. return -EINVAL;
  2401. }
  2402. if (maxfmode + clk_shift <= 1) {
  2403. fsize = up64(xres_n + fconst - 1);
  2404. if (min_fstrt + fsize - 64 > maxfetchstop)
  2405. par->vmode &= ~FB_VMODE_SMOOTH_XPAN;
  2406. fsize = up64(xres_n);
  2407. if (min_fstrt + fsize - 64 > maxfetchstop) {
  2408. DPRINTK("fetch size too high\n");
  2409. return -EINVAL;
  2410. }
  2411. fsize -= 64;
  2412. } else
  2413. fsize -= fconst;
  2414. /*
  2415. * Check if there is enough time to update the bitplane pointers for ywrap
  2416. */
  2417. if (par->htotal-fsize-64 < par->bpp*64)
  2418. par->vmode &= ~FB_VMODE_YWRAP;
  2419. /*
  2420. * Bitplane calculations and check the Memory Requirements
  2421. */
  2422. if (amifb_ilbm) {
  2423. par->next_plane = div8(upx(16<<maxfmode, par->vxres));
  2424. par->next_line = par->bpp*par->next_plane;
  2425. if (par->next_line * par->vyres > fb_info.fix.smem_len) {
  2426. DPRINTK("too few video mem\n");
  2427. return -EINVAL;
  2428. }
  2429. } else {
  2430. par->next_line = div8(upx(16<<maxfmode, par->vxres));
  2431. par->next_plane = par->vyres*par->next_line;
  2432. if (par->next_plane * par->bpp > fb_info.fix.smem_len) {
  2433. DPRINTK("too few video mem\n");
  2434. return -EINVAL;
  2435. }
  2436. }
  2437. /*
  2438. * Hardware Register Values
  2439. */
  2440. par->bplcon0 = BPC0_COLOR | bplpixmode[clk_shift];
  2441. if (!IS_OCS)
  2442. par->bplcon0 |= BPC0_ECSENA;
  2443. if (par->bpp == 8)
  2444. par->bplcon0 |= BPC0_BPU3;
  2445. else
  2446. par->bplcon0 |= par->bpp<<12;
  2447. if (var->nonstd == FB_NONSTD_HAM)
  2448. par->bplcon0 |= BPC0_HAM;
  2449. if (var->sync & FB_SYNC_EXT)
  2450. par->bplcon0 |= BPC0_ERSY;
  2451. if (IS_AGA)
  2452. par->fmode = bplfetchmode[maxfmode];
  2453. switch (par->vmode & FB_VMODE_MASK) {
  2454. case FB_VMODE_INTERLACED:
  2455. par->bplcon0 |= BPC0_LACE;
  2456. break;
  2457. case FB_VMODE_DOUBLE:
  2458. if (IS_AGA)
  2459. par->fmode |= FMODE_SSCAN2 | FMODE_BSCAN2;
  2460. break;
  2461. }
  2462. if (!((par->vmode ^ var->vmode) & FB_VMODE_YWRAP)) {
  2463. par->xoffset = var->xoffset;
  2464. par->yoffset = var->yoffset;
  2465. if (par->vmode & FB_VMODE_YWRAP) {
  2466. if (par->xoffset || par->yoffset < 0 || par->yoffset >= par->vyres)
  2467. par->xoffset = par->yoffset = 0;
  2468. } else {
  2469. if (par->xoffset < 0 || par->xoffset > upx(16<<maxfmode, par->vxres-par->xres) ||
  2470. par->yoffset < 0 || par->yoffset > par->vyres-par->yres)
  2471. par->xoffset = par->yoffset = 0;
  2472. }
  2473. } else
  2474. par->xoffset = par->yoffset = 0;
  2475. par->crsr.crsr_x = par->crsr.crsr_y = 0;
  2476. par->crsr.spot_x = par->crsr.spot_y = 0;
  2477. par->crsr.height = par->crsr.width = 0;
  2478. return 0;
  2479. }
  2480. /*
  2481. * Fill the `var' structure based on the values in `par' and maybe
  2482. * other values read out of the hardware.
  2483. */
  2484. static int ami_encode_var(struct fb_var_screeninfo *var,
  2485. struct amifb_par *par)
  2486. {
  2487. u_short clk_shift, line_shift;
  2488. memset(var, 0, sizeof(struct fb_var_screeninfo));
  2489. clk_shift = par->clk_shift;
  2490. line_shift = par->line_shift;
  2491. var->xres = par->xres;
  2492. var->yres = par->yres;
  2493. var->xres_virtual = par->vxres;
  2494. var->yres_virtual = par->vyres;
  2495. var->xoffset = par->xoffset;
  2496. var->yoffset = par->yoffset;
  2497. var->bits_per_pixel = par->bpp;
  2498. var->grayscale = 0;
  2499. var->red.offset = 0;
  2500. var->red.msb_right = 0;
  2501. var->red.length = par->bpp;
  2502. if (par->bplcon0 & BPC0_HAM)
  2503. var->red.length -= 2;
  2504. var->blue = var->green = var->red;
  2505. var->transp.offset = 0;
  2506. var->transp.length = 0;
  2507. var->transp.msb_right = 0;
  2508. if (par->bplcon0 & BPC0_HAM)
  2509. var->nonstd = FB_NONSTD_HAM;
  2510. else
  2511. var->nonstd = 0;
  2512. var->activate = 0;
  2513. var->height = -1;
  2514. var->width = -1;
  2515. var->pixclock = pixclock[clk_shift];
  2516. if (IS_AGA && par->fmode & FMODE_BSCAN2)
  2517. var->vmode = FB_VMODE_DOUBLE;
  2518. else if (par->bplcon0 & BPC0_LACE)
  2519. var->vmode = FB_VMODE_INTERLACED;
  2520. else
  2521. var->vmode = FB_VMODE_NONINTERLACED;
  2522. if (!IS_OCS && par->beamcon0 & BMC0_VARBEAMEN) {
  2523. var->hsync_len = (par->hsstop-par->hsstrt)>>clk_shift;
  2524. var->right_margin = par->hsstrt>>clk_shift;
  2525. var->left_margin = (par->htotal>>clk_shift) - var->xres - var->right_margin - var->hsync_len;
  2526. var->vsync_len = (par->vsstop-par->vsstrt)>>line_shift;
  2527. var->lower_margin = par->vsstrt>>line_shift;
  2528. var->upper_margin = (par->vtotal>>line_shift) - var->yres - var->lower_margin - var->vsync_len;
  2529. var->sync = 0;
  2530. if (par->beamcon0 & BMC0_HSYTRUE)
  2531. var->sync |= FB_SYNC_HOR_HIGH_ACT;
  2532. if (par->beamcon0 & BMC0_VSYTRUE)
  2533. var->sync |= FB_SYNC_VERT_HIGH_ACT;
  2534. if (par->beamcon0 & BMC0_CSYTRUE)
  2535. var->sync |= FB_SYNC_COMP_HIGH_ACT;
  2536. } else {
  2537. var->sync = FB_SYNC_BROADCAST;
  2538. var->hsync_len = (152>>clk_shift) + mod4(par->diwstop_h);
  2539. var->right_margin = ((par->htotal - down4(par->diwstop_h))>>clk_shift) + var->hsync_len;
  2540. var->left_margin = (par->htotal>>clk_shift) - var->xres - var->right_margin - var->hsync_len;
  2541. var->vsync_len = 4>>line_shift;
  2542. var->lower_margin = ((par->vtotal - par->diwstop_v)>>line_shift) + var->vsync_len;
  2543. var->upper_margin = (((par->vtotal - 2)>>line_shift) + 1) - var->yres -
  2544. var->lower_margin - var->vsync_len;
  2545. }
  2546. if (par->bplcon0 & BPC0_ERSY)
  2547. var->sync |= FB_SYNC_EXT;
  2548. if (par->vmode & FB_VMODE_YWRAP)
  2549. var->vmode |= FB_VMODE_YWRAP;
  2550. return 0;
  2551. }
  2552. /*
  2553. * Pan or Wrap the Display
  2554. *
  2555. * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
  2556. * in `var'.
  2557. */
  2558. static void ami_pan_var(struct fb_var_screeninfo *var)
  2559. {
  2560. struct amifb_par *par = &currentpar;
  2561. par->xoffset = var->xoffset;
  2562. par->yoffset = var->yoffset;
  2563. if (var->vmode & FB_VMODE_YWRAP)
  2564. par->vmode |= FB_VMODE_YWRAP;
  2565. else
  2566. par->vmode &= ~FB_VMODE_YWRAP;
  2567. do_vmode_pan = 0;
  2568. ami_update_par();
  2569. do_vmode_pan = 1;
  2570. }
  2571. /*
  2572. * Update hardware
  2573. */
  2574. static int ami_update_par(void)
  2575. {
  2576. struct amifb_par *par = &currentpar;
  2577. short clk_shift, vshift, fstrt, fsize, fstop, fconst, shift, move, mod;
  2578. clk_shift = par->clk_shift;
  2579. if (!(par->vmode & FB_VMODE_SMOOTH_XPAN))
  2580. par->xoffset = upx(16<<maxfmode, par->xoffset);
  2581. fconst = 16<<maxfmode<<clk_shift;
  2582. vshift = modx(16<<maxfmode, par->xoffset);
  2583. fstrt = par->diwstrt_h - (vshift<<clk_shift) - 4;
  2584. fsize = (par->xres+vshift)<<clk_shift;
  2585. shift = modx(fconst, fstrt);
  2586. move = downx(2<<maxfmode, div8(par->xoffset));
  2587. if (maxfmode + clk_shift > 1) {
  2588. fstrt = downx(fconst, fstrt) - 64;
  2589. fsize = upx(fconst, fsize);
  2590. fstop = fstrt + fsize - fconst;
  2591. } else {
  2592. mod = fstrt = downx(fconst, fstrt) - fconst;
  2593. fstop = fstrt + upx(fconst, fsize) - 64;
  2594. fsize = up64(fsize);
  2595. fstrt = fstop - fsize + 64;
  2596. if (fstrt < min_fstrt) {
  2597. fstop += min_fstrt - fstrt;
  2598. fstrt = min_fstrt;
  2599. }
  2600. move = move - div8((mod-fstrt)>>clk_shift);
  2601. }
  2602. mod = par->next_line - div8(fsize>>clk_shift);
  2603. par->ddfstrt = fstrt;
  2604. par->ddfstop = fstop;
  2605. par->bplcon1 = hscroll2hw(shift);
  2606. par->bpl2mod = mod;
  2607. if (par->bplcon0 & BPC0_LACE)
  2608. par->bpl2mod += par->next_line;
  2609. if (IS_AGA && (par->fmode & FMODE_BSCAN2))
  2610. par->bpl1mod = -div8(fsize>>clk_shift);
  2611. else
  2612. par->bpl1mod = par->bpl2mod;
  2613. if (par->yoffset) {
  2614. par->bplpt0 = fb_info.fix.smem_start + par->next_line*par->yoffset + move;
  2615. if (par->vmode & FB_VMODE_YWRAP) {
  2616. if (par->yoffset > par->vyres-par->yres) {
  2617. par->bplpt0wrap = fb_info.fix.smem_start + move;
  2618. if (par->bplcon0 & BPC0_LACE && mod2(par->diwstrt_v+par->vyres-par->yoffset))
  2619. par->bplpt0wrap += par->next_line;
  2620. }
  2621. }
  2622. } else
  2623. par->bplpt0 = fb_info.fix.smem_start + move;
  2624. if (par->bplcon0 & BPC0_LACE && mod2(par->diwstrt_v))
  2625. par->bplpt0 += par->next_line;
  2626. return 0;
  2627. }
  2628. /*
  2629. * Set a single color register. The values supplied are already
  2630. * rounded down to the hardware's capabilities (according to the
  2631. * entries in the var structure). Return != 0 for invalid regno.
  2632. */
  2633. static int amifb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  2634. u_int transp, struct fb_info *info)
  2635. {
  2636. if (IS_AGA) {
  2637. if (regno > 255)
  2638. return 1;
  2639. } else if (currentpar.bplcon0 & BPC0_SHRES) {
  2640. if (regno > 3)
  2641. return 1;
  2642. } else {
  2643. if (regno > 31)
  2644. return 1;
  2645. }
  2646. red >>= 8;
  2647. green >>= 8;
  2648. blue >>= 8;
  2649. if (!regno) {
  2650. red0 = red;
  2651. green0 = green;
  2652. blue0 = blue;
  2653. }
  2654. /*
  2655. * Update the corresponding Hardware Color Register, unless it's Color
  2656. * Register 0 and the screen is blanked.
  2657. *
  2658. * VBlank is switched off to protect bplcon3 or ecs_palette[] from
  2659. * being changed by ami_do_blank() during the VBlank.
  2660. */
  2661. if (regno || !is_blanked) {
  2662. #if defined(CONFIG_FB_AMIGA_AGA)
  2663. if (IS_AGA) {
  2664. u_short bplcon3 = currentpar.bplcon3;
  2665. VBlankOff();
  2666. custom.bplcon3 = bplcon3 | (regno<<8 & 0xe000);
  2667. custom.color[regno&31] = rgb2hw8_high(red, green, blue);
  2668. custom.bplcon3 = bplcon3 | (regno<<8 & 0xe000) | BPC3_LOCT;
  2669. custom.color[regno&31] = rgb2hw8_low(red, green, blue);
  2670. custom.bplcon3 = bplcon3;
  2671. VBlankOn();
  2672. } else
  2673. #endif
  2674. #if defined(CONFIG_FB_AMIGA_ECS)
  2675. if (currentpar.bplcon0 & BPC0_SHRES) {
  2676. u_short color, mask;
  2677. int i;
  2678. mask = 0x3333;
  2679. color = rgb2hw2(red, green, blue);
  2680. VBlankOff();
  2681. for (i = regno+12; i >= (int)regno; i -= 4)
  2682. custom.color[i] = ecs_palette[i] = (ecs_palette[i] & mask) | color;
  2683. mask <<=2; color >>= 2;
  2684. regno = down16(regno)+mul4(mod4(regno));
  2685. for (i = regno+3; i >= (int)regno; i--)
  2686. custom.color[i] = ecs_palette[i] = (ecs_palette[i] & mask) | color;
  2687. VBlankOn();
  2688. } else
  2689. #endif
  2690. custom.color[regno] = rgb2hw4(red, green, blue);
  2691. }
  2692. return 0;
  2693. }
  2694. static void ami_update_display(void)
  2695. {
  2696. struct amifb_par *par = &currentpar;
  2697. custom.bplcon1 = par->bplcon1;
  2698. custom.bpl1mod = par->bpl1mod;
  2699. custom.bpl2mod = par->bpl2mod;
  2700. custom.ddfstrt = ddfstrt2hw(par->ddfstrt);
  2701. custom.ddfstop = ddfstop2hw(par->ddfstop);
  2702. }
  2703. /*
  2704. * Change the video mode (called by VBlank interrupt)
  2705. */
  2706. static void ami_init_display(void)
  2707. {
  2708. struct amifb_par *par = &currentpar;
  2709. int i;
  2710. custom.bplcon0 = par->bplcon0 & ~BPC0_LACE;
  2711. custom.bplcon2 = (IS_OCS ? 0 : BPC2_KILLEHB) | BPC2_PF2P2 | BPC2_PF1P2;
  2712. if (!IS_OCS) {
  2713. custom.bplcon3 = par->bplcon3;
  2714. if (IS_AGA)
  2715. custom.bplcon4 = BPC4_ESPRM4 | BPC4_OSPRM4;
  2716. if (par->beamcon0 & BMC0_VARBEAMEN) {
  2717. custom.htotal = htotal2hw(par->htotal);
  2718. custom.hbstrt = hbstrt2hw(par->hbstrt);
  2719. custom.hbstop = hbstop2hw(par->hbstop);
  2720. custom.hsstrt = hsstrt2hw(par->hsstrt);
  2721. custom.hsstop = hsstop2hw(par->hsstop);
  2722. custom.hcenter = hcenter2hw(par->hcenter);
  2723. custom.vtotal = vtotal2hw(par->vtotal);
  2724. custom.vbstrt = vbstrt2hw(par->vbstrt);
  2725. custom.vbstop = vbstop2hw(par->vbstop);
  2726. custom.vsstrt = vsstrt2hw(par->vsstrt);
  2727. custom.vsstop = vsstop2hw(par->vsstop);
  2728. }
  2729. }
  2730. if (!IS_OCS || par->hsstop)
  2731. custom.beamcon0 = par->beamcon0;
  2732. if (IS_AGA)
  2733. custom.fmode = par->fmode;
  2734. /*
  2735. * The minimum period for audio depends on htotal
  2736. */
  2737. amiga_audio_min_period = div16(par->htotal);
  2738. is_lace = par->bplcon0 & BPC0_LACE ? 1 : 0;
  2739. #if 1
  2740. if (is_lace) {
  2741. i = custom.vposr >> 15;
  2742. } else {
  2743. custom.vposw = custom.vposr | 0x8000;
  2744. i = 1;
  2745. }
  2746. #else
  2747. i = 1;
  2748. custom.vposw = custom.vposr | 0x8000;
  2749. #endif
  2750. custom.cop2lc = (u_short *)ZTWO_PADDR(copdisplay.list[currentcop][i]);
  2751. }
  2752. /*
  2753. * (Un)Blank the screen (called by VBlank interrupt)
  2754. */
  2755. static void ami_do_blank(void)
  2756. {
  2757. struct amifb_par *par = &currentpar;
  2758. #if defined(CONFIG_FB_AMIGA_AGA)
  2759. u_short bplcon3 = par->bplcon3;
  2760. #endif
  2761. u_char red, green, blue;
  2762. if (do_blank > 0) {
  2763. custom.dmacon = DMAF_RASTER | DMAF_SPRITE;
  2764. red = green = blue = 0;
  2765. if (!IS_OCS && do_blank > 1) {
  2766. switch (do_blank) {
  2767. case FB_BLANK_VSYNC_SUSPEND:
  2768. custom.hsstrt = hsstrt2hw(par->hsstrt);
  2769. custom.hsstop = hsstop2hw(par->hsstop);
  2770. custom.vsstrt = vsstrt2hw(par->vtotal+4);
  2771. custom.vsstop = vsstop2hw(par->vtotal+4);
  2772. break;
  2773. case FB_BLANK_HSYNC_SUSPEND:
  2774. custom.hsstrt = hsstrt2hw(par->htotal+16);
  2775. custom.hsstop = hsstop2hw(par->htotal+16);
  2776. custom.vsstrt = vsstrt2hw(par->vsstrt);
  2777. custom.vsstop = vsstrt2hw(par->vsstop);
  2778. break;
  2779. case FB_BLANK_POWERDOWN:
  2780. custom.hsstrt = hsstrt2hw(par->htotal+16);
  2781. custom.hsstop = hsstop2hw(par->htotal+16);
  2782. custom.vsstrt = vsstrt2hw(par->vtotal+4);
  2783. custom.vsstop = vsstop2hw(par->vtotal+4);
  2784. break;
  2785. }
  2786. if (!(par->beamcon0 & BMC0_VARBEAMEN)) {
  2787. custom.htotal = htotal2hw(par->htotal);
  2788. custom.vtotal = vtotal2hw(par->vtotal);
  2789. custom.beamcon0 = BMC0_HARDDIS | BMC0_VARBEAMEN |
  2790. BMC0_VARVSYEN | BMC0_VARHSYEN | BMC0_VARCSYEN;
  2791. }
  2792. }
  2793. } else {
  2794. custom.dmacon = DMAF_SETCLR | DMAF_RASTER | DMAF_SPRITE;
  2795. red = red0;
  2796. green = green0;
  2797. blue = blue0;
  2798. if (!IS_OCS) {
  2799. custom.hsstrt = hsstrt2hw(par->hsstrt);
  2800. custom.hsstop = hsstop2hw(par->hsstop);
  2801. custom.vsstrt = vsstrt2hw(par->vsstrt);
  2802. custom.vsstop = vsstop2hw(par->vsstop);
  2803. custom.beamcon0 = par->beamcon0;
  2804. }
  2805. }
  2806. #if defined(CONFIG_FB_AMIGA_AGA)
  2807. if (IS_AGA) {
  2808. custom.bplcon3 = bplcon3;
  2809. custom.color[0] = rgb2hw8_high(red, green, blue);
  2810. custom.bplcon3 = bplcon3 | BPC3_LOCT;
  2811. custom.color[0] = rgb2hw8_low(red, green, blue);
  2812. custom.bplcon3 = bplcon3;
  2813. } else
  2814. #endif
  2815. #if defined(CONFIG_FB_AMIGA_ECS)
  2816. if (par->bplcon0 & BPC0_SHRES) {
  2817. u_short color, mask;
  2818. int i;
  2819. mask = 0x3333;
  2820. color = rgb2hw2(red, green, blue);
  2821. for (i = 12; i >= 0; i -= 4)
  2822. custom.color[i] = ecs_palette[i] = (ecs_palette[i] & mask) | color;
  2823. mask <<=2; color >>= 2;
  2824. for (i = 3; i >= 0; i--)
  2825. custom.color[i] = ecs_palette[i] = (ecs_palette[i] & mask) | color;
  2826. } else
  2827. #endif
  2828. custom.color[0] = rgb2hw4(red, green, blue);
  2829. is_blanked = do_blank > 0 ? do_blank : 0;
  2830. }
  2831. static int ami_get_fix_cursorinfo(struct fb_fix_cursorinfo *fix)
  2832. {
  2833. struct amifb_par *par = &currentpar;
  2834. fix->crsr_width = fix->crsr_xsize = par->crsr.width;
  2835. fix->crsr_height = fix->crsr_ysize = par->crsr.height;
  2836. fix->crsr_color1 = 17;
  2837. fix->crsr_color2 = 18;
  2838. return 0;
  2839. }
  2840. static int ami_get_var_cursorinfo(struct fb_var_cursorinfo *var, u_char __user *data)
  2841. {
  2842. struct amifb_par *par = &currentpar;
  2843. register u_short *lspr, *sspr;
  2844. #ifdef __mc68000__
  2845. register u_long datawords asm ("d2");
  2846. #else
  2847. register u_long datawords;
  2848. #endif
  2849. register short delta;
  2850. register u_char color;
  2851. short height, width, bits, words;
  2852. int size, alloc;
  2853. size = par->crsr.height*par->crsr.width;
  2854. alloc = var->height*var->width;
  2855. var->height = par->crsr.height;
  2856. var->width = par->crsr.width;
  2857. var->xspot = par->crsr.spot_x;
  2858. var->yspot = par->crsr.spot_y;
  2859. if (size > var->height*var->width)
  2860. return -ENAMETOOLONG;
  2861. if (!access_ok(VERIFY_WRITE, data, size))
  2862. return -EFAULT;
  2863. delta = 1<<par->crsr.fmode;
  2864. lspr = lofsprite + (delta<<1);
  2865. if (par->bplcon0 & BPC0_LACE)
  2866. sspr = shfsprite + (delta<<1);
  2867. else
  2868. sspr = NULL;
  2869. for (height = (short)var->height-1; height >= 0; height--) {
  2870. bits = 0; words = delta; datawords = 0;
  2871. for (width = (short)var->width-1; width >= 0; width--) {
  2872. if (bits == 0) {
  2873. bits = 16; --words;
  2874. #ifdef __mc68000__
  2875. asm volatile ("movew %1@(%3:w:2),%0 ; swap %0 ; movew %1@+,%0"
  2876. : "=d" (datawords), "=a" (lspr) : "1" (lspr), "d" (delta));
  2877. #else
  2878. datawords = (*(lspr+delta) << 16) | (*lspr++);
  2879. #endif
  2880. }
  2881. --bits;
  2882. #ifdef __mc68000__
  2883. asm volatile (
  2884. "clrb %0 ; swap %1 ; lslw #1,%1 ; roxlb #1,%0 ; "
  2885. "swap %1 ; lslw #1,%1 ; roxlb #1,%0"
  2886. : "=d" (color), "=d" (datawords) : "1" (datawords));
  2887. #else
  2888. color = (((datawords >> 30) & 2)
  2889. | ((datawords >> 15) & 1));
  2890. datawords <<= 1;
  2891. #endif
  2892. put_user(color, data++);
  2893. }
  2894. if (bits > 0) {
  2895. --words; ++lspr;
  2896. }
  2897. while (--words >= 0)
  2898. ++lspr;
  2899. #ifdef __mc68000__
  2900. asm volatile ("lea %0@(%4:w:2),%0 ; tstl %1 ; jeq 1f ; exg %0,%1\n1:"
  2901. : "=a" (lspr), "=a" (sspr) : "0" (lspr), "1" (sspr), "d" (delta));
  2902. #else
  2903. lspr += delta;
  2904. if (sspr) {
  2905. u_short *tmp = lspr;
  2906. lspr = sspr;
  2907. sspr = tmp;
  2908. }
  2909. #endif
  2910. }
  2911. return 0;
  2912. }
  2913. static int ami_set_var_cursorinfo(struct fb_var_cursorinfo *var, u_char __user *data)
  2914. {
  2915. struct amifb_par *par = &currentpar;
  2916. register u_short *lspr, *sspr;
  2917. #ifdef __mc68000__
  2918. register u_long datawords asm ("d2");
  2919. #else
  2920. register u_long datawords;
  2921. #endif
  2922. register short delta;
  2923. u_short fmode;
  2924. short height, width, bits, words;
  2925. if (!var->width)
  2926. return -EINVAL;
  2927. else if (var->width <= 16)
  2928. fmode = TAG_FMODE_1;
  2929. else if (var->width <= 32)
  2930. fmode = TAG_FMODE_2;
  2931. else if (var->width <= 64)
  2932. fmode = TAG_FMODE_4;
  2933. else
  2934. return -EINVAL;
  2935. if (fmode > maxfmode)
  2936. return -EINVAL;
  2937. if (!var->height)
  2938. return -EINVAL;
  2939. if (!access_ok(VERIFY_READ, data, var->width*var->height))
  2940. return -EFAULT;
  2941. delta = 1<<fmode;
  2942. lofsprite = shfsprite = (u_short *)spritememory;
  2943. lspr = lofsprite + (delta<<1);
  2944. if (par->bplcon0 & BPC0_LACE) {
  2945. if (((var->height+4)<<fmode<<2) > SPRITEMEMSIZE)
  2946. return -EINVAL;
  2947. memset(lspr, 0, (var->height+4)<<fmode<<2);
  2948. shfsprite += ((var->height+5)&-2)<<fmode;
  2949. sspr = shfsprite + (delta<<1);
  2950. } else {
  2951. if (((var->height+2)<<fmode<<2) > SPRITEMEMSIZE)
  2952. return -EINVAL;
  2953. memset(lspr, 0, (var->height+2)<<fmode<<2);
  2954. sspr = NULL;
  2955. }
  2956. for (height = (short)var->height-1; height >= 0; height--) {
  2957. bits = 16; words = delta; datawords = 0;
  2958. for (width = (short)var->width-1; width >= 0; width--) {
  2959. unsigned long tdata = 0;
  2960. get_user(tdata, data);
  2961. data++;
  2962. #ifdef __mc68000__
  2963. asm volatile (
  2964. "lsrb #1,%2 ; roxlw #1,%0 ; swap %0 ; "
  2965. "lsrb #1,%2 ; roxlw #1,%0 ; swap %0"
  2966. : "=d" (datawords)
  2967. : "0" (datawords), "d" (tdata));
  2968. #else
  2969. datawords = ((datawords << 1) & 0xfffefffe);
  2970. datawords |= tdata & 1;
  2971. datawords |= (tdata & 2) << (16-1);
  2972. #endif
  2973. if (--bits == 0) {
  2974. bits = 16; --words;
  2975. #ifdef __mc68000__
  2976. asm volatile ("swap %2 ; movew %2,%0@(%3:w:2) ; swap %2 ; movew %2,%0@+"
  2977. : "=a" (lspr) : "0" (lspr), "d" (datawords), "d" (delta));
  2978. #else
  2979. *(lspr+delta) = (u_short) (datawords >> 16);
  2980. *lspr++ = (u_short) (datawords & 0xffff);
  2981. #endif
  2982. }
  2983. }
  2984. if (bits < 16) {
  2985. --words;
  2986. #ifdef __mc68000__
  2987. asm volatile (
  2988. "swap %2 ; lslw %4,%2 ; movew %2,%0@(%3:w:2) ; "
  2989. "swap %2 ; lslw %4,%2 ; movew %2,%0@+"
  2990. : "=a" (lspr) : "0" (lspr), "d" (datawords), "d" (delta), "d" (bits));
  2991. #else
  2992. *(lspr+delta) = (u_short) (datawords >> (16+bits));
  2993. *lspr++ = (u_short) ((datawords & 0x0000ffff) >> bits);
  2994. #endif
  2995. }
  2996. while (--words >= 0) {
  2997. #ifdef __mc68000__
  2998. asm volatile ("moveql #0,%%d0 ; movew %%d0,%0@(%2:w:2) ; movew %%d0,%0@+"
  2999. : "=a" (lspr) : "0" (lspr), "d" (delta) : "d0");
  3000. #else
  3001. *(lspr+delta) = 0;
  3002. *lspr++ = 0;
  3003. #endif
  3004. }
  3005. #ifdef __mc68000__
  3006. asm volatile ("lea %0@(%4:w:2),%0 ; tstl %1 ; jeq 1f ; exg %0,%1\n1:"
  3007. : "=a" (lspr), "=a" (sspr) : "0" (lspr), "1" (sspr), "d" (delta));
  3008. #else
  3009. lspr += delta;
  3010. if (sspr) {
  3011. u_short *tmp = lspr;
  3012. lspr = sspr;
  3013. sspr = tmp;
  3014. }
  3015. #endif
  3016. }
  3017. par->crsr.height = var->height;
  3018. par->crsr.width = var->width;
  3019. par->crsr.spot_x = var->xspot;
  3020. par->crsr.spot_y = var->yspot;
  3021. par->crsr.fmode = fmode;
  3022. if (IS_AGA) {
  3023. par->fmode &= ~(FMODE_SPAGEM | FMODE_SPR32);
  3024. par->fmode |= sprfetchmode[fmode];
  3025. custom.fmode = par->fmode;
  3026. }
  3027. return 0;
  3028. }
  3029. static int ami_get_cursorstate(struct fb_cursorstate *state)
  3030. {
  3031. struct amifb_par *par = &currentpar;
  3032. state->xoffset = par->crsr.crsr_x;
  3033. state->yoffset = par->crsr.crsr_y;
  3034. state->mode = cursormode;
  3035. return 0;
  3036. }
  3037. static int ami_set_cursorstate(struct fb_cursorstate *state)
  3038. {
  3039. struct amifb_par *par = &currentpar;
  3040. par->crsr.crsr_x = state->xoffset;
  3041. par->crsr.crsr_y = state->yoffset;
  3042. if ((cursormode = state->mode) == FB_CURSOR_OFF)
  3043. cursorstate = -1;
  3044. do_cursor = 1;
  3045. return 0;
  3046. }
  3047. static void ami_set_sprite(void)
  3048. {
  3049. struct amifb_par *par = &currentpar;
  3050. copins *copl, *cops;
  3051. u_short hs, vs, ve;
  3052. u_long pl, ps, pt;
  3053. short mx, my;
  3054. cops = copdisplay.list[currentcop][0];
  3055. copl = copdisplay.list[currentcop][1];
  3056. ps = pl = ZTWO_PADDR(dummysprite);
  3057. mx = par->crsr.crsr_x-par->crsr.spot_x;
  3058. my = par->crsr.crsr_y-par->crsr.spot_y;
  3059. if (!(par->vmode & FB_VMODE_YWRAP)) {
  3060. mx -= par->xoffset;
  3061. my -= par->yoffset;
  3062. }
  3063. if (!is_blanked && cursorstate > 0 && par->crsr.height > 0 &&
  3064. mx > -(short)par->crsr.width && mx < par->xres &&
  3065. my > -(short)par->crsr.height && my < par->yres) {
  3066. pl = ZTWO_PADDR(lofsprite);
  3067. hs = par->diwstrt_h + (mx<<par->clk_shift) - 4;
  3068. vs = par->diwstrt_v + (my<<par->line_shift);
  3069. ve = vs + (par->crsr.height<<par->line_shift);
  3070. if (par->bplcon0 & BPC0_LACE) {
  3071. ps = ZTWO_PADDR(shfsprite);
  3072. lofsprite[0] = spr2hw_pos(vs, hs);
  3073. shfsprite[0] = spr2hw_pos(vs+1, hs);
  3074. if (mod2(vs)) {
  3075. lofsprite[1<<par->crsr.fmode] = spr2hw_ctl(vs, hs, ve);
  3076. shfsprite[1<<par->crsr.fmode] = spr2hw_ctl(vs+1, hs, ve+1);
  3077. pt = pl; pl = ps; ps = pt;
  3078. } else {
  3079. lofsprite[1<<par->crsr.fmode] = spr2hw_ctl(vs, hs, ve+1);
  3080. shfsprite[1<<par->crsr.fmode] = spr2hw_ctl(vs+1, hs, ve);
  3081. }
  3082. } else {
  3083. lofsprite[0] = spr2hw_pos(vs, hs) | (IS_AGA && (par->fmode & FMODE_BSCAN2) ? 0x80 : 0);
  3084. lofsprite[1<<par->crsr.fmode] = spr2hw_ctl(vs, hs, ve);
  3085. }
  3086. }
  3087. copl[cop_spr0ptrh].w[1] = highw(pl);
  3088. copl[cop_spr0ptrl].w[1] = loww(pl);
  3089. if (par->bplcon0 & BPC0_LACE) {
  3090. cops[cop_spr0ptrh].w[1] = highw(ps);
  3091. cops[cop_spr0ptrl].w[1] = loww(ps);
  3092. }
  3093. }
  3094. /*
  3095. * Initialise the Copper Initialisation List
  3096. */
  3097. static void __init ami_init_copper(void)
  3098. {
  3099. copins *cop = copdisplay.init;
  3100. u_long p;
  3101. int i;
  3102. if (!IS_OCS) {
  3103. (cop++)->l = CMOVE(BPC0_COLOR | BPC0_SHRES | BPC0_ECSENA, bplcon0);
  3104. (cop++)->l = CMOVE(0x0181, diwstrt);
  3105. (cop++)->l = CMOVE(0x0281, diwstop);
  3106. (cop++)->l = CMOVE(0x0000, diwhigh);
  3107. } else
  3108. (cop++)->l = CMOVE(BPC0_COLOR, bplcon0);
  3109. p = ZTWO_PADDR(dummysprite);
  3110. for (i = 0; i < 8; i++) {
  3111. (cop++)->l = CMOVE(0, spr[i].pos);
  3112. (cop++)->l = CMOVE(highw(p), sprpt[i]);
  3113. (cop++)->l = CMOVE2(loww(p), sprpt[i]);
  3114. }
  3115. (cop++)->l = CMOVE(IF_SETCLR | IF_COPER, intreq);
  3116. copdisplay.wait = cop;
  3117. (cop++)->l = CEND;
  3118. (cop++)->l = CMOVE(0, copjmp2);
  3119. cop->l = CEND;
  3120. custom.cop1lc = (u_short *)ZTWO_PADDR(copdisplay.init);
  3121. custom.copjmp1 = 0;
  3122. }
  3123. static void ami_reinit_copper(void)
  3124. {
  3125. struct amifb_par *par = &currentpar;
  3126. copdisplay.init[cip_bplcon0].w[1] = ~(BPC0_BPU3 | BPC0_BPU2 | BPC0_BPU1 | BPC0_BPU0) & par->bplcon0;
  3127. copdisplay.wait->l = CWAIT(32, par->diwstrt_v-4);
  3128. }
  3129. /*
  3130. * Build the Copper List
  3131. */
  3132. static void ami_build_copper(void)
  3133. {
  3134. struct amifb_par *par = &currentpar;
  3135. copins *copl, *cops;
  3136. u_long p;
  3137. currentcop = 1 - currentcop;
  3138. copl = copdisplay.list[currentcop][1];
  3139. (copl++)->l = CWAIT(0, 10);
  3140. (copl++)->l = CMOVE(par->bplcon0, bplcon0);
  3141. (copl++)->l = CMOVE(0, sprpt[0]);
  3142. (copl++)->l = CMOVE2(0, sprpt[0]);
  3143. if (par->bplcon0 & BPC0_LACE) {
  3144. cops = copdisplay.list[currentcop][0];
  3145. (cops++)->l = CWAIT(0, 10);
  3146. (cops++)->l = CMOVE(par->bplcon0, bplcon0);
  3147. (cops++)->l = CMOVE(0, sprpt[0]);
  3148. (cops++)->l = CMOVE2(0, sprpt[0]);
  3149. (copl++)->l = CMOVE(diwstrt2hw(par->diwstrt_h, par->diwstrt_v+1), diwstrt);
  3150. (copl++)->l = CMOVE(diwstop2hw(par->diwstop_h, par->diwstop_v+1), diwstop);
  3151. (cops++)->l = CMOVE(diwstrt2hw(par->diwstrt_h, par->diwstrt_v), diwstrt);
  3152. (cops++)->l = CMOVE(diwstop2hw(par->diwstop_h, par->diwstop_v), diwstop);
  3153. if (!IS_OCS) {
  3154. (copl++)->l = CMOVE(diwhigh2hw(par->diwstrt_h, par->diwstrt_v+1,
  3155. par->diwstop_h, par->diwstop_v+1), diwhigh);
  3156. (cops++)->l = CMOVE(diwhigh2hw(par->diwstrt_h, par->diwstrt_v,
  3157. par->diwstop_h, par->diwstop_v), diwhigh);
  3158. #if 0
  3159. if (par->beamcon0 & BMC0_VARBEAMEN) {
  3160. (copl++)->l = CMOVE(vtotal2hw(par->vtotal), vtotal);
  3161. (copl++)->l = CMOVE(vbstrt2hw(par->vbstrt+1), vbstrt);
  3162. (copl++)->l = CMOVE(vbstop2hw(par->vbstop+1), vbstop);
  3163. (cops++)->l = CMOVE(vtotal2hw(par->vtotal), vtotal);
  3164. (cops++)->l = CMOVE(vbstrt2hw(par->vbstrt), vbstrt);
  3165. (cops++)->l = CMOVE(vbstop2hw(par->vbstop), vbstop);
  3166. }
  3167. #endif
  3168. }
  3169. p = ZTWO_PADDR(copdisplay.list[currentcop][0]);
  3170. (copl++)->l = CMOVE(highw(p), cop2lc);
  3171. (copl++)->l = CMOVE2(loww(p), cop2lc);
  3172. p = ZTWO_PADDR(copdisplay.list[currentcop][1]);
  3173. (cops++)->l = CMOVE(highw(p), cop2lc);
  3174. (cops++)->l = CMOVE2(loww(p), cop2lc);
  3175. copdisplay.rebuild[0] = cops;
  3176. } else {
  3177. (copl++)->l = CMOVE(diwstrt2hw(par->diwstrt_h, par->diwstrt_v), diwstrt);
  3178. (copl++)->l = CMOVE(diwstop2hw(par->diwstop_h, par->diwstop_v), diwstop);
  3179. if (!IS_OCS) {
  3180. (copl++)->l = CMOVE(diwhigh2hw(par->diwstrt_h, par->diwstrt_v,
  3181. par->diwstop_h, par->diwstop_v), diwhigh);
  3182. #if 0
  3183. if (par->beamcon0 & BMC0_VARBEAMEN) {
  3184. (copl++)->l = CMOVE(vtotal2hw(par->vtotal), vtotal);
  3185. (copl++)->l = CMOVE(vbstrt2hw(par->vbstrt), vbstrt);
  3186. (copl++)->l = CMOVE(vbstop2hw(par->vbstop), vbstop);
  3187. }
  3188. #endif
  3189. }
  3190. }
  3191. copdisplay.rebuild[1] = copl;
  3192. ami_update_par();
  3193. ami_rebuild_copper();
  3194. }
  3195. /*
  3196. * Rebuild the Copper List
  3197. *
  3198. * We only change the things that are not static
  3199. */
  3200. static void ami_rebuild_copper(void)
  3201. {
  3202. struct amifb_par *par = &currentpar;
  3203. copins *copl, *cops;
  3204. u_short line, h_end1, h_end2;
  3205. short i;
  3206. u_long p;
  3207. if (IS_AGA && maxfmode + par->clk_shift == 0)
  3208. h_end1 = par->diwstrt_h-64;
  3209. else
  3210. h_end1 = par->htotal-32;
  3211. h_end2 = par->ddfstop+64;
  3212. ami_set_sprite();
  3213. copl = copdisplay.rebuild[1];
  3214. p = par->bplpt0;
  3215. if (par->vmode & FB_VMODE_YWRAP) {
  3216. if ((par->vyres-par->yoffset) != 1 || !mod2(par->diwstrt_v)) {
  3217. if (par->yoffset > par->vyres-par->yres) {
  3218. for (i = 0; i < (short)par->bpp; i++, p += par->next_plane) {
  3219. (copl++)->l = CMOVE(highw(p), bplpt[i]);
  3220. (copl++)->l = CMOVE2(loww(p), bplpt[i]);
  3221. }
  3222. line = par->diwstrt_v + ((par->vyres-par->yoffset)<<par->line_shift) - 1;
  3223. while (line >= 512) {
  3224. (copl++)->l = CWAIT(h_end1, 510);
  3225. line -= 512;
  3226. }
  3227. if (line >= 510 && IS_AGA && maxfmode + par->clk_shift == 0)
  3228. (copl++)->l = CWAIT(h_end1, line);
  3229. else
  3230. (copl++)->l = CWAIT(h_end2, line);
  3231. p = par->bplpt0wrap;
  3232. }
  3233. } else p = par->bplpt0wrap;
  3234. }
  3235. for (i = 0; i < (short)par->bpp; i++, p += par->next_plane) {
  3236. (copl++)->l = CMOVE(highw(p), bplpt[i]);
  3237. (copl++)->l = CMOVE2(loww(p), bplpt[i]);
  3238. }
  3239. copl->l = CEND;
  3240. if (par->bplcon0 & BPC0_LACE) {
  3241. cops = copdisplay.rebuild[0];
  3242. p = par->bplpt0;
  3243. if (mod2(par->diwstrt_v))
  3244. p -= par->next_line;
  3245. else
  3246. p += par->next_line;
  3247. if (par->vmode & FB_VMODE_YWRAP) {
  3248. if ((par->vyres-par->yoffset) != 1 || mod2(par->diwstrt_v)) {
  3249. if (par->yoffset > par->vyres-par->yres+1) {
  3250. for (i = 0; i < (short)par->bpp; i++, p += par->next_plane) {
  3251. (cops++)->l = CMOVE(highw(p), bplpt[i]);
  3252. (cops++)->l = CMOVE2(loww(p), bplpt[i]);
  3253. }
  3254. line = par->diwstrt_v + ((par->vyres-par->yoffset)<<par->line_shift) - 2;
  3255. while (line >= 512) {
  3256. (cops++)->l = CWAIT(h_end1, 510);
  3257. line -= 512;
  3258. }
  3259. if (line > 510 && IS_AGA && maxfmode + par->clk_shift == 0)
  3260. (cops++)->l = CWAIT(h_end1, line);
  3261. else
  3262. (cops++)->l = CWAIT(h_end2, line);
  3263. p = par->bplpt0wrap;
  3264. if (mod2(par->diwstrt_v+par->vyres-par->yoffset))
  3265. p -= par->next_line;
  3266. else
  3267. p += par->next_line;
  3268. }
  3269. } else p = par->bplpt0wrap - par->next_line;
  3270. }
  3271. for (i = 0; i < (short)par->bpp; i++, p += par->next_plane) {
  3272. (cops++)->l = CMOVE(highw(p), bplpt[i]);
  3273. (cops++)->l = CMOVE2(loww(p), bplpt[i]);
  3274. }
  3275. cops->l = CEND;
  3276. }
  3277. }
  3278. static void __exit amifb_exit(void)
  3279. {
  3280. unregister_framebuffer(&fb_info);
  3281. amifb_deinit();
  3282. amifb_video_off();
  3283. }
  3284. module_init(amifb_init);
  3285. module_exit(amifb_exit);
  3286. MODULE_LICENSE("GPL");