atafb.c 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106
  1. /*
  2. * linux/drivers/video/atafb.c -- Atari builtin chipset frame buffer device
  3. *
  4. * Copyright (C) 1994 Martin Schaller & Roman Hodek
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive
  8. * for more details.
  9. *
  10. * History:
  11. * - 03 Jan 95: Original version by Martin Schaller: The TT driver and
  12. * all the device independent stuff
  13. * - 09 Jan 95: Roman: I've added the hardware abstraction (hw_switch)
  14. * and wrote the Falcon, ST(E), and External drivers
  15. * based on the original TT driver.
  16. * - 07 May 95: Martin: Added colormap operations for the external driver
  17. * - 21 May 95: Martin: Added support for overscan
  18. * Andreas: some bug fixes for this
  19. * - Jul 95: Guenther Kelleter <guenther@pool.informatik.rwth-aachen.de>:
  20. * Programmable Falcon video modes
  21. * (thanks to Christian Cartus for documentation
  22. * of VIDEL registers).
  23. * - 27 Dec 95: Guenther: Implemented user definable video modes "user[0-7]"
  24. * on minor 24...31. "user0" may be set on commandline by
  25. * "R<x>;<y>;<depth>". (Makes sense only on Falcon)
  26. * Video mode switch on Falcon now done at next VBL interrupt
  27. * to avoid the annoying right shift of the screen.
  28. * - 23 Sep 97: Juergen: added xres_virtual for cards like ProMST
  29. * The external-part is legacy, therefore hardware-specific
  30. * functions like panning/hardwarescrolling/blanking isn't
  31. * supported.
  32. * - 29 Sep 97: Juergen: added Romans suggestion for pan_display
  33. * (var->xoffset was changed even if no set_screen_base avail.)
  34. * - 05 Oct 97: Juergen: extfb (PACKED_PIXEL) is FB_PSEUDOCOLOR 'cause
  35. * we know how to set the colors
  36. * ext_*palette: read from ext_colors (former MV300_colors)
  37. * write to ext_colors and RAMDAC
  38. *
  39. * To do:
  40. * - For the Falcon it is not possible to set random video modes on
  41. * SM124 and SC/TV, only the bootup resolution is supported.
  42. *
  43. */
  44. #define ATAFB_TT
  45. #define ATAFB_STE
  46. #define ATAFB_EXT
  47. #define ATAFB_FALCON
  48. #include <linux/module.h>
  49. #include <linux/kernel.h>
  50. #include <linux/errno.h>
  51. #include <linux/string.h>
  52. #include <linux/mm.h>
  53. #include <linux/slab.h>
  54. #include <linux/delay.h>
  55. #include <linux/init.h>
  56. #include <linux/interrupt.h>
  57. #include <asm/setup.h>
  58. #include <asm/uaccess.h>
  59. #include <asm/pgtable.h>
  60. #include <asm/irq.h>
  61. #include <asm/io.h>
  62. #include <asm/atarihw.h>
  63. #include <asm/atariints.h>
  64. #include <asm/atari_stram.h>
  65. #include <linux/fb.h>
  66. #include <asm/atarikb.h>
  67. #include <video/fbcon.h>
  68. #include <video/fbcon-cfb8.h>
  69. #include <video/fbcon-cfb16.h>
  70. #include <video/fbcon-iplan2p2.h>
  71. #include <video/fbcon-iplan2p4.h>
  72. #include <video/fbcon-iplan2p8.h>
  73. #include <video/fbcon-mfb.h>
  74. #define SWITCH_ACIA 0x01 /* modes for switch on OverScan */
  75. #define SWITCH_SND6 0x40
  76. #define SWITCH_SND7 0x80
  77. #define SWITCH_NONE 0x00
  78. #define up(x, r) (((x) + (r) - 1) & ~((r)-1))
  79. static int default_par=0; /* default resolution (0=none) */
  80. static unsigned long default_mem_req=0;
  81. static int hwscroll=-1;
  82. static int use_hwscroll = 1;
  83. static int sttt_xres=640,st_yres=400,tt_yres=480;
  84. static int sttt_xres_virtual=640,sttt_yres_virtual=400;
  85. static int ovsc_offset=0, ovsc_addlen=0;
  86. static struct atafb_par {
  87. void *screen_base;
  88. int yres_virtual;
  89. #if defined ATAFB_TT || defined ATAFB_STE
  90. union {
  91. struct {
  92. int mode;
  93. int sync;
  94. } tt, st;
  95. #endif
  96. #ifdef ATAFB_FALCON
  97. struct falcon_hw {
  98. /* Here are fields for storing a video mode, as direct
  99. * parameters for the hardware.
  100. */
  101. short sync;
  102. short line_width;
  103. short line_offset;
  104. short st_shift;
  105. short f_shift;
  106. short vid_control;
  107. short vid_mode;
  108. short xoffset;
  109. short hht, hbb, hbe, hdb, hde, hss;
  110. short vft, vbb, vbe, vdb, vde, vss;
  111. /* auxiliary information */
  112. short mono;
  113. short ste_mode;
  114. short bpp;
  115. } falcon;
  116. #endif
  117. /* Nothing needed for external mode */
  118. } hw;
  119. } current_par;
  120. /* Don't calculate an own resolution, and thus don't change the one found when
  121. * booting (currently used for the Falcon to keep settings for internal video
  122. * hardware extensions (e.g. ScreenBlaster) */
  123. static int DontCalcRes = 0;
  124. #ifdef ATAFB_FALCON
  125. #define HHT hw.falcon.hht
  126. #define HBB hw.falcon.hbb
  127. #define HBE hw.falcon.hbe
  128. #define HDB hw.falcon.hdb
  129. #define HDE hw.falcon.hde
  130. #define HSS hw.falcon.hss
  131. #define VFT hw.falcon.vft
  132. #define VBB hw.falcon.vbb
  133. #define VBE hw.falcon.vbe
  134. #define VDB hw.falcon.vdb
  135. #define VDE hw.falcon.vde
  136. #define VSS hw.falcon.vss
  137. #define VCO_CLOCK25 0x04
  138. #define VCO_CSYPOS 0x10
  139. #define VCO_VSYPOS 0x20
  140. #define VCO_HSYPOS 0x40
  141. #define VCO_SHORTOFFS 0x100
  142. #define VMO_DOUBLE 0x01
  143. #define VMO_INTER 0x02
  144. #define VMO_PREMASK 0x0c
  145. #endif
  146. static struct fb_info fb_info;
  147. static void *screen_base; /* base address of screen */
  148. static void *real_screen_base; /* (only for Overscan) */
  149. static int screen_len;
  150. static int current_par_valid=0;
  151. static int mono_moni=0;
  152. static struct display disp;
  153. #ifdef ATAFB_EXT
  154. /* external video handling */
  155. static unsigned external_xres;
  156. static unsigned external_xres_virtual;
  157. static unsigned external_yres;
  158. /* not needed - atafb will never support panning/hardwarescroll with external
  159. * static unsigned external_yres_virtual;
  160. */
  161. static unsigned external_depth;
  162. static int external_pmode;
  163. static void *external_addr = 0;
  164. static unsigned long external_len;
  165. static unsigned long external_vgaiobase = 0;
  166. static unsigned int external_bitspercol = 6;
  167. /*
  168. JOE <joe@amber.dinoco.de>:
  169. added card type for external driver, is only needed for
  170. colormap handling.
  171. */
  172. enum cardtype { IS_VGA, IS_MV300 };
  173. static enum cardtype external_card_type = IS_VGA;
  174. /*
  175. The MV300 mixes the color registers. So we need an array of munged
  176. indices in order to access the correct reg.
  177. */
  178. static int MV300_reg_1bit[2]={0,1};
  179. static int MV300_reg_4bit[16]={
  180. 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 };
  181. static int MV300_reg_8bit[256]={
  182. 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240,
  183. 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248,
  184. 4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244,
  185. 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252,
  186. 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242,
  187. 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250,
  188. 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246,
  189. 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254,
  190. 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241,
  191. 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249,
  192. 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245,
  193. 13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253,
  194. 3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243,
  195. 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251,
  196. 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247,
  197. 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255 };
  198. static int *MV300_reg = MV300_reg_8bit;
  199. /*
  200. And on the MV300 it's difficult to read out the hardware palette. So we
  201. just keep track of the set colors in our own array here, and use that!
  202. */
  203. static struct { unsigned char red,green,blue,pad; } ext_color[256];
  204. #endif /* ATAFB_EXT */
  205. static int inverse=0;
  206. extern int fontheight_8x8;
  207. extern int fontwidth_8x8;
  208. extern unsigned char fontdata_8x8[];
  209. extern int fontheight_8x16;
  210. extern int fontwidth_8x16;
  211. extern unsigned char fontdata_8x16[];
  212. /* ++roman: This structure abstracts from the underlying hardware (ST(e),
  213. * TT, or Falcon.
  214. *
  215. * int (*detect)( void )
  216. * This function should detect the current video mode settings and
  217. * store them in atafb_predefined[0] for later reference by the
  218. * user. Return the index+1 of an equivalent predefined mode or 0
  219. * if there is no such.
  220. *
  221. * int (*encode_fix)( struct fb_fix_screeninfo *fix,
  222. * struct atafb_par *par )
  223. * This function should fill in the 'fix' structure based on the
  224. * values in the 'par' structure.
  225. *
  226. * int (*decode_var)( struct fb_var_screeninfo *var,
  227. * struct atafb_par *par )
  228. * Get the video params out of 'var'. If a value doesn't fit, round
  229. * it up, if it's too big, return EINVAL.
  230. * Round up in the following order: bits_per_pixel, xres, yres,
  231. * xres_virtual, yres_virtual, xoffset, yoffset, grayscale, bitfields,
  232. * horizontal timing, vertical timing.
  233. *
  234. * int (*encode_var)( struct fb_var_screeninfo *var,
  235. * struct atafb_par *par );
  236. * Fill the 'var' structure based on the values in 'par' and maybe
  237. * other values read out of the hardware.
  238. *
  239. * void (*get_par)( struct atafb_par *par )
  240. * Fill the hardware's 'par' structure.
  241. *
  242. * void (*set_par)( struct atafb_par *par )
  243. * Set the hardware according to 'par'.
  244. *
  245. * int (*getcolreg)( unsigned regno, unsigned *red,
  246. * unsigned *green, unsigned *blue,
  247. * unsigned *transp, struct fb_info *info )
  248. * Read a single color register and split it into
  249. * colors/transparent. Return != 0 for invalid regno.
  250. *
  251. * void (*set_screen_base)(void *s_base)
  252. * Set the base address of the displayed frame buffer. Only called
  253. * if yres_virtual > yres or xres_virtual > xres.
  254. *
  255. * int (*blank)( int blank_mode )
  256. * Blank the screen if blank_mode!=0, else unblank. If blank==NULL then
  257. * the caller blanks by setting the CLUT to all black. Return 0 if blanking
  258. * succeeded, !=0 if un-/blanking failed due to e.g. a video mode which
  259. * doesn't support it. Implements VESA suspend and powerdown modes on
  260. * hardware that supports disabling hsync/vsync:
  261. * blank_mode==2: suspend vsync, 3:suspend hsync, 4: powerdown.
  262. */
  263. static struct fb_hwswitch {
  264. int (*detect)( void );
  265. int (*encode_fix)( struct fb_fix_screeninfo *fix,
  266. struct atafb_par *par );
  267. int (*decode_var)( struct fb_var_screeninfo *var,
  268. struct atafb_par *par );
  269. int (*encode_var)( struct fb_var_screeninfo *var,
  270. struct atafb_par *par );
  271. void (*get_par)( struct atafb_par *par );
  272. void (*set_par)( struct atafb_par *par );
  273. int (*getcolreg)( unsigned regno, unsigned *red,
  274. unsigned *green, unsigned *blue,
  275. unsigned *transp, struct fb_info *info );
  276. void (*set_screen_base)(void *s_base);
  277. int (*blank)( int blank_mode );
  278. int (*pan_display)( struct fb_var_screeninfo *var,
  279. struct atafb_par *par);
  280. } *fbhw;
  281. static char *autodetect_names[] = {"autodetect", NULL};
  282. static char *stlow_names[] = {"stlow", NULL};
  283. static char *stmid_names[] = {"stmid", "default5", NULL};
  284. static char *sthigh_names[] = {"sthigh", "default4", NULL};
  285. static char *ttlow_names[] = {"ttlow", NULL};
  286. static char *ttmid_names[]= {"ttmid", "default1", NULL};
  287. static char *tthigh_names[]= {"tthigh", "default2", NULL};
  288. static char *vga2_names[] = {"vga2", NULL};
  289. static char *vga4_names[] = {"vga4", NULL};
  290. static char *vga16_names[] = {"vga16", "default3", NULL};
  291. static char *vga256_names[] = {"vga256", NULL};
  292. static char *falh2_names[] = {"falh2", NULL};
  293. static char *falh16_names[] = {"falh16", NULL};
  294. static char **fb_var_names[] = {
  295. /* Writing the name arrays directly in this array (via "(char *[]){...}")
  296. * crashes gcc 2.5.8 (sigsegv) if the inner array
  297. * contains more than two items. I've also seen that all elements
  298. * were identical to the last (my cross-gcc) :-(*/
  299. autodetect_names,
  300. stlow_names,
  301. stmid_names,
  302. sthigh_names,
  303. ttlow_names,
  304. ttmid_names,
  305. tthigh_names,
  306. vga2_names,
  307. vga4_names,
  308. vga16_names,
  309. vga256_names,
  310. falh2_names,
  311. falh16_names,
  312. NULL
  313. /* ,NULL */ /* this causes a sigsegv on my gcc-2.5.8 */
  314. };
  315. static struct fb_var_screeninfo atafb_predefined[] = {
  316. /*
  317. * yres_virtual==0 means use hw-scrolling if possible, else yres
  318. */
  319. { /* autodetect */
  320. 0, 0, 0, 0, 0, 0, 0, 0, /* xres-grayscale */
  321. {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, /* red green blue tran*/
  322. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  323. { /* st low */
  324. 320, 200, 320, 0, 0, 0, 4, 0,
  325. {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
  326. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  327. { /* st mid */
  328. 640, 200, 640, 0, 0, 0, 2, 0,
  329. {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
  330. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  331. { /* st high */
  332. 640, 400, 640, 0, 0, 0, 1, 0,
  333. {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
  334. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  335. { /* tt low */
  336. 320, 480, 320, 0, 0, 0, 8, 0,
  337. {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
  338. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  339. { /* tt mid */
  340. 640, 480, 640, 0, 0, 0, 4, 0,
  341. {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
  342. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  343. { /* tt high */
  344. 1280, 960, 1280, 0, 0, 0, 1, 0,
  345. {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
  346. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  347. { /* vga2 */
  348. 640, 480, 640, 0, 0, 0, 1, 0,
  349. {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
  350. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  351. { /* vga4 */
  352. 640, 480, 640, 0, 0, 0, 2, 0,
  353. {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0},
  354. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  355. { /* vga16 */
  356. 640, 480, 640, 0, 0, 0, 4, 0,
  357. {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
  358. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  359. { /* vga256 */
  360. 640, 480, 640, 0, 0, 0, 8, 0,
  361. {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
  362. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  363. { /* falh2 */
  364. 896, 608, 896, 0, 0, 0, 1, 0,
  365. {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
  366. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  367. { /* falh16 */
  368. 896, 608, 896, 0, 0, 0, 4, 0,
  369. {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
  370. 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
  371. };
  372. static int num_atafb_predefined=ARRAY_SIZE(atafb_predefined);
  373. static int
  374. get_video_mode(char *vname)
  375. {
  376. char ***name_list;
  377. char **name;
  378. int i;
  379. name_list=fb_var_names;
  380. for (i = 0 ; i < num_atafb_predefined ; i++) {
  381. name=*(name_list++);
  382. if (! name || ! *name)
  383. break;
  384. while (*name) {
  385. if (! strcmp(vname, *name))
  386. return i+1;
  387. name++;
  388. }
  389. }
  390. return 0;
  391. }
  392. /* ------------------- TT specific functions ---------------------- */
  393. #ifdef ATAFB_TT
  394. static int tt_encode_fix( struct fb_fix_screeninfo *fix,
  395. struct atafb_par *par )
  396. {
  397. int mode;
  398. strcpy(fix->id,"Atari Builtin");
  399. fix->smem_start = (unsigned long)real_screen_base;
  400. fix->smem_len = screen_len;
  401. fix->type=FB_TYPE_INTERLEAVED_PLANES;
  402. fix->type_aux=2;
  403. fix->visual=FB_VISUAL_PSEUDOCOLOR;
  404. mode = par->hw.tt.mode & TT_SHIFTER_MODEMASK;
  405. if (mode == TT_SHIFTER_TTHIGH || mode == TT_SHIFTER_STHIGH) {
  406. fix->type=FB_TYPE_PACKED_PIXELS;
  407. fix->type_aux=0;
  408. if (mode == TT_SHIFTER_TTHIGH)
  409. fix->visual=FB_VISUAL_MONO01;
  410. }
  411. fix->xpanstep=0;
  412. fix->ypanstep=1;
  413. fix->ywrapstep=0;
  414. fix->line_length = 0;
  415. fix->accel = FB_ACCEL_ATARIBLITT;
  416. return 0;
  417. }
  418. static int tt_decode_var( struct fb_var_screeninfo *var,
  419. struct atafb_par *par )
  420. {
  421. int xres=var->xres;
  422. int yres=var->yres;
  423. int bpp=var->bits_per_pixel;
  424. int linelen;
  425. int yres_virtual = var->yres_virtual;
  426. if (mono_moni) {
  427. if (bpp > 1 || xres > sttt_xres*2 || yres >tt_yres*2)
  428. return -EINVAL;
  429. par->hw.tt.mode=TT_SHIFTER_TTHIGH;
  430. xres=sttt_xres*2;
  431. yres=tt_yres*2;
  432. bpp=1;
  433. } else {
  434. if (bpp > 8 || xres > sttt_xres || yres > tt_yres)
  435. return -EINVAL;
  436. if (bpp > 4) {
  437. if (xres > sttt_xres/2 || yres > tt_yres)
  438. return -EINVAL;
  439. par->hw.tt.mode=TT_SHIFTER_TTLOW;
  440. xres=sttt_xres/2;
  441. yres=tt_yres;
  442. bpp=8;
  443. }
  444. else if (bpp > 2) {
  445. if (xres > sttt_xres || yres > tt_yres)
  446. return -EINVAL;
  447. if (xres > sttt_xres/2 || yres > st_yres/2) {
  448. par->hw.tt.mode=TT_SHIFTER_TTMID;
  449. xres=sttt_xres;
  450. yres=tt_yres;
  451. bpp=4;
  452. }
  453. else {
  454. par->hw.tt.mode=TT_SHIFTER_STLOW;
  455. xres=sttt_xres/2;
  456. yres=st_yres/2;
  457. bpp=4;
  458. }
  459. }
  460. else if (bpp > 1) {
  461. if (xres > sttt_xres || yres > st_yres/2)
  462. return -EINVAL;
  463. par->hw.tt.mode=TT_SHIFTER_STMID;
  464. xres=sttt_xres;
  465. yres=st_yres/2;
  466. bpp=2;
  467. }
  468. else if (var->xres > sttt_xres || var->yres > st_yres) {
  469. return -EINVAL;
  470. }
  471. else {
  472. par->hw.tt.mode=TT_SHIFTER_STHIGH;
  473. xres=sttt_xres;
  474. yres=st_yres;
  475. bpp=1;
  476. }
  477. }
  478. if (yres_virtual <= 0)
  479. yres_virtual = 0;
  480. else if (yres_virtual < yres)
  481. yres_virtual = yres;
  482. if (var->sync & FB_SYNC_EXT)
  483. par->hw.tt.sync=0;
  484. else
  485. par->hw.tt.sync=1;
  486. linelen=xres*bpp/8;
  487. if (yres_virtual * linelen > screen_len && screen_len)
  488. return -EINVAL;
  489. if (yres * linelen > screen_len && screen_len)
  490. return -EINVAL;
  491. if (var->yoffset + yres > yres_virtual && yres_virtual)
  492. return -EINVAL;
  493. par->yres_virtual = yres_virtual;
  494. par->screen_base = screen_base + var->yoffset * linelen;
  495. return 0;
  496. }
  497. static int tt_encode_var( struct fb_var_screeninfo *var,
  498. struct atafb_par *par )
  499. {
  500. int linelen;
  501. memset(var, 0, sizeof(struct fb_var_screeninfo));
  502. var->red.offset=0;
  503. var->red.length=4;
  504. var->red.msb_right=0;
  505. var->grayscale=0;
  506. var->pixclock=31041;
  507. var->left_margin=120; /* these may be incorrect */
  508. var->right_margin=100;
  509. var->upper_margin=8;
  510. var->lower_margin=16;
  511. var->hsync_len=140;
  512. var->vsync_len=30;
  513. var->height=-1;
  514. var->width=-1;
  515. if (par->hw.tt.sync & 1)
  516. var->sync=0;
  517. else
  518. var->sync=FB_SYNC_EXT;
  519. switch (par->hw.tt.mode & TT_SHIFTER_MODEMASK) {
  520. case TT_SHIFTER_STLOW:
  521. var->xres=sttt_xres/2;
  522. var->xres_virtual=sttt_xres_virtual/2;
  523. var->yres=st_yres/2;
  524. var->bits_per_pixel=4;
  525. break;
  526. case TT_SHIFTER_STMID:
  527. var->xres=sttt_xres;
  528. var->xres_virtual=sttt_xres_virtual;
  529. var->yres=st_yres/2;
  530. var->bits_per_pixel=2;
  531. break;
  532. case TT_SHIFTER_STHIGH:
  533. var->xres=sttt_xres;
  534. var->xres_virtual=sttt_xres_virtual;
  535. var->yres=st_yres;
  536. var->bits_per_pixel=1;
  537. break;
  538. case TT_SHIFTER_TTLOW:
  539. var->xres=sttt_xres/2;
  540. var->xres_virtual=sttt_xres_virtual/2;
  541. var->yres=tt_yres;
  542. var->bits_per_pixel=8;
  543. break;
  544. case TT_SHIFTER_TTMID:
  545. var->xres=sttt_xres;
  546. var->xres_virtual=sttt_xres_virtual;
  547. var->yres=tt_yres;
  548. var->bits_per_pixel=4;
  549. break;
  550. case TT_SHIFTER_TTHIGH:
  551. var->red.length=0;
  552. var->xres=sttt_xres*2;
  553. var->xres_virtual=sttt_xres_virtual*2;
  554. var->yres=tt_yres*2;
  555. var->bits_per_pixel=1;
  556. break;
  557. }
  558. var->blue=var->green=var->red;
  559. var->transp.offset=0;
  560. var->transp.length=0;
  561. var->transp.msb_right=0;
  562. linelen=var->xres_virtual * var->bits_per_pixel / 8;
  563. if (! use_hwscroll)
  564. var->yres_virtual=var->yres;
  565. else if (screen_len) {
  566. if (par->yres_virtual)
  567. var->yres_virtual = par->yres_virtual;
  568. else
  569. /* yres_virtual==0 means use maximum */
  570. var->yres_virtual = screen_len / linelen;
  571. } else {
  572. if (hwscroll < 0)
  573. var->yres_virtual = 2 * var->yres;
  574. else
  575. var->yres_virtual=var->yres+hwscroll * 16;
  576. }
  577. var->xoffset=0;
  578. if (screen_base)
  579. var->yoffset=(par->screen_base - screen_base)/linelen;
  580. else
  581. var->yoffset=0;
  582. var->nonstd=0;
  583. var->activate=0;
  584. var->vmode=FB_VMODE_NONINTERLACED;
  585. return 0;
  586. }
  587. static void tt_get_par( struct atafb_par *par )
  588. {
  589. unsigned long addr;
  590. par->hw.tt.mode=shifter_tt.tt_shiftmode;
  591. par->hw.tt.sync=shifter.syncmode;
  592. addr = ((shifter.bas_hi & 0xff) << 16) |
  593. ((shifter.bas_md & 0xff) << 8) |
  594. ((shifter.bas_lo & 0xff));
  595. par->screen_base = phys_to_virt(addr);
  596. }
  597. static void tt_set_par( struct atafb_par *par )
  598. {
  599. shifter_tt.tt_shiftmode=par->hw.tt.mode;
  600. shifter.syncmode=par->hw.tt.sync;
  601. /* only set screen_base if really necessary */
  602. if (current_par.screen_base != par->screen_base)
  603. fbhw->set_screen_base(par->screen_base);
  604. }
  605. static int tt_getcolreg(unsigned regno, unsigned *red,
  606. unsigned *green, unsigned *blue,
  607. unsigned *transp, struct fb_info *info)
  608. {
  609. int t, col;
  610. if ((shifter_tt.tt_shiftmode & TT_SHIFTER_MODEMASK) == TT_SHIFTER_STHIGH)
  611. regno += 254;
  612. if (regno > 255)
  613. return 1;
  614. t = tt_palette[regno];
  615. col = t & 15;
  616. col |= col << 4;
  617. col |= col << 8;
  618. *blue = col;
  619. col = (t >> 4) & 15;
  620. col |= col << 4;
  621. col |= col << 8;
  622. *green = col;
  623. col = (t >> 8) & 15;
  624. col |= col << 4;
  625. col |= col << 8;
  626. *red = col;
  627. *transp = 0;
  628. return 0;
  629. }
  630. static int tt_setcolreg(unsigned regno, unsigned red,
  631. unsigned green, unsigned blue,
  632. unsigned transp, struct fb_info *info)
  633. {
  634. if ((shifter_tt.tt_shiftmode & TT_SHIFTER_MODEMASK) == TT_SHIFTER_STHIGH)
  635. regno += 254;
  636. if (regno > 255)
  637. return 1;
  638. tt_palette[regno] = (((red >> 12) << 8) | ((green >> 12) << 4) |
  639. (blue >> 12));
  640. if ((shifter_tt.tt_shiftmode & TT_SHIFTER_MODEMASK) ==
  641. TT_SHIFTER_STHIGH && regno == 254)
  642. tt_palette[0] = 0;
  643. return 0;
  644. }
  645. static int tt_detect( void )
  646. { struct atafb_par par;
  647. /* Determine the connected monitor: The DMA sound must be
  648. * disabled before reading the MFP GPIP, because the Sound
  649. * Done Signal and the Monochrome Detect are XORed together!
  650. *
  651. * Even on a TT, we should look if there is a DMA sound. It was
  652. * announced that the Eagle is TT compatible, but only the PCM is
  653. * missing...
  654. */
  655. if (ATARIHW_PRESENT(PCM_8BIT)) {
  656. tt_dmasnd.ctrl = DMASND_CTRL_OFF;
  657. udelay(20); /* wait a while for things to settle down */
  658. }
  659. mono_moni = (mfp.par_dt_reg & 0x80) == 0;
  660. tt_get_par(&par);
  661. tt_encode_var(&atafb_predefined[0], &par);
  662. return 1;
  663. }
  664. #endif /* ATAFB_TT */
  665. /* ------------------- Falcon specific functions ---------------------- */
  666. #ifdef ATAFB_FALCON
  667. static int mon_type; /* Falcon connected monitor */
  668. static int f030_bus_width; /* Falcon ram bus width (for vid_control) */
  669. #define F_MON_SM 0
  670. #define F_MON_SC 1
  671. #define F_MON_VGA 2
  672. #define F_MON_TV 3
  673. static struct pixel_clock {
  674. unsigned long f; /* f/[Hz] */
  675. unsigned long t; /* t/[ps] (=1/f) */
  676. int right, hsync, left; /* standard timing in clock cycles, not pixel */
  677. /* hsync initialized in falcon_detect() */
  678. int sync_mask; /* or-mask for hw.falcon.sync to set this clock */
  679. int control_mask; /* ditto, for hw.falcon.vid_control */
  680. }
  681. f25 = {25175000, 39721, 18, 0, 42, 0x0, VCO_CLOCK25},
  682. f32 = {32000000, 31250, 18, 0, 42, 0x0, 0},
  683. fext = { 0, 0, 18, 0, 42, 0x1, 0};
  684. /* VIDEL-prescale values [mon_type][pixel_length from VCO] */
  685. static int vdl_prescale[4][3] = {{4,2,1}, {4,2,1}, {4,2,2}, {4,2,1}};
  686. /* Default hsync timing [mon_type] in picoseconds */
  687. static long h_syncs[4] = {3000000, 4875000, 4000000, 4875000};
  688. #ifdef FBCON_HAS_CFB16
  689. static u16 fbcon_cfb16_cmap[16];
  690. #endif
  691. static inline int hxx_prescale(struct falcon_hw *hw)
  692. {
  693. return hw->ste_mode ? 16 :
  694. vdl_prescale[mon_type][hw->vid_mode >> 2 & 0x3];
  695. }
  696. static int falcon_encode_fix( struct fb_fix_screeninfo *fix,
  697. struct atafb_par *par )
  698. {
  699. strcpy(fix->id, "Atari Builtin");
  700. fix->smem_start = (unsigned long)real_screen_base;
  701. fix->smem_len = screen_len;
  702. fix->type = FB_TYPE_INTERLEAVED_PLANES;
  703. fix->type_aux = 2;
  704. fix->visual = FB_VISUAL_PSEUDOCOLOR;
  705. fix->xpanstep = 1;
  706. fix->ypanstep = 1;
  707. fix->ywrapstep = 0;
  708. if (par->hw.falcon.mono) {
  709. fix->type = FB_TYPE_PACKED_PIXELS;
  710. fix->type_aux = 0;
  711. /* no smooth scrolling with longword aligned video mem */
  712. fix->xpanstep = 32;
  713. }
  714. else if (par->hw.falcon.f_shift & 0x100) {
  715. fix->type = FB_TYPE_PACKED_PIXELS;
  716. fix->type_aux = 0;
  717. /* Is this ok or should it be DIRECTCOLOR? */
  718. fix->visual = FB_VISUAL_TRUECOLOR;
  719. fix->xpanstep = 2;
  720. }
  721. fix->line_length = 0;
  722. fix->accel = FB_ACCEL_ATARIBLITT;
  723. return 0;
  724. }
  725. static int falcon_decode_var( struct fb_var_screeninfo *var,
  726. struct atafb_par *par )
  727. {
  728. int bpp = var->bits_per_pixel;
  729. int xres = var->xres;
  730. int yres = var->yres;
  731. int xres_virtual = var->xres_virtual;
  732. int yres_virtual = var->yres_virtual;
  733. int left_margin, right_margin, hsync_len;
  734. int upper_margin, lower_margin, vsync_len;
  735. int linelen;
  736. int interlace = 0, doubleline = 0;
  737. struct pixel_clock *pclock;
  738. int plen; /* width of pixel in clock cycles */
  739. int xstretch;
  740. int prescale;
  741. int longoffset = 0;
  742. int hfreq, vfreq;
  743. /*
  744. Get the video params out of 'var'. If a value doesn't fit, round
  745. it up, if it's too big, return EINVAL.
  746. Round up in the following order: bits_per_pixel, xres, yres,
  747. xres_virtual, yres_virtual, xoffset, yoffset, grayscale, bitfields,
  748. horizontal timing, vertical timing.
  749. There is a maximum of screen resolution determined by pixelclock
  750. and minimum frame rate -- (X+hmarg.)*(Y+vmarg.)*vfmin <= pixelclock.
  751. In interlace mode this is " * " *vfmin <= pixelclock.
  752. Additional constraints: hfreq.
  753. Frequency range for multisync monitors is given via command line.
  754. For TV and SM124 both frequencies are fixed.
  755. X % 16 == 0 to fit 8x?? font (except 1 bitplane modes must use X%32==0)
  756. Y % 16 == 0 to fit 8x16 font
  757. Y % 8 == 0 if Y<400
  758. Currently interlace and doubleline mode in var are ignored.
  759. On SM124 and TV only the standard resolutions can be used.
  760. */
  761. /* Reject uninitialized mode */
  762. if (!xres || !yres || !bpp)
  763. return -EINVAL;
  764. if (mon_type == F_MON_SM && bpp != 1) {
  765. return -EINVAL;
  766. }
  767. else if (bpp <= 1) {
  768. bpp = 1;
  769. par->hw.falcon.f_shift = 0x400;
  770. par->hw.falcon.st_shift = 0x200;
  771. }
  772. else if (bpp <= 2) {
  773. bpp = 2;
  774. par->hw.falcon.f_shift = 0x000;
  775. par->hw.falcon.st_shift = 0x100;
  776. }
  777. else if (bpp <= 4) {
  778. bpp = 4;
  779. par->hw.falcon.f_shift = 0x000;
  780. par->hw.falcon.st_shift = 0x000;
  781. }
  782. else if (bpp <= 8) {
  783. bpp = 8;
  784. par->hw.falcon.f_shift = 0x010;
  785. }
  786. else if (bpp <= 16) {
  787. bpp = 16; /* packed pixel mode */
  788. par->hw.falcon.f_shift = 0x100; /* hicolor, no overlay */
  789. }
  790. else
  791. return -EINVAL;
  792. par->hw.falcon.bpp = bpp;
  793. if (mon_type == F_MON_SM || DontCalcRes) {
  794. /* Skip all calculations. VGA/TV/SC1224 only supported. */
  795. struct fb_var_screeninfo *myvar = &atafb_predefined[0];
  796. if (bpp > myvar->bits_per_pixel ||
  797. var->xres > myvar->xres ||
  798. var->yres > myvar->yres)
  799. return -EINVAL;
  800. fbhw->get_par(par); /* Current par will be new par */
  801. goto set_screen_base; /* Don't forget this */
  802. }
  803. /* Only some fixed resolutions < 640x400 */
  804. if (xres <= 320)
  805. xres = 320;
  806. else if (xres <= 640 && bpp != 16)
  807. xres = 640;
  808. if (yres <= 200)
  809. yres = 200;
  810. else if (yres <= 240)
  811. yres = 240;
  812. else if (yres <= 400)
  813. yres = 400;
  814. /* 2 planes must use STE compatibility mode */
  815. par->hw.falcon.ste_mode = bpp==2;
  816. par->hw.falcon.mono = bpp==1;
  817. /* Total and visible scanline length must be a multiple of one longword,
  818. * this and the console fontwidth yields the alignment for xres and
  819. * xres_virtual.
  820. * TODO: this way "odd" fontheights are not supported
  821. *
  822. * Special case in STE mode: blank and graphic positions don't align,
  823. * avoid trash at right margin
  824. */
  825. if (par->hw.falcon.ste_mode)
  826. xres = (xres + 63) & ~63;
  827. else if (bpp == 1)
  828. xres = (xres + 31) & ~31;
  829. else
  830. xres = (xres + 15) & ~15;
  831. if (yres >= 400)
  832. yres = (yres + 15) & ~15;
  833. else
  834. yres = (yres + 7) & ~7;
  835. if (xres_virtual < xres)
  836. xres_virtual = xres;
  837. else if (bpp == 1)
  838. xres_virtual = (xres_virtual + 31) & ~31;
  839. else
  840. xres_virtual = (xres_virtual + 15) & ~15;
  841. if (yres_virtual <= 0)
  842. yres_virtual = 0;
  843. else if (yres_virtual < yres)
  844. yres_virtual = yres;
  845. /* backward bug-compatibility */
  846. if (var->pixclock > 1)
  847. var->pixclock -= 1;
  848. par->hw.falcon.line_width = bpp * xres / 16;
  849. par->hw.falcon.line_offset = bpp * (xres_virtual - xres) / 16;
  850. /* single or double pixel width */
  851. xstretch = (xres < 640) ? 2 : 1;
  852. #if 0 /* SM124 supports only 640x400, this is rejected above */
  853. if (mon_type == F_MON_SM) {
  854. if (xres != 640 && yres != 400)
  855. return -EINVAL;
  856. plen = 1;
  857. pclock = &f32;
  858. /* SM124-mode is special */
  859. par->hw.falcon.ste_mode = 1;
  860. par->hw.falcon.f_shift = 0x000;
  861. par->hw.falcon.st_shift = 0x200;
  862. left_margin = hsync_len = 128 / plen;
  863. right_margin = 0;
  864. /* TODO set all margins */
  865. }
  866. else
  867. #endif
  868. if (mon_type == F_MON_SC || mon_type == F_MON_TV) {
  869. plen = 2 * xstretch;
  870. if (var->pixclock > f32.t * plen)
  871. return -EINVAL;
  872. pclock = &f32;
  873. if (yres > 240)
  874. interlace = 1;
  875. if (var->pixclock == 0) {
  876. /* set some minimal margins which center the screen */
  877. left_margin = 32;
  878. right_margin = 18;
  879. hsync_len = pclock->hsync / plen;
  880. upper_margin = 31;
  881. lower_margin = 14;
  882. vsync_len = interlace ? 3 : 4;
  883. } else {
  884. left_margin = var->left_margin;
  885. right_margin = var->right_margin;
  886. hsync_len = var->hsync_len;
  887. upper_margin = var->upper_margin;
  888. lower_margin = var->lower_margin;
  889. vsync_len = var->vsync_len;
  890. if (var->vmode & FB_VMODE_INTERLACED) {
  891. upper_margin = (upper_margin + 1) / 2;
  892. lower_margin = (lower_margin + 1) / 2;
  893. vsync_len = (vsync_len + 1) / 2;
  894. } else if (var->vmode & FB_VMODE_DOUBLE) {
  895. upper_margin *= 2;
  896. lower_margin *= 2;
  897. vsync_len *= 2;
  898. }
  899. }
  900. }
  901. else
  902. { /* F_MON_VGA */
  903. if (bpp == 16)
  904. xstretch = 2; /* Double pixel width only for hicolor */
  905. /* Default values are used for vert./hor. timing if no pixelclock given. */
  906. if (var->pixclock == 0) {
  907. int linesize;
  908. /* Choose master pixelclock depending on hor. timing */
  909. plen = 1 * xstretch;
  910. if ((plen * xres + f25.right+f25.hsync+f25.left) *
  911. fb_info.monspecs.hfmin < f25.f)
  912. pclock = &f25;
  913. else if ((plen * xres + f32.right+f32.hsync+f32.left) *
  914. fb_info.monspecs.hfmin < f32.f)
  915. pclock = &f32;
  916. else if ((plen * xres + fext.right+fext.hsync+fext.left) *
  917. fb_info.monspecs.hfmin < fext.f
  918. && fext.f)
  919. pclock = &fext;
  920. else
  921. return -EINVAL;
  922. left_margin = pclock->left / plen;
  923. right_margin = pclock->right / plen;
  924. hsync_len = pclock->hsync / plen;
  925. linesize = left_margin + xres + right_margin + hsync_len;
  926. upper_margin = 31;
  927. lower_margin = 11;
  928. vsync_len = 3;
  929. }
  930. else {
  931. /* Choose largest pixelclock <= wanted clock */
  932. int i;
  933. unsigned long pcl = ULONG_MAX;
  934. pclock = 0;
  935. for (i=1; i <= 4; i *= 2) {
  936. if (f25.t*i >= var->pixclock && f25.t*i < pcl) {
  937. pcl = f25.t * i;
  938. pclock = &f25;
  939. }
  940. if (f32.t*i >= var->pixclock && f32.t*i < pcl) {
  941. pcl = f32.t * i;
  942. pclock = &f32;
  943. }
  944. if (fext.t && fext.t*i >= var->pixclock && fext.t*i < pcl) {
  945. pcl = fext.t * i;
  946. pclock = &fext;
  947. }
  948. }
  949. if (!pclock)
  950. return -EINVAL;
  951. plen = pcl / pclock->t;
  952. left_margin = var->left_margin;
  953. right_margin = var->right_margin;
  954. hsync_len = var->hsync_len;
  955. upper_margin = var->upper_margin;
  956. lower_margin = var->lower_margin;
  957. vsync_len = var->vsync_len;
  958. /* Internal unit is [single lines per (half-)frame] */
  959. if (var->vmode & FB_VMODE_INTERLACED) {
  960. /* # lines in half frame */
  961. /* External unit is [lines per full frame] */
  962. upper_margin = (upper_margin + 1) / 2;
  963. lower_margin = (lower_margin + 1) / 2;
  964. vsync_len = (vsync_len + 1) / 2;
  965. }
  966. else if (var->vmode & FB_VMODE_DOUBLE) {
  967. /* External unit is [double lines per frame] */
  968. upper_margin *= 2;
  969. lower_margin *= 2;
  970. vsync_len *= 2;
  971. }
  972. }
  973. if (pclock == &fext)
  974. longoffset = 1; /* VIDEL doesn't synchronize on short offset */
  975. }
  976. /* Is video bus bandwidth (32MB/s) too low for this resolution? */
  977. /* this is definitely wrong if bus clock != 32MHz */
  978. if (pclock->f / plen / 8 * bpp > 32000000L)
  979. return -EINVAL;
  980. if (vsync_len < 1)
  981. vsync_len = 1;
  982. /* include sync lengths in right/lower margin for all calculations */
  983. right_margin += hsync_len;
  984. lower_margin += vsync_len;
  985. /* ! In all calculations of margins we use # of lines in half frame
  986. * (which is a full frame in non-interlace mode), so we can switch
  987. * between interlace and non-interlace without messing around
  988. * with these.
  989. */
  990. again:
  991. /* Set base_offset 128 and video bus width */
  992. par->hw.falcon.vid_control = mon_type | f030_bus_width;
  993. if (!longoffset)
  994. par->hw.falcon.vid_control |= VCO_SHORTOFFS; /* base_offset 64 */
  995. if (var->sync & FB_SYNC_HOR_HIGH_ACT)
  996. par->hw.falcon.vid_control |= VCO_HSYPOS;
  997. if (var->sync & FB_SYNC_VERT_HIGH_ACT)
  998. par->hw.falcon.vid_control |= VCO_VSYPOS;
  999. /* Pixelclock */
  1000. par->hw.falcon.vid_control |= pclock->control_mask;
  1001. /* External or internal clock */
  1002. par->hw.falcon.sync = pclock->sync_mask | 0x2;
  1003. /* Pixellength and prescale */
  1004. par->hw.falcon.vid_mode = (2/plen) << 2;
  1005. if (doubleline)
  1006. par->hw.falcon.vid_mode |= VMO_DOUBLE;
  1007. if (interlace)
  1008. par->hw.falcon.vid_mode |= VMO_INTER;
  1009. /*********************
  1010. Horizontal timing: unit = [master clock cycles]
  1011. unit of hxx-registers: [master clock cycles * prescale]
  1012. Hxx-registers are 9 bit wide
  1013. 1 line = ((hht + 2) * 2 * prescale) clock cycles
  1014. graphic output = hdb & 0x200 ?
  1015. ((hht+2)*2 - hdb + hde) * prescale - hdboff + hdeoff:
  1016. ( hht + 2 - hdb + hde) * prescale - hdboff + hdeoff
  1017. (this must be a multiple of plen*128/bpp, on VGA pixels
  1018. to the right may be cut off with a bigger right margin)
  1019. start of graphics relative to start of 1st halfline = hdb & 0x200 ?
  1020. (hdb - hht - 2) * prescale + hdboff :
  1021. hdb * prescale + hdboff
  1022. end of graphics relative to start of 1st halfline =
  1023. (hde + hht + 2) * prescale + hdeoff
  1024. *********************/
  1025. /* Calculate VIDEL registers */
  1026. {
  1027. int hdb_off, hde_off, base_off;
  1028. int gstart, gend1, gend2, align;
  1029. prescale = hxx_prescale(&par->hw.falcon);
  1030. base_off = par->hw.falcon.vid_control & VCO_SHORTOFFS ? 64 : 128;
  1031. /* Offsets depend on video mode */
  1032. /* Offsets are in clock cycles, divide by prescale to
  1033. * calculate hd[be]-registers
  1034. */
  1035. if (par->hw.falcon.f_shift & 0x100) {
  1036. align = 1;
  1037. hde_off = 0;
  1038. hdb_off = (base_off + 16 * plen) + prescale;
  1039. }
  1040. else {
  1041. align = 128 / bpp;
  1042. hde_off = ((128 / bpp + 2) * plen);
  1043. if (par->hw.falcon.ste_mode)
  1044. hdb_off = (64 + base_off + (128 / bpp + 2) * plen) + prescale;
  1045. else
  1046. hdb_off = (base_off + (128 / bpp + 18) * plen) + prescale;
  1047. }
  1048. gstart = (prescale/2 + plen * left_margin) / prescale;
  1049. /* gend1 is for hde (gend-gstart multiple of align), shifter's xres */
  1050. gend1 = gstart + ((xres + align-1) / align)*align * plen / prescale;
  1051. /* gend2 is for hbb, visible xres (rest to gend1 is cut off by hblank) */
  1052. gend2 = gstart + xres * plen / prescale;
  1053. par->HHT = plen * (left_margin + xres + right_margin) /
  1054. (2 * prescale) - 2;
  1055. /* par->HHT = (gend2 + plen * right_margin / prescale) / 2 - 2;*/
  1056. par->HDB = gstart - hdb_off/prescale;
  1057. par->HBE = gstart;
  1058. if (par->HDB < 0) par->HDB += par->HHT + 2 + 0x200;
  1059. par->HDE = gend1 - par->HHT - 2 - hde_off/prescale;
  1060. par->HBB = gend2 - par->HHT - 2;
  1061. #if 0
  1062. /* One more Videl constraint: data fetch of two lines must not overlap */
  1063. if ((par->HDB & 0x200) && (par->HDB & ~0x200) - par->HDE <= 5) {
  1064. /* if this happens increase margins, decrease hfreq. */
  1065. }
  1066. #endif
  1067. if (hde_off % prescale)
  1068. par->HBB++; /* compensate for non matching hde and hbb */
  1069. par->HSS = par->HHT + 2 - plen * hsync_len / prescale;
  1070. if (par->HSS < par->HBB)
  1071. par->HSS = par->HBB;
  1072. }
  1073. /* check hor. frequency */
  1074. hfreq = pclock->f / ((par->HHT+2)*prescale*2);
  1075. if (hfreq > fb_info.monspecs.hfmax && mon_type!=F_MON_VGA) {
  1076. /* ++guenther: ^^^^^^^^^^^^^^^^^^^ can't remember why I did this */
  1077. /* Too high -> enlarge margin */
  1078. left_margin += 1;
  1079. right_margin += 1;
  1080. goto again;
  1081. }
  1082. if (hfreq > fb_info.monspecs.hfmax || hfreq < fb_info.monspecs.hfmin)
  1083. return -EINVAL;
  1084. /* Vxx-registers */
  1085. /* All Vxx must be odd in non-interlace, since frame starts in the middle
  1086. * of the first displayed line!
  1087. * One frame consists of VFT+1 half lines. VFT+1 must be even in
  1088. * non-interlace, odd in interlace mode for synchronisation.
  1089. * Vxx-registers are 11 bit wide
  1090. */
  1091. par->VBE = (upper_margin * 2 + 1); /* must begin on odd halfline */
  1092. par->VDB = par->VBE;
  1093. par->VDE = yres;
  1094. if (!interlace) par->VDE <<= 1;
  1095. if (doubleline) par->VDE <<= 1; /* VDE now half lines per (half-)frame */
  1096. par->VDE += par->VDB;
  1097. par->VBB = par->VDE;
  1098. par->VFT = par->VBB + (lower_margin * 2 - 1) - 1;
  1099. par->VSS = par->VFT+1 - (vsync_len * 2 - 1);
  1100. /* vbb,vss,vft must be even in interlace mode */
  1101. if (interlace) {
  1102. par->VBB++;
  1103. par->VSS++;
  1104. par->VFT++;
  1105. }
  1106. /* V-frequency check, hope I didn't create any loop here. */
  1107. /* Interlace and doubleline are mutually exclusive. */
  1108. vfreq = (hfreq * 2) / (par->VFT + 1);
  1109. if (vfreq > fb_info.monspecs.vfmax && !doubleline && !interlace) {
  1110. /* Too high -> try again with doubleline */
  1111. doubleline = 1;
  1112. goto again;
  1113. }
  1114. else if (vfreq < fb_info.monspecs.vfmin && !interlace && !doubleline) {
  1115. /* Too low -> try again with interlace */
  1116. interlace = 1;
  1117. goto again;
  1118. }
  1119. else if (vfreq < fb_info.monspecs.vfmin && doubleline) {
  1120. /* Doubleline too low -> clear doubleline and enlarge margins */
  1121. int lines;
  1122. doubleline = 0;
  1123. for (lines=0;
  1124. (hfreq*2)/(par->VFT+1+4*lines-2*yres)>fb_info.monspecs.vfmax;
  1125. lines++)
  1126. ;
  1127. upper_margin += lines;
  1128. lower_margin += lines;
  1129. goto again;
  1130. }
  1131. else if (vfreq > fb_info.monspecs.vfmax && doubleline) {
  1132. /* Doubleline too high -> enlarge margins */
  1133. int lines;
  1134. for (lines=0;
  1135. (hfreq*2)/(par->VFT+1+4*lines)>fb_info.monspecs.vfmax;
  1136. lines+=2)
  1137. ;
  1138. upper_margin += lines;
  1139. lower_margin += lines;
  1140. goto again;
  1141. }
  1142. else if (vfreq > fb_info.monspecs.vfmax && interlace) {
  1143. /* Interlace, too high -> enlarge margins */
  1144. int lines;
  1145. for (lines=0;
  1146. (hfreq*2)/(par->VFT+1+4*lines)>fb_info.monspecs.vfmax;
  1147. lines++)
  1148. ;
  1149. upper_margin += lines;
  1150. lower_margin += lines;
  1151. goto again;
  1152. }
  1153. else if (vfreq < fb_info.monspecs.vfmin ||
  1154. vfreq > fb_info.monspecs.vfmax)
  1155. return -EINVAL;
  1156. set_screen_base:
  1157. linelen = xres_virtual * bpp / 8;
  1158. if (yres_virtual * linelen > screen_len && screen_len)
  1159. return -EINVAL;
  1160. if (yres * linelen > screen_len && screen_len)
  1161. return -EINVAL;
  1162. if (var->yoffset + yres > yres_virtual && yres_virtual)
  1163. return -EINVAL;
  1164. par->yres_virtual = yres_virtual;
  1165. par->screen_base = screen_base + var->yoffset * linelen;
  1166. par->hw.falcon.xoffset = 0;
  1167. return 0;
  1168. }
  1169. static int falcon_encode_var( struct fb_var_screeninfo *var,
  1170. struct atafb_par *par )
  1171. {
  1172. /* !!! only for VGA !!! */
  1173. int linelen;
  1174. int prescale, plen;
  1175. int hdb_off, hde_off, base_off;
  1176. struct falcon_hw *hw = &par->hw.falcon;
  1177. memset(var, 0, sizeof(struct fb_var_screeninfo));
  1178. /* possible frequencies: 25.175 or 32MHz */
  1179. var->pixclock = hw->sync & 0x1 ? fext.t :
  1180. hw->vid_control & VCO_CLOCK25 ? f25.t : f32.t;
  1181. var->height=-1;
  1182. var->width=-1;
  1183. var->sync=0;
  1184. if (hw->vid_control & VCO_HSYPOS)
  1185. var->sync |= FB_SYNC_HOR_HIGH_ACT;
  1186. if (hw->vid_control & VCO_VSYPOS)
  1187. var->sync |= FB_SYNC_VERT_HIGH_ACT;
  1188. var->vmode = FB_VMODE_NONINTERLACED;
  1189. if (hw->vid_mode & VMO_INTER)
  1190. var->vmode |= FB_VMODE_INTERLACED;
  1191. if (hw->vid_mode & VMO_DOUBLE)
  1192. var->vmode |= FB_VMODE_DOUBLE;
  1193. /* visible y resolution:
  1194. * Graphics display starts at line VDB and ends at line
  1195. * VDE. If interlace mode off unit of VC-registers is
  1196. * half lines, else lines.
  1197. */
  1198. var->yres = hw->vde - hw->vdb;
  1199. if (!(var->vmode & FB_VMODE_INTERLACED))
  1200. var->yres >>= 1;
  1201. if (var->vmode & FB_VMODE_DOUBLE)
  1202. var->yres >>= 1;
  1203. /* to get bpp, we must examine f_shift and st_shift.
  1204. * f_shift is valid if any of bits no. 10, 8 or 4
  1205. * is set. Priority in f_shift is: 10 ">" 8 ">" 4, i.e.
  1206. * if bit 10 set then bit 8 and bit 4 don't care...
  1207. * If all these bits are 0 get display depth from st_shift
  1208. * (as for ST and STE)
  1209. */
  1210. if (hw->f_shift & 0x400) /* 2 colors */
  1211. var->bits_per_pixel = 1;
  1212. else if (hw->f_shift & 0x100) /* hicolor */
  1213. var->bits_per_pixel = 16;
  1214. else if (hw->f_shift & 0x010) /* 8 bitplanes */
  1215. var->bits_per_pixel = 8;
  1216. else if (hw->st_shift == 0)
  1217. var->bits_per_pixel = 4;
  1218. else if (hw->st_shift == 0x100)
  1219. var->bits_per_pixel = 2;
  1220. else /* if (hw->st_shift == 0x200) */
  1221. var->bits_per_pixel = 1;
  1222. var->xres = hw->line_width * 16 / var->bits_per_pixel;
  1223. var->xres_virtual = var->xres + hw->line_offset * 16 / var->bits_per_pixel;
  1224. if (hw->xoffset)
  1225. var->xres_virtual += 16;
  1226. if (var->bits_per_pixel == 16) {
  1227. var->red.offset=11;
  1228. var->red.length=5;
  1229. var->red.msb_right=0;
  1230. var->green.offset=5;
  1231. var->green.length=6;
  1232. var->green.msb_right=0;
  1233. var->blue.offset=0;
  1234. var->blue.length=5;
  1235. var->blue.msb_right=0;
  1236. }
  1237. else {
  1238. var->red.offset=0;
  1239. var->red.length = hw->ste_mode ? 4 : 6;
  1240. var->red.msb_right=0;
  1241. var->grayscale=0;
  1242. var->blue=var->green=var->red;
  1243. }
  1244. var->transp.offset=0;
  1245. var->transp.length=0;
  1246. var->transp.msb_right=0;
  1247. linelen = var->xres_virtual * var->bits_per_pixel / 8;
  1248. if (screen_len) {
  1249. if (par->yres_virtual)
  1250. var->yres_virtual = par->yres_virtual;
  1251. else
  1252. /* yres_virtual==0 means use maximum */
  1253. var->yres_virtual = screen_len / linelen;
  1254. }
  1255. else {
  1256. if (hwscroll < 0)
  1257. var->yres_virtual = 2 * var->yres;
  1258. else
  1259. var->yres_virtual=var->yres+hwscroll * 16;
  1260. }
  1261. var->xoffset=0; /* TODO change this */
  1262. /* hdX-offsets */
  1263. prescale = hxx_prescale(hw);
  1264. plen = 4 >> (hw->vid_mode >> 2 & 0x3);
  1265. base_off = hw->vid_control & VCO_SHORTOFFS ? 64 : 128;
  1266. if (hw->f_shift & 0x100) {
  1267. hde_off = 0;
  1268. hdb_off = (base_off + 16 * plen) + prescale;
  1269. }
  1270. else {
  1271. hde_off = ((128 / var->bits_per_pixel + 2) * plen);
  1272. if (hw->ste_mode)
  1273. hdb_off = (64 + base_off + (128 / var->bits_per_pixel + 2) * plen)
  1274. + prescale;
  1275. else
  1276. hdb_off = (base_off + (128 / var->bits_per_pixel + 18) * plen)
  1277. + prescale;
  1278. }
  1279. /* Right margin includes hsync */
  1280. var->left_margin = hdb_off + prescale * ((hw->hdb & 0x1ff) -
  1281. (hw->hdb & 0x200 ? 2+hw->hht : 0));
  1282. if (hw->ste_mode || mon_type!=F_MON_VGA)
  1283. var->right_margin = prescale * (hw->hht + 2 - hw->hde) - hde_off;
  1284. else
  1285. /* can't use this in ste_mode, because hbb is +1 off */
  1286. var->right_margin = prescale * (hw->hht + 2 - hw->hbb);
  1287. var->hsync_len = prescale * (hw->hht + 2 - hw->hss);
  1288. /* Lower margin includes vsync */
  1289. var->upper_margin = hw->vdb / 2 ; /* round down to full lines */
  1290. var->lower_margin = (hw->vft+1 - hw->vde + 1) / 2; /* round up */
  1291. var->vsync_len = (hw->vft+1 - hw->vss + 1) / 2; /* round up */
  1292. if (var->vmode & FB_VMODE_INTERLACED) {
  1293. var->upper_margin *= 2;
  1294. var->lower_margin *= 2;
  1295. var->vsync_len *= 2;
  1296. }
  1297. else if (var->vmode & FB_VMODE_DOUBLE) {
  1298. var->upper_margin = (var->upper_margin + 1) / 2;
  1299. var->lower_margin = (var->lower_margin + 1) / 2;
  1300. var->vsync_len = (var->vsync_len + 1) / 2;
  1301. }
  1302. var->pixclock *= plen;
  1303. var->left_margin /= plen;
  1304. var->right_margin /= plen;
  1305. var->hsync_len /= plen;
  1306. var->right_margin -= var->hsync_len;
  1307. var->lower_margin -= var->vsync_len;
  1308. if (screen_base)
  1309. var->yoffset=(par->screen_base - screen_base)/linelen;
  1310. else
  1311. var->yoffset=0;
  1312. var->nonstd=0; /* what is this for? */
  1313. var->activate=0;
  1314. return 0;
  1315. }
  1316. static int f_change_mode = 0;
  1317. static struct falcon_hw f_new_mode;
  1318. static int f_pan_display = 0;
  1319. static void falcon_get_par( struct atafb_par *par )
  1320. {
  1321. unsigned long addr;
  1322. struct falcon_hw *hw = &par->hw.falcon;
  1323. hw->line_width = shifter_f030.scn_width;
  1324. hw->line_offset = shifter_f030.off_next;
  1325. hw->st_shift = videl.st_shift & 0x300;
  1326. hw->f_shift = videl.f_shift;
  1327. hw->vid_control = videl.control;
  1328. hw->vid_mode = videl.mode;
  1329. hw->sync = shifter.syncmode & 0x1;
  1330. hw->xoffset = videl.xoffset & 0xf;
  1331. hw->hht = videl.hht;
  1332. hw->hbb = videl.hbb;
  1333. hw->hbe = videl.hbe;
  1334. hw->hdb = videl.hdb;
  1335. hw->hde = videl.hde;
  1336. hw->hss = videl.hss;
  1337. hw->vft = videl.vft;
  1338. hw->vbb = videl.vbb;
  1339. hw->vbe = videl.vbe;
  1340. hw->vdb = videl.vdb;
  1341. hw->vde = videl.vde;
  1342. hw->vss = videl.vss;
  1343. addr = (shifter.bas_hi & 0xff) << 16 |
  1344. (shifter.bas_md & 0xff) << 8 |
  1345. (shifter.bas_lo & 0xff);
  1346. par->screen_base = phys_to_virt(addr);
  1347. /* derived parameters */
  1348. hw->ste_mode = (hw->f_shift & 0x510)==0 && hw->st_shift==0x100;
  1349. hw->mono = (hw->f_shift & 0x400) ||
  1350. ((hw->f_shift & 0x510)==0 && hw->st_shift==0x200);
  1351. }
  1352. static void falcon_set_par( struct atafb_par *par )
  1353. {
  1354. f_change_mode = 0;
  1355. /* only set screen_base if really necessary */
  1356. if (current_par.screen_base != par->screen_base)
  1357. fbhw->set_screen_base(par->screen_base);
  1358. /* Don't touch any other registers if we keep the default resolution */
  1359. if (DontCalcRes)
  1360. return;
  1361. /* Tell vbl-handler to change video mode.
  1362. * We change modes only on next VBL, to avoid desynchronisation
  1363. * (a shift to the right and wrap around by a random number of pixels
  1364. * in all monochrome modes).
  1365. * This seems to work on my Falcon.
  1366. */
  1367. f_new_mode = par->hw.falcon;
  1368. f_change_mode = 1;
  1369. }
  1370. static irqreturn_t falcon_vbl_switcher( int irq, void *dummy )
  1371. {
  1372. struct falcon_hw *hw = &f_new_mode;
  1373. if (f_change_mode) {
  1374. f_change_mode = 0;
  1375. if (hw->sync & 0x1) {
  1376. /* Enable external pixelclock. This code only for ScreenWonder */
  1377. *(volatile unsigned short*)0xffff9202 = 0xffbf;
  1378. }
  1379. else {
  1380. /* Turn off external clocks. Read sets all output bits to 1. */
  1381. *(volatile unsigned short*)0xffff9202;
  1382. }
  1383. shifter.syncmode = hw->sync;
  1384. videl.hht = hw->hht;
  1385. videl.hbb = hw->hbb;
  1386. videl.hbe = hw->hbe;
  1387. videl.hdb = hw->hdb;
  1388. videl.hde = hw->hde;
  1389. videl.hss = hw->hss;
  1390. videl.vft = hw->vft;
  1391. videl.vbb = hw->vbb;
  1392. videl.vbe = hw->vbe;
  1393. videl.vdb = hw->vdb;
  1394. videl.vde = hw->vde;
  1395. videl.vss = hw->vss;
  1396. videl.f_shift = 0; /* write enables Falcon palette, 0: 4 planes */
  1397. if (hw->ste_mode) {
  1398. videl.st_shift = hw->st_shift; /* write enables STE palette */
  1399. }
  1400. else {
  1401. /* IMPORTANT:
  1402. * set st_shift 0, so we can tell the screen-depth if f_shift==0.
  1403. * Writing 0 to f_shift enables 4 plane Falcon mode but
  1404. * doesn't set st_shift. st_shift!=0 (!=4planes) is impossible
  1405. * with Falcon palette.
  1406. */
  1407. videl.st_shift = 0;
  1408. /* now back to Falcon palette mode */
  1409. videl.f_shift = hw->f_shift;
  1410. }
  1411. /* writing to st_shift changed scn_width and vid_mode */
  1412. videl.xoffset = hw->xoffset;
  1413. shifter_f030.scn_width = hw->line_width;
  1414. shifter_f030.off_next = hw->line_offset;
  1415. videl.control = hw->vid_control;
  1416. videl.mode = hw->vid_mode;
  1417. }
  1418. if (f_pan_display) {
  1419. f_pan_display = 0;
  1420. videl.xoffset = current_par.hw.falcon.xoffset;
  1421. shifter_f030.off_next = current_par.hw.falcon.line_offset;
  1422. }
  1423. return IRQ_HANDLED;
  1424. }
  1425. static int falcon_pan_display( struct fb_var_screeninfo *var,
  1426. struct atafb_par *par )
  1427. {
  1428. int xoffset;
  1429. int bpp = fb_display[fb_info.currcon].var.bits_per_pixel;
  1430. if (bpp == 1)
  1431. var->xoffset = up(var->xoffset, 32);
  1432. if (bpp != 16)
  1433. par->hw.falcon.xoffset = var->xoffset & 15;
  1434. else {
  1435. par->hw.falcon.xoffset = 0;
  1436. var->xoffset = up(var->xoffset, 2);
  1437. }
  1438. par->hw.falcon.line_offset = bpp *
  1439. (fb_display[fb_info.currcon].var.xres_virtual - fb_display[fb_info.currcon].var.xres) / 16;
  1440. if (par->hw.falcon.xoffset)
  1441. par->hw.falcon.line_offset -= bpp;
  1442. xoffset = var->xoffset - par->hw.falcon.xoffset;
  1443. par->screen_base = screen_base +
  1444. (var->yoffset * fb_display[fb_info.currcon].var.xres_virtual + xoffset) * bpp / 8;
  1445. if (fbhw->set_screen_base)
  1446. fbhw->set_screen_base (par->screen_base);
  1447. else
  1448. return -EINVAL; /* shouldn't happen */
  1449. f_pan_display = 1;
  1450. return 0;
  1451. }
  1452. static int falcon_getcolreg( unsigned regno, unsigned *red,
  1453. unsigned *green, unsigned *blue,
  1454. unsigned *transp, struct fb_info *info )
  1455. { unsigned long col;
  1456. if (regno > 255)
  1457. return 1;
  1458. /* This works in STE-mode (with 4bit/color) since f030_col-registers
  1459. * hold up to 6bit/color.
  1460. * Even with hicolor r/g/b=5/6/5 bit!
  1461. */
  1462. col = f030_col[regno];
  1463. *red = (col >> 16) & 0xff00;
  1464. *green = (col >> 8) & 0xff00;
  1465. *blue = (col << 8) & 0xff00;
  1466. *transp = 0;
  1467. return 0;
  1468. }
  1469. static int falcon_setcolreg( unsigned regno, unsigned red,
  1470. unsigned green, unsigned blue,
  1471. unsigned transp, struct fb_info *info )
  1472. {
  1473. if (regno > 255)
  1474. return 1;
  1475. f030_col[regno] = (((red & 0xfc00) << 16) |
  1476. ((green & 0xfc00) << 8) |
  1477. ((blue & 0xfc00) >> 8));
  1478. if (regno < 16) {
  1479. shifter_tt.color_reg[regno] =
  1480. (((red & 0xe000) >> 13) | ((red & 0x1000) >> 12) << 8) |
  1481. (((green & 0xe000) >> 13) | ((green & 0x1000) >> 12) << 4) |
  1482. ((blue & 0xe000) >> 13) | ((blue & 0x1000) >> 12);
  1483. #ifdef FBCON_HAS_CFB16
  1484. fbcon_cfb16_cmap[regno] = ((red & 0xf800) |
  1485. ((green & 0xfc00) >> 5) |
  1486. ((blue & 0xf800) >> 11));
  1487. #endif
  1488. }
  1489. return 0;
  1490. }
  1491. static int falcon_blank( int blank_mode )
  1492. {
  1493. /* ++guenther: we can switch off graphics by changing VDB and VDE,
  1494. * so VIDEL doesn't hog the bus while saving.
  1495. * (this may affect usleep()).
  1496. */
  1497. int vdb, vss, hbe, hss;
  1498. if (mon_type == F_MON_SM) /* this doesn't work on SM124 */
  1499. return 1;
  1500. vdb = current_par.VDB;
  1501. vss = current_par.VSS;
  1502. hbe = current_par.HBE;
  1503. hss = current_par.HSS;
  1504. if (blank_mode >= 1) {
  1505. /* disable graphics output (this speeds up the CPU) ... */
  1506. vdb = current_par.VFT + 1;
  1507. /* ... and blank all lines */
  1508. hbe = current_par.HHT + 2;
  1509. }
  1510. /* use VESA suspend modes on VGA monitors */
  1511. if (mon_type == F_MON_VGA) {
  1512. if (blank_mode == 2 || blank_mode == 4)
  1513. vss = current_par.VFT + 1;
  1514. if (blank_mode == 3 || blank_mode == 4)
  1515. hss = current_par.HHT + 2;
  1516. }
  1517. videl.vdb = vdb;
  1518. videl.vss = vss;
  1519. videl.hbe = hbe;
  1520. videl.hss = hss;
  1521. return 0;
  1522. }
  1523. static int falcon_detect( void )
  1524. {
  1525. struct atafb_par par;
  1526. unsigned char fhw;
  1527. /* Determine connected monitor and set monitor parameters */
  1528. fhw = *(unsigned char*)0xffff8006;
  1529. mon_type = fhw >> 6 & 0x3;
  1530. /* bit 1 of fhw: 1=32 bit ram bus, 0=16 bit */
  1531. f030_bus_width = fhw << 6 & 0x80;
  1532. switch (mon_type) {
  1533. case F_MON_SM:
  1534. fb_info.monspecs.vfmin = 70;
  1535. fb_info.monspecs.vfmax = 72;
  1536. fb_info.monspecs.hfmin = 35713;
  1537. fb_info.monspecs.hfmax = 35715;
  1538. break;
  1539. case F_MON_SC:
  1540. case F_MON_TV:
  1541. /* PAL...NTSC */
  1542. fb_info.monspecs.vfmin = 49; /* not 50, since TOS defaults to 49.9x Hz */
  1543. fb_info.monspecs.vfmax = 60;
  1544. fb_info.monspecs.hfmin = 15620;
  1545. fb_info.monspecs.hfmax = 15755;
  1546. break;
  1547. }
  1548. /* initialize hsync-len */
  1549. f25.hsync = h_syncs[mon_type] / f25.t;
  1550. f32.hsync = h_syncs[mon_type] / f32.t;
  1551. if (fext.t)
  1552. fext.hsync = h_syncs[mon_type] / fext.t;
  1553. falcon_get_par(&par);
  1554. falcon_encode_var(&atafb_predefined[0], &par);
  1555. /* Detected mode is always the "autodetect" slot */
  1556. return 1;
  1557. }
  1558. #endif /* ATAFB_FALCON */
  1559. /* ------------------- ST(E) specific functions ---------------------- */
  1560. #ifdef ATAFB_STE
  1561. static int stste_encode_fix( struct fb_fix_screeninfo *fix,
  1562. struct atafb_par *par )
  1563. {
  1564. int mode;
  1565. strcpy(fix->id,"Atari Builtin");
  1566. fix->smem_start = (unsigned long)real_screen_base;
  1567. fix->smem_len = screen_len;
  1568. fix->type = FB_TYPE_INTERLEAVED_PLANES;
  1569. fix->type_aux = 2;
  1570. fix->visual = FB_VISUAL_PSEUDOCOLOR;
  1571. mode = par->hw.st.mode & 3;
  1572. if (mode == ST_HIGH) {
  1573. fix->type = FB_TYPE_PACKED_PIXELS;
  1574. fix->type_aux = 0;
  1575. fix->visual = FB_VISUAL_MONO10;
  1576. }
  1577. if (ATARIHW_PRESENT(EXTD_SHIFTER)) {
  1578. fix->xpanstep = 16;
  1579. fix->ypanstep = 1;
  1580. } else {
  1581. fix->xpanstep = 0;
  1582. fix->ypanstep = 0;
  1583. }
  1584. fix->ywrapstep = 0;
  1585. fix->line_length = 0;
  1586. fix->accel = FB_ACCEL_ATARIBLITT;
  1587. return 0;
  1588. }
  1589. static int stste_decode_var( struct fb_var_screeninfo *var,
  1590. struct atafb_par *par )
  1591. {
  1592. int xres=var->xres;
  1593. int yres=var->yres;
  1594. int bpp=var->bits_per_pixel;
  1595. int linelen;
  1596. int yres_virtual = var->yres_virtual;
  1597. if (mono_moni) {
  1598. if (bpp > 1 || xres > sttt_xres || yres > st_yres)
  1599. return -EINVAL;
  1600. par->hw.st.mode=ST_HIGH;
  1601. xres=sttt_xres;
  1602. yres=st_yres;
  1603. bpp=1;
  1604. } else {
  1605. if (bpp > 4 || xres > sttt_xres || yres > st_yres)
  1606. return -EINVAL;
  1607. if (bpp > 2) {
  1608. if (xres > sttt_xres/2 || yres > st_yres/2)
  1609. return -EINVAL;
  1610. par->hw.st.mode=ST_LOW;
  1611. xres=sttt_xres/2;
  1612. yres=st_yres/2;
  1613. bpp=4;
  1614. }
  1615. else if (bpp > 1) {
  1616. if (xres > sttt_xres || yres > st_yres/2)
  1617. return -EINVAL;
  1618. par->hw.st.mode=ST_MID;
  1619. xres=sttt_xres;
  1620. yres=st_yres/2;
  1621. bpp=2;
  1622. }
  1623. else
  1624. return -EINVAL;
  1625. }
  1626. if (yres_virtual <= 0)
  1627. yres_virtual = 0;
  1628. else if (yres_virtual < yres)
  1629. yres_virtual = yres;
  1630. if (var->sync & FB_SYNC_EXT)
  1631. par->hw.st.sync=(par->hw.st.sync & ~1) | 1;
  1632. else
  1633. par->hw.st.sync=(par->hw.st.sync & ~1);
  1634. linelen=xres*bpp/8;
  1635. if (yres_virtual * linelen > screen_len && screen_len)
  1636. return -EINVAL;
  1637. if (yres * linelen > screen_len && screen_len)
  1638. return -EINVAL;
  1639. if (var->yoffset + yres > yres_virtual && yres_virtual)
  1640. return -EINVAL;
  1641. par->yres_virtual = yres_virtual;
  1642. par->screen_base=screen_base+ var->yoffset*linelen;
  1643. return 0;
  1644. }
  1645. static int stste_encode_var( struct fb_var_screeninfo *var,
  1646. struct atafb_par *par )
  1647. {
  1648. int linelen;
  1649. memset(var, 0, sizeof(struct fb_var_screeninfo));
  1650. var->red.offset=0;
  1651. var->red.length = ATARIHW_PRESENT(EXTD_SHIFTER) ? 4 : 3;
  1652. var->red.msb_right=0;
  1653. var->grayscale=0;
  1654. var->pixclock=31041;
  1655. var->left_margin=120; /* these are incorrect */
  1656. var->right_margin=100;
  1657. var->upper_margin=8;
  1658. var->lower_margin=16;
  1659. var->hsync_len=140;
  1660. var->vsync_len=30;
  1661. var->height=-1;
  1662. var->width=-1;
  1663. if (!(par->hw.st.sync & 1))
  1664. var->sync=0;
  1665. else
  1666. var->sync=FB_SYNC_EXT;
  1667. switch (par->hw.st.mode & 3) {
  1668. case ST_LOW:
  1669. var->xres=sttt_xres/2;
  1670. var->yres=st_yres/2;
  1671. var->bits_per_pixel=4;
  1672. break;
  1673. case ST_MID:
  1674. var->xres=sttt_xres;
  1675. var->yres=st_yres/2;
  1676. var->bits_per_pixel=2;
  1677. break;
  1678. case ST_HIGH:
  1679. var->xres=sttt_xres;
  1680. var->yres=st_yres;
  1681. var->bits_per_pixel=1;
  1682. break;
  1683. }
  1684. var->blue=var->green=var->red;
  1685. var->transp.offset=0;
  1686. var->transp.length=0;
  1687. var->transp.msb_right=0;
  1688. var->xres_virtual=sttt_xres_virtual;
  1689. linelen=var->xres_virtual * var->bits_per_pixel / 8;
  1690. ovsc_addlen=linelen*(sttt_yres_virtual - st_yres);
  1691. if (! use_hwscroll)
  1692. var->yres_virtual=var->yres;
  1693. else if (screen_len) {
  1694. if (par->yres_virtual)
  1695. var->yres_virtual = par->yres_virtual;
  1696. else
  1697. /* yres_virtual==0 means use maximum */
  1698. var->yres_virtual = screen_len / linelen;
  1699. }
  1700. else {
  1701. if (hwscroll < 0)
  1702. var->yres_virtual = 2 * var->yres;
  1703. else
  1704. var->yres_virtual=var->yres+hwscroll * 16;
  1705. }
  1706. var->xoffset=0;
  1707. if (screen_base)
  1708. var->yoffset=(par->screen_base - screen_base)/linelen;
  1709. else
  1710. var->yoffset=0;
  1711. var->nonstd=0;
  1712. var->activate=0;
  1713. var->vmode=FB_VMODE_NONINTERLACED;
  1714. return 0;
  1715. }
  1716. static void stste_get_par( struct atafb_par *par )
  1717. {
  1718. unsigned long addr;
  1719. par->hw.st.mode=shifter_tt.st_shiftmode;
  1720. par->hw.st.sync=shifter.syncmode;
  1721. addr = ((shifter.bas_hi & 0xff) << 16) |
  1722. ((shifter.bas_md & 0xff) << 8);
  1723. if (ATARIHW_PRESENT(EXTD_SHIFTER))
  1724. addr |= (shifter.bas_lo & 0xff);
  1725. par->screen_base = phys_to_virt(addr);
  1726. }
  1727. static void stste_set_par( struct atafb_par *par )
  1728. {
  1729. shifter_tt.st_shiftmode=par->hw.st.mode;
  1730. shifter.syncmode=par->hw.st.sync;
  1731. /* only set screen_base if really necessary */
  1732. if (current_par.screen_base != par->screen_base)
  1733. fbhw->set_screen_base(par->screen_base);
  1734. }
  1735. static int stste_getcolreg(unsigned regno, unsigned *red,
  1736. unsigned *green, unsigned *blue,
  1737. unsigned *transp, struct fb_info *info)
  1738. {
  1739. unsigned col, t;
  1740. if (regno > 15)
  1741. return 1;
  1742. col = shifter_tt.color_reg[regno];
  1743. if (ATARIHW_PRESENT(EXTD_SHIFTER)) {
  1744. t = ((col >> 7) & 0xe) | ((col >> 11) & 1);
  1745. t |= t << 4;
  1746. *red = t | (t << 8);
  1747. t = ((col >> 3) & 0xe) | ((col >> 7) & 1);
  1748. t |= t << 4;
  1749. *green = t | (t << 8);
  1750. t = ((col << 1) & 0xe) | ((col >> 3) & 1);
  1751. t |= t << 4;
  1752. *blue = t | (t << 8);
  1753. }
  1754. else {
  1755. t = (col >> 7) & 0xe;
  1756. t |= t << 4;
  1757. *red = t | (t << 8);
  1758. t = (col >> 3) & 0xe;
  1759. t |= t << 4;
  1760. *green = t | (t << 8);
  1761. t = (col << 1) & 0xe;
  1762. t |= t << 4;
  1763. *blue = t | (t << 8);
  1764. }
  1765. *transp = 0;
  1766. return 0;
  1767. }
  1768. static int stste_setcolreg(unsigned regno, unsigned red,
  1769. unsigned green, unsigned blue,
  1770. unsigned transp, struct fb_info *info)
  1771. {
  1772. if (regno > 15)
  1773. return 1;
  1774. red >>= 12;
  1775. blue >>= 12;
  1776. green >>= 12;
  1777. if (ATARIHW_PRESENT(EXTD_SHIFTER))
  1778. shifter_tt.color_reg[regno] =
  1779. (((red & 0xe) >> 1) | ((red & 1) << 3) << 8) |
  1780. (((green & 0xe) >> 1) | ((green & 1) << 3) << 4) |
  1781. ((blue & 0xe) >> 1) | ((blue & 1) << 3);
  1782. else
  1783. shifter_tt.color_reg[regno] =
  1784. ((red & 0xe) << 7) |
  1785. ((green & 0xe) << 3) |
  1786. ((blue & 0xe) >> 1);
  1787. return 0;
  1788. }
  1789. static int stste_detect( void )
  1790. { struct atafb_par par;
  1791. /* Determine the connected monitor: The DMA sound must be
  1792. * disabled before reading the MFP GPIP, because the Sound
  1793. * Done Signal and the Monochrome Detect are XORed together!
  1794. */
  1795. if (ATARIHW_PRESENT(PCM_8BIT)) {
  1796. tt_dmasnd.ctrl = DMASND_CTRL_OFF;
  1797. udelay(20); /* wait a while for things to settle down */
  1798. }
  1799. mono_moni = (mfp.par_dt_reg & 0x80) == 0;
  1800. stste_get_par(&par);
  1801. stste_encode_var(&atafb_predefined[0], &par);
  1802. if (!ATARIHW_PRESENT(EXTD_SHIFTER))
  1803. use_hwscroll = 0;
  1804. return 1;
  1805. }
  1806. static void stste_set_screen_base(void *s_base)
  1807. {
  1808. unsigned long addr;
  1809. addr= virt_to_phys(s_base);
  1810. /* Setup Screen Memory */
  1811. shifter.bas_hi=(unsigned char) ((addr & 0xff0000) >> 16);
  1812. shifter.bas_md=(unsigned char) ((addr & 0x00ff00) >> 8);
  1813. if (ATARIHW_PRESENT(EXTD_SHIFTER))
  1814. shifter.bas_lo=(unsigned char) (addr & 0x0000ff);
  1815. }
  1816. #endif /* ATAFB_STE */
  1817. /* Switching the screen size should be done during vsync, otherwise
  1818. * the margins may get messed up. This is a well known problem of
  1819. * the ST's video system.
  1820. *
  1821. * Unfortunately there is hardly any way to find the vsync, as the
  1822. * vertical blank interrupt is no longer in time on machines with
  1823. * overscan type modifications.
  1824. *
  1825. * We can, however, use Timer B to safely detect the black shoulder,
  1826. * but then we've got to guess an appropriate delay to find the vsync.
  1827. * This might not work on every machine.
  1828. *
  1829. * martin_rogge @ ki.maus.de, 8th Aug 1995
  1830. */
  1831. #define LINE_DELAY (mono_moni ? 30 : 70)
  1832. #define SYNC_DELAY (mono_moni ? 1500 : 2000)
  1833. /* SWITCH_ACIA may be used for Falcon (ScreenBlaster III internal!) */
  1834. static void st_ovsc_switch(void)
  1835. {
  1836. unsigned long flags;
  1837. register unsigned char old, new;
  1838. if (!(atari_switches & ATARI_SWITCH_OVSC_MASK))
  1839. return;
  1840. local_irq_save(flags);
  1841. mfp.tim_ct_b = 0x10;
  1842. mfp.active_edge |= 8;
  1843. mfp.tim_ct_b = 0;
  1844. mfp.tim_dt_b = 0xf0;
  1845. mfp.tim_ct_b = 8;
  1846. while (mfp.tim_dt_b > 1) /* TOS does it this way, don't ask why */
  1847. ;
  1848. new = mfp.tim_dt_b;
  1849. do {
  1850. udelay(LINE_DELAY);
  1851. old = new;
  1852. new = mfp.tim_dt_b;
  1853. } while (old != new);
  1854. mfp.tim_ct_b = 0x10;
  1855. udelay(SYNC_DELAY);
  1856. if (atari_switches & ATARI_SWITCH_OVSC_IKBD)
  1857. acia.key_ctrl = ACIA_DIV64 | ACIA_D8N1S | ACIA_RHTID | ACIA_RIE;
  1858. if (atari_switches & ATARI_SWITCH_OVSC_MIDI)
  1859. acia.mid_ctrl = ACIA_DIV16 | ACIA_D8N1S | ACIA_RHTID;
  1860. if (atari_switches & (ATARI_SWITCH_OVSC_SND6|ATARI_SWITCH_OVSC_SND7)) {
  1861. sound_ym.rd_data_reg_sel = 14;
  1862. sound_ym.wd_data = sound_ym.rd_data_reg_sel |
  1863. ((atari_switches&ATARI_SWITCH_OVSC_SND6) ? 0x40:0) |
  1864. ((atari_switches&ATARI_SWITCH_OVSC_SND7) ? 0x80:0);
  1865. }
  1866. local_irq_restore(flags);
  1867. }
  1868. /* ------------------- External Video ---------------------- */
  1869. #ifdef ATAFB_EXT
  1870. static int ext_encode_fix( struct fb_fix_screeninfo *fix,
  1871. struct atafb_par *par )
  1872. {
  1873. strcpy(fix->id,"Unknown Extern");
  1874. fix->smem_start = (unsigned long)external_addr;
  1875. fix->smem_len = PAGE_ALIGN(external_len);
  1876. if (external_depth == 1) {
  1877. fix->type = FB_TYPE_PACKED_PIXELS;
  1878. /* The letters 'n' and 'i' in the "atavideo=external:" stand
  1879. * for "normal" and "inverted", rsp., in the monochrome case */
  1880. fix->visual =
  1881. (external_pmode == FB_TYPE_INTERLEAVED_PLANES ||
  1882. external_pmode == FB_TYPE_PACKED_PIXELS) ?
  1883. FB_VISUAL_MONO10 :
  1884. FB_VISUAL_MONO01;
  1885. }
  1886. else {
  1887. /* Use STATIC if we don't know how to access color registers */
  1888. int visual = external_vgaiobase ?
  1889. FB_VISUAL_PSEUDOCOLOR :
  1890. FB_VISUAL_STATIC_PSEUDOCOLOR;
  1891. switch (external_pmode) {
  1892. case -1: /* truecolor */
  1893. fix->type=FB_TYPE_PACKED_PIXELS;
  1894. fix->visual=FB_VISUAL_TRUECOLOR;
  1895. break;
  1896. case FB_TYPE_PACKED_PIXELS:
  1897. fix->type=FB_TYPE_PACKED_PIXELS;
  1898. fix->visual=visual;
  1899. break;
  1900. case FB_TYPE_PLANES:
  1901. fix->type=FB_TYPE_PLANES;
  1902. fix->visual=visual;
  1903. break;
  1904. case FB_TYPE_INTERLEAVED_PLANES:
  1905. fix->type=FB_TYPE_INTERLEAVED_PLANES;
  1906. fix->type_aux=2;
  1907. fix->visual=visual;
  1908. break;
  1909. }
  1910. }
  1911. fix->xpanstep = 0;
  1912. fix->ypanstep = 0;
  1913. fix->ywrapstep = 0;
  1914. fix->line_length = 0;
  1915. return 0;
  1916. }
  1917. static int ext_decode_var( struct fb_var_screeninfo *var,
  1918. struct atafb_par *par )
  1919. {
  1920. struct fb_var_screeninfo *myvar = &atafb_predefined[0];
  1921. if (var->bits_per_pixel > myvar->bits_per_pixel ||
  1922. var->xres > myvar->xres ||
  1923. var->xres_virtual > myvar->xres_virtual ||
  1924. var->yres > myvar->yres ||
  1925. var->xoffset > 0 ||
  1926. var->yoffset > 0)
  1927. return -EINVAL;
  1928. return 0;
  1929. }
  1930. static int ext_encode_var( struct fb_var_screeninfo *var,
  1931. struct atafb_par *par )
  1932. {
  1933. memset(var, 0, sizeof(struct fb_var_screeninfo));
  1934. var->red.offset=0;
  1935. var->red.length=(external_pmode == -1) ? external_depth/3 :
  1936. (external_vgaiobase ? external_bitspercol : 0);
  1937. var->red.msb_right=0;
  1938. var->grayscale=0;
  1939. var->pixclock=31041;
  1940. var->left_margin=120; /* these are surely incorrect */
  1941. var->right_margin=100;
  1942. var->upper_margin=8;
  1943. var->lower_margin=16;
  1944. var->hsync_len=140;
  1945. var->vsync_len=30;
  1946. var->height=-1;
  1947. var->width=-1;
  1948. var->sync=0;
  1949. var->xres = external_xres;
  1950. var->yres = external_yres;
  1951. var->xres_virtual = external_xres_virtual;
  1952. var->bits_per_pixel = external_depth;
  1953. var->blue=var->green=var->red;
  1954. var->transp.offset=0;
  1955. var->transp.length=0;
  1956. var->transp.msb_right=0;
  1957. var->yres_virtual=var->yres;
  1958. var->xoffset=0;
  1959. var->yoffset=0;
  1960. var->nonstd=0;
  1961. var->activate=0;
  1962. var->vmode=FB_VMODE_NONINTERLACED;
  1963. return 0;
  1964. }
  1965. static void ext_get_par( struct atafb_par *par )
  1966. {
  1967. par->screen_base = external_addr;
  1968. }
  1969. static void ext_set_par( struct atafb_par *par )
  1970. {
  1971. }
  1972. #define OUTB(port,val) \
  1973. *((unsigned volatile char *) ((port)+external_vgaiobase))=(val)
  1974. #define INB(port) \
  1975. (*((unsigned volatile char *) ((port)+external_vgaiobase)))
  1976. #define DACDelay \
  1977. do { \
  1978. unsigned char tmp=INB(0x3da); \
  1979. tmp=INB(0x3da); \
  1980. } while (0)
  1981. static int ext_getcolreg( unsigned regno, unsigned *red,
  1982. unsigned *green, unsigned *blue,
  1983. unsigned *transp, struct fb_info *info )
  1984. {
  1985. if (! external_vgaiobase)
  1986. return 1;
  1987. *red = ext_color[regno].red;
  1988. *green = ext_color[regno].green;
  1989. *blue = ext_color[regno].blue;
  1990. *transp=0;
  1991. return 0;
  1992. }
  1993. static int ext_setcolreg( unsigned regno, unsigned red,
  1994. unsigned green, unsigned blue,
  1995. unsigned transp, struct fb_info *info )
  1996. { unsigned char colmask = (1 << external_bitspercol) - 1;
  1997. if (! external_vgaiobase)
  1998. return 1;
  1999. ext_color[regno].red = red;
  2000. ext_color[regno].green = green;
  2001. ext_color[regno].blue = blue;
  2002. switch (external_card_type) {
  2003. case IS_VGA:
  2004. OUTB(0x3c8, regno);
  2005. DACDelay;
  2006. OUTB(0x3c9, red & colmask);
  2007. DACDelay;
  2008. OUTB(0x3c9, green & colmask);
  2009. DACDelay;
  2010. OUTB(0x3c9, blue & colmask);
  2011. DACDelay;
  2012. return 0;
  2013. case IS_MV300:
  2014. OUTB((MV300_reg[regno] << 2)+1, red);
  2015. OUTB((MV300_reg[regno] << 2)+1, green);
  2016. OUTB((MV300_reg[regno] << 2)+1, blue);
  2017. return 0;
  2018. default:
  2019. return 1;
  2020. }
  2021. }
  2022. static int ext_detect( void )
  2023. {
  2024. struct fb_var_screeninfo *myvar = &atafb_predefined[0];
  2025. struct atafb_par dummy_par;
  2026. myvar->xres = external_xres;
  2027. myvar->xres_virtual = external_xres_virtual;
  2028. myvar->yres = external_yres;
  2029. myvar->bits_per_pixel = external_depth;
  2030. ext_encode_var(myvar, &dummy_par);
  2031. return 1;
  2032. }
  2033. #endif /* ATAFB_EXT */
  2034. /* ------ This is the same for most hardware types -------- */
  2035. static void set_screen_base(void *s_base)
  2036. {
  2037. unsigned long addr;
  2038. addr= virt_to_phys(s_base);
  2039. /* Setup Screen Memory */
  2040. shifter.bas_hi=(unsigned char) ((addr & 0xff0000) >> 16);
  2041. shifter.bas_md=(unsigned char) ((addr & 0x00ff00) >> 8);
  2042. shifter.bas_lo=(unsigned char) (addr & 0x0000ff);
  2043. }
  2044. static int pan_display( struct fb_var_screeninfo *var,
  2045. struct atafb_par *par )
  2046. {
  2047. if (!fbhw->set_screen_base ||
  2048. (!ATARIHW_PRESENT(EXTD_SHIFTER) && var->xoffset))
  2049. return -EINVAL;
  2050. var->xoffset = up(var->xoffset, 16);
  2051. par->screen_base = screen_base +
  2052. (var->yoffset * fb_display[fb_info.currcon].var.xres_virtual + var->xoffset)
  2053. * fb_display[fb_info.currcon].var.bits_per_pixel / 8;
  2054. fbhw->set_screen_base (par->screen_base);
  2055. return 0;
  2056. }
  2057. /* ------------ Interfaces to hardware functions ------------ */
  2058. #ifdef ATAFB_TT
  2059. static struct fb_hwswitch tt_switch = {
  2060. tt_detect, tt_encode_fix, tt_decode_var, tt_encode_var,
  2061. tt_get_par, tt_set_par, tt_getcolreg,
  2062. set_screen_base, NULL, pan_display
  2063. };
  2064. #endif
  2065. #ifdef ATAFB_FALCON
  2066. static struct fb_hwswitch falcon_switch = {
  2067. falcon_detect, falcon_encode_fix, falcon_decode_var, falcon_encode_var,
  2068. falcon_get_par, falcon_set_par, falcon_getcolreg,
  2069. set_screen_base, falcon_blank, falcon_pan_display
  2070. };
  2071. #endif
  2072. #ifdef ATAFB_STE
  2073. static struct fb_hwswitch st_switch = {
  2074. stste_detect, stste_encode_fix, stste_decode_var, stste_encode_var,
  2075. stste_get_par, stste_set_par, stste_getcolreg,
  2076. stste_set_screen_base, NULL, pan_display
  2077. };
  2078. #endif
  2079. #ifdef ATAFB_EXT
  2080. static struct fb_hwswitch ext_switch = {
  2081. ext_detect, ext_encode_fix, ext_decode_var, ext_encode_var,
  2082. ext_get_par, ext_set_par, ext_getcolreg, NULL, NULL, NULL
  2083. };
  2084. #endif
  2085. static void atafb_get_par( struct atafb_par *par )
  2086. {
  2087. if (current_par_valid) {
  2088. *par=current_par;
  2089. }
  2090. else
  2091. fbhw->get_par(par);
  2092. }
  2093. static void atafb_set_par( struct atafb_par *par )
  2094. {
  2095. fbhw->set_par(par);
  2096. current_par=*par;
  2097. current_par_valid=1;
  2098. }
  2099. /* =========================================================== */
  2100. /* ============== Hardware Independent Functions ============= */
  2101. /* =========================================================== */
  2102. /* used for hardware scrolling */
  2103. static int
  2104. fb_update_var(int con, struct fb_info *info)
  2105. {
  2106. int off=fb_display[con].var.yoffset*fb_display[con].var.xres_virtual*
  2107. fb_display[con].var.bits_per_pixel>>3;
  2108. current_par.screen_base=screen_base + off;
  2109. if (fbhw->set_screen_base)
  2110. fbhw->set_screen_base(current_par.screen_base);
  2111. return 0;
  2112. }
  2113. static int
  2114. do_fb_set_var(struct fb_var_screeninfo *var, int isactive)
  2115. {
  2116. int err,activate;
  2117. struct atafb_par par;
  2118. if ((err=fbhw->decode_var(var, &par)))
  2119. return err;
  2120. activate=var->activate;
  2121. if (((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) && isactive)
  2122. atafb_set_par(&par);
  2123. fbhw->encode_var(var, &par);
  2124. var->activate=activate;
  2125. return 0;
  2126. }
  2127. static int
  2128. atafb_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *info)
  2129. {
  2130. struct atafb_par par;
  2131. if (con == -1)
  2132. atafb_get_par(&par);
  2133. else {
  2134. int err;
  2135. if ((err=fbhw->decode_var(&fb_display[con].var,&par)))
  2136. return err;
  2137. }
  2138. memset(fix, 0, sizeof(struct fb_fix_screeninfo));
  2139. return fbhw->encode_fix(fix, &par);
  2140. }
  2141. static int
  2142. atafb_get_var(struct fb_var_screeninfo *var, int con, struct fb_info *info)
  2143. {
  2144. struct atafb_par par;
  2145. if (con == -1) {
  2146. atafb_get_par(&par);
  2147. fbhw->encode_var(var, &par);
  2148. }
  2149. else
  2150. *var=fb_display[con].var;
  2151. return 0;
  2152. }
  2153. static void
  2154. atafb_set_disp(int con, struct fb_info *info)
  2155. {
  2156. struct fb_fix_screeninfo fix;
  2157. struct fb_var_screeninfo var;
  2158. struct display *display;
  2159. if (con >= 0)
  2160. display = &fb_display[con];
  2161. else
  2162. display = &disp; /* used during initialization */
  2163. atafb_get_fix(&fix, con, info);
  2164. atafb_get_var(&var, con, info);
  2165. if (con == -1)
  2166. con=0;
  2167. info->screen_base = (void *)fix.smem_start;
  2168. display->visual = fix.visual;
  2169. display->type = fix.type;
  2170. display->type_aux = fix.type_aux;
  2171. display->ypanstep = fix.ypanstep;
  2172. display->ywrapstep = fix.ywrapstep;
  2173. display->line_length = fix.line_length;
  2174. if (fix.visual != FB_VISUAL_PSEUDOCOLOR &&
  2175. fix.visual != FB_VISUAL_DIRECTCOLOR)
  2176. display->can_soft_blank = 0;
  2177. else
  2178. display->can_soft_blank = 1;
  2179. display->inverse =
  2180. (fix.visual == FB_VISUAL_MONO01 ? !inverse : inverse);
  2181. switch (fix.type) {
  2182. case FB_TYPE_INTERLEAVED_PLANES:
  2183. switch (var.bits_per_pixel) {
  2184. #ifdef FBCON_HAS_IPLAN2P2
  2185. case 2:
  2186. display->dispsw = &fbcon_iplan2p2;
  2187. break;
  2188. #endif
  2189. #ifdef FBCON_HAS_IPLAN2P4
  2190. case 4:
  2191. display->dispsw = &fbcon_iplan2p4;
  2192. break;
  2193. #endif
  2194. #ifdef FBCON_HAS_IPLAN2P8
  2195. case 8:
  2196. display->dispsw = &fbcon_iplan2p8;
  2197. break;
  2198. #endif
  2199. }
  2200. break;
  2201. case FB_TYPE_PACKED_PIXELS:
  2202. switch (var.bits_per_pixel) {
  2203. #ifdef FBCON_HAS_MFB
  2204. case 1:
  2205. display->dispsw = &fbcon_mfb;
  2206. break;
  2207. #endif
  2208. #ifdef FBCON_HAS_CFB8
  2209. case 8:
  2210. display->dispsw = &fbcon_cfb8;
  2211. break;
  2212. #endif
  2213. #ifdef FBCON_HAS_CFB16
  2214. case 16:
  2215. display->dispsw = &fbcon_cfb16;
  2216. display->dispsw_data = fbcon_cfb16_cmap;
  2217. break;
  2218. #endif
  2219. }
  2220. break;
  2221. }
  2222. }
  2223. static int
  2224. atafb_set_var(struct fb_var_screeninfo *var, int con, struct fb_info *info)
  2225. {
  2226. int err,oldxres,oldyres,oldbpp,oldxres_virtual,
  2227. oldyres_virtual,oldyoffset;
  2228. if ((err=do_fb_set_var(var, con==info->currcon)))
  2229. return err;
  2230. if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
  2231. oldxres=fb_display[con].var.xres;
  2232. oldyres=fb_display[con].var.yres;
  2233. oldxres_virtual=fb_display[con].var.xres_virtual;
  2234. oldyres_virtual=fb_display[con].var.yres_virtual;
  2235. oldbpp=fb_display[con].var.bits_per_pixel;
  2236. oldyoffset=fb_display[con].var.yoffset;
  2237. fb_display[con].var=*var;
  2238. if (oldxres != var->xres || oldyres != var->yres
  2239. || oldxres_virtual != var->xres_virtual
  2240. || oldyres_virtual != var->yres_virtual
  2241. || oldbpp != var->bits_per_pixel
  2242. || oldyoffset != var->yoffset) {
  2243. atafb_set_disp(con, info);
  2244. (*fb_info.changevar)(con);
  2245. fb_alloc_cmap(&fb_display[con].cmap, 0, 0);
  2246. do_install_cmap(con, info);
  2247. }
  2248. }
  2249. var->activate=0;
  2250. return 0;
  2251. }
  2252. static int
  2253. atafb_get_cmap(struct fb_cmap *cmap, int kspc, int con, struct fb_info *info)
  2254. {
  2255. if (con == info->currcon) /* current console ? */
  2256. return fb_get_cmap(cmap, kspc, fbhw->getcolreg, info);
  2257. else
  2258. if (fb_display[con].cmap.len) /* non default colormap ? */
  2259. fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
  2260. else
  2261. fb_copy_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel),
  2262. cmap, kspc ? 0 : 2);
  2263. return 0;
  2264. }
  2265. static int
  2266. atafb_pan_display(struct fb_var_screeninfo *var, int con, struct fb_info *info)
  2267. {
  2268. int xoffset = var->xoffset;
  2269. int yoffset = var->yoffset;
  2270. int err;
  2271. if ( xoffset < 0 || xoffset + fb_display[con].var.xres > fb_display[con].var.xres_virtual
  2272. || yoffset < 0 || yoffset + fb_display[con].var.yres > fb_display[con].var.yres_virtual)
  2273. return -EINVAL;
  2274. if (con == info->currcon) {
  2275. if (fbhw->pan_display) {
  2276. if ((err = fbhw->pan_display(var, &current_par)))
  2277. return err;
  2278. }
  2279. else
  2280. return -EINVAL;
  2281. }
  2282. fb_display[con].var.xoffset = var->xoffset;
  2283. fb_display[con].var.yoffset = var->yoffset;
  2284. return 0;
  2285. }
  2286. static int
  2287. atafb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
  2288. {
  2289. switch (cmd) {
  2290. #ifdef FBCMD_GET_CURRENTPAR
  2291. case FBCMD_GET_CURRENTPAR:
  2292. if (copy_to_user((void *)arg, (void *)&current_par,
  2293. sizeof(struct atafb_par)))
  2294. return -EFAULT;
  2295. return 0;
  2296. #endif
  2297. #ifdef FBCMD_SET_CURRENTPAR
  2298. case FBCMD_SET_CURRENTPAR:
  2299. if (copy_from_user((void *)&current_par, (void *)arg,
  2300. sizeof(struct atafb_par)))
  2301. return -EFAULT;
  2302. atafb_set_par(&current_par);
  2303. return 0;
  2304. #endif
  2305. }
  2306. return -EINVAL;
  2307. }
  2308. /* (un)blank/poweroff
  2309. * 0 = unblank
  2310. * 1 = blank
  2311. * 2 = suspend vsync
  2312. * 3 = suspend hsync
  2313. * 4 = off
  2314. */
  2315. static int
  2316. atafb_blank(int blank, struct fb_info *info)
  2317. {
  2318. unsigned short black[16];
  2319. struct fb_cmap cmap;
  2320. if (fbhw->blank && !fbhw->blank(blank))
  2321. return 1;
  2322. if (blank) {
  2323. memset(black, 0, 16*sizeof(unsigned short));
  2324. cmap.red=black;
  2325. cmap.green=black;
  2326. cmap.blue=black;
  2327. cmap.transp=NULL;
  2328. cmap.start=0;
  2329. cmap.len=16;
  2330. fb_set_cmap(&cmap, 1, info);
  2331. }
  2332. else
  2333. do_install_cmap(info->currcon, info);
  2334. return 0;
  2335. }
  2336. static struct fb_ops atafb_ops = {
  2337. .owner = THIS_MODULE,
  2338. .fb_get_fix = atafb_get_fix,
  2339. .fb_get_var = atafb_get_var,
  2340. .fb_set_var = atafb_set_var,
  2341. .fb_get_cmap = atafb_get_cmap,
  2342. .fb_set_cmap = gen_set_cmap,
  2343. .fb_pan_display =atafb_pan_display,
  2344. .fb_blank = atafb_blank,
  2345. .fb_ioctl = atafb_ioctl,
  2346. };
  2347. static void
  2348. check_default_par( int detected_mode )
  2349. {
  2350. char default_name[10];
  2351. int i;
  2352. struct fb_var_screeninfo var;
  2353. unsigned long min_mem;
  2354. /* First try the user supplied mode */
  2355. if (default_par) {
  2356. var=atafb_predefined[default_par-1];
  2357. var.activate = FB_ACTIVATE_TEST;
  2358. if (do_fb_set_var(&var,1))
  2359. default_par=0; /* failed */
  2360. }
  2361. /* Next is the autodetected one */
  2362. if (! default_par) {
  2363. var=atafb_predefined[detected_mode-1]; /* autodetect */
  2364. var.activate = FB_ACTIVATE_TEST;
  2365. if (!do_fb_set_var(&var,1))
  2366. default_par=detected_mode;
  2367. }
  2368. /* If that also failed, try some default modes... */
  2369. if (! default_par) {
  2370. /* try default1, default2... */
  2371. for (i=1 ; i < 10 ; i++) {
  2372. sprintf(default_name,"default%d",i);
  2373. default_par=get_video_mode(default_name);
  2374. if (! default_par)
  2375. panic("can't set default video mode");
  2376. var=atafb_predefined[default_par-1];
  2377. var.activate = FB_ACTIVATE_TEST;
  2378. if (! do_fb_set_var(&var,1))
  2379. break; /* ok */
  2380. }
  2381. }
  2382. min_mem=var.xres_virtual * var.yres_virtual * var.bits_per_pixel/8;
  2383. if (default_mem_req < min_mem)
  2384. default_mem_req=min_mem;
  2385. }
  2386. static int
  2387. atafb_switch(int con, struct fb_info *info)
  2388. {
  2389. /* Do we have to save the colormap ? */
  2390. if (fb_display[info->currcon].cmap.len)
  2391. fb_get_cmap(&fb_display[info->currcon].cmap, 1, fbhw->getcolreg,
  2392. info);
  2393. do_fb_set_var(&fb_display[con].var,1);
  2394. info->currcon=con;
  2395. /* Install new colormap */
  2396. do_install_cmap(con, info);
  2397. return 0;
  2398. }
  2399. int __init atafb_init(void)
  2400. {
  2401. int pad;
  2402. int detected_mode;
  2403. unsigned long mem_req;
  2404. if (!MACH_IS_ATARI)
  2405. return -ENXIO;
  2406. do {
  2407. #ifdef ATAFB_EXT
  2408. if (external_addr) {
  2409. fbhw = &ext_switch;
  2410. atafb_ops.fb_setcolreg = &ext_setcolreg;
  2411. break;
  2412. }
  2413. #endif
  2414. #ifdef ATAFB_TT
  2415. if (ATARIHW_PRESENT(TT_SHIFTER)) {
  2416. fbhw = &tt_switch;
  2417. atafb_ops.fb_setcolreg = &tt_setcolreg;
  2418. break;
  2419. }
  2420. #endif
  2421. #ifdef ATAFB_FALCON
  2422. if (ATARIHW_PRESENT(VIDEL_SHIFTER)) {
  2423. fbhw = &falcon_switch;
  2424. atafb_ops.fb_setcolreg = &falcon_setcolreg;
  2425. request_irq(IRQ_AUTO_4, falcon_vbl_switcher, IRQ_TYPE_PRIO,
  2426. "framebuffer/modeswitch", falcon_vbl_switcher);
  2427. break;
  2428. }
  2429. #endif
  2430. #ifdef ATAFB_STE
  2431. if (ATARIHW_PRESENT(STND_SHIFTER) ||
  2432. ATARIHW_PRESENT(EXTD_SHIFTER)) {
  2433. fbhw = &st_switch;
  2434. atafb_ops.fb_setcolreg = &stste_setcolreg;
  2435. break;
  2436. }
  2437. fbhw = &st_switch;
  2438. atafb_ops.fb_setcolreg = &stste_setcolreg;
  2439. printk("Cannot determine video hardware; defaulting to ST(e)\n");
  2440. #else /* ATAFB_STE */
  2441. /* no default driver included */
  2442. /* Nobody will ever see this message :-) */
  2443. panic("Cannot initialize video hardware");
  2444. #endif
  2445. } while (0);
  2446. /* Multisync monitor capabilities */
  2447. /* Atari-TOS defaults if no boot option present */
  2448. if (fb_info.monspecs.hfmin == 0) {
  2449. fb_info.monspecs.hfmin = 31000;
  2450. fb_info.monspecs.hfmax = 32000;
  2451. fb_info.monspecs.vfmin = 58;
  2452. fb_info.monspecs.vfmax = 62;
  2453. }
  2454. detected_mode = fbhw->detect();
  2455. check_default_par(detected_mode);
  2456. #ifdef ATAFB_EXT
  2457. if (!external_addr) {
  2458. #endif /* ATAFB_EXT */
  2459. mem_req = default_mem_req + ovsc_offset + ovsc_addlen;
  2460. mem_req = PAGE_ALIGN(mem_req) + PAGE_SIZE;
  2461. screen_base = atari_stram_alloc(mem_req, "atafb");
  2462. if (!screen_base)
  2463. panic("Cannot allocate screen memory");
  2464. memset(screen_base, 0, mem_req);
  2465. pad = -(unsigned long)screen_base & (PAGE_SIZE-1);
  2466. screen_base+=pad;
  2467. real_screen_base=screen_base+ovsc_offset;
  2468. screen_len = (mem_req - pad - ovsc_offset) & PAGE_MASK;
  2469. st_ovsc_switch();
  2470. if (CPU_IS_040_OR_060) {
  2471. /* On a '040+, the cache mode of video RAM must be set to
  2472. * write-through also for internal video hardware! */
  2473. cache_push(virt_to_phys(screen_base), screen_len);
  2474. kernel_set_cachemode(screen_base, screen_len,
  2475. IOMAP_WRITETHROUGH);
  2476. }
  2477. #ifdef ATAFB_EXT
  2478. }
  2479. else {
  2480. /* Map the video memory (physical address given) to somewhere
  2481. * in the kernel address space.
  2482. */
  2483. external_addr =
  2484. ioremap_writethrough((unsigned long)external_addr,
  2485. external_len);
  2486. if (external_vgaiobase)
  2487. external_vgaiobase =
  2488. (unsigned long)ioremap(external_vgaiobase, 0x10000);
  2489. screen_base =
  2490. real_screen_base = external_addr;
  2491. screen_len = external_len & PAGE_MASK;
  2492. memset (screen_base, 0, external_len);
  2493. }
  2494. #endif /* ATAFB_EXT */
  2495. strcpy(fb_info.modename, "Atari Builtin ");
  2496. fb_info.changevar = NULL;
  2497. fb_info.fbops = &atafb_ops;
  2498. fb_info.disp = &disp;
  2499. fb_info.currcon = -1;
  2500. fb_info.switch_con = &atafb_switch;
  2501. fb_info.updatevar = &fb_update_var;
  2502. fb_info.flags = FBINFO_FLAG_DEFAULT;
  2503. do_fb_set_var(&atafb_predefined[default_par-1], 1);
  2504. strcat(fb_info.modename, fb_var_names[default_par-1][0]);
  2505. atafb_get_var(&disp.var, -1, &fb_info);
  2506. atafb_set_disp(-1, &fb_info);
  2507. do_install_cmap(0, &fb_info);
  2508. if (register_framebuffer(&fb_info) < 0) {
  2509. #ifdef ATAFB_EXT
  2510. if (external_addr) {
  2511. iounmap(external_addr);
  2512. external_addr = NULL;
  2513. }
  2514. if (external_vgaiobase) {
  2515. iounmap((void*)external_vgaiobase);
  2516. external_vgaiobase = 0;
  2517. }
  2518. #endif
  2519. return -EINVAL;
  2520. }
  2521. printk("Determined %dx%d, depth %d\n",
  2522. disp.var.xres, disp.var.yres, disp.var.bits_per_pixel);
  2523. if ((disp.var.xres != disp.var.xres_virtual) ||
  2524. (disp.var.yres != disp.var.yres_virtual))
  2525. printk(" virtual %dx%d\n",
  2526. disp.var.xres_virtual, disp.var.yres_virtual);
  2527. printk("fb%d: %s frame buffer device, using %dK of video memory\n",
  2528. fb_info.node, fb_info.modename, screen_len>>10);
  2529. /* TODO: This driver cannot be unloaded yet */
  2530. return 0;
  2531. }
  2532. #ifdef ATAFB_EXT
  2533. static void __init atafb_setup_ext(char *spec)
  2534. {
  2535. int xres, xres_virtual, yres, depth, planes;
  2536. unsigned long addr, len;
  2537. char *p;
  2538. /* Format is: <xres>;<yres>;<depth>;<plane organ.>;
  2539. * <screen mem addr>
  2540. * [;<screen mem length>[;<vgaiobase>[;<bits-per-col>[;<colorreg-type>
  2541. * [;<xres-virtual>]]]]]
  2542. *
  2543. * 09/23/97 Juergen
  2544. * <xres_virtual>: hardware's x-resolution (f.e. ProMST)
  2545. *
  2546. * Even xres_virtual is available, we neither support panning nor hw-scrolling!
  2547. */
  2548. if (!(p = strsep(&spec, ";")) || !*p)
  2549. return;
  2550. xres_virtual = xres = simple_strtoul(p, NULL, 10);
  2551. if (xres <= 0)
  2552. return;
  2553. if (!(p = strsep(&spec, ";")) || !*p)
  2554. return;
  2555. yres = simple_strtoul(p, NULL, 10);
  2556. if (yres <= 0)
  2557. return;
  2558. if (!(p = strsep(&spec, ";")) || !*p)
  2559. return;
  2560. depth = simple_strtoul(p, NULL, 10);
  2561. if (depth != 1 && depth != 2 && depth != 4 && depth != 8 &&
  2562. depth != 16 && depth != 24)
  2563. return;
  2564. if (!(p = strsep(&spec, ";")) || !*p)
  2565. return;
  2566. if (*p == 'i')
  2567. planes = FB_TYPE_INTERLEAVED_PLANES;
  2568. else if (*p == 'p')
  2569. planes = FB_TYPE_PACKED_PIXELS;
  2570. else if (*p == 'n')
  2571. planes = FB_TYPE_PLANES;
  2572. else if (*p == 't')
  2573. planes = -1; /* true color */
  2574. else
  2575. return;
  2576. if (!(p = strsep(&spec, ";")) || !*p)
  2577. return;
  2578. addr = simple_strtoul(p, NULL, 0);
  2579. if (!(p = strsep(&spec, ";")) || !*p)
  2580. len = xres*yres*depth/8;
  2581. else
  2582. len = simple_strtoul(p, NULL, 0);
  2583. if ((p = strsep(&spec, ";")) && *p) {
  2584. external_vgaiobase=simple_strtoul(p, NULL, 0);
  2585. }
  2586. if ((p = strsep(&spec, ";")) && *p) {
  2587. external_bitspercol = simple_strtoul(p, NULL, 0);
  2588. if (external_bitspercol > 8)
  2589. external_bitspercol = 8;
  2590. else if (external_bitspercol < 1)
  2591. external_bitspercol = 1;
  2592. }
  2593. if ((p = strsep(&spec, ";")) && *p) {
  2594. if (!strcmp(p, "vga"))
  2595. external_card_type = IS_VGA;
  2596. if (!strcmp(p, "mv300"))
  2597. external_card_type = IS_MV300;
  2598. }
  2599. if ((p = strsep(&spec, ";")) && *p) {
  2600. xres_virtual = simple_strtoul(p, NULL, 10);
  2601. if (xres_virtual < xres)
  2602. xres_virtual = xres;
  2603. if (xres_virtual*yres*depth/8 > len)
  2604. len=xres_virtual*yres*depth/8;
  2605. }
  2606. external_xres = xres;
  2607. external_xres_virtual = xres_virtual;
  2608. external_yres = yres;
  2609. external_depth = depth;
  2610. external_pmode = planes;
  2611. external_addr = (void *)addr;
  2612. external_len = len;
  2613. if (external_card_type == IS_MV300)
  2614. switch (external_depth) {
  2615. case 1:
  2616. MV300_reg = MV300_reg_1bit;
  2617. break;
  2618. case 4:
  2619. MV300_reg = MV300_reg_4bit;
  2620. break;
  2621. case 8:
  2622. MV300_reg = MV300_reg_8bit;
  2623. break;
  2624. }
  2625. }
  2626. #endif /* ATAFB_EXT */
  2627. static void __init atafb_setup_int(char *spec)
  2628. {
  2629. /* Format to config extended internal video hardware like OverScan:
  2630. "internal:<xres>;<yres>;<xres_max>;<yres_max>;<offset>"
  2631. Explanation:
  2632. <xres>: x-resolution
  2633. <yres>: y-resolution
  2634. The following are only needed if you have an overscan which
  2635. needs a black border:
  2636. <xres_max>: max. length of a line in pixels your OverScan hardware would allow
  2637. <yres_max>: max. number of lines your OverScan hardware would allow
  2638. <offset>: Offset from physical beginning to visible beginning
  2639. of screen in bytes
  2640. */
  2641. int xres;
  2642. char *p;
  2643. if (!(p = strsep(&spec, ";")) || !*p)
  2644. return;
  2645. xres = simple_strtoul(p, NULL, 10);
  2646. if (!(p = strsep(&spec, ";")) || !*p)
  2647. return;
  2648. sttt_xres=xres;
  2649. tt_yres=st_yres=simple_strtoul(p, NULL, 10);
  2650. if ((p=strsep(&spec, ";")) && *p) {
  2651. sttt_xres_virtual=simple_strtoul(p, NULL, 10);
  2652. }
  2653. if ((p=strsep(&spec, ";")) && *p) {
  2654. sttt_yres_virtual=simple_strtoul(p, NULL, 0);
  2655. }
  2656. if ((p=strsep(&spec, ";")) && *p) {
  2657. ovsc_offset=simple_strtoul(p, NULL, 0);
  2658. }
  2659. if (ovsc_offset || (sttt_yres_virtual != st_yres))
  2660. use_hwscroll=0;
  2661. }
  2662. #ifdef ATAFB_FALCON
  2663. static void __init atafb_setup_mcap(char *spec)
  2664. {
  2665. char *p;
  2666. int vmin, vmax, hmin, hmax;
  2667. /* Format for monitor capabilities is: <Vmin>;<Vmax>;<Hmin>;<Hmax>
  2668. * <V*> vertical freq. in Hz
  2669. * <H*> horizontal freq. in kHz
  2670. */
  2671. if (!(p = strsep(&spec, ";")) || !*p)
  2672. return;
  2673. vmin = simple_strtoul(p, NULL, 10);
  2674. if (vmin <= 0)
  2675. return;
  2676. if (!(p = strsep(&spec, ";")) || !*p)
  2677. return;
  2678. vmax = simple_strtoul(p, NULL, 10);
  2679. if (vmax <= 0 || vmax <= vmin)
  2680. return;
  2681. if (!(p = strsep(&spec, ";")) || !*p)
  2682. return;
  2683. hmin = 1000 * simple_strtoul(p, NULL, 10);
  2684. if (hmin <= 0)
  2685. return;
  2686. if (!(p = strsep(&spec, "")) || !*p)
  2687. return;
  2688. hmax = 1000 * simple_strtoul(p, NULL, 10);
  2689. if (hmax <= 0 || hmax <= hmin)
  2690. return;
  2691. fb_info.monspecs.vfmin = vmin;
  2692. fb_info.monspecs.vfmax = vmax;
  2693. fb_info.monspecs.hfmin = hmin;
  2694. fb_info.monspecs.hfmax = hmax;
  2695. }
  2696. #endif /* ATAFB_FALCON */
  2697. static void __init atafb_setup_user(char *spec)
  2698. {
  2699. /* Format of user defined video mode is: <xres>;<yres>;<depth>
  2700. */
  2701. char *p;
  2702. int xres, yres, depth, temp;
  2703. if (!(p = strsep(&spec, ";")) || !*p)
  2704. return;
  2705. xres = simple_strtoul(p, NULL, 10);
  2706. if (!(p = strsep(&spec, ";")) || !*p)
  2707. return;
  2708. yres = simple_strtoul(p, NULL, 10);
  2709. if (!(p = strsep(&spec, "")) || !*p)
  2710. return;
  2711. depth = simple_strtoul(p, NULL, 10);
  2712. if ((temp=get_video_mode("user0"))) {
  2713. default_par=temp;
  2714. atafb_predefined[default_par-1].xres = xres;
  2715. atafb_predefined[default_par-1].yres = yres;
  2716. atafb_predefined[default_par-1].bits_per_pixel = depth;
  2717. }
  2718. }
  2719. int __init atafb_setup( char *options )
  2720. {
  2721. char *this_opt;
  2722. int temp;
  2723. fb_info.fontname[0] = '\0';
  2724. if (!options || !*options)
  2725. return 0;
  2726. while ((this_opt = strsep(&options, ",")) != NULL) {
  2727. if (!*this_opt) continue;
  2728. if ((temp=get_video_mode(this_opt)))
  2729. default_par=temp;
  2730. else if (! strcmp(this_opt, "inverse"))
  2731. inverse=1;
  2732. else if (!strncmp(this_opt, "font:", 5))
  2733. strcpy(fb_info.fontname, this_opt+5);
  2734. else if (! strncmp(this_opt, "hwscroll_",9)) {
  2735. hwscroll=simple_strtoul(this_opt+9, NULL, 10);
  2736. if (hwscroll < 0)
  2737. hwscroll = 0;
  2738. if (hwscroll > 200)
  2739. hwscroll = 200;
  2740. }
  2741. #ifdef ATAFB_EXT
  2742. else if (!strcmp(this_opt,"mv300")) {
  2743. external_bitspercol = 8;
  2744. external_card_type = IS_MV300;
  2745. }
  2746. else if (!strncmp(this_opt,"external:",9))
  2747. atafb_setup_ext(this_opt+9);
  2748. #endif
  2749. else if (!strncmp(this_opt,"internal:",9))
  2750. atafb_setup_int(this_opt+9);
  2751. #ifdef ATAFB_FALCON
  2752. else if (!strncmp(this_opt, "eclock:", 7)) {
  2753. fext.f = simple_strtoul(this_opt+7, NULL, 10);
  2754. /* external pixelclock in kHz --> ps */
  2755. fext.t = 1000000000/fext.f;
  2756. fext.f *= 1000;
  2757. }
  2758. else if (!strncmp(this_opt, "monitorcap:", 11))
  2759. atafb_setup_mcap(this_opt+11);
  2760. #endif
  2761. else if (!strcmp(this_opt, "keep"))
  2762. DontCalcRes = 1;
  2763. else if (!strncmp(this_opt, "R", 1))
  2764. atafb_setup_user(this_opt+1);
  2765. }
  2766. return 0;
  2767. }
  2768. #ifdef MODULE
  2769. MODULE_LICENSE("GPL");
  2770. int init_module(void)
  2771. {
  2772. return atafb_init();
  2773. }
  2774. #endif /* MODULE */