atyfb_base.c 108 KB

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