atyfb_base.c 109 KB

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