sstfb.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * linux/drivers/video/sstfb.h -- voodoo graphics frame buffer
  4. *
  5. * Copyright (c) 2000,2001 Ghozlane Toumi <gtoumi@messel.emse.fr>
  6. *
  7. * Created 28 Aug 2001 by Ghozlane Toumi
  8. */
  9. #ifndef _SSTFB_H_
  10. #define _SSTFB_H_
  11. /*
  12. *
  13. * Debug Stuff
  14. *
  15. */
  16. #ifdef SST_DEBUG
  17. # define dprintk(X...) printk("sstfb: " X)
  18. # define SST_DEBUG_REG 1
  19. # define SST_DEBUG_FUNC 1
  20. # define SST_DEBUG_VAR 1
  21. #else
  22. # define dprintk(X...)
  23. # define SST_DEBUG_REG 0
  24. # define SST_DEBUG_FUNC 0
  25. # define SST_DEBUG_VAR 0
  26. #endif
  27. #if (SST_DEBUG_REG > 0)
  28. # define r_dprintk(X...) dprintk(X)
  29. #else
  30. # define r_dprintk(X...)
  31. #endif
  32. #if (SST_DEBUG_REG > 1)
  33. # define r_ddprintk(X...) dprintk(" " X)
  34. #else
  35. # define r_ddprintk(X...)
  36. #endif
  37. #if (SST_DEBUG_FUNC > 0)
  38. # define f_dprintk(X...) dprintk(X)
  39. #else
  40. # define f_dprintk(X...)
  41. #endif
  42. #if (SST_DEBUG_FUNC > 1)
  43. # define f_ddprintk(X...) dprintk(" " X)
  44. #else
  45. # define f_ddprintk(X...)
  46. #endif
  47. #if (SST_DEBUG_FUNC > 2)
  48. # define f_dddprintk(X...) dprintk(" " X)
  49. #else
  50. # define f_dddprintk(X...)
  51. #endif
  52. #if (SST_DEBUG_VAR > 0)
  53. # define v_dprintk(X...) dprintk(X)
  54. # define print_var(V, X...) \
  55. { \
  56. dprintk(X); \
  57. printk(" :\n"); \
  58. sst_dbg_print_var(V); \
  59. }
  60. #else
  61. # define v_dprintk(X...)
  62. # define print_var(X,Y...)
  63. #endif
  64. #define POW2(x) (1ul<<(x))
  65. /*
  66. *
  67. * Const
  68. *
  69. */
  70. /* pci stuff */
  71. #define PCI_INIT_ENABLE 0x40
  72. # define PCI_EN_INIT_WR BIT(0)
  73. # define PCI_EN_FIFO_WR BIT(1)
  74. # define PCI_REMAP_DAC BIT(2)
  75. #define PCI_VCLK_ENABLE 0xc0 /* enable video */
  76. #define PCI_VCLK_DISABLE 0xe0
  77. /* register offsets from memBaseAddr */
  78. #define STATUS 0x0000
  79. # define STATUS_FBI_BUSY BIT(7)
  80. #define FBZMODE 0x0110
  81. # define EN_CLIPPING BIT(0) /* enable clipping */
  82. # define EN_RGB_WRITE BIT(9) /* enable writes to rgb area */
  83. # define EN_ALPHA_WRITE BIT(10)
  84. # define ENGINE_INVERT_Y BIT(17) /* invert Y origin (pipe) */
  85. #define LFBMODE 0x0114
  86. # define LFB_565 0 /* bits 3:0 .16 bits RGB */
  87. # define LFB_888 4 /* 24 bits RGB */
  88. # define LFB_8888 5 /* 32 bits ARGB */
  89. # define WR_BUFF_FRONT 0 /* write buf select (front) */
  90. # define WR_BUFF_BACK (1 << 4) /* back */
  91. # define RD_BUFF_FRONT 0 /* read buff select (front) */
  92. # define RD_BUFF_BACK (1 << 6) /* back */
  93. # define EN_PXL_PIPELINE BIT(8) /* pixel pipeline (clip..)*/
  94. # define LFB_WORD_SWIZZLE_WR BIT(11) /* enable write-wordswap (big-endian) */
  95. # define LFB_BYTE_SWIZZLE_WR BIT(12) /* enable write-byteswap (big-endian) */
  96. # define LFB_INVERT_Y BIT(13) /* invert Y origin (LFB) */
  97. # define LFB_WORD_SWIZZLE_RD BIT(15) /* enable read-wordswap (big-endian) */
  98. # define LFB_BYTE_SWIZZLE_RD BIT(16) /* enable read-byteswap (big-endian) */
  99. #define CLIP_LEFT_RIGHT 0x0118
  100. #define CLIP_LOWY_HIGHY 0x011c
  101. #define NOPCMD 0x0120
  102. #define FASTFILLCMD 0x0124
  103. #define SWAPBUFFCMD 0x0128
  104. #define FBIINIT4 0x0200 /* misc controls */
  105. # define FAST_PCI_READS 0 /* 1 waitstate */
  106. # define SLOW_PCI_READS BIT(0) /* 2 ws */
  107. # define LFB_READ_AHEAD BIT(1)
  108. #define BACKPORCH 0x0208
  109. #define VIDEODIMENSIONS 0x020c
  110. #define FBIINIT0 0x0210 /* misc+fifo controls */
  111. # define DIS_VGA_PASSTHROUGH BIT(0)
  112. # define FBI_RESET BIT(1)
  113. # define FIFO_RESET BIT(2)
  114. #define FBIINIT1 0x0214 /* PCI + video controls */
  115. # define VIDEO_MASK 0x8080010f /* masks video related bits V1+V2*/
  116. # define FAST_PCI_WRITES 0 /* 0 ws */
  117. # define SLOW_PCI_WRITES BIT(1) /* 1 ws */
  118. # define EN_LFB_READ BIT(3)
  119. # define TILES_IN_X_SHIFT 4
  120. # define VIDEO_RESET BIT(8)
  121. # define EN_BLANKING BIT(12)
  122. # define EN_DATA_OE BIT(13)
  123. # define EN_BLANK_OE BIT(14)
  124. # define EN_HVSYNC_OE BIT(15)
  125. # define EN_DCLK_OE BIT(16)
  126. # define SEL_INPUT_VCLK_2X 0 /* bit 17 */
  127. # define SEL_INPUT_VCLK_SLAVE BIT(17)
  128. # define SEL_SOURCE_VCLK_SLAVE 0 /* bits 21:20 */
  129. # define SEL_SOURCE_VCLK_2X_DIV2 (0x01 << 20)
  130. # define SEL_SOURCE_VCLK_2X_SEL (0x02 << 20)
  131. # define EN_24BPP BIT(22)
  132. # define TILES_IN_X_MSB_SHIFT 24 /* v2 */
  133. # define VCLK_2X_SEL_DEL_SHIFT 27 /* vclk out delay 0,4,6,8ns */
  134. # define VCLK_DEL_SHIFT 29 /* vclk in delay */
  135. #define FBIINIT2 0x0218 /* Dram controls */
  136. # define EN_FAST_RAS_READ BIT(5)
  137. # define EN_DRAM_OE BIT(6)
  138. # define EN_FAST_RD_AHEAD_WR BIT(7)
  139. # define VIDEO_OFFSET_SHIFT 11 /* unit: #rows tile 64x16/2 */
  140. # define SWAP_DACVSYNC 0
  141. # define SWAP_DACDATA0 (1 << 9)
  142. # define SWAP_FIFO_STALL (2 << 9)
  143. # define EN_RD_AHEAD_FIFO BIT(21)
  144. # define EN_DRAM_REFRESH BIT(22)
  145. # define DRAM_REFRESH_16 (0x30 << 23) /* dram 16 ms */
  146. #define DAC_READ FBIINIT2 /* in remap mode */
  147. #define FBIINIT3 0x021c /* fbi controls */
  148. # define DISABLE_TEXTURE BIT(6)
  149. # define Y_SWAP_ORIGIN_SHIFT 22 /* Y swap subtraction value */
  150. #define HSYNC 0x0220
  151. #define VSYNC 0x0224
  152. #define DAC_DATA 0x022c
  153. # define DAC_READ_CMD BIT(11) /* set read dacreg mode */
  154. #define FBIINIT5 0x0244 /* v2 specific */
  155. # define FBIINIT5_MASK 0xfa40ffff /* mask video bits*/
  156. # define HDOUBLESCAN BIT(20)
  157. # define VDOUBLESCAN BIT(21)
  158. # define HSYNC_HIGH BIT(23)
  159. # define VSYNC_HIGH BIT(24)
  160. # define INTERLACE BIT(26)
  161. #define FBIINIT6 0x0248 /* v2 specific */
  162. # define TILES_IN_X_LSB_SHIFT 30 /* v2 */
  163. #define FBIINIT7 0x024c /* v2 specific */
  164. #define BLTSRCBASEADDR 0x02c0 /* BitBLT Source base address */
  165. #define BLTDSTBASEADDR 0x02c4 /* BitBLT Destination base address */
  166. #define BLTXYSTRIDES 0x02c8 /* BitBLT Source and Destination strides */
  167. #define BLTSRCCHROMARANGE 0x02cc /* BitBLT Source Chroma key range */
  168. #define BLTDSTCHROMARANGE 0x02d0 /* BitBLT Destination Chroma key range */
  169. #define BLTCLIPX 0x02d4 /* BitBLT Min/Max X clip values */
  170. #define BLTCLIPY 0x02d8 /* BitBLT Min/Max Y clip values */
  171. #define BLTSRCXY 0x02e0 /* BitBLT Source starting XY coordinates */
  172. #define BLTDSTXY 0x02e4 /* BitBLT Destination starting XY coordinates */
  173. #define BLTSIZE 0x02e8 /* BitBLT width and height */
  174. #define BLTROP 0x02ec /* BitBLT Raster operations */
  175. # define BLTROP_COPY 0x0cccc
  176. # define BLTROP_INVERT 0x05555
  177. # define BLTROP_XOR 0x06666
  178. #define BLTCOLOR 0x02f0 /* BitBLT and foreground background colors */
  179. #define BLTCOMMAND 0x02f8 /* BitBLT command mode (v2 specific) */
  180. # define BLT_SCR2SCR_BITBLT 0 /* Screen-to-Screen BitBLT */
  181. # define BLT_CPU2SCR_BITBLT 1 /* CPU-to-screen BitBLT */
  182. # define BLT_RECFILL_BITBLT 2 /* BitBLT Rectangle Fill */
  183. # define BLT_16BPP_FMT 2 /* 16 BPP (5-6-5 RGB) */
  184. #define BLTDATA 0x02fc /* BitBLT data for CPU-to-Screen BitBLTs */
  185. # define LAUNCH_BITBLT BIT(31) /* Launch BitBLT in BltCommand, bltDstXY or bltSize */
  186. /* Dac Registers */
  187. #define DACREG_WMA 0x0 /* pixel write mode address */
  188. #define DACREG_LUT 0x01 /* color value */
  189. #define DACREG_RMR 0x02 /* pixel mask */
  190. #define DACREG_RMA 0x03 /* pixel read mode address */
  191. /*Dac registers in indexed mode (TI, ATT dacs) */
  192. #define DACREG_ADDR_I DACREG_WMA
  193. #define DACREG_DATA_I DACREG_RMR
  194. #define DACREG_RMR_I 0x00
  195. #define DACREG_CR0_I 0x01
  196. # define DACREG_CR0_EN_INDEXED BIT(0) /* enable indexec mode */
  197. # define DACREG_CR0_8BIT BIT(1) /* set dac to 8 bits/read */
  198. # define DACREG_CR0_PWDOWN BIT(3) /* powerdown dac */
  199. # define DACREG_CR0_16BPP 0x30 /* mode 3 */
  200. # define DACREG_CR0_24BPP 0x50 /* mode 5 */
  201. #define DACREG_CR1_I 0x05
  202. #define DACREG_CC_I 0x06
  203. # define DACREG_CC_CLKA BIT(7) /* clk A controlled by regs */
  204. # define DACREG_CC_CLKA_C (2<<4) /* clk A uses reg C */
  205. # define DACREG_CC_CLKB BIT(3) /* clk B controlled by regs */
  206. # define DACREG_CC_CLKB_D 3 /* clkB uses reg D */
  207. #define DACREG_AC0_I 0x48 /* clock A reg C */
  208. #define DACREG_AC1_I 0x49
  209. #define DACREG_BD0_I 0x6c /* clock B reg D */
  210. #define DACREG_BD1_I 0x6d
  211. /* identification constants */
  212. #define DACREG_MIR_TI 0x97
  213. #define DACREG_DIR_TI 0x09
  214. #define DACREG_MIR_ATT 0x84
  215. #define DACREG_DIR_ATT 0x09
  216. /* ics dac specific registers */
  217. #define DACREG_ICS_PLLWMA 0x04 /* PLL write mode address */
  218. #define DACREG_ICS_PLLDATA 0x05 /* PLL data /parameter */
  219. #define DACREG_ICS_CMD 0x06 /* command */
  220. # define DACREG_ICS_CMD_16BPP 0x50 /* ics color mode 6 (16bpp bypass)*/
  221. # define DACREG_ICS_CMD_24BPP 0x70 /* ics color mode 7 (24bpp bypass)*/
  222. # define DACREG_ICS_CMD_PWDOWN BIT(0) /* powerdown dac */
  223. #define DACREG_ICS_PLLRMA 0x07 /* PLL read mode address */
  224. /*
  225. * pll parameter register:
  226. * indexed : write addr to PLLWMA, write data in PLLDATA.
  227. * for reads use PLLRMA .
  228. * 8 freq registers (0-7) for video clock (CLK0)
  229. * 2 freq registers (a-b) for graphic clock (CLK1)
  230. */
  231. #define DACREG_ICS_PLL_CLK0_1_INI 0x55 /* initial pll M value for freq f1 */
  232. #define DACREG_ICS_PLL_CLK0_7_INI 0x71 /* f7 */
  233. #define DACREG_ICS_PLL_CLK1_B_INI 0x79 /* fb */
  234. #define DACREG_ICS_PLL_CTRL 0x0e
  235. # define DACREG_ICS_CLK0 BIT(5)
  236. # define DACREG_ICS_CLK0_0 0
  237. # define DACREG_ICS_CLK1_A 0 /* bit4 */
  238. /* sst default init registers */
  239. #define FBIINIT0_DEFAULT DIS_VGA_PASSTHROUGH
  240. #define FBIINIT1_DEFAULT \
  241. ( \
  242. FAST_PCI_WRITES \
  243. /* SLOW_PCI_WRITES*/ \
  244. | VIDEO_RESET \
  245. | 10 << TILES_IN_X_SHIFT\
  246. | SEL_SOURCE_VCLK_2X_SEL\
  247. | EN_LFB_READ \
  248. )
  249. #define FBIINIT2_DEFAULT \
  250. ( \
  251. SWAP_DACVSYNC \
  252. | EN_DRAM_OE \
  253. | DRAM_REFRESH_16 \
  254. | EN_DRAM_REFRESH \
  255. | EN_FAST_RAS_READ \
  256. | EN_RD_AHEAD_FIFO \
  257. | EN_FAST_RD_AHEAD_WR \
  258. )
  259. #define FBIINIT3_DEFAULT \
  260. ( DISABLE_TEXTURE )
  261. #define FBIINIT4_DEFAULT \
  262. ( \
  263. FAST_PCI_READS \
  264. /* SLOW_PCI_READS*/ \
  265. | LFB_READ_AHEAD \
  266. )
  267. /* Careful with this one : writing back the data just read will trash the DAC
  268. reading some fields give logic value on pins, but setting this field will
  269. set the source signal driving the pin. conclusion : just use the default
  270. as a base before writing back .
  271. */
  272. #define FBIINIT6_DEFAULT (0x0)
  273. /*
  274. *
  275. * Misc Const
  276. *
  277. */
  278. /* ioctl to enable/disable VGA passthrough */
  279. #define SSTFB_SET_VGAPASS _IOW('F', 0xdd, __u32)
  280. #define SSTFB_GET_VGAPASS _IOR('F', 0xdd, __u32)
  281. /* used to know witch clock to set */
  282. enum {
  283. VID_CLOCK=0,
  284. GFX_CLOCK=1,
  285. };
  286. /* freq max */
  287. #define DAC_FREF 14318 /* DAC reference freq (Khz) */
  288. #define VCO_MAX 260000
  289. /*
  290. * driver structs
  291. */
  292. struct pll_timing {
  293. unsigned int m;
  294. unsigned int n;
  295. unsigned int p;
  296. };
  297. struct dac_switch {
  298. const char *name;
  299. int (*detect) (struct fb_info *info);
  300. int (*set_pll) (struct fb_info *info, const struct pll_timing *t, const int clock);
  301. void (*set_vidmod) (struct fb_info *info, const int bpp);
  302. };
  303. struct sst_spec {
  304. char * name;
  305. int default_gfx_clock; /* 50000 for voodoo1, 75000 for voodoo2 */
  306. int max_gfxclk; /* ! in Mhz ie 60 for voodoo 1 */
  307. };
  308. struct sstfb_par {
  309. u32 palette[16];
  310. unsigned int yDim;
  311. unsigned int hSyncOn; /* hsync_len */
  312. unsigned int hSyncOff; /* left_margin + xres + right_margin */
  313. unsigned int hBackPorch;/* left_margin */
  314. unsigned int vSyncOn;
  315. unsigned int vSyncOff;
  316. unsigned int vBackPorch;
  317. struct pll_timing pll;
  318. unsigned int tiles_in_X;/* num of tiles in X res */
  319. u8 __iomem *mmio_vbase;
  320. struct dac_switch dac_sw; /* dac specific functions */
  321. struct pci_dev *dev;
  322. int type;
  323. u8 revision;
  324. u8 vgapass; /* VGA pass through: 1=enabled, 0=disabled */
  325. };
  326. #endif /* _SSTFB_H_ */