amifb.c 101 KB

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