atafb.c 87 KB

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