atyfb_base.c 109 KB

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