atafb.c 89 KB

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