amifb.c 99 KB

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