atafb.c 82 KB

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