amifb.c 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809
  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 int amifb_inverse = 0;
  772. static u32 amifb_hfmin __initdata; /* monitor hfreq lower limit (Hz) */
  773. static u32 amifb_hfmax __initdata; /* monitor hfreq upper limit (Hz) */
  774. static u16 amifb_vfmin __initdata; /* monitor vfreq lower limit (Hz) */
  775. static u16 amifb_vfmax __initdata; /* monitor vfreq upper limit (Hz) */
  776. /*
  777. * Macros for the conversion from real world values to hardware register
  778. * values
  779. *
  780. * This helps us to keep our attention on the real stuff...
  781. *
  782. * Hardware limits for AGA:
  783. *
  784. * parameter min max step
  785. * --------- --- ---- ----
  786. * diwstrt_h 0 2047 1
  787. * diwstrt_v 0 2047 1
  788. * diwstop_h 0 4095 1
  789. * diwstop_v 0 4095 1
  790. *
  791. * ddfstrt 0 2032 16
  792. * ddfstop 0 2032 16
  793. *
  794. * htotal 8 2048 8
  795. * hsstrt 0 2040 8
  796. * hsstop 0 2040 8
  797. * vtotal 1 4096 1
  798. * vsstrt 0 4095 1
  799. * vsstop 0 4095 1
  800. * hcenter 0 2040 8
  801. *
  802. * hbstrt 0 2047 1
  803. * hbstop 0 2047 1
  804. * vbstrt 0 4095 1
  805. * vbstop 0 4095 1
  806. *
  807. * Horizontal values are in 35 ns (SHRES) pixels
  808. * Vertical values are in half scanlines
  809. */
  810. /* bplcon1 (smooth scrolling) */
  811. #define hscroll2hw(hscroll) \
  812. (((hscroll) << 12 & 0x3000) | ((hscroll) << 8 & 0xc300) | \
  813. ((hscroll) << 4 & 0x0c00) | ((hscroll) << 2 & 0x00f0) | \
  814. ((hscroll)>>2 & 0x000f))
  815. /* diwstrt/diwstop/diwhigh (visible display window) */
  816. #define diwstrt2hw(diwstrt_h, diwstrt_v) \
  817. (((diwstrt_v) << 7 & 0xff00) | ((diwstrt_h)>>2 & 0x00ff))
  818. #define diwstop2hw(diwstop_h, diwstop_v) \
  819. (((diwstop_v) << 7 & 0xff00) | ((diwstop_h)>>2 & 0x00ff))
  820. #define diwhigh2hw(diwstrt_h, diwstrt_v, diwstop_h, diwstop_v) \
  821. (((diwstop_h) << 3 & 0x2000) | ((diwstop_h) << 11 & 0x1800) | \
  822. ((diwstop_v)>>1 & 0x0700) | ((diwstrt_h)>>5 & 0x0020) | \
  823. ((diwstrt_h) << 3 & 0x0018) | ((diwstrt_v)>>9 & 0x0007))
  824. /* ddfstrt/ddfstop (display DMA) */
  825. #define ddfstrt2hw(ddfstrt) div8(ddfstrt)
  826. #define ddfstop2hw(ddfstop) div8(ddfstop)
  827. /* hsstrt/hsstop/htotal/vsstrt/vsstop/vtotal/hcenter (sync timings) */
  828. #define hsstrt2hw(hsstrt) (div8(hsstrt))
  829. #define hsstop2hw(hsstop) (div8(hsstop))
  830. #define htotal2hw(htotal) (div8(htotal) - 1)
  831. #define vsstrt2hw(vsstrt) (div2(vsstrt))
  832. #define vsstop2hw(vsstop) (div2(vsstop))
  833. #define vtotal2hw(vtotal) (div2(vtotal) - 1)
  834. #define hcenter2hw(htotal) (div8(htotal))
  835. /* hbstrt/hbstop/vbstrt/vbstop (blanking timings) */
  836. #define hbstrt2hw(hbstrt) (((hbstrt) << 8 & 0x0700) | ((hbstrt)>>3 & 0x00ff))
  837. #define hbstop2hw(hbstop) (((hbstop) << 8 & 0x0700) | ((hbstop)>>3 & 0x00ff))
  838. #define vbstrt2hw(vbstrt) (div2(vbstrt))
  839. #define vbstop2hw(vbstop) (div2(vbstop))
  840. /* colour */
  841. #define rgb2hw8_high(red, green, blue) \
  842. (((red & 0xf0) << 4) | (green & 0xf0) | ((blue & 0xf0)>>4))
  843. #define rgb2hw8_low(red, green, blue) \
  844. (((red & 0x0f) << 8) | ((green & 0x0f) << 4) | (blue & 0x0f))
  845. #define rgb2hw4(red, green, blue) \
  846. (((red & 0xf0) << 4) | (green & 0xf0) | ((blue & 0xf0)>>4))
  847. #define rgb2hw2(red, green, blue) \
  848. (((red & 0xc0) << 4) | (green & 0xc0) | ((blue & 0xc0)>>4))
  849. /* sprpos/sprctl (sprite positioning) */
  850. #define spr2hw_pos(start_v, start_h) \
  851. (((start_v) << 7 & 0xff00) | ((start_h)>>3 & 0x00ff))
  852. #define spr2hw_ctl(start_v, start_h, stop_v) \
  853. (((stop_v) << 7 & 0xff00) | ((start_v)>>4 & 0x0040) | \
  854. ((stop_v)>>5 & 0x0020) | ((start_h) << 3 & 0x0018) | \
  855. ((start_v)>>7 & 0x0004) | ((stop_v)>>8 & 0x0002) | \
  856. ((start_h)>>2 & 0x0001))
  857. /* get current vertical position of beam */
  858. #define get_vbpos() ((u_short)((*(u_long volatile *)&custom.vposr >> 7) & 0xffe))
  859. /*
  860. * Copper Initialisation List
  861. */
  862. #define COPINITSIZE (sizeof(copins) * 40)
  863. enum {
  864. cip_bplcon0
  865. };
  866. /*
  867. * Long Frame/Short Frame Copper List
  868. * Don't change the order, build_copper()/rebuild_copper() rely on this
  869. */
  870. #define COPLISTSIZE (sizeof(copins) * 64)
  871. enum {
  872. cop_wait, cop_bplcon0,
  873. cop_spr0ptrh, cop_spr0ptrl,
  874. cop_diwstrt, cop_diwstop,
  875. cop_diwhigh,
  876. };
  877. /*
  878. * Pixel modes for Bitplanes and Sprites
  879. */
  880. static u_short bplpixmode[3] = {
  881. BPC0_SHRES, /* 35 ns */
  882. BPC0_HIRES, /* 70 ns */
  883. 0 /* 140 ns */
  884. };
  885. static u_short sprpixmode[3] = {
  886. BPC3_SPRES1 | BPC3_SPRES0, /* 35 ns */
  887. BPC3_SPRES1, /* 70 ns */
  888. BPC3_SPRES0 /* 140 ns */
  889. };
  890. /*
  891. * Fetch modes for Bitplanes and Sprites
  892. */
  893. static u_short bplfetchmode[3] = {
  894. 0, /* 1x */
  895. FMODE_BPL32, /* 2x */
  896. FMODE_BPAGEM | FMODE_BPL32 /* 4x */
  897. };
  898. static u_short sprfetchmode[3] = {
  899. 0, /* 1x */
  900. FMODE_SPR32, /* 2x */
  901. FMODE_SPAGEM | FMODE_SPR32 /* 4x */
  902. };
  903. /* --------------------------- Hardware routines --------------------------- */
  904. /*
  905. * Get the video params out of `var'. If a value doesn't fit, round
  906. * it up, if it's too big, return -EINVAL.
  907. */
  908. static int ami_decode_var(struct fb_var_screeninfo *var, struct amifb_par *par,
  909. const struct fb_info *info)
  910. {
  911. u_short clk_shift, line_shift;
  912. u_long maxfetchstop, fstrt, fsize, fconst, xres_n, yres_n;
  913. u_int htotal, vtotal;
  914. /*
  915. * Find a matching Pixel Clock
  916. */
  917. for (clk_shift = TAG_SHRES; clk_shift <= TAG_LORES; clk_shift++)
  918. if (var->pixclock <= pixclock[clk_shift])
  919. break;
  920. if (clk_shift > TAG_LORES) {
  921. DPRINTK("pixclock too high\n");
  922. return -EINVAL;
  923. }
  924. par->clk_shift = clk_shift;
  925. /*
  926. * Check the Geometry Values
  927. */
  928. if ((par->xres = var->xres) < 64)
  929. par->xres = 64;
  930. if ((par->yres = var->yres) < 64)
  931. par->yres = 64;
  932. if ((par->vxres = var->xres_virtual) < par->xres)
  933. par->vxres = par->xres;
  934. if ((par->vyres = var->yres_virtual) < par->yres)
  935. par->vyres = par->yres;
  936. par->bpp = var->bits_per_pixel;
  937. if (!var->nonstd) {
  938. if (par->bpp < 1)
  939. par->bpp = 1;
  940. if (par->bpp > maxdepth[clk_shift]) {
  941. if (round_down_bpp && maxdepth[clk_shift])
  942. par->bpp = maxdepth[clk_shift];
  943. else {
  944. DPRINTK("invalid bpp\n");
  945. return -EINVAL;
  946. }
  947. }
  948. } else if (var->nonstd == FB_NONSTD_HAM) {
  949. if (par->bpp < 6)
  950. par->bpp = 6;
  951. if (par->bpp != 6) {
  952. if (par->bpp < 8)
  953. par->bpp = 8;
  954. if (par->bpp != 8 || !IS_AGA) {
  955. DPRINTK("invalid bpp for ham mode\n");
  956. return -EINVAL;
  957. }
  958. }
  959. } else {
  960. DPRINTK("unknown nonstd mode\n");
  961. return -EINVAL;
  962. }
  963. /*
  964. * FB_VMODE_SMOOTH_XPAN will be cleared, if one of the folloing
  965. * checks failed and smooth scrolling is not possible
  966. */
  967. par->vmode = var->vmode | FB_VMODE_SMOOTH_XPAN;
  968. switch (par->vmode & FB_VMODE_MASK) {
  969. case FB_VMODE_INTERLACED:
  970. line_shift = 0;
  971. break;
  972. case FB_VMODE_NONINTERLACED:
  973. line_shift = 1;
  974. break;
  975. case FB_VMODE_DOUBLE:
  976. if (!IS_AGA) {
  977. DPRINTK("double mode only possible with aga\n");
  978. return -EINVAL;
  979. }
  980. line_shift = 2;
  981. break;
  982. default:
  983. DPRINTK("unknown video mode\n");
  984. return -EINVAL;
  985. break;
  986. }
  987. par->line_shift = line_shift;
  988. /*
  989. * Vertical and Horizontal Timings
  990. */
  991. xres_n = par->xres << clk_shift;
  992. yres_n = par->yres << line_shift;
  993. par->htotal = down8((var->left_margin + par->xres + var->right_margin +
  994. var->hsync_len) << clk_shift);
  995. par->vtotal =
  996. down2(((var->upper_margin + par->yres + var->lower_margin +
  997. var->vsync_len) << line_shift) + 1);
  998. if (IS_AGA)
  999. par->bplcon3 = sprpixmode[clk_shift];
  1000. else
  1001. par->bplcon3 = 0;
  1002. if (var->sync & FB_SYNC_BROADCAST) {
  1003. par->diwstop_h = par->htotal -
  1004. ((var->right_margin - var->hsync_len) << clk_shift);
  1005. if (IS_AGA)
  1006. par->diwstop_h += mod4(var->hsync_len);
  1007. else
  1008. par->diwstop_h = down4(par->diwstop_h);
  1009. par->diwstrt_h = par->diwstop_h - xres_n;
  1010. par->diwstop_v = par->vtotal -
  1011. ((var->lower_margin - var->vsync_len) << line_shift);
  1012. par->diwstrt_v = par->diwstop_v - yres_n;
  1013. if (par->diwstop_h >= par->htotal + 8) {
  1014. DPRINTK("invalid diwstop_h\n");
  1015. return -EINVAL;
  1016. }
  1017. if (par->diwstop_v > par->vtotal) {
  1018. DPRINTK("invalid diwstop_v\n");
  1019. return -EINVAL;
  1020. }
  1021. if (!IS_OCS) {
  1022. /* Initialize sync with some reasonable values for pwrsave */
  1023. par->hsstrt = 160;
  1024. par->hsstop = 320;
  1025. par->vsstrt = 30;
  1026. par->vsstop = 34;
  1027. } else {
  1028. par->hsstrt = 0;
  1029. par->hsstop = 0;
  1030. par->vsstrt = 0;
  1031. par->vsstop = 0;
  1032. }
  1033. if (par->vtotal > (PAL_VTOTAL + NTSC_VTOTAL) / 2) {
  1034. /* PAL video mode */
  1035. if (par->htotal != PAL_HTOTAL) {
  1036. DPRINTK("htotal invalid for pal\n");
  1037. return -EINVAL;
  1038. }
  1039. if (par->diwstrt_h < PAL_DIWSTRT_H) {
  1040. DPRINTK("diwstrt_h too low for pal\n");
  1041. return -EINVAL;
  1042. }
  1043. if (par->diwstrt_v < PAL_DIWSTRT_V) {
  1044. DPRINTK("diwstrt_v too low for pal\n");
  1045. return -EINVAL;
  1046. }
  1047. htotal = PAL_HTOTAL>>clk_shift;
  1048. vtotal = PAL_VTOTAL>>1;
  1049. if (!IS_OCS) {
  1050. par->beamcon0 = BMC0_PAL;
  1051. par->bplcon3 |= BPC3_BRDRBLNK;
  1052. } else if (AMIGAHW_PRESENT(AGNUS_HR_PAL) ||
  1053. AMIGAHW_PRESENT(AGNUS_HR_NTSC)) {
  1054. par->beamcon0 = BMC0_PAL;
  1055. par->hsstop = 1;
  1056. } else if (amiga_vblank != 50) {
  1057. DPRINTK("pal not supported by this chipset\n");
  1058. return -EINVAL;
  1059. }
  1060. } else {
  1061. /* NTSC video mode
  1062. * In the AGA chipset seems to be hardware bug with BPC3_BRDRBLNK
  1063. * and NTSC activated, so than better let diwstop_h <= 1812
  1064. */
  1065. if (par->htotal != NTSC_HTOTAL) {
  1066. DPRINTK("htotal invalid for ntsc\n");
  1067. return -EINVAL;
  1068. }
  1069. if (par->diwstrt_h < NTSC_DIWSTRT_H) {
  1070. DPRINTK("diwstrt_h too low for ntsc\n");
  1071. return -EINVAL;
  1072. }
  1073. if (par->diwstrt_v < NTSC_DIWSTRT_V) {
  1074. DPRINTK("diwstrt_v too low for ntsc\n");
  1075. return -EINVAL;
  1076. }
  1077. htotal = NTSC_HTOTAL>>clk_shift;
  1078. vtotal = NTSC_VTOTAL>>1;
  1079. if (!IS_OCS) {
  1080. par->beamcon0 = 0;
  1081. par->bplcon3 |= BPC3_BRDRBLNK;
  1082. } else if (AMIGAHW_PRESENT(AGNUS_HR_PAL) ||
  1083. AMIGAHW_PRESENT(AGNUS_HR_NTSC)) {
  1084. par->beamcon0 = 0;
  1085. par->hsstop = 1;
  1086. } else if (amiga_vblank != 60) {
  1087. DPRINTK("ntsc not supported by this chipset\n");
  1088. return -EINVAL;
  1089. }
  1090. }
  1091. if (IS_OCS) {
  1092. if (par->diwstrt_h >= 1024 || par->diwstop_h < 1024 ||
  1093. par->diwstrt_v >= 512 || par->diwstop_v < 256) {
  1094. DPRINTK("invalid position for display on ocs\n");
  1095. return -EINVAL;
  1096. }
  1097. }
  1098. } else if (!IS_OCS) {
  1099. /* Programmable video mode */
  1100. par->hsstrt = var->right_margin << clk_shift;
  1101. par->hsstop = (var->right_margin + var->hsync_len) << clk_shift;
  1102. par->diwstop_h = par->htotal - mod8(par->hsstrt) + 8 - (1 << clk_shift);
  1103. if (!IS_AGA)
  1104. par->diwstop_h = down4(par->diwstop_h) - 16;
  1105. par->diwstrt_h = par->diwstop_h - xres_n;
  1106. par->hbstop = par->diwstrt_h + 4;
  1107. par->hbstrt = par->diwstop_h + 4;
  1108. if (par->hbstrt >= par->htotal + 8)
  1109. par->hbstrt -= par->htotal;
  1110. par->hcenter = par->hsstrt + (par->htotal >> 1);
  1111. par->vsstrt = var->lower_margin << line_shift;
  1112. par->vsstop = (var->lower_margin + var->vsync_len) << line_shift;
  1113. par->diwstop_v = par->vtotal;
  1114. if ((par->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED)
  1115. par->diwstop_v -= 2;
  1116. par->diwstrt_v = par->diwstop_v - yres_n;
  1117. par->vbstop = par->diwstrt_v - 2;
  1118. par->vbstrt = par->diwstop_v - 2;
  1119. if (par->vtotal > 2048) {
  1120. DPRINTK("vtotal too high\n");
  1121. return -EINVAL;
  1122. }
  1123. if (par->htotal > 2048) {
  1124. DPRINTK("htotal too high\n");
  1125. return -EINVAL;
  1126. }
  1127. par->bplcon3 |= BPC3_EXTBLKEN;
  1128. par->beamcon0 = BMC0_HARDDIS | BMC0_VARVBEN | BMC0_LOLDIS |
  1129. BMC0_VARVSYEN | BMC0_VARHSYEN | BMC0_VARBEAMEN |
  1130. BMC0_PAL | BMC0_VARCSYEN;
  1131. if (var->sync & FB_SYNC_HOR_HIGH_ACT)
  1132. par->beamcon0 |= BMC0_HSYTRUE;
  1133. if (var->sync & FB_SYNC_VERT_HIGH_ACT)
  1134. par->beamcon0 |= BMC0_VSYTRUE;
  1135. if (var->sync & FB_SYNC_COMP_HIGH_ACT)
  1136. par->beamcon0 |= BMC0_CSYTRUE;
  1137. htotal = par->htotal>>clk_shift;
  1138. vtotal = par->vtotal>>1;
  1139. } else {
  1140. DPRINTK("only broadcast modes possible for ocs\n");
  1141. return -EINVAL;
  1142. }
  1143. /*
  1144. * Checking the DMA timing
  1145. */
  1146. fconst = 16 << maxfmode << clk_shift;
  1147. /*
  1148. * smallest window start value without turn off other dma cycles
  1149. * than sprite1-7, unless you change min_fstrt
  1150. */
  1151. fsize = ((maxfmode + clk_shift <= 1) ? fconst : 64);
  1152. fstrt = downx(fconst, par->diwstrt_h - 4) - fsize;
  1153. if (fstrt < min_fstrt) {
  1154. DPRINTK("fetch start too low\n");
  1155. return -EINVAL;
  1156. }
  1157. /*
  1158. * smallest window start value where smooth scrolling is possible
  1159. */
  1160. fstrt = downx(fconst, par->diwstrt_h - fconst + (1 << clk_shift) - 4) -
  1161. fsize;
  1162. if (fstrt < min_fstrt)
  1163. par->vmode &= ~FB_VMODE_SMOOTH_XPAN;
  1164. maxfetchstop = down16(par->htotal - 80);
  1165. fstrt = downx(fconst, par->diwstrt_h - 4) - 64 - fconst;
  1166. fsize = upx(fconst, xres_n +
  1167. modx(fconst, downx(1 << clk_shift, par->diwstrt_h - 4)));
  1168. if (fstrt + fsize > maxfetchstop)
  1169. par->vmode &= ~FB_VMODE_SMOOTH_XPAN;
  1170. fsize = upx(fconst, xres_n);
  1171. if (fstrt + fsize > maxfetchstop) {
  1172. DPRINTK("fetch stop too high\n");
  1173. return -EINVAL;
  1174. }
  1175. if (maxfmode + clk_shift <= 1) {
  1176. fsize = up64(xres_n + fconst - 1);
  1177. if (min_fstrt + fsize - 64 > maxfetchstop)
  1178. par->vmode &= ~FB_VMODE_SMOOTH_XPAN;
  1179. fsize = up64(xres_n);
  1180. if (min_fstrt + fsize - 64 > maxfetchstop) {
  1181. DPRINTK("fetch size too high\n");
  1182. return -EINVAL;
  1183. }
  1184. fsize -= 64;
  1185. } else
  1186. fsize -= fconst;
  1187. /*
  1188. * Check if there is enough time to update the bitplane pointers for ywrap
  1189. */
  1190. if (par->htotal - fsize - 64 < par->bpp * 64)
  1191. par->vmode &= ~FB_VMODE_YWRAP;
  1192. /*
  1193. * Bitplane calculations and check the Memory Requirements
  1194. */
  1195. if (amifb_ilbm) {
  1196. par->next_plane = div8(upx(16 << maxfmode, par->vxres));
  1197. par->next_line = par->bpp * par->next_plane;
  1198. if (par->next_line * par->vyres > info->fix.smem_len) {
  1199. DPRINTK("too few video mem\n");
  1200. return -EINVAL;
  1201. }
  1202. } else {
  1203. par->next_line = div8(upx(16 << maxfmode, par->vxres));
  1204. par->next_plane = par->vyres * par->next_line;
  1205. if (par->next_plane * par->bpp > info->fix.smem_len) {
  1206. DPRINTK("too few video mem\n");
  1207. return -EINVAL;
  1208. }
  1209. }
  1210. /*
  1211. * Hardware Register Values
  1212. */
  1213. par->bplcon0 = BPC0_COLOR | bplpixmode[clk_shift];
  1214. if (!IS_OCS)
  1215. par->bplcon0 |= BPC0_ECSENA;
  1216. if (par->bpp == 8)
  1217. par->bplcon0 |= BPC0_BPU3;
  1218. else
  1219. par->bplcon0 |= par->bpp << 12;
  1220. if (var->nonstd == FB_NONSTD_HAM)
  1221. par->bplcon0 |= BPC0_HAM;
  1222. if (var->sync & FB_SYNC_EXT)
  1223. par->bplcon0 |= BPC0_ERSY;
  1224. if (IS_AGA)
  1225. par->fmode = bplfetchmode[maxfmode];
  1226. switch (par->vmode & FB_VMODE_MASK) {
  1227. case FB_VMODE_INTERLACED:
  1228. par->bplcon0 |= BPC0_LACE;
  1229. break;
  1230. case FB_VMODE_DOUBLE:
  1231. if (IS_AGA)
  1232. par->fmode |= FMODE_SSCAN2 | FMODE_BSCAN2;
  1233. break;
  1234. }
  1235. if (!((par->vmode ^ var->vmode) & FB_VMODE_YWRAP)) {
  1236. par->xoffset = var->xoffset;
  1237. par->yoffset = var->yoffset;
  1238. if (par->vmode & FB_VMODE_YWRAP) {
  1239. if (par->xoffset || par->yoffset < 0 ||
  1240. par->yoffset >= par->vyres)
  1241. par->xoffset = par->yoffset = 0;
  1242. } else {
  1243. if (par->xoffset < 0 ||
  1244. par->xoffset > upx(16 << maxfmode, par->vxres - par->xres) ||
  1245. par->yoffset < 0 || par->yoffset > par->vyres - par->yres)
  1246. par->xoffset = par->yoffset = 0;
  1247. }
  1248. } else
  1249. par->xoffset = par->yoffset = 0;
  1250. par->crsr.crsr_x = par->crsr.crsr_y = 0;
  1251. par->crsr.spot_x = par->crsr.spot_y = 0;
  1252. par->crsr.height = par->crsr.width = 0;
  1253. return 0;
  1254. }
  1255. /*
  1256. * Fill the `var' structure based on the values in `par' and maybe
  1257. * other values read out of the hardware.
  1258. */
  1259. static void ami_encode_var(struct fb_var_screeninfo *var,
  1260. struct amifb_par *par)
  1261. {
  1262. u_short clk_shift, line_shift;
  1263. memset(var, 0, sizeof(struct fb_var_screeninfo));
  1264. clk_shift = par->clk_shift;
  1265. line_shift = par->line_shift;
  1266. var->xres = par->xres;
  1267. var->yres = par->yres;
  1268. var->xres_virtual = par->vxres;
  1269. var->yres_virtual = par->vyres;
  1270. var->xoffset = par->xoffset;
  1271. var->yoffset = par->yoffset;
  1272. var->bits_per_pixel = par->bpp;
  1273. var->grayscale = 0;
  1274. var->red.offset = 0;
  1275. var->red.msb_right = 0;
  1276. var->red.length = par->bpp;
  1277. if (par->bplcon0 & BPC0_HAM)
  1278. var->red.length -= 2;
  1279. var->blue = var->green = var->red;
  1280. var->transp.offset = 0;
  1281. var->transp.length = 0;
  1282. var->transp.msb_right = 0;
  1283. if (par->bplcon0 & BPC0_HAM)
  1284. var->nonstd = FB_NONSTD_HAM;
  1285. else
  1286. var->nonstd = 0;
  1287. var->activate = 0;
  1288. var->height = -1;
  1289. var->width = -1;
  1290. var->pixclock = pixclock[clk_shift];
  1291. if (IS_AGA && par->fmode & FMODE_BSCAN2)
  1292. var->vmode = FB_VMODE_DOUBLE;
  1293. else if (par->bplcon0 & BPC0_LACE)
  1294. var->vmode = FB_VMODE_INTERLACED;
  1295. else
  1296. var->vmode = FB_VMODE_NONINTERLACED;
  1297. if (!IS_OCS && par->beamcon0 & BMC0_VARBEAMEN) {
  1298. var->hsync_len = (par->hsstop - par->hsstrt)>>clk_shift;
  1299. var->right_margin = par->hsstrt>>clk_shift;
  1300. var->left_margin = (par->htotal>>clk_shift) - var->xres - var->right_margin - var->hsync_len;
  1301. var->vsync_len = (par->vsstop - par->vsstrt)>>line_shift;
  1302. var->lower_margin = par->vsstrt>>line_shift;
  1303. var->upper_margin = (par->vtotal>>line_shift) - var->yres - var->lower_margin - var->vsync_len;
  1304. var->sync = 0;
  1305. if (par->beamcon0 & BMC0_HSYTRUE)
  1306. var->sync |= FB_SYNC_HOR_HIGH_ACT;
  1307. if (par->beamcon0 & BMC0_VSYTRUE)
  1308. var->sync |= FB_SYNC_VERT_HIGH_ACT;
  1309. if (par->beamcon0 & BMC0_CSYTRUE)
  1310. var->sync |= FB_SYNC_COMP_HIGH_ACT;
  1311. } else {
  1312. var->sync = FB_SYNC_BROADCAST;
  1313. var->hsync_len = (152>>clk_shift) + mod4(par->diwstop_h);
  1314. var->right_margin = ((par->htotal - down4(par->diwstop_h))>>clk_shift) + var->hsync_len;
  1315. var->left_margin = (par->htotal>>clk_shift) - var->xres - var->right_margin - var->hsync_len;
  1316. var->vsync_len = 4>>line_shift;
  1317. var->lower_margin = ((par->vtotal - par->diwstop_v)>>line_shift) + var->vsync_len;
  1318. var->upper_margin = (((par->vtotal - 2)>>line_shift) + 1) - var->yres -
  1319. var->lower_margin - var->vsync_len;
  1320. }
  1321. if (par->bplcon0 & BPC0_ERSY)
  1322. var->sync |= FB_SYNC_EXT;
  1323. if (par->vmode & FB_VMODE_YWRAP)
  1324. var->vmode |= FB_VMODE_YWRAP;
  1325. }
  1326. /*
  1327. * Update hardware
  1328. */
  1329. static void ami_update_par(struct fb_info *info)
  1330. {
  1331. struct amifb_par *par = info->par;
  1332. short clk_shift, vshift, fstrt, fsize, fstop, fconst, shift, move, mod;
  1333. clk_shift = par->clk_shift;
  1334. if (!(par->vmode & FB_VMODE_SMOOTH_XPAN))
  1335. par->xoffset = upx(16 << maxfmode, par->xoffset);
  1336. fconst = 16 << maxfmode << clk_shift;
  1337. vshift = modx(16 << maxfmode, par->xoffset);
  1338. fstrt = par->diwstrt_h - (vshift << clk_shift) - 4;
  1339. fsize = (par->xres + vshift) << clk_shift;
  1340. shift = modx(fconst, fstrt);
  1341. move = downx(2 << maxfmode, div8(par->xoffset));
  1342. if (maxfmode + clk_shift > 1) {
  1343. fstrt = downx(fconst, fstrt) - 64;
  1344. fsize = upx(fconst, fsize);
  1345. fstop = fstrt + fsize - fconst;
  1346. } else {
  1347. mod = fstrt = downx(fconst, fstrt) - fconst;
  1348. fstop = fstrt + upx(fconst, fsize) - 64;
  1349. fsize = up64(fsize);
  1350. fstrt = fstop - fsize + 64;
  1351. if (fstrt < min_fstrt) {
  1352. fstop += min_fstrt - fstrt;
  1353. fstrt = min_fstrt;
  1354. }
  1355. move = move - div8((mod - fstrt)>>clk_shift);
  1356. }
  1357. mod = par->next_line - div8(fsize>>clk_shift);
  1358. par->ddfstrt = fstrt;
  1359. par->ddfstop = fstop;
  1360. par->bplcon1 = hscroll2hw(shift);
  1361. par->bpl2mod = mod;
  1362. if (par->bplcon0 & BPC0_LACE)
  1363. par->bpl2mod += par->next_line;
  1364. if (IS_AGA && (par->fmode & FMODE_BSCAN2))
  1365. par->bpl1mod = -div8(fsize>>clk_shift);
  1366. else
  1367. par->bpl1mod = par->bpl2mod;
  1368. if (par->yoffset) {
  1369. par->bplpt0 = info->fix.smem_start +
  1370. par->next_line * par->yoffset + move;
  1371. if (par->vmode & FB_VMODE_YWRAP) {
  1372. if (par->yoffset > par->vyres - par->yres) {
  1373. par->bplpt0wrap = info->fix.smem_start + move;
  1374. if (par->bplcon0 & BPC0_LACE &&
  1375. mod2(par->diwstrt_v + par->vyres -
  1376. par->yoffset))
  1377. par->bplpt0wrap += par->next_line;
  1378. }
  1379. }
  1380. } else
  1381. par->bplpt0 = info->fix.smem_start + move;
  1382. if (par->bplcon0 & BPC0_LACE && mod2(par->diwstrt_v))
  1383. par->bplpt0 += par->next_line;
  1384. }
  1385. /*
  1386. * Pan or Wrap the Display
  1387. *
  1388. * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
  1389. * in `var'.
  1390. */
  1391. static void ami_pan_var(struct fb_var_screeninfo *var, struct fb_info *info)
  1392. {
  1393. struct amifb_par *par = info->par;
  1394. par->xoffset = var->xoffset;
  1395. par->yoffset = var->yoffset;
  1396. if (var->vmode & FB_VMODE_YWRAP)
  1397. par->vmode |= FB_VMODE_YWRAP;
  1398. else
  1399. par->vmode &= ~FB_VMODE_YWRAP;
  1400. do_vmode_pan = 0;
  1401. ami_update_par(info);
  1402. do_vmode_pan = 1;
  1403. }
  1404. static void ami_update_display(const struct amifb_par *par)
  1405. {
  1406. custom.bplcon1 = par->bplcon1;
  1407. custom.bpl1mod = par->bpl1mod;
  1408. custom.bpl2mod = par->bpl2mod;
  1409. custom.ddfstrt = ddfstrt2hw(par->ddfstrt);
  1410. custom.ddfstop = ddfstop2hw(par->ddfstop);
  1411. }
  1412. /*
  1413. * Change the video mode (called by VBlank interrupt)
  1414. */
  1415. static void ami_init_display(const struct amifb_par *par)
  1416. {
  1417. int i;
  1418. custom.bplcon0 = par->bplcon0 & ~BPC0_LACE;
  1419. custom.bplcon2 = (IS_OCS ? 0 : BPC2_KILLEHB) | BPC2_PF2P2 | BPC2_PF1P2;
  1420. if (!IS_OCS) {
  1421. custom.bplcon3 = par->bplcon3;
  1422. if (IS_AGA)
  1423. custom.bplcon4 = BPC4_ESPRM4 | BPC4_OSPRM4;
  1424. if (par->beamcon0 & BMC0_VARBEAMEN) {
  1425. custom.htotal = htotal2hw(par->htotal);
  1426. custom.hbstrt = hbstrt2hw(par->hbstrt);
  1427. custom.hbstop = hbstop2hw(par->hbstop);
  1428. custom.hsstrt = hsstrt2hw(par->hsstrt);
  1429. custom.hsstop = hsstop2hw(par->hsstop);
  1430. custom.hcenter = hcenter2hw(par->hcenter);
  1431. custom.vtotal = vtotal2hw(par->vtotal);
  1432. custom.vbstrt = vbstrt2hw(par->vbstrt);
  1433. custom.vbstop = vbstop2hw(par->vbstop);
  1434. custom.vsstrt = vsstrt2hw(par->vsstrt);
  1435. custom.vsstop = vsstop2hw(par->vsstop);
  1436. }
  1437. }
  1438. if (!IS_OCS || par->hsstop)
  1439. custom.beamcon0 = par->beamcon0;
  1440. if (IS_AGA)
  1441. custom.fmode = par->fmode;
  1442. /*
  1443. * The minimum period for audio depends on htotal
  1444. */
  1445. amiga_audio_min_period = div16(par->htotal);
  1446. is_lace = par->bplcon0 & BPC0_LACE ? 1 : 0;
  1447. #if 1
  1448. if (is_lace) {
  1449. i = custom.vposr >> 15;
  1450. } else {
  1451. custom.vposw = custom.vposr | 0x8000;
  1452. i = 1;
  1453. }
  1454. #else
  1455. i = 1;
  1456. custom.vposw = custom.vposr | 0x8000;
  1457. #endif
  1458. custom.cop2lc = (u_short *)ZTWO_PADDR(copdisplay.list[currentcop][i]);
  1459. }
  1460. /*
  1461. * (Un)Blank the screen (called by VBlank interrupt)
  1462. */
  1463. static void ami_do_blank(const struct amifb_par *par)
  1464. {
  1465. #if defined(CONFIG_FB_AMIGA_AGA)
  1466. u_short bplcon3 = par->bplcon3;
  1467. #endif
  1468. u_char red, green, blue;
  1469. if (do_blank > 0) {
  1470. custom.dmacon = DMAF_RASTER | DMAF_SPRITE;
  1471. red = green = blue = 0;
  1472. if (!IS_OCS && do_blank > 1) {
  1473. switch (do_blank) {
  1474. case FB_BLANK_VSYNC_SUSPEND:
  1475. custom.hsstrt = hsstrt2hw(par->hsstrt);
  1476. custom.hsstop = hsstop2hw(par->hsstop);
  1477. custom.vsstrt = vsstrt2hw(par->vtotal + 4);
  1478. custom.vsstop = vsstop2hw(par->vtotal + 4);
  1479. break;
  1480. case FB_BLANK_HSYNC_SUSPEND:
  1481. custom.hsstrt = hsstrt2hw(par->htotal + 16);
  1482. custom.hsstop = hsstop2hw(par->htotal + 16);
  1483. custom.vsstrt = vsstrt2hw(par->vsstrt);
  1484. custom.vsstop = vsstrt2hw(par->vsstop);
  1485. break;
  1486. case FB_BLANK_POWERDOWN:
  1487. custom.hsstrt = hsstrt2hw(par->htotal + 16);
  1488. custom.hsstop = hsstop2hw(par->htotal + 16);
  1489. custom.vsstrt = vsstrt2hw(par->vtotal + 4);
  1490. custom.vsstop = vsstop2hw(par->vtotal + 4);
  1491. break;
  1492. }
  1493. if (!(par->beamcon0 & BMC0_VARBEAMEN)) {
  1494. custom.htotal = htotal2hw(par->htotal);
  1495. custom.vtotal = vtotal2hw(par->vtotal);
  1496. custom.beamcon0 = BMC0_HARDDIS | BMC0_VARBEAMEN |
  1497. BMC0_VARVSYEN | BMC0_VARHSYEN | BMC0_VARCSYEN;
  1498. }
  1499. }
  1500. } else {
  1501. custom.dmacon = DMAF_SETCLR | DMAF_RASTER | DMAF_SPRITE;
  1502. red = red0;
  1503. green = green0;
  1504. blue = blue0;
  1505. if (!IS_OCS) {
  1506. custom.hsstrt = hsstrt2hw(par->hsstrt);
  1507. custom.hsstop = hsstop2hw(par->hsstop);
  1508. custom.vsstrt = vsstrt2hw(par->vsstrt);
  1509. custom.vsstop = vsstop2hw(par->vsstop);
  1510. custom.beamcon0 = par->beamcon0;
  1511. }
  1512. }
  1513. #if defined(CONFIG_FB_AMIGA_AGA)
  1514. if (IS_AGA) {
  1515. custom.bplcon3 = bplcon3;
  1516. custom.color[0] = rgb2hw8_high(red, green, blue);
  1517. custom.bplcon3 = bplcon3 | BPC3_LOCT;
  1518. custom.color[0] = rgb2hw8_low(red, green, blue);
  1519. custom.bplcon3 = bplcon3;
  1520. } else
  1521. #endif
  1522. #if defined(CONFIG_FB_AMIGA_ECS)
  1523. if (par->bplcon0 & BPC0_SHRES) {
  1524. u_short color, mask;
  1525. int i;
  1526. mask = 0x3333;
  1527. color = rgb2hw2(red, green, blue);
  1528. for (i = 12; i >= 0; i -= 4)
  1529. custom.color[i] = ecs_palette[i] = (ecs_palette[i] & mask) | color;
  1530. mask <<= 2; color >>= 2;
  1531. for (i = 3; i >= 0; i--)
  1532. custom.color[i] = ecs_palette[i] = (ecs_palette[i] & mask) | color;
  1533. } else
  1534. #endif
  1535. custom.color[0] = rgb2hw4(red, green, blue);
  1536. is_blanked = do_blank > 0 ? do_blank : 0;
  1537. }
  1538. static int ami_get_fix_cursorinfo(struct fb_fix_cursorinfo *fix,
  1539. const struct amifb_par *par)
  1540. {
  1541. fix->crsr_width = fix->crsr_xsize = par->crsr.width;
  1542. fix->crsr_height = fix->crsr_ysize = par->crsr.height;
  1543. fix->crsr_color1 = 17;
  1544. fix->crsr_color2 = 18;
  1545. return 0;
  1546. }
  1547. static int ami_get_var_cursorinfo(struct fb_var_cursorinfo *var,
  1548. u_char __user *data,
  1549. const struct amifb_par *par)
  1550. {
  1551. register u_short *lspr, *sspr;
  1552. #ifdef __mc68000__
  1553. register u_long datawords asm ("d2");
  1554. #else
  1555. register u_long datawords;
  1556. #endif
  1557. register short delta;
  1558. register u_char color;
  1559. short height, width, bits, words;
  1560. int size, alloc;
  1561. size = par->crsr.height * par->crsr.width;
  1562. alloc = var->height * var->width;
  1563. var->height = par->crsr.height;
  1564. var->width = par->crsr.width;
  1565. var->xspot = par->crsr.spot_x;
  1566. var->yspot = par->crsr.spot_y;
  1567. if (size > var->height * var->width)
  1568. return -ENAMETOOLONG;
  1569. if (!access_ok(VERIFY_WRITE, data, size))
  1570. return -EFAULT;
  1571. delta = 1 << par->crsr.fmode;
  1572. lspr = lofsprite + (delta << 1);
  1573. if (par->bplcon0 & BPC0_LACE)
  1574. sspr = shfsprite + (delta << 1);
  1575. else
  1576. sspr = NULL;
  1577. for (height = (short)var->height - 1; height >= 0; height--) {
  1578. bits = 0; words = delta; datawords = 0;
  1579. for (width = (short)var->width - 1; width >= 0; width--) {
  1580. if (bits == 0) {
  1581. bits = 16; --words;
  1582. #ifdef __mc68000__
  1583. asm volatile ("movew %1@(%3:w:2),%0 ; swap %0 ; movew %1@+,%0"
  1584. : "=d" (datawords), "=a" (lspr) : "1" (lspr), "d" (delta));
  1585. #else
  1586. datawords = (*(lspr + delta) << 16) | (*lspr++);
  1587. #endif
  1588. }
  1589. --bits;
  1590. #ifdef __mc68000__
  1591. asm volatile (
  1592. "clrb %0 ; swap %1 ; lslw #1,%1 ; roxlb #1,%0 ; "
  1593. "swap %1 ; lslw #1,%1 ; roxlb #1,%0"
  1594. : "=d" (color), "=d" (datawords) : "1" (datawords));
  1595. #else
  1596. color = (((datawords >> 30) & 2)
  1597. | ((datawords >> 15) & 1));
  1598. datawords <<= 1;
  1599. #endif
  1600. put_user(color, data++);
  1601. }
  1602. if (bits > 0) {
  1603. --words; ++lspr;
  1604. }
  1605. while (--words >= 0)
  1606. ++lspr;
  1607. #ifdef __mc68000__
  1608. asm volatile ("lea %0@(%4:w:2),%0 ; tstl %1 ; jeq 1f ; exg %0,%1\n1:"
  1609. : "=a" (lspr), "=a" (sspr) : "0" (lspr), "1" (sspr), "d" (delta));
  1610. #else
  1611. lspr += delta;
  1612. if (sspr) {
  1613. u_short *tmp = lspr;
  1614. lspr = sspr;
  1615. sspr = tmp;
  1616. }
  1617. #endif
  1618. }
  1619. return 0;
  1620. }
  1621. static int ami_set_var_cursorinfo(struct fb_var_cursorinfo *var,
  1622. u_char __user *data, struct amifb_par *par)
  1623. {
  1624. register u_short *lspr, *sspr;
  1625. #ifdef __mc68000__
  1626. register u_long datawords asm ("d2");
  1627. #else
  1628. register u_long datawords;
  1629. #endif
  1630. register short delta;
  1631. u_short fmode;
  1632. short height, width, bits, words;
  1633. if (!var->width)
  1634. return -EINVAL;
  1635. else if (var->width <= 16)
  1636. fmode = TAG_FMODE_1;
  1637. else if (var->width <= 32)
  1638. fmode = TAG_FMODE_2;
  1639. else if (var->width <= 64)
  1640. fmode = TAG_FMODE_4;
  1641. else
  1642. return -EINVAL;
  1643. if (fmode > maxfmode)
  1644. return -EINVAL;
  1645. if (!var->height)
  1646. return -EINVAL;
  1647. if (!access_ok(VERIFY_READ, data, var->width * var->height))
  1648. return -EFAULT;
  1649. delta = 1 << fmode;
  1650. lofsprite = shfsprite = (u_short *)spritememory;
  1651. lspr = lofsprite + (delta << 1);
  1652. if (par->bplcon0 & BPC0_LACE) {
  1653. if (((var->height + 4) << fmode << 2) > SPRITEMEMSIZE)
  1654. return -EINVAL;
  1655. memset(lspr, 0, (var->height + 4) << fmode << 2);
  1656. shfsprite += ((var->height + 5)&-2) << fmode;
  1657. sspr = shfsprite + (delta << 1);
  1658. } else {
  1659. if (((var->height + 2) << fmode << 2) > SPRITEMEMSIZE)
  1660. return -EINVAL;
  1661. memset(lspr, 0, (var->height + 2) << fmode << 2);
  1662. sspr = NULL;
  1663. }
  1664. for (height = (short)var->height - 1; height >= 0; height--) {
  1665. bits = 16; words = delta; datawords = 0;
  1666. for (width = (short)var->width - 1; width >= 0; width--) {
  1667. unsigned long tdata = 0;
  1668. get_user(tdata, data);
  1669. data++;
  1670. #ifdef __mc68000__
  1671. asm volatile (
  1672. "lsrb #1,%2 ; roxlw #1,%0 ; swap %0 ; "
  1673. "lsrb #1,%2 ; roxlw #1,%0 ; swap %0"
  1674. : "=d" (datawords)
  1675. : "0" (datawords), "d" (tdata));
  1676. #else
  1677. datawords = ((datawords << 1) & 0xfffefffe);
  1678. datawords |= tdata & 1;
  1679. datawords |= (tdata & 2) << (16 - 1);
  1680. #endif
  1681. if (--bits == 0) {
  1682. bits = 16; --words;
  1683. #ifdef __mc68000__
  1684. asm volatile ("swap %2 ; movew %2,%0@(%3:w:2) ; swap %2 ; movew %2,%0@+"
  1685. : "=a" (lspr) : "0" (lspr), "d" (datawords), "d" (delta));
  1686. #else
  1687. *(lspr + delta) = (u_short) (datawords >> 16);
  1688. *lspr++ = (u_short) (datawords & 0xffff);
  1689. #endif
  1690. }
  1691. }
  1692. if (bits < 16) {
  1693. --words;
  1694. #ifdef __mc68000__
  1695. asm volatile (
  1696. "swap %2 ; lslw %4,%2 ; movew %2,%0@(%3:w:2) ; "
  1697. "swap %2 ; lslw %4,%2 ; movew %2,%0@+"
  1698. : "=a" (lspr) : "0" (lspr), "d" (datawords), "d" (delta), "d" (bits));
  1699. #else
  1700. *(lspr + delta) = (u_short) (datawords >> (16 + bits));
  1701. *lspr++ = (u_short) ((datawords & 0x0000ffff) >> bits);
  1702. #endif
  1703. }
  1704. while (--words >= 0) {
  1705. #ifdef __mc68000__
  1706. asm volatile ("moveql #0,%%d0 ; movew %%d0,%0@(%2:w:2) ; movew %%d0,%0@+"
  1707. : "=a" (lspr) : "0" (lspr), "d" (delta) : "d0");
  1708. #else
  1709. *(lspr + delta) = 0;
  1710. *lspr++ = 0;
  1711. #endif
  1712. }
  1713. #ifdef __mc68000__
  1714. asm volatile ("lea %0@(%4:w:2),%0 ; tstl %1 ; jeq 1f ; exg %0,%1\n1:"
  1715. : "=a" (lspr), "=a" (sspr) : "0" (lspr), "1" (sspr), "d" (delta));
  1716. #else
  1717. lspr += delta;
  1718. if (sspr) {
  1719. u_short *tmp = lspr;
  1720. lspr = sspr;
  1721. sspr = tmp;
  1722. }
  1723. #endif
  1724. }
  1725. par->crsr.height = var->height;
  1726. par->crsr.width = var->width;
  1727. par->crsr.spot_x = var->xspot;
  1728. par->crsr.spot_y = var->yspot;
  1729. par->crsr.fmode = fmode;
  1730. if (IS_AGA) {
  1731. par->fmode &= ~(FMODE_SPAGEM | FMODE_SPR32);
  1732. par->fmode |= sprfetchmode[fmode];
  1733. custom.fmode = par->fmode;
  1734. }
  1735. return 0;
  1736. }
  1737. static int ami_get_cursorstate(struct fb_cursorstate *state,
  1738. const struct amifb_par *par)
  1739. {
  1740. state->xoffset = par->crsr.crsr_x;
  1741. state->yoffset = par->crsr.crsr_y;
  1742. state->mode = cursormode;
  1743. return 0;
  1744. }
  1745. static int ami_set_cursorstate(struct fb_cursorstate *state,
  1746. struct amifb_par *par)
  1747. {
  1748. par->crsr.crsr_x = state->xoffset;
  1749. par->crsr.crsr_y = state->yoffset;
  1750. if ((cursormode = state->mode) == FB_CURSOR_OFF)
  1751. cursorstate = -1;
  1752. do_cursor = 1;
  1753. return 0;
  1754. }
  1755. static void ami_set_sprite(const struct amifb_par *par)
  1756. {
  1757. copins *copl, *cops;
  1758. u_short hs, vs, ve;
  1759. u_long pl, ps, pt;
  1760. short mx, my;
  1761. cops = copdisplay.list[currentcop][0];
  1762. copl = copdisplay.list[currentcop][1];
  1763. ps = pl = ZTWO_PADDR(dummysprite);
  1764. mx = par->crsr.crsr_x - par->crsr.spot_x;
  1765. my = par->crsr.crsr_y - par->crsr.spot_y;
  1766. if (!(par->vmode & FB_VMODE_YWRAP)) {
  1767. mx -= par->xoffset;
  1768. my -= par->yoffset;
  1769. }
  1770. if (!is_blanked && cursorstate > 0 && par->crsr.height > 0 &&
  1771. mx > -(short)par->crsr.width && mx < par->xres &&
  1772. my > -(short)par->crsr.height && my < par->yres) {
  1773. pl = ZTWO_PADDR(lofsprite);
  1774. hs = par->diwstrt_h + (mx << par->clk_shift) - 4;
  1775. vs = par->diwstrt_v + (my << par->line_shift);
  1776. ve = vs + (par->crsr.height << par->line_shift);
  1777. if (par->bplcon0 & BPC0_LACE) {
  1778. ps = ZTWO_PADDR(shfsprite);
  1779. lofsprite[0] = spr2hw_pos(vs, hs);
  1780. shfsprite[0] = spr2hw_pos(vs + 1, hs);
  1781. if (mod2(vs)) {
  1782. lofsprite[1 << par->crsr.fmode] = spr2hw_ctl(vs, hs, ve);
  1783. shfsprite[1 << par->crsr.fmode] = spr2hw_ctl(vs + 1, hs, ve + 1);
  1784. pt = pl; pl = ps; ps = pt;
  1785. } else {
  1786. lofsprite[1 << par->crsr.fmode] = spr2hw_ctl(vs, hs, ve + 1);
  1787. shfsprite[1 << par->crsr.fmode] = spr2hw_ctl(vs + 1, hs, ve);
  1788. }
  1789. } else {
  1790. lofsprite[0] = spr2hw_pos(vs, hs) | (IS_AGA && (par->fmode & FMODE_BSCAN2) ? 0x80 : 0);
  1791. lofsprite[1 << par->crsr.fmode] = spr2hw_ctl(vs, hs, ve);
  1792. }
  1793. }
  1794. copl[cop_spr0ptrh].w[1] = highw(pl);
  1795. copl[cop_spr0ptrl].w[1] = loww(pl);
  1796. if (par->bplcon0 & BPC0_LACE) {
  1797. cops[cop_spr0ptrh].w[1] = highw(ps);
  1798. cops[cop_spr0ptrl].w[1] = loww(ps);
  1799. }
  1800. }
  1801. /*
  1802. * Initialise the Copper Initialisation List
  1803. */
  1804. static void __init ami_init_copper(void)
  1805. {
  1806. copins *cop = copdisplay.init;
  1807. u_long p;
  1808. int i;
  1809. if (!IS_OCS) {
  1810. (cop++)->l = CMOVE(BPC0_COLOR | BPC0_SHRES | BPC0_ECSENA, bplcon0);
  1811. (cop++)->l = CMOVE(0x0181, diwstrt);
  1812. (cop++)->l = CMOVE(0x0281, diwstop);
  1813. (cop++)->l = CMOVE(0x0000, diwhigh);
  1814. } else
  1815. (cop++)->l = CMOVE(BPC0_COLOR, bplcon0);
  1816. p = ZTWO_PADDR(dummysprite);
  1817. for (i = 0; i < 8; i++) {
  1818. (cop++)->l = CMOVE(0, spr[i].pos);
  1819. (cop++)->l = CMOVE(highw(p), sprpt[i]);
  1820. (cop++)->l = CMOVE2(loww(p), sprpt[i]);
  1821. }
  1822. (cop++)->l = CMOVE(IF_SETCLR | IF_COPER, intreq);
  1823. copdisplay.wait = cop;
  1824. (cop++)->l = CEND;
  1825. (cop++)->l = CMOVE(0, copjmp2);
  1826. cop->l = CEND;
  1827. custom.cop1lc = (u_short *)ZTWO_PADDR(copdisplay.init);
  1828. custom.copjmp1 = 0;
  1829. }
  1830. static void ami_reinit_copper(const struct amifb_par *par)
  1831. {
  1832. copdisplay.init[cip_bplcon0].w[1] = ~(BPC0_BPU3 | BPC0_BPU2 | BPC0_BPU1 | BPC0_BPU0) & par->bplcon0;
  1833. copdisplay.wait->l = CWAIT(32, par->diwstrt_v - 4);
  1834. }
  1835. /*
  1836. * Rebuild the Copper List
  1837. *
  1838. * We only change the things that are not static
  1839. */
  1840. static void ami_rebuild_copper(const struct amifb_par *par)
  1841. {
  1842. copins *copl, *cops;
  1843. u_short line, h_end1, h_end2;
  1844. short i;
  1845. u_long p;
  1846. if (IS_AGA && maxfmode + par->clk_shift == 0)
  1847. h_end1 = par->diwstrt_h - 64;
  1848. else
  1849. h_end1 = par->htotal - 32;
  1850. h_end2 = par->ddfstop + 64;
  1851. ami_set_sprite(par);
  1852. copl = copdisplay.rebuild[1];
  1853. p = par->bplpt0;
  1854. if (par->vmode & FB_VMODE_YWRAP) {
  1855. if ((par->vyres - par->yoffset) != 1 || !mod2(par->diwstrt_v)) {
  1856. if (par->yoffset > par->vyres - par->yres) {
  1857. for (i = 0; i < (short)par->bpp; i++, p += par->next_plane) {
  1858. (copl++)->l = CMOVE(highw(p), bplpt[i]);
  1859. (copl++)->l = CMOVE2(loww(p), bplpt[i]);
  1860. }
  1861. line = par->diwstrt_v + ((par->vyres - par->yoffset) << par->line_shift) - 1;
  1862. while (line >= 512) {
  1863. (copl++)->l = CWAIT(h_end1, 510);
  1864. line -= 512;
  1865. }
  1866. if (line >= 510 && IS_AGA && maxfmode + par->clk_shift == 0)
  1867. (copl++)->l = CWAIT(h_end1, line);
  1868. else
  1869. (copl++)->l = CWAIT(h_end2, line);
  1870. p = par->bplpt0wrap;
  1871. }
  1872. } else
  1873. p = par->bplpt0wrap;
  1874. }
  1875. for (i = 0; i < (short)par->bpp; i++, p += par->next_plane) {
  1876. (copl++)->l = CMOVE(highw(p), bplpt[i]);
  1877. (copl++)->l = CMOVE2(loww(p), bplpt[i]);
  1878. }
  1879. copl->l = CEND;
  1880. if (par->bplcon0 & BPC0_LACE) {
  1881. cops = copdisplay.rebuild[0];
  1882. p = par->bplpt0;
  1883. if (mod2(par->diwstrt_v))
  1884. p -= par->next_line;
  1885. else
  1886. p += par->next_line;
  1887. if (par->vmode & FB_VMODE_YWRAP) {
  1888. if ((par->vyres - par->yoffset) != 1 || mod2(par->diwstrt_v)) {
  1889. if (par->yoffset > par->vyres - par->yres + 1) {
  1890. for (i = 0; i < (short)par->bpp; i++, p += par->next_plane) {
  1891. (cops++)->l = CMOVE(highw(p), bplpt[i]);
  1892. (cops++)->l = CMOVE2(loww(p), bplpt[i]);
  1893. }
  1894. line = par->diwstrt_v + ((par->vyres - par->yoffset) << par->line_shift) - 2;
  1895. while (line >= 512) {
  1896. (cops++)->l = CWAIT(h_end1, 510);
  1897. line -= 512;
  1898. }
  1899. if (line > 510 && IS_AGA && maxfmode + par->clk_shift == 0)
  1900. (cops++)->l = CWAIT(h_end1, line);
  1901. else
  1902. (cops++)->l = CWAIT(h_end2, line);
  1903. p = par->bplpt0wrap;
  1904. if (mod2(par->diwstrt_v + par->vyres -
  1905. par->yoffset))
  1906. p -= par->next_line;
  1907. else
  1908. p += par->next_line;
  1909. }
  1910. } else
  1911. p = par->bplpt0wrap - par->next_line;
  1912. }
  1913. for (i = 0; i < (short)par->bpp; i++, p += par->next_plane) {
  1914. (cops++)->l = CMOVE(highw(p), bplpt[i]);
  1915. (cops++)->l = CMOVE2(loww(p), bplpt[i]);
  1916. }
  1917. cops->l = CEND;
  1918. }
  1919. }
  1920. /*
  1921. * Build the Copper List
  1922. */
  1923. static void ami_build_copper(struct fb_info *info)
  1924. {
  1925. struct amifb_par *par = info->par;
  1926. copins *copl, *cops;
  1927. u_long p;
  1928. currentcop = 1 - currentcop;
  1929. copl = copdisplay.list[currentcop][1];
  1930. (copl++)->l = CWAIT(0, 10);
  1931. (copl++)->l = CMOVE(par->bplcon0, bplcon0);
  1932. (copl++)->l = CMOVE(0, sprpt[0]);
  1933. (copl++)->l = CMOVE2(0, sprpt[0]);
  1934. if (par->bplcon0 & BPC0_LACE) {
  1935. cops = copdisplay.list[currentcop][0];
  1936. (cops++)->l = CWAIT(0, 10);
  1937. (cops++)->l = CMOVE(par->bplcon0, bplcon0);
  1938. (cops++)->l = CMOVE(0, sprpt[0]);
  1939. (cops++)->l = CMOVE2(0, sprpt[0]);
  1940. (copl++)->l = CMOVE(diwstrt2hw(par->diwstrt_h, par->diwstrt_v + 1), diwstrt);
  1941. (copl++)->l = CMOVE(diwstop2hw(par->diwstop_h, par->diwstop_v + 1), diwstop);
  1942. (cops++)->l = CMOVE(diwstrt2hw(par->diwstrt_h, par->diwstrt_v), diwstrt);
  1943. (cops++)->l = CMOVE(diwstop2hw(par->diwstop_h, par->diwstop_v), diwstop);
  1944. if (!IS_OCS) {
  1945. (copl++)->l = CMOVE(diwhigh2hw(par->diwstrt_h, par->diwstrt_v + 1,
  1946. par->diwstop_h, par->diwstop_v + 1), diwhigh);
  1947. (cops++)->l = CMOVE(diwhigh2hw(par->diwstrt_h, par->diwstrt_v,
  1948. par->diwstop_h, par->diwstop_v), diwhigh);
  1949. #if 0
  1950. if (par->beamcon0 & BMC0_VARBEAMEN) {
  1951. (copl++)->l = CMOVE(vtotal2hw(par->vtotal), vtotal);
  1952. (copl++)->l = CMOVE(vbstrt2hw(par->vbstrt + 1), vbstrt);
  1953. (copl++)->l = CMOVE(vbstop2hw(par->vbstop + 1), vbstop);
  1954. (cops++)->l = CMOVE(vtotal2hw(par->vtotal), vtotal);
  1955. (cops++)->l = CMOVE(vbstrt2hw(par->vbstrt), vbstrt);
  1956. (cops++)->l = CMOVE(vbstop2hw(par->vbstop), vbstop);
  1957. }
  1958. #endif
  1959. }
  1960. p = ZTWO_PADDR(copdisplay.list[currentcop][0]);
  1961. (copl++)->l = CMOVE(highw(p), cop2lc);
  1962. (copl++)->l = CMOVE2(loww(p), cop2lc);
  1963. p = ZTWO_PADDR(copdisplay.list[currentcop][1]);
  1964. (cops++)->l = CMOVE(highw(p), cop2lc);
  1965. (cops++)->l = CMOVE2(loww(p), cop2lc);
  1966. copdisplay.rebuild[0] = cops;
  1967. } else {
  1968. (copl++)->l = CMOVE(diwstrt2hw(par->diwstrt_h, par->diwstrt_v), diwstrt);
  1969. (copl++)->l = CMOVE(diwstop2hw(par->diwstop_h, par->diwstop_v), diwstop);
  1970. if (!IS_OCS) {
  1971. (copl++)->l = CMOVE(diwhigh2hw(par->diwstrt_h, par->diwstrt_v,
  1972. par->diwstop_h, par->diwstop_v), diwhigh);
  1973. #if 0
  1974. if (par->beamcon0 & BMC0_VARBEAMEN) {
  1975. (copl++)->l = CMOVE(vtotal2hw(par->vtotal), vtotal);
  1976. (copl++)->l = CMOVE(vbstrt2hw(par->vbstrt), vbstrt);
  1977. (copl++)->l = CMOVE(vbstop2hw(par->vbstop), vbstop);
  1978. }
  1979. #endif
  1980. }
  1981. }
  1982. copdisplay.rebuild[1] = copl;
  1983. ami_update_par(info);
  1984. ami_rebuild_copper(info->par);
  1985. }
  1986. static void __init amifb_setup_mcap(char *spec)
  1987. {
  1988. char *p;
  1989. int vmin, vmax, hmin, hmax;
  1990. /* Format for monitor capabilities is: <Vmin>;<Vmax>;<Hmin>;<Hmax>
  1991. * <V*> vertical freq. in Hz
  1992. * <H*> horizontal freq. in kHz
  1993. */
  1994. if (!(p = strsep(&spec, ";")) || !*p)
  1995. return;
  1996. vmin = simple_strtoul(p, NULL, 10);
  1997. if (vmin <= 0)
  1998. return;
  1999. if (!(p = strsep(&spec, ";")) || !*p)
  2000. return;
  2001. vmax = simple_strtoul(p, NULL, 10);
  2002. if (vmax <= 0 || vmax <= vmin)
  2003. return;
  2004. if (!(p = strsep(&spec, ";")) || !*p)
  2005. return;
  2006. hmin = 1000 * simple_strtoul(p, NULL, 10);
  2007. if (hmin <= 0)
  2008. return;
  2009. if (!(p = strsep(&spec, "")) || !*p)
  2010. return;
  2011. hmax = 1000 * simple_strtoul(p, NULL, 10);
  2012. if (hmax <= 0 || hmax <= hmin)
  2013. return;
  2014. amifb_hfmin = hmin;
  2015. amifb_hfmax = hmax;
  2016. amifb_vfmin = vmin;
  2017. amifb_vfmax = vmax;
  2018. }
  2019. static int __init amifb_setup(char *options)
  2020. {
  2021. char *this_opt;
  2022. if (!options || !*options)
  2023. return 0;
  2024. while ((this_opt = strsep(&options, ",")) != NULL) {
  2025. if (!*this_opt)
  2026. continue;
  2027. if (!strcmp(this_opt, "inverse")) {
  2028. amifb_inverse = 1;
  2029. fb_invert_cmaps();
  2030. } else if (!strcmp(this_opt, "ilbm"))
  2031. amifb_ilbm = 1;
  2032. else if (!strncmp(this_opt, "monitorcap:", 11))
  2033. amifb_setup_mcap(this_opt + 11);
  2034. else if (!strncmp(this_opt, "fstart:", 7))
  2035. min_fstrt = simple_strtoul(this_opt + 7, NULL, 0);
  2036. else
  2037. mode_option = this_opt;
  2038. }
  2039. if (min_fstrt < 48)
  2040. min_fstrt = 48;
  2041. return 0;
  2042. }
  2043. static int amifb_check_var(struct fb_var_screeninfo *var,
  2044. struct fb_info *info)
  2045. {
  2046. int err;
  2047. struct amifb_par par;
  2048. /* Validate wanted screen parameters */
  2049. err = ami_decode_var(var, &par, info);
  2050. if (err)
  2051. return err;
  2052. /* Encode (possibly rounded) screen parameters */
  2053. ami_encode_var(var, &par);
  2054. return 0;
  2055. }
  2056. static int amifb_set_par(struct fb_info *info)
  2057. {
  2058. struct amifb_par *par = info->par;
  2059. int error;
  2060. do_vmode_pan = 0;
  2061. do_vmode_full = 0;
  2062. /* Decode wanted screen parameters */
  2063. error = ami_decode_var(&info->var, par, info);
  2064. if (error)
  2065. return error;
  2066. /* Set new videomode */
  2067. ami_build_copper(info);
  2068. /* Set VBlank trigger */
  2069. do_vmode_full = 1;
  2070. /* Update fix for new screen parameters */
  2071. if (par->bpp == 1) {
  2072. info->fix.type = FB_TYPE_PACKED_PIXELS;
  2073. info->fix.type_aux = 0;
  2074. } else if (amifb_ilbm) {
  2075. info->fix.type = FB_TYPE_INTERLEAVED_PLANES;
  2076. info->fix.type_aux = par->next_line;
  2077. } else {
  2078. info->fix.type = FB_TYPE_PLANES;
  2079. info->fix.type_aux = 0;
  2080. }
  2081. info->fix.line_length = div8(upx(16 << maxfmode, par->vxres));
  2082. if (par->vmode & FB_VMODE_YWRAP) {
  2083. info->fix.ywrapstep = 1;
  2084. info->fix.xpanstep = 0;
  2085. info->fix.ypanstep = 0;
  2086. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YWRAP |
  2087. FBINFO_READS_FAST; /* override SCROLL_REDRAW */
  2088. } else {
  2089. info->fix.ywrapstep = 0;
  2090. if (par->vmode & FB_VMODE_SMOOTH_XPAN)
  2091. info->fix.xpanstep = 1;
  2092. else
  2093. info->fix.xpanstep = 16 << maxfmode;
  2094. info->fix.ypanstep = 1;
  2095. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  2096. }
  2097. return 0;
  2098. }
  2099. /*
  2100. * Set a single color register. The values supplied are already
  2101. * rounded down to the hardware's capabilities (according to the
  2102. * entries in the var structure). Return != 0 for invalid regno.
  2103. */
  2104. static int amifb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  2105. u_int transp, struct fb_info *info)
  2106. {
  2107. const struct amifb_par *par = info->par;
  2108. if (IS_AGA) {
  2109. if (regno > 255)
  2110. return 1;
  2111. } else if (par->bplcon0 & BPC0_SHRES) {
  2112. if (regno > 3)
  2113. return 1;
  2114. } else {
  2115. if (regno > 31)
  2116. return 1;
  2117. }
  2118. red >>= 8;
  2119. green >>= 8;
  2120. blue >>= 8;
  2121. if (!regno) {
  2122. red0 = red;
  2123. green0 = green;
  2124. blue0 = blue;
  2125. }
  2126. /*
  2127. * Update the corresponding Hardware Color Register, unless it's Color
  2128. * Register 0 and the screen is blanked.
  2129. *
  2130. * VBlank is switched off to protect bplcon3 or ecs_palette[] from
  2131. * being changed by ami_do_blank() during the VBlank.
  2132. */
  2133. if (regno || !is_blanked) {
  2134. #if defined(CONFIG_FB_AMIGA_AGA)
  2135. if (IS_AGA) {
  2136. u_short bplcon3 = par->bplcon3;
  2137. VBlankOff();
  2138. custom.bplcon3 = bplcon3 | (regno << 8 & 0xe000);
  2139. custom.color[regno & 31] = rgb2hw8_high(red, green,
  2140. blue);
  2141. custom.bplcon3 = bplcon3 | (regno << 8 & 0xe000) |
  2142. BPC3_LOCT;
  2143. custom.color[regno & 31] = rgb2hw8_low(red, green,
  2144. blue);
  2145. custom.bplcon3 = bplcon3;
  2146. VBlankOn();
  2147. } else
  2148. #endif
  2149. #if defined(CONFIG_FB_AMIGA_ECS)
  2150. if (par->bplcon0 & BPC0_SHRES) {
  2151. u_short color, mask;
  2152. int i;
  2153. mask = 0x3333;
  2154. color = rgb2hw2(red, green, blue);
  2155. VBlankOff();
  2156. for (i = regno + 12; i >= (int)regno; i -= 4)
  2157. custom.color[i] = ecs_palette[i] = (ecs_palette[i] & mask) | color;
  2158. mask <<= 2; color >>= 2;
  2159. regno = down16(regno) + mul4(mod4(regno));
  2160. for (i = regno + 3; i >= (int)regno; i--)
  2161. custom.color[i] = ecs_palette[i] = (ecs_palette[i] & mask) | color;
  2162. VBlankOn();
  2163. } else
  2164. #endif
  2165. custom.color[regno] = rgb2hw4(red, green, blue);
  2166. }
  2167. return 0;
  2168. }
  2169. /*
  2170. * Blank the display.
  2171. */
  2172. static int amifb_blank(int blank, struct fb_info *info)
  2173. {
  2174. do_blank = blank ? blank : -1;
  2175. return 0;
  2176. }
  2177. /*
  2178. * Pan or Wrap the Display
  2179. *
  2180. * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
  2181. */
  2182. static int amifb_pan_display(struct fb_var_screeninfo *var,
  2183. struct fb_info *info)
  2184. {
  2185. if (var->vmode & FB_VMODE_YWRAP) {
  2186. if (var->yoffset < 0 ||
  2187. var->yoffset >= info->var.yres_virtual || var->xoffset)
  2188. return -EINVAL;
  2189. } else {
  2190. /*
  2191. * TODO: There will be problems when xpan!=1, so some columns
  2192. * on the right side will never be seen
  2193. */
  2194. if (var->xoffset + info->var.xres >
  2195. upx(16 << maxfmode, info->var.xres_virtual) ||
  2196. var->yoffset + info->var.yres > info->var.yres_virtual)
  2197. return -EINVAL;
  2198. }
  2199. ami_pan_var(var, info);
  2200. info->var.xoffset = var->xoffset;
  2201. info->var.yoffset = var->yoffset;
  2202. if (var->vmode & FB_VMODE_YWRAP)
  2203. info->var.vmode |= FB_VMODE_YWRAP;
  2204. else
  2205. info->var.vmode &= ~FB_VMODE_YWRAP;
  2206. return 0;
  2207. }
  2208. #if BITS_PER_LONG == 32
  2209. #define BYTES_PER_LONG 4
  2210. #define SHIFT_PER_LONG 5
  2211. #elif BITS_PER_LONG == 64
  2212. #define BYTES_PER_LONG 8
  2213. #define SHIFT_PER_LONG 6
  2214. #else
  2215. #define Please update me
  2216. #endif
  2217. /*
  2218. * Compose two values, using a bitmask as decision value
  2219. * This is equivalent to (a & mask) | (b & ~mask)
  2220. */
  2221. static inline unsigned long comp(unsigned long a, unsigned long b,
  2222. unsigned long mask)
  2223. {
  2224. return ((a ^ b) & mask) ^ b;
  2225. }
  2226. static inline unsigned long xor(unsigned long a, unsigned long b,
  2227. unsigned long mask)
  2228. {
  2229. return (a & mask) ^ b;
  2230. }
  2231. /*
  2232. * Unaligned forward bit copy using 32-bit or 64-bit memory accesses
  2233. */
  2234. static void bitcpy(unsigned long *dst, int dst_idx, const unsigned long *src,
  2235. int src_idx, u32 n)
  2236. {
  2237. unsigned long first, last;
  2238. int shift = dst_idx - src_idx, left, right;
  2239. unsigned long d0, d1;
  2240. int m;
  2241. if (!n)
  2242. return;
  2243. shift = dst_idx - src_idx;
  2244. first = ~0UL >> dst_idx;
  2245. last = ~(~0UL >> ((dst_idx + n) % BITS_PER_LONG));
  2246. if (!shift) {
  2247. // Same alignment for source and dest
  2248. if (dst_idx + n <= BITS_PER_LONG) {
  2249. // Single word
  2250. if (last)
  2251. first &= last;
  2252. *dst = comp(*src, *dst, first);
  2253. } else {
  2254. // Multiple destination words
  2255. // Leading bits
  2256. if (first) {
  2257. *dst = comp(*src, *dst, first);
  2258. dst++;
  2259. src++;
  2260. n -= BITS_PER_LONG - dst_idx;
  2261. }
  2262. // Main chunk
  2263. n /= BITS_PER_LONG;
  2264. while (n >= 8) {
  2265. *dst++ = *src++;
  2266. *dst++ = *src++;
  2267. *dst++ = *src++;
  2268. *dst++ = *src++;
  2269. *dst++ = *src++;
  2270. *dst++ = *src++;
  2271. *dst++ = *src++;
  2272. *dst++ = *src++;
  2273. n -= 8;
  2274. }
  2275. while (n--)
  2276. *dst++ = *src++;
  2277. // Trailing bits
  2278. if (last)
  2279. *dst = comp(*src, *dst, last);
  2280. }
  2281. } else {
  2282. // Different alignment for source and dest
  2283. right = shift & (BITS_PER_LONG - 1);
  2284. left = -shift & (BITS_PER_LONG - 1);
  2285. if (dst_idx + n <= BITS_PER_LONG) {
  2286. // Single destination word
  2287. if (last)
  2288. first &= last;
  2289. if (shift > 0) {
  2290. // Single source word
  2291. *dst = comp(*src >> right, *dst, first);
  2292. } else if (src_idx + n <= BITS_PER_LONG) {
  2293. // Single source word
  2294. *dst = comp(*src << left, *dst, first);
  2295. } else {
  2296. // 2 source words
  2297. d0 = *src++;
  2298. d1 = *src;
  2299. *dst = comp(d0 << left | d1 >> right, *dst,
  2300. first);
  2301. }
  2302. } else {
  2303. // Multiple destination words
  2304. d0 = *src++;
  2305. // Leading bits
  2306. if (shift > 0) {
  2307. // Single source word
  2308. *dst = comp(d0 >> right, *dst, first);
  2309. dst++;
  2310. n -= BITS_PER_LONG - dst_idx;
  2311. } else {
  2312. // 2 source words
  2313. d1 = *src++;
  2314. *dst = comp(d0 << left | d1 >> right, *dst,
  2315. first);
  2316. d0 = d1;
  2317. dst++;
  2318. n -= BITS_PER_LONG - dst_idx;
  2319. }
  2320. // Main chunk
  2321. m = n % BITS_PER_LONG;
  2322. n /= BITS_PER_LONG;
  2323. while (n >= 4) {
  2324. d1 = *src++;
  2325. *dst++ = d0 << left | d1 >> right;
  2326. d0 = d1;
  2327. d1 = *src++;
  2328. *dst++ = d0 << left | d1 >> right;
  2329. d0 = d1;
  2330. d1 = *src++;
  2331. *dst++ = d0 << left | d1 >> right;
  2332. d0 = d1;
  2333. d1 = *src++;
  2334. *dst++ = d0 << left | d1 >> right;
  2335. d0 = d1;
  2336. n -= 4;
  2337. }
  2338. while (n--) {
  2339. d1 = *src++;
  2340. *dst++ = d0 << left | d1 >> right;
  2341. d0 = d1;
  2342. }
  2343. // Trailing bits
  2344. if (last) {
  2345. if (m <= right) {
  2346. // Single source word
  2347. *dst = comp(d0 << left, *dst, last);
  2348. } else {
  2349. // 2 source words
  2350. d1 = *src;
  2351. *dst = comp(d0 << left | d1 >> right,
  2352. *dst, last);
  2353. }
  2354. }
  2355. }
  2356. }
  2357. }
  2358. /*
  2359. * Unaligned reverse bit copy using 32-bit or 64-bit memory accesses
  2360. */
  2361. static void bitcpy_rev(unsigned long *dst, int dst_idx,
  2362. const unsigned long *src, int src_idx, u32 n)
  2363. {
  2364. unsigned long first, last;
  2365. int shift = dst_idx - src_idx, left, right;
  2366. unsigned long d0, d1;
  2367. int m;
  2368. if (!n)
  2369. return;
  2370. dst += (n - 1) / BITS_PER_LONG;
  2371. src += (n - 1) / BITS_PER_LONG;
  2372. if ((n - 1) % BITS_PER_LONG) {
  2373. dst_idx += (n - 1) % BITS_PER_LONG;
  2374. dst += dst_idx >> SHIFT_PER_LONG;
  2375. dst_idx &= BITS_PER_LONG - 1;
  2376. src_idx += (n - 1) % BITS_PER_LONG;
  2377. src += src_idx >> SHIFT_PER_LONG;
  2378. src_idx &= BITS_PER_LONG - 1;
  2379. }
  2380. shift = dst_idx - src_idx;
  2381. first = ~0UL << (BITS_PER_LONG - 1 - dst_idx);
  2382. last = ~(~0UL << (BITS_PER_LONG - 1 - ((dst_idx - n) % BITS_PER_LONG)));
  2383. if (!shift) {
  2384. // Same alignment for source and dest
  2385. if ((unsigned long)dst_idx + 1 >= n) {
  2386. // Single word
  2387. if (last)
  2388. first &= last;
  2389. *dst = comp(*src, *dst, first);
  2390. } else {
  2391. // Multiple destination words
  2392. // Leading bits
  2393. if (first) {
  2394. *dst = comp(*src, *dst, first);
  2395. dst--;
  2396. src--;
  2397. n -= dst_idx + 1;
  2398. }
  2399. // Main chunk
  2400. n /= BITS_PER_LONG;
  2401. while (n >= 8) {
  2402. *dst-- = *src--;
  2403. *dst-- = *src--;
  2404. *dst-- = *src--;
  2405. *dst-- = *src--;
  2406. *dst-- = *src--;
  2407. *dst-- = *src--;
  2408. *dst-- = *src--;
  2409. *dst-- = *src--;
  2410. n -= 8;
  2411. }
  2412. while (n--)
  2413. *dst-- = *src--;
  2414. // Trailing bits
  2415. if (last)
  2416. *dst = comp(*src, *dst, last);
  2417. }
  2418. } else {
  2419. // Different alignment for source and dest
  2420. right = shift & (BITS_PER_LONG - 1);
  2421. left = -shift & (BITS_PER_LONG - 1);
  2422. if ((unsigned long)dst_idx + 1 >= n) {
  2423. // Single destination word
  2424. if (last)
  2425. first &= last;
  2426. if (shift < 0) {
  2427. // Single source word
  2428. *dst = comp(*src << left, *dst, first);
  2429. } else if (1 + (unsigned long)src_idx >= n) {
  2430. // Single source word
  2431. *dst = comp(*src >> right, *dst, first);
  2432. } else {
  2433. // 2 source words
  2434. d0 = *src--;
  2435. d1 = *src;
  2436. *dst = comp(d0 >> right | d1 << left, *dst,
  2437. first);
  2438. }
  2439. } else {
  2440. // Multiple destination words
  2441. d0 = *src--;
  2442. // Leading bits
  2443. if (shift < 0) {
  2444. // Single source word
  2445. *dst = comp(d0 << left, *dst, first);
  2446. dst--;
  2447. n -= dst_idx + 1;
  2448. } else {
  2449. // 2 source words
  2450. d1 = *src--;
  2451. *dst = comp(d0 >> right | d1 << left, *dst,
  2452. first);
  2453. d0 = d1;
  2454. dst--;
  2455. n -= dst_idx + 1;
  2456. }
  2457. // Main chunk
  2458. m = n % BITS_PER_LONG;
  2459. n /= BITS_PER_LONG;
  2460. while (n >= 4) {
  2461. d1 = *src--;
  2462. *dst-- = d0 >> right | d1 << left;
  2463. d0 = d1;
  2464. d1 = *src--;
  2465. *dst-- = d0 >> right | d1 << left;
  2466. d0 = d1;
  2467. d1 = *src--;
  2468. *dst-- = d0 >> right | d1 << left;
  2469. d0 = d1;
  2470. d1 = *src--;
  2471. *dst-- = d0 >> right | d1 << left;
  2472. d0 = d1;
  2473. n -= 4;
  2474. }
  2475. while (n--) {
  2476. d1 = *src--;
  2477. *dst-- = d0 >> right | d1 << left;
  2478. d0 = d1;
  2479. }
  2480. // Trailing bits
  2481. if (last) {
  2482. if (m <= left) {
  2483. // Single source word
  2484. *dst = comp(d0 >> right, *dst, last);
  2485. } else {
  2486. // 2 source words
  2487. d1 = *src;
  2488. *dst = comp(d0 >> right | d1 << left,
  2489. *dst, last);
  2490. }
  2491. }
  2492. }
  2493. }
  2494. }
  2495. /*
  2496. * Unaligned forward inverting bit copy using 32-bit or 64-bit memory
  2497. * accesses
  2498. */
  2499. static void bitcpy_not(unsigned long *dst, int dst_idx,
  2500. const unsigned long *src, int src_idx, u32 n)
  2501. {
  2502. unsigned long first, last;
  2503. int shift = dst_idx - src_idx, left, right;
  2504. unsigned long d0, d1;
  2505. int m;
  2506. if (!n)
  2507. return;
  2508. shift = dst_idx - src_idx;
  2509. first = ~0UL >> dst_idx;
  2510. last = ~(~0UL >> ((dst_idx + n) % BITS_PER_LONG));
  2511. if (!shift) {
  2512. // Same alignment for source and dest
  2513. if (dst_idx + n <= BITS_PER_LONG) {
  2514. // Single word
  2515. if (last)
  2516. first &= last;
  2517. *dst = comp(~*src, *dst, first);
  2518. } else {
  2519. // Multiple destination words
  2520. // Leading bits
  2521. if (first) {
  2522. *dst = comp(~*src, *dst, first);
  2523. dst++;
  2524. src++;
  2525. n -= BITS_PER_LONG - dst_idx;
  2526. }
  2527. // Main chunk
  2528. n /= BITS_PER_LONG;
  2529. while (n >= 8) {
  2530. *dst++ = ~*src++;
  2531. *dst++ = ~*src++;
  2532. *dst++ = ~*src++;
  2533. *dst++ = ~*src++;
  2534. *dst++ = ~*src++;
  2535. *dst++ = ~*src++;
  2536. *dst++ = ~*src++;
  2537. *dst++ = ~*src++;
  2538. n -= 8;
  2539. }
  2540. while (n--)
  2541. *dst++ = ~*src++;
  2542. // Trailing bits
  2543. if (last)
  2544. *dst = comp(~*src, *dst, last);
  2545. }
  2546. } else {
  2547. // Different alignment for source and dest
  2548. right = shift & (BITS_PER_LONG - 1);
  2549. left = -shift & (BITS_PER_LONG - 1);
  2550. if (dst_idx + n <= BITS_PER_LONG) {
  2551. // Single destination word
  2552. if (last)
  2553. first &= last;
  2554. if (shift > 0) {
  2555. // Single source word
  2556. *dst = comp(~*src >> right, *dst, first);
  2557. } else if (src_idx + n <= BITS_PER_LONG) {
  2558. // Single source word
  2559. *dst = comp(~*src << left, *dst, first);
  2560. } else {
  2561. // 2 source words
  2562. d0 = ~*src++;
  2563. d1 = ~*src;
  2564. *dst = comp(d0 << left | d1 >> right, *dst,
  2565. first);
  2566. }
  2567. } else {
  2568. // Multiple destination words
  2569. d0 = ~*src++;
  2570. // Leading bits
  2571. if (shift > 0) {
  2572. // Single source word
  2573. *dst = comp(d0 >> right, *dst, first);
  2574. dst++;
  2575. n -= BITS_PER_LONG - dst_idx;
  2576. } else {
  2577. // 2 source words
  2578. d1 = ~*src++;
  2579. *dst = comp(d0 << left | d1 >> right, *dst,
  2580. first);
  2581. d0 = d1;
  2582. dst++;
  2583. n -= BITS_PER_LONG - dst_idx;
  2584. }
  2585. // Main chunk
  2586. m = n % BITS_PER_LONG;
  2587. n /= BITS_PER_LONG;
  2588. while (n >= 4) {
  2589. d1 = ~*src++;
  2590. *dst++ = d0 << left | d1 >> right;
  2591. d0 = d1;
  2592. d1 = ~*src++;
  2593. *dst++ = d0 << left | d1 >> right;
  2594. d0 = d1;
  2595. d1 = ~*src++;
  2596. *dst++ = d0 << left | d1 >> right;
  2597. d0 = d1;
  2598. d1 = ~*src++;
  2599. *dst++ = d0 << left | d1 >> right;
  2600. d0 = d1;
  2601. n -= 4;
  2602. }
  2603. while (n--) {
  2604. d1 = ~*src++;
  2605. *dst++ = d0 << left | d1 >> right;
  2606. d0 = d1;
  2607. }
  2608. // Trailing bits
  2609. if (last) {
  2610. if (m <= right) {
  2611. // Single source word
  2612. *dst = comp(d0 << left, *dst, last);
  2613. } else {
  2614. // 2 source words
  2615. d1 = ~*src;
  2616. *dst = comp(d0 << left | d1 >> right,
  2617. *dst, last);
  2618. }
  2619. }
  2620. }
  2621. }
  2622. }
  2623. /*
  2624. * Unaligned 32-bit pattern fill using 32/64-bit memory accesses
  2625. */
  2626. static void bitfill32(unsigned long *dst, int dst_idx, u32 pat, u32 n)
  2627. {
  2628. unsigned long val = pat;
  2629. unsigned long first, last;
  2630. if (!n)
  2631. return;
  2632. #if BITS_PER_LONG == 64
  2633. val |= val << 32;
  2634. #endif
  2635. first = ~0UL >> dst_idx;
  2636. last = ~(~0UL >> ((dst_idx + n) % BITS_PER_LONG));
  2637. if (dst_idx + n <= BITS_PER_LONG) {
  2638. // Single word
  2639. if (last)
  2640. first &= last;
  2641. *dst = comp(val, *dst, first);
  2642. } else {
  2643. // Multiple destination words
  2644. // Leading bits
  2645. if (first) {
  2646. *dst = comp(val, *dst, first);
  2647. dst++;
  2648. n -= BITS_PER_LONG - dst_idx;
  2649. }
  2650. // Main chunk
  2651. n /= BITS_PER_LONG;
  2652. while (n >= 8) {
  2653. *dst++ = val;
  2654. *dst++ = val;
  2655. *dst++ = val;
  2656. *dst++ = val;
  2657. *dst++ = val;
  2658. *dst++ = val;
  2659. *dst++ = val;
  2660. *dst++ = val;
  2661. n -= 8;
  2662. }
  2663. while (n--)
  2664. *dst++ = val;
  2665. // Trailing bits
  2666. if (last)
  2667. *dst = comp(val, *dst, last);
  2668. }
  2669. }
  2670. /*
  2671. * Unaligned 32-bit pattern xor using 32/64-bit memory accesses
  2672. */
  2673. static void bitxor32(unsigned long *dst, int dst_idx, u32 pat, u32 n)
  2674. {
  2675. unsigned long val = pat;
  2676. unsigned long first, last;
  2677. if (!n)
  2678. return;
  2679. #if BITS_PER_LONG == 64
  2680. val |= val << 32;
  2681. #endif
  2682. first = ~0UL >> dst_idx;
  2683. last = ~(~0UL >> ((dst_idx + n) % BITS_PER_LONG));
  2684. if (dst_idx + n <= BITS_PER_LONG) {
  2685. // Single word
  2686. if (last)
  2687. first &= last;
  2688. *dst = xor(val, *dst, first);
  2689. } else {
  2690. // Multiple destination words
  2691. // Leading bits
  2692. if (first) {
  2693. *dst = xor(val, *dst, first);
  2694. dst++;
  2695. n -= BITS_PER_LONG - dst_idx;
  2696. }
  2697. // Main chunk
  2698. n /= BITS_PER_LONG;
  2699. while (n >= 4) {
  2700. *dst++ ^= val;
  2701. *dst++ ^= val;
  2702. *dst++ ^= val;
  2703. *dst++ ^= val;
  2704. n -= 4;
  2705. }
  2706. while (n--)
  2707. *dst++ ^= val;
  2708. // Trailing bits
  2709. if (last)
  2710. *dst = xor(val, *dst, last);
  2711. }
  2712. }
  2713. static inline void fill_one_line(int bpp, unsigned long next_plane,
  2714. unsigned long *dst, int dst_idx, u32 n,
  2715. u32 color)
  2716. {
  2717. while (1) {
  2718. dst += dst_idx >> SHIFT_PER_LONG;
  2719. dst_idx &= (BITS_PER_LONG - 1);
  2720. bitfill32(dst, dst_idx, color & 1 ? ~0 : 0, n);
  2721. if (!--bpp)
  2722. break;
  2723. color >>= 1;
  2724. dst_idx += next_plane * 8;
  2725. }
  2726. }
  2727. static inline void xor_one_line(int bpp, unsigned long next_plane,
  2728. unsigned long *dst, int dst_idx, u32 n,
  2729. u32 color)
  2730. {
  2731. while (color) {
  2732. dst += dst_idx >> SHIFT_PER_LONG;
  2733. dst_idx &= (BITS_PER_LONG - 1);
  2734. bitxor32(dst, dst_idx, color & 1 ? ~0 : 0, n);
  2735. if (!--bpp)
  2736. break;
  2737. color >>= 1;
  2738. dst_idx += next_plane * 8;
  2739. }
  2740. }
  2741. static void amifb_fillrect(struct fb_info *info,
  2742. const struct fb_fillrect *rect)
  2743. {
  2744. struct amifb_par *par = info->par;
  2745. int dst_idx, x2, y2;
  2746. unsigned long *dst;
  2747. u32 width, height;
  2748. if (!rect->width || !rect->height)
  2749. return;
  2750. /*
  2751. * We could use hardware clipping but on many cards you get around
  2752. * hardware clipping by writing to framebuffer directly.
  2753. * */
  2754. x2 = rect->dx + rect->width;
  2755. y2 = rect->dy + rect->height;
  2756. x2 = x2 < info->var.xres_virtual ? x2 : info->var.xres_virtual;
  2757. y2 = y2 < info->var.yres_virtual ? y2 : info->var.yres_virtual;
  2758. width = x2 - rect->dx;
  2759. height = y2 - rect->dy;
  2760. dst = (unsigned long *)
  2761. ((unsigned long)info->screen_base & ~(BYTES_PER_LONG - 1));
  2762. dst_idx = ((unsigned long)info->screen_base & (BYTES_PER_LONG - 1)) * 8;
  2763. dst_idx += rect->dy * par->next_line * 8 + rect->dx;
  2764. while (height--) {
  2765. switch (rect->rop) {
  2766. case ROP_COPY:
  2767. fill_one_line(info->var.bits_per_pixel,
  2768. par->next_plane, dst, dst_idx, width,
  2769. rect->color);
  2770. break;
  2771. case ROP_XOR:
  2772. xor_one_line(info->var.bits_per_pixel, par->next_plane,
  2773. dst, dst_idx, width, rect->color);
  2774. break;
  2775. }
  2776. dst_idx += par->next_line * 8;
  2777. }
  2778. }
  2779. static inline void copy_one_line(int bpp, unsigned long next_plane,
  2780. unsigned long *dst, int dst_idx,
  2781. unsigned long *src, int src_idx, u32 n)
  2782. {
  2783. while (1) {
  2784. dst += dst_idx >> SHIFT_PER_LONG;
  2785. dst_idx &= (BITS_PER_LONG - 1);
  2786. src += src_idx >> SHIFT_PER_LONG;
  2787. src_idx &= (BITS_PER_LONG - 1);
  2788. bitcpy(dst, dst_idx, src, src_idx, n);
  2789. if (!--bpp)
  2790. break;
  2791. dst_idx += next_plane * 8;
  2792. src_idx += next_plane * 8;
  2793. }
  2794. }
  2795. static inline void copy_one_line_rev(int bpp, unsigned long next_plane,
  2796. unsigned long *dst, int dst_idx,
  2797. unsigned long *src, int src_idx, u32 n)
  2798. {
  2799. while (1) {
  2800. dst += dst_idx >> SHIFT_PER_LONG;
  2801. dst_idx &= (BITS_PER_LONG - 1);
  2802. src += src_idx >> SHIFT_PER_LONG;
  2803. src_idx &= (BITS_PER_LONG - 1);
  2804. bitcpy_rev(dst, dst_idx, src, src_idx, n);
  2805. if (!--bpp)
  2806. break;
  2807. dst_idx += next_plane * 8;
  2808. src_idx += next_plane * 8;
  2809. }
  2810. }
  2811. static void amifb_copyarea(struct fb_info *info,
  2812. const struct fb_copyarea *area)
  2813. {
  2814. struct amifb_par *par = info->par;
  2815. int x2, y2;
  2816. u32 dx, dy, sx, sy, width, height;
  2817. unsigned long *dst, *src;
  2818. int dst_idx, src_idx;
  2819. int rev_copy = 0;
  2820. /* clip the destination */
  2821. x2 = area->dx + area->width;
  2822. y2 = area->dy + area->height;
  2823. dx = area->dx > 0 ? area->dx : 0;
  2824. dy = area->dy > 0 ? area->dy : 0;
  2825. x2 = x2 < info->var.xres_virtual ? x2 : info->var.xres_virtual;
  2826. y2 = y2 < info->var.yres_virtual ? y2 : info->var.yres_virtual;
  2827. width = x2 - dx;
  2828. height = y2 - dy;
  2829. if (area->sx + dx < area->dx || area->sy + dy < area->dy)
  2830. return;
  2831. /* update sx,sy */
  2832. sx = area->sx + (dx - area->dx);
  2833. sy = area->sy + (dy - area->dy);
  2834. /* the source must be completely inside the virtual screen */
  2835. if (sx + width > info->var.xres_virtual ||
  2836. sy + height > info->var.yres_virtual)
  2837. return;
  2838. if (dy > sy || (dy == sy && dx > sx)) {
  2839. dy += height;
  2840. sy += height;
  2841. rev_copy = 1;
  2842. }
  2843. dst = (unsigned long *)
  2844. ((unsigned long)info->screen_base & ~(BYTES_PER_LONG - 1));
  2845. src = dst;
  2846. dst_idx = ((unsigned long)info->screen_base & (BYTES_PER_LONG - 1)) * 8;
  2847. src_idx = dst_idx;
  2848. dst_idx += dy * par->next_line * 8 + dx;
  2849. src_idx += sy * par->next_line * 8 + sx;
  2850. if (rev_copy) {
  2851. while (height--) {
  2852. dst_idx -= par->next_line * 8;
  2853. src_idx -= par->next_line * 8;
  2854. copy_one_line_rev(info->var.bits_per_pixel,
  2855. par->next_plane, dst, dst_idx, src,
  2856. src_idx, width);
  2857. }
  2858. } else {
  2859. while (height--) {
  2860. copy_one_line(info->var.bits_per_pixel,
  2861. par->next_plane, dst, dst_idx, src,
  2862. src_idx, width);
  2863. dst_idx += par->next_line * 8;
  2864. src_idx += par->next_line * 8;
  2865. }
  2866. }
  2867. }
  2868. static inline void expand_one_line(int bpp, unsigned long next_plane,
  2869. unsigned long *dst, int dst_idx, u32 n,
  2870. const u8 *data, u32 bgcolor, u32 fgcolor)
  2871. {
  2872. const unsigned long *src;
  2873. int src_idx;
  2874. while (1) {
  2875. dst += dst_idx >> SHIFT_PER_LONG;
  2876. dst_idx &= (BITS_PER_LONG - 1);
  2877. if ((bgcolor ^ fgcolor) & 1) {
  2878. src = (unsigned long *)
  2879. ((unsigned long)data & ~(BYTES_PER_LONG - 1));
  2880. src_idx = ((unsigned long)data & (BYTES_PER_LONG - 1)) * 8;
  2881. if (fgcolor & 1)
  2882. bitcpy(dst, dst_idx, src, src_idx, n);
  2883. else
  2884. bitcpy_not(dst, dst_idx, src, src_idx, n);
  2885. /* set or clear */
  2886. } else
  2887. bitfill32(dst, dst_idx, fgcolor & 1 ? ~0 : 0, n);
  2888. if (!--bpp)
  2889. break;
  2890. bgcolor >>= 1;
  2891. fgcolor >>= 1;
  2892. dst_idx += next_plane * 8;
  2893. }
  2894. }
  2895. static void amifb_imageblit(struct fb_info *info, const struct fb_image *image)
  2896. {
  2897. struct amifb_par *par = info->par;
  2898. int x2, y2;
  2899. unsigned long *dst;
  2900. int dst_idx;
  2901. const char *src;
  2902. u32 dx, dy, width, height, pitch;
  2903. /*
  2904. * We could use hardware clipping but on many cards you get around
  2905. * hardware clipping by writing to framebuffer directly like we are
  2906. * doing here.
  2907. */
  2908. x2 = image->dx + image->width;
  2909. y2 = image->dy + image->height;
  2910. dx = image->dx;
  2911. dy = image->dy;
  2912. x2 = x2 < info->var.xres_virtual ? x2 : info->var.xres_virtual;
  2913. y2 = y2 < info->var.yres_virtual ? y2 : info->var.yres_virtual;
  2914. width = x2 - dx;
  2915. height = y2 - dy;
  2916. if (image->depth == 1) {
  2917. dst = (unsigned long *)
  2918. ((unsigned long)info->screen_base & ~(BYTES_PER_LONG - 1));
  2919. dst_idx = ((unsigned long)info->screen_base & (BYTES_PER_LONG - 1)) * 8;
  2920. dst_idx += dy * par->next_line * 8 + dx;
  2921. src = image->data;
  2922. pitch = (image->width + 7) / 8;
  2923. while (height--) {
  2924. expand_one_line(info->var.bits_per_pixel,
  2925. par->next_plane, dst, dst_idx, width,
  2926. src, image->bg_color,
  2927. image->fg_color);
  2928. dst_idx += par->next_line * 8;
  2929. src += pitch;
  2930. }
  2931. } else {
  2932. c2p_planar(info->screen_base, image->data, dx, dy, width,
  2933. height, par->next_line, par->next_plane,
  2934. image->width, info->var.bits_per_pixel);
  2935. }
  2936. }
  2937. /*
  2938. * Amiga Frame Buffer Specific ioctls
  2939. */
  2940. static int amifb_ioctl(struct fb_info *info,
  2941. unsigned int cmd, unsigned long arg)
  2942. {
  2943. union {
  2944. struct fb_fix_cursorinfo fix;
  2945. struct fb_var_cursorinfo var;
  2946. struct fb_cursorstate state;
  2947. } crsr;
  2948. void __user *argp = (void __user *)arg;
  2949. int i;
  2950. switch (cmd) {
  2951. case FBIOGET_FCURSORINFO:
  2952. i = ami_get_fix_cursorinfo(&crsr.fix, info->par);
  2953. if (i)
  2954. return i;
  2955. return copy_to_user(argp, &crsr.fix,
  2956. sizeof(crsr.fix)) ? -EFAULT : 0;
  2957. case FBIOGET_VCURSORINFO:
  2958. i = ami_get_var_cursorinfo(&crsr.var,
  2959. ((struct fb_var_cursorinfo __user *)arg)->data,
  2960. info->par);
  2961. if (i)
  2962. return i;
  2963. return copy_to_user(argp, &crsr.var,
  2964. sizeof(crsr.var)) ? -EFAULT : 0;
  2965. case FBIOPUT_VCURSORINFO:
  2966. if (copy_from_user(&crsr.var, argp, sizeof(crsr.var)))
  2967. return -EFAULT;
  2968. return ami_set_var_cursorinfo(&crsr.var,
  2969. ((struct fb_var_cursorinfo __user *)arg)->data,
  2970. info->par);
  2971. case FBIOGET_CURSORSTATE:
  2972. i = ami_get_cursorstate(&crsr.state, info->par);
  2973. if (i)
  2974. return i;
  2975. return copy_to_user(argp, &crsr.state,
  2976. sizeof(crsr.state)) ? -EFAULT : 0;
  2977. case FBIOPUT_CURSORSTATE:
  2978. if (copy_from_user(&crsr.state, argp, sizeof(crsr.state)))
  2979. return -EFAULT;
  2980. return ami_set_cursorstate(&crsr.state, info->par);
  2981. }
  2982. return -EINVAL;
  2983. }
  2984. /*
  2985. * Flash the cursor (called by VBlank interrupt)
  2986. */
  2987. static int flash_cursor(void)
  2988. {
  2989. static int cursorcount = 1;
  2990. if (cursormode == FB_CURSOR_FLASH) {
  2991. if (!--cursorcount) {
  2992. cursorstate = -cursorstate;
  2993. cursorcount = cursorrate;
  2994. if (!is_blanked)
  2995. return 1;
  2996. }
  2997. }
  2998. return 0;
  2999. }
  3000. /*
  3001. * VBlank Display Interrupt
  3002. */
  3003. static irqreturn_t amifb_interrupt(int irq, void *dev_id)
  3004. {
  3005. struct amifb_par *par = dev_id;
  3006. if (do_vmode_pan || do_vmode_full)
  3007. ami_update_display(par);
  3008. if (do_vmode_full)
  3009. ami_init_display(par);
  3010. if (do_vmode_pan) {
  3011. flash_cursor();
  3012. ami_rebuild_copper(par);
  3013. do_cursor = do_vmode_pan = 0;
  3014. } else if (do_cursor) {
  3015. flash_cursor();
  3016. ami_set_sprite(par);
  3017. do_cursor = 0;
  3018. } else {
  3019. if (flash_cursor())
  3020. ami_set_sprite(par);
  3021. }
  3022. if (do_blank) {
  3023. ami_do_blank(par);
  3024. do_blank = 0;
  3025. }
  3026. if (do_vmode_full) {
  3027. ami_reinit_copper(par);
  3028. do_vmode_full = 0;
  3029. }
  3030. return IRQ_HANDLED;
  3031. }
  3032. static struct fb_ops amifb_ops = {
  3033. .owner = THIS_MODULE,
  3034. .fb_check_var = amifb_check_var,
  3035. .fb_set_par = amifb_set_par,
  3036. .fb_setcolreg = amifb_setcolreg,
  3037. .fb_blank = amifb_blank,
  3038. .fb_pan_display = amifb_pan_display,
  3039. .fb_fillrect = amifb_fillrect,
  3040. .fb_copyarea = amifb_copyarea,
  3041. .fb_imageblit = amifb_imageblit,
  3042. .fb_ioctl = amifb_ioctl,
  3043. };
  3044. /*
  3045. * Allocate, Clear and Align a Block of Chip Memory
  3046. */
  3047. static void *aligned_chipptr;
  3048. static inline u_long __init chipalloc(u_long size)
  3049. {
  3050. aligned_chipptr = amiga_chip_alloc(size, "amifb [RAM]");
  3051. if (!aligned_chipptr) {
  3052. pr_err("amifb: No Chip RAM for frame buffer");
  3053. return 0;
  3054. }
  3055. memset(aligned_chipptr, 0, size);
  3056. return (u_long)aligned_chipptr;
  3057. }
  3058. static inline void chipfree(void)
  3059. {
  3060. if (aligned_chipptr)
  3061. amiga_chip_free(aligned_chipptr);
  3062. }
  3063. /*
  3064. * Initialisation
  3065. */
  3066. static int __init amifb_probe(struct platform_device *pdev)
  3067. {
  3068. struct fb_info *info;
  3069. int tag, i, err = 0;
  3070. u_long chipptr;
  3071. u_int defmode;
  3072. #ifndef MODULE
  3073. char *option = NULL;
  3074. if (fb_get_options("amifb", &option)) {
  3075. amifb_video_off();
  3076. return -ENODEV;
  3077. }
  3078. amifb_setup(option);
  3079. #endif
  3080. custom.dmacon = DMAF_ALL | DMAF_MASTER;
  3081. info = framebuffer_alloc(sizeof(struct amifb_par), &pdev->dev);
  3082. if (!info) {
  3083. dev_err(&pdev->dev, "framebuffer_alloc failed\n");
  3084. return -ENOMEM;
  3085. }
  3086. strcpy(info->fix.id, "Amiga ");
  3087. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  3088. info->fix.accel = FB_ACCEL_AMIGABLITT;
  3089. switch (amiga_chipset) {
  3090. #ifdef CONFIG_FB_AMIGA_OCS
  3091. case CS_OCS:
  3092. strcat(info->fix.id, "OCS");
  3093. default_chipset:
  3094. chipset = TAG_OCS;
  3095. maxdepth[TAG_SHRES] = 0; /* OCS means no SHRES */
  3096. maxdepth[TAG_HIRES] = 4;
  3097. maxdepth[TAG_LORES] = 6;
  3098. maxfmode = TAG_FMODE_1;
  3099. defmode = amiga_vblank == 50 ? DEFMODE_PAL : DEFMODE_NTSC;
  3100. info->fix.smem_len = VIDEOMEMSIZE_OCS;
  3101. break;
  3102. #endif /* CONFIG_FB_AMIGA_OCS */
  3103. #ifdef CONFIG_FB_AMIGA_ECS
  3104. case CS_ECS:
  3105. strcat(info->fix.id, "ECS");
  3106. chipset = TAG_ECS;
  3107. maxdepth[TAG_SHRES] = 2;
  3108. maxdepth[TAG_HIRES] = 4;
  3109. maxdepth[TAG_LORES] = 6;
  3110. maxfmode = TAG_FMODE_1;
  3111. if (AMIGAHW_PRESENT(AMBER_FF))
  3112. defmode = amiga_vblank == 50 ? DEFMODE_AMBER_PAL
  3113. : DEFMODE_AMBER_NTSC;
  3114. else
  3115. defmode = amiga_vblank == 50 ? DEFMODE_PAL
  3116. : DEFMODE_NTSC;
  3117. if (amiga_chip_avail() - CHIPRAM_SAFETY_LIMIT >
  3118. VIDEOMEMSIZE_ECS_2M)
  3119. info->fix.smem_len = VIDEOMEMSIZE_ECS_2M;
  3120. else
  3121. info->fix.smem_len = VIDEOMEMSIZE_ECS_1M;
  3122. break;
  3123. #endif /* CONFIG_FB_AMIGA_ECS */
  3124. #ifdef CONFIG_FB_AMIGA_AGA
  3125. case CS_AGA:
  3126. strcat(info->fix.id, "AGA");
  3127. chipset = TAG_AGA;
  3128. maxdepth[TAG_SHRES] = 8;
  3129. maxdepth[TAG_HIRES] = 8;
  3130. maxdepth[TAG_LORES] = 8;
  3131. maxfmode = TAG_FMODE_4;
  3132. defmode = DEFMODE_AGA;
  3133. if (amiga_chip_avail() - CHIPRAM_SAFETY_LIMIT >
  3134. VIDEOMEMSIZE_AGA_2M)
  3135. info->fix.smem_len = VIDEOMEMSIZE_AGA_2M;
  3136. else
  3137. info->fix.smem_len = VIDEOMEMSIZE_AGA_1M;
  3138. break;
  3139. #endif /* CONFIG_FB_AMIGA_AGA */
  3140. default:
  3141. #ifdef CONFIG_FB_AMIGA_OCS
  3142. printk("Unknown graphics chipset, defaulting to OCS\n");
  3143. strcat(info->fix.id, "Unknown");
  3144. goto default_chipset;
  3145. #else /* CONFIG_FB_AMIGA_OCS */
  3146. err = -ENODEV;
  3147. goto release;
  3148. #endif /* CONFIG_FB_AMIGA_OCS */
  3149. break;
  3150. }
  3151. /*
  3152. * Calculate the Pixel Clock Values for this Machine
  3153. */
  3154. {
  3155. u_long tmp = DIVUL(200000000000ULL, amiga_eclock);
  3156. pixclock[TAG_SHRES] = (tmp + 4) / 8; /* SHRES: 35 ns / 28 MHz */
  3157. pixclock[TAG_HIRES] = (tmp + 2) / 4; /* HIRES: 70 ns / 14 MHz */
  3158. pixclock[TAG_LORES] = (tmp + 1) / 2; /* LORES: 140 ns / 7 MHz */
  3159. }
  3160. /*
  3161. * Replace the Tag Values with the Real Pixel Clock Values
  3162. */
  3163. for (i = 0; i < NUM_TOTAL_MODES; i++) {
  3164. struct fb_videomode *mode = &ami_modedb[i];
  3165. tag = mode->pixclock;
  3166. if (tag == TAG_SHRES || tag == TAG_HIRES || tag == TAG_LORES) {
  3167. mode->pixclock = pixclock[tag];
  3168. }
  3169. }
  3170. if (amifb_hfmin) {
  3171. info->monspecs.hfmin = amifb_hfmin;
  3172. info->monspecs.hfmax = amifb_hfmax;
  3173. info->monspecs.vfmin = amifb_vfmin;
  3174. info->monspecs.vfmax = amifb_vfmax;
  3175. } else {
  3176. /*
  3177. * These are for a typical Amiga monitor (e.g. A1960)
  3178. */
  3179. info->monspecs.hfmin = 15000;
  3180. info->monspecs.hfmax = 38000;
  3181. info->monspecs.vfmin = 49;
  3182. info->monspecs.vfmax = 90;
  3183. }
  3184. info->fbops = &amifb_ops;
  3185. info->flags = FBINFO_DEFAULT;
  3186. info->device = &pdev->dev;
  3187. if (!fb_find_mode(&info->var, info, mode_option, ami_modedb,
  3188. NUM_TOTAL_MODES, &ami_modedb[defmode], 4)) {
  3189. err = -EINVAL;
  3190. goto release;
  3191. }
  3192. fb_videomode_to_modelist(ami_modedb, NUM_TOTAL_MODES,
  3193. &info->modelist);
  3194. round_down_bpp = 0;
  3195. chipptr = chipalloc(info->fix.smem_len + SPRITEMEMSIZE +
  3196. DUMMYSPRITEMEMSIZE + COPINITSIZE +
  3197. 4 * COPLISTSIZE);
  3198. if (!chipptr) {
  3199. err = -ENOMEM;
  3200. goto release;
  3201. }
  3202. assignchunk(videomemory, u_long, chipptr, info->fix.smem_len);
  3203. assignchunk(spritememory, u_long, chipptr, SPRITEMEMSIZE);
  3204. assignchunk(dummysprite, u_short *, chipptr, DUMMYSPRITEMEMSIZE);
  3205. assignchunk(copdisplay.init, copins *, chipptr, COPINITSIZE);
  3206. assignchunk(copdisplay.list[0][0], copins *, chipptr, COPLISTSIZE);
  3207. assignchunk(copdisplay.list[0][1], copins *, chipptr, COPLISTSIZE);
  3208. assignchunk(copdisplay.list[1][0], copins *, chipptr, COPLISTSIZE);
  3209. assignchunk(copdisplay.list[1][1], copins *, chipptr, COPLISTSIZE);
  3210. /*
  3211. * access the videomem with writethrough cache
  3212. */
  3213. info->fix.smem_start = (u_long)ZTWO_PADDR(videomemory);
  3214. videomemory = (u_long)ioremap_writethrough(info->fix.smem_start,
  3215. info->fix.smem_len);
  3216. if (!videomemory) {
  3217. dev_warn(&pdev->dev,
  3218. "Unable to map videomem cached writethrough\n");
  3219. info->screen_base = (char *)ZTWO_VADDR(info->fix.smem_start);
  3220. } else
  3221. info->screen_base = (char *)videomemory;
  3222. memset(dummysprite, 0, DUMMYSPRITEMEMSIZE);
  3223. /*
  3224. * Make sure the Copper has something to do
  3225. */
  3226. ami_init_copper();
  3227. /*
  3228. * Enable Display DMA
  3229. */
  3230. custom.dmacon = DMAF_SETCLR | DMAF_MASTER | DMAF_RASTER | DMAF_COPPER |
  3231. DMAF_BLITTER | DMAF_SPRITE;
  3232. err = request_irq(IRQ_AMIGA_COPPER, amifb_interrupt, 0,
  3233. "fb vertb handler", info->par);
  3234. if (err)
  3235. goto disable_dma;
  3236. err = fb_alloc_cmap(&info->cmap, 1 << info->var.bits_per_pixel, 0);
  3237. if (err)
  3238. goto free_irq;
  3239. dev_set_drvdata(&pdev->dev, info);
  3240. err = register_framebuffer(info);
  3241. if (err)
  3242. goto unset_drvdata;
  3243. printk("fb%d: %s frame buffer device, using %dK of video memory\n",
  3244. info->node, info->fix.id, info->fix.smem_len>>10);
  3245. return 0;
  3246. unset_drvdata:
  3247. dev_set_drvdata(&pdev->dev, NULL);
  3248. fb_dealloc_cmap(&info->cmap);
  3249. free_irq:
  3250. free_irq(IRQ_AMIGA_COPPER, info->par);
  3251. disable_dma:
  3252. custom.dmacon = DMAF_ALL | DMAF_MASTER;
  3253. if (videomemory)
  3254. iounmap((void *)videomemory);
  3255. chipfree();
  3256. release:
  3257. framebuffer_release(info);
  3258. return err;
  3259. }
  3260. static int __exit amifb_remove(struct platform_device *pdev)
  3261. {
  3262. struct fb_info *info = dev_get_drvdata(&pdev->dev);
  3263. unregister_framebuffer(info);
  3264. dev_set_drvdata(&pdev->dev, NULL);
  3265. fb_dealloc_cmap(&info->cmap);
  3266. free_irq(IRQ_AMIGA_COPPER, info->par);
  3267. custom.dmacon = DMAF_ALL | DMAF_MASTER;
  3268. if (videomemory)
  3269. iounmap((void *)videomemory);
  3270. chipfree();
  3271. framebuffer_release(info);
  3272. amifb_video_off();
  3273. return 0;
  3274. }
  3275. static struct platform_driver amifb_driver = {
  3276. .remove = __exit_p(amifb_remove),
  3277. .driver = {
  3278. .name = "amiga-video",
  3279. .owner = THIS_MODULE,
  3280. },
  3281. };
  3282. static int __init amifb_init(void)
  3283. {
  3284. return platform_driver_probe(&amifb_driver, amifb_probe);
  3285. }
  3286. module_init(amifb_init);
  3287. static void __exit amifb_exit(void)
  3288. {
  3289. platform_driver_unregister(&amifb_driver);
  3290. }
  3291. module_exit(amifb_exit);
  3292. MODULE_LICENSE("GPL");
  3293. MODULE_ALIAS("platform:amiga-video");