savagefb.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /*
  2. * linux/drivers/video/savagefb.h -- S3 Savage Framebuffer Driver
  3. *
  4. * Copyright (c) 2001 Denis Oliver Kropp <dok@convergence.de>
  5. *
  6. * This file is subject to the terms and conditions of the GNU General
  7. * Public License. See the file COPYING in the main directory of this
  8. * archive for more details.
  9. */
  10. #ifndef __SAVAGEFB_H__
  11. #define __SAVAGEFB_H__
  12. #include <linux/i2c.h>
  13. #include <linux/i2c-id.h>
  14. #include <linux/i2c-algo-bit.h>
  15. #include "../edid.h"
  16. #ifdef SAVAGEFB_DEBUG
  17. # define DBG(x) printk (KERN_DEBUG "savagefb: %s\n", (x));
  18. #else
  19. # define DBG(x)
  20. # define SavagePrintRegs(...)
  21. #endif
  22. #define PCI_CHIP_SAVAGE4 0x8a22
  23. #define PCI_CHIP_SAVAGE3D 0x8a20
  24. #define PCI_CHIP_SAVAGE3D_MV 0x8a21
  25. #define PCI_CHIP_SAVAGE2000 0x9102
  26. #define PCI_CHIP_SAVAGE_MX_MV 0x8c10
  27. #define PCI_CHIP_SAVAGE_MX 0x8c11
  28. #define PCI_CHIP_SAVAGE_IX_MV 0x8c12
  29. #define PCI_CHIP_SAVAGE_IX 0x8c13
  30. #define PCI_CHIP_PROSAVAGE_PM 0x8a25
  31. #define PCI_CHIP_PROSAVAGE_KM 0x8a26
  32. /* Twister is a code name; hope I get the real name soon. */
  33. #define PCI_CHIP_S3TWISTER_P 0x8d01
  34. #define PCI_CHIP_S3TWISTER_K 0x8d02
  35. #define PCI_CHIP_PROSAVAGE_DDR 0x8d03
  36. #define PCI_CHIP_PROSAVAGE_DDRK 0x8d04
  37. #define PCI_CHIP_SUPSAV_MX128 0x8c22
  38. #define PCI_CHIP_SUPSAV_MX64 0x8c24
  39. #define PCI_CHIP_SUPSAV_MX64C 0x8c26
  40. #define PCI_CHIP_SUPSAV_IX128SDR 0x8c2a
  41. #define PCI_CHIP_SUPSAV_IX128DDR 0x8c2b
  42. #define PCI_CHIP_SUPSAV_IX64SDR 0x8c2c
  43. #define PCI_CHIP_SUPSAV_IX64DDR 0x8c2d
  44. #define PCI_CHIP_SUPSAV_IXCSDR 0x8c2e
  45. #define PCI_CHIP_SUPSAV_IXCDDR 0x8c2f
  46. #define S3_SAVAGE3D_SERIES(chip) ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE_MX))
  47. #define S3_SAVAGE4_SERIES(chip) ((chip==S3_SAVAGE4) || (chip==S3_PROSAVAGE))
  48. #define S3_SAVAGE_MOBILE_SERIES(chip) ((chip==S3_SAVAGE_MX) || (chip==S3_SUPERSAVAGE))
  49. #define S3_SAVAGE_SERIES(chip) ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE2000))
  50. /* Chip tags. These are used to group the adapters into
  51. * related families.
  52. */
  53. typedef enum {
  54. S3_UNKNOWN = 0,
  55. S3_SAVAGE3D,
  56. S3_SAVAGE_MX,
  57. S3_SAVAGE4,
  58. S3_PROSAVAGE,
  59. S3_SUPERSAVAGE,
  60. S3_SAVAGE2000,
  61. S3_LAST
  62. } savage_chipset;
  63. #define BIOS_BSIZE 1024
  64. #define BIOS_BASE 0xc0000
  65. #define SAVAGE_NEWMMIO_REGBASE_S3 0x1000000 /* 16MB */
  66. #define SAVAGE_NEWMMIO_REGBASE_S4 0x0000000
  67. #define SAVAGE_NEWMMIO_REGSIZE 0x0080000 /* 512kb */
  68. #define SAVAGE_NEWMMIO_VGABASE 0x8000
  69. #define BASE_FREQ 14318
  70. #define HALF_BASE_FREQ 7159
  71. #define FIFO_CONTROL_REG 0x8200
  72. #define MIU_CONTROL_REG 0x8204
  73. #define STREAMS_TIMEOUT_REG 0x8208
  74. #define MISC_TIMEOUT_REG 0x820c
  75. #define MONO_PAT_0 0xa4e8
  76. #define MONO_PAT_1 0xa4ec
  77. #define MAXFIFO 0x7f00
  78. #define BCI_CMD_NOP 0x40000000
  79. #define BCI_CMD_SETREG 0x96000000
  80. #define BCI_CMD_RECT 0x48000000
  81. #define BCI_CMD_RECT_XP 0x01000000
  82. #define BCI_CMD_RECT_YP 0x02000000
  83. #define BCI_CMD_SEND_COLOR 0x00008000
  84. #define BCI_CMD_DEST_GBD 0x00000000
  85. #define BCI_CMD_SRC_GBD 0x00000020
  86. #define BCI_CMD_SRC_SOLID 0x00000000
  87. #define BCI_CMD_SRC_MONO 0x00000060
  88. #define BCI_CMD_CLIP_NEW 0x00006000
  89. #define BCI_CMD_CLIP_LR 0x00004000
  90. #define BCI_CLIP_LR(l, r) ((((r) << 16) | (l)) & 0x0FFF0FFF)
  91. #define BCI_CLIP_TL(t, l) ((((t) << 16) | (l)) & 0x0FFF0FFF)
  92. #define BCI_CLIP_BR(b, r) ((((b) << 16) | (r)) & 0x0FFF0FFF)
  93. #define BCI_W_H(w, h) (((h) << 16) | ((w) & 0xFFF))
  94. #define BCI_X_Y(x, y) (((y) << 16) | ((x) & 0xFFF))
  95. #define BCI_GBD1 0xE0
  96. #define BCI_GBD2 0xE1
  97. #define BCI_BUFFER_OFFSET 0x10000
  98. #define BCI_SIZE 0x4000
  99. #define BCI_SEND(dw) writel(dw, par->bci_base + par->bci_ptr++)
  100. #define BCI_CMD_GET_ROP(cmd) (((cmd) >> 16) & 0xFF)
  101. #define BCI_CMD_SET_ROP(cmd, rop) ((cmd) |= ((rop & 0xFF) << 16))
  102. #define BCI_CMD_SEND_COLOR 0x00008000
  103. #define DISP_CRT 1
  104. #define DISP_LCD 2
  105. #define DISP_DFP 3
  106. struct xtimings {
  107. unsigned int Clock;
  108. unsigned int HDisplay;
  109. unsigned int HSyncStart;
  110. unsigned int HSyncEnd;
  111. unsigned int HTotal;
  112. unsigned int HAdjusted;
  113. unsigned int VDisplay;
  114. unsigned int VSyncStart;
  115. unsigned int VSyncEnd;
  116. unsigned int VTotal;
  117. unsigned int sync;
  118. int dblscan;
  119. int interlaced;
  120. };
  121. /* --------------------------------------------------------------------- */
  122. #define NR_PALETTE 256
  123. struct savagefb_par;
  124. struct savagefb_i2c_chan {
  125. struct savagefb_par *par;
  126. struct i2c_adapter adapter;
  127. struct i2c_algo_bit_data algo;
  128. volatile u8 __iomem *ioaddr;
  129. u32 reg;
  130. };
  131. struct savagefb_par {
  132. struct pci_dev *pcidev;
  133. savage_chipset chip;
  134. struct savagefb_i2c_chan chan;
  135. unsigned char *edid;
  136. u32 pseudo_palette[16];
  137. int pm_state;
  138. int display_type;
  139. int dvi;
  140. int crtonly;
  141. int dacSpeedBpp;
  142. int maxClock;
  143. int minClock;
  144. int numClocks;
  145. int clock[4];
  146. struct {
  147. u8 __iomem *vbase;
  148. u32 pbase;
  149. u32 len;
  150. #ifdef CONFIG_MTRR
  151. int mtrr;
  152. #endif
  153. } video;
  154. struct {
  155. volatile u8 __iomem *vbase;
  156. u32 pbase;
  157. u32 len;
  158. } mmio;
  159. volatile u32 __iomem *bci_base;
  160. unsigned int bci_ptr;
  161. u32 cob_offset;
  162. u32 cob_size;
  163. int cob_index;
  164. void (*SavageWaitIdle) (struct savagefb_par *par);
  165. void (*SavageWaitFifo) (struct savagefb_par *par, int space);
  166. int MCLK, REFCLK, LCDclk;
  167. int HorizScaleFactor;
  168. /* Panels size */
  169. int SavagePanelWidth;
  170. int SavagePanelHeight;
  171. struct {
  172. u16 red, green, blue, transp;
  173. } palette[NR_PALETTE];
  174. int depth;
  175. int vwidth;
  176. unsigned char MiscOutReg; /* Misc */
  177. unsigned char CRTC[25]; /* Crtc Controller */
  178. unsigned char Sequencer[5]; /* Video Sequencer */
  179. unsigned char Graphics[9]; /* Video Graphics */
  180. unsigned char Attribute[21]; /* Video Atribute */
  181. unsigned int mode, refresh;
  182. unsigned char SR08, SR0E, SR0F;
  183. unsigned char SR10, SR11, SR12, SR13, SR15, SR18, SR29, SR30;
  184. unsigned char SR54[8];
  185. unsigned char Clock;
  186. unsigned char CR31, CR32, CR33, CR34, CR36, CR3A, CR3B, CR3C;
  187. unsigned char CR40, CR41, CR42, CR43, CR45;
  188. unsigned char CR50, CR51, CR53, CR55, CR58, CR5B, CR5D, CR5E;
  189. unsigned char CR60, CR63, CR65, CR66, CR67, CR68, CR69, CR6D, CR6F;
  190. unsigned char CR86, CR88;
  191. unsigned char CR90, CR91, CRB0;
  192. unsigned int STREAMS[22]; /* yuck, streams regs */
  193. unsigned int MMPR0, MMPR1, MMPR2, MMPR3;
  194. };
  195. #define BCI_BD_BW_DISABLE 0x10000000
  196. #define BCI_BD_SET_BPP(bd, bpp) ((bd) |= (((bpp) & 0xFF) << 16))
  197. #define BCI_BD_SET_STRIDE(bd, st) ((bd) |= ((st) & 0xFFFF))
  198. /* IO functions */
  199. #define vga_in8(addr) (inb (addr))
  200. #define vga_in16(addr) (inw (addr))
  201. #define vga_in32(addr) (inl (addr))
  202. #define vga_out8(addr,val) (outb ((val), (addr)))
  203. #define vga_out16(addr,val) (outw ((val), (addr)))
  204. #define vga_out32(addr,val) (outl ((val), (addr)))
  205. #define savage_in16(addr) readw(par->mmio.vbase + (addr))
  206. #define savage_in32(addr) readl(par->mmio.vbase + (addr))
  207. #define savage_out16(addr,val) writew((val), par->mmio.vbase + (addr))
  208. #define savage_out32(addr,val) writel((val), par->mmio.vbase + (addr))
  209. static inline u8 VGArCR (u8 index)
  210. {
  211. outb (index, 0x3d4);
  212. return inb (0x3d5);
  213. }
  214. static inline u8 VGArGR (u8 index)
  215. {
  216. outb (index, 0x3ce);
  217. return inb (0x3cf);
  218. }
  219. static inline u8 VGArSEQ (u8 index)
  220. {
  221. outb (index, 0x3c4);
  222. return inb (0x3c5);
  223. }
  224. #define VGAwCR(index, val) \
  225. do { \
  226. vga_out8 (0x3d4, index); \
  227. vga_out8 (0x3d5, val); \
  228. } while (0)
  229. #define VGAwGR(index, val) \
  230. do { \
  231. vga_out8 (0x3ce, index); \
  232. vga_out8 (0x3cf, val); \
  233. } while (0)
  234. #define VGAwSEQ(index, val) \
  235. do { \
  236. vga_out8 (0x3c4, index); \
  237. vga_out8 (0x3c5, val); \
  238. } while (0)
  239. #define VGAenablePalette() \
  240. do { \
  241. u8 tmp; \
  242. \
  243. tmp = vga_in8 (0x3da); \
  244. vga_out8 (0x3c0, 0x00); \
  245. paletteEnabled = 1; \
  246. } while (0)
  247. #define VGAdisablePalette() \
  248. do { \
  249. u8 tmp; \
  250. \
  251. tmp = vga_in8 (0x3da); \
  252. vga_out8 (0x3c0, 0x20); \
  253. paletteEnabled = 0; \
  254. } while (0)
  255. #define VGAwATTR(index, value) \
  256. do { \
  257. u8 tmp; \
  258. \
  259. if (paletteEnabled) \
  260. index &= ~0x20; \
  261. else \
  262. index |= 0x20; \
  263. \
  264. tmp = vga_in8 (0x3da); \
  265. vga_out8 (0x3c0, index); \
  266. vga_out8 (0x3c0, value); \
  267. } while (0)
  268. #define VGAwMISC(value) \
  269. do { \
  270. vga_out8 (0x3c2, value); \
  271. } while (0)
  272. #ifndef CONFIG_FB_SAVAGE_ACCEL
  273. #define savagefb_set_clip(x)
  274. #endif
  275. #define VerticalRetraceWait() \
  276. { \
  277. vga_out8 (0x3d4, 0x17); \
  278. if (vga_in8 (0x3d5) & 0x80) { \
  279. while ((vga_in8(0x3da) & 0x08) == 0x08) ; \
  280. while ((vga_in8(0x3da) & 0x08) == 0x00) ; \
  281. } \
  282. }
  283. extern int savagefb_probe_i2c_connector(struct fb_info *info,
  284. u8 **out_edid);
  285. extern void savagefb_create_i2c_busses(struct fb_info *info);
  286. extern void savagefb_delete_i2c_busses(struct fb_info *info);
  287. extern int savagefb_sync(struct fb_info *info);
  288. extern void savagefb_copyarea(struct fb_info *info,
  289. const struct fb_copyarea *region);
  290. extern void savagefb_fillrect(struct fb_info *info,
  291. const struct fb_fillrect *rect);
  292. extern void savagefb_imageblit(struct fb_info *info,
  293. const struct fb_image *image);
  294. #endif /* __SAVAGEFB_H__ */