atafb.c 89 KB

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