atyfb_base.c 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760
  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/config.h>
  46. #include <linux/module.h>
  47. #include <linux/moduleparam.h>
  48. #include <linux/kernel.h>
  49. #include <linux/errno.h>
  50. #include <linux/string.h>
  51. #include <linux/mm.h>
  52. #include <linux/slab.h>
  53. #include <linux/vmalloc.h>
  54. #include <linux/delay.h>
  55. #include <linux/console.h>
  56. #include <linux/fb.h>
  57. #include <linux/init.h>
  58. #include <linux/pci.h>
  59. #include <linux/interrupt.h>
  60. #include <linux/spinlock.h>
  61. #include <linux/wait.h>
  62. #include <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 __initdata = -1;
  280. static char *mode;
  281. #ifdef CONFIG_PPC
  282. static int default_vmode __initdata = VMODE_CHOOSE;
  283. static int default_cmode __initdata = 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 __initdata = 0;
  291. static unsigned long phys_vmembase[FB_MAX] __initdata = { 0, };
  292. static unsigned long phys_size[FB_MAX] __initdata = { 0, };
  293. static unsigned long phys_guiregbase[FB_MAX] __initdata = { 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 __init 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 (par->blitter_may_be_busy)
  1123. wait_for_idle(par);
  1124. aty_set_crtc(par, &par->crtc);
  1125. par->dac_ops->set_dac(info, &par->pll, var->bits_per_pixel, par->accel_flags);
  1126. par->pll_ops->set_pll(info, &par->pll);
  1127. #ifdef DEBUG
  1128. if(par->pll_ops && par->pll_ops->pll_to_var)
  1129. pixclock_in_ps = par->pll_ops->pll_to_var(info, &(par->pll));
  1130. else
  1131. pixclock_in_ps = 0;
  1132. if(0 == pixclock_in_ps) {
  1133. PRINTKE("ALERT ops->pll_to_var get 0\n");
  1134. pixclock_in_ps = pixclock;
  1135. }
  1136. memset(&debug, 0, sizeof(debug));
  1137. if(!aty_crtc_to_var(&(par->crtc), &debug)) {
  1138. u32 hSync, vRefresh;
  1139. u32 h_disp, h_sync_strt, h_sync_end, h_total;
  1140. u32 v_disp, v_sync_strt, v_sync_end, v_total;
  1141. h_disp = debug.xres;
  1142. h_sync_strt = h_disp + debug.right_margin;
  1143. h_sync_end = h_sync_strt + debug.hsync_len;
  1144. h_total = h_sync_end + debug.left_margin;
  1145. v_disp = debug.yres;
  1146. v_sync_strt = v_disp + debug.lower_margin;
  1147. v_sync_end = v_sync_strt + debug.vsync_len;
  1148. v_total = v_sync_end + debug.upper_margin;
  1149. hSync = 1000000000 / (pixclock_in_ps * h_total);
  1150. vRefresh = (hSync * 1000) / v_total;
  1151. if (par->crtc.gen_cntl & CRTC_INTERLACE_EN)
  1152. vRefresh *= 2;
  1153. if (par->crtc.gen_cntl & CRTC_DBL_SCAN_EN)
  1154. vRefresh /= 2;
  1155. DPRINTK("atyfb_set_par\n");
  1156. DPRINTK(" Set Visible Mode to %ix%i-%i\n", var->xres, var->yres, var->bits_per_pixel);
  1157. DPRINTK(" Virtual resolution %ix%i, pixclock_in_ps %i (calculated %i)\n",
  1158. var->xres_virtual, var->yres_virtual, pixclock, pixclock_in_ps);
  1159. DPRINTK(" Dot clock: %i MHz\n", 1000000 / pixclock_in_ps);
  1160. DPRINTK(" Horizontal sync: %i kHz\n", hSync);
  1161. DPRINTK(" Vertical refresh: %i Hz\n", vRefresh);
  1162. DPRINTK(" x style: %i.%03i %i %i %i %i %i %i %i %i\n",
  1163. 1000000 / pixclock_in_ps, 1000000 % pixclock_in_ps,
  1164. h_disp, h_sync_strt, h_sync_end, h_total,
  1165. v_disp, v_sync_strt, v_sync_end, v_total);
  1166. DPRINTK(" fb style: %i %i %i %i %i %i %i %i %i\n",
  1167. pixclock_in_ps,
  1168. debug.left_margin, h_disp, debug.right_margin, debug.hsync_len,
  1169. debug.upper_margin, v_disp, debug.lower_margin, debug.vsync_len);
  1170. }
  1171. #endif /* DEBUG */
  1172. if (!M64_HAS(INTEGRATED)) {
  1173. /* Don't forget MEM_CNTL */
  1174. tmp = aty_ld_le32(MEM_CNTL, par) & 0xf0ffffff;
  1175. switch (var->bits_per_pixel) {
  1176. case 8:
  1177. tmp |= 0x02000000;
  1178. break;
  1179. case 16:
  1180. tmp |= 0x03000000;
  1181. break;
  1182. case 32:
  1183. tmp |= 0x06000000;
  1184. break;
  1185. }
  1186. aty_st_le32(MEM_CNTL, tmp, par);
  1187. } else {
  1188. tmp = aty_ld_le32(MEM_CNTL, par) & 0xf00fffff;
  1189. if (!M64_HAS(MAGIC_POSTDIV))
  1190. tmp |= par->mem_refresh_rate << 20;
  1191. switch (var->bits_per_pixel) {
  1192. case 8:
  1193. case 24:
  1194. tmp |= 0x00000000;
  1195. break;
  1196. case 16:
  1197. tmp |= 0x04000000;
  1198. break;
  1199. case 32:
  1200. tmp |= 0x08000000;
  1201. break;
  1202. }
  1203. if (M64_HAS(CT_BUS)) {
  1204. aty_st_le32(DAC_CNTL, 0x87010184, par);
  1205. aty_st_le32(BUS_CNTL, 0x680000f9, par);
  1206. } else if (M64_HAS(VT_BUS)) {
  1207. aty_st_le32(DAC_CNTL, 0x87010184, par);
  1208. aty_st_le32(BUS_CNTL, 0x680000f9, par);
  1209. } else if (M64_HAS(MOBIL_BUS)) {
  1210. aty_st_le32(DAC_CNTL, 0x80010102, par);
  1211. aty_st_le32(BUS_CNTL, 0x7b33a040 | (par->aux_start ? BUS_APER_REG_DIS : 0), par);
  1212. } else {
  1213. /* GT */
  1214. aty_st_le32(DAC_CNTL, 0x86010102, par);
  1215. aty_st_le32(BUS_CNTL, 0x7b23a040 | (par->aux_start ? BUS_APER_REG_DIS : 0), par);
  1216. aty_st_le32(EXT_MEM_CNTL, aty_ld_le32(EXT_MEM_CNTL, par) | 0x5000001, par);
  1217. }
  1218. aty_st_le32(MEM_CNTL, tmp, par);
  1219. }
  1220. aty_st_8(DAC_MASK, 0xff, par);
  1221. info->fix.line_length = var->xres_virtual * var->bits_per_pixel/8;
  1222. info->fix.visual = var->bits_per_pixel <= 8 ?
  1223. FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
  1224. /* Initialize the graphics engine */
  1225. if (par->accel_flags & FB_ACCELF_TEXT)
  1226. aty_init_engine(par, info);
  1227. #ifdef CONFIG_BOOTX_TEXT
  1228. btext_update_display(info->fix.smem_start,
  1229. (((par->crtc.h_tot_disp >> 16) & 0xff) + 1) * 8,
  1230. ((par->crtc.v_tot_disp >> 16) & 0x7ff) + 1,
  1231. var->bits_per_pixel,
  1232. par->crtc.vxres * var->bits_per_pixel / 8);
  1233. #endif /* CONFIG_BOOTX_TEXT */
  1234. #if 0
  1235. /* switch to accelerator mode */
  1236. if (!(par->crtc.gen_cntl & CRTC_EXT_DISP_EN))
  1237. aty_st_le32(CRTC_GEN_CNTL, par->crtc.gen_cntl | CRTC_EXT_DISP_EN, par);
  1238. #endif
  1239. #ifdef DEBUG
  1240. {
  1241. /* dump non shadow CRTC, pll, LCD registers */
  1242. int i; u32 base;
  1243. /* CRTC registers */
  1244. base = 0x2000;
  1245. printk("debug atyfb: Mach64 non-shadow register values:");
  1246. for (i = 0; i < 256; i = i+4) {
  1247. if(i%16 == 0) printk("\ndebug atyfb: 0x%04X: ", base + i);
  1248. printk(" %08X", aty_ld_le32(i, par));
  1249. }
  1250. printk("\n\n");
  1251. #ifdef CONFIG_FB_ATY_CT
  1252. /* PLL registers */
  1253. base = 0x00;
  1254. printk("debug atyfb: Mach64 PLL register values:");
  1255. for (i = 0; i < 64; i++) {
  1256. if(i%16 == 0) printk("\ndebug atyfb: 0x%02X: ", base + i);
  1257. if(i%4 == 0) printk(" ");
  1258. printk("%02X", aty_ld_pll_ct(i, par));
  1259. }
  1260. printk("\n\n");
  1261. #endif /* CONFIG_FB_ATY_CT */
  1262. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  1263. if (par->lcd_table != 0) {
  1264. /* LCD registers */
  1265. base = 0x00;
  1266. printk("debug atyfb: LCD register values:");
  1267. if(M64_HAS(LT_LCD_REGS)) {
  1268. for(i = 0; i <= POWER_MANAGEMENT; i++) {
  1269. if(i == EXT_VERT_STRETCH)
  1270. continue;
  1271. printk("\ndebug atyfb: 0x%04X: ", lt_lcd_regs[i]);
  1272. printk(" %08X", aty_ld_lcd(i, par));
  1273. }
  1274. } else {
  1275. for (i = 0; i < 64; i++) {
  1276. if(i%4 == 0) printk("\ndebug atyfb: 0x%02X: ", base + i);
  1277. printk(" %08X", aty_ld_lcd(i, par));
  1278. }
  1279. }
  1280. printk("\n\n");
  1281. }
  1282. #endif /* CONFIG_FB_ATY_GENERIC_LCD */
  1283. }
  1284. #endif /* DEBUG */
  1285. return 0;
  1286. }
  1287. static int atyfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  1288. {
  1289. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1290. int err;
  1291. struct crtc crtc;
  1292. union aty_pll pll;
  1293. u32 pixclock;
  1294. memcpy(&pll, &(par->pll), sizeof(pll));
  1295. if((err = aty_var_to_crtc(info, var, &crtc)))
  1296. return err;
  1297. pixclock = atyfb_get_pixclock(var, par);
  1298. if (pixclock == 0) {
  1299. if (!(var->activate & FB_ACTIVATE_TEST))
  1300. PRINTKE("Invalid pixclock\n");
  1301. return -EINVAL;
  1302. } else {
  1303. if((err = par->pll_ops->var_to_pll(info, pixclock, var->bits_per_pixel, &pll)))
  1304. return err;
  1305. }
  1306. if (var->accel_flags & FB_ACCELF_TEXT)
  1307. info->var.accel_flags = FB_ACCELF_TEXT;
  1308. else
  1309. info->var.accel_flags = 0;
  1310. #if 0 /* fbmon is not done. uncomment for 2.5.x -brad */
  1311. if (!fbmon_valid_timings(pixclock, htotal, vtotal, info))
  1312. return -EINVAL;
  1313. #endif
  1314. aty_crtc_to_var(&crtc, var);
  1315. var->pixclock = par->pll_ops->pll_to_var(info, &pll);
  1316. return 0;
  1317. }
  1318. static void set_off_pitch(struct atyfb_par *par, const struct fb_info *info)
  1319. {
  1320. u32 xoffset = info->var.xoffset;
  1321. u32 yoffset = info->var.yoffset;
  1322. u32 vxres = par->crtc.vxres;
  1323. u32 bpp = info->var.bits_per_pixel;
  1324. par->crtc.off_pitch = ((yoffset * vxres + xoffset) * bpp / 64) | (vxres << 19);
  1325. }
  1326. /*
  1327. * Open/Release the frame buffer device
  1328. */
  1329. static int atyfb_open(struct fb_info *info, int user)
  1330. {
  1331. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1332. if (user) {
  1333. par->open++;
  1334. #ifdef __sparc__
  1335. par->mmaped = 0;
  1336. #endif
  1337. }
  1338. return (0);
  1339. }
  1340. static irqreturn_t aty_irq(int irq, void *dev_id, struct pt_regs *fp)
  1341. {
  1342. struct atyfb_par *par = dev_id;
  1343. int handled = 0;
  1344. u32 int_cntl;
  1345. spin_lock(&par->int_lock);
  1346. int_cntl = aty_ld_le32(CRTC_INT_CNTL, par);
  1347. if (int_cntl & CRTC_VBLANK_INT) {
  1348. /* clear interrupt */
  1349. aty_st_le32(CRTC_INT_CNTL, (int_cntl & CRTC_INT_EN_MASK) | CRTC_VBLANK_INT_AK, par);
  1350. par->vblank.count++;
  1351. if (par->vblank.pan_display) {
  1352. par->vblank.pan_display = 0;
  1353. aty_st_le32(CRTC_OFF_PITCH, par->crtc.off_pitch, par);
  1354. }
  1355. wake_up_interruptible(&par->vblank.wait);
  1356. handled = 1;
  1357. }
  1358. spin_unlock(&par->int_lock);
  1359. return IRQ_RETVAL(handled);
  1360. }
  1361. static int aty_enable_irq(struct atyfb_par *par, int reenable)
  1362. {
  1363. u32 int_cntl;
  1364. if (!test_and_set_bit(0, &par->irq_flags)) {
  1365. if (request_irq(par->irq, aty_irq, SA_SHIRQ, "atyfb", par)) {
  1366. clear_bit(0, &par->irq_flags);
  1367. return -EINVAL;
  1368. }
  1369. spin_lock_irq(&par->int_lock);
  1370. int_cntl = aty_ld_le32(CRTC_INT_CNTL, par) & CRTC_INT_EN_MASK;
  1371. /* clear interrupt */
  1372. aty_st_le32(CRTC_INT_CNTL, int_cntl | CRTC_VBLANK_INT_AK, par);
  1373. /* enable interrupt */
  1374. aty_st_le32(CRTC_INT_CNTL, int_cntl | CRTC_VBLANK_INT_EN, par);
  1375. spin_unlock_irq(&par->int_lock);
  1376. } else if (reenable) {
  1377. spin_lock_irq(&par->int_lock);
  1378. int_cntl = aty_ld_le32(CRTC_INT_CNTL, par) & CRTC_INT_EN_MASK;
  1379. if (!(int_cntl & CRTC_VBLANK_INT_EN)) {
  1380. printk("atyfb: someone disabled IRQ [%08x]\n", int_cntl);
  1381. /* re-enable interrupt */
  1382. aty_st_le32(CRTC_INT_CNTL, int_cntl | CRTC_VBLANK_INT_EN, par );
  1383. }
  1384. spin_unlock_irq(&par->int_lock);
  1385. }
  1386. return 0;
  1387. }
  1388. static int aty_disable_irq(struct atyfb_par *par)
  1389. {
  1390. u32 int_cntl;
  1391. if (test_and_clear_bit(0, &par->irq_flags)) {
  1392. if (par->vblank.pan_display) {
  1393. par->vblank.pan_display = 0;
  1394. aty_st_le32(CRTC_OFF_PITCH, par->crtc.off_pitch, par);
  1395. }
  1396. spin_lock_irq(&par->int_lock);
  1397. int_cntl = aty_ld_le32(CRTC_INT_CNTL, par) & CRTC_INT_EN_MASK;
  1398. /* disable interrupt */
  1399. aty_st_le32(CRTC_INT_CNTL, int_cntl & ~CRTC_VBLANK_INT_EN, par );
  1400. spin_unlock_irq(&par->int_lock);
  1401. free_irq(par->irq, par);
  1402. }
  1403. return 0;
  1404. }
  1405. static int atyfb_release(struct fb_info *info, int user)
  1406. {
  1407. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1408. if (user) {
  1409. par->open--;
  1410. mdelay(1);
  1411. wait_for_idle(par);
  1412. if (!par->open) {
  1413. #ifdef __sparc__
  1414. int was_mmaped = par->mmaped;
  1415. par->mmaped = 0;
  1416. if (was_mmaped) {
  1417. struct fb_var_screeninfo var;
  1418. /* Now reset the default display config, we have no
  1419. * idea what the program(s) which mmap'd the chip did
  1420. * to the configuration, nor whether it restored it
  1421. * correctly.
  1422. */
  1423. var = default_var;
  1424. if (noaccel)
  1425. var.accel_flags &= ~FB_ACCELF_TEXT;
  1426. else
  1427. var.accel_flags |= FB_ACCELF_TEXT;
  1428. if (var.yres == var.yres_virtual) {
  1429. u32 videoram = (info->fix.smem_len - (PAGE_SIZE << 2));
  1430. var.yres_virtual = ((videoram * 8) / var.bits_per_pixel) / var.xres_virtual;
  1431. if (var.yres_virtual < var.yres)
  1432. var.yres_virtual = var.yres;
  1433. }
  1434. }
  1435. #endif
  1436. aty_disable_irq(par);
  1437. }
  1438. }
  1439. return (0);
  1440. }
  1441. /*
  1442. * Pan or Wrap the Display
  1443. *
  1444. * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
  1445. */
  1446. static int atyfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  1447. {
  1448. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1449. u32 xres, yres, xoffset, yoffset;
  1450. xres = (((par->crtc.h_tot_disp >> 16) & 0xff) + 1) * 8;
  1451. yres = ((par->crtc.v_tot_disp >> 16) & 0x7ff) + 1;
  1452. if (par->crtc.gen_cntl & CRTC_DBL_SCAN_EN)
  1453. yres >>= 1;
  1454. xoffset = (var->xoffset + 7) & ~7;
  1455. yoffset = var->yoffset;
  1456. if (xoffset + xres > par->crtc.vxres || yoffset + yres > par->crtc.vyres)
  1457. return -EINVAL;
  1458. info->var.xoffset = xoffset;
  1459. info->var.yoffset = yoffset;
  1460. if (par->asleep)
  1461. return 0;
  1462. set_off_pitch(par, info);
  1463. if ((var->activate & FB_ACTIVATE_VBL) && !aty_enable_irq(par, 0)) {
  1464. par->vblank.pan_display = 1;
  1465. } else {
  1466. par->vblank.pan_display = 0;
  1467. aty_st_le32(CRTC_OFF_PITCH, par->crtc.off_pitch, par);
  1468. }
  1469. return 0;
  1470. }
  1471. static int aty_waitforvblank(struct atyfb_par *par, u32 crtc)
  1472. {
  1473. struct aty_interrupt *vbl;
  1474. unsigned int count;
  1475. int ret;
  1476. switch (crtc) {
  1477. case 0:
  1478. vbl = &par->vblank;
  1479. break;
  1480. default:
  1481. return -ENODEV;
  1482. }
  1483. ret = aty_enable_irq(par, 0);
  1484. if (ret)
  1485. return ret;
  1486. count = vbl->count;
  1487. ret = wait_event_interruptible_timeout(vbl->wait, count != vbl->count, HZ/10);
  1488. if (ret < 0) {
  1489. return ret;
  1490. }
  1491. if (ret == 0) {
  1492. aty_enable_irq(par, 1);
  1493. return -ETIMEDOUT;
  1494. }
  1495. return 0;
  1496. }
  1497. #ifdef DEBUG
  1498. #define ATYIO_CLKR 0x41545900 /* ATY\00 */
  1499. #define ATYIO_CLKW 0x41545901 /* ATY\01 */
  1500. struct atyclk {
  1501. u32 ref_clk_per;
  1502. u8 pll_ref_div;
  1503. u8 mclk_fb_div;
  1504. u8 mclk_post_div; /* 1,2,3,4,8 */
  1505. u8 mclk_fb_mult; /* 2 or 4 */
  1506. u8 xclk_post_div; /* 1,2,3,4,8 */
  1507. u8 vclk_fb_div;
  1508. u8 vclk_post_div; /* 1,2,3,4,6,8,12 */
  1509. u32 dsp_xclks_per_row; /* 0-16383 */
  1510. u32 dsp_loop_latency; /* 0-15 */
  1511. u32 dsp_precision; /* 0-7 */
  1512. u32 dsp_on; /* 0-2047 */
  1513. u32 dsp_off; /* 0-2047 */
  1514. };
  1515. #define ATYIO_FEATR 0x41545902 /* ATY\02 */
  1516. #define ATYIO_FEATW 0x41545903 /* ATY\03 */
  1517. #endif
  1518. #ifndef FBIO_WAITFORVSYNC
  1519. #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
  1520. #endif
  1521. static int atyfb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
  1522. {
  1523. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1524. #ifdef __sparc__
  1525. struct fbtype fbtyp;
  1526. #endif
  1527. switch (cmd) {
  1528. #ifdef __sparc__
  1529. case FBIOGTYPE:
  1530. fbtyp.fb_type = FBTYPE_PCI_GENERIC;
  1531. fbtyp.fb_width = par->crtc.vxres;
  1532. fbtyp.fb_height = par->crtc.vyres;
  1533. fbtyp.fb_depth = info->var.bits_per_pixel;
  1534. fbtyp.fb_cmsize = info->cmap.len;
  1535. fbtyp.fb_size = info->fix.smem_len;
  1536. if (copy_to_user((struct fbtype __user *) arg, &fbtyp, sizeof(fbtyp)))
  1537. return -EFAULT;
  1538. break;
  1539. #endif /* __sparc__ */
  1540. case FBIO_WAITFORVSYNC:
  1541. {
  1542. u32 crtc;
  1543. if (get_user(crtc, (__u32 __user *) arg))
  1544. return -EFAULT;
  1545. return aty_waitforvblank(par, crtc);
  1546. }
  1547. break;
  1548. #if defined(DEBUG) && defined(CONFIG_FB_ATY_CT)
  1549. case ATYIO_CLKR:
  1550. if (M64_HAS(INTEGRATED)) {
  1551. struct atyclk clk;
  1552. union aty_pll *pll = &(par->pll);
  1553. u32 dsp_config = pll->ct.dsp_config;
  1554. u32 dsp_on_off = pll->ct.dsp_on_off;
  1555. clk.ref_clk_per = par->ref_clk_per;
  1556. clk.pll_ref_div = pll->ct.pll_ref_div;
  1557. clk.mclk_fb_div = pll->ct.mclk_fb_div;
  1558. clk.mclk_post_div = pll->ct.mclk_post_div_real;
  1559. clk.mclk_fb_mult = pll->ct.mclk_fb_mult;
  1560. clk.xclk_post_div = pll->ct.xclk_post_div_real;
  1561. clk.vclk_fb_div = pll->ct.vclk_fb_div;
  1562. clk.vclk_post_div = pll->ct.vclk_post_div_real;
  1563. clk.dsp_xclks_per_row = dsp_config & 0x3fff;
  1564. clk.dsp_loop_latency = (dsp_config >> 16) & 0xf;
  1565. clk.dsp_precision = (dsp_config >> 20) & 7;
  1566. clk.dsp_off = dsp_on_off & 0x7ff;
  1567. clk.dsp_on = (dsp_on_off >> 16) & 0x7ff;
  1568. if (copy_to_user((struct atyclk __user *) arg, &clk,
  1569. sizeof(clk)))
  1570. return -EFAULT;
  1571. } else
  1572. return -EINVAL;
  1573. break;
  1574. case ATYIO_CLKW:
  1575. if (M64_HAS(INTEGRATED)) {
  1576. struct atyclk clk;
  1577. union aty_pll *pll = &(par->pll);
  1578. if (copy_from_user(&clk, (struct atyclk __user *) arg, sizeof(clk)))
  1579. return -EFAULT;
  1580. par->ref_clk_per = clk.ref_clk_per;
  1581. pll->ct.pll_ref_div = clk.pll_ref_div;
  1582. pll->ct.mclk_fb_div = clk.mclk_fb_div;
  1583. pll->ct.mclk_post_div_real = clk.mclk_post_div;
  1584. pll->ct.mclk_fb_mult = clk.mclk_fb_mult;
  1585. pll->ct.xclk_post_div_real = clk.xclk_post_div;
  1586. pll->ct.vclk_fb_div = clk.vclk_fb_div;
  1587. pll->ct.vclk_post_div_real = clk.vclk_post_div;
  1588. pll->ct.dsp_config = (clk.dsp_xclks_per_row & 0x3fff) |
  1589. ((clk.dsp_loop_latency & 0xf)<<16)| ((clk.dsp_precision & 7)<<20);
  1590. pll->ct.dsp_on_off = (clk.dsp_off & 0x7ff) | ((clk.dsp_on & 0x7ff)<<16);
  1591. /*aty_calc_pll_ct(info, &pll->ct);*/
  1592. aty_set_pll_ct(info, pll);
  1593. } else
  1594. return -EINVAL;
  1595. break;
  1596. case ATYIO_FEATR:
  1597. if (get_user(par->features, (u32 __user *) arg))
  1598. return -EFAULT;
  1599. break;
  1600. case ATYIO_FEATW:
  1601. if (put_user(par->features, (u32 __user *) arg))
  1602. return -EFAULT;
  1603. break;
  1604. #endif /* DEBUG && CONFIG_FB_ATY_CT */
  1605. default:
  1606. return -EINVAL;
  1607. }
  1608. return 0;
  1609. }
  1610. static int atyfb_sync(struct fb_info *info)
  1611. {
  1612. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1613. if (par->blitter_may_be_busy)
  1614. wait_for_idle(par);
  1615. return 0;
  1616. }
  1617. #ifdef __sparc__
  1618. static int atyfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
  1619. {
  1620. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1621. unsigned int size, page, map_size = 0;
  1622. unsigned long map_offset = 0;
  1623. unsigned long off;
  1624. int i;
  1625. if (!par->mmap_map)
  1626. return -ENXIO;
  1627. if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
  1628. return -EINVAL;
  1629. off = vma->vm_pgoff << PAGE_SHIFT;
  1630. size = vma->vm_end - vma->vm_start;
  1631. /* To stop the swapper from even considering these pages. */
  1632. vma->vm_flags |= (VM_IO | VM_RESERVED);
  1633. if (((vma->vm_pgoff == 0) && (size == info->fix.smem_len)) ||
  1634. ((off == info->fix.smem_len) && (size == PAGE_SIZE)))
  1635. off += 0x8000000000000000UL;
  1636. vma->vm_pgoff = off >> PAGE_SHIFT; /* propagate off changes */
  1637. /* Each page, see which map applies */
  1638. for (page = 0; page < size;) {
  1639. map_size = 0;
  1640. for (i = 0; par->mmap_map[i].size; i++) {
  1641. unsigned long start = par->mmap_map[i].voff;
  1642. unsigned long end = start + par->mmap_map[i].size;
  1643. unsigned long offset = off + page;
  1644. if (start > offset)
  1645. continue;
  1646. if (offset >= end)
  1647. continue;
  1648. map_size = par->mmap_map[i].size - (offset - start);
  1649. map_offset =
  1650. par->mmap_map[i].poff + (offset - start);
  1651. break;
  1652. }
  1653. if (!map_size) {
  1654. page += PAGE_SIZE;
  1655. continue;
  1656. }
  1657. if (page + map_size > size)
  1658. map_size = size - page;
  1659. pgprot_val(vma->vm_page_prot) &=
  1660. ~(par->mmap_map[i].prot_mask);
  1661. pgprot_val(vma->vm_page_prot) |= par->mmap_map[i].prot_flag;
  1662. if (remap_pfn_range(vma, vma->vm_start + page,
  1663. map_offset >> PAGE_SHIFT, map_size, vma->vm_page_prot))
  1664. return -EAGAIN;
  1665. page += map_size;
  1666. }
  1667. if (!map_size)
  1668. return -EINVAL;
  1669. if (!par->mmaped)
  1670. par->mmaped = 1;
  1671. return 0;
  1672. }
  1673. static struct {
  1674. u32 yoffset;
  1675. u8 r[2][256];
  1676. u8 g[2][256];
  1677. u8 b[2][256];
  1678. } atyfb_save;
  1679. static void atyfb_save_palette(struct atyfb_par *par, int enter)
  1680. {
  1681. int i, tmp;
  1682. for (i = 0; i < 256; i++) {
  1683. tmp = aty_ld_8(DAC_CNTL, par) & 0xfc;
  1684. if (M64_HAS(EXTRA_BRIGHT))
  1685. tmp |= 0x2;
  1686. aty_st_8(DAC_CNTL, tmp, par);
  1687. aty_st_8(DAC_MASK, 0xff, par);
  1688. writeb(i, &par->aty_cmap_regs->rindex);
  1689. atyfb_save.r[enter][i] = readb(&par->aty_cmap_regs->lut);
  1690. atyfb_save.g[enter][i] = readb(&par->aty_cmap_regs->lut);
  1691. atyfb_save.b[enter][i] = readb(&par->aty_cmap_regs->lut);
  1692. writeb(i, &par->aty_cmap_regs->windex);
  1693. writeb(atyfb_save.r[1 - enter][i],
  1694. &par->aty_cmap_regs->lut);
  1695. writeb(atyfb_save.g[1 - enter][i],
  1696. &par->aty_cmap_regs->lut);
  1697. writeb(atyfb_save.b[1 - enter][i],
  1698. &par->aty_cmap_regs->lut);
  1699. }
  1700. }
  1701. static void atyfb_palette(int enter)
  1702. {
  1703. struct atyfb_par *par;
  1704. struct fb_info *info;
  1705. int i;
  1706. for (i = 0; i < FB_MAX; i++) {
  1707. info = registered_fb[i];
  1708. if (info && info->fbops == &atyfb_ops) {
  1709. par = (struct atyfb_par *) info->par;
  1710. atyfb_save_palette(par, enter);
  1711. if (enter) {
  1712. atyfb_save.yoffset = info->var.yoffset;
  1713. info->var.yoffset = 0;
  1714. set_off_pitch(par, info);
  1715. } else {
  1716. info->var.yoffset = atyfb_save.yoffset;
  1717. set_off_pitch(par, info);
  1718. }
  1719. aty_st_le32(CRTC_OFF_PITCH, par->crtc.off_pitch, par);
  1720. break;
  1721. }
  1722. }
  1723. }
  1724. #endif /* __sparc__ */
  1725. #if defined(CONFIG_PM) && defined(CONFIG_PCI)
  1726. /* Power management routines. Those are used for PowerBook sleep.
  1727. */
  1728. static int aty_power_mgmt(int sleep, struct atyfb_par *par)
  1729. {
  1730. u32 pm;
  1731. int timeout;
  1732. pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  1733. pm = (pm & ~PWR_MGT_MODE_MASK) | PWR_MGT_MODE_REG;
  1734. aty_st_lcd(POWER_MANAGEMENT, pm, par);
  1735. pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  1736. timeout = 2000;
  1737. if (sleep) {
  1738. /* Sleep */
  1739. pm &= ~PWR_MGT_ON;
  1740. aty_st_lcd(POWER_MANAGEMENT, pm, par);
  1741. pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  1742. udelay(10);
  1743. pm &= ~(PWR_BLON | AUTO_PWR_UP);
  1744. pm |= SUSPEND_NOW;
  1745. aty_st_lcd(POWER_MANAGEMENT, pm, par);
  1746. pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  1747. udelay(10);
  1748. pm |= PWR_MGT_ON;
  1749. aty_st_lcd(POWER_MANAGEMENT, pm, par);
  1750. do {
  1751. pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  1752. mdelay(1);
  1753. if ((--timeout) == 0)
  1754. break;
  1755. } while ((pm & PWR_MGT_STATUS_MASK) != PWR_MGT_STATUS_SUSPEND);
  1756. } else {
  1757. /* Wakeup */
  1758. pm &= ~PWR_MGT_ON;
  1759. aty_st_lcd(POWER_MANAGEMENT, pm, par);
  1760. pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  1761. udelay(10);
  1762. pm &= ~SUSPEND_NOW;
  1763. pm |= (PWR_BLON | AUTO_PWR_UP);
  1764. aty_st_lcd(POWER_MANAGEMENT, pm, par);
  1765. pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  1766. udelay(10);
  1767. pm |= PWR_MGT_ON;
  1768. aty_st_lcd(POWER_MANAGEMENT, pm, par);
  1769. do {
  1770. pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  1771. mdelay(1);
  1772. if ((--timeout) == 0)
  1773. break;
  1774. } while ((pm & PWR_MGT_STATUS_MASK) != 0);
  1775. }
  1776. mdelay(500);
  1777. return timeout ? 0 : -EIO;
  1778. }
  1779. static int atyfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  1780. {
  1781. struct fb_info *info = pci_get_drvdata(pdev);
  1782. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1783. #ifndef CONFIG_PPC_PMAC
  1784. /* HACK ALERT ! Once I find a proper way to say to each driver
  1785. * individually what will happen with it's PCI slot, I'll change
  1786. * that. On laptops, the AGP slot is just unclocked, so D2 is
  1787. * expected, while on desktops, the card is powered off
  1788. */
  1789. return 0;
  1790. #endif /* CONFIG_PPC_PMAC */
  1791. if (state.event == pdev->dev.power.power_state.event)
  1792. return 0;
  1793. acquire_console_sem();
  1794. fb_set_suspend(info, 1);
  1795. /* Idle & reset engine */
  1796. wait_for_idle(par);
  1797. aty_reset_engine(par);
  1798. /* Blank display and LCD */
  1799. atyfb_blank(FB_BLANK_POWERDOWN, info);
  1800. par->asleep = 1;
  1801. par->lock_blank = 1;
  1802. /* Set chip to "suspend" mode */
  1803. if (aty_power_mgmt(1, par)) {
  1804. par->asleep = 0;
  1805. par->lock_blank = 0;
  1806. atyfb_blank(FB_BLANK_UNBLANK, info);
  1807. fb_set_suspend(info, 0);
  1808. release_console_sem();
  1809. return -EIO;
  1810. }
  1811. release_console_sem();
  1812. pdev->dev.power.power_state = state;
  1813. return 0;
  1814. }
  1815. static int atyfb_pci_resume(struct pci_dev *pdev)
  1816. {
  1817. struct fb_info *info = pci_get_drvdata(pdev);
  1818. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1819. if (pdev->dev.power.power_state.event == PM_EVENT_ON)
  1820. return 0;
  1821. acquire_console_sem();
  1822. if (pdev->dev.power.power_state.event == 2)
  1823. aty_power_mgmt(0, par);
  1824. par->asleep = 0;
  1825. /* Restore display */
  1826. atyfb_set_par(info);
  1827. /* Refresh */
  1828. fb_set_suspend(info, 0);
  1829. /* Unblank */
  1830. par->lock_blank = 0;
  1831. atyfb_blank(FB_BLANK_UNBLANK, info);
  1832. release_console_sem();
  1833. pdev->dev.power.power_state = PMSG_ON;
  1834. return 0;
  1835. }
  1836. #endif /* defined(CONFIG_PM) && defined(CONFIG_PCI) */
  1837. #ifdef CONFIG_PMAC_BACKLIGHT
  1838. /*
  1839. * LCD backlight control
  1840. */
  1841. static int backlight_conv[] = {
  1842. 0x00, 0x3f, 0x4c, 0x59, 0x66, 0x73, 0x80, 0x8d,
  1843. 0x9a, 0xa7, 0xb4, 0xc1, 0xcf, 0xdc, 0xe9, 0xff
  1844. };
  1845. static int aty_set_backlight_enable(int on, int level, void *data)
  1846. {
  1847. struct fb_info *info = (struct fb_info *) data;
  1848. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1849. unsigned int reg = aty_ld_lcd(LCD_MISC_CNTL, par);
  1850. reg |= (BLMOD_EN | BIASMOD_EN);
  1851. if (on && level > BACKLIGHT_OFF) {
  1852. reg &= ~BIAS_MOD_LEVEL_MASK;
  1853. reg |= (backlight_conv[level] << BIAS_MOD_LEVEL_SHIFT);
  1854. } else {
  1855. reg &= ~BIAS_MOD_LEVEL_MASK;
  1856. reg |= (backlight_conv[0] << BIAS_MOD_LEVEL_SHIFT);
  1857. }
  1858. aty_st_lcd(LCD_MISC_CNTL, reg, par);
  1859. return 0;
  1860. }
  1861. static int aty_set_backlight_level(int level, void *data)
  1862. {
  1863. return aty_set_backlight_enable(1, level, data);
  1864. }
  1865. static struct backlight_controller aty_backlight_controller = {
  1866. aty_set_backlight_enable,
  1867. aty_set_backlight_level
  1868. };
  1869. #endif /* CONFIG_PMAC_BACKLIGHT */
  1870. static void __init aty_calc_mem_refresh(struct atyfb_par *par, int xclk)
  1871. {
  1872. const int ragepro_tbl[] = {
  1873. 44, 50, 55, 66, 75, 80, 100
  1874. };
  1875. const int ragexl_tbl[] = {
  1876. 50, 66, 75, 83, 90, 95, 100, 105,
  1877. 110, 115, 120, 125, 133, 143, 166
  1878. };
  1879. const int *refresh_tbl;
  1880. int i, size;
  1881. if (IS_XL(par->pci_id) || IS_MOBILITY(par->pci_id)) {
  1882. refresh_tbl = ragexl_tbl;
  1883. size = ARRAY_SIZE(ragexl_tbl);
  1884. } else {
  1885. refresh_tbl = ragepro_tbl;
  1886. size = ARRAY_SIZE(ragepro_tbl);
  1887. }
  1888. for (i=0; i < size; i++) {
  1889. if (xclk < refresh_tbl[i])
  1890. break;
  1891. }
  1892. par->mem_refresh_rate = i;
  1893. }
  1894. /*
  1895. * Initialisation
  1896. */
  1897. static struct fb_info *fb_list = NULL;
  1898. #if defined(__i386__) && defined(CONFIG_FB_ATY_GENERIC_LCD)
  1899. static int __devinit atyfb_get_timings_from_lcd(struct atyfb_par *par,
  1900. struct fb_var_screeninfo *var)
  1901. {
  1902. int ret = -EINVAL;
  1903. if (par->lcd_table != 0 && (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) {
  1904. *var = default_var;
  1905. var->xres = var->xres_virtual = par->lcd_hdisp;
  1906. var->right_margin = par->lcd_right_margin;
  1907. var->left_margin = par->lcd_hblank_len -
  1908. (par->lcd_right_margin + par->lcd_hsync_dly +
  1909. par->lcd_hsync_len);
  1910. var->hsync_len = par->lcd_hsync_len + par->lcd_hsync_dly;
  1911. var->yres = var->yres_virtual = par->lcd_vdisp;
  1912. var->lower_margin = par->lcd_lower_margin;
  1913. var->upper_margin = par->lcd_vblank_len -
  1914. (par->lcd_lower_margin + par->lcd_vsync_len);
  1915. var->vsync_len = par->lcd_vsync_len;
  1916. var->pixclock = par->lcd_pixclock;
  1917. ret = 0;
  1918. }
  1919. return ret;
  1920. }
  1921. #endif /* defined(__i386__) && defined(CONFIG_FB_ATY_GENERIC_LCD) */
  1922. static int __init aty_init(struct fb_info *info, const char *name)
  1923. {
  1924. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1925. const char *ramname = NULL, *xtal;
  1926. int gtb_memsize, has_var = 0;
  1927. struct fb_var_screeninfo var;
  1928. u8 pll_ref_div;
  1929. u32 i;
  1930. #if defined(CONFIG_PPC)
  1931. int sense;
  1932. #endif
  1933. init_waitqueue_head(&par->vblank.wait);
  1934. spin_lock_init(&par->int_lock);
  1935. par->aty_cmap_regs =
  1936. (struct aty_cmap_regs __iomem *) (par->ati_regbase + 0xc0);
  1937. #ifdef CONFIG_PPC_PMAC
  1938. /* The Apple iBook1 uses non-standard memory frequencies. We detect it
  1939. * and set the frequency manually. */
  1940. if (machine_is_compatible("PowerBook2,1")) {
  1941. par->pll_limits.mclk = 70;
  1942. par->pll_limits.xclk = 53;
  1943. }
  1944. #endif
  1945. if (pll)
  1946. par->pll_limits.pll_max = pll;
  1947. if (mclk)
  1948. par->pll_limits.mclk = mclk;
  1949. if (xclk)
  1950. par->pll_limits.xclk = xclk;
  1951. aty_calc_mem_refresh(par, par->pll_limits.xclk);
  1952. par->pll_per = 1000000/par->pll_limits.pll_max;
  1953. par->mclk_per = 1000000/par->pll_limits.mclk;
  1954. par->xclk_per = 1000000/par->pll_limits.xclk;
  1955. par->ref_clk_per = 1000000000000ULL / 14318180;
  1956. xtal = "14.31818";
  1957. #ifdef CONFIG_FB_ATY_GX
  1958. if (!M64_HAS(INTEGRATED)) {
  1959. u32 stat0;
  1960. u8 dac_type, dac_subtype, clk_type;
  1961. stat0 = aty_ld_le32(CONFIG_STAT0, par);
  1962. par->bus_type = (stat0 >> 0) & 0x07;
  1963. par->ram_type = (stat0 >> 3) & 0x07;
  1964. ramname = aty_gx_ram[par->ram_type];
  1965. /* FIXME: clockchip/RAMDAC probing? */
  1966. dac_type = (aty_ld_le32(DAC_CNTL, par) >> 16) & 0x07;
  1967. #ifdef CONFIG_ATARI
  1968. clk_type = CLK_ATI18818_1;
  1969. dac_type = (stat0 >> 9) & 0x07;
  1970. if (dac_type == 0x07)
  1971. dac_subtype = DAC_ATT20C408;
  1972. else
  1973. dac_subtype = (aty_ld_8(SCRATCH_REG1 + 1, par) & 0xF0) | dac_type;
  1974. #else
  1975. dac_type = DAC_IBMRGB514;
  1976. dac_subtype = DAC_IBMRGB514;
  1977. clk_type = CLK_IBMRGB514;
  1978. #endif
  1979. switch (dac_subtype) {
  1980. case DAC_IBMRGB514:
  1981. par->dac_ops = &aty_dac_ibm514;
  1982. break;
  1983. case DAC_ATI68860_B:
  1984. case DAC_ATI68860_C:
  1985. par->dac_ops = &aty_dac_ati68860b;
  1986. break;
  1987. case DAC_ATT20C408:
  1988. case DAC_ATT21C498:
  1989. par->dac_ops = &aty_dac_att21c498;
  1990. break;
  1991. default:
  1992. PRINTKI("aty_init: DAC type not implemented yet!\n");
  1993. par->dac_ops = &aty_dac_unsupported;
  1994. break;
  1995. }
  1996. switch (clk_type) {
  1997. case CLK_ATI18818_1:
  1998. par->pll_ops = &aty_pll_ati18818_1;
  1999. break;
  2000. case CLK_IBMRGB514:
  2001. par->pll_ops = &aty_pll_ibm514;
  2002. break;
  2003. #if 0 /* dead code */
  2004. case CLK_STG1703:
  2005. par->pll_ops = &aty_pll_stg1703;
  2006. break;
  2007. case CLK_CH8398:
  2008. par->pll_ops = &aty_pll_ch8398;
  2009. break;
  2010. case CLK_ATT20C408:
  2011. par->pll_ops = &aty_pll_att20c408;
  2012. break;
  2013. #endif
  2014. default:
  2015. PRINTKI("aty_init: CLK type not implemented yet!");
  2016. par->pll_ops = &aty_pll_unsupported;
  2017. break;
  2018. }
  2019. }
  2020. #endif /* CONFIG_FB_ATY_GX */
  2021. #ifdef CONFIG_FB_ATY_CT
  2022. if (M64_HAS(INTEGRATED)) {
  2023. par->dac_ops = &aty_dac_ct;
  2024. par->pll_ops = &aty_pll_ct;
  2025. par->bus_type = PCI;
  2026. par->ram_type = (aty_ld_le32(CONFIG_STAT0, par) & 0x07);
  2027. ramname = aty_ct_ram[par->ram_type];
  2028. /* for many chips, the mclk is 67 MHz for SDRAM, 63 MHz otherwise */
  2029. if (par->pll_limits.mclk == 67 && par->ram_type < SDRAM)
  2030. par->pll_limits.mclk = 63;
  2031. }
  2032. if (M64_HAS(GTB_DSP)
  2033. && (pll_ref_div = aty_ld_pll_ct(PLL_REF_DIV, par))) {
  2034. int diff1, diff2;
  2035. diff1 = 510 * 14 / pll_ref_div - par->pll_limits.pll_max;
  2036. diff2 = 510 * 29 / pll_ref_div - par->pll_limits.pll_max;
  2037. if (diff1 < 0)
  2038. diff1 = -diff1;
  2039. if (diff2 < 0)
  2040. diff2 = -diff2;
  2041. if (diff2 < diff1) {
  2042. par->ref_clk_per = 1000000000000ULL / 29498928;
  2043. xtal = "29.498928";
  2044. }
  2045. }
  2046. #endif /* CONFIG_FB_ATY_CT */
  2047. /* save previous video mode */
  2048. aty_get_crtc(par, &saved_crtc);
  2049. if(par->pll_ops->get_pll)
  2050. par->pll_ops->get_pll(info, &saved_pll);
  2051. i = aty_ld_le32(MEM_CNTL, par);
  2052. gtb_memsize = M64_HAS(GTB_DSP);
  2053. if (gtb_memsize)
  2054. switch (i & 0xF) { /* 0xF used instead of MEM_SIZE_ALIAS */
  2055. case MEM_SIZE_512K:
  2056. info->fix.smem_len = 0x80000;
  2057. break;
  2058. case MEM_SIZE_1M:
  2059. info->fix.smem_len = 0x100000;
  2060. break;
  2061. case MEM_SIZE_2M_GTB:
  2062. info->fix.smem_len = 0x200000;
  2063. break;
  2064. case MEM_SIZE_4M_GTB:
  2065. info->fix.smem_len = 0x400000;
  2066. break;
  2067. case MEM_SIZE_6M_GTB:
  2068. info->fix.smem_len = 0x600000;
  2069. break;
  2070. case MEM_SIZE_8M_GTB:
  2071. info->fix.smem_len = 0x800000;
  2072. break;
  2073. default:
  2074. info->fix.smem_len = 0x80000;
  2075. } else
  2076. switch (i & MEM_SIZE_ALIAS) {
  2077. case MEM_SIZE_512K:
  2078. info->fix.smem_len = 0x80000;
  2079. break;
  2080. case MEM_SIZE_1M:
  2081. info->fix.smem_len = 0x100000;
  2082. break;
  2083. case MEM_SIZE_2M:
  2084. info->fix.smem_len = 0x200000;
  2085. break;
  2086. case MEM_SIZE_4M:
  2087. info->fix.smem_len = 0x400000;
  2088. break;
  2089. case MEM_SIZE_6M:
  2090. info->fix.smem_len = 0x600000;
  2091. break;
  2092. case MEM_SIZE_8M:
  2093. info->fix.smem_len = 0x800000;
  2094. break;
  2095. default:
  2096. info->fix.smem_len = 0x80000;
  2097. }
  2098. if (M64_HAS(MAGIC_VRAM_SIZE)) {
  2099. if (aty_ld_le32(CONFIG_STAT1, par) & 0x40000000)
  2100. info->fix.smem_len += 0x400000;
  2101. }
  2102. if (vram) {
  2103. info->fix.smem_len = vram * 1024;
  2104. i = i & ~(gtb_memsize ? 0xF : MEM_SIZE_ALIAS);
  2105. if (info->fix.smem_len <= 0x80000)
  2106. i |= MEM_SIZE_512K;
  2107. else if (info->fix.smem_len <= 0x100000)
  2108. i |= MEM_SIZE_1M;
  2109. else if (info->fix.smem_len <= 0x200000)
  2110. i |= gtb_memsize ? MEM_SIZE_2M_GTB : MEM_SIZE_2M;
  2111. else if (info->fix.smem_len <= 0x400000)
  2112. i |= gtb_memsize ? MEM_SIZE_4M_GTB : MEM_SIZE_4M;
  2113. else if (info->fix.smem_len <= 0x600000)
  2114. i |= gtb_memsize ? MEM_SIZE_6M_GTB : MEM_SIZE_6M;
  2115. else
  2116. i |= gtb_memsize ? MEM_SIZE_8M_GTB : MEM_SIZE_8M;
  2117. aty_st_le32(MEM_CNTL, i, par);
  2118. }
  2119. /*
  2120. * Reg Block 0 (CT-compatible block) is at mmio_start
  2121. * Reg Block 1 (multimedia extensions) is at mmio_start - 0x400
  2122. */
  2123. if (M64_HAS(GX)) {
  2124. info->fix.mmio_len = 0x400;
  2125. info->fix.accel = FB_ACCEL_ATI_MACH64GX;
  2126. } else if (M64_HAS(CT)) {
  2127. info->fix.mmio_len = 0x400;
  2128. info->fix.accel = FB_ACCEL_ATI_MACH64CT;
  2129. } else if (M64_HAS(VT)) {
  2130. info->fix.mmio_start -= 0x400;
  2131. info->fix.mmio_len = 0x800;
  2132. info->fix.accel = FB_ACCEL_ATI_MACH64VT;
  2133. } else {/* GT */
  2134. info->fix.mmio_start -= 0x400;
  2135. info->fix.mmio_len = 0x800;
  2136. info->fix.accel = FB_ACCEL_ATI_MACH64GT;
  2137. }
  2138. PRINTKI("%d%c %s, %s MHz XTAL, %d MHz PLL, %d Mhz MCLK, %d MHz XCLK\n",
  2139. info->fix.smem_len == 0x80000 ? 512 : (info->fix.smem_len >> 20),
  2140. info->fix.smem_len == 0x80000 ? 'K' : 'M', ramname, xtal, par->pll_limits.pll_max,
  2141. par->pll_limits.mclk, par->pll_limits.xclk);
  2142. #if defined(DEBUG) && defined(CONFIG_ATY_CT)
  2143. if (M64_HAS(INTEGRATED)) {
  2144. int i;
  2145. printk("debug atyfb: BUS_CNTL DAC_CNTL MEM_CNTL EXT_MEM_CNTL CRTC_GEN_CNTL "
  2146. "DSP_CONFIG DSP_ON_OFF CLOCK_CNTL\n"
  2147. "debug atyfb: %08x %08x %08x %08x %08x %08x %08x %08x\n"
  2148. "debug atyfb: PLL",
  2149. aty_ld_le32(BUS_CNTL, par), aty_ld_le32(DAC_CNTL, par),
  2150. aty_ld_le32(MEM_CNTL, par), aty_ld_le32(EXT_MEM_CNTL, par),
  2151. aty_ld_le32(CRTC_GEN_CNTL, par), aty_ld_le32(DSP_CONFIG, par),
  2152. aty_ld_le32(DSP_ON_OFF, par), aty_ld_le32(CLOCK_CNTL, par));
  2153. for (i = 0; i < 40; i++)
  2154. printk(" %02x", aty_ld_pll_ct(i, par));
  2155. printk("\n");
  2156. }
  2157. #endif
  2158. if(par->pll_ops->init_pll)
  2159. par->pll_ops->init_pll(info, &par->pll);
  2160. /*
  2161. * Last page of 8 MB (4 MB on ISA) aperture is MMIO
  2162. * FIXME: we should use the auxiliary aperture instead so we can access
  2163. * the full 8 MB of video RAM on 8 MB boards
  2164. */
  2165. if (!par->aux_start &&
  2166. (info->fix.smem_len == 0x800000 || (par->bus_type == ISA && info->fix.smem_len == 0x400000)))
  2167. info->fix.smem_len -= GUI_RESERVE;
  2168. /*
  2169. * Disable register access through the linear aperture
  2170. * if the auxiliary aperture is used so we can access
  2171. * the full 8 MB of video RAM on 8 MB boards.
  2172. */
  2173. if (par->aux_start)
  2174. aty_st_le32(BUS_CNTL, aty_ld_le32(BUS_CNTL, par) | BUS_APER_REG_DIS, par);
  2175. #ifdef CONFIG_MTRR
  2176. par->mtrr_aper = -1;
  2177. par->mtrr_reg = -1;
  2178. if (!nomtrr) {
  2179. /* Cover the whole resource. */
  2180. par->mtrr_aper = mtrr_add(par->res_start, par->res_size, MTRR_TYPE_WRCOMB, 1);
  2181. if (par->mtrr_aper >= 0 && !par->aux_start) {
  2182. /* Make a hole for mmio. */
  2183. par->mtrr_reg = mtrr_add(par->res_start + 0x800000 - GUI_RESERVE,
  2184. GUI_RESERVE, MTRR_TYPE_UNCACHABLE, 1);
  2185. if (par->mtrr_reg < 0) {
  2186. mtrr_del(par->mtrr_aper, 0, 0);
  2187. par->mtrr_aper = -1;
  2188. }
  2189. }
  2190. }
  2191. #endif
  2192. info->fbops = &atyfb_ops;
  2193. info->pseudo_palette = pseudo_palette;
  2194. info->flags = FBINFO_FLAG_DEFAULT;
  2195. #ifdef CONFIG_PMAC_BACKLIGHT
  2196. if (M64_HAS(G3_PB_1_1) && machine_is_compatible("PowerBook1,1")) {
  2197. /* these bits let the 101 powerbook wake up from sleep -- paulus */
  2198. aty_st_lcd(POWER_MANAGEMENT, aty_ld_lcd(POWER_MANAGEMENT, par)
  2199. | (USE_F32KHZ | TRISTATE_MEM_EN), par);
  2200. } else if (M64_HAS(MOBIL_BUS))
  2201. register_backlight_controller(&aty_backlight_controller, info, "ati");
  2202. #endif /* CONFIG_PMAC_BACKLIGHT */
  2203. memset(&var, 0, sizeof(var));
  2204. #ifdef CONFIG_PPC
  2205. if (machine_is(powermac)) {
  2206. /*
  2207. * FIXME: The NVRAM stuff should be put in a Mac-specific file, as it
  2208. * applies to all Mac video cards
  2209. */
  2210. if (mode) {
  2211. if (mac_find_mode(&var, info, mode, 8))
  2212. has_var = 1;
  2213. } else {
  2214. if (default_vmode == VMODE_CHOOSE) {
  2215. if (M64_HAS(G3_PB_1024x768))
  2216. /* G3 PowerBook with 1024x768 LCD */
  2217. default_vmode = VMODE_1024_768_60;
  2218. else if (machine_is_compatible("iMac"))
  2219. default_vmode = VMODE_1024_768_75;
  2220. else if (machine_is_compatible
  2221. ("PowerBook2,1"))
  2222. /* iBook with 800x600 LCD */
  2223. default_vmode = VMODE_800_600_60;
  2224. else
  2225. default_vmode = VMODE_640_480_67;
  2226. sense = read_aty_sense(par);
  2227. PRINTKI("monitor sense=%x, mode %d\n",
  2228. sense, mac_map_monitor_sense(sense));
  2229. }
  2230. if (default_vmode <= 0 || default_vmode > VMODE_MAX)
  2231. default_vmode = VMODE_640_480_60;
  2232. if (default_cmode < CMODE_8 || default_cmode > CMODE_32)
  2233. default_cmode = CMODE_8;
  2234. if (!mac_vmode_to_var(default_vmode, default_cmode,
  2235. &var))
  2236. has_var = 1;
  2237. }
  2238. }
  2239. #endif /* !CONFIG_PPC */
  2240. #if defined(__i386__) && defined(CONFIG_FB_ATY_GENERIC_LCD)
  2241. if (!atyfb_get_timings_from_lcd(par, &var))
  2242. has_var = 1;
  2243. #endif
  2244. if (mode && fb_find_mode(&var, info, mode, NULL, 0, &defmode, 8))
  2245. has_var = 1;
  2246. if (!has_var)
  2247. var = default_var;
  2248. if (noaccel)
  2249. var.accel_flags &= ~FB_ACCELF_TEXT;
  2250. else
  2251. var.accel_flags |= FB_ACCELF_TEXT;
  2252. if (comp_sync != -1) {
  2253. if (!comp_sync)
  2254. var.sync &= ~FB_SYNC_COMP_HIGH_ACT;
  2255. else
  2256. var.sync |= FB_SYNC_COMP_HIGH_ACT;
  2257. }
  2258. if (var.yres == var.yres_virtual) {
  2259. u32 videoram = (info->fix.smem_len - (PAGE_SIZE << 2));
  2260. var.yres_virtual = ((videoram * 8) / var.bits_per_pixel) / var.xres_virtual;
  2261. if (var.yres_virtual < var.yres)
  2262. var.yres_virtual = var.yres;
  2263. }
  2264. if (atyfb_check_var(&var, info)) {
  2265. PRINTKE("can't set default video mode\n");
  2266. goto aty_init_exit;
  2267. }
  2268. #ifdef __sparc__
  2269. atyfb_save_palette(par, 0);
  2270. #endif
  2271. #ifdef CONFIG_FB_ATY_CT
  2272. if (!noaccel && M64_HAS(INTEGRATED))
  2273. aty_init_cursor(info);
  2274. #endif /* CONFIG_FB_ATY_CT */
  2275. info->var = var;
  2276. fb_alloc_cmap(&info->cmap, 256, 0);
  2277. if (register_framebuffer(info) < 0)
  2278. goto aty_init_exit;
  2279. fb_list = info;
  2280. PRINTKI("fb%d: %s frame buffer device on %s\n",
  2281. info->node, info->fix.id, name);
  2282. return 0;
  2283. aty_init_exit:
  2284. /* restore video mode */
  2285. aty_set_crtc(par, &saved_crtc);
  2286. par->pll_ops->set_pll(info, &saved_pll);
  2287. #ifdef CONFIG_MTRR
  2288. if (par->mtrr_reg >= 0) {
  2289. mtrr_del(par->mtrr_reg, 0, 0);
  2290. par->mtrr_reg = -1;
  2291. }
  2292. if (par->mtrr_aper >= 0) {
  2293. mtrr_del(par->mtrr_aper, 0, 0);
  2294. par->mtrr_aper = -1;
  2295. }
  2296. #endif
  2297. return -1;
  2298. }
  2299. #ifdef CONFIG_ATARI
  2300. static int __init store_video_par(char *video_str, unsigned char m64_num)
  2301. {
  2302. char *p;
  2303. unsigned long vmembase, size, guiregbase;
  2304. PRINTKI("store_video_par() '%s' \n", video_str);
  2305. if (!(p = strsep(&video_str, ";")) || !*p)
  2306. goto mach64_invalid;
  2307. vmembase = simple_strtoul(p, NULL, 0);
  2308. if (!(p = strsep(&video_str, ";")) || !*p)
  2309. goto mach64_invalid;
  2310. size = simple_strtoul(p, NULL, 0);
  2311. if (!(p = strsep(&video_str, ";")) || !*p)
  2312. goto mach64_invalid;
  2313. guiregbase = simple_strtoul(p, NULL, 0);
  2314. phys_vmembase[m64_num] = vmembase;
  2315. phys_size[m64_num] = size;
  2316. phys_guiregbase[m64_num] = guiregbase;
  2317. PRINTKI("stored them all: $%08lX $%08lX $%08lX \n", vmembase, size,
  2318. guiregbase);
  2319. return 0;
  2320. mach64_invalid:
  2321. phys_vmembase[m64_num] = 0;
  2322. return -1;
  2323. }
  2324. #endif /* CONFIG_ATARI */
  2325. /*
  2326. * Blank the display.
  2327. */
  2328. static int atyfb_blank(int blank, struct fb_info *info)
  2329. {
  2330. struct atyfb_par *par = (struct atyfb_par *) info->par;
  2331. u32 gen_cntl;
  2332. if (par->lock_blank || par->asleep)
  2333. return 0;
  2334. #ifdef CONFIG_PMAC_BACKLIGHT
  2335. if (machine_is(powermac) && blank > FB_BLANK_NORMAL)
  2336. set_backlight_enable(0);
  2337. #elif defined(CONFIG_FB_ATY_GENERIC_LCD)
  2338. if (par->lcd_table && blank > FB_BLANK_NORMAL &&
  2339. (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) {
  2340. u32 pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  2341. pm &= ~PWR_BLON;
  2342. aty_st_lcd(POWER_MANAGEMENT, pm, par);
  2343. }
  2344. #endif
  2345. gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par);
  2346. switch (blank) {
  2347. case FB_BLANK_UNBLANK:
  2348. gen_cntl &= ~0x400004c;
  2349. break;
  2350. case FB_BLANK_NORMAL:
  2351. gen_cntl |= 0x4000040;
  2352. break;
  2353. case FB_BLANK_VSYNC_SUSPEND:
  2354. gen_cntl |= 0x4000048;
  2355. break;
  2356. case FB_BLANK_HSYNC_SUSPEND:
  2357. gen_cntl |= 0x4000044;
  2358. break;
  2359. case FB_BLANK_POWERDOWN:
  2360. gen_cntl |= 0x400004c;
  2361. break;
  2362. }
  2363. aty_st_le32(CRTC_GEN_CNTL, gen_cntl, par);
  2364. #ifdef CONFIG_PMAC_BACKLIGHT
  2365. if (machine_is(powermac) && blank <= FB_BLANK_NORMAL)
  2366. set_backlight_enable(1);
  2367. #elif defined(CONFIG_FB_ATY_GENERIC_LCD)
  2368. if (par->lcd_table && blank <= FB_BLANK_NORMAL &&
  2369. (aty_ld_lcd(LCD_GEN_CNTL, par) & LCD_ON)) {
  2370. u32 pm = aty_ld_lcd(POWER_MANAGEMENT, par);
  2371. pm |= PWR_BLON;
  2372. aty_st_lcd(POWER_MANAGEMENT, pm, par);
  2373. }
  2374. #endif
  2375. return 0;
  2376. }
  2377. static void aty_st_pal(u_int regno, u_int red, u_int green, u_int blue,
  2378. const struct atyfb_par *par)
  2379. {
  2380. #ifdef CONFIG_ATARI
  2381. out_8(&par->aty_cmap_regs->windex, regno);
  2382. out_8(&par->aty_cmap_regs->lut, red);
  2383. out_8(&par->aty_cmap_regs->lut, green);
  2384. out_8(&par->aty_cmap_regs->lut, blue);
  2385. #else
  2386. writeb(regno, &par->aty_cmap_regs->windex);
  2387. writeb(red, &par->aty_cmap_regs->lut);
  2388. writeb(green, &par->aty_cmap_regs->lut);
  2389. writeb(blue, &par->aty_cmap_regs->lut);
  2390. #endif
  2391. }
  2392. /*
  2393. * Set a single color register. The values supplied are already
  2394. * rounded down to the hardware's capabilities (according to the
  2395. * entries in the var structure). Return != 0 for invalid regno.
  2396. * !! 4 & 8 = PSEUDO, > 8 = DIRECTCOLOR
  2397. */
  2398. static int atyfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  2399. u_int transp, struct fb_info *info)
  2400. {
  2401. struct atyfb_par *par = (struct atyfb_par *) info->par;
  2402. int i, depth;
  2403. u32 *pal = info->pseudo_palette;
  2404. depth = info->var.bits_per_pixel;
  2405. if (depth == 16)
  2406. depth = (info->var.green.length == 5) ? 15 : 16;
  2407. if (par->asleep)
  2408. return 0;
  2409. if (regno > 255 ||
  2410. (depth == 16 && regno > 63) ||
  2411. (depth == 15 && regno > 31))
  2412. return 1;
  2413. red >>= 8;
  2414. green >>= 8;
  2415. blue >>= 8;
  2416. par->palette[regno].red = red;
  2417. par->palette[regno].green = green;
  2418. par->palette[regno].blue = blue;
  2419. if (regno < 16) {
  2420. switch (depth) {
  2421. case 15:
  2422. pal[regno] = (regno << 10) | (regno << 5) | regno;
  2423. break;
  2424. case 16:
  2425. pal[regno] = (regno << 11) | (regno << 5) | regno;
  2426. break;
  2427. case 24:
  2428. pal[regno] = (regno << 16) | (regno << 8) | regno;
  2429. break;
  2430. case 32:
  2431. i = (regno << 8) | regno;
  2432. pal[regno] = (i << 16) | i;
  2433. break;
  2434. }
  2435. }
  2436. i = aty_ld_8(DAC_CNTL, par) & 0xfc;
  2437. if (M64_HAS(EXTRA_BRIGHT))
  2438. i |= 0x2; /* DAC_CNTL | 0x2 turns off the extra brightness for gt */
  2439. aty_st_8(DAC_CNTL, i, par);
  2440. aty_st_8(DAC_MASK, 0xff, par);
  2441. if (M64_HAS(INTEGRATED)) {
  2442. if (depth == 16) {
  2443. if (regno < 32)
  2444. aty_st_pal(regno << 3, red,
  2445. par->palette[regno<<1].green,
  2446. blue, par);
  2447. red = par->palette[regno>>1].red;
  2448. blue = par->palette[regno>>1].blue;
  2449. regno <<= 2;
  2450. } else if (depth == 15) {
  2451. regno <<= 3;
  2452. for(i = 0; i < 8; i++) {
  2453. aty_st_pal(regno + i, red, green, blue, par);
  2454. }
  2455. }
  2456. }
  2457. aty_st_pal(regno, red, green, blue, par);
  2458. return 0;
  2459. }
  2460. #ifdef CONFIG_PCI
  2461. #ifdef __sparc__
  2462. extern void (*prom_palette) (int);
  2463. static int __devinit atyfb_setup_sparc(struct pci_dev *pdev,
  2464. struct fb_info *info, unsigned long addr)
  2465. {
  2466. extern int con_is_present(void);
  2467. struct atyfb_par *par = info->par;
  2468. struct pcidev_cookie *pcp;
  2469. char prop[128];
  2470. int node, len, i, j, ret;
  2471. u32 mem, chip_id;
  2472. /* Do not attach when we have a serial console. */
  2473. if (!con_is_present())
  2474. return -ENXIO;
  2475. /*
  2476. * Map memory-mapped registers.
  2477. */
  2478. par->ati_regbase = (void *)addr + 0x7ffc00UL;
  2479. info->fix.mmio_start = addr + 0x7ffc00UL;
  2480. /*
  2481. * Map in big-endian aperture.
  2482. */
  2483. info->screen_base = (char *) (addr + 0x800000UL);
  2484. info->fix.smem_start = addr + 0x800000UL;
  2485. /*
  2486. * Figure mmap addresses from PCI config space.
  2487. * Split Framebuffer in big- and little-endian halfs.
  2488. */
  2489. for (i = 0; i < 6 && pdev->resource[i].start; i++)
  2490. /* nothing */ ;
  2491. j = i + 4;
  2492. par->mmap_map = kmalloc(j * sizeof(*par->mmap_map), GFP_ATOMIC);
  2493. if (!par->mmap_map) {
  2494. PRINTKE("atyfb_setup_sparc() can't alloc mmap_map\n");
  2495. return -ENOMEM;
  2496. }
  2497. memset(par->mmap_map, 0, j * sizeof(*par->mmap_map));
  2498. for (i = 0, j = 2; i < 6 && pdev->resource[i].start; i++) {
  2499. struct resource *rp = &pdev->resource[i];
  2500. int io, breg = PCI_BASE_ADDRESS_0 + (i << 2);
  2501. unsigned long base;
  2502. u32 size, pbase;
  2503. base = rp->start;
  2504. io = (rp->flags & IORESOURCE_IO);
  2505. size = rp->end - base + 1;
  2506. pci_read_config_dword(pdev, breg, &pbase);
  2507. if (io)
  2508. size &= ~1;
  2509. /*
  2510. * Map the framebuffer a second time, this time without
  2511. * the braindead _PAGE_IE setting. This is used by the
  2512. * fixed Xserver, but we need to maintain the old mapping
  2513. * to stay compatible with older ones...
  2514. */
  2515. if (base == addr) {
  2516. par->mmap_map[j].voff = (pbase + 0x10000000) & PAGE_MASK;
  2517. par->mmap_map[j].poff = base & PAGE_MASK;
  2518. par->mmap_map[j].size = (size + ~PAGE_MASK) & PAGE_MASK;
  2519. par->mmap_map[j].prot_mask = _PAGE_CACHE;
  2520. par->mmap_map[j].prot_flag = _PAGE_E;
  2521. j++;
  2522. }
  2523. /*
  2524. * Here comes the old framebuffer mapping with _PAGE_IE
  2525. * set for the big endian half of the framebuffer...
  2526. */
  2527. if (base == addr) {
  2528. par->mmap_map[j].voff = (pbase + 0x800000) & PAGE_MASK;
  2529. par->mmap_map[j].poff = (base + 0x800000) & PAGE_MASK;
  2530. par->mmap_map[j].size = 0x800000;
  2531. par->mmap_map[j].prot_mask = _PAGE_CACHE;
  2532. par->mmap_map[j].prot_flag = _PAGE_E | _PAGE_IE;
  2533. size -= 0x800000;
  2534. j++;
  2535. }
  2536. par->mmap_map[j].voff = pbase & PAGE_MASK;
  2537. par->mmap_map[j].poff = base & PAGE_MASK;
  2538. par->mmap_map[j].size = (size + ~PAGE_MASK) & PAGE_MASK;
  2539. par->mmap_map[j].prot_mask = _PAGE_CACHE;
  2540. par->mmap_map[j].prot_flag = _PAGE_E;
  2541. j++;
  2542. }
  2543. if((ret = correct_chipset(par)))
  2544. return ret;
  2545. if (IS_XL(pdev->device)) {
  2546. /*
  2547. * Fix PROMs idea of MEM_CNTL settings...
  2548. */
  2549. mem = aty_ld_le32(MEM_CNTL, par);
  2550. chip_id = aty_ld_le32(CONFIG_CHIP_ID, par);
  2551. if (((chip_id & CFG_CHIP_TYPE) == VT_CHIP_ID) && !((chip_id >> 24) & 1)) {
  2552. switch (mem & 0x0f) {
  2553. case 3:
  2554. mem = (mem & ~(0x0f)) | 2;
  2555. break;
  2556. case 7:
  2557. mem = (mem & ~(0x0f)) | 3;
  2558. break;
  2559. case 9:
  2560. mem = (mem & ~(0x0f)) | 4;
  2561. break;
  2562. case 11:
  2563. mem = (mem & ~(0x0f)) | 5;
  2564. break;
  2565. default:
  2566. break;
  2567. }
  2568. if ((aty_ld_le32(CONFIG_STAT0, par) & 7) >= SDRAM)
  2569. mem &= ~(0x00700000);
  2570. }
  2571. mem &= ~(0xcf80e000); /* Turn off all undocumented bits. */
  2572. aty_st_le32(MEM_CNTL, mem, par);
  2573. }
  2574. /*
  2575. * If this is the console device, we will set default video
  2576. * settings to what the PROM left us with.
  2577. */
  2578. node = prom_getchild(prom_root_node);
  2579. node = prom_searchsiblings(node, "aliases");
  2580. if (node) {
  2581. len = prom_getproperty(node, "screen", prop, sizeof(prop));
  2582. if (len > 0) {
  2583. prop[len] = '\0';
  2584. node = prom_finddevice(prop);
  2585. } else
  2586. node = 0;
  2587. }
  2588. pcp = pdev->sysdata;
  2589. if (node == pcp->prom_node) {
  2590. struct fb_var_screeninfo *var = &default_var;
  2591. unsigned int N, P, Q, M, T, R;
  2592. u32 v_total, h_total;
  2593. struct crtc crtc;
  2594. u8 pll_regs[16];
  2595. u8 clock_cntl;
  2596. crtc.vxres = prom_getintdefault(node, "width", 1024);
  2597. crtc.vyres = prom_getintdefault(node, "height", 768);
  2598. var->bits_per_pixel = prom_getintdefault(node, "depth", 8);
  2599. var->xoffset = var->yoffset = 0;
  2600. crtc.h_tot_disp = aty_ld_le32(CRTC_H_TOTAL_DISP, par);
  2601. crtc.h_sync_strt_wid = aty_ld_le32(CRTC_H_SYNC_STRT_WID, par);
  2602. crtc.v_tot_disp = aty_ld_le32(CRTC_V_TOTAL_DISP, par);
  2603. crtc.v_sync_strt_wid = aty_ld_le32(CRTC_V_SYNC_STRT_WID, par);
  2604. crtc.gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par);
  2605. aty_crtc_to_var(&crtc, var);
  2606. h_total = var->xres + var->right_margin + var->hsync_len + var->left_margin;
  2607. v_total = var->yres + var->lower_margin + var->vsync_len + var->upper_margin;
  2608. /*
  2609. * Read the PLL to figure actual Refresh Rate.
  2610. */
  2611. clock_cntl = aty_ld_8(CLOCK_CNTL, par);
  2612. /* DPRINTK("CLOCK_CNTL %02x\n", clock_cntl); */
  2613. for (i = 0; i < 16; i++)
  2614. pll_regs[i] = aty_ld_pll_ct(i, par);
  2615. /*
  2616. * PLL Reference Divider M:
  2617. */
  2618. M = pll_regs[2];
  2619. /*
  2620. * PLL Feedback Divider N (Dependant on CLOCK_CNTL):
  2621. */
  2622. N = pll_regs[7 + (clock_cntl & 3)];
  2623. /*
  2624. * PLL Post Divider P (Dependant on CLOCK_CNTL):
  2625. */
  2626. P = 1 << (pll_regs[6] >> ((clock_cntl & 3) << 1));
  2627. /*
  2628. * PLL Divider Q:
  2629. */
  2630. Q = N / P;
  2631. /*
  2632. * Target Frequency:
  2633. *
  2634. * T * M
  2635. * Q = -------
  2636. * 2 * R
  2637. *
  2638. * where R is XTALIN (= 14318 or 29498 kHz).
  2639. */
  2640. if (IS_XL(pdev->device))
  2641. R = 29498;
  2642. else
  2643. R = 14318;
  2644. T = 2 * Q * R / M;
  2645. default_var.pixclock = 1000000000 / T;
  2646. }
  2647. return 0;
  2648. }
  2649. #else /* __sparc__ */
  2650. #ifdef __i386__
  2651. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  2652. static void aty_init_lcd(struct atyfb_par *par, u32 bios_base)
  2653. {
  2654. u32 driv_inf_tab, sig;
  2655. u16 lcd_ofs;
  2656. /* To support an LCD panel, we should know it's dimensions and
  2657. * it's desired pixel clock.
  2658. * There are two ways to do it:
  2659. * - Check the startup video mode and calculate the panel
  2660. * size from it. This is unreliable.
  2661. * - Read it from the driver information table in the video BIOS.
  2662. */
  2663. /* Address of driver information table is at offset 0x78. */
  2664. driv_inf_tab = bios_base + *((u16 *)(bios_base+0x78));
  2665. /* Check for the driver information table signature. */
  2666. sig = (*(u32 *)driv_inf_tab);
  2667. if ((sig == 0x54504c24) || /* Rage LT pro */
  2668. (sig == 0x544d5224) || /* Rage mobility */
  2669. (sig == 0x54435824) || /* Rage XC */
  2670. (sig == 0x544c5824)) { /* Rage XL */
  2671. PRINTKI("BIOS contains driver information table.\n");
  2672. lcd_ofs = (*(u16 *)(driv_inf_tab + 10));
  2673. par->lcd_table = 0;
  2674. if (lcd_ofs != 0) {
  2675. par->lcd_table = bios_base + lcd_ofs;
  2676. }
  2677. }
  2678. if (par->lcd_table != 0) {
  2679. char model[24];
  2680. char strbuf[16];
  2681. char refresh_rates_buf[100];
  2682. int id, tech, f, i, m, default_refresh_rate;
  2683. char *txtcolour;
  2684. char *txtmonitor;
  2685. char *txtdual;
  2686. char *txtformat;
  2687. u16 width, height, panel_type, refresh_rates;
  2688. u16 *lcdmodeptr;
  2689. u32 format;
  2690. u8 lcd_refresh_rates[16] = {50,56,60,67,70,72,75,76,85,90,100,120,140,150,160,200};
  2691. /* The most important information is the panel size at
  2692. * offset 25 and 27, but there's some other nice information
  2693. * which we print to the screen.
  2694. */
  2695. id = *(u8 *)par->lcd_table;
  2696. strncpy(model,(char *)par->lcd_table+1,24);
  2697. model[23]=0;
  2698. width = par->lcd_width = *(u16 *)(par->lcd_table+25);
  2699. height = par->lcd_height = *(u16 *)(par->lcd_table+27);
  2700. panel_type = *(u16 *)(par->lcd_table+29);
  2701. if (panel_type & 1)
  2702. txtcolour = "colour";
  2703. else
  2704. txtcolour = "monochrome";
  2705. if (panel_type & 2)
  2706. txtdual = "dual (split) ";
  2707. else
  2708. txtdual = "";
  2709. tech = (panel_type>>2) & 63;
  2710. switch (tech) {
  2711. case 0:
  2712. txtmonitor = "passive matrix";
  2713. break;
  2714. case 1:
  2715. txtmonitor = "active matrix";
  2716. break;
  2717. case 2:
  2718. txtmonitor = "active addressed STN";
  2719. break;
  2720. case 3:
  2721. txtmonitor = "EL";
  2722. break;
  2723. case 4:
  2724. txtmonitor = "plasma";
  2725. break;
  2726. default:
  2727. txtmonitor = "unknown";
  2728. }
  2729. format = *(u32 *)(par->lcd_table+57);
  2730. if (tech == 0 || tech == 2) {
  2731. switch (format & 7) {
  2732. case 0:
  2733. txtformat = "12 bit interface";
  2734. break;
  2735. case 1:
  2736. txtformat = "16 bit interface";
  2737. break;
  2738. case 2:
  2739. txtformat = "24 bit interface";
  2740. break;
  2741. default:
  2742. txtformat = "unkown format";
  2743. }
  2744. } else {
  2745. switch (format & 7) {
  2746. case 0:
  2747. txtformat = "8 colours";
  2748. break;
  2749. case 1:
  2750. txtformat = "512 colours";
  2751. break;
  2752. case 2:
  2753. txtformat = "4096 colours";
  2754. break;
  2755. case 4:
  2756. txtformat = "262144 colours (LT mode)";
  2757. break;
  2758. case 5:
  2759. txtformat = "16777216 colours";
  2760. break;
  2761. case 6:
  2762. txtformat = "262144 colours (FDPI-2 mode)";
  2763. break;
  2764. default:
  2765. txtformat = "unkown format";
  2766. }
  2767. }
  2768. PRINTKI("%s%s %s monitor detected: %s\n",
  2769. txtdual ,txtcolour, txtmonitor, model);
  2770. PRINTKI(" id=%d, %dx%d pixels, %s\n",
  2771. id, width, height, txtformat);
  2772. refresh_rates_buf[0] = 0;
  2773. refresh_rates = *(u16 *)(par->lcd_table+62);
  2774. m = 1;
  2775. f = 0;
  2776. for (i=0;i<16;i++) {
  2777. if (refresh_rates & m) {
  2778. if (f == 0) {
  2779. sprintf(strbuf, "%d", lcd_refresh_rates[i]);
  2780. f++;
  2781. } else {
  2782. sprintf(strbuf, ",%d", lcd_refresh_rates[i]);
  2783. }
  2784. strcat(refresh_rates_buf,strbuf);
  2785. }
  2786. m = m << 1;
  2787. }
  2788. default_refresh_rate = (*(u8 *)(par->lcd_table+61) & 0xf0) >> 4;
  2789. PRINTKI(" supports refresh rates [%s], default %d Hz\n",
  2790. refresh_rates_buf, lcd_refresh_rates[default_refresh_rate]);
  2791. par->lcd_refreshrate = lcd_refresh_rates[default_refresh_rate];
  2792. /* We now need to determine the crtc parameters for the
  2793. * LCD monitor. This is tricky, because they are not stored
  2794. * individually in the BIOS. Instead, the BIOS contains a
  2795. * table of display modes that work for this monitor.
  2796. *
  2797. * The idea is that we search for a mode of the same dimensions
  2798. * as the dimensions of the LCD monitor. Say our LCD monitor
  2799. * is 800x600 pixels, we search for a 800x600 monitor.
  2800. * The CRTC parameters we find here are the ones that we need
  2801. * to use to simulate other resolutions on the LCD screen.
  2802. */
  2803. lcdmodeptr = (u16 *)(par->lcd_table + 64);
  2804. while (*lcdmodeptr != 0) {
  2805. u32 modeptr;
  2806. u16 mwidth, mheight, lcd_hsync_start, lcd_vsync_start;
  2807. modeptr = bios_base + *lcdmodeptr;
  2808. mwidth = *((u16 *)(modeptr+0));
  2809. mheight = *((u16 *)(modeptr+2));
  2810. if (mwidth == width && mheight == height) {
  2811. par->lcd_pixclock = 100000000 / *((u16 *)(modeptr+9));
  2812. par->lcd_htotal = *((u16 *)(modeptr+17)) & 511;
  2813. par->lcd_hdisp = *((u16 *)(modeptr+19)) & 511;
  2814. lcd_hsync_start = *((u16 *)(modeptr+21)) & 511;
  2815. par->lcd_hsync_dly = (*((u16 *)(modeptr+21)) >> 9) & 7;
  2816. par->lcd_hsync_len = *((u8 *)(modeptr+23)) & 63;
  2817. par->lcd_vtotal = *((u16 *)(modeptr+24)) & 2047;
  2818. par->lcd_vdisp = *((u16 *)(modeptr+26)) & 2047;
  2819. lcd_vsync_start = *((u16 *)(modeptr+28)) & 2047;
  2820. par->lcd_vsync_len = (*((u16 *)(modeptr+28)) >> 11) & 31;
  2821. par->lcd_htotal = (par->lcd_htotal + 1) * 8;
  2822. par->lcd_hdisp = (par->lcd_hdisp + 1) * 8;
  2823. lcd_hsync_start = (lcd_hsync_start + 1) * 8;
  2824. par->lcd_hsync_len = par->lcd_hsync_len * 8;
  2825. par->lcd_vtotal++;
  2826. par->lcd_vdisp++;
  2827. lcd_vsync_start++;
  2828. par->lcd_right_margin = lcd_hsync_start - par->lcd_hdisp;
  2829. par->lcd_lower_margin = lcd_vsync_start - par->lcd_vdisp;
  2830. par->lcd_hblank_len = par->lcd_htotal - par->lcd_hdisp;
  2831. par->lcd_vblank_len = par->lcd_vtotal - par->lcd_vdisp;
  2832. break;
  2833. }
  2834. lcdmodeptr++;
  2835. }
  2836. if (*lcdmodeptr == 0) {
  2837. PRINTKE("LCD monitor CRTC parameters not found!!!\n");
  2838. /* To do: Switch to CRT if possible. */
  2839. } else {
  2840. PRINTKI(" LCD CRTC parameters: %d.%d %d %d %d %d %d %d %d %d\n",
  2841. 1000000 / par->lcd_pixclock, 1000000 % par->lcd_pixclock,
  2842. par->lcd_hdisp,
  2843. par->lcd_hdisp + par->lcd_right_margin,
  2844. par->lcd_hdisp + par->lcd_right_margin
  2845. + par->lcd_hsync_dly + par->lcd_hsync_len,
  2846. par->lcd_htotal,
  2847. par->lcd_vdisp,
  2848. par->lcd_vdisp + par->lcd_lower_margin,
  2849. par->lcd_vdisp + par->lcd_lower_margin + par->lcd_vsync_len,
  2850. par->lcd_vtotal);
  2851. PRINTKI(" : %d %d %d %d %d %d %d %d %d\n",
  2852. par->lcd_pixclock,
  2853. par->lcd_hblank_len - (par->lcd_right_margin +
  2854. par->lcd_hsync_dly + par->lcd_hsync_len),
  2855. par->lcd_hdisp,
  2856. par->lcd_right_margin,
  2857. par->lcd_hsync_len,
  2858. par->lcd_vblank_len - (par->lcd_lower_margin + par->lcd_vsync_len),
  2859. par->lcd_vdisp,
  2860. par->lcd_lower_margin,
  2861. par->lcd_vsync_len);
  2862. }
  2863. }
  2864. }
  2865. #endif /* CONFIG_FB_ATY_GENERIC_LCD */
  2866. static int __devinit init_from_bios(struct atyfb_par *par)
  2867. {
  2868. u32 bios_base, rom_addr;
  2869. int ret;
  2870. rom_addr = 0xc0000 + ((aty_ld_le32(SCRATCH_REG1, par) & 0x7f) << 11);
  2871. bios_base = (unsigned long)ioremap(rom_addr, 0x10000);
  2872. /* The BIOS starts with 0xaa55. */
  2873. if (*((u16 *)bios_base) == 0xaa55) {
  2874. u8 *bios_ptr;
  2875. u16 rom_table_offset, freq_table_offset;
  2876. PLL_BLOCK_MACH64 pll_block;
  2877. PRINTKI("Mach64 BIOS is located at %x, mapped at %x.\n", rom_addr, bios_base);
  2878. /* check for frequncy table */
  2879. bios_ptr = (u8*)bios_base;
  2880. rom_table_offset = (u16)(bios_ptr[0x48] | (bios_ptr[0x49] << 8));
  2881. freq_table_offset = bios_ptr[rom_table_offset + 16] | (bios_ptr[rom_table_offset + 17] << 8);
  2882. memcpy(&pll_block, bios_ptr + freq_table_offset, sizeof(PLL_BLOCK_MACH64));
  2883. PRINTKI("BIOS frequency table:\n");
  2884. PRINTKI("PCLK_min_freq %d, PCLK_max_freq %d, ref_freq %d, ref_divider %d\n",
  2885. pll_block.PCLK_min_freq, pll_block.PCLK_max_freq,
  2886. pll_block.ref_freq, pll_block.ref_divider);
  2887. PRINTKI("MCLK_pwd %d, MCLK_max_freq %d, XCLK_max_freq %d, SCLK_freq %d\n",
  2888. pll_block.MCLK_pwd, pll_block.MCLK_max_freq,
  2889. pll_block.XCLK_max_freq, pll_block.SCLK_freq);
  2890. par->pll_limits.pll_min = pll_block.PCLK_min_freq/100;
  2891. par->pll_limits.pll_max = pll_block.PCLK_max_freq/100;
  2892. par->pll_limits.ref_clk = pll_block.ref_freq/100;
  2893. par->pll_limits.ref_div = pll_block.ref_divider;
  2894. par->pll_limits.sclk = pll_block.SCLK_freq/100;
  2895. par->pll_limits.mclk = pll_block.MCLK_max_freq/100;
  2896. par->pll_limits.mclk_pm = pll_block.MCLK_pwd/100;
  2897. par->pll_limits.xclk = pll_block.XCLK_max_freq/100;
  2898. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  2899. aty_init_lcd(par, bios_base);
  2900. #endif
  2901. ret = 0;
  2902. } else {
  2903. PRINTKE("no BIOS frequency table found, use parameters\n");
  2904. ret = -ENXIO;
  2905. }
  2906. iounmap((void* __iomem )bios_base);
  2907. return ret;
  2908. }
  2909. #endif /* __i386__ */
  2910. static int __devinit atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, unsigned long addr)
  2911. {
  2912. struct atyfb_par *par = info->par;
  2913. u16 tmp;
  2914. unsigned long raddr;
  2915. struct resource *rrp;
  2916. int ret = 0;
  2917. raddr = addr + 0x7ff000UL;
  2918. rrp = &pdev->resource[2];
  2919. if ((rrp->flags & IORESOURCE_MEM) && request_mem_region(rrp->start, rrp->end - rrp->start + 1, "atyfb")) {
  2920. par->aux_start = rrp->start;
  2921. par->aux_size = rrp->end - rrp->start + 1;
  2922. raddr = rrp->start;
  2923. PRINTKI("using auxiliary register aperture\n");
  2924. }
  2925. info->fix.mmio_start = raddr;
  2926. par->ati_regbase = ioremap(info->fix.mmio_start, 0x1000);
  2927. if (par->ati_regbase == 0)
  2928. return -ENOMEM;
  2929. info->fix.mmio_start += par->aux_start ? 0x400 : 0xc00;
  2930. par->ati_regbase += par->aux_start ? 0x400 : 0xc00;
  2931. /*
  2932. * Enable memory-space accesses using config-space
  2933. * command register.
  2934. */
  2935. pci_read_config_word(pdev, PCI_COMMAND, &tmp);
  2936. if (!(tmp & PCI_COMMAND_MEMORY)) {
  2937. tmp |= PCI_COMMAND_MEMORY;
  2938. pci_write_config_word(pdev, PCI_COMMAND, tmp);
  2939. }
  2940. #ifdef __BIG_ENDIAN
  2941. /* Use the big-endian aperture */
  2942. addr += 0x800000;
  2943. #endif
  2944. /* Map in frame buffer */
  2945. info->fix.smem_start = addr;
  2946. info->screen_base = ioremap(addr, 0x800000);
  2947. if (info->screen_base == NULL) {
  2948. ret = -ENOMEM;
  2949. goto atyfb_setup_generic_fail;
  2950. }
  2951. if((ret = correct_chipset(par)))
  2952. goto atyfb_setup_generic_fail;
  2953. #ifdef __i386__
  2954. if((ret = init_from_bios(par)))
  2955. goto atyfb_setup_generic_fail;
  2956. #endif
  2957. if (!(aty_ld_le32(CRTC_GEN_CNTL, par) & CRTC_EXT_DISP_EN))
  2958. par->clk_wr_offset = (inb(R_GENMO) & 0x0CU) >> 2;
  2959. else
  2960. par->clk_wr_offset = aty_ld_8(CLOCK_CNTL, par) & 0x03U;
  2961. /* according to ATI, we should use clock 3 for acelerated mode */
  2962. par->clk_wr_offset = 3;
  2963. return 0;
  2964. atyfb_setup_generic_fail:
  2965. iounmap(par->ati_regbase);
  2966. par->ati_regbase = NULL;
  2967. return ret;
  2968. }
  2969. #endif /* !__sparc__ */
  2970. static int __devinit atyfb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  2971. {
  2972. unsigned long addr, res_start, res_size;
  2973. struct fb_info *info;
  2974. struct resource *rp;
  2975. struct atyfb_par *par;
  2976. int i, rc = -ENOMEM;
  2977. for (i = ARRAY_SIZE(aty_chips) - 1; i >= 0; i--)
  2978. if (pdev->device == aty_chips[i].pci_id)
  2979. break;
  2980. if (i < 0)
  2981. return -ENODEV;
  2982. /* Enable device in PCI config */
  2983. if (pci_enable_device(pdev)) {
  2984. PRINTKE("Cannot enable PCI device\n");
  2985. return -ENXIO;
  2986. }
  2987. /* Find which resource to use */
  2988. rp = &pdev->resource[0];
  2989. if (rp->flags & IORESOURCE_IO)
  2990. rp = &pdev->resource[1];
  2991. addr = rp->start;
  2992. if (!addr)
  2993. return -ENXIO;
  2994. /* Reserve space */
  2995. res_start = rp->start;
  2996. res_size = rp->end - rp->start + 1;
  2997. if (!request_mem_region (res_start, res_size, "atyfb"))
  2998. return -EBUSY;
  2999. /* Allocate framebuffer */
  3000. info = framebuffer_alloc(sizeof(struct atyfb_par), &pdev->dev);
  3001. if (!info) {
  3002. PRINTKE("atyfb_pci_probe() can't alloc fb_info\n");
  3003. return -ENOMEM;
  3004. }
  3005. par = info->par;
  3006. info->fix = atyfb_fix;
  3007. info->device = &pdev->dev;
  3008. par->pci_id = aty_chips[i].pci_id;
  3009. par->res_start = res_start;
  3010. par->res_size = res_size;
  3011. par->irq = pdev->irq;
  3012. /* Setup "info" structure */
  3013. #ifdef __sparc__
  3014. rc = atyfb_setup_sparc(pdev, info, addr);
  3015. #else
  3016. rc = atyfb_setup_generic(pdev, info, addr);
  3017. #endif
  3018. if (rc)
  3019. goto err_release_mem;
  3020. pci_set_drvdata(pdev, info);
  3021. /* Init chip & register framebuffer */
  3022. if (aty_init(info, "PCI"))
  3023. goto err_release_io;
  3024. #ifdef __sparc__
  3025. if (!prom_palette)
  3026. prom_palette = atyfb_palette;
  3027. /*
  3028. * Add /dev/fb mmap values.
  3029. */
  3030. par->mmap_map[0].voff = 0x8000000000000000UL;
  3031. par->mmap_map[0].poff = (unsigned long) info->screen_base & PAGE_MASK;
  3032. par->mmap_map[0].size = info->fix.smem_len;
  3033. par->mmap_map[0].prot_mask = _PAGE_CACHE;
  3034. par->mmap_map[0].prot_flag = _PAGE_E;
  3035. par->mmap_map[1].voff = par->mmap_map[0].voff + info->fix.smem_len;
  3036. par->mmap_map[1].poff = (long)par->ati_regbase & PAGE_MASK;
  3037. par->mmap_map[1].size = PAGE_SIZE;
  3038. par->mmap_map[1].prot_mask = _PAGE_CACHE;
  3039. par->mmap_map[1].prot_flag = _PAGE_E;
  3040. #endif /* __sparc__ */
  3041. return 0;
  3042. err_release_io:
  3043. #ifdef __sparc__
  3044. kfree(par->mmap_map);
  3045. #else
  3046. if (par->ati_regbase)
  3047. iounmap(par->ati_regbase);
  3048. if (info->screen_base)
  3049. iounmap(info->screen_base);
  3050. #endif
  3051. err_release_mem:
  3052. if (par->aux_start)
  3053. release_mem_region(par->aux_start, par->aux_size);
  3054. release_mem_region(par->res_start, par->res_size);
  3055. framebuffer_release(info);
  3056. return rc;
  3057. }
  3058. #endif /* CONFIG_PCI */
  3059. #ifdef CONFIG_ATARI
  3060. static int __devinit atyfb_atari_probe(void)
  3061. {
  3062. struct atyfb_par *par;
  3063. struct fb_info *info;
  3064. int m64_num;
  3065. u32 clock_r;
  3066. for (m64_num = 0; m64_num < mach64_count; m64_num++) {
  3067. if (!phys_vmembase[m64_num] || !phys_size[m64_num] ||
  3068. !phys_guiregbase[m64_num]) {
  3069. PRINTKI("phys_*[%d] parameters not set => returning early. \n", m64_num);
  3070. continue;
  3071. }
  3072. info = framebuffer_alloc(sizeof(struct atyfb_par), NULL);
  3073. if (!info) {
  3074. PRINTKE("atyfb_atari_probe() can't alloc fb_info\n");
  3075. return -ENOMEM;
  3076. }
  3077. par = info->par;
  3078. info->fix = atyfb_fix;
  3079. par->irq = (unsigned int) -1; /* something invalid */
  3080. /*
  3081. * Map the video memory (physical address given) to somewhere in the
  3082. * kernel address space.
  3083. */
  3084. info->screen_base = ioremap(phys_vmembase[m64_num], phys_size[m64_num]);
  3085. info->fix.smem_start = (unsigned long)info->screen_base; /* Fake! */
  3086. par->ati_regbase = ioremap(phys_guiregbase[m64_num], 0x10000) +
  3087. 0xFC00ul;
  3088. info->fix.mmio_start = (unsigned long)par->ati_regbase; /* Fake! */
  3089. aty_st_le32(CLOCK_CNTL, 0x12345678, par);
  3090. clock_r = aty_ld_le32(CLOCK_CNTL, par);
  3091. switch (clock_r & 0x003F) {
  3092. case 0x12:
  3093. par->clk_wr_offset = 3; /* */
  3094. break;
  3095. case 0x34:
  3096. par->clk_wr_offset = 2; /* Medusa ST-IO ISA Adapter etc. */
  3097. break;
  3098. case 0x16:
  3099. par->clk_wr_offset = 1; /* */
  3100. break;
  3101. case 0x38:
  3102. par->clk_wr_offset = 0; /* Panther 1 ISA Adapter (Gerald) */
  3103. break;
  3104. }
  3105. if (aty_init(info, "ISA bus")) {
  3106. framebuffer_release(info);
  3107. /* This is insufficient! kernel_map has added two large chunks!! */
  3108. return -ENXIO;
  3109. }
  3110. }
  3111. }
  3112. #endif /* CONFIG_ATARI */
  3113. static void __devexit atyfb_remove(struct fb_info *info)
  3114. {
  3115. struct atyfb_par *par = (struct atyfb_par *) info->par;
  3116. /* restore video mode */
  3117. aty_set_crtc(par, &saved_crtc);
  3118. par->pll_ops->set_pll(info, &saved_pll);
  3119. unregister_framebuffer(info);
  3120. #ifdef CONFIG_MTRR
  3121. if (par->mtrr_reg >= 0) {
  3122. mtrr_del(par->mtrr_reg, 0, 0);
  3123. par->mtrr_reg = -1;
  3124. }
  3125. if (par->mtrr_aper >= 0) {
  3126. mtrr_del(par->mtrr_aper, 0, 0);
  3127. par->mtrr_aper = -1;
  3128. }
  3129. #endif
  3130. #ifndef __sparc__
  3131. if (par->ati_regbase)
  3132. iounmap(par->ati_regbase);
  3133. if (info->screen_base)
  3134. iounmap(info->screen_base);
  3135. #ifdef __BIG_ENDIAN
  3136. if (info->sprite.addr)
  3137. iounmap(info->sprite.addr);
  3138. #endif
  3139. #endif
  3140. #ifdef __sparc__
  3141. kfree(par->mmap_map);
  3142. #endif
  3143. if (par->aux_start)
  3144. release_mem_region(par->aux_start, par->aux_size);
  3145. if (par->res_start)
  3146. release_mem_region(par->res_start, par->res_size);
  3147. framebuffer_release(info);
  3148. }
  3149. #ifdef CONFIG_PCI
  3150. static void __devexit atyfb_pci_remove(struct pci_dev *pdev)
  3151. {
  3152. struct fb_info *info = pci_get_drvdata(pdev);
  3153. atyfb_remove(info);
  3154. }
  3155. /*
  3156. * This driver uses its own matching table. That will be more difficult
  3157. * to fix, so for now, we just match against any ATI ID and let the
  3158. * probe() function find out what's up. That also mean we don't have
  3159. * a module ID table though.
  3160. */
  3161. static struct pci_device_id atyfb_pci_tbl[] = {
  3162. { PCI_VENDOR_ID_ATI, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  3163. PCI_BASE_CLASS_DISPLAY << 16, 0xff0000, 0 },
  3164. { 0, }
  3165. };
  3166. static struct pci_driver atyfb_driver = {
  3167. .name = "atyfb",
  3168. .id_table = atyfb_pci_tbl,
  3169. .probe = atyfb_pci_probe,
  3170. .remove = __devexit_p(atyfb_pci_remove),
  3171. #ifdef CONFIG_PM
  3172. .suspend = atyfb_pci_suspend,
  3173. .resume = atyfb_pci_resume,
  3174. #endif /* CONFIG_PM */
  3175. };
  3176. #endif /* CONFIG_PCI */
  3177. #ifndef MODULE
  3178. static int __init atyfb_setup(char *options)
  3179. {
  3180. char *this_opt;
  3181. if (!options || !*options)
  3182. return 0;
  3183. while ((this_opt = strsep(&options, ",")) != NULL) {
  3184. if (!strncmp(this_opt, "noaccel", 7)) {
  3185. noaccel = 1;
  3186. #ifdef CONFIG_MTRR
  3187. } else if (!strncmp(this_opt, "nomtrr", 6)) {
  3188. nomtrr = 1;
  3189. #endif
  3190. } else if (!strncmp(this_opt, "vram:", 5))
  3191. vram = simple_strtoul(this_opt + 5, NULL, 0);
  3192. else if (!strncmp(this_opt, "pll:", 4))
  3193. pll = simple_strtoul(this_opt + 4, NULL, 0);
  3194. else if (!strncmp(this_opt, "mclk:", 5))
  3195. mclk = simple_strtoul(this_opt + 5, NULL, 0);
  3196. else if (!strncmp(this_opt, "xclk:", 5))
  3197. xclk = simple_strtoul(this_opt+5, NULL, 0);
  3198. else if (!strncmp(this_opt, "comp_sync:", 10))
  3199. comp_sync = simple_strtoul(this_opt+10, NULL, 0);
  3200. #ifdef CONFIG_PPC
  3201. else if (!strncmp(this_opt, "vmode:", 6)) {
  3202. unsigned int vmode =
  3203. simple_strtoul(this_opt + 6, NULL, 0);
  3204. if (vmode > 0 && vmode <= VMODE_MAX)
  3205. default_vmode = vmode;
  3206. } else if (!strncmp(this_opt, "cmode:", 6)) {
  3207. unsigned int cmode =
  3208. simple_strtoul(this_opt + 6, NULL, 0);
  3209. switch (cmode) {
  3210. case 0:
  3211. case 8:
  3212. default_cmode = CMODE_8;
  3213. break;
  3214. case 15:
  3215. case 16:
  3216. default_cmode = CMODE_16;
  3217. break;
  3218. case 24:
  3219. case 32:
  3220. default_cmode = CMODE_32;
  3221. break;
  3222. }
  3223. }
  3224. #endif
  3225. #ifdef CONFIG_ATARI
  3226. /*
  3227. * Why do we need this silly Mach64 argument?
  3228. * We are already here because of mach64= so its redundant.
  3229. */
  3230. else if (MACH_IS_ATARI
  3231. && (!strncmp(this_opt, "Mach64:", 7))) {
  3232. static unsigned char m64_num;
  3233. static char mach64_str[80];
  3234. strlcpy(mach64_str, this_opt + 7, sizeof(mach64_str));
  3235. if (!store_video_par(mach64_str, m64_num)) {
  3236. m64_num++;
  3237. mach64_count = m64_num;
  3238. }
  3239. }
  3240. #endif
  3241. else
  3242. mode = this_opt;
  3243. }
  3244. return 0;
  3245. }
  3246. #endif /* MODULE */
  3247. static int __init atyfb_init(void)
  3248. {
  3249. #ifndef MODULE
  3250. char *option = NULL;
  3251. if (fb_get_options("atyfb", &option))
  3252. return -ENODEV;
  3253. atyfb_setup(option);
  3254. #endif
  3255. pci_register_driver(&atyfb_driver);
  3256. #ifdef CONFIG_ATARI
  3257. atyfb_atari_probe();
  3258. #endif
  3259. return 0;
  3260. }
  3261. static void __exit atyfb_exit(void)
  3262. {
  3263. pci_unregister_driver(&atyfb_driver);
  3264. }
  3265. module_init(atyfb_init);
  3266. module_exit(atyfb_exit);
  3267. MODULE_DESCRIPTION("FBDev driver for ATI Mach64 cards");
  3268. MODULE_LICENSE("GPL");
  3269. module_param(noaccel, bool, 0);
  3270. MODULE_PARM_DESC(noaccel, "bool: disable acceleration");
  3271. module_param(vram, int, 0);
  3272. MODULE_PARM_DESC(vram, "int: override size of video ram");
  3273. module_param(pll, int, 0);
  3274. MODULE_PARM_DESC(pll, "int: override video clock");
  3275. module_param(mclk, int, 0);
  3276. MODULE_PARM_DESC(mclk, "int: override memory clock");
  3277. module_param(xclk, int, 0);
  3278. MODULE_PARM_DESC(xclk, "int: override accelerated engine clock");
  3279. module_param(comp_sync, int, 0);
  3280. MODULE_PARM_DESC(comp_sync,
  3281. "Set composite sync signal to low (0) or high (1)");
  3282. module_param(mode, charp, 0);
  3283. MODULE_PARM_DESC(mode, "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
  3284. #ifdef CONFIG_MTRR
  3285. module_param(nomtrr, bool, 0);
  3286. MODULE_PARM_DESC(nomtrr, "bool: disable use of MTRR registers");
  3287. #endif