savagefb.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. struct xtimings {
  104. unsigned int Clock;
  105. unsigned int HDisplay;
  106. unsigned int HSyncStart;
  107. unsigned int HSyncEnd;
  108. unsigned int HTotal;
  109. unsigned int HAdjusted;
  110. unsigned int VDisplay;
  111. unsigned int VSyncStart;
  112. unsigned int VSyncEnd;
  113. unsigned int VTotal;
  114. unsigned int sync;
  115. int dblscan;
  116. int interlaced;
  117. };
  118. /* --------------------------------------------------------------------- */
  119. #define NR_PALETTE 256
  120. struct savagefb_par;
  121. struct savagefb_i2c_chan {
  122. struct savagefb_par *par;
  123. struct i2c_adapter adapter;
  124. struct i2c_algo_bit_data algo;
  125. volatile u8 __iomem *ioaddr;
  126. u32 reg;
  127. };
  128. struct savagefb_par {
  129. struct pci_dev *pcidev;
  130. savage_chipset chip;
  131. struct savagefb_i2c_chan chan;
  132. unsigned char *edid;
  133. u32 pseudo_palette[16];
  134. int dacSpeedBpp;
  135. int maxClock;
  136. int minClock;
  137. int numClocks;
  138. int clock[4];
  139. struct {
  140. u8 __iomem *vbase;
  141. u32 pbase;
  142. u32 len;
  143. #ifdef CONFIG_MTRR
  144. int mtrr;
  145. #endif
  146. } video;
  147. struct {
  148. volatile u8 __iomem *vbase;
  149. u32 pbase;
  150. u32 len;
  151. } mmio;
  152. volatile u32 __iomem *bci_base;
  153. unsigned int bci_ptr;
  154. u32 cob_offset;
  155. u32 cob_size;
  156. int cob_index;
  157. void (*SavageWaitIdle) (struct savagefb_par *par);
  158. void (*SavageWaitFifo) (struct savagefb_par *par, int space);
  159. int MCLK, REFCLK, LCDclk;
  160. int HorizScaleFactor;
  161. /* Panels size */
  162. int SavagePanelWidth;
  163. int SavagePanelHeight;
  164. struct {
  165. u16 red, green, blue, transp;
  166. } palette[NR_PALETTE];
  167. int depth;
  168. int vwidth;
  169. unsigned char MiscOutReg; /* Misc */
  170. unsigned char CRTC[25]; /* Crtc Controller */
  171. unsigned char Sequencer[5]; /* Video Sequencer */
  172. unsigned char Graphics[9]; /* Video Graphics */
  173. unsigned char Attribute[21]; /* Video Atribute */
  174. unsigned int mode, refresh;
  175. unsigned char SR08, SR0E, SR0F;
  176. unsigned char SR10, SR11, SR12, SR13, SR15, SR18, SR29, SR30;
  177. unsigned char SR54[8];
  178. unsigned char Clock;
  179. unsigned char CR31, CR32, CR33, CR34, CR36, CR3A, CR3B, CR3C;
  180. unsigned char CR40, CR41, CR42, CR43, CR45;
  181. unsigned char CR50, CR51, CR53, CR55, CR58, CR5B, CR5D, CR5E;
  182. unsigned char CR60, CR63, CR65, CR66, CR67, CR68, CR69, CR6D, CR6F;
  183. unsigned char CR86, CR88;
  184. unsigned char CR90, CR91, CRB0;
  185. unsigned int STREAMS[22]; /* yuck, streams regs */
  186. unsigned int MMPR0, MMPR1, MMPR2, MMPR3;
  187. };
  188. #define BCI_BD_BW_DISABLE 0x10000000
  189. #define BCI_BD_SET_BPP(bd, bpp) ((bd) |= (((bpp) & 0xFF) << 16))
  190. #define BCI_BD_SET_STRIDE(bd, st) ((bd) |= ((st) & 0xFFFF))
  191. /* IO functions */
  192. #define vga_in8(addr) (inb (addr))
  193. #define vga_in16(addr) (inw (addr))
  194. #define vga_in32(addr) (inl (addr))
  195. #define vga_out8(addr,val) (outb ((val), (addr)))
  196. #define vga_out16(addr,val) (outw ((val), (addr)))
  197. #define vga_out32(addr,val) (outl ((val), (addr)))
  198. #define savage_in16(addr) readw(par->mmio.vbase + (addr))
  199. #define savage_in32(addr) readl(par->mmio.vbase + (addr))
  200. #define savage_out16(addr,val) writew((val), par->mmio.vbase + (addr))
  201. #define savage_out32(addr,val) writel((val), par->mmio.vbase + (addr))
  202. static inline u8 VGArCR (u8 index)
  203. {
  204. outb (index, 0x3d4);
  205. return inb (0x3d5);
  206. }
  207. static inline u8 VGArGR (u8 index)
  208. {
  209. outb (index, 0x3ce);
  210. return inb (0x3cf);
  211. }
  212. static inline u8 VGArSEQ (u8 index)
  213. {
  214. outb (index, 0x3c4);
  215. return inb (0x3c5);
  216. }
  217. #define VGAwCR(index, val) \
  218. do { \
  219. vga_out8 (0x3d4, index); \
  220. vga_out8 (0x3d5, val); \
  221. } while (0)
  222. #define VGAwGR(index, val) \
  223. do { \
  224. vga_out8 (0x3ce, index); \
  225. vga_out8 (0x3cf, val); \
  226. } while (0)
  227. #define VGAwSEQ(index, val) \
  228. do { \
  229. vga_out8 (0x3c4, index); \
  230. vga_out8 (0x3c5, val); \
  231. } while (0)
  232. #define VGAenablePalette() \
  233. do { \
  234. u8 tmp; \
  235. \
  236. tmp = vga_in8 (0x3da); \
  237. vga_out8 (0x3c0, 0x00); \
  238. paletteEnabled = 1; \
  239. } while (0)
  240. #define VGAdisablePalette() \
  241. do { \
  242. u8 tmp; \
  243. \
  244. tmp = vga_in8 (0x3da); \
  245. vga_out8 (0x3c0, 0x20); \
  246. paletteEnabled = 0; \
  247. } while (0)
  248. #define VGAwATTR(index, value) \
  249. do { \
  250. u8 tmp; \
  251. \
  252. if (paletteEnabled) \
  253. index &= ~0x20; \
  254. else \
  255. index |= 0x20; \
  256. \
  257. tmp = vga_in8 (0x3da); \
  258. vga_out8 (0x3c0, index); \
  259. vga_out8 (0x3c0, value); \
  260. } while (0)
  261. #define VGAwMISC(value) \
  262. do { \
  263. vga_out8 (0x3c2, value); \
  264. } while (0)
  265. #ifndef CONFIG_FB_SAVAGE_ACCEL
  266. #define savagefb_set_clip(x)
  267. #endif
  268. #define VerticalRetraceWait() \
  269. { \
  270. vga_out8 (0x3d4, 0x17); \
  271. if (vga_in8 (0x3d5) & 0x80) { \
  272. while ((vga_in8(0x3da) & 0x08) == 0x08) ; \
  273. while ((vga_in8(0x3da) & 0x08) == 0x00) ; \
  274. } \
  275. }
  276. extern int savagefb_probe_i2c_connector(struct savagefb_par *par,
  277. u8 **out_edid);
  278. extern void savagefb_create_i2c_busses(struct fb_info *info);
  279. extern void savagefb_delete_i2c_busses(struct fb_info *info);
  280. extern int savagefb_sync(struct fb_info *info);
  281. extern void savagefb_copyarea(struct fb_info *info,
  282. const struct fb_copyarea *region);
  283. extern void savagefb_fillrect(struct fb_info *info,
  284. const struct fb_fillrect *rect);
  285. extern void savagefb_imageblit(struct fb_info *info,
  286. const struct fb_image *image);
  287. #endif /* __SAVAGEFB_H__ */