savagefb.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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-algo-bit.h>
  14. #include <linux/mutex.h>
  15. #include <video/vga.h>
  16. #include "../edid.h"
  17. #ifdef SAVAGEFB_DEBUG
  18. # define DBG(x) printk (KERN_DEBUG "savagefb: %s\n", (x));
  19. #else
  20. # define DBG(x)
  21. # define SavagePrintRegs(...)
  22. #endif
  23. #define PCI_CHIP_SAVAGE4 0x8a22
  24. #define PCI_CHIP_SAVAGE3D 0x8a20
  25. #define PCI_CHIP_SAVAGE3D_MV 0x8a21
  26. #define PCI_CHIP_SAVAGE2000 0x9102
  27. #define PCI_CHIP_SAVAGE_MX_MV 0x8c10
  28. #define PCI_CHIP_SAVAGE_MX 0x8c11
  29. #define PCI_CHIP_SAVAGE_IX_MV 0x8c12
  30. #define PCI_CHIP_SAVAGE_IX 0x8c13
  31. #define PCI_CHIP_PROSAVAGE_PM 0x8a25
  32. #define PCI_CHIP_PROSAVAGE_KM 0x8a26
  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_SAVAGE_SERIES(chip) ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE2000))
  47. #define S3_SAVAGE3D_SERIES(chip) ((chip>=S3_SAVAGE3D) && (chip<=S3_SAVAGE_MX))
  48. #define S3_SAVAGE4_SERIES(chip) ((chip>=S3_SAVAGE4) && (chip<=S3_PROSAVAGEDDR))
  49. #define S3_SAVAGE_MOBILE_SERIES(chip) ((chip==S3_SAVAGE_MX) || (chip==S3_SUPERSAVAGE))
  50. #define S3_MOBILE_TWISTER_SERIES(chip) ((chip==S3_TWISTER) || (chip==S3_PROSAVAGEDDR))
  51. /* Chip tags. These are used to group the adapters into
  52. * related families.
  53. */
  54. typedef enum {
  55. S3_UNKNOWN = 0,
  56. S3_SAVAGE3D,
  57. S3_SAVAGE_MX,
  58. S3_SAVAGE4,
  59. S3_PROSAVAGE,
  60. S3_TWISTER,
  61. S3_PROSAVAGEDDR,
  62. S3_SUPERSAVAGE,
  63. S3_SAVAGE2000,
  64. S3_LAST
  65. } savage_chipset;
  66. #define BIOS_BSIZE 1024
  67. #define BIOS_BASE 0xc0000
  68. #define SAVAGE_NEWMMIO_REGBASE_S3 0x1000000 /* 16MB */
  69. #define SAVAGE_NEWMMIO_REGBASE_S4 0x0000000
  70. #define SAVAGE_NEWMMIO_REGSIZE 0x0080000 /* 512kb */
  71. #define SAVAGE_NEWMMIO_VGABASE 0x8000
  72. #define BASE_FREQ 14318
  73. #define HALF_BASE_FREQ 7159
  74. #define FIFO_CONTROL_REG 0x8200
  75. #define MIU_CONTROL_REG 0x8204
  76. #define STREAMS_TIMEOUT_REG 0x8208
  77. #define MISC_TIMEOUT_REG 0x820c
  78. #define MONO_PAT_0 0xa4e8
  79. #define MONO_PAT_1 0xa4ec
  80. #define MAXFIFO 0x7f00
  81. #define BCI_CMD_NOP 0x40000000
  82. #define BCI_CMD_SETREG 0x96000000
  83. #define BCI_CMD_RECT 0x48000000
  84. #define BCI_CMD_RECT_XP 0x01000000
  85. #define BCI_CMD_RECT_YP 0x02000000
  86. #define BCI_CMD_SEND_COLOR 0x00008000
  87. #define BCI_CMD_DEST_GBD 0x00000000
  88. #define BCI_CMD_SRC_GBD 0x00000020
  89. #define BCI_CMD_SRC_SOLID 0x00000000
  90. #define BCI_CMD_SRC_MONO 0x00000060
  91. #define BCI_CMD_CLIP_NEW 0x00006000
  92. #define BCI_CMD_CLIP_LR 0x00004000
  93. #define BCI_CLIP_LR(l, r) ((((r) << 16) | (l)) & 0x0FFF0FFF)
  94. #define BCI_CLIP_TL(t, l) ((((t) << 16) | (l)) & 0x0FFF0FFF)
  95. #define BCI_CLIP_BR(b, r) ((((b) << 16) | (r)) & 0x0FFF0FFF)
  96. #define BCI_W_H(w, h) (((h) << 16) | ((w) & 0xFFF))
  97. #define BCI_X_Y(x, y) (((y) << 16) | ((x) & 0xFFF))
  98. #define BCI_GBD1 0xE0
  99. #define BCI_GBD2 0xE1
  100. #define BCI_BUFFER_OFFSET 0x10000
  101. #define BCI_SIZE 0x4000
  102. #define BCI_SEND(dw) writel(dw, par->bci_base + par->bci_ptr++)
  103. #define BCI_CMD_GET_ROP(cmd) (((cmd) >> 16) & 0xFF)
  104. #define BCI_CMD_SET_ROP(cmd, rop) ((cmd) |= ((rop & 0xFF) << 16))
  105. #define BCI_CMD_SEND_COLOR 0x00008000
  106. #define DISP_CRT 1
  107. #define DISP_LCD 2
  108. #define DISP_DFP 3
  109. struct xtimings {
  110. unsigned int Clock;
  111. unsigned int HDisplay;
  112. unsigned int HSyncStart;
  113. unsigned int HSyncEnd;
  114. unsigned int HTotal;
  115. unsigned int HAdjusted;
  116. unsigned int VDisplay;
  117. unsigned int VSyncStart;
  118. unsigned int VSyncEnd;
  119. unsigned int VTotal;
  120. unsigned int sync;
  121. int dblscan;
  122. int interlaced;
  123. };
  124. struct savage_reg {
  125. unsigned char MiscOutReg; /* Misc */
  126. unsigned char CRTC[25]; /* Crtc Controller */
  127. unsigned char Sequencer[5]; /* Video Sequencer */
  128. unsigned char Graphics[9]; /* Video Graphics */
  129. unsigned char Attribute[21]; /* Video Attribute */
  130. unsigned int mode, refresh;
  131. unsigned char SR08, SR0E, SR0F;
  132. unsigned char SR10, SR11, SR12, SR13, SR15, SR18, SR29, SR30;
  133. unsigned char SR54[8];
  134. unsigned char Clock;
  135. unsigned char CR31, CR32, CR33, CR34, CR36, CR3A, CR3B, CR3C;
  136. unsigned char CR40, CR41, CR42, CR43, CR45;
  137. unsigned char CR50, CR51, CR53, CR55, CR58, CR5B, CR5D, CR5E;
  138. unsigned char CR60, CR63, CR65, CR66, CR67, CR68, CR69, CR6D, CR6F;
  139. unsigned char CR86, CR88;
  140. unsigned char CR90, CR91, CRB0;
  141. unsigned int STREAMS[22]; /* yuck, streams regs */
  142. unsigned int MMPR0, MMPR1, MMPR2, MMPR3;
  143. };
  144. /* --------------------------------------------------------------------- */
  145. #define NR_PALETTE 256
  146. struct savagefb_par;
  147. struct savagefb_i2c_chan {
  148. struct savagefb_par *par;
  149. struct i2c_adapter adapter;
  150. struct i2c_algo_bit_data algo;
  151. volatile u8 __iomem *ioaddr;
  152. u32 reg;
  153. };
  154. struct savagefb_par {
  155. struct pci_dev *pcidev;
  156. savage_chipset chip;
  157. struct savagefb_i2c_chan chan;
  158. struct savage_reg state;
  159. struct savage_reg save;
  160. struct savage_reg initial;
  161. struct vgastate vgastate;
  162. struct mutex open_lock;
  163. unsigned char *edid;
  164. u32 pseudo_palette[16];
  165. u32 open_count;
  166. int paletteEnabled;
  167. int pm_state;
  168. int display_type;
  169. int dvi;
  170. int crtonly;
  171. int dacSpeedBpp;
  172. int maxClock;
  173. int minClock;
  174. int numClocks;
  175. int clock[4];
  176. int MCLK, REFCLK, LCDclk;
  177. struct {
  178. void __iomem *vbase;
  179. u32 pbase;
  180. u32 len;
  181. int wc_cookie;
  182. } video;
  183. struct {
  184. void __iomem *vbase;
  185. u32 pbase;
  186. u32 len;
  187. } mmio;
  188. volatile u32 __iomem *bci_base;
  189. unsigned int bci_ptr;
  190. u32 cob_offset;
  191. u32 cob_size;
  192. int cob_index;
  193. void (*SavageWaitIdle) (struct savagefb_par *par);
  194. void (*SavageWaitFifo) (struct savagefb_par *par, int space);
  195. int HorizScaleFactor;
  196. /* Panels size */
  197. int SavagePanelWidth;
  198. int SavagePanelHeight;
  199. struct {
  200. u16 red, green, blue, transp;
  201. } palette[NR_PALETTE];
  202. int depth;
  203. int vwidth;
  204. };
  205. #define BCI_BD_BW_DISABLE 0x10000000
  206. #define BCI_BD_SET_BPP(bd, bpp) ((bd) |= (((bpp) & 0xFF) << 16))
  207. #define BCI_BD_SET_STRIDE(bd, st) ((bd) |= ((st) & 0xFFFF))
  208. /* IO functions */
  209. static inline u8 savage_in8(u32 addr, struct savagefb_par *par)
  210. {
  211. return readb(par->mmio.vbase + addr);
  212. }
  213. static inline u16 savage_in16(u32 addr, struct savagefb_par *par)
  214. {
  215. return readw(par->mmio.vbase + addr);
  216. }
  217. static inline u32 savage_in32(u32 addr, struct savagefb_par *par)
  218. {
  219. return readl(par->mmio.vbase + addr);
  220. }
  221. static inline void savage_out8(u32 addr, u8 val, struct savagefb_par *par)
  222. {
  223. writeb(val, par->mmio.vbase + addr);
  224. }
  225. static inline void savage_out16(u32 addr, u16 val, struct savagefb_par *par)
  226. {
  227. writew(val, par->mmio.vbase + addr);
  228. }
  229. static inline void savage_out32(u32 addr, u32 val, struct savagefb_par *par)
  230. {
  231. writel(val, par->mmio.vbase + addr);
  232. }
  233. static inline u8 vga_in8(int addr, struct savagefb_par *par)
  234. {
  235. return savage_in8(0x8000 + addr, par);
  236. }
  237. static inline u16 vga_in16(int addr, struct savagefb_par *par)
  238. {
  239. return savage_in16(0x8000 + addr, par);
  240. }
  241. static inline u8 vga_in32(int addr, struct savagefb_par *par)
  242. {
  243. return savage_in32(0x8000 + addr, par);
  244. }
  245. static inline void vga_out8(int addr, u8 val, struct savagefb_par *par)
  246. {
  247. savage_out8(0x8000 + addr, val, par);
  248. }
  249. static inline void vga_out16(int addr, u16 val, struct savagefb_par *par)
  250. {
  251. savage_out16(0x8000 + addr, val, par);
  252. }
  253. static inline void vga_out32(int addr, u32 val, struct savagefb_par *par)
  254. {
  255. savage_out32(0x8000 + addr, val, par);
  256. }
  257. static inline u8 VGArCR (u8 index, struct savagefb_par *par)
  258. {
  259. vga_out8(0x3d4, index, par);
  260. return vga_in8(0x3d5, par);
  261. }
  262. static inline u8 VGArGR (u8 index, struct savagefb_par *par)
  263. {
  264. vga_out8(0x3ce, index, par);
  265. return vga_in8(0x3cf, par);
  266. }
  267. static inline u8 VGArSEQ (u8 index, struct savagefb_par *par)
  268. {
  269. vga_out8(0x3c4, index, par);
  270. return vga_in8(0x3c5, par);
  271. }
  272. static inline void VGAwCR(u8 index, u8 val, struct savagefb_par *par)
  273. {
  274. vga_out8(0x3d4, index, par);
  275. vga_out8(0x3d5, val, par);
  276. }
  277. static inline void VGAwGR(u8 index, u8 val, struct savagefb_par *par)
  278. {
  279. vga_out8(0x3ce, index, par);
  280. vga_out8(0x3cf, val, par);
  281. }
  282. static inline void VGAwSEQ(u8 index, u8 val, struct savagefb_par *par)
  283. {
  284. vga_out8(0x3c4, index, par);
  285. vga_out8 (0x3c5, val, par);
  286. }
  287. static inline void VGAenablePalette(struct savagefb_par *par)
  288. {
  289. vga_in8(0x3da, par);
  290. vga_out8(0x3c0, 0x00, par);
  291. par->paletteEnabled = 1;
  292. }
  293. static inline void VGAdisablePalette(struct savagefb_par *par)
  294. {
  295. vga_in8(0x3da, par);
  296. vga_out8(0x3c0, 0x20, par);
  297. par->paletteEnabled = 0;
  298. }
  299. static inline void VGAwATTR(u8 index, u8 value, struct savagefb_par *par)
  300. {
  301. if (par->paletteEnabled)
  302. index &= ~0x20;
  303. else
  304. index |= 0x20;
  305. vga_in8(0x3da, par);
  306. vga_out8(0x3c0, index, par);
  307. vga_out8 (0x3c0, value, par);
  308. }
  309. static inline void VGAwMISC(u8 value, struct savagefb_par *par)
  310. {
  311. vga_out8(0x3c2, value, par);
  312. }
  313. #ifndef CONFIG_FB_SAVAGE_ACCEL
  314. #define savagefb_set_clip(x)
  315. #endif
  316. static inline void VerticalRetraceWait(struct savagefb_par *par)
  317. {
  318. vga_out8(0x3d4, 0x17, par);
  319. if (vga_in8(0x3d5, par) & 0x80) {
  320. while ((vga_in8(0x3da, par) & 0x08) == 0x08);
  321. while ((vga_in8(0x3da, par) & 0x08) == 0x00);
  322. }
  323. }
  324. extern int savagefb_probe_i2c_connector(struct fb_info *info,
  325. u8 **out_edid);
  326. extern void savagefb_create_i2c_busses(struct fb_info *info);
  327. extern void savagefb_delete_i2c_busses(struct fb_info *info);
  328. extern int savagefb_sync(struct fb_info *info);
  329. extern void savagefb_copyarea(struct fb_info *info,
  330. const struct fb_copyarea *region);
  331. extern void savagefb_fillrect(struct fb_info *info,
  332. const struct fb_fillrect *rect);
  333. extern void savagefb_imageblit(struct fb_info *info,
  334. const struct fb_image *image);
  335. #endif /* __SAVAGEFB_H__ */