amifb.c 99 KB

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