PageRenderTime 62ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/video/aty/atyfb_base.c

https://github.com/mstsirkin/linux
C | 1631 lines | 1255 code | 199 blank | 177 comment | 169 complexity | def674e294f81689722f612f46ca2ea4 MD5 | raw file
  1. /*
  2. * ATI Frame Buffer Device Driver Core
  3. *
  4. * Copyright (C) 2004 Alex Kern <alex.kern@gmx.de>
  5. * Copyright (C) 1997-2001 Geert Uytterhoeven
  6. * Copyright (C) 1998 Bernd Harries
  7. * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
  8. *
  9. * This driver supports the following ATI graphics chips:
  10. * - ATI Mach64
  11. *
  12. * To do: add support for
  13. * - ATI Rage128 (from aty128fb.c)
  14. * - ATI Radeon (from radeonfb.c)
  15. *
  16. * This driver is partly based on the PowerMac console driver:
  17. *
  18. * Copyright (C) 1996 Paul Mackerras
  19. *
  20. * and on the PowerMac ATI/mach64 display driver:
  21. *
  22. * Copyright (C) 1997 Michael AK Tesch
  23. *
  24. * with work by Jon Howell
  25. * Harry AC Eaton
  26. * Anthony Tong <atong@uiuc.edu>
  27. *
  28. * Generic LCD support written by Daniel Mantione, ported from 2.4.20 by Alex Kern
  29. * Many Thanks to Ville Syrjälä for patches and fixing nasting 16 bit color bug.
  30. *
  31. * This file is subject to the terms and conditions of the GNU General Public
  32. * License. See the file COPYING in the main directory of this archive for
  33. * more details.
  34. *
  35. * Many thanks to Nitya from ATI devrel for support and patience !
  36. */
  37. /******************************************************************************
  38. TODO:
  39. - cursor support on all cards and all ramdacs.
  40. - cursor parameters controlable via ioctl()s.
  41. - guess PLL and MCLK based on the original PLL register values initialized
  42. by Open Firmware (if they are initialized). BIOS is done
  43. (Anyone with Mac to help with this?)
  44. ******************************************************************************/
  45. #include <linux/module.h>
  46. #include <linux/moduleparam.h>
  47. #include <linux/kernel.h>
  48. #include <linux/errno.h>
  49. #include <linux/string.h>
  50. #include <linux/mm.h>
  51. #include <linux/slab.h>
  52. #include <linux/vmalloc.h>
  53. #include <linux/delay.h>
  54. #include <linux/console.h>
  55. #include <linux/fb.h>
  56. #include <linux/init.h>
  57. #include <linux/pci.h>
  58. #include <linux/interrupt.h>
  59. #include <linux/spinlock.h>
  60. #include <linux/wait.h>
  61. #include <linux/backlight.h>
  62. #include <linux/reboot.h>
  63. #include <linux/dmi.h>
  64. #include <asm/io.h>
  65. #include <linux/uaccess.h>
  66. #include <video/mach64.h>
  67. #include "atyfb.h"
  68. #include "ati_ids.h"
  69. #ifdef __powerpc__
  70. #include <asm/machdep.h>
  71. #include <asm/prom.h>
  72. #include "../macmodes.h"
  73. #endif
  74. #ifdef __sparc__
  75. #include <asm/fbio.h>
  76. #include <asm/oplib.h>
  77. #include <asm/prom.h>
  78. #endif
  79. #ifdef CONFIG_ADB_PMU
  80. #include <linux/adb.h>
  81. #include <linux/pmu.h>
  82. #endif
  83. #ifdef CONFIG_BOOTX_TEXT
  84. #include <asm/btext.h>
  85. #endif
  86. #ifdef CONFIG_PMAC_BACKLIGHT
  87. #include <asm/backlight.h>
  88. #endif
  89. #ifdef CONFIG_MTRR
  90. #include <asm/mtrr.h>
  91. #endif
  92. /*
  93. * Debug flags.
  94. */
  95. #undef DEBUG
  96. /*#define DEBUG*/
  97. /* Make sure n * PAGE_SIZE is protected at end of Aperture for GUI-regs */
  98. /* - must be large enough to catch all GUI-Regs */
  99. /* - must be aligned to a PAGE boundary */
  100. #define GUI_RESERVE (1 * PAGE_SIZE)
  101. /* FIXME: remove the FAIL definition */
  102. #define FAIL(msg) do { \
  103. if (!(var->activate & FB_ACTIVATE_TEST)) \
  104. printk(KERN_CRIT "atyfb: " msg "\n"); \
  105. return -EINVAL; \
  106. } while (0)
  107. #define FAIL_MAX(msg, x, _max_) do { \
  108. if (x > _max_) { \
  109. if (!(var->activate & FB_ACTIVATE_TEST)) \
  110. printk(KERN_CRIT "atyfb: " msg " %x(%x)\n", x, _max_); \
  111. return -EINVAL; \
  112. } \
  113. } while (0)
  114. #ifdef DEBUG
  115. #define DPRINTK(fmt, args...) printk(KERN_DEBUG "atyfb: " fmt, ## args)
  116. #else
  117. #define DPRINTK(fmt, args...)
  118. #endif
  119. #define PRINTKI(fmt, args...) printk(KERN_INFO "atyfb: " fmt, ## args)
  120. #define PRINTKE(fmt, args...) printk(KERN_ERR "atyfb: " fmt, ## args)
  121. #if defined(CONFIG_PM) || defined(CONFIG_PMAC_BACKLIGHT) || \
  122. defined (CONFIG_FB_ATY_GENERIC_LCD) || defined(CONFIG_FB_ATY_BACKLIGHT)
  123. static const u32 lt_lcd_regs[] = {
  124. CNFG_PANEL_LG,
  125. LCD_GEN_CNTL_LG,
  126. DSTN_CONTROL_LG,
  127. HFB_PITCH_ADDR_LG,
  128. HORZ_STRETCHING_LG,
  129. VERT_STRETCHING_LG,
  130. 0, /* EXT_VERT_STRETCH */
  131. LT_GIO_LG,
  132. POWER_MANAGEMENT_LG
  133. };
  134. void aty_st_lcd(int index, u32 val, const struct atyfb_par *par)
  135. {
  136. if (M64_HAS(LT_LCD_REGS)) {
  137. aty_st_le32(lt_lcd_regs[index], val, par);
  138. } else {
  139. unsigned long temp;
  140. /* write addr byte */
  141. temp = aty_ld_le32(LCD_INDEX, par);
  142. aty_st_le32(LCD_INDEX, (temp & ~LCD_INDEX_MASK) | index, par);
  143. /* write the register value */
  144. aty_st_le32(LCD_DATA, val, par);
  145. }
  146. }
  147. u32 aty_ld_lcd(int index, const struct atyfb_par *par)
  148. {
  149. if (M64_HAS(LT_LCD_REGS)) {
  150. return aty_ld_le32(lt_lcd_regs[index], par);
  151. } else {
  152. unsigned long temp;
  153. /* write addr byte */
  154. temp = aty_ld_le32(LCD_INDEX, par);
  155. aty_st_le32(LCD_INDEX, (temp & ~LCD_INDEX_MASK) | index, par);
  156. /* read the register value */
  157. return aty_ld_le32(LCD_DATA, par);
  158. }
  159. }
  160. #endif /* defined(CONFIG_PM) || defined(CONFIG_PMAC_BACKLIGHT) || defined (CONFIG_FB_ATY_GENERIC_LCD) */
  161. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  162. /*
  163. * ATIReduceRatio --
  164. *
  165. * Reduce a fraction by factoring out the largest common divider of the
  166. * fraction's numerator and denominator.
  167. */
  168. static void ATIReduceRatio(int *Numerator, int *Denominator)
  169. {
  170. int Multiplier, Divider, Remainder;
  171. Multiplier = *Numerator;
  172. Divider = *Denominator;
  173. while ((Remainder = Multiplier % Divider)) {
  174. Multiplier = Divider;
  175. Divider = Remainder;
  176. }
  177. *Numerator /= Divider;
  178. *Denominator /= Divider;
  179. }
  180. #endif
  181. /*
  182. * The Hardware parameters for each card
  183. */
  184. struct pci_mmap_map {
  185. unsigned long voff;
  186. unsigned long poff;
  187. unsigned long size;
  188. unsigned long prot_flag;
  189. unsigned long prot_mask;
  190. };
  191. static struct fb_fix_screeninfo atyfb_fix __devinitdata = {
  192. .id = "ATY Mach64",
  193. .type = FB_TYPE_PACKED_PIXELS,
  194. .visual = FB_VISUAL_PSEUDOCOLOR,
  195. .xpanstep = 8,
  196. .ypanstep = 1,
  197. };
  198. /*
  199. * Frame buffer device API
  200. */
  201. static int atyfb_open(struct fb_info *info, int user);
  202. static int atyfb_release(struct fb_info *info, int user);
  203. static int atyfb_check_var(struct fb_var_screeninfo *var,
  204. struct fb_info *info);
  205. static int atyfb_set_par(struct fb_info *info);
  206. static int atyfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  207. u_int transp, struct fb_info *info);
  208. static int atyfb_pan_display(struct fb_var_screeninfo *var,
  209. struct fb_info *info);
  210. static int atyfb_blank(int blank, struct fb_info *info);
  211. static int atyfb_ioctl(struct fb_info *info, u_int cmd, u_long arg);
  212. #ifdef __sparc__
  213. static int atyfb_mmap(struct fb_info *info, struct vm_area_struct *vma);
  214. #endif
  215. static int atyfb_sync(struct fb_info *info);
  216. /*
  217. * Internal routines
  218. */
  219. static int aty_init(struct fb_info *info);
  220. static void aty_get_crtc(const struct atyfb_par *par, struct crtc *crtc);
  221. static void aty_set_crtc(const struct atyfb_par *par, const struct crtc *crtc);
  222. static int aty_var_to_crtc(const struct fb_info *info,
  223. const struct fb_var_screeninfo *var,
  224. struct crtc *crtc);
  225. static int aty_crtc_to_var(const struct crtc *crtc,
  226. struct fb_var_screeninfo *var);
  227. static void set_off_pitch(struct atyfb_par *par, const struct fb_info *info);
  228. #ifdef CONFIG_PPC
  229. static int read_aty_sense(const struct atyfb_par *par);
  230. #endif
  231. static DEFINE_MUTEX(reboot_lock);
  232. static struct fb_info *reboot_info;
  233. /*
  234. * Interface used by the world
  235. */
  236. static struct fb_var_screeninfo default_var = {
  237. /* 640x480, 60 Hz, Non-Interlaced (25.175 MHz dotclock) */
  238. 640, 480, 640, 480, 0, 0, 8, 0,
  239. {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
  240. 0, 0, -1, -1, 0, 39722, 48, 16, 33, 10, 96, 2,
  241. 0, FB_VMODE_NONINTERLACED
  242. };
  243. static struct fb_videomode defmode = {
  244. /* 640x480 @ 60 Hz, 31.5 kHz hsync */
  245. NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2,
  246. 0, FB_VMODE_NONINTERLACED
  247. };
  248. static struct fb_ops atyfb_ops = {
  249. .owner = THIS_MODULE,
  250. .fb_open = atyfb_open,
  251. .fb_release = atyfb_release,
  252. .fb_check_var = atyfb_check_var,
  253. .fb_set_par = atyfb_set_par,
  254. .fb_setcolreg = atyfb_setcolreg,
  255. .fb_pan_display = atyfb_pan_display,
  256. .fb_blank = atyfb_blank,
  257. .fb_ioctl = atyfb_ioctl,
  258. .fb_fillrect = atyfb_fillrect,
  259. .fb_copyarea = atyfb_copyarea,
  260. .fb_imageblit = atyfb_imageblit,
  261. #ifdef __sparc__
  262. .fb_mmap = atyfb_mmap,
  263. #endif
  264. .fb_sync = atyfb_sync,
  265. };
  266. static int noaccel;
  267. #ifdef CONFIG_MTRR
  268. static int nomtrr;
  269. #endif
  270. static int vram;
  271. static int pll;
  272. static int mclk;
  273. static int xclk;
  274. static int comp_sync __devinitdata = -1;
  275. static char *mode;
  276. #ifdef CONFIG_PMAC_BACKLIGHT
  277. static int backlight __devinitdata = 1;
  278. #else
  279. static int backlight __devinitdata = 0;
  280. #endif
  281. #ifdef CONFIG_PPC
  282. static int default_vmode __devinitdata = VMODE_CHOOSE;
  283. static int default_cmode __devinitdata = CMODE_CHOOSE;
  284. module_param_named(vmode, default_vmode, int, 0);
  285. MODULE_PARM_DESC(vmode, "int: video mode for mac");
  286. module_param_named(cmode, default_cmode, int, 0);
  287. MODULE_PARM_DESC(cmode, "int: color mode for mac");
  288. #endif
  289. #ifdef CONFIG_ATARI
  290. static unsigned int mach64_count __devinitdata = 0;
  291. static unsigned long phys_vmembase[FB_MAX] __devinitdata = { 0, };
  292. static unsigned long phys_size[FB_MAX] __devinitdata = { 0, };
  293. static unsigned long phys_guiregbase[FB_MAX] __devinitdata = { 0, };
  294. #endif
  295. /* top -> down is an evolution of mach64 chipset, any corrections? */
  296. #define ATI_CHIP_88800GX (M64F_GX)
  297. #define ATI_CHIP_88800CX (M64F_GX)
  298. #define ATI_CHIP_264CT (M64F_CT | M64F_INTEGRATED | M64F_CT_BUS | M64F_MAGIC_FIFO)
  299. #define ATI_CHIP_264ET (M64F_CT | M64F_INTEGRATED | M64F_CT_BUS | M64F_MAGIC_FIFO)
  300. #define ATI_CHIP_264VT (M64F_VT | M64F_INTEGRATED | M64F_VT_BUS | M64F_MAGIC_FIFO)
  301. #define ATI_CHIP_264GT (M64F_GT | M64F_INTEGRATED | M64F_MAGIC_FIFO | M64F_EXTRA_BRIGHT)
  302. #define ATI_CHIP_264VTB (M64F_VT | M64F_INTEGRATED | M64F_VT_BUS | M64F_GTB_DSP)
  303. #define ATI_CHIP_264VT3 (M64F_VT | M64F_INTEGRATED | M64F_VT_BUS | M64F_GTB_DSP | M64F_SDRAM_MAGIC_PLL)
  304. #define ATI_CHIP_264VT4 (M64F_VT | M64F_INTEGRATED | M64F_GTB_DSP)
  305. /* FIXME what is this chip? */
  306. #define ATI_CHIP_264LT (M64F_GT | M64F_INTEGRATED | M64F_GTB_DSP)
  307. /* make sets shorter */
  308. #define ATI_MODERN_SET (M64F_GT | M64F_INTEGRATED | M64F_GTB_DSP | M64F_EXTRA_BRIGHT)
  309. #define ATI_CHIP_264GTB (ATI_MODERN_SET | M64F_SDRAM_MAGIC_PLL)
  310. /*#define ATI_CHIP_264GTDVD ?*/
  311. #define ATI_CHIP_264LTG (ATI_MODERN_SET | M64F_SDRAM_MAGIC_PLL)
  312. #define ATI_CHIP_264GT2C (ATI_MODERN_SET | M64F_SDRAM_MAGIC_PLL | M64F_HW_TRIPLE)
  313. #define ATI_CHIP_264GTPRO (ATI_MODERN_SET | M64F_SDRAM_MAGIC_PLL | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D)
  314. #define ATI_CHIP_264LTPRO (ATI_MODERN_SET | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D)
  315. #define ATI_CHIP_264XL (ATI_MODERN_SET | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D | M64F_XL_DLL | M64F_MFB_FORCE_4 | M64F_XL_MEM)
  316. #define ATI_CHIP_MOBILITY (ATI_MODERN_SET | M64F_HW_TRIPLE | M64F_FIFO_32 | M64F_RESET_3D | M64F_XL_DLL | M64F_MFB_FORCE_4 | M64F_XL_MEM | M64F_MOBIL_BUS)
  317. static struct {
  318. u16 pci_id;
  319. const char *name;
  320. int pll, mclk, xclk, ecp_max;
  321. u32 features;
  322. } aty_chips[] __devinitdata = {
  323. #ifdef CONFIG_FB_ATY_GX
  324. /* Mach64 GX */
  325. { PCI_CHIP_MACH64GX, "ATI888GX00 (Mach64 GX)", 135, 50, 50, 0, ATI_CHIP_88800GX },
  326. { PCI_CHIP_MACH64CX, "ATI888CX00 (Mach64 CX)", 135, 50, 50, 0, ATI_CHIP_88800CX },
  327. #endif /* CONFIG_FB_ATY_GX */
  328. #ifdef CONFIG_FB_ATY_CT
  329. { PCI_CHIP_MACH64CT, "ATI264CT (Mach64 CT)", 135, 60, 60, 0, ATI_CHIP_264CT },
  330. { PCI_CHIP_MACH64ET, "ATI264ET (Mach64 ET)", 135, 60, 60, 0, ATI_CHIP_264ET },
  331. /* FIXME what is this chip? */
  332. { PCI_CHIP_MACH64LT, "ATI264LT (Mach64 LT)", 135, 63, 63, 0, ATI_CHIP_264LT },
  333. { PCI_CHIP_MACH64VT, "ATI264VT (Mach64 VT)", 170, 67, 67, 80, ATI_CHIP_264VT },
  334. { PCI_CHIP_MACH64GT, "3D RAGE (Mach64 GT)", 135, 63, 63, 80, ATI_CHIP_264GT },
  335. { PCI_CHIP_MACH64VU, "ATI264VT3 (Mach64 VU)", 200, 67, 67, 80, ATI_CHIP_264VT3 },
  336. { PCI_CHIP_MACH64GU, "3D RAGE II+ (Mach64 GU)", 200, 67, 67, 100, ATI_CHIP_264GTB },
  337. { PCI_CHIP_MACH64LG, "3D RAGE LT (Mach64 LG)", 230, 63, 63, 100, ATI_CHIP_264LTG | M64F_LT_LCD_REGS | M64F_G3_PB_1024x768 },
  338. { PCI_CHIP_MACH64VV, "ATI264VT4 (Mach64 VV)", 230, 83, 83, 100, ATI_CHIP_264VT4 },
  339. { PCI_CHIP_MACH64GV, "3D RAGE IIC (Mach64 GV, PCI)", 230, 83, 83, 100, ATI_CHIP_264GT2C },
  340. { PCI_CHIP_MACH64GW, "3D RAGE IIC (Mach64 GW, AGP)", 230, 83, 83, 100, ATI_CHIP_264GT2C },
  341. { PCI_CHIP_MACH64GY, "3D RAGE IIC (Mach64 GY, PCI)", 230, 83, 83, 100, ATI_CHIP_264GT2C },
  342. { PCI_CHIP_MACH64GZ, "3D RAGE IIC (Mach64 GZ, AGP)", 230, 83, 83, 100, ATI_CHIP_264GT2C },
  343. { PCI_CHIP_MACH64GB, "3D RAGE PRO (Mach64 GB, BGA, AGP)", 230, 100, 100, 125, ATI_CHIP_264GTPRO },
  344. { PCI_CHIP_MACH64GD, "3D RAGE PRO (Mach64 GD, BGA, AGP 1x)", 230, 100, 100, 125, ATI_CHIP_264GTPRO },
  345. { PCI_CHIP_MACH64GI, "3D RAGE PRO (Mach64 GI, BGA, PCI)", 230, 100, 100, 125, ATI_CHIP_264GTPRO | M64F_MAGIC_VRAM_SIZE },
  346. { PCI_CHIP_MACH64GP, "3D RAGE PRO (Mach64 GP, PQFP, PCI)", 230, 100, 100, 125, ATI_CHIP_264GTPRO },
  347. { PCI_CHIP_MACH64GQ, "3D RAGE PRO (Mach64 GQ, PQFP, PCI, limited 3D)", 230, 100, 100, 125, ATI_CHIP_264GTPRO },
  348. { PCI_CHIP_MACH64LB, "3D RAGE LT PRO (Mach64 LB, AGP)", 236, 75, 100, 135, ATI_CHIP_264LTPRO },
  349. { PCI_CHIP_MACH64LD, "3D RAGE LT PRO (Mach64 LD, AGP)", 230, 100, 100, 135, ATI_CHIP_264LTPRO },
  350. { PCI_CHIP_MACH64LI, "3D RAGE LT PRO (Mach64 LI, PCI)", 230, 100, 100, 135, ATI_CHIP_264LTPRO | M64F_G3_PB_1_1 | M64F_G3_PB_1024x768 },
  351. { PCI_CHIP_MACH64LP, "3D RAGE LT PRO (Mach64 LP, PCI)", 230, 100, 100, 135, ATI_CHIP_264LTPRO | M64F_G3_PB_1024x768 },
  352. { PCI_CHIP_MACH64LQ, "3D RAGE LT PRO (Mach64 LQ, PCI)", 230, 100, 100, 135, ATI_CHIP_264LTPRO },
  353. { PCI_CHIP_MACH64GM, "3D RAGE XL (Mach64 GM, AGP 2x)", 230, 83, 63, 135, ATI_CHIP_264XL },
  354. { PCI_CHIP_MACH64GN, "3D RAGE XC (Mach64 GN, AGP 2x)", 230, 83, 63, 135, ATI_CHIP_264XL },
  355. { PCI_CHIP_MACH64GO, "3D RAGE XL (Mach64 GO, PCI-66)", 230, 83, 63, 135, ATI_CHIP_264XL },
  356. { PCI_CHIP_MACH64GL, "3D RAGE XC (Mach64 GL, PCI-66)", 230, 83, 63, 135, ATI_CHIP_264XL },
  357. { PCI_CHIP_MACH64GR, "3D RAGE XL (Mach64 GR, PCI-33)", 230, 83, 63, 135, ATI_CHIP_264XL | M64F_SDRAM_MAGIC_PLL },
  358. { PCI_CHIP_MACH64GS, "3D RAGE XC (Mach64 GS, PCI-33)", 230, 83, 63, 135, ATI_CHIP_264XL },
  359. { PCI_CHIP_MACH64LM, "3D RAGE Mobility P/M (Mach64 LM, AGP 2x)", 230, 83, 125, 135, ATI_CHIP_MOBILITY },
  360. { PCI_CHIP_MACH64LN, "3D RAGE Mobility L (Mach64 LN, AGP 2x)", 230, 83, 125, 135, ATI_CHIP_MOBILITY },
  361. { PCI_CHIP_MACH64LR, "3D RAGE Mobility P/M (Mach64 LR, PCI)", 230, 83, 125, 135, ATI_CHIP_MOBILITY },
  362. { PCI_CHIP_MACH64LS, "3D RAGE Mobility L (Mach64 LS, PCI)", 230, 83, 125, 135, ATI_CHIP_MOBILITY },
  363. #endif /* CONFIG_FB_ATY_CT */
  364. };
  365. static int __devinit correct_chipset(struct atyfb_par *par)
  366. {
  367. u8 rev;
  368. u16 type;
  369. u32 chip_id;
  370. const char *name;
  371. int i;
  372. for (i = ARRAY_SIZE(aty_chips) - 1; i >= 0; i--)
  373. if (par->pci_id == aty_chips[i].pci_id)
  374. break;
  375. if (i < 0)
  376. return -ENODEV;
  377. name = aty_chips[i].name;
  378. par->pll_limits.pll_max = aty_chips[i].pll;
  379. par->pll_limits.mclk = aty_chips[i].mclk;
  380. par->pll_limits.xclk = aty_chips[i].xclk;
  381. par->pll_limits.ecp_max = aty_chips[i].ecp_max;
  382. par->features = aty_chips[i].features;
  383. chip_id = aty_ld_le32(CNFG_CHIP_ID, par);
  384. type = chip_id & CFG_CHIP_TYPE;
  385. rev = (chip_id & CFG_CHIP_REV) >> 24;
  386. switch (par->pci_id) {
  387. #ifdef CONFIG_FB_ATY_GX
  388. case PCI_CHIP_MACH64GX:
  389. if (type != 0x00d7)
  390. return -ENODEV;
  391. break;
  392. case PCI_CHIP_MACH64CX:
  393. if (type != 0x0057)
  394. return -ENODEV;
  395. break;
  396. #endif
  397. #ifdef CONFIG_FB_ATY_CT
  398. case PCI_CHIP_MACH64VT:
  399. switch (rev & 0x07) {
  400. case 0x00:
  401. switch (rev & 0xc0) {
  402. case 0x00:
  403. name = "ATI264VT (A3) (Mach64 VT)";
  404. par->pll_limits.pll_max = 170;
  405. par->pll_limits.mclk = 67;
  406. par->pll_limits.xclk = 67;
  407. par->pll_limits.ecp_max = 80;
  408. par->features = ATI_CHIP_264VT;
  409. break;
  410. case 0x40:
  411. name = "ATI264VT2 (A4) (Mach64 VT)";
  412. par->pll_limits.pll_max = 200;
  413. par->pll_limits.mclk = 67;
  414. par->pll_limits.xclk = 67;
  415. par->pll_limits.ecp_max = 80;
  416. par->features = ATI_CHIP_264VT | M64F_MAGIC_POSTDIV;
  417. break;
  418. }
  419. break;
  420. case 0x01:
  421. name = "ATI264VT3 (B1) (Mach64 VT)";
  422. par->pll_limits.pll_max = 200;
  423. par->pll_limits.mclk = 67;
  424. par->pll_limits.xclk = 67;
  425. par->pll_limits.ecp_max = 80;
  426. par->features = ATI_CHIP_264VTB;
  427. break;
  428. case 0x02:
  429. name = "ATI264VT3 (B2) (Mach64 VT)";
  430. par->pll_limits.pll_max = 200;
  431. par->pll_limits.mclk = 67;
  432. par->pll_limits.xclk = 67;
  433. par->pll_limits.ecp_max = 80;
  434. par->features = ATI_CHIP_264VT3;
  435. break;
  436. }
  437. break;
  438. case PCI_CHIP_MACH64GT:
  439. switch (rev & 0x07) {
  440. case 0x01:
  441. name = "3D RAGE II (Mach64 GT)";
  442. par->pll_limits.pll_max = 170;
  443. par->pll_limits.mclk = 67;
  444. par->pll_limits.xclk = 67;
  445. par->pll_limits.ecp_max = 80;
  446. par->features = ATI_CHIP_264GTB;
  447. break;
  448. case 0x02:
  449. name = "3D RAGE II+ (Mach64 GT)";
  450. par->pll_limits.pll_max = 200;
  451. par->pll_limits.mclk = 67;
  452. par->pll_limits.xclk = 67;
  453. par->pll_limits.ecp_max = 100;
  454. par->features = ATI_CHIP_264GTB;
  455. break;
  456. }
  457. break;
  458. #endif
  459. }
  460. PRINTKI("%s [0x%04x rev 0x%02x]\n", name, type, rev);
  461. return 0;
  462. }
  463. static char ram_dram[] __devinitdata = "DRAM";
  464. static char ram_resv[] __devinitdata = "RESV";
  465. #ifdef CONFIG_FB_ATY_GX
  466. static char ram_vram[] __devinitdata = "VRAM";
  467. #endif /* CONFIG_FB_ATY_GX */
  468. #ifdef CONFIG_FB_ATY_CT
  469. static char ram_edo[] __devinitdata = "EDO";
  470. static char ram_sdram[] __devinitdata = "SDRAM (1:1)";
  471. static char ram_sgram[] __devinitdata = "SGRAM (1:1)";
  472. static char ram_sdram32[] __devinitdata = "SDRAM (2:1) (32-bit)";
  473. static char ram_wram[] __devinitdata = "WRAM";
  474. static char ram_off[] __devinitdata = "OFF";
  475. #endif /* CONFIG_FB_ATY_CT */
  476. #ifdef CONFIG_FB_ATY_GX
  477. static char *aty_gx_ram[8] __devinitdata = {
  478. ram_dram, ram_vram, ram_vram, ram_dram,
  479. ram_dram, ram_vram, ram_vram, ram_resv
  480. };
  481. #endif /* CONFIG_FB_ATY_GX */
  482. #ifdef CONFIG_FB_ATY_CT
  483. static char *aty_ct_ram[8] __devinitdata = {
  484. ram_off, ram_dram, ram_edo, ram_edo,
  485. ram_sdram, ram_sgram, ram_wram, ram_resv
  486. };
  487. static char *aty_xl_ram[8] __devinitdata = {
  488. ram_off, ram_dram, ram_edo, ram_edo,
  489. ram_sdram, ram_sgram, ram_sdram32, ram_resv
  490. };
  491. #endif /* CONFIG_FB_ATY_CT */
  492. static u32 atyfb_get_pixclock(struct fb_var_screeninfo *var,
  493. struct atyfb_par *par)
  494. {
  495. u32 pixclock = var->pixclock;
  496. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  497. u32 lcd_on_off;
  498. par->pll.ct.xres = 0;
  499. if (par->lcd_table != 0) {
  500. lcd_on_off = aty_ld_lcd(LCD_GEN_CNTL, par);
  501. if (lcd_on_off & LCD_ON) {
  502. par->pll.ct.xres = var->xres;
  503. pixclock = par->lcd_pixclock;
  504. }
  505. }
  506. #endif
  507. return pixclock;
  508. }
  509. #if defined(CONFIG_PPC)
  510. /*
  511. * Apple monitor sense
  512. */
  513. static int __devinit read_aty_sense(const struct atyfb_par *par)
  514. {
  515. int sense, i;
  516. aty_st_le32(GP_IO, 0x31003100, par); /* drive outputs high */
  517. __delay(200);
  518. aty_st_le32(GP_IO, 0, par); /* turn off outputs */
  519. __delay(2000);
  520. i = aty_ld_le32(GP_IO, par); /* get primary sense value */
  521. sense = ((i & 0x3000) >> 3) | (i & 0x100);
  522. /* drive each sense line low in turn and collect the other 2 */
  523. aty_st_le32(GP_IO, 0x20000000, par); /* drive A low */
  524. __delay(2000);
  525. i = aty_ld_le32(GP_IO, par);
  526. sense |= ((i & 0x1000) >> 7) | ((i & 0x100) >> 4);
  527. aty_st_le32(GP_IO, 0x20002000, par); /* drive A high again */
  528. __delay(200);
  529. aty_st_le32(GP_IO, 0x10000000, par); /* drive B low */
  530. __delay(2000);
  531. i = aty_ld_le32(GP_IO, par);
  532. sense |= ((i & 0x2000) >> 10) | ((i & 0x100) >> 6);
  533. aty_st_le32(GP_IO, 0x10001000, par); /* drive B high again */
  534. __delay(200);
  535. aty_st_le32(GP_IO, 0x01000000, par); /* drive C low */
  536. __delay(2000);
  537. sense |= (aty_ld_le32(GP_IO, par) & 0x3000) >> 12;
  538. aty_st_le32(GP_IO, 0, par); /* turn off outputs */
  539. return sense;
  540. }
  541. #endif /* defined(CONFIG_PPC) */
  542. /* ------------------------------------------------------------------------- */
  543. /*
  544. * CRTC programming
  545. */
  546. static void aty_get_crtc(const struct atyfb_par *par, struct crtc *crtc)
  547. {
  548. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  549. if (par->lcd_table != 0) {
  550. if (!M64_HAS(LT_LCD_REGS)) {
  551. crtc->lcd_index = aty_ld_le32(LCD_INDEX, par);
  552. aty_st_le32(LCD_INDEX, crtc->lcd_index, par);
  553. }
  554. crtc->lcd_config_panel = aty_ld_lcd(CNFG_PANEL, par);
  555. crtc->lcd_gen_cntl = aty_ld_lcd(LCD_GEN_CNTL, par);
  556. /* switch to non shadow registers */
  557. aty_st_lcd(LCD_GEN_CNTL, crtc->lcd_gen_cntl &
  558. ~(CRTC_RW_SELECT | SHADOW_EN | SHADOW_RW_EN), par);
  559. /* save stretching */
  560. crtc->horz_stretching = aty_ld_lcd(HORZ_STRETCHING, par);
  561. crtc->vert_stretching = aty_ld_lcd(VERT_STRETCHING, par);
  562. if (!M64_HAS(LT_LCD_REGS))
  563. crtc->ext_vert_stretch = aty_ld_lcd(EXT_VERT_STRETCH, par);
  564. }
  565. #endif
  566. crtc->h_tot_disp = aty_ld_le32(CRTC_H_TOTAL_DISP, par);
  567. crtc->h_sync_strt_wid = aty_ld_le32(CRTC_H_SYNC_STRT_WID, par);
  568. crtc->v_tot_disp = aty_ld_le32(CRTC_V_TOTAL_DISP, par);
  569. crtc->v_sync_strt_wid = aty_ld_le32(CRTC_V_SYNC_STRT_WID, par);
  570. crtc->vline_crnt_vline = aty_ld_le32(CRTC_VLINE_CRNT_VLINE, par);
  571. crtc->off_pitch = aty_ld_le32(CRTC_OFF_PITCH, par);
  572. crtc->gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par);
  573. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  574. if (par->lcd_table != 0) {
  575. /* switch to shadow registers */
  576. aty_st_lcd(LCD_GEN_CNTL, (crtc->lcd_gen_cntl & ~CRTC_RW_SELECT) |
  577. SHADOW_EN | SHADOW_RW_EN, par);
  578. crtc->shadow_h_tot_disp = aty_ld_le32(CRTC_H_TOTAL_DISP, par);
  579. crtc->shadow_h_sync_strt_wid = aty_ld_le32(CRTC_H_SYNC_STRT_WID, par);
  580. crtc->shadow_v_tot_disp = aty_ld_le32(CRTC_V_TOTAL_DISP, par);
  581. crtc->shadow_v_sync_strt_wid = aty_ld_le32(CRTC_V_SYNC_STRT_WID, par);
  582. aty_st_le32(LCD_GEN_CNTL, crtc->lcd_gen_cntl, par);
  583. }
  584. #endif /* CONFIG_FB_ATY_GENERIC_LCD */
  585. }
  586. static void aty_set_crtc(const struct atyfb_par *par, const struct crtc *crtc)
  587. {
  588. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  589. if (par->lcd_table != 0) {
  590. /* stop CRTC */
  591. aty_st_le32(CRTC_GEN_CNTL, crtc->gen_cntl &
  592. ~(CRTC_EXT_DISP_EN | CRTC_EN), par);
  593. /* update non-shadow registers first */
  594. aty_st_lcd(CNFG_PANEL, crtc->lcd_config_panel, par);
  595. aty_st_lcd(LCD_GEN_CNTL, crtc->lcd_gen_cntl &
  596. ~(CRTC_RW_SELECT | SHADOW_EN | SHADOW_RW_EN), par);
  597. /* temporarily disable stretching */
  598. aty_st_lcd(HORZ_STRETCHING, crtc->horz_stretching &
  599. ~(HORZ_STRETCH_MODE | HORZ_STRETCH_EN), par);
  600. aty_st_lcd(VERT_STRETCHING, crtc->vert_stretching &
  601. ~(VERT_STRETCH_RATIO1 | VERT_STRETCH_RATIO2 |
  602. VERT_STRETCH_USE0 | VERT_STRETCH_EN), par);
  603. }
  604. #endif
  605. /* turn off CRT */
  606. aty_st_le32(CRTC_GEN_CNTL, crtc->gen_cntl & ~CRTC_EN, par);
  607. DPRINTK("setting up CRTC\n");
  608. DPRINTK("set primary CRT to %ix%i %c%c composite %c\n",
  609. ((((crtc->h_tot_disp >> 16) & 0xff) + 1) << 3),
  610. (((crtc->v_tot_disp >> 16) & 0x7ff) + 1),
  611. (crtc->h_sync_strt_wid & 0x200000) ? 'N' : 'P',
  612. (crtc->v_sync_strt_wid & 0x200000) ? 'N' : 'P',
  613. (crtc->gen_cntl & CRTC_CSYNC_EN) ? 'P' : 'N');
  614. DPRINTK("CRTC_H_TOTAL_DISP: %x\n", crtc->h_tot_disp);
  615. DPRINTK("CRTC_H_SYNC_STRT_WID: %x\n", crtc->h_sync_strt_wid);
  616. DPRINTK("CRTC_V_TOTAL_DISP: %x\n", crtc->v_tot_disp);
  617. DPRINTK("CRTC_V_SYNC_STRT_WID: %x\n", crtc->v_sync_strt_wid);
  618. DPRINTK("CRTC_OFF_PITCH: %x\n", crtc->off_pitch);
  619. DPRINTK("CRTC_VLINE_CRNT_VLINE: %x\n", crtc->vline_crnt_vline);
  620. DPRINTK("CRTC_GEN_CNTL: %x\n", crtc->gen_cntl);
  621. aty_st_le32(CRTC_H_TOTAL_DISP, crtc->h_tot_disp, par);
  622. aty_st_le32(CRTC_H_SYNC_STRT_WID, crtc->h_sync_strt_wid, par);
  623. aty_st_le32(CRTC_V_TOTAL_DISP, crtc->v_tot_disp, par);
  624. aty_st_le32(CRTC_V_SYNC_STRT_WID, crtc->v_sync_strt_wid, par);
  625. aty_st_le32(CRTC_OFF_PITCH, crtc->off_pitch, par);
  626. aty_st_le32(CRTC_VLINE_CRNT_VLINE, crtc->vline_crnt_vline, par);
  627. aty_st_le32(CRTC_GEN_CNTL, crtc->gen_cntl, par);
  628. #if 0
  629. FIXME
  630. if (par->accel_flags & FB_ACCELF_TEXT)
  631. aty_init_engine(par, info);
  632. #endif
  633. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  634. /* after setting the CRTC registers we should set the LCD registers. */
  635. if (par->lcd_table != 0) {
  636. /* switch to shadow registers */
  637. aty_st_lcd(LCD_GEN_CNTL, (crtc->lcd_gen_cntl & ~CRTC_RW_SELECT) |
  638. SHADOW_EN | SHADOW_RW_EN, par);
  639. DPRINTK("set shadow CRT to %ix%i %c%c\n",
  640. ((((crtc->shadow_h_tot_disp >> 16) & 0xff) + 1) << 3),
  641. (((crtc->shadow_v_tot_disp >> 16) & 0x7ff) + 1),
  642. (crtc->shadow_h_sync_strt_wid & 0x200000) ? 'N' : 'P',
  643. (crtc->shadow_v_sync_strt_wid & 0x200000) ? 'N' : 'P');
  644. DPRINTK("SHADOW CRTC_H_TOTAL_DISP: %x\n",
  645. crtc->shadow_h_tot_disp);
  646. DPRINTK("SHADOW CRTC_H_SYNC_STRT_WID: %x\n",
  647. crtc->shadow_h_sync_strt_wid);
  648. DPRINTK("SHADOW CRTC_V_TOTAL_DISP: %x\n",
  649. crtc->shadow_v_tot_disp);
  650. DPRINTK("SHADOW CRTC_V_SYNC_STRT_WID: %x\n",
  651. crtc->shadow_v_sync_strt_wid);
  652. aty_st_le32(CRTC_H_TOTAL_DISP, crtc->shadow_h_tot_disp, par);
  653. aty_st_le32(CRTC_H_SYNC_STRT_WID, crtc->shadow_h_sync_strt_wid, par);
  654. aty_st_le32(CRTC_V_TOTAL_DISP, crtc->shadow_v_tot_disp, par);
  655. aty_st_le32(CRTC_V_SYNC_STRT_WID, crtc->shadow_v_sync_strt_wid, par);
  656. /* restore CRTC selection & shadow state and enable stretching */
  657. DPRINTK("LCD_GEN_CNTL: %x\n", crtc->lcd_gen_cntl);
  658. DPRINTK("HORZ_STRETCHING: %x\n", crtc->horz_stretching);
  659. DPRINTK("VERT_STRETCHING: %x\n", crtc->vert_stretching);
  660. if (!M64_HAS(LT_LCD_REGS))
  661. DPRINTK("EXT_VERT_STRETCH: %x\n", crtc->ext_vert_stretch);
  662. aty_st_lcd(LCD_GEN_CNTL, crtc->lcd_gen_cntl, par);
  663. aty_st_lcd(HORZ_STRETCHING, crtc->horz_stretching, par);
  664. aty_st_lcd(VERT_STRETCHING, crtc->vert_stretching, par);
  665. if (!M64_HAS(LT_LCD_REGS)) {
  666. aty_st_lcd(EXT_VERT_STRETCH, crtc->ext_vert_stretch, par);
  667. aty_ld_le32(LCD_INDEX, par);
  668. aty_st_le32(LCD_INDEX, crtc->lcd_index, par);
  669. }
  670. }
  671. #endif /* CONFIG_FB_ATY_GENERIC_LCD */
  672. }
  673. static u32 calc_line_length(struct atyfb_par *par, u32 vxres, u32 bpp)
  674. {
  675. u32 line_length = vxres * bpp / 8;
  676. if (par->ram_type == SGRAM ||
  677. (!M64_HAS(XL_MEM) && par->ram_type == WRAM))
  678. line_length = (line_length + 63) & ~63;
  679. return line_length;
  680. }
  681. static int aty_var_to_crtc(const struct fb_info *info,
  682. const struct fb_var_screeninfo *var,
  683. struct crtc *crtc)
  684. {
  685. struct atyfb_par *par = (struct atyfb_par *) info->par;
  686. u32 xres, yres, vxres, vyres, xoffset, yoffset, bpp;
  687. u32 sync, vmode, vdisplay;
  688. u32 h_total, h_disp, h_sync_strt, h_sync_end, h_sync_dly, h_sync_wid, h_sync_pol;
  689. u32 v_total, v_disp, v_sync_strt, v_sync_end, v_sync_wid, v_sync_pol, c_sync;
  690. u32 pix_width, dp_pix_width, dp_chain_mask;
  691. u32 line_length;
  692. /* input */
  693. xres = (var->xres + 7) & ~7;
  694. yres = var->yres;
  695. vxres = (var->xres_virtual + 7) & ~7;
  696. vyres = var->yres_virtual;
  697. xoffset = (var->xoffset + 7) & ~7;
  698. yoffset = var->yoffset;
  699. bpp = var->bits_per_pixel;
  700. if (bpp == 16)
  701. bpp = (var->green.length == 5) ? 15 : 16;
  702. sync = var->sync;
  703. vmode = var->vmode;
  704. /* convert (and round up) and validate */
  705. if (vxres < xres + xoffset)
  706. vxres = xres + xoffset;
  707. h_disp = xres;
  708. if (vyres < yres + yoffset)
  709. vyres = yres + yoffset;
  710. v_disp = yres;
  711. if (bpp <= 8) {
  712. bpp = 8;
  713. pix_width = CRTC_PIX_WIDTH_8BPP;
  714. dp_pix_width = HOST_8BPP | SRC_8BPP | DST_8BPP |
  715. BYTE_ORDER_LSB_TO_MSB;
  716. dp_chain_mask = DP_CHAIN_8BPP;
  717. } else if (bpp <= 15) {
  718. bpp = 16;
  719. pix_width = CRTC_PIX_WIDTH_15BPP;
  720. dp_pix_width = HOST_15BPP | SRC_15BPP | DST_15BPP |
  721. BYTE_ORDER_LSB_TO_MSB;
  722. dp_chain_mask = DP_CHAIN_15BPP;
  723. } else if (bpp <= 16) {
  724. bpp = 16;
  725. pix_width = CRTC_PIX_WIDTH_16BPP;
  726. dp_pix_width = HOST_16BPP | SRC_16BPP | DST_16BPP |
  727. BYTE_ORDER_LSB_TO_MSB;
  728. dp_chain_mask = DP_CHAIN_16BPP;
  729. } else if (bpp <= 24 && M64_HAS(INTEGRATED)) {
  730. bpp = 24;
  731. pix_width = CRTC_PIX_WIDTH_24BPP;
  732. dp_pix_width = HOST_8BPP | SRC_8BPP | DST_8BPP |
  733. BYTE_ORDER_LSB_TO_MSB;
  734. dp_chain_mask = DP_CHAIN_24BPP;
  735. } else if (bpp <= 32) {
  736. bpp = 32;
  737. pix_width = CRTC_PIX_WIDTH_32BPP;
  738. dp_pix_width = HOST_32BPP | SRC_32BPP | DST_32BPP |
  739. BYTE_ORDER_LSB_TO_MSB;
  740. dp_chain_mask = DP_CHAIN_32BPP;
  741. } else
  742. FAIL("invalid bpp");
  743. line_length = calc_line_length(par, vxres, bpp);
  744. if (vyres * line_length > info->fix.smem_len)
  745. FAIL("not enough video RAM");
  746. h_sync_pol = sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
  747. v_sync_pol = sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
  748. if ((xres > 1600) || (yres > 1200)) {
  749. FAIL("MACH64 chips are designed for max 1600x1200\n"
  750. "select anoter resolution.");
  751. }
  752. h_sync_strt = h_disp + var->right_margin;
  753. h_sync_end = h_sync_strt + var->hsync_len;
  754. h_sync_dly = var->right_margin & 7;
  755. h_total = h_sync_end + h_sync_dly + var->left_margin;
  756. v_sync_strt = v_disp + var->lower_margin;
  757. v_sync_end = v_sync_strt + var->vsync_len;
  758. v_total = v_sync_end + var->upper_margin;
  759. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  760. if (par->lcd_table != 0) {
  761. if (!M64_HAS(LT_LCD_REGS)) {
  762. u32 lcd_index = aty_ld_le32(LCD_INDEX, par);
  763. crtc->lcd_index = lcd_index &
  764. ~(LCD_INDEX_MASK | LCD_DISPLAY_DIS |
  765. LCD_SRC_SEL | CRTC2_DISPLAY_DIS);
  766. aty_st_le32(LCD_INDEX, lcd_index, par);
  767. }
  768. if (!M64_HAS(MOBIL_BUS))
  769. crtc->lcd_index |= CRTC2_DISPLAY_DIS;
  770. crtc->lcd_config_panel = aty_ld_lcd(CNFG_PANEL, par) | 0x4000;
  771. crtc->lcd_gen_cntl = aty_ld_lcd(LCD_GEN_CNTL, par) & ~CRTC_RW_SELECT;
  772. crtc->lcd_gen_cntl &=
  773. ~(HORZ_DIVBY2_EN | DIS_HOR_CRT_DIVBY2 | TVCLK_PM_EN |
  774. /*VCLK_DAC_PM_EN | USE_SHADOWED_VEND |*/
  775. USE_SHADOWED_ROWCUR | SHADOW_EN | SHADOW_RW_EN);
  776. crtc->lcd_gen_cntl |= DONT_SHADOW_VPAR | LOCK_8DOT;
  777. if ((crtc->lcd_gen_cntl & LCD_ON) &&
  778. ((xres > par->lcd_width) || (yres > par->lcd_height))) {
  779. /*
  780. * We cannot display the mode on the LCD. If the CRT is
  781. * enabled we can turn off the LCD.
  782. * If the CRT is off, it isn't a good idea to switch it
  783. * on; we don't know if one is connected. So it's better
  784. * to fail then.
  785. */
  786. if (crtc->lcd_gen_cntl & CRT_ON) {
  787. if (!(var->activate & FB_ACTIVATE_TEST))
  788. PRINTKI("Disable LCD panel, because video mode does not fit.\n");
  789. crtc->lcd_gen_cntl &= ~LCD_ON;
  790. /*aty_st_lcd(LCD_GEN_CNTL, crtc->lcd_gen_cntl, par);*/
  791. } else {
  792. if (!(var->activate & FB_ACTIVATE_TEST))
  793. PRINTKE("Video mode exceeds size of LCD panel.\nConnect this computer to a conventional monitor if you really need this mode.\n");
  794. return -EINVAL;
  795. }
  796. }
  797. }
  798. if ((par->lcd_table != 0) && (crtc->lcd_gen_cntl & LCD_ON)) {
  799. int VScan = 1;
  800. /* bpp -> bytespp, 1,4 -> 0; 8 -> 2; 15,16 -> 1; 24 -> 6; 32 -> 5
  801. const u8 DFP_h_sync_dly_LT[] = { 0, 2, 1, 6, 5 };
  802. const u8 ADD_to_strt_wid_and_dly_LT_DAC[] = { 0, 5, 6, 9, 9, 12, 12 }; */
  803. vmode &= ~(FB_VMODE_DOUBLE | FB_VMODE_INTERLACED);
  804. /*
  805. * This is horror! When we simulate, say 640x480 on an 800x600
  806. * LCD monitor, the CRTC should be programmed 800x600 values for
  807. * the non visible part, but 640x480 for the visible part.
  808. * This code has been tested on a laptop with it's 1400x1050 LCD
  809. * monitor and a conventional monitor both switched on.
  810. * Tested modes: 1280x1024, 1152x864, 1024x768, 800x600,
  811. * works with little glitches also with DOUBLESCAN modes
  812. */
  813. if (yres < par->lcd_height) {
  814. VScan = par->lcd_height / yres;
  815. if (VScan > 1) {
  816. VScan = 2;
  817. vmode |= FB_VMODE_DOUBLE;
  818. }
  819. }
  820. h_sync_strt = h_disp + par->lcd_right_margin;
  821. h_sync_end = h_sync_strt + par->lcd_hsync_len;
  822. h_sync_dly = /*DFP_h_sync_dly[ ( bpp + 1 ) / 3 ]; */par->lcd_hsync_dly;
  823. h_total = h_disp + par->lcd_hblank_len;
  824. v_sync_strt = v_disp + par->lcd_lower_margin / VScan;
  825. v_sync_end = v_sync_strt + par->lcd_vsync_len / VScan;
  826. v_total = v_disp + par->lcd_vblank_len / VScan;
  827. }
  828. #endif /* CONFIG_FB_ATY_GENERIC_LCD */
  829. h_disp = (h_disp >> 3) - 1;
  830. h_sync_strt = (h_sync_strt >> 3) - 1;
  831. h_sync_end = (h_sync_end >> 3) - 1;
  832. h_total = (h_total >> 3) - 1;
  833. h_sync_wid = h_sync_end - h_sync_strt;
  834. FAIL_MAX("h_disp too large", h_disp, 0xff);
  835. FAIL_MAX("h_sync_strt too large", h_sync_strt, 0x1ff);
  836. /*FAIL_MAX("h_sync_wid too large", h_sync_wid, 0x1f);*/
  837. if (h_sync_wid > 0x1f)
  838. h_sync_wid = 0x1f;
  839. FAIL_MAX("h_total too large", h_total, 0x1ff);
  840. if (vmode & FB_VMODE_DOUBLE) {
  841. v_disp <<= 1;
  842. v_sync_strt <<= 1;
  843. v_sync_end <<= 1;
  844. v_total <<= 1;
  845. }
  846. vdisplay = yres;
  847. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  848. if ((par->lcd_table != 0) && (crtc->lcd_gen_cntl & LCD_ON))
  849. vdisplay = par->lcd_height;
  850. #endif
  851. v_disp--;
  852. v_sync_strt--;
  853. v_sync_end--;
  854. v_total--;
  855. v_sync_wid = v_sync_end - v_sync_strt;
  856. FAIL_MAX("v_disp too large", v_disp, 0x7ff);
  857. FAIL_MAX("v_sync_stsrt too large", v_sync_strt, 0x7ff);
  858. /*FAIL_MAX("v_sync_wid too large", v_sync_wid, 0x1f);*/
  859. if (v_sync_wid > 0x1f)
  860. v_sync_wid = 0x1f;
  861. FAIL_MAX("v_total too large", v_total, 0x7ff);
  862. c_sync = sync & FB_SYNC_COMP_HIGH_ACT ? CRTC_CSYNC_EN : 0;
  863. /* output */
  864. crtc->vxres = vxres;
  865. crtc->vyres = vyres;
  866. crtc->xoffset = xoffset;
  867. crtc->yoffset = yoffset;
  868. crtc->bpp = bpp;
  869. crtc->off_pitch =
  870. ((yoffset * line_length + xoffset * bpp / 8) / 8) |
  871. ((line_length / bpp) << 22);
  872. crtc->vline_crnt_vline = 0;
  873. crtc->h_tot_disp = h_total | (h_disp << 16);
  874. crtc->h_sync_strt_wid = (h_sync_strt & 0xff) | (h_sync_dly << 8) |
  875. ((h_sync_strt & 0x100) << 4) | (h_sync_wid << 16) |
  876. (h_sync_pol << 21);
  877. crtc->v_tot_disp = v_total | (v_disp << 16);
  878. crtc->v_sync_strt_wid = v_sync_strt | (v_sync_wid << 16) |
  879. (v_sync_pol << 21);
  880. /* crtc->gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par) & CRTC_PRESERVED_MASK; */
  881. crtc->gen_cntl = CRTC_EXT_DISP_EN | CRTC_EN | pix_width | c_sync;
  882. crtc->gen_cntl |= CRTC_VGA_LINEAR;
  883. /* Enable doublescan mode if requested */
  884. if (vmode & FB_VMODE_DOUBLE)
  885. crtc->gen_cntl |= CRTC_DBL_SCAN_EN;
  886. /* Enable interlaced mode if requested */
  887. if (vmode & FB_VMODE_INTERLACED)
  888. crtc->gen_cntl |= CRTC_INTERLACE_EN;
  889. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  890. if (par->lcd_table != 0) {
  891. vdisplay = yres;
  892. if (vmode & FB_VMODE_DOUBLE)
  893. vdisplay <<= 1;
  894. crtc->gen_cntl &= ~(CRTC2_EN | CRTC2_PIX_WIDTH);
  895. crtc->lcd_gen_cntl &= ~(HORZ_DIVBY2_EN | DIS_HOR_CRT_DIVBY2 |
  896. /*TVCLK_PM_EN | VCLK_DAC_PM_EN |*/
  897. USE_SHADOWED_VEND |
  898. USE_SHADOWED_ROWCUR |
  899. SHADOW_EN | SHADOW_RW_EN);
  900. crtc->lcd_gen_cntl |= DONT_SHADOW_VPAR/* | LOCK_8DOT*/;
  901. /* MOBILITY M1 tested, FIXME: LT */
  902. crtc->horz_stretching = aty_ld_lcd(HORZ_STRETCHING, par);
  903. if (!M64_HAS(LT_LCD_REGS))
  904. crtc->ext_vert_stretch = aty_ld_lcd(EXT_VERT_STRETCH, par) &
  905. ~(AUTO_VERT_RATIO | VERT_STRETCH_MODE | VERT_STRETCH_RATIO3);
  906. crtc->horz_stretching &= ~(HORZ_STRETCH_RATIO |
  907. HORZ_STRETCH_LOOP | AUTO_HORZ_RATIO |
  908. HORZ_STRETCH_MODE | HORZ_STRETCH_EN);
  909. if (xres < par->lcd_width && crtc->lcd_gen_cntl & LCD_ON) {
  910. do {
  911. /*
  912. * The horizontal blender misbehaves when
  913. * HDisplay is less than a certain threshold
  914. * (440 for a 1024-wide panel). It doesn't
  915. * stretch such modes enough. Use pixel
  916. * replication instead of blending to stretch
  917. * modes that can be made to exactly fit the
  918. * panel width. The undocumented "NoLCDBlend"
  919. * option allows the pixel-replicated mode to
  920. * be slightly wider or narrower than the
  921. * panel width. It also causes a mode that is
  922. * exactly half as wide as the panel to be
  923. * pixel-replicated, rather than blended.
  924. */
  925. int HDisplay = xres & ~7;
  926. int nStretch = par->lcd_width / HDisplay;
  927. int Remainder = par->lcd_width % HDisplay;
  928. if ((!Remainder && ((nStretch > 2))) ||
  929. (((HDisplay * 16) / par->lcd_width) < 7)) {
  930. static const char StretchLoops[] = { 10, 12, 13, 15, 16 };
  931. int horz_stretch_loop = -1, BestRemainder;
  932. int Numerator = HDisplay, Denominator = par->lcd_width;
  933. int Index = 5;
  934. ATIReduceRatio(&Numerator, &Denominator);
  935. BestRemainder = (Numerator * 16) / Denominator;
  936. while (--Index >= 0) {
  937. Remainder = ((Denominator - Numerator) * StretchLoops[Index]) %
  938. Denominator;
  939. if (Remainder < BestRemainder) {
  940. horz_stretch_loop = Index;
  941. if (!(BestRemainder = Remainder))
  942. break;
  943. }
  944. }
  945. if ((horz_stretch_loop >= 0) && !BestRemainder) {
  946. int horz_stretch_ratio = 0, Accumulator = 0;
  947. int reuse_previous = 1;
  948. Index = StretchLoops[horz_stretch_loop];
  949. while (--Index >= 0) {
  950. if (Accumulator > 0)
  951. horz_stretch_ratio |= reuse_previous;
  952. else
  953. Accumulator += Denominator;
  954. Accumulator -= Numerator;
  955. reuse_previous <<= 1;
  956. }
  957. crtc->horz_stretching |= (HORZ_STRETCH_EN |
  958. ((horz_stretch_loop & HORZ_STRETCH_LOOP) << 16) |
  959. (horz_stretch_ratio & HORZ_STRETCH_RATIO));
  960. break; /* Out of the do { ... } while (0) */
  961. }
  962. }
  963. crtc->horz_stretching |= (HORZ_STRETCH_MODE | HORZ_STRETCH_EN |
  964. (((HDisplay * (HORZ_STRETCH_BLEND + 1)) / par->lcd_width) & HORZ_STRETCH_BLEND));
  965. } while (0);
  966. }
  967. if (vdisplay < par->lcd_height && crtc->lcd_gen_cntl & LCD_ON) {
  968. crtc->vert_stretching = (VERT_STRETCH_USE0 | VERT_STRETCH_EN |
  969. (((vdisplay * (VERT_STRETCH_RATIO0 + 1)) / par->lcd_height) & VERT_STRETCH_RATIO0));
  970. if (!M64_HAS(LT_LCD_REGS) &&
  971. xres <= (M64_HAS(MOBIL_BUS) ? 1024 : 800))
  972. crtc->ext_vert_stretch |= VERT_STRETCH_MODE;
  973. } else {
  974. /*
  975. * Don't use vertical blending if the mode is too wide
  976. * or not vertically stretched.
  977. */
  978. crtc->vert_stretching = 0;
  979. }
  980. /* copy to shadow crtc */
  981. crtc->shadow_h_tot_disp = crtc->h_tot_disp;
  982. crtc->shadow_h_sync_strt_wid = crtc->h_sync_strt_wid;
  983. crtc->shadow_v_tot_disp = crtc->v_tot_disp;
  984. crtc->shadow_v_sync_strt_wid = crtc->v_sync_strt_wid;
  985. }
  986. #endif /* CONFIG_FB_ATY_GENERIC_LCD */
  987. if (M64_HAS(MAGIC_FIFO)) {
  988. /* FIXME: display FIFO low watermark values */
  989. crtc->gen_cntl |= (aty_ld_le32(CRTC_GEN_CNTL, par) & CRTC_FIFO_LWM);
  990. }
  991. crtc->dp_pix_width = dp_pix_width;
  992. crtc->dp_chain_mask = dp_chain_mask;
  993. return 0;
  994. }
  995. static int aty_crtc_to_var(const struct crtc *crtc,
  996. struct fb_var_screeninfo *var)
  997. {
  998. u32 xres, yres, bpp, left, right, upper, lower, hslen, vslen, sync;
  999. u32 h_total, h_disp, h_sync_strt, h_sync_dly, h_sync_wid, h_sync_pol;
  1000. u32 v_total, v_disp, v_sync_strt, v_sync_wid, v_sync_pol, c_sync;
  1001. u32 pix_width;
  1002. u32 double_scan, interlace;
  1003. /* input */
  1004. h_total = crtc->h_tot_disp & 0x1ff;
  1005. h_disp = (crtc->h_tot_disp >> 16) & 0xff;
  1006. h_sync_strt = (crtc->h_sync_strt_wid & 0xff) | ((crtc->h_sync_strt_wid >> 4) & 0x100);
  1007. h_sync_dly = (crtc->h_sync_strt_wid >> 8) & 0x7;
  1008. h_sync_wid = (crtc->h_sync_strt_wid >> 16) & 0x1f;
  1009. h_sync_pol = (crtc->h_sync_strt_wid >> 21) & 0x1;
  1010. v_total = crtc->v_tot_disp & 0x7ff;
  1011. v_disp = (crtc->v_tot_disp >> 16) & 0x7ff;
  1012. v_sync_strt = crtc->v_sync_strt_wid & 0x7ff;
  1013. v_sync_wid = (crtc->v_sync_strt_wid >> 16) & 0x1f;
  1014. v_sync_pol = (crtc->v_sync_strt_wid >> 21) & 0x1;
  1015. c_sync = crtc->gen_cntl & CRTC_CSYNC_EN ? 1 : 0;
  1016. pix_width = crtc->gen_cntl & CRTC_PIX_WIDTH_MASK;
  1017. double_scan = crtc->gen_cntl & CRTC_DBL_SCAN_EN;
  1018. interlace = crtc->gen_cntl & CRTC_INTERLACE_EN;
  1019. /* convert */
  1020. xres = (h_disp + 1) * 8;
  1021. yres = v_disp + 1;
  1022. left = (h_total - h_sync_strt - h_sync_wid) * 8 - h_sync_dly;
  1023. right = (h_sync_strt - h_disp) * 8 + h_sync_dly;
  1024. hslen = h_sync_wid * 8;
  1025. upper = v_total - v_sync_strt - v_sync_wid;
  1026. lower = v_sync_strt - v_disp;
  1027. vslen = v_sync_wid;
  1028. sync = (h_sync_pol ? 0 : FB_SYNC_HOR_HIGH_ACT) |
  1029. (v_sync_pol ? 0 : FB_SYNC_VERT_HIGH_ACT) |
  1030. (c_sync ? FB_SYNC_COMP_HIGH_ACT : 0);
  1031. switch (pix_width) {
  1032. #if 0
  1033. case CRTC_PIX_WIDTH_4BPP:
  1034. bpp = 4;
  1035. var->red.offset = 0;
  1036. var->red.length = 8;
  1037. var->green.offset = 0;
  1038. var->green.length = 8;
  1039. var->blue.offset = 0;
  1040. var->blue.length = 8;
  1041. var->transp.offset = 0;
  1042. var->transp.length = 0;
  1043. break;
  1044. #endif
  1045. case CRTC_PIX_WIDTH_8BPP:
  1046. bpp = 8;
  1047. var->red.offset = 0;
  1048. var->red.length = 8;
  1049. var->green.offset = 0;
  1050. var->green.length = 8;
  1051. var->blue.offset = 0;
  1052. var->blue.length = 8;
  1053. var->transp.offset = 0;
  1054. var->transp.length = 0;
  1055. break;
  1056. case CRTC_PIX_WIDTH_15BPP: /* RGB 555 */
  1057. bpp = 16;
  1058. var->red.offset = 10;
  1059. var->red.length = 5;
  1060. var->green.offset = 5;
  1061. var->green.length = 5;
  1062. var->blue.offset = 0;
  1063. var->blue.length = 5;
  1064. var->transp.offset = 0;
  1065. var->transp.length = 0;
  1066. break;
  1067. case CRTC_PIX_WIDTH_16BPP: /* RGB 565 */
  1068. bpp = 16;
  1069. var->red.offset = 11;
  1070. var->red.length = 5;
  1071. var->green.offset = 5;
  1072. var->green.length = 6;
  1073. var->blue.offset = 0;
  1074. var->blue.length = 5;
  1075. var->transp.offset = 0;
  1076. var->transp.length = 0;
  1077. break;
  1078. case CRTC_PIX_WIDTH_24BPP: /* RGB 888 */
  1079. bpp = 24;
  1080. var->red.offset = 16;
  1081. var->red.length = 8;
  1082. var->green.offset = 8;
  1083. var->green.length = 8;
  1084. var->blue.offset = 0;
  1085. var->blue.length = 8;
  1086. var->transp.offset = 0;
  1087. var->transp.length = 0;
  1088. break;
  1089. case CRTC_PIX_WIDTH_32BPP: /* ARGB 8888 */
  1090. bpp = 32;
  1091. var->red.offset = 16;
  1092. var->red.length = 8;
  1093. var->green.offset = 8;
  1094. var->green.length = 8;
  1095. var->blue.offset = 0;
  1096. var->blue.length = 8;
  1097. var->transp.offset = 24;
  1098. var->transp.length = 8;
  1099. break;
  1100. default:
  1101. PRINTKE("Invalid pixel width\n");
  1102. return -EINVAL;
  1103. }
  1104. /* output */
  1105. var->xres = xres;
  1106. var->yres = yres;
  1107. var->xres_virtual = crtc->vxres;
  1108. var->yres_virtual = crtc->vyres;
  1109. var->bits_per_pixel = bpp;
  1110. var->left_margin = left;
  1111. var->right_margin = right;
  1112. var->upper_margin = upper;
  1113. var->lower_margin = lower;
  1114. var->hsync_len = hslen;
  1115. var->vsync_len = vslen;
  1116. var->sync = sync;
  1117. var->vmode = FB_VMODE_NONINTERLACED;
  1118. /*
  1119. * In double scan mode, the vertical parameters are doubled,
  1120. * so we need to halve them to get the right values.
  1121. * In interlaced mode the values are already correct,
  1122. * so no correction is necessary.
  1123. */
  1124. if (interlace)
  1125. var->vmode = FB_VMODE_INTERLACED;
  1126. if (double_scan) {
  1127. var->vmode = FB_VMODE_DOUBLE;
  1128. var->yres >>= 1;
  1129. var->upper_margin >>= 1;
  1130. var->lower_margin >>= 1;
  1131. var->vsync_len >>= 1;
  1132. }
  1133. return 0;
  1134. }
  1135. /* ------------------------------------------------------------------------- */
  1136. static int atyfb_set_par(struct fb_info *info)
  1137. {
  1138. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1139. struct fb_var_screeninfo *var = &info->var;
  1140. u32 tmp, pixclock;
  1141. int err;
  1142. #ifdef DEBUG
  1143. struct fb_var_screeninfo debug;
  1144. u32 pixclock_in_ps;
  1145. #endif
  1146. if (par->asleep)
  1147. return 0;
  1148. err = aty_var_to_crtc(info, var, &par->crtc);
  1149. if (err)
  1150. return err;
  1151. pixclock = atyfb_get_pixclock(var, par);
  1152. if (pixclock == 0) {
  1153. PRINTKE("Invalid pixclock\n");
  1154. return -EINVAL;
  1155. } else {
  1156. err = par->pll_ops->var_to_pll(info, pixclock,
  1157. var->bits_per_pixel, &par->pll);
  1158. if (err)
  1159. return err;
  1160. }
  1161. par->accel_flags = var->accel_flags; /* hack */
  1162. if (var->accel_flags) {
  1163. info->fbops->fb_sync = atyfb_sync;
  1164. info->flags &= ~FBINFO_HWACCEL_DISABLED;
  1165. } else {
  1166. info->fbops->fb_sync = NULL;
  1167. info->flags |= FBINFO_HWACCEL_DISABLED;
  1168. }
  1169. if (par->blitter_may_be_busy)
  1170. wait_for_idle(par);
  1171. aty_set_crtc(par, &par->crtc);
  1172. par->dac_ops->set_dac(info, &par->pll,
  1173. var->bits_per_pixel, par->accel_flags);
  1174. par->pll_ops->set_pll(info, &par->pll);
  1175. #ifdef DEBUG
  1176. if (par->pll_ops && par->pll_ops->pll_to_var)
  1177. pixclock_in_ps = par->pll_ops->pll_to_var(info, &par->pll);
  1178. else
  1179. pixclock_in_ps = 0;
  1180. if (0 == pixclock_in_ps) {
  1181. PRINTKE("ALERT ops->pll_to_var get 0\n");
  1182. pixclock_in_ps = pixclock;
  1183. }
  1184. memset(&debug, 0, sizeof(debug));
  1185. if (!aty_crtc_to_var(&par->crtc, &debug)) {
  1186. u32 hSync, vRefresh;
  1187. u32 h_disp, h_sync_strt, h_sync_end, h_total;
  1188. u32 v_disp, v_sync_strt, v_sync_end, v_total;
  1189. h_disp = debug.xres;
  1190. h_sync_strt = h_disp + debug.right_margin;
  1191. h_sync_end = h_sync_strt + debug.hsync_len;
  1192. h_total = h_sync_end + debug.left_margin;
  1193. v_disp = debug.yres;
  1194. v_sync_strt = v_disp + debug.lower_margin;
  1195. v_sync_end = v_sync_strt + debug.vsync_len;
  1196. v_total = v_sync_end + debug.upper_margin;
  1197. hSync = 1000000000 / (pixclock_in_ps * h_total);
  1198. vRefresh = (hSync * 1000) / v_total;
  1199. if (par->crtc.gen_cntl & CRTC_INTERLACE_EN)
  1200. vRefresh *= 2;
  1201. if (par->crtc.gen_cntl & CRTC_DBL_SCAN_EN)
  1202. vRefresh /= 2;
  1203. DPRINTK("atyfb_set_par\n");
  1204. DPRINTK(" Set Visible Mode to %ix%i-%i\n",
  1205. var->xres, var->yres, var->bits_per_pixel);
  1206. DPRINTK(" Virtual resolution %ix%i, "
  1207. "pixclock_in_ps %i (calculated %i)\n",
  1208. var->xres_virtual, var->yres_virtual,
  1209. pixclock, pixclock_in_ps);
  1210. DPRINTK(" Dot clock: %i MHz\n",
  1211. 1000000 / pixclock_in_ps);
  1212. DPRINTK(" Horizontal sync: %i kHz\n", hSync);
  1213. DPRINTK(" Vertical refresh: %i Hz\n", vRefresh);
  1214. DPRINTK(" x style: %i.%03i %i %i %i %i %i %i %i %i\n",
  1215. 1000000 / pixclock_in_ps, 1000000 % pixclock_in_ps,
  1216. h_disp, h_sync_strt, h_sync_end, h_total,
  1217. v_disp, v_sync_strt, v_sync_end, v_total);
  1218. DPRINTK(" fb style: %i %i %i %i %i %i %i %i %i\n",
  1219. pixclock_in_ps,
  1220. debug.left_margin, h_disp, debug.right_margin, debug.hsync_len,
  1221. debug.upper_margin, v_disp, debug.lower_margin, debug.vsync_len);
  1222. }
  1223. #endif /* DEBUG */
  1224. if (!M64_HAS(INTEGRATED)) {
  1225. /* Don't forget MEM_CNTL */
  1226. tmp = aty_ld_le32(MEM_CNTL, par) & 0xf0ffffff;
  1227. switch (var->bits_per_pixel) {
  1228. case 8:
  1229. tmp |= 0x02000000;
  1230. break;
  1231. case 16:
  1232. tmp |= 0x03000000;
  1233. break;
  1234. case 32:
  1235. tmp |= 0x06000000;
  1236. break;
  1237. }
  1238. aty_st_le32(MEM_CNTL, tmp, par);
  1239. } else {
  1240. tmp = aty_ld_le32(MEM_CNTL, par) & 0xf00fffff;
  1241. if (!M64_HAS(MAGIC_POSTDIV))
  1242. tmp |= par->mem_refresh_rate << 20;
  1243. switch (var->bits_per_pixel) {
  1244. case 8:
  1245. case 24:
  1246. tmp |= 0x00000000;
  1247. break;
  1248. case 16:
  1249. tmp |= 0x04000000;
  1250. break;
  1251. case 32:
  1252. tmp |= 0x08000000;
  1253. break;
  1254. }
  1255. if (M64_HAS(CT_BUS)) {
  1256. aty_st_le32(DAC_CNTL, 0x87010184, par);
  1257. aty_st_le32(BUS_CNTL, 0x680000f9, par);
  1258. } else if (M64_HAS(VT_BUS)) {
  1259. aty_st_le32(DAC_CNTL, 0x87010184, par);
  1260. aty_st_le32(BUS_CNTL, 0x680000f9, par);
  1261. } else if (M64_HAS(MOBIL_BUS)) {
  1262. aty_st_le32(DAC_CNTL, 0x80010102, par);
  1263. aty_st_le32(BUS_CNTL, 0x7b33a040 | (par->aux_start ? BUS_APER_REG_DIS : 0), par);
  1264. } else {
  1265. /* GT */
  1266. aty_st_le32(DAC_CNTL, 0x86010102, par);
  1267. aty_st_le32(BUS_CNTL, 0x7b23a040 | (par->aux_start ? BUS_APER_REG_DIS : 0), par);
  1268. aty_st_le32(EXT_MEM_CNTL, aty_ld_le32(EXT_MEM_CNTL, par) | 0x5000001, par);
  1269. }
  1270. aty_st_le32(MEM_CNTL, tmp, par);
  1271. }
  1272. aty_st_8(DAC_MASK, 0xff, par);
  1273. info->fix.line_length = calc_line_length(par, var->xres_virtual,
  1274. var->bits_per_pixel);
  1275. info->fix.visual = var->bits_per_pixel <= 8 ?
  1276. FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
  1277. /* Initialize the graphics engine */
  1278. if (par->accel_flags & FB_ACCELF_TEXT)
  1279. aty_init_engine(par, info);
  1280. #ifdef CONFIG_BOOTX_TEXT
  1281. btext_update_display(info->fix.smem_start,
  1282. (((par->crtc.h_tot_disp >> 16) & 0xff) + 1) * 8,
  1283. ((par->crtc.v_tot_disp >> 16) & 0x7ff) + 1,
  1284. var->bits_per_pixel,
  1285. par->crtc.vxres * var->bits_per_pixel / 8);
  1286. #endif /* CONFIG_BOOTX_TEXT */
  1287. #if 0
  1288. /* switch to accelerator mode */
  1289. if (!(par->crtc.gen_cntl & CRTC_EXT_DISP_EN))
  1290. aty_st_le32(CRTC_GEN_CNTL, par->crtc.gen_cntl | CRTC_EXT_DISP_EN, par);
  1291. #endif
  1292. #ifdef DEBUG
  1293. {
  1294. /* dump non shadow CRTC, pll, LCD registers */
  1295. int i; u32 base;
  1296. /* CRTC registers */
  1297. base = 0x2000;
  1298. printk("debug atyfb: Mach64 non-shadow register values:");
  1299. for (i = 0; i < 256; i = i+4) {
  1300. if (i % 16 == 0)
  1301. printk("\ndebug atyfb: 0x%04X: ", base + i);
  1302. printk(" %08X", aty_ld_le32(i, par));
  1303. }
  1304. printk("\n\n");
  1305. #ifdef CONFIG_FB_ATY_CT
  1306. /* PLL registers */
  1307. base = 0x00;
  1308. printk("debug atyfb: Mach64 PLL register values:");
  1309. for (i = 0; i < 64; i++) {
  1310. if (i % 16 == 0)
  1311. printk("\ndebug atyfb: 0x%02X: ", base + i);
  1312. if (i % 4 == 0)
  1313. printk(" ");
  1314. printk("%02X", aty_ld_pll_ct(i, par));
  1315. }
  1316. printk("\n\n");
  1317. #endif /* CONFIG_FB_ATY_CT */
  1318. #ifdef CONFIG_FB_ATY_GENERIC_LCD
  1319. if (par->lcd_table != 0) {
  1320. /* LCD registers */
  1321. base = 0x00;
  1322. printk("debug atyfb: LCD register values:");
  1323. if (M64_HAS(LT_LCD_REGS)) {
  1324. for (i = 0; i <= POWER_MANAGEMENT; i++) {
  1325. if (i == EXT_VERT_STRETCH)
  1326. continue;
  1327. printk("\ndebug atyfb: 0x%04X: ",
  1328. lt_lcd_regs[i]);
  1329. printk(" %08X", aty_ld_lcd(i, par));
  1330. }
  1331. } else {
  1332. for (i = 0; i < 64; i++) {
  1333. if (i % 4 == 0)
  1334. printk("\ndebug atyfb: 0x%02X: ",
  1335. base + i);
  1336. printk(" %08X", aty_ld_lcd(i, par));
  1337. }
  1338. }
  1339. printk("\n\n");
  1340. }
  1341. #endif /* CONFIG_FB_ATY_GENERIC_LCD */
  1342. }
  1343. #endif /* DEBUG */
  1344. return 0;
  1345. }
  1346. static int atyfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  1347. {
  1348. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1349. int err;
  1350. struct crtc crtc;
  1351. union aty_pll pll;
  1352. u32 pixclock;
  1353. memcpy(&pll, &par->pll, sizeof(pll));
  1354. err = aty_var_to_crtc(info, var, &crtc);
  1355. if (err)
  1356. return err;
  1357. pixclock = atyfb_get_pixclock(var, par);
  1358. if (pixclock == 0) {
  1359. if (!(var->activate & FB_ACTIVATE_TEST))
  1360. PRINTKE("Invalid pixclock\n");
  1361. return -EINVAL;
  1362. } else {
  1363. err = par->pll_ops->var_to_pll(info, pixclock,
  1364. var->bits_per_pixel, &pll);
  1365. if (err)
  1366. return err;
  1367. }
  1368. if (var->accel_flags & FB_ACCELF_TEXT)
  1369. info->var.accel_flags = FB_ACCELF_TEXT;
  1370. else
  1371. info->var.accel_flags = 0;
  1372. aty_crtc_to_var(&crtc, var);
  1373. var->pixclock = par->pll_ops->pll_to_var(info, &pll);
  1374. return 0;
  1375. }
  1376. static void set_off_pitch(struct atyfb_par *par, const struct fb_info *info)
  1377. {
  1378. u32 xoffset = info->var.xoffset;
  1379. u32 yoffset = info->var.yoffset;
  1380. u32 line_length = info->fix.line_length;
  1381. u32 bpp = info->var.bits_per_pixel;
  1382. par->crtc.off_pitch =
  1383. ((yoffset * line_length + xoffset * bpp / 8) / 8) |
  1384. ((line_length / bpp) << 22);
  1385. }
  1386. /*
  1387. * Open/Release the frame buffer device
  1388. */
  1389. static int atyfb_open(struct fb_info *info, int user)
  1390. {
  1391. struct atyfb_par *par = (struct atyfb_par *) info->par;
  1392. if (user) {
  1393. par->open++;
  1394. #ifdef __sparc__
  1395. par->mmaped = 0;
  1396. #endif
  1397. }
  1398. return 0;
  1399. }
  1400. static irqreturn_t aty_irq(int irq, void *dev_id)
  1401. {
  1402. struct atyfb_par *par = dev_id;
  1403. int handled = 0;
  1404. u32 int_cntl;
  1405. spin_lock(&par->int_lock);
  1406. int_cntl = aty_ld_le32(CRTC_INT_CNTL, par);
  1407. if (int_cntl & CRTC_VBLANK_INT) {
  1408. /* clear interrupt */
  1409. aty_st_le32(CRTC_INT_CNTL, (int_cntl & CRTC_INT_EN_MASK) |
  1410. CRTC_VBLANK_INT_AK, par);
  1411. par->vblank.count++;
  1412. if (par->vblank.pan_display) {
  1413. par->vblank.pan_display = 0;
  1414. aty_st_le32(CRTC_OFF_PITCH, par->crtc.off_pitch, par);
  1415. }
  1416. wake_up_interruptible(&par->vblank.wait);
  1417. handled = 1;
  1418. }
  1419. spin_unlock(&par->int_lock);
  1420. return IRQ_RETVAL(handled);
  1421. }
  1422. static int aty_enable_irq(struct atyfb_par *par, int reenable)
  1423. {
  1424. u32 int_cntl;
  1425. if (!test_and_set_bit(0, &par->irq_flags)) {
  1426. if (request_irq(par->irq, aty_irq, IRQF_SHARED, "atyfb", par)) {
  1427. clear_bit(0, &par->irq_flags);
  1428. return -EINVAL;