atyfb_base.c 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912
  1. /*
  2. * ATI Frame Buffer Device Driver Core
  3. *
  4. * Copyright (C) 2004 Alex Kern <alex.kern@gmx.de>
  5. * Copyright (C) 1997-2001 Geert Uytterhoeven
  6. * Copyright (C) 1998 Bernd Harries
  7. * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
  8. *
  9. * This driver supports the following ATI graphics chips:
  10. * - ATI Mach64
  11. *
  12. * To do: add support for
  13. * - ATI Rage128 (from aty128fb.c)
  14. * - ATI Radeon (from radeonfb.c)
  15. *
  16. * This driver is partly based on the PowerMac console driver:
  17. *
  18. * Copyright (C) 1996 Paul Mackerras
  19. *
  20. * and on the PowerMac ATI/mach64 display driver:
  21. *
  22. * Copyright (C) 1997 Michael AK Tesch
  23. *
  24. * with work by Jon Howell
  25. * Harry AC Eaton
  26. * Anthony Tong <atong@uiuc.edu>
  27. *
  28. * Generic LCD support written by Daniel Mantione, ported from 2.4.20 by Alex Kern
  29. * Many Thanks to Ville Syrjälä for patches and fixing nasting 16 bit color bug.
  30. *
  31. * This file is subject to the terms and conditions of the GNU General Public
  32. * License. See the file COPYING in the main directory of this archive for
  33. * more details.
  34. *
  35. * Many thanks to Nitya from ATI devrel for support and patience !
  36. */
  37. /******************************************************************************
  38. TODO:
  39. - cursor support on all cards and all ramdacs.
  40. - cursor parameters controlable via ioctl()s.
  41. - guess PLL and MCLK based on the original PLL register values initialized
  42. by Open Firmware (if they are initialized). BIOS is done
  43. (Anyone with Mac to help with this?)
  44. ******************************************************************************/
  45. #include <linux/module.h>
  46. #include <linux/moduleparam.h>
  47. #include <linux/kernel.h>
  48. #include <linux/errno.h>
  49. #include <linux/string.h>
  50. #include <linux/mm.h>
  51. #include <linux/slab.h>
  52. #include <linux/vmalloc.h>
  53. #include <linux/delay.h>
  54. #include <linux/console.h>
  55. #include <linux/fb.h>
  56. #include <linux/init.h>
  57. #include <linux/pci.h>
  58. #include <linux/interrupt.h>
  59. #include <linux/spinlock.h>
  60. #include <linux/wait.h>
  61. #include <linux/backlight.h>
  62. #include <asm/io.h>
  63. #include <asm/uaccess.h>
  64. #include <video/mach64.h>
  65. #include "atyfb.h"
  66. #include "ati_ids.h"
  67. #ifdef __powerpc__
  68. #include <asm/machdep.h>
  69. #include <asm/prom.h>
  70. #include "../macmodes.h"
  71. #endif
  72. #ifdef __sparc__
  73. #include <asm/pbm.h>
  74. #include <asm/fbio.h>
  75. #endif
  76. #ifdef CONFIG_ADB_PMU
  77. #include <linux/adb.h>
  78. #include <linux/pmu.h>
  79. #endif
  80. #ifdef CONFIG_BOOTX_TEXT
  81. #include <asm/btext.h>
  82. #endif
  83. #ifdef CONFIG_PMAC_BACKLIGHT
  84. #include <asm/backlight.h>
  85. #endif
  86. #ifdef CONFIG_MTRR
  87. #include <asm/mtrr.h>
  88. #endif
  89. /*
  90. * Debug flags.
  91. */
  92. #undef DEBUG
  93. /*#define DEBUG*/
  94. /* Make sure n * PAGE_SIZE is protected at end of Aperture for GUI-regs */
  95. /* - must be large enough to catch all GUI-Regs */
  96. /* - must be aligned to a PAGE boundary */
  97. #define GUI_RESERVE (1 * PAGE_SIZE)
  98. /* FIXME: remove the FAIL definition */
  99. #define FAIL(msg) do { \
  100. if (!(var->activate & FB_ACTIVATE_TEST)) \
  101. printk(KERN_CRIT "atyfb: " msg "\n"); \
  102. return -EINVAL; \
  103. } while (0)
  104. #define FAIL_MAX(msg, x, _max_) do { \
  105. if (x > _max_) { \
  106. if (!(var->activate & FB_ACTIVATE_TEST)) \
  107. printk(KERN_CRIT "atyfb: " msg " %x(%x)\n", x, _max_); \
  108. return -EINVAL; \
  109. } \
  110. } while (0)
  111. #ifdef DEBUG
  112. #define DPRINTK(fmt, args...) printk(KERN_DEBUG "atyfb: " fmt, ## args)
  113. #else
  114. #define DPRINTK(fmt, args...)
  115. #endif
  116. #define PRINTKI(fmt, args...) printk(KERN_INFO "atyfb: " fmt, ## args)
  117. #define PRINTKE(fmt, args...) printk(KERN_ERR "atyfb: " fmt, ## args)
  118. #if defined(CONFIG_PM) || defined(CONFIG_PMAC_BACKLIGHT) || defined (CONFIG_FB_ATY_GENERIC_LCD)
  119. static const u32 lt_lcd_regs[] = {
  120. CONFIG_PANEL_LG,
  121. LCD_GEN_CNTL_LG,
  122. DSTN_CONTROL_LG,
  123. HFB_PITCH_ADDR_LG,
  124. HORZ_STRETCHING_LG,
  125. VERT_STRETCHING_LG,
  126. 0, /* EXT_VERT_STRETCH */
  127. LT_GIO_LG,
  128. POWER_MANAGEMENT_LG
  129. };
  130. void aty_st_lcd(int index, u32 val, const struct atyfb_par *par)
  131. {
  132. if (M64_HAS(LT_LCD_REGS)) {
  133. aty_st_le32(lt_lcd_regs[index], val, par);
  134. } else {
  135. unsigned long temp;
  136. /* write addr byte */
  137. temp = aty_ld_le32(LCD_INDEX, par);
  138. aty_st_le32(LCD_INDEX, (temp & ~LCD_INDEX_MASK) | index, par);
  139. /* write the register value */
  140. aty_st_le32(LCD_DATA, val, par);
  141. }
  142. }
  143. u32 aty_ld_lcd(int index, const struct atyfb_par *par)
  144. {
  145. if (M64_HAS(LT_LCD_REGS)) {
  146. return aty_ld_le32(lt_lcd_regs[index], par);
  147. } else {
  148. unsigned long temp;
  149. /* write addr byte */
  150. temp = aty_ld_le32(LCD_INDEX, par);
  151. aty_st_le32(LCD_INDEX, (temp & ~LCD_INDEX_MASK) | index, par);
  152. /* read the register value */
  153. return aty_ld_le32(LCD_DATA, par);
  154. }
  155. }
  156. #endif /* defined(CONFIG_PM) || defined(CONFIG_PMAC_BACKLIGHT) || defined (CONFIG_FB_ATY_GENERIC_LCD) */
  157. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  158. /*
  159. * ATIReduceRatio --
  160. *
  161. * Reduce a fraction by factoring out the largest common divider of the
  162. * fraction's numerator and denominator.
  163. */
  164. static void ATIReduceRatio(int *Numerator, int *Denominator)
  165. {
  166. int Multiplier, Divider, Remainder;
  167. Multiplier = *Numerator;
  168. Divider = *Denominator;
  169. while ((Remainder = Multiplier % Divider))
  170. {
  171. Multiplier = Divider;
  172. Divider = Remainder;
  173. }
  174. *Numerator /= Divider;
  175. *Denominator /= Divider;
  176. }
  177. #endif
  178. /*
  179. * The Hardware parameters for each card
  180. */
  181. struct aty_cmap_regs {
  182. u8 windex;
  183. u8 lut;
  184. u8 mask;
  185. u8 rindex;
  186. u8 cntl;
  187. };
  188. struct pci_mmap_map {
  189. unsigned long voff;
  190. unsigned long poff;
  191. unsigned long size;
  192. unsigned long prot_flag;
  193. unsigned long prot_mask;
  194. };
  195. static struct fb_fix_screeninfo atyfb_fix __devinitdata = {
  196. .id = "ATY Mach64",
  197. .type = FB_TYPE_PACKED_PIXELS,
  198. .visual = FB_VISUAL_PSEUDOCOLOR,
  199. .xpanstep = 8,
  200. .ypanstep = 1,
  201. };
  202. /*
  203. * Frame buffer device API
  204. */
  205. static int atyfb_open(struct fb_info *info, int user);
  206. static int atyfb_release(struct fb_info *info, int user);
  207. static int atyfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info);
  208. static int atyfb_set_par(struct fb_info *info);
  209. static int atyfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  210. u_int transp, struct fb_info *info);
  211. static int atyfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info);
  212. static int atyfb_blank(int blank, struct fb_info *info);
  213. static int atyfb_ioctl(struct fb_info *info, u_int cmd, u_long arg);
  214. #ifdef __sparc__
  215. static int atyfb_mmap(struct fb_info *info, struct vm_area_struct *vma);
  216. #endif
  217. static int atyfb_sync(struct fb_info *info);
  218. /*
  219. * Internal routines
  220. */
  221. static int aty_init(struct fb_info *info, const char *name);
  222. #ifdef CONFIG_ATARI
  223. static int store_video_par(char *videopar, unsigned char m64_num);
  224. #endif
  225. static struct crtc saved_crtc;
  226. static union aty_pll saved_pll;
  227. static void aty_get_crtc(const struct atyfb_par *par, struct crtc *crtc);
  228. static void aty_set_crtc(const struct atyfb_par *par, const struct crtc *crtc);
  229. static int aty_var_to_crtc(const struct fb_info *info, const struct fb_var_screeninfo *var, struct crtc *crtc);
  230. static int aty_crtc_to_var(const struct crtc *crtc, struct fb_var_screeninfo *var);
  231. static void set_off_pitch(struct atyfb_par *par, const struct fb_info *info);
  232. #ifdef CONFIG_PPC
  233. static int read_aty_sense(const struct atyfb_par *par);
  234. #endif
  235. /*
  236. * Interface used by the world
  237. */
  238. static struct fb_var_screeninfo default_var = {
  239. /* 640x480, 60 Hz, Non-Interlaced (25.175 MHz dotclock) */
  240. 640, 480, 640, 480, 0, 0, 8, 0,
  241. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  242. 0, 0, -1, -1, 0, 39722, 48, 16, 33, 10, 96, 2,
  243. 0, FB_VMODE_NONINTERLACED
  244. };
  245. static struct fb_videomode defmode = {
  246. /* 640x480 @ 60 Hz, 31.5 kHz hsync */
  247. NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2,
  248. 0, FB_VMODE_NONINTERLACED
  249. };
  250. static struct fb_ops atyfb_ops = {
  251. .owner = THIS_MODULE,
  252. .fb_open = atyfb_open,
  253. .fb_release = atyfb_release,
  254. .fb_check_var = atyfb_check_var,
  255. .fb_set_par = atyfb_set_par,
  256. .fb_setcolreg = atyfb_setcolreg,
  257. .fb_pan_display = atyfb_pan_display,
  258. .fb_blank = atyfb_blank,
  259. .fb_ioctl = atyfb_ioctl,
  260. .fb_fillrect = atyfb_fillrect,
  261. .fb_copyarea = atyfb_copyarea,
  262. .fb_imageblit = atyfb_imageblit,
  263. #ifdef __sparc__
  264. .fb_mmap = atyfb_mmap,
  265. #endif
  266. .fb_sync = atyfb_sync,
  267. };
  268. static int noaccel;
  269. #ifdef CONFIG_MTRR
  270. static int nomtrr;
  271. #endif
  272. static int vram;
  273. static int pll;
  274. static int mclk;
  275. static int xclk;
  276. static int comp_sync __devinitdata = -1;
  277. static char *mode;
  278. #ifdef CONFIG_PPC
  279. static int default_vmode __devinitdata = VMODE_CHOOSE;
  280. static int default_cmode __devinitdata = CMODE_CHOOSE;
  281. module_param_named(vmode, default_vmode, int, 0);
  282. MODULE_PARM_DESC(vmode, "int: video mode for mac");
  283. module_param_named(cmode, default_cmode, int, 0);
  284. MODULE_PARM_DESC(cmode, "int: color mode for mac");
  285. #endif
  286. #ifdef CONFIG_ATARI
  287. static unsigned int mach64_count __devinitdata = 0;
  288. static unsigned long phys_vmembase[FB_MAX] __devinitdata = { 0, };
  289. static unsigned long phys_size[FB_MAX] __devinitdata = { 0, };
  290. static unsigned long phys_guiregbase[FB_MAX] __devinitdata = { 0, };
  291. #endif
  292. /* top -> down is an evolution of mach64 chipset, any corrections? */
  293. #define ATI_CHIP_88800GX (M64F_GX)
  294. #define ATI_CHIP_88800CX (M64F_GX)
  295. #define ATI_CHIP_264CT (M64F_CT | M64F_INTEGRATED | M64F_CT_BUS | M64F_MAGIC_FIFO)
  296. #define ATI_CHIP_264ET (M64F_CT | M64F_INTEGRATED | M64F_CT_BUS | M64F_MAGIC_FIFO)
  297. #define ATI_CHIP_264VT (M64F_VT | M64F_INTEGRATED | M64F_VT_BUS | M64F_MAGIC_FIFO)
  298. #define ATI_CHIP_264GT (M64F_GT | M64F_INTEGRATED | M64F_MAGIC_FIFO | M64F_EXTRA_BRIGHT)
  299. #define ATI_CHIP_264VTB (M64F_VT | M64F_INTEGRATED | M64F_VT_BUS | M64F_GTB_DSP)
  300. #define ATI_CHIP_264VT3 (M64F_VT | M64F_INTEGRATED | M64F_VT_BUS | M64F_GTB_DSP | M64F_SDRAM_MAGIC_PLL)
  301. #define ATI_CHIP_264VT4 (M64F_VT | M64F_INTEGRATED | M64F_GTB_DSP)
  302. /* FIXME what is this chip? */
  303. #define ATI_CHIP_264LT (M64F_GT | M64F_INTEGRATED | M64F_GTB_DSP)
  304. /* make sets shorter */
  305. #define ATI_MODERN_SET (M64F_GT | M64F_INTEGRATED | M64F_GTB_DSP | M64F_EXTRA_BRIGHT)
  306. #define ATI_CHIP_264GTB (ATI_MODERN_SET | M64F_SDRAM_MAGIC_PLL)
  307. /*#define ATI_CHIP_264GTDVD ?*/
  308. #define ATI_CHIP_264LTG (ATI_MODERN_SET | M64F_SDRAM_MAGIC_PLL)
  309. #define ATI_CHIP_264GT2C (ATI_MODERN_SET | M64F_SDRAM_MAGIC_PLL | M64F_HW_TRIPLE)
  310. #define ATI_CHIP_264GTPRO (ATI_MODERN_SET | M64F_SDRAM_MAGIC_PLL | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D)
  311. #define ATI_CHIP_264LTPRO (ATI_MODERN_SET | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D)
  312. #define ATI_CHIP_264XL (ATI_MODERN_SET | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D | M64F_XL_DLL | M64F_MFB_FORCE_4)
  313. #define ATI_CHIP_MOBILITY (ATI_MODERN_SET | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D | M64F_XL_DLL | M64F_MFB_FORCE_4 | M64F_MOBIL_BUS)
  314. static struct {
  315. u16 pci_id;
  316. const char *name;
  317. int pll, mclk, xclk, ecp_max;
  318. u32 features;
  319. } aty_chips[] __devinitdata = {
  320. #ifdef CONFIG_FB_ATY_GX
  321. /* Mach64 GX */
  322. { PCI_CHIP_MACH64GX, "ATI888GX00 (Mach64 GX)", 135, 50, 50, 0, ATI_CHIP_88800GX },
  323. { PCI_CHIP_MACH64CX, "ATI888CX00 (Mach64 CX)", 135, 50, 50, 0, ATI_CHIP_88800CX },
  324. #endif /* CONFIG_FB_ATY_GX */
  325. #ifdef CONFIG_FB_ATY_CT
  326. { PCI_CHIP_MACH64CT, "ATI264CT (Mach64 CT)", 135, 60, 60, 0, ATI_CHIP_264CT },
  327. { PCI_CHIP_MACH64ET, "ATI264ET (Mach64 ET)", 135, 60, 60, 0, ATI_CHIP_264ET },
  328. /* FIXME what is this chip? */
  329. { PCI_CHIP_MACH64LT, "ATI264LT (Mach64 LT)", 135, 63, 63, 0, ATI_CHIP_264LT },
  330. { PCI_CHIP_MACH64VT, "ATI264VT (Mach64 VT)", 170, 67, 67, 80, ATI_CHIP_264VT },
  331. { PCI_CHIP_MACH64GT, "3D RAGE (Mach64 GT)", 135, 63, 63, 80, ATI_CHIP_264GT },
  332. { PCI_CHIP_MACH64VU, "ATI264VT3 (Mach64 VU)", 200, 67, 67, 80, ATI_CHIP_264VT3 },
  333. { PCI_CHIP_MACH64GU, "3D RAGE II+ (Mach64 GU)", 200, 67, 67, 100, ATI_CHIP_264GTB },
  334. { PCI_CHIP_MACH64LG, "3D RAGE LT (Mach64 LG)", 230, 63, 63, 100, ATI_CHIP_264LTG | M64F_LT_LCD_REGS | M64F_G3_PB_1024x768 },
  335. { PCI_CHIP_MACH64VV, "ATI264VT4 (Mach64 VV)", 230, 83, 83, 100, ATI_CHIP_264VT4 },
  336. { PCI_CHIP_MACH64GV, "3D RAGE IIC (Mach64 GV, PCI)", 230, 83, 83, 100, ATI_CHIP_264GT2C },
  337. { PCI_CHIP_MACH64GW, "3D RAGE IIC (Mach64 GW, AGP)", 230, 83, 83, 100, ATI_CHIP_264GT2C },
  338. { PCI_CHIP_MACH64GY, "3D RAGE IIC (Mach64 GY, PCI)", 230, 83, 83, 100, ATI_CHIP_264GT2C },
  339. { PCI_CHIP_MACH64GZ, "3D RAGE IIC (Mach64 GZ, AGP)", 230, 83, 83, 100, ATI_CHIP_264GT2C },
  340. { PCI_CHIP_MACH64GB, "3D RAGE PRO (Mach64 GB, BGA, AGP)", 230, 100, 100, 125, ATI_CHIP_264GTPRO },
  341. { PCI_CHIP_MACH64GD, "3D RAGE PRO (Mach64 GD, BGA, AGP 1x)", 230, 100, 100, 125, ATI_CHIP_264GTPRO },
  342. { PCI_CHIP_MACH64GI, "3D RAGE PRO (Mach64 GI, BGA, PCI)", 230, 100, 100, 125, ATI_CHIP_264GTPRO | M64F_MAGIC_VRAM_SIZE },
  343. { PCI_CHIP_MACH64GP, "3D RAGE PRO (Mach64 GP, PQFP, PCI)", 230, 100, 100, 125, ATI_CHIP_264GTPRO },
  344. { PCI_CHIP_MACH64GQ, "3D RAGE PRO (Mach64 GQ, PQFP, PCI, limited 3D)", 230, 100, 100, 125, ATI_CHIP_264GTPRO },
  345. { PCI_CHIP_MACH64LB, "3D RAGE LT PRO (Mach64 LB, AGP)", 236, 75, 100, 135, ATI_CHIP_264LTPRO },
  346. { PCI_CHIP_MACH64LD, "3D RAGE LT PRO (Mach64 LD, AGP)", 230, 100, 100, 135, ATI_CHIP_264LTPRO },
  347. { PCI_CHIP_MACH64LI, "3D RAGE LT PRO (Mach64 LI, PCI)", 230, 100, 100, 135, ATI_CHIP_264LTPRO | M64F_G3_PB_1_1 | M64F_G3_PB_1024x768 },
  348. { PCI_CHIP_MACH64LP, "3D RAGE LT PRO (Mach64 LP, PCI)", 230, 100, 100, 135, ATI_CHIP_264LTPRO },
  349. { PCI_CHIP_MACH64LQ, "3D RAGE LT PRO (Mach64 LQ, PCI)", 230, 100, 100, 135, ATI_CHIP_264LTPRO },
  350. { PCI_CHIP_MACH64GM, "3D RAGE XL (Mach64 GM, AGP 2x)", 230, 83, 63, 135, ATI_CHIP_264XL },
  351. { PCI_CHIP_MACH64GN, "3D RAGE XC (Mach64 GN, AGP 2x)", 230, 83, 63, 135, ATI_CHIP_264XL },
  352. { PCI_CHIP_MACH64GO, "3D RAGE XL (Mach64 GO, PCI-66)", 230, 83, 63, 135, ATI_CHIP_264XL },
  353. { PCI_CHIP_MACH64GL, "3D RAGE XC (Mach64 GL, PCI-66)", 230, 83, 63, 135, ATI_CHIP_264XL },
  354. { PCI_CHIP_MACH64GR, "3D RAGE XL (Mach64 GR, PCI-33)", 230, 83, 63, 135, ATI_CHIP_264XL | M64F_SDRAM_MAGIC_PLL },
  355. { PCI_CHIP_MACH64GS, "3D RAGE XC (Mach64 GS, PCI-33)", 230, 83, 63, 135, ATI_CHIP_264XL },
  356. { PCI_CHIP_MACH64LM, "3D RAGE Mobility P/M (Mach64 LM, AGP 2x)", 230, 83, 125, 135, ATI_CHIP_MOBILITY },
  357. { PCI_CHIP_MACH64LN, "3D RAGE Mobility L (Mach64 LN, AGP 2x)", 230, 83, 125, 135, ATI_CHIP_MOBILITY },
  358. { PCI_CHIP_MACH64LR, "3D RAGE Mobility P/M (Mach64 LR, PCI)", 230, 83, 125, 135, ATI_CHIP_MOBILITY },
  359. { PCI_CHIP_MACH64LS, "3D RAGE Mobility L (Mach64 LS, PCI)", 230, 83, 125, 135, ATI_CHIP_MOBILITY },
  360. #endif /* CONFIG_FB_ATY_CT */
  361. };
  362. /* can not fail */
  363. static int __devinit correct_chipset(struct atyfb_par *par)
  364. {
  365. u8 rev;
  366. u16 type;
  367. u32 chip_id;
  368. const char *name;
  369. int i;
  370. for (i = ARRAY_SIZE(aty_chips) - 1; i >= 0; i--)
  371. if (par->pci_id == aty_chips[i].pci_id)
  372. break;
  373. name = aty_chips[i].name;
  374. par->pll_limits.pll_max = aty_chips[i].pll;
  375. par->pll_limits.mclk = aty_chips[i].mclk;
  376. par->pll_limits.xclk = aty_chips[i].xclk;
  377. par->pll_limits.ecp_max = aty_chips[i].ecp_max;
  378. par->features = aty_chips[i].features;
  379. chip_id = aty_ld_le32(CONFIG_CHIP_ID, par);
  380. type = chip_id & CFG_CHIP_TYPE;
  381. rev = (chip_id & CFG_CHIP_REV) >> 24;
  382. switch(par->pci_id) {
  383. #ifdef CONFIG_FB_ATY_GX
  384. case PCI_CHIP_MACH64GX:
  385. if(type != 0x00d7)
  386. return -ENODEV;
  387. break;
  388. case PCI_CHIP_MACH64CX:
  389. if(type != 0x0057)
  390. return -ENODEV;
  391. break;
  392. #endif
  393. #ifdef CONFIG_FB_ATY_CT
  394. case PCI_CHIP_MACH64VT:
  395. switch (rev & 0x07) {
  396. case 0x00:
  397. switch (rev & 0xc0) {
  398. case 0x00:
  399. name = "ATI264VT (A3) (Mach64 VT)";
  400. par->pll_limits.pll_max = 170;
  401. par->pll_limits.mclk = 67;
  402. par->pll_limits.xclk = 67;
  403. par->pll_limits.ecp_max = 80;
  404. par->features = ATI_CHIP_264VT;
  405. break;
  406. case 0x40:
  407. name = "ATI264VT2 (A4) (Mach64 VT)";
  408. par->pll_limits.pll_max = 200;
  409. par->pll_limits.mclk = 67;
  410. par->pll_limits.xclk = 67;
  411. par->pll_limits.ecp_max = 80;
  412. par->features = ATI_CHIP_264VT | M64F_MAGIC_POSTDIV;
  413. break;
  414. }
  415. break;
  416. case 0x01:
  417. name = "ATI264VT3 (B1) (Mach64 VT)";
  418. par->pll_limits.pll_max = 200;
  419. par->pll_limits.mclk = 67;
  420. par->pll_limits.xclk = 67;
  421. par->pll_limits.ecp_max = 80;
  422. par->features = ATI_CHIP_264VTB;
  423. break;
  424. case 0x02:
  425. name = "ATI264VT3 (B2) (Mach64 VT)";
  426. par->pll_limits.pll_max = 200;
  427. par->pll_limits.mclk = 67;
  428. par->pll_limits.xclk = 67;
  429. par->pll_limits.ecp_max = 80;
  430. par->features = ATI_CHIP_264VT3;
  431. break;
  432. }
  433. break;
  434. case PCI_CHIP_MACH64GT:
  435. switch (rev & 0x07) {
  436. case 0x01:
  437. name = "3D RAGE II (Mach64 GT)";
  438. par->pll_limits.pll_max = 170;
  439. par->pll_limits.mclk = 67;
  440. par->pll_limits.xclk = 67;
  441. par->pll_limits.ecp_max = 80;
  442. par->features = ATI_CHIP_264GTB;
  443. break;
  444. case 0x02:
  445. name = "3D RAGE II+ (Mach64 GT)";
  446. par->pll_limits.pll_max = 200;
  447. par->pll_limits.mclk = 67;
  448. par->pll_limits.xclk = 67;
  449. par->pll_limits.ecp_max = 100;
  450. par->features = ATI_CHIP_264GTB;
  451. break;
  452. }
  453. break;
  454. #endif
  455. }
  456. PRINTKI("%s [0x%04x rev 0x%02x]\n", name, type, rev);
  457. return 0;
  458. }
  459. static char ram_dram[] __devinitdata = "DRAM";
  460. static char ram_resv[] __devinitdata = "RESV";
  461. #ifdef CONFIG_FB_ATY_GX
  462. static char ram_vram[] __devinitdata = "VRAM";
  463. #endif /* CONFIG_FB_ATY_GX */
  464. #ifdef CONFIG_FB_ATY_CT
  465. static char ram_edo[] __devinitdata = "EDO";
  466. static char ram_sdram[] __devinitdata = "SDRAM (1:1)";
  467. static char ram_sgram[] __devinitdata = "SGRAM (1:1)";
  468. static char ram_sdram32[] __devinitdata = "SDRAM (2:1) (32-bit)";
  469. static char ram_off[] __devinitdata = "OFF";
  470. #endif /* CONFIG_FB_ATY_CT */
  471. static u32 pseudo_palette[17];
  472. #ifdef CONFIG_FB_ATY_GX
  473. static char *aty_gx_ram[8] __devinitdata = {
  474. ram_dram, ram_vram, ram_vram, ram_dram,
  475. ram_dram, ram_vram, ram_vram, ram_resv
  476. };
  477. #endif /* CONFIG_FB_ATY_GX */
  478. #ifdef CONFIG_FB_ATY_CT
  479. static char *aty_ct_ram[8] __devinitdata = {
  480. ram_off, ram_dram, ram_edo, ram_edo,
  481. ram_sdram, ram_sgram, ram_sdram32, ram_resv
  482. };
  483. #endif /* CONFIG_FB_ATY_CT */
  484. static u32 atyfb_get_pixclock(struct fb_var_screeninfo *var, struct atyfb_par *par)
  485. {
  486. u32 pixclock = var->pixclock;
  487. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  488. u32 lcd_on_off;
  489. par->pll.ct.xres = 0;
  490. if (par->lcd_table != 0) {
  491. lcd_on_off = aty_ld_lcd(LCD_GEN_CNTL, par);
  492. if(lcd_on_off & LCD_ON) {
  493. par->pll.ct.xres = var->xres;
  494. pixclock = par->lcd_pixclock;
  495. }
  496. }
  497. #endif
  498. return pixclock;
  499. }
  500. #if defined(CONFIG_PPC)
  501. /*
  502. * Apple monitor sense
  503. */
  504. static int __devinit read_aty_sense(const struct atyfb_par *par)
  505. {
  506. int sense, i;
  507. aty_st_le32(GP_IO, 0x31003100, par); /* drive outputs high */
  508. __delay(200);
  509. aty_st_le32(GP_IO, 0, par); /* turn off outputs */
  510. __delay(2000);
  511. i = aty_ld_le32(GP_IO, par); /* get primary sense value */
  512. sense = ((i & 0x3000) >> 3) | (i & 0x100);
  513. /* drive each sense line low in turn and collect the other 2 */
  514. aty_st_le32(GP_IO, 0x20000000, par); /* drive A low */
  515. __delay(2000);
  516. i = aty_ld_le32(GP_IO, par);
  517. sense |= ((i & 0x1000) >> 7) | ((i & 0x100) >> 4);
  518. aty_st_le32(GP_IO, 0x20002000, par); /* drive A high again */
  519. __delay(200);
  520. aty_st_le32(GP_IO, 0x10000000, par); /* drive B low */
  521. __delay(2000);
  522. i = aty_ld_le32(GP_IO, par);
  523. sense |= ((i & 0x2000) >> 10) | ((i & 0x100) >> 6);
  524. aty_st_le32(GP_IO, 0x10001000, par); /* drive B high again */
  525. __delay(200);
  526. aty_st_le32(GP_IO, 0x01000000, par); /* drive C low */
  527. __delay(2000);
  528. sense |= (aty_ld_le32(GP_IO, par) & 0x3000) >> 12;
  529. aty_st_le32(GP_IO, 0, par); /* turn off outputs */
  530. return sense;
  531. }
  532. #endif /* defined(CONFIG_PPC) */
  533. /* ------------------------------------------------------------------------- */
  534. /*
  535. * CRTC programming
  536. */
  537. static void aty_get_crtc(const struct atyfb_par *par, struct crtc *crtc)
  538. {
  539. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  540. if (par->lcd_table != 0) {
  541. if(!M64_HAS(LT_LCD_REGS)) {
  542. crtc->lcd_index = aty_ld_le32(LCD_INDEX, par);
  543. aty_st_le32(LCD_INDEX, crtc->lcd_index, par);
  544. }
  545. crtc->lcd_config_panel = aty_ld_lcd(CONFIG_PANEL, par);
  546. crtc->lcd_gen_cntl = aty_ld_lcd(LCD_GEN_CNTL, par);
  547. /* switch to non shadow registers */
  548. aty_st_lcd(LCD_GEN_CNTL, crtc->lcd_gen_cntl &
  549. ~(CRTC_RW_SELECT | SHADOW_EN | SHADOW_RW_EN), par);
  550. /* save stretching */
  551. crtc->horz_stretching = aty_ld_lcd(HORZ_STRETCHING, par);
  552. crtc->vert_stretching = aty_ld_lcd(VERT_STRETCHING, par);
  553. if (!M64_HAS(LT_LCD_REGS))
  554. crtc->ext_vert_stretch = aty_ld_lcd(EXT_VERT_STRETCH, par);
  555. }
  556. #endif
  557. crtc->h_tot_disp = aty_ld_le32(CRTC_H_TOTAL_DISP, par);
  558. crtc->h_sync_strt_wid = aty_ld_le32(CRTC_H_SYNC_STRT_WID, par);
  559. crtc->v_tot_disp = aty_ld_le32(CRTC_V_TOTAL_DISP, par);
  560. crtc->v_sync_strt_wid = aty_ld_le32(CRTC_V_SYNC_STRT_WID, par);
  561. crtc->vline_crnt_vline = aty_ld_le32(CRTC_VLINE_CRNT_VLINE, par);
  562. crtc->off_pitch = aty_ld_le32(CRTC_OFF_PITCH, par);
  563. crtc->gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par);
  564. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  565. if (par->lcd_table != 0) {
  566. /* switch to shadow registers */
  567. aty_st_lcd(LCD_GEN_CNTL, (crtc->lcd_gen_cntl & ~CRTC_RW_SELECT) |
  568. SHADOW_EN | SHADOW_RW_EN, par);
  569. crtc->shadow_h_tot_disp = aty_ld_le32(CRTC_H_TOTAL_DISP, par);
  570. crtc->shadow_h_sync_strt_wid = aty_ld_le32(CRTC_H_SYNC_STRT_WID, par);
  571. crtc->shadow_v_tot_disp = aty_ld_le32(CRTC_V_TOTAL_DISP, par);
  572. crtc->shadow_v_sync_strt_wid = aty_ld_le32(CRTC_V_SYNC_STRT_WID, par);
  573. aty_st_le32(LCD_GEN_CNTL, crtc->lcd_gen_cntl, par);
  574. }
  575. #endif /* CONFIG_FB_ATY_GENERIC_LCD */
  576. }
  577. static void aty_set_crtc(const struct atyfb_par *par, const struct crtc *crtc)
  578. {
  579. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  580. if (par->lcd_table != 0) {
  581. /* stop CRTC */
  582. aty_st_le32(CRTC_GEN_CNTL, crtc->gen_cntl & ~(CRTC_EXT_DISP_EN | CRTC_EN), par);
  583. /* update non-shadow registers first */
  584. aty_st_lcd(CONFIG_PANEL, crtc->lcd_config_panel, par);
  585. aty_st_lcd(LCD_GEN_CNTL, crtc->lcd_gen_cntl &
  586. ~(CRTC_RW_SELECT | SHADOW_EN | SHADOW_RW_EN), par);
  587. /* temporarily disable stretching */
  588. aty_st_lcd(HORZ_STRETCHING,
  589. crtc->horz_stretching &
  590. ~(HORZ_STRETCH_MODE | HORZ_STRETCH_EN), par);
  591. aty_st_lcd(VERT_STRETCHING,
  592. crtc->vert_stretching &
  593. ~(VERT_STRETCH_RATIO1 | VERT_STRETCH_RATIO2 |
  594. VERT_STRETCH_USE0 | VERT_STRETCH_EN), par);
  595. }
  596. #endif
  597. /* turn off CRT */
  598. aty_st_le32(CRTC_GEN_CNTL, crtc->gen_cntl & ~CRTC_EN, par);
  599. DPRINTK("setting up CRTC\n");
  600. DPRINTK("set primary CRT to %ix%i %c%c composite %c\n",
  601. ((((crtc->h_tot_disp>>16) & 0xff) + 1)<<3), (((crtc->v_tot_disp>>16) & 0x7ff) + 1),
  602. (crtc->h_sync_strt_wid & 0x200000)?'N':'P', (crtc->v_sync_strt_wid & 0x200000)?'N':'P',
  603. (crtc->gen_cntl & CRTC_CSYNC_EN)?'P':'N');
  604. DPRINTK("CRTC_H_TOTAL_DISP: %x\n",crtc->h_tot_disp);
  605. DPRINTK("CRTC_H_SYNC_STRT_WID: %x\n",crtc->h_sync_strt_wid);
  606. DPRINTK("CRTC_V_TOTAL_DISP: %x\n",crtc->v_tot_disp);
  607. DPRINTK("CRTC_V_SYNC_STRT_WID: %x\n",crtc->v_sync_strt_wid);
  608. DPRINTK("CRTC_OFF_PITCH: %x\n", crtc->off_pitch);
  609. DPRINTK("CRTC_VLINE_CRNT_VLINE: %x\n", crtc->vline_crnt_vline);
  610. DPRINTK("CRTC_GEN_CNTL: %x\n",crtc->gen_cntl);
  611. aty_st_le32(CRTC_H_TOTAL_DISP, crtc->h_tot_disp, par);
  612. aty_st_le32(CRTC_H_SYNC_STRT_WID, crtc->h_sync_strt_wid, par);
  613. aty_st_le32(CRTC_V_TOTAL_DISP, crtc->v_tot_disp, par);
  614. aty_st_le32(CRTC_V_SYNC_STRT_WID, crtc->v_sync_strt_wid, par);
  615. aty_st_le32(CRTC_OFF_PITCH, crtc->off_pitch, par);
  616. aty_st_le32(CRTC_VLINE_CRNT_VLINE, crtc->vline_crnt_vline, par);
  617. aty_st_le32(CRTC_GEN_CNTL, crtc->gen_cntl, par);
  618. #if 0
  619. FIXME
  620. if (par->accel_flags & FB_ACCELF_TEXT)
  621. aty_init_engine(par, info);
  622. #endif
  623. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  624. /* after setting the CRTC registers we should set the LCD registers. */
  625. if (par->lcd_table != 0) {
  626. /* switch to shadow registers */
  627. aty_st_lcd(LCD_GEN_CNTL, (crtc->lcd_gen_cntl & ~CRTC_RW_SELECT) |
  628. (SHADOW_EN | SHADOW_RW_EN), par);
  629. DPRINTK("set shadow CRT to %ix%i %c%c\n",
  630. ((((crtc->shadow_h_tot_disp>>16) & 0xff) + 1)<<3), (((crtc->shadow_v_tot_disp>>16) & 0x7ff) + 1),
  631. (crtc->shadow_h_sync_strt_wid & 0x200000)?'N':'P', (crtc->shadow_v_sync_strt_wid & 0x200000)?'N':'P');
  632. DPRINTK("SHADOW CRTC_H_TOTAL_DISP: %x\n", crtc->shadow_h_tot_disp);
  633. DPRINTK("SHADOW CRTC_H_SYNC_STRT_WID: %x\n", crtc->shadow_h_sync_strt_wid);
  634. DPRINTK("SHADOW CRTC_V_TOTAL_DISP: %x\n", crtc->shadow_v_tot_disp);
  635. DPRINTK("SHADOW CRTC_V_SYNC_STRT_WID: %x\n", crtc->shadow_v_sync_strt_wid);
  636. aty_st_le32(CRTC_H_TOTAL_DISP, crtc->shadow_h_tot_disp, par);
  637. aty_st_le32(CRTC_H_SYNC_STRT_WID, crtc->shadow_h_sync_strt_wid, par);
  638. aty_st_le32(CRTC_V_TOTAL_DISP, crtc->shadow_v_tot_disp, par);
  639. aty_st_le32(CRTC_V_SYNC_STRT_WID, crtc->shadow_v_sync_strt_wid, par);
  640. /* restore CRTC selection & shadow state and enable stretching */
  641. DPRINTK("LCD_GEN_CNTL: %x\n", crtc->lcd_gen_cntl);
  642. DPRINTK("HORZ_STRETCHING: %x\n", crtc->horz_stretching);
  643. DPRINTK("VERT_STRETCHING: %x\n", crtc->vert_stretching);
  644. if(!M64_HAS(LT_LCD_REGS))
  645. DPRINTK("EXT_VERT_STRETCH: %x\n", crtc->ext_vert_stretch);
  646. aty_st_lcd(LCD_GEN_CNTL, crtc->lcd_gen_cntl, par);
  647. aty_st_lcd(HORZ_STRETCHING, crtc->horz_stretching, par);
  648. aty_st_lcd(VERT_STRETCHING, crtc->vert_stretching, par);
  649. if(!M64_HAS(LT_LCD_REGS)) {
  650. aty_st_lcd(EXT_VERT_STRETCH, crtc->ext_vert_stretch, par);
  651. aty_ld_le32(LCD_INDEX, par);
  652. aty_st_le32(LCD_INDEX, crtc->lcd_index, par);
  653. }
  654. }
  655. #endif /* CONFIG_FB_ATY_GENERIC_LCD */
  656. }
  657. static int aty_var_to_crtc(const struct fb_info *info,
  658. const struct fb_var_screeninfo *var, struct crtc *crtc)
  659. {
  660. struct atyfb_par *par = (struct atyfb_par *) info->par;
  661. u32 xres, yres, vxres, vyres, xoffset, yoffset, bpp;
  662. u32 sync, vmode, vdisplay;
  663. u32 h_total, h_disp, h_sync_strt, h_sync_end, h_sync_dly, h_sync_wid, h_sync_pol;
  664. u32 v_total, v_disp, v_sync_strt, v_sync_end, v_sync_wid, v_sync_pol, c_sync;
  665. u32 pix_width, dp_pix_width, dp_chain_mask;
  666. /* input */
  667. xres = var->xres;
  668. yres = var->yres;
  669. vxres = var->xres_virtual;
  670. vyres = var->yres_virtual;
  671. xoffset = var->xoffset;
  672. yoffset = var->yoffset;
  673. bpp = var->bits_per_pixel;
  674. if (bpp == 16)
  675. bpp = (var->green.length == 5) ? 15 : 16;
  676. sync = var->sync;
  677. vmode = var->vmode;
  678. /* convert (and round up) and validate */
  679. if (vxres < xres + xoffset)
  680. vxres = xres + xoffset;
  681. h_disp = xres;
  682. if (vyres < yres + yoffset)
  683. vyres = yres + yoffset;
  684. v_disp = yres;
  685. if (bpp <= 8) {
  686. bpp = 8;
  687. pix_width = CRTC_PIX_WIDTH_8BPP;
  688. dp_pix_width =
  689. HOST_8BPP | SRC_8BPP | DST_8BPP |
  690. BYTE_ORDER_LSB_TO_MSB;
  691. dp_chain_mask = DP_CHAIN_8BPP;
  692. } else if (bpp <= 15) {
  693. bpp = 16;
  694. pix_width = CRTC_PIX_WIDTH_15BPP;
  695. dp_pix_width = HOST_15BPP | SRC_15BPP | DST_15BPP |
  696. BYTE_ORDER_LSB_TO_MSB;
  697. dp_chain_mask = DP_CHAIN_15BPP;
  698. } else if (bpp <= 16) {
  699. bpp = 16;
  700. pix_width = CRTC_PIX_WIDTH_16BPP;
  701. dp_pix_width = HOST_16BPP | SRC_16BPP | DST_16BPP |
  702. BYTE_ORDER_LSB_TO_MSB;
  703. dp_chain_mask = DP_CHAIN_16BPP;
  704. } else if (bpp <= 24 && M64_HAS(INTEGRATED)) {
  705. bpp = 24;
  706. pix_width = CRTC_PIX_WIDTH_24BPP;
  707. dp_pix_width =
  708. HOST_8BPP | SRC_8BPP | DST_8BPP |
  709. BYTE_ORDER_LSB_TO_MSB;
  710. dp_chain_mask = DP_CHAIN_24BPP;
  711. } else if (bpp <= 32) {
  712. bpp = 32;
  713. pix_width = CRTC_PIX_WIDTH_32BPP;
  714. dp_pix_width = HOST_32BPP | SRC_32BPP | DST_32BPP |
  715. BYTE_ORDER_LSB_TO_MSB;
  716. dp_chain_mask = DP_CHAIN_32BPP;
  717. } else
  718. FAIL("invalid bpp");
  719. if (vxres * vyres * bpp / 8 > info->fix.smem_len)
  720. FAIL("not enough video RAM");
  721. h_sync_pol = sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
  722. v_sync_pol = sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
  723. if((xres > 1600) || (yres > 1200)) {
  724. FAIL("MACH64 chips are designed for max 1600x1200\n"
  725. "select anoter resolution.");
  726. }
  727. h_sync_strt = h_disp + var->right_margin;
  728. h_sync_end = h_sync_strt + var->hsync_len;
  729. h_sync_dly = var->right_margin & 7;
  730. h_total = h_sync_end + h_sync_dly + var->left_margin;
  731. v_sync_strt = v_disp + var->lower_margin;
  732. v_sync_end = v_sync_strt + var->vsync_len;
  733. v_total = v_sync_end + var->upper_margin;
  734. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  735. if (par->lcd_table != 0) {
  736. if(!M64_HAS(LT_LCD_REGS)) {
  737. u32 lcd_index = aty_ld_le32(LCD_INDEX, par);
  738. crtc->lcd_index = lcd_index &
  739. ~(LCD_INDEX_MASK | LCD_DISPLAY_DIS | LCD_SRC_SEL | CRTC2_DISPLAY_DIS);
  740. aty_st_le32(LCD_INDEX, lcd_index, par);
  741. }
  742. if (!M64_HAS(MOBIL_BUS))
  743. crtc->lcd_index |= CRTC2_DISPLAY_DIS;
  744. crtc->lcd_config_panel = aty_ld_lcd(CONFIG_PANEL, par) | 0x4000;
  745. crtc->lcd_gen_cntl = aty_ld_lcd(LCD_GEN_CNTL, par) & ~CRTC_RW_SELECT;
  746. crtc->lcd_gen_cntl &=
  747. ~(HORZ_DIVBY2_EN | DIS_HOR_CRT_DIVBY2 | TVCLK_PM_EN |
  748. /*VCLK_DAC_PM_EN | USE_SHADOWED_VEND |*/
  749. USE_SHADOWED_ROWCUR | SHADOW_EN | SHADOW_RW_EN);
  750. crtc->lcd_gen_cntl |= DONT_SHADOW_VPAR | LOCK_8DOT;
  751. if((crtc->lcd_gen_cntl & LCD_ON) &&
  752. ((xres > par->lcd_width) || (yres > par->lcd_height))) {
  753. /* We cannot display the mode on the LCD. If the CRT is enabled
  754. we can turn off the LCD.
  755. If the CRT is off, it isn't a good idea to switch it on; we don't
  756. know if one is connected. So it's better to fail then.
  757. */
  758. if (crtc->lcd_gen_cntl & CRT_ON) {
  759. if (!(var->activate & FB_ACTIVATE_TEST))
  760. PRINTKI("Disable LCD panel, because video mode does not fit.\n");
  761. crtc->lcd_gen_cntl &= ~LCD_ON;
  762. /*aty_st_lcd(LCD_GEN_CNTL, crtc->lcd_gen_cntl, par);*/
  763. } else {
  764. if (!(var->activate & FB_ACTIVATE_TEST))
  765. PRINTKE("Video mode exceeds size of LCD panel.\nConnect this computer to a conventional monitor if you really need this mode.\n");
  766. return -EINVAL;
  767. }
  768. }
  769. }
  770. if ((par->lcd_table != 0) && (crtc->lcd_gen_cntl & LCD_ON)) {
  771. int VScan = 1;
  772. /* bpp -> bytespp, 1,4 -> 0; 8 -> 2; 15,16 -> 1; 24 -> 6; 32 -> 5
  773. const u8 DFP_h_sync_dly_LT[] = { 0, 2, 1, 6, 5 };
  774. const u8 ADD_to_strt_wid_and_dly_LT_DAC[] = { 0, 5, 6, 9, 9, 12, 12 }; */
  775. vmode &= ~(FB_VMODE_DOUBLE | FB_VMODE_INTERLACED);
  776. /* This is horror! When we simulate, say 640x480 on an 800x600
  777. LCD monitor, the CRTC should be programmed 800x600 values for
  778. the non visible part, but 640x480 for the visible part.
  779. This code has been tested on a laptop with it's 1400x1050 LCD
  780. monitor and a conventional monitor both switched on.
  781. Tested modes: 1280x1024, 1152x864, 1024x768, 800x600,
  782. works with little glitches also with DOUBLESCAN modes
  783. */
  784. if (yres < par->lcd_height) {
  785. VScan = par->lcd_height / yres;
  786. if(VScan > 1) {
  787. VScan = 2;
  788. vmode |= FB_VMODE_DOUBLE;
  789. }
  790. }
  791. h_sync_strt = h_disp + par->lcd_right_margin;
  792. h_sync_end = h_sync_strt + par->lcd_hsync_len;
  793. h_sync_dly = /*DFP_h_sync_dly[ ( bpp + 1 ) / 3 ]; */par->lcd_hsync_dly;
  794. h_total = h_disp + par->lcd_hblank_len;
  795. v_sync_strt = v_disp + par->lcd_lower_margin / VScan;
  796. v_sync_end = v_sync_strt + par->lcd_vsync_len / VScan;
  797. v_total = v_disp + par->lcd_vblank_len / VScan;
  798. }
  799. #endif /* CONFIG_FB_ATY_GENERIC_LCD */
  800. h_disp = (h_disp >> 3) - 1;
  801. h_sync_strt = (h_sync_strt >> 3) - 1;
  802. h_sync_end = (h_sync_end >> 3) - 1;
  803. h_total = (h_total >> 3) - 1;
  804. h_sync_wid = h_sync_end - h_sync_strt;
  805. FAIL_MAX("h_disp too large", h_disp, 0xff);
  806. FAIL_MAX("h_sync_strt too large", h_sync_strt, 0x1ff);
  807. /*FAIL_MAX("h_sync_wid too large", h_sync_wid, 0x1f);*/
  808. if(h_sync_wid > 0x1f)
  809. h_sync_wid = 0x1f;
  810. FAIL_MAX("h_total too large", h_total, 0x1ff);
  811. if (vmode & FB_VMODE_DOUBLE) {
  812. v_disp <<= 1;
  813. v_sync_strt <<= 1;
  814. v_sync_end <<= 1;
  815. v_total <<= 1;
  816. }
  817. vdisplay = yres;
  818. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  819. if ((par->lcd_table != 0) && (crtc->lcd_gen_cntl & LCD_ON))
  820. vdisplay = par->lcd_height;
  821. #endif
  822. v_disp--;
  823. v_sync_strt--;
  824. v_sync_end--;
  825. v_total--;
  826. v_sync_wid = v_sync_end - v_sync_strt;
  827. FAIL_MAX("v_disp too large", v_disp, 0x7ff);
  828. FAIL_MAX("v_sync_stsrt too large", v_sync_strt, 0x7ff);
  829. /*FAIL_MAX("v_sync_wid too large", v_sync_wid, 0x1f);*/
  830. if(v_sync_wid > 0x1f)
  831. v_sync_wid = 0x1f;
  832. FAIL_MAX("v_total too large", v_total, 0x7ff);
  833. c_sync = sync & FB_SYNC_COMP_HIGH_ACT ? CRTC_CSYNC_EN : 0;
  834. /* output */
  835. crtc->vxres = vxres;
  836. crtc->vyres = vyres;
  837. crtc->xoffset = xoffset;
  838. crtc->yoffset = yoffset;
  839. crtc->bpp = bpp;
  840. crtc->off_pitch = ((yoffset*vxres+xoffset)*bpp/64) | (vxres<<19);
  841. crtc->vline_crnt_vline = 0;
  842. crtc->h_tot_disp = h_total | (h_disp<<16);
  843. crtc->h_sync_strt_wid = (h_sync_strt & 0xff) | (h_sync_dly<<8) |
  844. ((h_sync_strt & 0x100)<<4) | (h_sync_wid<<16) | (h_sync_pol<<21);
  845. crtc->v_tot_disp = v_total | (v_disp<<16);
  846. crtc->v_sync_strt_wid = v_sync_strt | (v_sync_wid<<16) | (v_sync_pol<<21);
  847. /* crtc->gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par) & CRTC_PRESERVED_MASK; */
  848. crtc->gen_cntl = CRTC_EXT_DISP_EN | CRTC_EN | pix_width | c_sync;
  849. crtc->gen_cntl |= CRTC_VGA_LINEAR;
  850. /* Enable doublescan mode if requested */
  851. if (vmode & FB_VMODE_DOUBLE)
  852. crtc->gen_cntl |= CRTC_DBL_SCAN_EN;
  853. /* Enable interlaced mode if requested */
  854. if (vmode & FB_VMODE_INTERLACED)
  855. crtc->gen_cntl |= CRTC_INTERLACE_EN;
  856. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  857. if (par->lcd_table != 0) {
  858. vdisplay = yres;
  859. if(vmode & FB_VMODE_DOUBLE)
  860. vdisplay <<= 1;
  861. crtc->gen_cntl &= ~(CRTC2_EN | CRTC2_PIX_WIDTH);
  862. crtc->lcd_gen_cntl &= ~(HORZ_DIVBY2_EN | DIS_HOR_CRT_DIVBY2 |
  863. /*TVCLK_PM_EN | VCLK_DAC_PM_EN |*/
  864. USE_SHADOWED_VEND | USE_SHADOWED_ROWCUR | SHADOW_EN | SHADOW_RW_EN);
  865. crtc->lcd_gen_cntl |= (DONT_SHADOW_VPAR/* | LOCK_8DOT*/);
  866. /* MOBILITY M1 tested, FIXME: LT */
  867. crtc->horz_stretching = aty_ld_lcd(HORZ_STRETCHING, par);
  868. if (!M64_HAS(LT_LCD_REGS))
  869. crtc->ext_vert_stretch = aty_ld_lcd(EXT_VERT_STRETCH, par) &
  870. ~(AUTO_VERT_RATIO | VERT_STRETCH_MODE | VERT_STRETCH_RATIO3);
  871. crtc->horz_stretching &=
  872. ~(HORZ_STRETCH_RATIO | HORZ_STRETCH_LOOP | AUTO_HORZ_RATIO |
  873. HORZ_STRETCH_MODE | HORZ_STRETCH_EN);
  874. if (xres < par->lcd_width && crtc->lcd_gen_cntl & LCD_ON) {
  875. do {
  876. /*
  877. * The horizontal blender misbehaves when HDisplay is less than a
  878. * a certain threshold (440 for a 1024-wide panel). It doesn't
  879. * stretch such modes enough. Use pixel replication instead of
  880. * blending to stretch modes that can be made to exactly fit the
  881. * panel width. The undocumented "NoLCDBlend" option allows the
  882. * pixel-replicated mode to be slightly wider or narrower than the
  883. * panel width. It also causes a mode that is exactly half as wide
  884. * as the panel to be pixel-replicated, rather than blended.
  885. */
  886. int HDisplay = xres & ~7;
  887. int nStretch = par->lcd_width / HDisplay;
  888. int Remainder = par->lcd_width % HDisplay;
  889. if ((!Remainder && ((nStretch > 2))) ||
  890. (((HDisplay * 16) / par->lcd_width) < 7)) {
  891. static const char StretchLoops[] = {10, 12, 13, 15, 16};
  892. int horz_stretch_loop = -1, BestRemainder;
  893. int Numerator = HDisplay, Denominator = par->lcd_width;
  894. int Index = 5;
  895. ATIReduceRatio(&Numerator, &Denominator);
  896. BestRemainder = (Numerator * 16) / Denominator;
  897. while (--Index >= 0) {
  898. Remainder = ((Denominator - Numerator) * StretchLoops[Index]) %
  899. Denominator;
  900. if (Remainder < BestRemainder) {
  901. horz_stretch_loop = Index;
  902. if (!(BestRemainder = Remainder))
  903. break;
  904. }
  905. }
  906. if ((horz_stretch_loop >= 0) && !BestRemainder) {
  907. int horz_stretch_ratio = 0, Accumulator = 0;
  908. int reuse_previous = 1;
  909. Index = StretchLoops[horz_stretch_loop];
  910. while (--Index >= 0) {
  911. if (Accumulator > 0)
  912. horz_stretch_ratio |= reuse_previous;
  913. else
  914. Accumulator += Denominator;
  915. Accumulator -= Numerator;
  916. reuse_previous <<= 1;
  917. }
  918. crtc->horz_stretching |= (HORZ_STRETCH_EN |
  919. ((horz_stretch_loop & HORZ_STRETCH_LOOP) << 16) |
  920. (horz_stretch_ratio & HORZ_STRETCH_RATIO));
  921. break; /* Out of the do { ... } while (0) */
  922. }
  923. }
  924. crtc->horz_stretching |= (HORZ_STRETCH_MODE | HORZ_STRETCH_EN |
  925. (((HDisplay * (HORZ_STRETCH_BLEND + 1)) / par->lcd_width) & HORZ_STRETCH_BLEND));
  926. } while (0);
  927. }
  928. if (vdisplay < par->lcd_height && crtc->lcd_gen_cntl & LCD_ON) {
  929. crtc->vert_stretching = (VERT_STRETCH_USE0 | VERT_STRETCH_EN |
  930. (((vdisplay * (VERT_STRETCH_RATIO0 + 1)) / par->lcd_height) & VERT_STRETCH_RATIO0));
  931. if (!M64_HAS(LT_LCD_REGS) &&
  932. xres <= (M64_HAS(MOBIL_BUS)?1024:800))
  933. crtc->ext_vert_stretch |= VERT_STRETCH_MODE;
  934. } else {
  935. /*
  936. * Don't use vertical blending if the mode is too wide or not
  937. * vertically stretched.
  938. */
  939. crtc->vert_stretching = 0;
  940. }
  941. /* copy to shadow crtc */
  942. crtc->shadow_h_tot_disp = crtc->h_tot_disp;
  943. crtc->shadow_h_sync_strt_wid = crtc->h_sync_strt_wid;
  944. crtc->shadow_v_tot_disp = crtc->v_tot_disp;
  945. crtc->shadow_v_sync_strt_wid = crtc->v_sync_strt_wid;
  946. }
  947. #endif /* CONFIG_FB_ATY_GENERIC_LCD */
  948. if (M64_HAS(MAGIC_FIFO)) {
  949. /* FIXME: display FIFO low watermark values */
  950. crtc->gen_cntl |= (aty_ld_le32(CRTC_GEN_CNTL, par) & CRTC_FIFO_LWM);
  951. }
  952. crtc->dp_pix_width = dp_pix_width;
  953. crtc->dp_chain_mask = dp_chain_mask;
  954. return 0;
  955. }
  956. static int aty_crtc_to_var(const struct crtc *crtc, struct fb_var_screeninfo *var)
  957. {
  958. u32 xres, yres, bpp, left, right, upper, lower, hslen, vslen, sync;
  959. u32 h_total, h_disp, h_sync_strt, h_sync_dly, h_sync_wid,
  960. h_sync_pol;
  961. u32 v_total, v_disp, v_sync_strt, v_sync_wid, v_sync_pol, c_sync;
  962. u32 pix_width;
  963. u32 double_scan, interlace;
  964. /* input */
  965. h_total = crtc->h_tot_disp & 0x1ff;
  966. h_disp = (crtc->h_tot_disp >> 16) & 0xff;
  967. h_sync_strt = (crtc->h_sync_strt_wid & 0xff) | ((crtc->h_sync_strt_wid >> 4) & 0x100);
  968. h_sync_dly = (crtc->h_sync_strt_wid >> 8) & 0x7;
  969. h_sync_wid = (crtc->h_sync_strt_wid >> 16) & 0x1f;
  970. h_sync_pol = (crtc->h_sync_strt_wid >> 21) & 0x1;
  971. v_total = crtc->v_tot_disp & 0x7ff;
  972. v_disp = (crtc->v_tot_disp >> 16) & 0x7ff;
  973. v_sync_strt = crtc->v_sync_strt_wid & 0x7ff;
  974. v_sync_wid = (crtc->v_sync_strt_wid >> 16) & 0x1f;
  975. v_sync_pol = (crtc->v_sync_strt_wid >> 21) & 0x1;
  976. c_sync = crtc->gen_cntl & CRTC_CSYNC_EN ? 1 : 0;
  977. pix_width = crtc->gen_cntl & CRTC_PIX_WIDTH_MASK;
  978. double_scan = crtc->gen_cntl & CRTC_DBL_SCAN_EN;
  979. interlace = crtc->gen_cntl & CRTC_INTERLACE_EN;
  980. /* convert */
  981. xres = (h_disp + 1) * 8;
  982. yres = v_disp + 1;
  983. left = (h_total - h_sync_strt - h_sync_wid) * 8 - h_sync_dly;
  984. right = (h_sync_strt - h_disp) * 8 + h_sync_dly;
  985. hslen = h_sync_wid * 8;
  986. upper = v_total - v_sync_strt - v_sync_wid;
  987. lower = v_sync_strt - v_disp;
  988. vslen = v_sync_wid;
  989. sync = (h_sync_pol ? 0 : FB_SYNC_HOR_HIGH_ACT) |
  990. (v_sync_pol ? 0 : FB_SYNC_VERT_HIGH_ACT) |
  991. (c_sync ? FB_SYNC_COMP_HIGH_ACT : 0);
  992. switch (pix_width) {
  993. #if 0
  994. case CRTC_PIX_WIDTH_4BPP:
  995. bpp = 4;
  996. var->red.offset = 0;
  997. var->red.length = 8;
  998. var->green.offset = 0;
  999. var->green.length = 8;
  1000. var->blue.offset = 0;
  1001. var->blue.length = 8;
  1002. var->transp.offset = 0;
  1003. var->transp.length = 0;
  1004. break;
  1005. #endif
  1006. case CRTC_PIX_WIDTH_8BPP:
  1007. bpp = 8;
  1008. var->red.offset = 0;
  1009. var->red.length = 8;
  1010. var->green.offset = 0;
  1011. var->green.length = 8;
  1012. var->blue.offset = 0;
  1013. var->blue.length = 8;
  1014. var->transp.offset = 0;
  1015. var->transp.length = 0;
  1016. break;
  1017. case CRTC_PIX_WIDTH_15BPP: /* RGB 555 */
  1018. bpp = 16;
  1019. var->red.offset = 10;
  1020. var->red.length = 5;
  1021. var->green.offset = 5;
  1022. var->green.length = 5;
  1023. var->blue.offset = 0;
  1024. var->blue.length = 5;
  1025. var->transp.offset = 0;
  1026. var->transp.length = 0;
  1027. break;
  1028. case CRTC_PIX_WIDTH_16BPP: /* RGB 565 */
  1029. bpp = 16;
  1030. var->red.offset = 11;
  1031. var->red.length = 5;
  1032. var->green.offset = 5;
  1033. var->green.length = 6;
  1034. var->blue.offset = 0;
  1035. var->blue.length = 5;
  1036. var->transp.offset = 0;
  1037. var->transp.length = 0;
  1038. break;
  1039. case CRTC_PIX_WIDTH_24BPP: /* RGB 888 */
  1040. bpp = 24;
  1041. var->red.offset = 16;
  1042. var->red.length = 8;
  1043. var->green.offset = 8;
  1044. var->green.length = 8;
  1045. var->blue.offset = 0;
  1046. var->blue.length = 8;
  1047. var->transp.offset = 0;
  1048. var->transp.length = 0;
  1049. break;
  1050. case CRTC_PIX_WIDTH_32BPP: /* ARGB 8888 */
  1051. bpp = 32;
  1052. var->red.offset = 16;
  1053. var->red.length = 8;
  1054. var->green.offset = 8;
  1055. var->green.length = 8;
  1056. var->blue.offset = 0;
  1057. var->blue.length = 8;
  1058. var->transp.offset = 24;
  1059. var->transp.length = 8;
  1060. break;
  1061. default:
  1062. PRINTKE("Invalid pixel width\n");
  1063. return -EINVAL;
  1064. }
  1065. /* output */
  1066. var->xres = xres;
  1067. var->yres = yres;
  1068. var->xres_virtual = crtc->vxres;
  1069. var->yres_virtual = crtc->vyres;
  1070. var->bits_per_pixel = bpp;
  1071. var->left_margin = left;
  1072. var->right_margin = right;
  1073. var->upper_margin = upper;
  1074. var->lower_margin = lower;
  1075. var->hsync_len = hslen;
  1076. var->vsync_len = vslen;
  1077. var->sync = sync;
  1078. var->vmode = FB_VMODE_NONINTERLACED;
  1079. /* In double scan mode, the vertical parameters are doubled, so we need to
  1080. half them to get the right values.
  1081. In interlaced mode the values are already correct, so no correction is
  1082. necessary.
  1083. */
  1084. if (interlace)
  1085. var->vmode = FB_VMODE_INTERLACED;
  1086. if (double_scan) {
  1087. var->vmode = FB_VMODE_DOUBLE;
  1088. var->yres>>=1;
  1089. var->upper_margin>>=1;
  1090. var->lower_margin>>=1;
  1091. var->vsync_len>>=1;
  1092. }
  1093. return 0;
  1094. }
  1095. /* ------------------------------------------------------------------------- */
  1096. static int atyfb_set_par(struct fb_info *info)
  1097. {
  1098. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1099. struct fb_var_screeninfo *var = &info->var;
  1100. u32 tmp, pixclock;
  1101. int err;
  1102. #ifdef DEBUG
  1103. struct fb_var_screeninfo debug;
  1104. u32 pixclock_in_ps;
  1105. #endif
  1106. if (par->asleep)
  1107. return 0;
  1108. if ((err = aty_var_to_crtc(info, var, &par->crtc)))
  1109. return err;
  1110. pixclock = atyfb_get_pixclock(var, par);
  1111. if (pixclock == 0) {
  1112. PRINTKE("Invalid pixclock\n");
  1113. return -EINVAL;
  1114. } else {
  1115. if((err = par->pll_ops->var_to_pll(info, pixclock, var->bits_per_pixel, &par->pll)))
  1116. return err;
  1117. }
  1118. par->accel_flags = var->accel_flags; /* hack */
  1119. if (var->accel_flags) {
  1120. info->fbops->fb_sync = atyfb_sync;
  1121. info->flags &= ~FBINFO_HWACCEL_DISABLED;
  1122. } else {
  1123. info->fbops->fb_sync = NULL;
  1124. info->flags |= FBINFO_HWACCEL_DISABLED;
  1125. }
  1126. if (par->blitter_may_be_busy)
  1127. wait_for_idle(par);
  1128. aty_set_crtc(par, &par->crtc);
  1129. par->dac_ops->set_dac(info, &par->pll, var->bits_per_pixel, par->accel_flags);
  1130. par->pll_ops->set_pll(info, &par->pll);
  1131. #ifdef DEBUG
  1132. if(par->pll_ops && par->pll_ops->pll_to_var)
  1133. pixclock_in_ps = par->pll_ops->pll_to_var(info, &(par->pll));
  1134. else
  1135. pixclock_in_ps = 0;
  1136. if(0 == pixclock_in_ps) {
  1137. PRINTKE("ALERT ops->pll_to_var get 0\n");
  1138. pixclock_in_ps = pixclock;
  1139. }
  1140. memset(&debug, 0, sizeof(debug));
  1141. if(!aty_crtc_to_var(&(par->crtc), &debug)) {
  1142. u32 hSync, vRefresh;
  1143. u32 h_disp, h_sync_strt, h_sync_end, h_total;
  1144. u32 v_disp, v_sync_strt, v_sync_end, v_total;
  1145. h_disp = debug.xres;
  1146. h_sync_strt = h_disp + debug.right_margin;
  1147. h_sync_end = h_sync_strt + debug.hsync_len;
  1148. h_total = h_sync_end + debug.left_margin;
  1149. v_disp = debug.yres;
  1150. v_sync_strt = v_disp + debug.lower_margin;
  1151. v_sync_end = v_sync_strt + debug.vsync_len;
  1152. v_total = v_sync_end + debug.upper_margin;
  1153. hSync = 1000000000 / (pixclock_in_ps * h_total);
  1154. vRefresh = (hSync * 1000) / v_total;
  1155. if (par->crtc.gen_cntl & CRTC_INTERLACE_EN)
  1156. vRefresh *= 2;
  1157. if (par->crtc.gen_cntl & CRTC_DBL_SCAN_EN)
  1158. vRefresh /= 2;
  1159. DPRINTK("atyfb_set_par\n");
  1160. DPRINTK(" Set Visible Mode to %ix%i-%i\n", var->xres, var->yres, var->bits_per_pixel);
  1161. DPRINTK(" Virtual resolution %ix%i, pixclock_in_ps %i (calculated %i)\n",
  1162. var->xres_virtual, var->yres_virtual, pixclock, pixclock_in_ps);
  1163. DPRINTK(" Dot clock: %i MHz\n", 1000000 / pixclock_in_ps);
  1164. DPRINTK(" Horizontal sync: %i kHz\n", hSync);
  1165. DPRINTK(" Vertical refresh: %i Hz\n", vRefresh);
  1166. DPRINTK(" x style: %i.%03i %i %i %i %i %i %i %i %i\n",
  1167. 1000000 / pixclock_in_ps, 1000000 % pixclock_in_ps,
  1168. h_disp, h_sync_strt, h_sync_end, h_total,
  1169. v_disp, v_sync_strt, v_sync_end, v_total);
  1170. DPRINTK(" fb style: %i %i %i %i %i %i %i %i %i\n",
  1171. pixclock_in_ps,
  1172. debug.left_margin, h_disp, debug.right_margin, debug.hsync_len,
  1173. debug.upper_margin, v_disp, debug.lower_margin, debug.vsync_len);
  1174. }
  1175. #endif /* DEBUG */
  1176. if (!M64_HAS(INTEGRATED)) {
  1177. /* Don't forget MEM_CNTL */
  1178. tmp = aty_ld_le32(MEM_CNTL, par) & 0xf0ffffff;
  1179. switch (var->bits_per_pixel) {
  1180. case 8:
  1181. tmp |= 0x02000000;
  1182. break;
  1183. case 16:
  1184. tmp |= 0x03000000;
  1185. break;
  1186. case 32:
  1187. tmp |= 0x06000000;
  1188. break;
  1189. }
  1190. aty_st_le32(MEM_CNTL, tmp, par);
  1191. } else {
  1192. tmp = aty_ld_le32(MEM_CNTL, par) & 0xf00fffff;
  1193. if (!M64_HAS(MAGIC_POSTDIV))
  1194. tmp |= par->mem_refresh_rate << 20;
  1195. switch (var->bits_per_pixel) {
  1196. case 8:
  1197. case 24:
  1198. tmp |= 0x00000000;
  1199. break;
  1200. case 16:
  1201. tmp |= 0x04000000;
  1202. break;
  1203. case 32:
  1204. tmp |= 0x08000000;
  1205. break;
  1206. }
  1207. if (M64_HAS(CT_BUS)) {
  1208. aty_st_le32(DAC_CNTL, 0x87010184, par);
  1209. aty_st_le32(BUS_CNTL, 0x680000f9, par);
  1210. } else if (M64_HAS(VT_BUS)) {
  1211. aty_st_le32(DAC_CNTL, 0x87010184, par);
  1212. aty_st_le32(BUS_CNTL, 0x680000f9, par);
  1213. } else if (M64_HAS(MOBIL_BUS)) {
  1214. aty_st_le32(DAC_CNTL, 0x80010102, par);
  1215. aty_st_le32(BUS_CNTL, 0x7b33a040 | (par->aux_start ? BUS_APER_REG_DIS : 0), par);
  1216. } else {
  1217. /* GT */
  1218. aty_st_le32(DAC_CNTL, 0x86010102, par);
  1219. aty_st_le32(BUS_CNTL, 0x7b23a040 | (par->aux_start ? BUS_APER_REG_DIS : 0), par);
  1220. aty_st_le32(EXT_MEM_CNTL, aty_ld_le32(EXT_MEM_CNTL, par) | 0x5000001, par);
  1221. }
  1222. aty_st_le32(MEM_CNTL, tmp, par);
  1223. }
  1224. aty_st_8(DAC_MASK, 0xff, par);
  1225. info->fix.line_length = var->xres_virtual * var->bits_per_pixel/8;
  1226. info->fix.visual = var->bits_per_pixel <= 8 ?
  1227. FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
  1228. /* Initialize the graphics engine */
  1229. if (par->accel_flags & FB_ACCELF_TEXT)
  1230. aty_init_engine(par, info);
  1231. #ifdef CONFIG_BOOTX_TEXT
  1232. btext_update_display(info->fix.smem_start,
  1233. (((par->crtc.h_tot_disp >> 16) & 0xff) + 1) * 8,
  1234. ((par->crtc.v_tot_disp >> 16) & 0x7ff) + 1,
  1235. var->bits_per_pixel,
  1236. par->crtc.vxres * var->bits_per_pixel / 8);
  1237. #endif /* CONFIG_BOOTX_TEXT */
  1238. #if 0
  1239. /* switch to accelerator mode */
  1240. if (!(par->crtc.gen_cntl & CRTC_EXT_DISP_EN))
  1241. aty_st_le32(CRTC_GEN_CNTL, par->crtc.gen_cntl | CRTC_EXT_DISP_EN, par);
  1242. #endif
  1243. #ifdef DEBUG
  1244. {
  1245. /* dump non shadow CRTC, pll, LCD registers */
  1246. int i; u32 base;
  1247. /* CRTC registers */
  1248. base = 0x2000;
  1249. printk("debug atyfb: Mach64 non-shadow register values:");
  1250. for (i = 0; i < 256; i = i+4) {
  1251. if(i%16 == 0) printk("\ndebug atyfb: 0x%04X: ", base + i);
  1252. printk(" %08X", aty_ld_le32(i, par));
  1253. }
  1254. printk("\n\n");
  1255. #ifdef CONFIG_FB_ATY_CT
  1256. /* PLL registers */
  1257. base = 0x00;
  1258. printk("debug atyfb: Mach64 PLL register values:");
  1259. for (i = 0; i < 64; i++) {
  1260. if(i%16 == 0) printk("\ndebug atyfb: 0x%02X: ", base + i);
  1261. if(i%4 == 0) printk(" ");
  1262. printk("%02X", aty_ld_pll_ct(i, par));
  1263. }
  1264. printk("\n\n");
  1265. #endif /* CONFIG_FB_ATY_CT */
  1266. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  1267. if (par->lcd_table != 0) {
  1268. /* LCD registers */
  1269. base = 0x00;
  1270. printk("debug atyfb: LCD register values:");
  1271. if(M64_HAS(LT_LCD_REGS)) {
  1272. for(i = 0; i <= POWER_MANAGEMENT; i++) {
  1273. if(i == EXT_VERT_STRETCH)
  1274. continue;
  1275. printk("\ndebug atyfb: 0x%04X: ", lt_lcd_regs[i]);
  1276. printk(" %08X", aty_ld_lcd(i, par));
  1277. }
  1278. } else {
  1279. for (i = 0; i < 64; i++) {
  1280. if(i%4 == 0) printk("\ndebug atyfb: 0x%02X: ", base + i);
  1281. printk(" %08X", aty_ld_lcd(i, par));
  1282. }
  1283. }
  1284. printk("\n\n");
  1285. }
  1286. #endif /* CONFIG_FB_ATY_GENERIC_LCD */
  1287. }
  1288. #endif /* DEBUG */
  1289. return 0;
  1290. }
  1291. static int atyfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  1292. {
  1293. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1294. int err;
  1295. struct crtc crtc;
  1296. union aty_pll pll;
  1297. u32 pixclock;
  1298. memcpy(&pll, &(par->pll), sizeof(pll));
  1299. if((err = aty_var_to_crtc(info, var, &crtc)))
  1300. return err;
  1301. pixclock = atyfb_get_pixclock(var, par);
  1302. if (pixclock == 0) {
  1303. if (!(var->activate & FB_ACTIVATE_TEST))
  1304. PRINTKE("Invalid pixclock\n");
  1305. return -EINVAL;
  1306. } else {
  1307. if((err = par->pll_ops->var_to_pll(info, pixclock, var->bits_per_pixel, &pll)))
  1308. return err;
  1309. }
  1310. if (var->accel_flags & FB_ACCELF_TEXT)
  1311. info->var.accel_flags = FB_ACCELF_TEXT;
  1312. else
  1313. info->var.accel_flags = 0;
  1314. #if 0 /* fbmon is not done. uncomment for 2.5.x -brad */
  1315. if (!fbmon_valid_timings(pixclock, htotal, vtotal, info))
  1316. return -EINVAL;
  1317. #endif
  1318. aty_crtc_to_var(&crtc, var);
  1319. var->pixclock = par->pll_ops->pll_to_var(info, &pll);
  1320. return 0;
  1321. }
  1322. static void set_off_pitch(struct atyfb_par *par, const struct fb_info *info)
  1323. {
  1324. u32 xoffset = info->var.xoffset;
  1325. u32 yoffset = info->var.yoffset;
  1326. u32 vxres = par->crtc.vxres;
  1327. u32 bpp = info->var.bits_per_pixel;
  1328. par->crtc.off_pitch = ((yoffset * vxres + xoffset) * bpp / 64) | (vxres << 19);
  1329. }
  1330. /*
  1331. * Open/Release the frame buffer device
  1332. */
  1333. static int atyfb_open(struct fb_info *info, int user)
  1334. {
  1335. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1336. if (user) {
  1337. par->open++;
  1338. #ifdef __sparc__
  1339. par->mmaped = 0;
  1340. #endif
  1341. }
  1342. return (0);
  1343. }
  1344. static irqreturn_t aty_irq(int irq, void *dev_id)
  1345. {
  1346. struct atyfb_par *par = dev_id;
  1347. int handled = 0;
  1348. u32 int_cntl;
  1349. spin_lock(&par->int_lock);
  1350. int_cntl = aty_ld_le32(CRTC_INT_CNTL, par);
  1351. if (int_cntl & CRTC_VBLANK_INT) {
  1352. /* clear interrupt */
  1353. aty_st_le32(CRTC_INT_CNTL, (int_cntl & CRTC_INT_EN_MASK) | CRTC_VBLANK_INT_AK, par);
  1354. par->vblank.count++;
  1355. if (par->vblank.pan_display) {
  1356. par->vblank.pan_display = 0;
  1357. aty_st_le32(CRTC_OFF_PITCH, par->crtc.off_pitch, par);
  1358. }
  1359. wake_up_interruptible(&par->vblank.wait);
  1360. handled = 1;
  1361. }
  1362. spin_unlock(&par->int_lock);
  1363. return IRQ_RETVAL(handled);
  1364. }
  1365. static int aty_enable_irq(struct atyfb_par *par, int reenable)
  1366. {
  1367. u32 int_cntl;
  1368. if (!test_and_set_bit(0, &par->irq_flags)) {
  1369. if (request_irq(par->irq, aty_irq, IRQF_SHARED, "atyfb", par)) {
  1370. clear_bit(0, &par->irq_flags);
  1371. return -EINVAL;
  1372. }
  1373. spin_lock_irq(&par->int_lock);
  1374. int_cntl = aty_ld_le32(CRTC_INT_CNTL, par) & CRTC_INT_EN_MASK;
  1375. /* clear interrupt */
  1376. aty_st_le32(CRTC_INT_CNTL, int_cntl | CRTC_VBLANK_INT_AK, par);
  1377. /* enable interrupt */
  1378. aty_st_le32(CRTC_INT_CNTL, int_cntl | CRTC_VBLANK_INT_EN, par);
  1379. spin_unlock_irq(&par->int_lock);
  1380. } else if (reenable) {
  1381. spin_lock_irq(&par->int_lock);
  1382. int_cntl = aty_ld_le32(CRTC_INT_CNTL, par) & CRTC_INT_EN_MASK;
  1383. if (!(int_cntl & CRTC_VBLANK_INT_EN)) {
  1384. printk("atyfb: someone disabled IRQ [%08x]\n", int_cntl);
  1385. /* re-enable interrupt */
  1386. aty_st_le32(CRTC_INT_CNTL, int_cntl | CRTC_VBLANK_INT_EN, par );
  1387. }
  1388. spin_unlock_irq(&par->int_lock);
  1389. }
  1390. return 0;
  1391. }
  1392. static int aty_disable_irq(struct atyfb_par *par)
  1393. {
  1394. u32 int_cntl;
  1395. if (test_and_clear_bit(0, &par->irq_flags)) {
  1396. if (par->vblank.pan_display) {
  1397. par->vblank.pan_display = 0;
  1398. aty_st_le32(CRTC_OFF_PITCH, par->crtc.off_pitch, par);
  1399. }
  1400. spin_lock_irq(&par->int_lock);
  1401. int_cntl = aty_ld_le32(CRTC_INT_CNTL, par) & CRTC_INT_EN_MASK;
  1402. /* disable interrupt */
  1403. aty_st_le32(CRTC_INT_CNTL, int_cntl & ~CRTC_VBLANK_INT_EN, par );
  1404. spin_unlock_irq(&par->int_lock);
  1405. free_irq(par->irq, par);
  1406. }
  1407. return 0;
  1408. }
  1409. static int atyfb_release(struct fb_info *info, int user)
  1410. {
  1411. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1412. if (user) {
  1413. par->open--;
  1414. mdelay(1);
  1415. wait_for_idle(par);
  1416. if (!par->open) {
  1417. #ifdef __sparc__
  1418. int was_mmaped = par->mmaped;
  1419. par->mmaped = 0;
  1420. if (was_mmaped) {
  1421. struct fb_var_screeninfo var;
  1422. /* Now reset the default display config, we have no
  1423. * idea what the program(s) which mmap'd the chip did
  1424. * to the configuration, nor whether it restored it
  1425. * correctly.
  1426. */
  1427. var = default_var;
  1428. if (noaccel)
  1429. var.accel_flags &= ~FB_ACCELF_TEXT;
  1430. else
  1431. var.accel_flags |= FB_ACCELF_TEXT;
  1432. if (var.yres == var.yres_virtual) {
  1433. u32 videoram = (info->fix.smem_len - (PAGE_SIZE << 2));
  1434. var.yres_virtual = ((videoram * 8) / var.bits_per_pixel) / var.xres_virtual;
  1435. if (var.yres_virtual < var.yres)
  1436. var.yres_virtual = var.yres;
  1437. }
  1438. }
  1439. #endif
  1440. aty_disable_irq(par);
  1441. }
  1442. }
  1443. return (0);
  1444. }
  1445. /*
  1446. * Pan or Wrap the Display
  1447. *
  1448. * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
  1449. */
  1450. static int atyfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  1451. {
  1452. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1453. u32 xres, yres, xoffset, yoffset;
  1454. xres = (((par->crtc.h_tot_disp >> 16) & 0xff) + 1) * 8;
  1455. yres = ((par->crtc.v_tot_disp >> 16) & 0x7ff) + 1;
  1456. if (par->crtc.gen_cntl & CRTC_DBL_SCAN_EN)
  1457. yres >>= 1;
  1458. xoffset = (var->xoffset + 7) & ~7;
  1459. yoffset = var->yoffset;
  1460. if (xoffset + xres > par->crtc.vxres || yoffset + yres > par->crtc.vyres)
  1461. return -EINVAL;
  1462. info->var.xoffset = xoffset;
  1463. info->var.yoffset = yoffset;
  1464. if (par->asleep)
  1465. return 0;
  1466. set_off_pitch(par, info);
  1467. if ((var->activate & FB_ACTIVATE_VBL) && !aty_enable_irq(par, 0)) {
  1468. par->vblank.pan_display = 1;
  1469. } else {
  1470. par->vblank.pan_display = 0;
  1471. aty_st_le32(CRTC_OFF_PITCH, par->crtc.off_pitch, par);
  1472. }
  1473. return 0;
  1474. }
  1475. static int aty_waitforvblank(struct atyfb_par *par, u32 crtc)
  1476. {
  1477. struct aty_interrupt *vbl;
  1478. unsigned int count;
  1479. int ret;
  1480. switch (crtc) {
  1481. case 0:
  1482. vbl = &par->vblank;
  1483. break;
  1484. default:
  1485. return -ENODEV;
  1486. }
  1487. ret = aty_enable_irq(par, 0);
  1488. if (ret)
  1489. return ret;
  1490. count = vbl->count;
  1491. ret = wait_event_interruptible_timeout(vbl->wait, count != vbl->count, HZ/10);
  1492. if (ret < 0) {
  1493. return ret;
  1494. }
  1495. if (ret == 0) {
  1496. aty_enable_irq(par, 1);
  1497. return -ETIMEDOUT;
  1498. }
  1499. return 0;
  1500. }
  1501. #ifdef DEBUG
  1502. #define ATYIO_CLKR 0x41545900 /* ATY\00 */
  1503. #define ATYIO_CLKW 0x41545901 /* ATY\01 */
  1504. struct atyclk {
  1505. u32 ref_clk_per;
  1506. u8 pll_ref_div;
  1507. u8 mclk_fb_div;
  1508. u8 mclk_post_div; /* 1,2,3,4,8 */
  1509. u8 mclk_fb_mult; /* 2 or 4 */
  1510. u8 xclk_post_div; /* 1,2,3,4,8 */
  1511. u8 vclk_fb_div;
  1512. u8 vclk_post_div; /* 1,2,3,4,6,8,12 */
  1513. u32 dsp_xclks_per_row; /* 0-16383 */
  1514. u32 dsp_loop_latency; /* 0-15 */
  1515. u32 dsp_precision; /* 0-7 */
  1516. u32 dsp_on; /* 0-2047 */
  1517. u32 dsp_off; /* 0-2047 */
  1518. };
  1519. #define ATYIO_FEATR 0x41545902 /* ATY\02 */
  1520. #define ATYIO_FEATW 0x41545903 /* ATY\03 */
  1521. #endif
  1522. #ifndef FBIO_WAITFORVSYNC
  1523. #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
  1524. #endif
  1525. static int atyfb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
  1526. {
  1527. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1528. #ifdef __sparc__
  1529. struct fbtype fbtyp;
  1530. #endif
  1531. switch (cmd) {
  1532. #ifdef __sparc__
  1533. case FBIOGTYPE:
  1534. fbtyp.fb_type = FBTYPE_PCI_GENERIC;
  1535. fbtyp.fb_width = par->crtc.vxres;
  1536. fbtyp.fb_height = par->crtc.vyres;
  1537. fbtyp.fb_depth = info->var.bits_per_pixel;
  1538. fbtyp.fb_cmsize = info->cmap.len;
  1539. fbtyp.fb_size = info->fix.smem_len;
  1540. if (copy_to_user((struct fbtype __user *) arg, &fbtyp, sizeof(fbtyp)))
  1541. return -EFAULT;
  1542. break;
  1543. #endif /* __sparc__ */
  1544. case FBIO_WAITFORVSYNC:
  1545. {
  1546. u32 crtc;
  1547. if (get_user(crtc, (__u32 __user *) arg))
  1548. return -EFAULT;
  1549. return aty_waitforvblank(par, crtc);
  1550. }
  1551. break;
  1552. #if defined(DEBUG) && defined(CONFIG_FB_ATY_CT)
  1553. case ATYIO_CLKR:
  1554. if (M64_HAS(INTEGRATED)) {
  1555. struct atyclk clk;
  1556. union aty_pll *pll = &(par->pll);
  1557. u32 dsp_config = pll->ct.dsp_config;
  1558. u32 dsp_on_off = pll->ct.dsp_on_off;
  1559. clk.ref_clk_per = par->ref_clk_per;
  1560. clk.pll_ref_div = pll->ct.pll_ref_div;
  1561. clk.mclk_fb_div = pll->ct.mclk_fb_div;
  1562. clk.mclk_post_div = pll->ct.mclk_post_div_real;
  1563. clk.mclk_fb_mult = pll->ct.mclk_fb_mult;
  1564. clk.xclk_post_div = pll->ct.xclk_post_div_real;
  1565. clk.vclk_fb_div = pll->ct.vclk_fb_div;
  1566. clk.vclk_post_div = pll->ct.vclk_post_div_real;
  1567. clk.dsp_xclks_per_row = dsp_config & 0x3fff;
  1568. clk.dsp_loop_latency = (dsp_config >> 16) & 0xf;
  1569. clk.dsp_precision = (dsp_config >> 20) & 7;
  1570. clk.dsp_off = dsp_on_off & 0x7ff;
  1571. clk.dsp_on = (dsp_on_off >> 16) & 0x7ff;
  1572. if (copy_to_user((struct atyclk __user *) arg, &clk,
  1573. sizeof(clk)))
  1574. return -EFAULT;
  1575. } else
  1576. return -EINVAL;
  1577. break;
  1578. case ATYIO_CLKW:
  1579. if (M64_HAS(INTEGRATED)) {
  1580. struct atyclk clk;
  1581. union aty_pll *pll = &(par->pll);
  1582. if (copy_from_user(&clk, (struct atyclk __user *) arg, sizeof(clk)))
  1583. return -EFAULT;
  1584. par->ref_clk_per = clk.ref_clk_per;
  1585. pll->ct.pll_ref_div = clk.pll_ref_div;
  1586. pll->ct.mclk_fb_div = clk.mclk_fb_div;
  1587. pll->ct.mclk_post_div_real = clk.mclk_post_div;
  1588. pll->ct.mclk_fb_mult = clk.mclk_fb_mult;
  1589. pll->ct.xclk_post_div_real = clk.xclk_post_div;
  1590. pll->ct.vclk_fb_div = clk.vclk_fb_div;
  1591. pll->ct.vclk_post_div_real = clk.vclk_post_div;
  1592. pll->ct.dsp_config = (clk.dsp_xclks_per_row & 0x3fff) |
  1593. ((clk.dsp_loop_latency & 0xf)<<16)| ((clk.dsp_precision & 7)<<20);
  1594. pll->ct.dsp_on_off = (clk.dsp_off & 0x7ff) | ((clk.dsp_on & 0x7ff)<<16);
  1595. /*aty_calc_pll_ct(info, &pll->ct);*/
  1596. aty_set_pll_ct(info, pll);
  1597. } else
  1598. return -EINVAL;
  1599. break;
  1600. case ATYIO_FEATR:
  1601. if (get_user(par->features, (u32 __user *) arg))
  1602. return -EFAULT;
  1603. break;
  1604. case ATYIO_FEATW:
  1605. if (put_user(par->features, (u32 __user *) arg))
  1606. return -EFAULT;
  1607. break;
  1608. #endif /* DEBUG && CONFIG_FB_ATY_CT */
  1609. default:
  1610. return -EINVAL;
  1611. }
  1612. return 0;
  1613. }
  1614. static int atyfb_sync(struct fb_info *info)
  1615. {
  1616. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1617. if (par->blitter_may_be_busy)
  1618. wait_for_idle(par);
  1619. return 0;
  1620. }
  1621. #ifdef __sparc__
  1622. static int atyfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
  1623. {
  1624. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1625. unsigned int size, page, map_size = 0;
  1626. unsigned long map_offset = 0;
  1627. unsigned long off;
  1628. int i;
  1629. if (!par->mmap_map)
  1630. return -ENXIO;
  1631. if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
  1632. return -EINVAL;
  1633. off = vma->vm_pgoff << PAGE_SHIFT;
  1634. size = vma->vm_end - vma->vm_start;
  1635. /* To stop the swapper from even considering these pages. */
  1636. vma->vm_flags |= (VM_IO | VM_RESERVED);
  1637. if (((vma->vm_pgoff == 0) && (size == info->fix.smem_len)) ||
  1638. ((off == info->fix.smem_len) && (size == PAGE_SIZE)))
  1639. off += 0x8000000000000000UL;
  1640. vma->vm_pgoff = off >> PAGE_SHIFT; /* propagate off changes */
  1641. /* Each page, see which map applies */
  1642. for (page = 0; page < size;) {
  1643. map_size = 0;
  1644. for (i = 0; par->mmap_map[i].size; i++) {
  1645. unsigned long start = par->mmap_map[i].voff;
  1646. unsigned long end = start + par->mmap_map[i].size;
  1647. unsigned long offset = off + page;
  1648. if (start > offset)
  1649. continue;
  1650. if (offset >= end)
  1651. continue;
  1652. map_size = par->mmap_map[i].size - (offset - start);
  1653. map_offset =
  1654. par->mmap_map[i].poff + (offset - start);
  1655. break;
  1656. }
  1657. if (!map_size) {
  1658. page += PAGE_SIZE;
  1659. continue;
  1660. }
  1661. if (page + map_size > size)
  1662. map_size = size - page;
  1663. pgprot_val(vma->vm_page_prot) &=
  1664. ~(par->mmap_map[i].prot_mask);
  1665. pgprot_val(vma->vm_page_prot) |= par->mmap_map[i].prot_flag;
  1666. if (remap_pfn_range(vma, vma->vm_start + page,
  1667. map_offset >> PAGE_SHIFT, map_size, vma->vm_page_prot))
  1668. return -EAGAIN;
  1669. page += map_size;
  1670. }
  1671. if (!map_size)
  1672. return -EINVAL;
  1673. if (!par->mmaped)
  1674. par->mmaped = 1;
  1675. return 0;
  1676. }
  1677. static struct {
  1678. u32 yoffset;
  1679. u8 r[2][256];
  1680. u8 g[2][256];
  1681. u8 b[2][256];
  1682. } atyfb_save;
  1683. static void atyfb_save_palette(struct atyfb_par *par, int enter)
  1684. {
  1685. int i, tmp;
  1686. for (i = 0; i < 256; i++) {
  1687. tmp = aty_ld_8(DAC_CNTL, par) & 0xfc;
  1688. if (M64_HAS(EXTRA_BRIGHT))
  1689. tmp |= 0x2;
  1690. aty_st_8(DAC_CNTL, tmp, par);
  1691. aty_st_8(DAC_MASK, 0xff, par);
  1692. writeb(i, &par->aty_cmap_regs->rindex);
  1693. atyfb_save.r[enter][i] = readb(&par->aty_cmap_regs->lut);
  1694. atyfb_save.g[enter][i] = readb(&par->aty_cmap_regs->lut);
  1695. atyfb_save.b[enter][i] = readb(&par->aty_cmap_regs->lut);
  1696. writeb(i, &par->aty_cmap_regs->windex);
  1697. writeb(atyfb_save.r[1 - enter][i],
  1698. &par->aty_cmap_regs->lut);
  1699. writeb(atyfb_save.g[1 - enter][i],
  1700. &par->aty_cmap_regs->lut);
  1701. writeb(atyfb_save.b[1 - enter][i],
  1702. &par->aty_cmap_regs->lut);
  1703. }
  1704. }
  1705. static void atyfb_palette(int enter)
  1706. {
  1707. struct atyfb_par *par;
  1708. struct fb_info *info;
  1709. int i;
  1710. for (i = 0; i < FB_MAX; i++) {
  1711. info = registered_fb[i];
  1712. if (info && info->fbops == &atyfb_ops) {
  1713. par = (struct atyfb_par *) info->par;
  1714. atyfb_save_palette(par, enter);
  1715. if (enter) {
  1716. atyfb_save.yoffset = info->var.yoffset;
  1717. info->var.yoffset = 0;
  1718. set_off_pitch(par, info);
  1719. } else {
  1720. info->var.yoffset = atyfb_save.yoffset;
  1721. set_off_pitch(par, info);
  1722. }
  1723. aty_st_le32(CRTC_OFF_PITCH, par->crtc.off_pitch, par);
  1724. break;
  1725. }
  1726. }
  1727. }
  1728. #endif /* __sparc__ */
  1729. #if defined(CONFIG_PM) && defined(CONFIG_PCI)
  1730. /* Power management routines. Those are used for PowerBook sleep.
  1731. */
  1732. static int aty_power_mgmt(int sleep, struct atyfb_par *par)
  1733. {
  1734. u32 pm;
  1735. int timeout;
  1736. pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  1737. pm = (pm & ~PWR_MGT_MODE_MASK) | PWR_MGT_MODE_REG;
  1738. aty_st_lcd(POWER_MANAGEMENT, pm, par);
  1739. pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  1740. timeout = 2000;
  1741. if (sleep) {
  1742. /* Sleep */
  1743. pm &= ~PWR_MGT_ON;
  1744. aty_st_lcd(POWER_MANAGEMENT, pm, par);
  1745. pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  1746. udelay(10);
  1747. pm &= ~(PWR_BLON | AUTO_PWR_UP);
  1748. pm |= SUSPEND_NOW;
  1749. aty_st_lcd(POWER_MANAGEMENT, pm, par);
  1750. pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  1751. udelay(10);
  1752. pm |= PWR_MGT_ON;
  1753. aty_st_lcd(POWER_MANAGEMENT, pm, par);
  1754. do {
  1755. pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  1756. mdelay(1);
  1757. if ((--timeout) == 0)
  1758. break;
  1759. } while ((pm & PWR_MGT_STATUS_MASK) != PWR_MGT_STATUS_SUSPEND);
  1760. } else {
  1761. /* Wakeup */
  1762. pm &= ~PWR_MGT_ON;
  1763. aty_st_lcd(POWER_MANAGEMENT, pm, par);
  1764. pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  1765. udelay(10);
  1766. pm &= ~SUSPEND_NOW;
  1767. pm |= (PWR_BLON | AUTO_PWR_UP);
  1768. aty_st_lcd(POWER_MANAGEMENT, pm, par);
  1769. pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  1770. udelay(10);
  1771. pm |= PWR_MGT_ON;
  1772. aty_st_lcd(POWER_MANAGEMENT, pm, par);
  1773. do {
  1774. pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  1775. mdelay(1);
  1776. if ((--timeout) == 0)
  1777. break;
  1778. } while ((pm & PWR_MGT_STATUS_MASK) != 0);
  1779. }
  1780. mdelay(500);
  1781. return timeout ? 0 : -EIO;
  1782. }
  1783. static int atyfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  1784. {
  1785. struct fb_info *info = pci_get_drvdata(pdev);
  1786. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1787. #ifndef CONFIG_PPC_PMAC
  1788. /* HACK ALERT ! Once I find a proper way to say to each driver
  1789. * individually what will happen with it's PCI slot, I'll change
  1790. * that. On laptops, the AGP slot is just unclocked, so D2 is
  1791. * expected, while on desktops, the card is powered off
  1792. */
  1793. return 0;
  1794. #endif /* CONFIG_PPC_PMAC */
  1795. if (state.event == pdev->dev.power.power_state.event)
  1796. return 0;
  1797. acquire_console_sem();
  1798. fb_set_suspend(info, 1);
  1799. /* Idle & reset engine */
  1800. wait_for_idle(par);
  1801. aty_reset_engine(par);
  1802. /* Blank display and LCD */
  1803. atyfb_blank(FB_BLANK_POWERDOWN, info);
  1804. par->asleep = 1;
  1805. par->lock_blank = 1;
  1806. /* Set chip to "suspend" mode */
  1807. if (aty_power_mgmt(1, par)) {
  1808. par->asleep = 0;
  1809. par->lock_blank = 0;
  1810. atyfb_blank(FB_BLANK_UNBLANK, info);
  1811. fb_set_suspend(info, 0);
  1812. release_console_sem();
  1813. return -EIO;
  1814. }
  1815. release_console_sem();
  1816. pdev->dev.power.power_state = state;
  1817. return 0;
  1818. }
  1819. static int atyfb_pci_resume(struct pci_dev *pdev)
  1820. {
  1821. struct fb_info *info = pci_get_drvdata(pdev);
  1822. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1823. if (pdev->dev.power.power_state.event == PM_EVENT_ON)
  1824. return 0;
  1825. acquire_console_sem();
  1826. if (pdev->dev.power.power_state.event == 2)
  1827. aty_power_mgmt(0, par);
  1828. par->asleep = 0;
  1829. /* Restore display */
  1830. atyfb_set_par(info);
  1831. /* Refresh */
  1832. fb_set_suspend(info, 0);
  1833. /* Unblank */
  1834. par->lock_blank = 0;
  1835. atyfb_blank(FB_BLANK_UNBLANK, info);
  1836. release_console_sem();
  1837. pdev->dev.power.power_state = PMSG_ON;
  1838. return 0;
  1839. }
  1840. #endif /* defined(CONFIG_PM) && defined(CONFIG_PCI) */
  1841. /* Backlight */
  1842. #ifdef CONFIG_FB_ATY_BACKLIGHT
  1843. #define MAX_LEVEL 0xFF
  1844. static struct backlight_properties aty_bl_data;
  1845. /* Call with fb_info->bl_mutex held */
  1846. static int aty_bl_get_level_brightness(struct atyfb_par *par, int level)
  1847. {
  1848. struct fb_info *info = pci_get_drvdata(par->pdev);
  1849. int atylevel;
  1850. /* Get and convert the value */
  1851. atylevel = info->bl_curve[level] * FB_BACKLIGHT_MAX / MAX_LEVEL;
  1852. if (atylevel < 0)
  1853. atylevel = 0;
  1854. else if (atylevel > MAX_LEVEL)
  1855. atylevel = MAX_LEVEL;
  1856. return atylevel;
  1857. }
  1858. /* Call with fb_info->bl_mutex held */
  1859. static int __aty_bl_update_status(struct backlight_device *bd)
  1860. {
  1861. struct atyfb_par *par = class_get_devdata(&bd->class_dev);
  1862. unsigned int reg = aty_ld_lcd(LCD_MISC_CNTL, par);
  1863. int level;
  1864. if (bd->props->power != FB_BLANK_UNBLANK ||
  1865. bd->props->fb_blank != FB_BLANK_UNBLANK)
  1866. level = 0;
  1867. else
  1868. level = bd->props->brightness;
  1869. reg |= (BLMOD_EN | BIASMOD_EN);
  1870. if (level > 0) {
  1871. reg &= ~BIAS_MOD_LEVEL_MASK;
  1872. reg |= (aty_bl_get_level_brightness(par, level) << BIAS_MOD_LEVEL_SHIFT);
  1873. } else {
  1874. reg &= ~BIAS_MOD_LEVEL_MASK;
  1875. reg |= (aty_bl_get_level_brightness(par, 0) << BIAS_MOD_LEVEL_SHIFT);
  1876. }
  1877. aty_st_lcd(LCD_MISC_CNTL, reg, par);
  1878. return 0;
  1879. }
  1880. static int aty_bl_update_status(struct backlight_device *bd)
  1881. {
  1882. struct atyfb_par *par = class_get_devdata(&bd->class_dev);
  1883. struct fb_info *info = pci_get_drvdata(par->pdev);
  1884. int ret;
  1885. mutex_lock(&info->bl_mutex);
  1886. ret = __aty_bl_update_status(bd);
  1887. mutex_unlock(&info->bl_mutex);
  1888. return ret;
  1889. }
  1890. static int aty_bl_get_brightness(struct backlight_device *bd)
  1891. {
  1892. return bd->props->brightness;
  1893. }
  1894. static struct backlight_properties aty_bl_data = {
  1895. .owner = THIS_MODULE,
  1896. .get_brightness = aty_bl_get_brightness,
  1897. .update_status = aty_bl_update_status,
  1898. .max_brightness = (FB_BACKLIGHT_LEVELS - 1),
  1899. };
  1900. static void aty_bl_set_power(struct fb_info *info, int power)
  1901. {
  1902. mutex_lock(&info->bl_mutex);
  1903. if (info->bl_dev) {
  1904. down(&info->bl_dev->sem);
  1905. info->bl_dev->props->power = power;
  1906. __aty_bl_update_status(info->bl_dev);
  1907. up(&info->bl_dev->sem);
  1908. }
  1909. mutex_unlock(&info->bl_mutex);
  1910. }
  1911. static void aty_bl_init(struct atyfb_par *par)
  1912. {
  1913. struct fb_info *info = pci_get_drvdata(par->pdev);
  1914. struct backlight_device *bd;
  1915. char name[12];
  1916. #ifdef CONFIG_PMAC_BACKLIGHT
  1917. if (!pmac_has_backlight_type("ati"))
  1918. return;
  1919. #endif
  1920. snprintf(name, sizeof(name), "atybl%d", info->node);
  1921. bd = backlight_device_register(name, par, &aty_bl_data);
  1922. if (IS_ERR(bd)) {
  1923. info->bl_dev = NULL;
  1924. printk(KERN_WARNING "aty: Backlight registration failed\n");
  1925. goto error;
  1926. }
  1927. mutex_lock(&info->bl_mutex);
  1928. info->bl_dev = bd;
  1929. fb_bl_default_curve(info, 0,
  1930. 0x3F * FB_BACKLIGHT_MAX / MAX_LEVEL,
  1931. 0xFF * FB_BACKLIGHT_MAX / MAX_LEVEL);
  1932. mutex_unlock(&info->bl_mutex);
  1933. down(&bd->sem);
  1934. bd->props->brightness = aty_bl_data.max_brightness;
  1935. bd->props->power = FB_BLANK_UNBLANK;
  1936. bd->props->update_status(bd);
  1937. up(&bd->sem);
  1938. #ifdef CONFIG_PMAC_BACKLIGHT
  1939. mutex_lock(&pmac_backlight_mutex);
  1940. if (!pmac_backlight)
  1941. pmac_backlight = bd;
  1942. mutex_unlock(&pmac_backlight_mutex);
  1943. #endif
  1944. printk("aty: Backlight initialized (%s)\n", name);
  1945. return;
  1946. error:
  1947. return;
  1948. }
  1949. static void aty_bl_exit(struct atyfb_par *par)
  1950. {
  1951. struct fb_info *info = pci_get_drvdata(par->pdev);
  1952. #ifdef CONFIG_PMAC_BACKLIGHT
  1953. mutex_lock(&pmac_backlight_mutex);
  1954. #endif
  1955. mutex_lock(&info->bl_mutex);
  1956. if (info->bl_dev) {
  1957. #ifdef CONFIG_PMAC_BACKLIGHT
  1958. if (pmac_backlight == info->bl_dev)
  1959. pmac_backlight = NULL;
  1960. #endif
  1961. backlight_device_unregister(info->bl_dev);
  1962. printk("aty: Backlight unloaded\n");
  1963. }
  1964. mutex_unlock(&info->bl_mutex);
  1965. #ifdef CONFIG_PMAC_BACKLIGHT
  1966. mutex_unlock(&pmac_backlight_mutex);
  1967. #endif
  1968. }
  1969. #endif /* CONFIG_FB_ATY_BACKLIGHT */
  1970. static void __devinit aty_calc_mem_refresh(struct atyfb_par *par, int xclk)
  1971. {
  1972. const int ragepro_tbl[] = {
  1973. 44, 50, 55, 66, 75, 80, 100
  1974. };
  1975. const int ragexl_tbl[] = {
  1976. 50, 66, 75, 83, 90, 95, 100, 105,
  1977. 110, 115, 120, 125, 133, 143, 166
  1978. };
  1979. const int *refresh_tbl;
  1980. int i, size;
  1981. if (IS_XL(par->pci_id) || IS_MOBILITY(par->pci_id)) {
  1982. refresh_tbl = ragexl_tbl;
  1983. size = ARRAY_SIZE(ragexl_tbl);
  1984. } else {
  1985. refresh_tbl = ragepro_tbl;
  1986. size = ARRAY_SIZE(ragepro_tbl);
  1987. }
  1988. for (i=0; i < size; i++) {
  1989. if (xclk < refresh_tbl[i])
  1990. break;
  1991. }
  1992. par->mem_refresh_rate = i;
  1993. }
  1994. /*
  1995. * Initialisation
  1996. */
  1997. static struct fb_info *fb_list = NULL;
  1998. #if defined(__i386__) && defined(CONFIG_FB_ATY_GENERIC_LCD)
  1999. static int __devinit atyfb_get_timings_from_lcd(struct atyfb_par *par,
  2000. struct fb_var_screeninfo *var)
  2001. {
  2002. int ret = -EINVAL;
  2003. if (par->lcd_table != 0 && (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) {
  2004. *var = default_var;
  2005. var->xres = var->xres_virtual = par->lcd_hdisp;
  2006. var->right_margin = par->lcd_right_margin;
  2007. var->left_margin = par->lcd_hblank_len -
  2008. (par->lcd_right_margin + par->lcd_hsync_dly +
  2009. par->lcd_hsync_len);
  2010. var->hsync_len = par->lcd_hsync_len + par->lcd_hsync_dly;
  2011. var->yres = var->yres_virtual = par->lcd_vdisp;
  2012. var->lower_margin = par->lcd_lower_margin;
  2013. var->upper_margin = par->lcd_vblank_len -
  2014. (par->lcd_lower_margin + par->lcd_vsync_len);
  2015. var->vsync_len = par->lcd_vsync_len;
  2016. var->pixclock = par->lcd_pixclock;
  2017. ret = 0;
  2018. }
  2019. return ret;
  2020. }
  2021. #endif /* defined(__i386__) && defined(CONFIG_FB_ATY_GENERIC_LCD) */
  2022. static int __devinit aty_init(struct fb_info *info, const char *name)
  2023. {
  2024. struct atyfb_par *par = (struct atyfb_par *) info->par;
  2025. const char *ramname = NULL, *xtal;
  2026. int gtb_memsize, has_var = 0;
  2027. struct fb_var_screeninfo var;
  2028. u8 pll_ref_div;
  2029. u32 i;
  2030. #if defined(CONFIG_PPC)
  2031. int sense;
  2032. #endif
  2033. init_waitqueue_head(&par->vblank.wait);
  2034. spin_lock_init(&par->int_lock);
  2035. par->aty_cmap_regs =
  2036. (struct aty_cmap_regs __iomem *) (par->ati_regbase + 0xc0);
  2037. #ifdef CONFIG_PPC_PMAC
  2038. /* The Apple iBook1 uses non-standard memory frequencies. We detect it
  2039. * and set the frequency manually. */
  2040. if (machine_is_compatible("PowerBook2,1")) {
  2041. par->pll_limits.mclk = 70;
  2042. par->pll_limits.xclk = 53;
  2043. }
  2044. #endif
  2045. if (pll)
  2046. par->pll_limits.pll_max = pll;
  2047. if (mclk)
  2048. par->pll_limits.mclk = mclk;
  2049. if (xclk)
  2050. par->pll_limits.xclk = xclk;
  2051. aty_calc_mem_refresh(par, par->pll_limits.xclk);
  2052. par->pll_per = 1000000/par->pll_limits.pll_max;
  2053. par->mclk_per = 1000000/par->pll_limits.mclk;
  2054. par->xclk_per = 1000000/par->pll_limits.xclk;
  2055. par->ref_clk_per = 1000000000000ULL / 14318180;
  2056. xtal = "14.31818";
  2057. #ifdef CONFIG_FB_ATY_GX
  2058. if (!M64_HAS(INTEGRATED)) {
  2059. u32 stat0;
  2060. u8 dac_type, dac_subtype, clk_type;
  2061. stat0 = aty_ld_le32(CONFIG_STAT0, par);
  2062. par->bus_type = (stat0 >> 0) & 0x07;
  2063. par->ram_type = (stat0 >> 3) & 0x07;
  2064. ramname = aty_gx_ram[par->ram_type];
  2065. /* FIXME: clockchip/RAMDAC probing? */
  2066. dac_type = (aty_ld_le32(DAC_CNTL, par) >> 16) & 0x07;
  2067. #ifdef CONFIG_ATARI
  2068. clk_type = CLK_ATI18818_1;
  2069. dac_type = (stat0 >> 9) & 0x07;
  2070. if (dac_type == 0x07)
  2071. dac_subtype = DAC_ATT20C408;
  2072. else
  2073. dac_subtype = (aty_ld_8(SCRATCH_REG1 + 1, par) & 0xF0) | dac_type;
  2074. #else
  2075. dac_type = DAC_IBMRGB514;
  2076. dac_subtype = DAC_IBMRGB514;
  2077. clk_type = CLK_IBMRGB514;
  2078. #endif
  2079. switch (dac_subtype) {
  2080. case DAC_IBMRGB514:
  2081. par->dac_ops = &aty_dac_ibm514;
  2082. break;
  2083. case DAC_ATI68860_B:
  2084. case DAC_ATI68860_C:
  2085. par->dac_ops = &aty_dac_ati68860b;
  2086. break;
  2087. case DAC_ATT20C408:
  2088. case DAC_ATT21C498:
  2089. par->dac_ops = &aty_dac_att21c498;
  2090. break;
  2091. default:
  2092. PRINTKI("aty_init: DAC type not implemented yet!\n");
  2093. par->dac_ops = &aty_dac_unsupported;
  2094. break;
  2095. }
  2096. switch (clk_type) {
  2097. #ifdef CONFIG_ATARI
  2098. case CLK_ATI18818_1:
  2099. par->pll_ops = &aty_pll_ati18818_1;
  2100. break;
  2101. #else
  2102. case CLK_IBMRGB514:
  2103. par->pll_ops = &aty_pll_ibm514;
  2104. break;
  2105. #endif
  2106. #if 0 /* dead code */
  2107. case CLK_STG1703:
  2108. par->pll_ops = &aty_pll_stg1703;
  2109. break;
  2110. case CLK_CH8398:
  2111. par->pll_ops = &aty_pll_ch8398;
  2112. break;
  2113. case CLK_ATT20C408:
  2114. par->pll_ops = &aty_pll_att20c408;
  2115. break;
  2116. #endif
  2117. default:
  2118. PRINTKI("aty_init: CLK type not implemented yet!");
  2119. par->pll_ops = &aty_pll_unsupported;
  2120. break;
  2121. }
  2122. }
  2123. #endif /* CONFIG_FB_ATY_GX */
  2124. #ifdef CONFIG_FB_ATY_CT
  2125. if (M64_HAS(INTEGRATED)) {
  2126. par->dac_ops = &aty_dac_ct;
  2127. par->pll_ops = &aty_pll_ct;
  2128. par->bus_type = PCI;
  2129. par->ram_type = (aty_ld_le32(CONFIG_STAT0, par) & 0x07);
  2130. ramname = aty_ct_ram[par->ram_type];
  2131. /* for many chips, the mclk is 67 MHz for SDRAM, 63 MHz otherwise */
  2132. if (par->pll_limits.mclk == 67 && par->ram_type < SDRAM)
  2133. par->pll_limits.mclk = 63;
  2134. }
  2135. if (M64_HAS(GTB_DSP)
  2136. && (pll_ref_div = aty_ld_pll_ct(PLL_REF_DIV, par))) {
  2137. int diff1, diff2;
  2138. diff1 = 510 * 14 / pll_ref_div - par->pll_limits.pll_max;
  2139. diff2 = 510 * 29 / pll_ref_div - par->pll_limits.pll_max;
  2140. if (diff1 < 0)
  2141. diff1 = -diff1;
  2142. if (diff2 < 0)
  2143. diff2 = -diff2;
  2144. if (diff2 < diff1) {
  2145. par->ref_clk_per = 1000000000000ULL / 29498928;
  2146. xtal = "29.498928";
  2147. }
  2148. }
  2149. #endif /* CONFIG_FB_ATY_CT */
  2150. /* save previous video mode */
  2151. aty_get_crtc(par, &saved_crtc);
  2152. if(par->pll_ops->get_pll)
  2153. par->pll_ops->get_pll(info, &saved_pll);
  2154. i = aty_ld_le32(MEM_CNTL, par);
  2155. gtb_memsize = M64_HAS(GTB_DSP);
  2156. if (gtb_memsize)
  2157. switch (i & 0xF) { /* 0xF used instead of MEM_SIZE_ALIAS */
  2158. case MEM_SIZE_512K:
  2159. info->fix.smem_len = 0x80000;
  2160. break;
  2161. case MEM_SIZE_1M:
  2162. info->fix.smem_len = 0x100000;
  2163. break;
  2164. case MEM_SIZE_2M_GTB:
  2165. info->fix.smem_len = 0x200000;
  2166. break;
  2167. case MEM_SIZE_4M_GTB:
  2168. info->fix.smem_len = 0x400000;
  2169. break;
  2170. case MEM_SIZE_6M_GTB:
  2171. info->fix.smem_len = 0x600000;
  2172. break;
  2173. case MEM_SIZE_8M_GTB:
  2174. info->fix.smem_len = 0x800000;
  2175. break;
  2176. default:
  2177. info->fix.smem_len = 0x80000;
  2178. } else
  2179. switch (i & MEM_SIZE_ALIAS) {
  2180. case MEM_SIZE_512K:
  2181. info->fix.smem_len = 0x80000;
  2182. break;
  2183. case MEM_SIZE_1M:
  2184. info->fix.smem_len = 0x100000;
  2185. break;
  2186. case MEM_SIZE_2M:
  2187. info->fix.smem_len = 0x200000;
  2188. break;
  2189. case MEM_SIZE_4M:
  2190. info->fix.smem_len = 0x400000;
  2191. break;
  2192. case MEM_SIZE_6M:
  2193. info->fix.smem_len = 0x600000;
  2194. break;
  2195. case MEM_SIZE_8M:
  2196. info->fix.smem_len = 0x800000;
  2197. break;
  2198. default:
  2199. info->fix.smem_len = 0x80000;
  2200. }
  2201. if (M64_HAS(MAGIC_VRAM_SIZE)) {
  2202. if (aty_ld_le32(CONFIG_STAT1, par) & 0x40000000)
  2203. info->fix.smem_len += 0x400000;
  2204. }
  2205. if (vram) {
  2206. info->fix.smem_len = vram * 1024;
  2207. i = i & ~(gtb_memsize ? 0xF : MEM_SIZE_ALIAS);
  2208. if (info->fix.smem_len <= 0x80000)
  2209. i |= MEM_SIZE_512K;
  2210. else if (info->fix.smem_len <= 0x100000)
  2211. i |= MEM_SIZE_1M;
  2212. else if (info->fix.smem_len <= 0x200000)
  2213. i |= gtb_memsize ? MEM_SIZE_2M_GTB : MEM_SIZE_2M;
  2214. else if (info->fix.smem_len <= 0x400000)
  2215. i |= gtb_memsize ? MEM_SIZE_4M_GTB : MEM_SIZE_4M;
  2216. else if (info->fix.smem_len <= 0x600000)
  2217. i |= gtb_memsize ? MEM_SIZE_6M_GTB : MEM_SIZE_6M;
  2218. else
  2219. i |= gtb_memsize ? MEM_SIZE_8M_GTB : MEM_SIZE_8M;
  2220. aty_st_le32(MEM_CNTL, i, par);
  2221. }
  2222. /*
  2223. * Reg Block 0 (CT-compatible block) is at mmio_start
  2224. * Reg Block 1 (multimedia extensions) is at mmio_start - 0x400
  2225. */
  2226. if (M64_HAS(GX)) {
  2227. info->fix.mmio_len = 0x400;
  2228. info->fix.accel = FB_ACCEL_ATI_MACH64GX;
  2229. } else if (M64_HAS(CT)) {
  2230. info->fix.mmio_len = 0x400;
  2231. info->fix.accel = FB_ACCEL_ATI_MACH64CT;
  2232. } else if (M64_HAS(VT)) {
  2233. info->fix.mmio_start -= 0x400;
  2234. info->fix.mmio_len = 0x800;
  2235. info->fix.accel = FB_ACCEL_ATI_MACH64VT;
  2236. } else {/* GT */
  2237. info->fix.mmio_start -= 0x400;
  2238. info->fix.mmio_len = 0x800;
  2239. info->fix.accel = FB_ACCEL_ATI_MACH64GT;
  2240. }
  2241. PRINTKI("%d%c %s, %s MHz XTAL, %d MHz PLL, %d Mhz MCLK, %d MHz XCLK\n",
  2242. info->fix.smem_len == 0x80000 ? 512 : (info->fix.smem_len >> 20),
  2243. info->fix.smem_len == 0x80000 ? 'K' : 'M', ramname, xtal, par->pll_limits.pll_max,
  2244. par->pll_limits.mclk, par->pll_limits.xclk);
  2245. #if defined(DEBUG) && defined(CONFIG_ATY_CT)
  2246. if (M64_HAS(INTEGRATED)) {
  2247. int i;
  2248. printk("debug atyfb: BUS_CNTL DAC_CNTL MEM_CNTL EXT_MEM_CNTL CRTC_GEN_CNTL "
  2249. "DSP_CONFIG DSP_ON_OFF CLOCK_CNTL\n"
  2250. "debug atyfb: %08x %08x %08x %08x %08x %08x %08x %08x\n"
  2251. "debug atyfb: PLL",
  2252. aty_ld_le32(BUS_CNTL, par), aty_ld_le32(DAC_CNTL, par),
  2253. aty_ld_le32(MEM_CNTL, par), aty_ld_le32(EXT_MEM_CNTL, par),
  2254. aty_ld_le32(CRTC_GEN_CNTL, par), aty_ld_le32(DSP_CONFIG, par),
  2255. aty_ld_le32(DSP_ON_OFF, par), aty_ld_le32(CLOCK_CNTL, par));
  2256. for (i = 0; i < 40; i++)
  2257. printk(" %02x", aty_ld_pll_ct(i, par));
  2258. printk("\n");
  2259. }
  2260. #endif
  2261. if(par->pll_ops->init_pll)
  2262. par->pll_ops->init_pll(info, &par->pll);
  2263. /*
  2264. * Last page of 8 MB (4 MB on ISA) aperture is MMIO
  2265. * FIXME: we should use the auxiliary aperture instead so we can access
  2266. * the full 8 MB of video RAM on 8 MB boards
  2267. */
  2268. if (!par->aux_start &&
  2269. (info->fix.smem_len == 0x800000 || (par->bus_type == ISA && info->fix.smem_len == 0x400000)))
  2270. info->fix.smem_len -= GUI_RESERVE;
  2271. /*
  2272. * Disable register access through the linear aperture
  2273. * if the auxiliary aperture is used so we can access
  2274. * the full 8 MB of video RAM on 8 MB boards.
  2275. */
  2276. if (par->aux_start)
  2277. aty_st_le32(BUS_CNTL, aty_ld_le32(BUS_CNTL, par) | BUS_APER_REG_DIS, par);
  2278. #ifdef CONFIG_MTRR
  2279. par->mtrr_aper = -1;
  2280. par->mtrr_reg = -1;
  2281. if (!nomtrr) {
  2282. /* Cover the whole resource. */
  2283. par->mtrr_aper = mtrr_add(par->res_start, par->res_size, MTRR_TYPE_WRCOMB, 1);
  2284. if (par->mtrr_aper >= 0 && !par->aux_start) {
  2285. /* Make a hole for mmio. */
  2286. par->mtrr_reg = mtrr_add(par->res_start + 0x800000 - GUI_RESERVE,
  2287. GUI_RESERVE, MTRR_TYPE_UNCACHABLE, 1);
  2288. if (par->mtrr_reg < 0) {
  2289. mtrr_del(par->mtrr_aper, 0, 0);
  2290. par->mtrr_aper = -1;
  2291. }
  2292. }
  2293. }
  2294. #endif
  2295. info->fbops = &atyfb_ops;
  2296. info->pseudo_palette = pseudo_palette;
  2297. info->flags = FBINFO_DEFAULT |
  2298. FBINFO_HWACCEL_IMAGEBLIT |
  2299. FBINFO_HWACCEL_FILLRECT |
  2300. FBINFO_HWACCEL_COPYAREA |
  2301. FBINFO_HWACCEL_YPAN;
  2302. #ifdef CONFIG_PMAC_BACKLIGHT
  2303. if (M64_HAS(G3_PB_1_1) && machine_is_compatible("PowerBook1,1")) {
  2304. /* these bits let the 101 powerbook wake up from sleep -- paulus */
  2305. aty_st_lcd(POWER_MANAGEMENT, aty_ld_lcd(POWER_MANAGEMENT, par)
  2306. | (USE_F32KHZ | TRISTATE_MEM_EN), par);
  2307. } else
  2308. #endif
  2309. if (M64_HAS(MOBIL_BUS)) {
  2310. #ifdef CONFIG_FB_ATY_BACKLIGHT
  2311. aty_bl_init (par);
  2312. #endif
  2313. }
  2314. memset(&var, 0, sizeof(var));
  2315. #ifdef CONFIG_PPC
  2316. if (machine_is(powermac)) {
  2317. /*
  2318. * FIXME: The NVRAM stuff should be put in a Mac-specific file, as it
  2319. * applies to all Mac video cards
  2320. */
  2321. if (mode) {
  2322. if (mac_find_mode(&var, info, mode, 8))
  2323. has_var = 1;
  2324. } else {
  2325. if (default_vmode == VMODE_CHOOSE) {
  2326. if (M64_HAS(G3_PB_1024x768))
  2327. /* G3 PowerBook with 1024x768 LCD */
  2328. default_vmode = VMODE_1024_768_60;
  2329. else if (machine_is_compatible("iMac"))
  2330. default_vmode = VMODE_1024_768_75;
  2331. else if (machine_is_compatible
  2332. ("PowerBook2,1"))
  2333. /* iBook with 800x600 LCD */
  2334. default_vmode = VMODE_800_600_60;
  2335. else
  2336. default_vmode = VMODE_640_480_67;
  2337. sense = read_aty_sense(par);
  2338. PRINTKI("monitor sense=%x, mode %d\n",
  2339. sense, mac_map_monitor_sense(sense));
  2340. }
  2341. if (default_vmode <= 0 || default_vmode > VMODE_MAX)
  2342. default_vmode = VMODE_640_480_60;
  2343. if (default_cmode < CMODE_8 || default_cmode > CMODE_32)
  2344. default_cmode = CMODE_8;
  2345. if (!mac_vmode_to_var(default_vmode, default_cmode,
  2346. &var))
  2347. has_var = 1;
  2348. }
  2349. }
  2350. #endif /* !CONFIG_PPC */
  2351. #if defined(__i386__) && defined(CONFIG_FB_ATY_GENERIC_LCD)
  2352. if (!atyfb_get_timings_from_lcd(par, &var))
  2353. has_var = 1;
  2354. #endif
  2355. if (mode && fb_find_mode(&var, info, mode, NULL, 0, &defmode, 8))
  2356. has_var = 1;
  2357. if (!has_var)
  2358. var = default_var;
  2359. if (noaccel)
  2360. var.accel_flags &= ~FB_ACCELF_TEXT;
  2361. else
  2362. var.accel_flags |= FB_ACCELF_TEXT;
  2363. if (comp_sync != -1) {
  2364. if (!comp_sync)
  2365. var.sync &= ~FB_SYNC_COMP_HIGH_ACT;
  2366. else
  2367. var.sync |= FB_SYNC_COMP_HIGH_ACT;
  2368. }
  2369. if (var.yres == var.yres_virtual) {
  2370. u32 videoram = (info->fix.smem_len - (PAGE_SIZE << 2));
  2371. var.yres_virtual = ((videoram * 8) / var.bits_per_pixel) / var.xres_virtual;
  2372. if (var.yres_virtual < var.yres)
  2373. var.yres_virtual = var.yres;
  2374. }
  2375. if (atyfb_check_var(&var, info)) {
  2376. PRINTKE("can't set default video mode\n");
  2377. goto aty_init_exit;
  2378. }
  2379. #ifdef __sparc__
  2380. atyfb_save_palette(par, 0);
  2381. #endif
  2382. #ifdef CONFIG_FB_ATY_CT
  2383. if (!noaccel && M64_HAS(INTEGRATED))
  2384. aty_init_cursor(info);
  2385. #endif /* CONFIG_FB_ATY_CT */
  2386. info->var = var;
  2387. fb_alloc_cmap(&info->cmap, 256, 0);
  2388. if (register_framebuffer(info) < 0)
  2389. goto aty_init_exit;
  2390. fb_list = info;
  2391. PRINTKI("fb%d: %s frame buffer device on %s\n",
  2392. info->node, info->fix.id, name);
  2393. return 0;
  2394. aty_init_exit:
  2395. /* restore video mode */
  2396. aty_set_crtc(par, &saved_crtc);
  2397. par->pll_ops->set_pll(info, &saved_pll);
  2398. #ifdef CONFIG_MTRR
  2399. if (par->mtrr_reg >= 0) {
  2400. mtrr_del(par->mtrr_reg, 0, 0);
  2401. par->mtrr_reg = -1;
  2402. }
  2403. if (par->mtrr_aper >= 0) {
  2404. mtrr_del(par->mtrr_aper, 0, 0);
  2405. par->mtrr_aper = -1;
  2406. }
  2407. #endif
  2408. return -1;
  2409. }
  2410. #ifdef CONFIG_ATARI
  2411. static int __devinit store_video_par(char *video_str, unsigned char m64_num)
  2412. {
  2413. char *p;
  2414. unsigned long vmembase, size, guiregbase;
  2415. PRINTKI("store_video_par() '%s' \n", video_str);
  2416. if (!(p = strsep(&video_str, ";")) || !*p)
  2417. goto mach64_invalid;
  2418. vmembase = simple_strtoul(p, NULL, 0);
  2419. if (!(p = strsep(&video_str, ";")) || !*p)
  2420. goto mach64_invalid;
  2421. size = simple_strtoul(p, NULL, 0);
  2422. if (!(p = strsep(&video_str, ";")) || !*p)
  2423. goto mach64_invalid;
  2424. guiregbase = simple_strtoul(p, NULL, 0);
  2425. phys_vmembase[m64_num] = vmembase;
  2426. phys_size[m64_num] = size;
  2427. phys_guiregbase[m64_num] = guiregbase;
  2428. PRINTKI("stored them all: $%08lX $%08lX $%08lX \n", vmembase, size,
  2429. guiregbase);
  2430. return 0;
  2431. mach64_invalid:
  2432. phys_vmembase[m64_num] = 0;
  2433. return -1;
  2434. }
  2435. #endif /* CONFIG_ATARI */
  2436. /*
  2437. * Blank the display.
  2438. */
  2439. static int atyfb_blank(int blank, struct fb_info *info)
  2440. {
  2441. struct atyfb_par *par = (struct atyfb_par *) info->par;
  2442. u32 gen_cntl;
  2443. if (par->lock_blank || par->asleep)
  2444. return 0;
  2445. #ifdef CONFIG_FB_ATY_BACKLIGHT
  2446. if (machine_is(powermac) && blank > FB_BLANK_NORMAL)
  2447. aty_bl_set_power(info, FB_BLANK_POWERDOWN);
  2448. #elif defined(CONFIG_FB_ATY_GENERIC_LCD)
  2449. if (par->lcd_table && blank > FB_BLANK_NORMAL &&
  2450. (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) {
  2451. u32 pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  2452. pm &= ~PWR_BLON;
  2453. aty_st_lcd(POWER_MANAGEMENT, pm, par);
  2454. }
  2455. #endif
  2456. gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par);
  2457. switch (blank) {
  2458. case FB_BLANK_UNBLANK:
  2459. gen_cntl &= ~0x400004c;
  2460. break;
  2461. case FB_BLANK_NORMAL:
  2462. gen_cntl |= 0x4000040;
  2463. break;
  2464. case FB_BLANK_VSYNC_SUSPEND:
  2465. gen_cntl |= 0x4000048;
  2466. break;
  2467. case FB_BLANK_HSYNC_SUSPEND:
  2468. gen_cntl |= 0x4000044;
  2469. break;
  2470. case FB_BLANK_POWERDOWN:
  2471. gen_cntl |= 0x400004c;
  2472. break;
  2473. }
  2474. aty_st_le32(CRTC_GEN_CNTL, gen_cntl, par);
  2475. #ifdef CONFIG_FB_ATY_BACKLIGHT
  2476. if (machine_is(powermac) && blank <= FB_BLANK_NORMAL)
  2477. aty_bl_set_power(info, FB_BLANK_UNBLANK);
  2478. #elif defined(CONFIG_FB_ATY_GENERIC_LCD)
  2479. if (par->lcd_table && blank <= FB_BLANK_NORMAL &&
  2480. (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) {
  2481. u32 pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  2482. pm |= PWR_BLON;
  2483. aty_st_lcd(POWER_MANAGEMENT, pm, par);
  2484. }
  2485. #endif
  2486. return 0;
  2487. }
  2488. static void aty_st_pal(u_int regno, u_int red, u_int green, u_int blue,
  2489. const struct atyfb_par *par)
  2490. {
  2491. #ifdef CONFIG_ATARI
  2492. out_8(&par->aty_cmap_regs->windex, regno);
  2493. out_8(&par->aty_cmap_regs->lut, red);
  2494. out_8(&par->aty_cmap_regs->lut, green);
  2495. out_8(&par->aty_cmap_regs->lut, blue);
  2496. #else
  2497. writeb(regno, &par->aty_cmap_regs->windex);
  2498. writeb(red, &par->aty_cmap_regs->lut);
  2499. writeb(green, &par->aty_cmap_regs->lut);
  2500. writeb(blue, &par->aty_cmap_regs->lut);
  2501. #endif
  2502. }
  2503. /*
  2504. * Set a single color register. The values supplied are already
  2505. * rounded down to the hardware's capabilities (according to the
  2506. * entries in the var structure). Return != 0 for invalid regno.
  2507. * !! 4 & 8 = PSEUDO, > 8 = DIRECTCOLOR
  2508. */
  2509. static int atyfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  2510. u_int transp, struct fb_info *info)
  2511. {
  2512. struct atyfb_par *par = (struct atyfb_par *) info->par;
  2513. int i, depth;
  2514. u32 *pal = info->pseudo_palette;
  2515. depth = info->var.bits_per_pixel;
  2516. if (depth == 16)
  2517. depth = (info->var.green.length == 5) ? 15 : 16;
  2518. if (par->asleep)
  2519. return 0;
  2520. if (regno > 255 ||
  2521. (depth == 16 && regno > 63) ||
  2522. (depth == 15 && regno > 31))
  2523. return 1;
  2524. red >>= 8;
  2525. green >>= 8;
  2526. blue >>= 8;
  2527. par->palette[regno].red = red;
  2528. par->palette[regno].green = green;
  2529. par->palette[regno].blue = blue;
  2530. if (regno < 16) {
  2531. switch (depth) {
  2532. case 15:
  2533. pal[regno] = (regno << 10) | (regno << 5) | regno;
  2534. break;
  2535. case 16:
  2536. pal[regno] = (regno << 11) | (regno << 5) | regno;
  2537. break;
  2538. case 24:
  2539. pal[regno] = (regno << 16) | (regno << 8) | regno;
  2540. break;
  2541. case 32:
  2542. i = (regno << 8) | regno;
  2543. pal[regno] = (i << 16) | i;
  2544. break;
  2545. }
  2546. }
  2547. i = aty_ld_8(DAC_CNTL, par) & 0xfc;
  2548. if (M64_HAS(EXTRA_BRIGHT))
  2549. i |= 0x2; /* DAC_CNTL | 0x2 turns off the extra brightness for gt */
  2550. aty_st_8(DAC_CNTL, i, par);
  2551. aty_st_8(DAC_MASK, 0xff, par);
  2552. if (M64_HAS(INTEGRATED)) {
  2553. if (depth == 16) {
  2554. if (regno < 32)
  2555. aty_st_pal(regno << 3, red,
  2556. par->palette[regno<<1].green,
  2557. blue, par);
  2558. red = par->palette[regno>>1].red;
  2559. blue = par->palette[regno>>1].blue;
  2560. regno <<= 2;
  2561. } else if (depth == 15) {
  2562. regno <<= 3;
  2563. for(i = 0; i < 8; i++) {
  2564. aty_st_pal(regno + i, red, green, blue, par);
  2565. }
  2566. }
  2567. }
  2568. aty_st_pal(regno, red, green, blue, par);
  2569. return 0;
  2570. }
  2571. #ifdef CONFIG_PCI
  2572. #ifdef __sparc__
  2573. extern void (*prom_palette) (int);
  2574. static int __devinit atyfb_setup_sparc(struct pci_dev *pdev,
  2575. struct fb_info *info, unsigned long addr)
  2576. {
  2577. extern int con_is_present(void);
  2578. struct atyfb_par *par = info->par;
  2579. struct pcidev_cookie *pcp;
  2580. char prop[128];
  2581. int node, len, i, j, ret;
  2582. u32 mem, chip_id;
  2583. /* Do not attach when we have a serial console. */
  2584. if (!con_is_present())
  2585. return -ENXIO;
  2586. /*
  2587. * Map memory-mapped registers.
  2588. */
  2589. par->ati_regbase = (void *)addr + 0x7ffc00UL;
  2590. info->fix.mmio_start = addr + 0x7ffc00UL;
  2591. /*
  2592. * Map in big-endian aperture.
  2593. */
  2594. info->screen_base = (char *) (addr + 0x800000UL);
  2595. info->fix.smem_start = addr + 0x800000UL;
  2596. /*
  2597. * Figure mmap addresses from PCI config space.
  2598. * Split Framebuffer in big- and little-endian halfs.
  2599. */
  2600. for (i = 0; i < 6 && pdev->resource[i].start; i++)
  2601. /* nothing */ ;
  2602. j = i + 4;
  2603. par->mmap_map = kmalloc(j * sizeof(*par->mmap_map), GFP_ATOMIC);
  2604. if (!par->mmap_map) {
  2605. PRINTKE("atyfb_setup_sparc() can't alloc mmap_map\n");
  2606. return -ENOMEM;
  2607. }
  2608. memset(par->mmap_map, 0, j * sizeof(*par->mmap_map));
  2609. for (i = 0, j = 2; i < 6 && pdev->resource[i].start; i++) {
  2610. struct resource *rp = &pdev->resource[i];
  2611. int io, breg = PCI_BASE_ADDRESS_0 + (i << 2);
  2612. unsigned long base;
  2613. u32 size, pbase;
  2614. base = rp->start;
  2615. io = (rp->flags & IORESOURCE_IO);
  2616. size = rp->end - base + 1;
  2617. pci_read_config_dword(pdev, breg, &pbase);
  2618. if (io)
  2619. size &= ~1;
  2620. /*
  2621. * Map the framebuffer a second time, this time without
  2622. * the braindead _PAGE_IE setting. This is used by the
  2623. * fixed Xserver, but we need to maintain the old mapping
  2624. * to stay compatible with older ones...
  2625. */
  2626. if (base == addr) {
  2627. par->mmap_map[j].voff = (pbase + 0x10000000) & PAGE_MASK;
  2628. par->mmap_map[j].poff = base & PAGE_MASK;
  2629. par->mmap_map[j].size = (size + ~PAGE_MASK) & PAGE_MASK;
  2630. par->mmap_map[j].prot_mask = _PAGE_CACHE;
  2631. par->mmap_map[j].prot_flag = _PAGE_E;
  2632. j++;
  2633. }
  2634. /*
  2635. * Here comes the old framebuffer mapping with _PAGE_IE
  2636. * set for the big endian half of the framebuffer...
  2637. */
  2638. if (base == addr) {
  2639. par->mmap_map[j].voff = (pbase + 0x800000) & PAGE_MASK;
  2640. par->mmap_map[j].poff = (base + 0x800000) & PAGE_MASK;
  2641. par->mmap_map[j].size = 0x800000;
  2642. par->mmap_map[j].prot_mask = _PAGE_CACHE;
  2643. par->mmap_map[j].prot_flag = _PAGE_E | _PAGE_IE;
  2644. size -= 0x800000;
  2645. j++;
  2646. }
  2647. par->mmap_map[j].voff = pbase & PAGE_MASK;
  2648. par->mmap_map[j].poff = base & PAGE_MASK;
  2649. par->mmap_map[j].size = (size + ~PAGE_MASK) & PAGE_MASK;
  2650. par->mmap_map[j].prot_mask = _PAGE_CACHE;
  2651. par->mmap_map[j].prot_flag = _PAGE_E;
  2652. j++;
  2653. }
  2654. if((ret = correct_chipset(par)))
  2655. return ret;
  2656. if (IS_XL(pdev->device)) {
  2657. /*
  2658. * Fix PROMs idea of MEM_CNTL settings...
  2659. */
  2660. mem = aty_ld_le32(MEM_CNTL, par);
  2661. chip_id = aty_ld_le32(CONFIG_CHIP_ID, par);
  2662. if (((chip_id & CFG_CHIP_TYPE) == VT_CHIP_ID) && !((chip_id >> 24) & 1)) {
  2663. switch (mem & 0x0f) {
  2664. case 3:
  2665. mem = (mem & ~(0x0f)) | 2;
  2666. break;
  2667. case 7:
  2668. mem = (mem & ~(0x0f)) | 3;
  2669. break;
  2670. case 9:
  2671. mem = (mem & ~(0x0f)) | 4;
  2672. break;
  2673. case 11:
  2674. mem = (mem & ~(0x0f)) | 5;
  2675. break;
  2676. default:
  2677. break;
  2678. }
  2679. if ((aty_ld_le32(CONFIG_STAT0, par) & 7) >= SDRAM)
  2680. mem &= ~(0x00700000);
  2681. }
  2682. mem &= ~(0xcf80e000); /* Turn off all undocumented bits. */
  2683. aty_st_le32(MEM_CNTL, mem, par);
  2684. }
  2685. /*
  2686. * If this is the console device, we will set default video
  2687. * settings to what the PROM left us with.
  2688. */
  2689. node = prom_getchild(prom_root_node);
  2690. node = prom_searchsiblings(node, "aliases");
  2691. if (node) {
  2692. len = prom_getproperty(node, "screen", prop, sizeof(prop));
  2693. if (len > 0) {
  2694. prop[len] = '\0';
  2695. node = prom_finddevice(prop);
  2696. } else
  2697. node = 0;
  2698. }
  2699. pcp = pdev->sysdata;
  2700. if (node == pcp->prom_node->node) {
  2701. struct fb_var_screeninfo *var = &default_var;
  2702. unsigned int N, P, Q, M, T, R;
  2703. u32 v_total, h_total;
  2704. struct crtc crtc;
  2705. u8 pll_regs[16];
  2706. u8 clock_cntl;
  2707. crtc.vxres = prom_getintdefault(node, "width", 1024);
  2708. crtc.vyres = prom_getintdefault(node, "height", 768);
  2709. var->bits_per_pixel = prom_getintdefault(node, "depth", 8);
  2710. var->xoffset = var->yoffset = 0;
  2711. crtc.h_tot_disp = aty_ld_le32(CRTC_H_TOTAL_DISP, par);
  2712. crtc.h_sync_strt_wid = aty_ld_le32(CRTC_H_SYNC_STRT_WID, par);
  2713. crtc.v_tot_disp = aty_ld_le32(CRTC_V_TOTAL_DISP, par);
  2714. crtc.v_sync_strt_wid = aty_ld_le32(CRTC_V_SYNC_STRT_WID, par);
  2715. crtc.gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par);
  2716. aty_crtc_to_var(&crtc, var);
  2717. h_total = var->xres + var->right_margin + var->hsync_len + var->left_margin;
  2718. v_total = var->yres + var->lower_margin + var->vsync_len + var->upper_margin;
  2719. /*
  2720. * Read the PLL to figure actual Refresh Rate.
  2721. */
  2722. clock_cntl = aty_ld_8(CLOCK_CNTL, par);
  2723. /* DPRINTK("CLOCK_CNTL %02x\n", clock_cntl); */
  2724. for (i = 0; i < 16; i++)
  2725. pll_regs[i] = aty_ld_pll_ct(i, par);
  2726. /*
  2727. * PLL Reference Divider M:
  2728. */
  2729. M = pll_regs[2];
  2730. /*
  2731. * PLL Feedback Divider N (Dependant on CLOCK_CNTL):
  2732. */
  2733. N = pll_regs[7 + (clock_cntl & 3)];
  2734. /*
  2735. * PLL Post Divider P (Dependant on CLOCK_CNTL):
  2736. */
  2737. P = 1 << (pll_regs[6] >> ((clock_cntl & 3) << 1));
  2738. /*
  2739. * PLL Divider Q:
  2740. */
  2741. Q = N / P;
  2742. /*
  2743. * Target Frequency:
  2744. *
  2745. * T * M
  2746. * Q = -------
  2747. * 2 * R
  2748. *
  2749. * where R is XTALIN (= 14318 or 29498 kHz).
  2750. */
  2751. if (IS_XL(pdev->device))
  2752. R = 29498;
  2753. else
  2754. R = 14318;
  2755. T = 2 * Q * R / M;
  2756. default_var.pixclock = 1000000000 / T;
  2757. }
  2758. return 0;
  2759. }
  2760. #else /* __sparc__ */
  2761. #ifdef __i386__
  2762. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  2763. static void aty_init_lcd(struct atyfb_par *par, u32 bios_base)
  2764. {
  2765. u32 driv_inf_tab, sig;
  2766. u16 lcd_ofs;
  2767. /* To support an LCD panel, we should know it's dimensions and
  2768. * it's desired pixel clock.
  2769. * There are two ways to do it:
  2770. * - Check the startup video mode and calculate the panel
  2771. * size from it. This is unreliable.
  2772. * - Read it from the driver information table in the video BIOS.
  2773. */
  2774. /* Address of driver information table is at offset 0x78. */
  2775. driv_inf_tab = bios_base + *((u16 *)(bios_base+0x78));
  2776. /* Check for the driver information table signature. */
  2777. sig = (*(u32 *)driv_inf_tab);
  2778. if ((sig == 0x54504c24) || /* Rage LT pro */
  2779. (sig == 0x544d5224) || /* Rage mobility */
  2780. (sig == 0x54435824) || /* Rage XC */
  2781. (sig == 0x544c5824)) { /* Rage XL */
  2782. PRINTKI("BIOS contains driver information table.\n");
  2783. lcd_ofs = (*(u16 *)(driv_inf_tab + 10));
  2784. par->lcd_table = 0;
  2785. if (lcd_ofs != 0) {
  2786. par->lcd_table = bios_base + lcd_ofs;
  2787. }
  2788. }
  2789. if (par->lcd_table != 0) {
  2790. char model[24];
  2791. char strbuf[16];
  2792. char refresh_rates_buf[100];
  2793. int id, tech, f, i, m, default_refresh_rate;
  2794. char *txtcolour;
  2795. char *txtmonitor;
  2796. char *txtdual;
  2797. char *txtformat;
  2798. u16 width, height, panel_type, refresh_rates;
  2799. u16 *lcdmodeptr;
  2800. u32 format;
  2801. u8 lcd_refresh_rates[16] = {50,56,60,67,70,72,75,76,85,90,100,120,140,150,160,200};
  2802. /* The most important information is the panel size at
  2803. * offset 25 and 27, but there's some other nice information
  2804. * which we print to the screen.
  2805. */
  2806. id = *(u8 *)par->lcd_table;
  2807. strncpy(model,(char *)par->lcd_table+1,24);
  2808. model[23]=0;
  2809. width = par->lcd_width = *(u16 *)(par->lcd_table+25);
  2810. height = par->lcd_height = *(u16 *)(par->lcd_table+27);
  2811. panel_type = *(u16 *)(par->lcd_table+29);
  2812. if (panel_type & 1)
  2813. txtcolour = "colour";
  2814. else
  2815. txtcolour = "monochrome";
  2816. if (panel_type & 2)
  2817. txtdual = "dual (split) ";
  2818. else
  2819. txtdual = "";
  2820. tech = (panel_type>>2) & 63;
  2821. switch (tech) {
  2822. case 0:
  2823. txtmonitor = "passive matrix";
  2824. break;
  2825. case 1:
  2826. txtmonitor = "active matrix";
  2827. break;
  2828. case 2:
  2829. txtmonitor = "active addressed STN";
  2830. break;
  2831. case 3:
  2832. txtmonitor = "EL";
  2833. break;
  2834. case 4:
  2835. txtmonitor = "plasma";
  2836. break;
  2837. default:
  2838. txtmonitor = "unknown";
  2839. }
  2840. format = *(u32 *)(par->lcd_table+57);
  2841. if (tech == 0 || tech == 2) {
  2842. switch (format & 7) {
  2843. case 0:
  2844. txtformat = "12 bit interface";
  2845. break;
  2846. case 1:
  2847. txtformat = "16 bit interface";
  2848. break;
  2849. case 2:
  2850. txtformat = "24 bit interface";
  2851. break;
  2852. default:
  2853. txtformat = "unkown format";
  2854. }
  2855. } else {
  2856. switch (format & 7) {
  2857. case 0:
  2858. txtformat = "8 colours";
  2859. break;
  2860. case 1:
  2861. txtformat = "512 colours";
  2862. break;
  2863. case 2:
  2864. txtformat = "4096 colours";
  2865. break;
  2866. case 4:
  2867. txtformat = "262144 colours (LT mode)";
  2868. break;
  2869. case 5:
  2870. txtformat = "16777216 colours";
  2871. break;
  2872. case 6:
  2873. txtformat = "262144 colours (FDPI-2 mode)";
  2874. break;
  2875. default:
  2876. txtformat = "unkown format";
  2877. }
  2878. }
  2879. PRINTKI("%s%s %s monitor detected: %s\n",
  2880. txtdual ,txtcolour, txtmonitor, model);
  2881. PRINTKI(" id=%d, %dx%d pixels, %s\n",
  2882. id, width, height, txtformat);
  2883. refresh_rates_buf[0] = 0;
  2884. refresh_rates = *(u16 *)(par->lcd_table+62);
  2885. m = 1;
  2886. f = 0;
  2887. for (i=0;i<16;i++) {
  2888. if (refresh_rates & m) {
  2889. if (f == 0) {
  2890. sprintf(strbuf, "%d", lcd_refresh_rates[i]);
  2891. f++;
  2892. } else {
  2893. sprintf(strbuf, ",%d", lcd_refresh_rates[i]);
  2894. }
  2895. strcat(refresh_rates_buf,strbuf);
  2896. }
  2897. m = m << 1;
  2898. }
  2899. default_refresh_rate = (*(u8 *)(par->lcd_table+61) & 0xf0) >> 4;
  2900. PRINTKI(" supports refresh rates [%s], default %d Hz\n",
  2901. refresh_rates_buf, lcd_refresh_rates[default_refresh_rate]);
  2902. par->lcd_refreshrate = lcd_refresh_rates[default_refresh_rate];
  2903. /* We now need to determine the crtc parameters for the
  2904. * LCD monitor. This is tricky, because they are not stored
  2905. * individually in the BIOS. Instead, the BIOS contains a
  2906. * table of display modes that work for this monitor.
  2907. *
  2908. * The idea is that we search for a mode of the same dimensions
  2909. * as the dimensions of the LCD monitor. Say our LCD monitor
  2910. * is 800x600 pixels, we search for a 800x600 monitor.
  2911. * The CRTC parameters we find here are the ones that we need
  2912. * to use to simulate other resolutions on the LCD screen.
  2913. */
  2914. lcdmodeptr = (u16 *)(par->lcd_table + 64);
  2915. while (*lcdmodeptr != 0) {
  2916. u32 modeptr;
  2917. u16 mwidth, mheight, lcd_hsync_start, lcd_vsync_start;
  2918. modeptr = bios_base + *lcdmodeptr;
  2919. mwidth = *((u16 *)(modeptr+0));
  2920. mheight = *((u16 *)(modeptr+2));
  2921. if (mwidth == width && mheight == height) {
  2922. par->lcd_pixclock = 100000000 / *((u16 *)(modeptr+9));
  2923. par->lcd_htotal = *((u16 *)(modeptr+17)) & 511;
  2924. par->lcd_hdisp = *((u16 *)(modeptr+19)) & 511;
  2925. lcd_hsync_start = *((u16 *)(modeptr+21)) & 511;
  2926. par->lcd_hsync_dly = (*((u16 *)(modeptr+21)) >> 9) & 7;
  2927. par->lcd_hsync_len = *((u8 *)(modeptr+23)) & 63;
  2928. par->lcd_vtotal = *((u16 *)(modeptr+24)) & 2047;
  2929. par->lcd_vdisp = *((u16 *)(modeptr+26)) & 2047;
  2930. lcd_vsync_start = *((u16 *)(modeptr+28)) & 2047;
  2931. par->lcd_vsync_len = (*((u16 *)(modeptr+28)) >> 11) & 31;
  2932. par->lcd_htotal = (par->lcd_htotal + 1) * 8;
  2933. par->lcd_hdisp = (par->lcd_hdisp + 1) * 8;
  2934. lcd_hsync_start = (lcd_hsync_start + 1) * 8;
  2935. par->lcd_hsync_len = par->lcd_hsync_len * 8;
  2936. par->lcd_vtotal++;
  2937. par->lcd_vdisp++;
  2938. lcd_vsync_start++;
  2939. par->lcd_right_margin = lcd_hsync_start - par->lcd_hdisp;
  2940. par->lcd_lower_margin = lcd_vsync_start - par->lcd_vdisp;
  2941. par->lcd_hblank_len = par->lcd_htotal - par->lcd_hdisp;
  2942. par->lcd_vblank_len = par->lcd_vtotal - par->lcd_vdisp;
  2943. break;
  2944. }
  2945. lcdmodeptr++;
  2946. }
  2947. if (*lcdmodeptr == 0) {
  2948. PRINTKE("LCD monitor CRTC parameters not found!!!\n");
  2949. /* To do: Switch to CRT if possible. */
  2950. } else {
  2951. PRINTKI(" LCD CRTC parameters: %d.%d %d %d %d %d %d %d %d %d\n",
  2952. 1000000 / par->lcd_pixclock, 1000000 % par->lcd_pixclock,
  2953. par->lcd_hdisp,
  2954. par->lcd_hdisp + par->lcd_right_margin,
  2955. par->lcd_hdisp + par->lcd_right_margin
  2956. + par->lcd_hsync_dly + par->lcd_hsync_len,
  2957. par->lcd_htotal,
  2958. par->lcd_vdisp,
  2959. par->lcd_vdisp + par->lcd_lower_margin,
  2960. par->lcd_vdisp + par->lcd_lower_margin + par->lcd_vsync_len,
  2961. par->lcd_vtotal);
  2962. PRINTKI(" : %d %d %d %d %d %d %d %d %d\n",
  2963. par->lcd_pixclock,
  2964. par->lcd_hblank_len - (par->lcd_right_margin +
  2965. par->lcd_hsync_dly + par->lcd_hsync_len),
  2966. par->lcd_hdisp,
  2967. par->lcd_right_margin,
  2968. par->lcd_hsync_len,
  2969. par->lcd_vblank_len - (par->lcd_lower_margin + par->lcd_vsync_len),
  2970. par->lcd_vdisp,
  2971. par->lcd_lower_margin,
  2972. par->lcd_vsync_len);
  2973. }
  2974. }
  2975. }
  2976. #endif /* CONFIG_FB_ATY_GENERIC_LCD */
  2977. static int __devinit init_from_bios(struct atyfb_par *par)
  2978. {
  2979. u32 bios_base, rom_addr;
  2980. int ret;
  2981. rom_addr = 0xc0000 + ((aty_ld_le32(SCRATCH_REG1, par) & 0x7f) << 11);
  2982. bios_base = (unsigned long)ioremap(rom_addr, 0x10000);
  2983. /* The BIOS starts with 0xaa55. */
  2984. if (*((u16 *)bios_base) == 0xaa55) {
  2985. u8 *bios_ptr;
  2986. u16 rom_table_offset, freq_table_offset;
  2987. PLL_BLOCK_MACH64 pll_block;
  2988. PRINTKI("Mach64 BIOS is located at %x, mapped at %x.\n", rom_addr, bios_base);
  2989. /* check for frequncy table */
  2990. bios_ptr = (u8*)bios_base;
  2991. rom_table_offset = (u16)(bios_ptr[0x48] | (bios_ptr[0x49] << 8));
  2992. freq_table_offset = bios_ptr[rom_table_offset + 16] | (bios_ptr[rom_table_offset + 17] << 8);
  2993. memcpy(&pll_block, bios_ptr + freq_table_offset, sizeof(PLL_BLOCK_MACH64));
  2994. PRINTKI("BIOS frequency table:\n");
  2995. PRINTKI("PCLK_min_freq %d, PCLK_max_freq %d, ref_freq %d, ref_divider %d\n",
  2996. pll_block.PCLK_min_freq, pll_block.PCLK_max_freq,
  2997. pll_block.ref_freq, pll_block.ref_divider);
  2998. PRINTKI("MCLK_pwd %d, MCLK_max_freq %d, XCLK_max_freq %d, SCLK_freq %d\n",
  2999. pll_block.MCLK_pwd, pll_block.MCLK_max_freq,
  3000. pll_block.XCLK_max_freq, pll_block.SCLK_freq);
  3001. par->pll_limits.pll_min = pll_block.PCLK_min_freq/100;
  3002. par->pll_limits.pll_max = pll_block.PCLK_max_freq/100;
  3003. par->pll_limits.ref_clk = pll_block.ref_freq/100;
  3004. par->pll_limits.ref_div = pll_block.ref_divider;
  3005. par->pll_limits.sclk = pll_block.SCLK_freq/100;
  3006. par->pll_limits.mclk = pll_block.MCLK_max_freq/100;
  3007. par->pll_limits.mclk_pm = pll_block.MCLK_pwd/100;
  3008. par->pll_limits.xclk = pll_block.XCLK_max_freq/100;
  3009. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  3010. aty_init_lcd(par, bios_base);
  3011. #endif
  3012. ret = 0;
  3013. } else {
  3014. PRINTKE("no BIOS frequency table found, use parameters\n");
  3015. ret = -ENXIO;
  3016. }
  3017. iounmap((void* __iomem )bios_base);
  3018. return ret;
  3019. }
  3020. #endif /* __i386__ */
  3021. static int __devinit atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, unsigned long addr)
  3022. {
  3023. struct atyfb_par *par = info->par;
  3024. u16 tmp;
  3025. unsigned long raddr;
  3026. struct resource *rrp;
  3027. int ret = 0;
  3028. raddr = addr + 0x7ff000UL;
  3029. rrp = &pdev->resource[2];
  3030. if ((rrp->flags & IORESOURCE_MEM) && request_mem_region(rrp->start, rrp->end - rrp->start + 1, "atyfb")) {
  3031. par->aux_start = rrp->start;
  3032. par->aux_size = rrp->end - rrp->start + 1;
  3033. raddr = rrp->start;
  3034. PRINTKI("using auxiliary register aperture\n");
  3035. }
  3036. info->fix.mmio_start = raddr;
  3037. par->ati_regbase = ioremap(info->fix.mmio_start, 0x1000);
  3038. if (par->ati_regbase == 0)
  3039. return -ENOMEM;
  3040. info->fix.mmio_start += par->aux_start ? 0x400 : 0xc00;
  3041. par->ati_regbase += par->aux_start ? 0x400 : 0xc00;
  3042. /*
  3043. * Enable memory-space accesses using config-space
  3044. * command register.
  3045. */
  3046. pci_read_config_word(pdev, PCI_COMMAND, &tmp);
  3047. if (!(tmp & PCI_COMMAND_MEMORY)) {
  3048. tmp |= PCI_COMMAND_MEMORY;
  3049. pci_write_config_word(pdev, PCI_COMMAND, tmp);
  3050. }
  3051. #ifdef __BIG_ENDIAN
  3052. /* Use the big-endian aperture */
  3053. addr += 0x800000;
  3054. #endif
  3055. /* Map in frame buffer */
  3056. info->fix.smem_start = addr;
  3057. info->screen_base = ioremap(addr, 0x800000);
  3058. if (info->screen_base == NULL) {
  3059. ret = -ENOMEM;
  3060. goto atyfb_setup_generic_fail;
  3061. }
  3062. if((ret = correct_chipset(par)))
  3063. goto atyfb_setup_generic_fail;
  3064. #ifdef __i386__
  3065. if((ret = init_from_bios(par)))
  3066. goto atyfb_setup_generic_fail;
  3067. #endif
  3068. if (!(aty_ld_le32(CRTC_GEN_CNTL, par) & CRTC_EXT_DISP_EN))
  3069. par->clk_wr_offset = (inb(R_GENMO) & 0x0CU) >> 2;
  3070. else
  3071. par->clk_wr_offset = aty_ld_8(CLOCK_CNTL, par) & 0x03U;
  3072. /* according to ATI, we should use clock 3 for acelerated mode */
  3073. par->clk_wr_offset = 3;
  3074. return 0;
  3075. atyfb_setup_generic_fail:
  3076. iounmap(par->ati_regbase);
  3077. par->ati_regbase = NULL;
  3078. return ret;
  3079. }
  3080. #endif /* !__sparc__ */
  3081. static int __devinit atyfb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  3082. {
  3083. unsigned long addr, res_start, res_size;
  3084. struct fb_info *info;
  3085. struct resource *rp;
  3086. struct atyfb_par *par;
  3087. int i, rc = -ENOMEM;
  3088. for (i = ARRAY_SIZE(aty_chips) - 1; i >= 0; i--)
  3089. if (pdev->device == aty_chips[i].pci_id)
  3090. break;
  3091. if (i < 0)
  3092. return -ENODEV;
  3093. /* Enable device in PCI config */
  3094. if (pci_enable_device(pdev)) {
  3095. PRINTKE("Cannot enable PCI device\n");
  3096. return -ENXIO;
  3097. }
  3098. /* Find which resource to use */
  3099. rp = &pdev->resource[0];
  3100. if (rp->flags & IORESOURCE_IO)
  3101. rp = &pdev->resource[1];
  3102. addr = rp->start;
  3103. if (!addr)
  3104. return -ENXIO;
  3105. /* Reserve space */
  3106. res_start = rp->start;
  3107. res_size = rp->end - rp->start + 1;
  3108. if (!request_mem_region (res_start, res_size, "atyfb"))
  3109. return -EBUSY;
  3110. /* Allocate framebuffer */
  3111. info = framebuffer_alloc(sizeof(struct atyfb_par), &pdev->dev);
  3112. if (!info) {
  3113. PRINTKE("atyfb_pci_probe() can't alloc fb_info\n");
  3114. return -ENOMEM;
  3115. }
  3116. par = info->par;
  3117. info->fix = atyfb_fix;
  3118. info->device = &pdev->dev;
  3119. par->pci_id = aty_chips[i].pci_id;
  3120. par->res_start = res_start;
  3121. par->res_size = res_size;
  3122. par->irq = pdev->irq;
  3123. par->pdev = pdev;
  3124. /* Setup "info" structure */
  3125. #ifdef __sparc__
  3126. rc = atyfb_setup_sparc(pdev, info, addr);
  3127. #else
  3128. rc = atyfb_setup_generic(pdev, info, addr);
  3129. #endif
  3130. if (rc)
  3131. goto err_release_mem;
  3132. pci_set_drvdata(pdev, info);
  3133. /* Init chip & register framebuffer */
  3134. if (aty_init(info, "PCI"))
  3135. goto err_release_io;
  3136. #ifdef __sparc__
  3137. if (!prom_palette)
  3138. prom_palette = atyfb_palette;
  3139. /*
  3140. * Add /dev/fb mmap values.
  3141. */
  3142. par->mmap_map[0].voff = 0x8000000000000000UL;
  3143. par->mmap_map[0].poff = (unsigned long) info->screen_base & PAGE_MASK;
  3144. par->mmap_map[0].size = info->fix.smem_len;
  3145. par->mmap_map[0].prot_mask = _PAGE_CACHE;
  3146. par->mmap_map[0].prot_flag = _PAGE_E;
  3147. par->mmap_map[1].voff = par->mmap_map[0].voff + info->fix.smem_len;
  3148. par->mmap_map[1].poff = (long)par->ati_regbase & PAGE_MASK;
  3149. par->mmap_map[1].size = PAGE_SIZE;
  3150. par->mmap_map[1].prot_mask = _PAGE_CACHE;
  3151. par->mmap_map[1].prot_flag = _PAGE_E;
  3152. #endif /* __sparc__ */
  3153. return 0;
  3154. err_release_io:
  3155. #ifdef __sparc__
  3156. kfree(par->mmap_map);
  3157. #else
  3158. if (par->ati_regbase)
  3159. iounmap(par->ati_regbase);
  3160. if (info->screen_base)
  3161. iounmap(info->screen_base);
  3162. #endif
  3163. err_release_mem:
  3164. if (par->aux_start)
  3165. release_mem_region(par->aux_start, par->aux_size);
  3166. release_mem_region(par->res_start, par->res_size);
  3167. framebuffer_release(info);
  3168. return rc;
  3169. }
  3170. #endif /* CONFIG_PCI */
  3171. #ifdef CONFIG_ATARI
  3172. static int __devinit atyfb_atari_probe(void)
  3173. {
  3174. struct atyfb_par *par;
  3175. struct fb_info *info;
  3176. int m64_num;
  3177. u32 clock_r;
  3178. for (m64_num = 0; m64_num < mach64_count; m64_num++) {
  3179. if (!phys_vmembase[m64_num] || !phys_size[m64_num] ||
  3180. !phys_guiregbase[m64_num]) {
  3181. PRINTKI("phys_*[%d] parameters not set => returning early. \n", m64_num);
  3182. continue;
  3183. }
  3184. info = framebuffer_alloc(sizeof(struct atyfb_par), NULL);
  3185. if (!info) {
  3186. PRINTKE("atyfb_atari_probe() can't alloc fb_info\n");
  3187. return -ENOMEM;
  3188. }
  3189. par = info->par;
  3190. info->fix = atyfb_fix;
  3191. par->irq = (unsigned int) -1; /* something invalid */
  3192. /*
  3193. * Map the video memory (physical address given) to somewhere in the
  3194. * kernel address space.
  3195. */
  3196. info->screen_base = ioremap(phys_vmembase[m64_num], phys_size[m64_num]);
  3197. info->fix.smem_start = (unsigned long)info->screen_base; /* Fake! */
  3198. par->ati_regbase = ioremap(phys_guiregbase[m64_num], 0x10000) +
  3199. 0xFC00ul;
  3200. info->fix.mmio_start = (unsigned long)par->ati_regbase; /* Fake! */
  3201. aty_st_le32(CLOCK_CNTL, 0x12345678, par);
  3202. clock_r = aty_ld_le32(CLOCK_CNTL, par);
  3203. switch (clock_r & 0x003F) {
  3204. case 0x12:
  3205. par->clk_wr_offset = 3; /* */
  3206. break;
  3207. case 0x34:
  3208. par->clk_wr_offset = 2; /* Medusa ST-IO ISA Adapter etc. */
  3209. break;
  3210. case 0x16:
  3211. par->clk_wr_offset = 1; /* */
  3212. break;
  3213. case 0x38:
  3214. par->clk_wr_offset = 0; /* Panther 1 ISA Adapter (Gerald) */
  3215. break;
  3216. }
  3217. if (aty_init(info, "ISA bus")) {
  3218. framebuffer_release(info);
  3219. /* This is insufficient! kernel_map has added two large chunks!! */
  3220. return -ENXIO;
  3221. }
  3222. }
  3223. }
  3224. #endif /* CONFIG_ATARI */
  3225. static void __devexit atyfb_remove(struct fb_info *info)
  3226. {
  3227. struct atyfb_par *par = (struct atyfb_par *) info->par;
  3228. /* restore video mode */
  3229. aty_set_crtc(par, &saved_crtc);
  3230. par->pll_ops->set_pll(info, &saved_pll);
  3231. #ifdef CONFIG_FB_ATY_BACKLIGHT
  3232. if (M64_HAS(MOBIL_BUS))
  3233. aty_bl_exit(par);
  3234. #endif
  3235. unregister_framebuffer(info);
  3236. #ifdef CONFIG_MTRR
  3237. if (par->mtrr_reg >= 0) {
  3238. mtrr_del(par->mtrr_reg, 0, 0);
  3239. par->mtrr_reg = -1;
  3240. }
  3241. if (par->mtrr_aper >= 0) {
  3242. mtrr_del(par->mtrr_aper, 0, 0);
  3243. par->mtrr_aper = -1;
  3244. }
  3245. #endif
  3246. #ifndef __sparc__
  3247. if (par->ati_regbase)
  3248. iounmap(par->ati_regbase);
  3249. if (info->screen_base)
  3250. iounmap(info->screen_base);
  3251. #ifdef __BIG_ENDIAN
  3252. if (info->sprite.addr)
  3253. iounmap(info->sprite.addr);
  3254. #endif
  3255. #endif
  3256. #ifdef __sparc__
  3257. kfree(par->mmap_map);
  3258. #endif
  3259. if (par->aux_start)
  3260. release_mem_region(par->aux_start, par->aux_size);
  3261. if (par->res_start)
  3262. release_mem_region(par->res_start, par->res_size);
  3263. framebuffer_release(info);
  3264. }
  3265. #ifdef CONFIG_PCI
  3266. static void __devexit atyfb_pci_remove(struct pci_dev *pdev)
  3267. {
  3268. struct fb_info *info = pci_get_drvdata(pdev);
  3269. atyfb_remove(info);
  3270. }
  3271. /*
  3272. * This driver uses its own matching table. That will be more difficult
  3273. * to fix, so for now, we just match against any ATI ID and let the
  3274. * probe() function find out what's up. That also mean we don't have
  3275. * a module ID table though.
  3276. */
  3277. static struct pci_device_id atyfb_pci_tbl[] = {
  3278. { PCI_VENDOR_ID_ATI, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  3279. PCI_BASE_CLASS_DISPLAY << 16, 0xff0000, 0 },
  3280. { 0, }
  3281. };
  3282. static struct pci_driver atyfb_driver = {
  3283. .name = "atyfb",
  3284. .id_table = atyfb_pci_tbl,
  3285. .probe = atyfb_pci_probe,
  3286. .remove = __devexit_p(atyfb_pci_remove),
  3287. #ifdef CONFIG_PM
  3288. .suspend = atyfb_pci_suspend,
  3289. .resume = atyfb_pci_resume,
  3290. #endif /* CONFIG_PM */
  3291. };
  3292. #endif /* CONFIG_PCI */
  3293. #ifndef MODULE
  3294. static int __devinit atyfb_setup(char *options)
  3295. {
  3296. char *this_opt;
  3297. if (!options || !*options)
  3298. return 0;
  3299. while ((this_opt = strsep(&options, ",")) != NULL) {
  3300. if (!strncmp(this_opt, "noaccel", 7)) {
  3301. noaccel = 1;
  3302. #ifdef CONFIG_MTRR
  3303. } else if (!strncmp(this_opt, "nomtrr", 6)) {
  3304. nomtrr = 1;
  3305. #endif
  3306. } else if (!strncmp(this_opt, "vram:", 5))
  3307. vram = simple_strtoul(this_opt + 5, NULL, 0);
  3308. else if (!strncmp(this_opt, "pll:", 4))
  3309. pll = simple_strtoul(this_opt + 4, NULL, 0);
  3310. else if (!strncmp(this_opt, "mclk:", 5))
  3311. mclk = simple_strtoul(this_opt + 5, NULL, 0);
  3312. else if (!strncmp(this_opt, "xclk:", 5))
  3313. xclk = simple_strtoul(this_opt+5, NULL, 0);
  3314. else if (!strncmp(this_opt, "comp_sync:", 10))
  3315. comp_sync = simple_strtoul(this_opt+10, NULL, 0);
  3316. #ifdef CONFIG_PPC
  3317. else if (!strncmp(this_opt, "vmode:", 6)) {
  3318. unsigned int vmode =
  3319. simple_strtoul(this_opt + 6, NULL, 0);
  3320. if (vmode > 0 && vmode <= VMODE_MAX)
  3321. default_vmode = vmode;
  3322. } else if (!strncmp(this_opt, "cmode:", 6)) {
  3323. unsigned int cmode =
  3324. simple_strtoul(this_opt + 6, NULL, 0);
  3325. switch (cmode) {
  3326. case 0:
  3327. case 8:
  3328. default_cmode = CMODE_8;
  3329. break;
  3330. case 15:
  3331. case 16:
  3332. default_cmode = CMODE_16;
  3333. break;
  3334. case 24:
  3335. case 32:
  3336. default_cmode = CMODE_32;
  3337. break;
  3338. }
  3339. }
  3340. #endif
  3341. #ifdef CONFIG_ATARI
  3342. /*
  3343. * Why do we need this silly Mach64 argument?
  3344. * We are already here because of mach64= so its redundant.
  3345. */
  3346. else if (MACH_IS_ATARI
  3347. && (!strncmp(this_opt, "Mach64:", 7))) {
  3348. static unsigned char m64_num;
  3349. static char mach64_str[80];
  3350. strlcpy(mach64_str, this_opt + 7, sizeof(mach64_str));
  3351. if (!store_video_par(mach64_str, m64_num)) {
  3352. m64_num++;
  3353. mach64_count = m64_num;
  3354. }
  3355. }
  3356. #endif
  3357. else
  3358. mode = this_opt;
  3359. }
  3360. return 0;
  3361. }
  3362. #endif /* MODULE */
  3363. static int __devinit atyfb_init(void)
  3364. {
  3365. int err1 = 1, err2 = 1;
  3366. #ifndef MODULE
  3367. char *option = NULL;
  3368. if (fb_get_options("atyfb", &option))
  3369. return -ENODEV;
  3370. atyfb_setup(option);
  3371. #endif
  3372. #ifdef CONFIG_PCI
  3373. err1 = pci_register_driver(&atyfb_driver);
  3374. #endif
  3375. #ifdef CONFIG_ATARI
  3376. err2 = atyfb_atari_probe();
  3377. #endif
  3378. return (err1 && err2) ? -ENODEV : 0;
  3379. }
  3380. static void __exit atyfb_exit(void)
  3381. {
  3382. #ifdef CONFIG_PCI
  3383. pci_unregister_driver(&atyfb_driver);
  3384. #endif
  3385. }
  3386. module_init(atyfb_init);
  3387. module_exit(atyfb_exit);
  3388. MODULE_DESCRIPTION("FBDev driver for ATI Mach64 cards");
  3389. MODULE_LICENSE("GPL");
  3390. module_param(noaccel, bool, 0);
  3391. MODULE_PARM_DESC(noaccel, "bool: disable acceleration");
  3392. module_param(vram, int, 0);
  3393. MODULE_PARM_DESC(vram, "int: override size of video ram");
  3394. module_param(pll, int, 0);
  3395. MODULE_PARM_DESC(pll, "int: override video clock");
  3396. module_param(mclk, int, 0);
  3397. MODULE_PARM_DESC(mclk, "int: override memory clock");
  3398. module_param(xclk, int, 0);
  3399. MODULE_PARM_DESC(xclk, "int: override accelerated engine clock");
  3400. module_param(comp_sync, int, 0);
  3401. MODULE_PARM_DESC(comp_sync,
  3402. "Set composite sync signal to low (0) or high (1)");
  3403. module_param(mode, charp, 0);
  3404. MODULE_PARM_DESC(mode, "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
  3405. #ifdef CONFIG_MTRR
  3406. module_param(nomtrr, bool, 0);
  3407. MODULE_PARM_DESC(nomtrr, "bool: disable use of MTRR registers");
  3408. #endif