lsdc_regs.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2023 Loongson Technology Corporation Limited
  4. */
  5. #ifndef __LSDC_REGS_H__
  6. #define __LSDC_REGS_H__
  7. #include <linux/bitops.h>
  8. #include <linux/types.h>
  9. /*
  10. * PIXEL PLL Reference clock
  11. */
  12. #define LSDC_PLL_REF_CLK_KHZ 100000
  13. /*
  14. * Those PLL registers are relative to LSxxxxx_CFG_REG_BASE. xxxxx = 7A1000,
  15. * 7A2000, 2K2000, 2K1000 etc.
  16. */
  17. /* LS7A1000 */
  18. #define LS7A1000_PIXPLL0_REG 0x04B0
  19. #define LS7A1000_PIXPLL1_REG 0x04C0
  20. /* The DC, GPU, Graphic Memory Controller share the single gfxpll */
  21. #define LS7A1000_PLL_GFX_REG 0x0490
  22. #define LS7A1000_CONF_REG_BASE 0x10010000
  23. /* LS7A2000 */
  24. #define LS7A2000_PIXPLL0_REG 0x04B0
  25. #define LS7A2000_PIXPLL1_REG 0x04C0
  26. /* The DC, GPU, Graphic Memory Controller share the single gfxpll */
  27. #define LS7A2000_PLL_GFX_REG 0x0490
  28. #define LS7A2000_CONF_REG_BASE 0x10010000
  29. /* For LSDC_CRTCx_CFG_REG */
  30. #define CFG_PIX_FMT_MASK GENMASK(2, 0)
  31. enum lsdc_pixel_format {
  32. LSDC_PF_NONE = 0,
  33. LSDC_PF_XRGB444 = 1, /* [12 bits] */
  34. LSDC_PF_XRGB555 = 2, /* [15 bits] */
  35. LSDC_PF_XRGB565 = 3, /* RGB [16 bits] */
  36. LSDC_PF_XRGB8888 = 4, /* XRGB [32 bits] */
  37. };
  38. /*
  39. * Each crtc has two set fb address registers usable, FB_REG_IN_USING bit of
  40. * LSDC_CRTCx_CFG_REG indicate which fb address register is in using by the
  41. * CRTC currently. CFG_PAGE_FLIP is used to trigger the switch, the switching
  42. * will be finished at the very next vblank. Trigger it again if you want to
  43. * switch back.
  44. *
  45. * If FB0_ADDR_REG is in using, we write the address to FB0_ADDR_REG,
  46. * if FB1_ADDR_REG is in using, we write the address to FB1_ADDR_REG.
  47. */
  48. #define CFG_PAGE_FLIP BIT(7)
  49. #define CFG_OUTPUT_ENABLE BIT(8)
  50. #define CFG_HW_CLONE BIT(9)
  51. /* Indicate witch fb addr reg is in using, currently. read only */
  52. #define FB_REG_IN_USING BIT(11)
  53. #define CFG_GAMMA_EN BIT(12)
  54. /* The DC get soft reset if this bit changed from "1" to "0", active low */
  55. #define CFG_RESET_N BIT(20)
  56. /* If this bit is set, it say that the CRTC stop working anymore, anchored. */
  57. #define CRTC_ANCHORED BIT(24)
  58. /*
  59. * The DMA step of the DC in LS7A2000/LS2K2000 is configurable,
  60. * setting those bits on ls7a1000 platform make no effect.
  61. */
  62. #define CFG_DMA_STEP_MASK GENMASK(17, 16)
  63. #define CFG_DMA_STEP_SHIFT 16
  64. enum lsdc_dma_steps {
  65. LSDC_DMA_STEP_256_BYTES = 0,
  66. LSDC_DMA_STEP_128_BYTES = 1,
  67. LSDC_DMA_STEP_64_BYTES = 2,
  68. LSDC_DMA_STEP_32_BYTES = 3,
  69. };
  70. #define CFG_VALID_BITS_MASK GENMASK(20, 0)
  71. /* For LSDC_CRTCx_HSYNC_REG */
  72. #define HSYNC_INV BIT(31)
  73. #define HSYNC_EN BIT(30)
  74. #define HSYNC_END_MASK GENMASK(28, 16)
  75. #define HSYNC_END_SHIFT 16
  76. #define HSYNC_START_MASK GENMASK(12, 0)
  77. #define HSYNC_START_SHIFT 0
  78. /* For LSDC_CRTCx_VSYNC_REG */
  79. #define VSYNC_INV BIT(31)
  80. #define VSYNC_EN BIT(30)
  81. #define VSYNC_END_MASK GENMASK(27, 16)
  82. #define VSYNC_END_SHIFT 16
  83. #define VSYNC_START_MASK GENMASK(11, 0)
  84. #define VSYNC_START_SHIFT 0
  85. /*********** CRTC0 ***********/
  86. #define LSDC_CRTC0_CFG_REG 0x1240
  87. #define LSDC_CRTC0_FB0_ADDR_LO_REG 0x1260
  88. #define LSDC_CRTC0_FB0_ADDR_HI_REG 0x15A0
  89. #define LSDC_CRTC0_STRIDE_REG 0x1280
  90. #define LSDC_CRTC0_FB_ORIGIN_REG 0x1300
  91. #define LSDC_CRTC0_HDISPLAY_REG 0x1400
  92. #define LSDC_CRTC0_HSYNC_REG 0x1420
  93. #define LSDC_CRTC0_VDISPLAY_REG 0x1480
  94. #define LSDC_CRTC0_VSYNC_REG 0x14A0
  95. #define LSDC_CRTC0_GAMMA_INDEX_REG 0x14E0
  96. #define LSDC_CRTC0_GAMMA_DATA_REG 0x1500
  97. #define LSDC_CRTC0_FB1_ADDR_LO_REG 0x1580
  98. #define LSDC_CRTC0_FB1_ADDR_HI_REG 0x15C0
  99. /*********** CRTC1 ***********/
  100. #define LSDC_CRTC1_CFG_REG 0x1250
  101. #define LSDC_CRTC1_FB0_ADDR_LO_REG 0x1270
  102. #define LSDC_CRTC1_FB0_ADDR_HI_REG 0x15B0
  103. #define LSDC_CRTC1_STRIDE_REG 0x1290
  104. #define LSDC_CRTC1_FB_ORIGIN_REG 0x1310
  105. #define LSDC_CRTC1_HDISPLAY_REG 0x1410
  106. #define LSDC_CRTC1_HSYNC_REG 0x1430
  107. #define LSDC_CRTC1_VDISPLAY_REG 0x1490
  108. #define LSDC_CRTC1_VSYNC_REG 0x14B0
  109. #define LSDC_CRTC1_GAMMA_INDEX_REG 0x14F0
  110. #define LSDC_CRTC1_GAMMA_DATA_REG 0x1510
  111. #define LSDC_CRTC1_FB1_ADDR_LO_REG 0x1590
  112. #define LSDC_CRTC1_FB1_ADDR_HI_REG 0x15D0
  113. /* For LSDC_CRTCx_DVO_CONF_REG */
  114. #define PHY_CLOCK_POL BIT(9)
  115. #define PHY_CLOCK_EN BIT(8)
  116. #define PHY_DE_POL BIT(1)
  117. #define PHY_DATA_EN BIT(0)
  118. /*********** DVO0 ***********/
  119. #define LSDC_CRTC0_DVO_CONF_REG 0x13C0
  120. /*********** DVO1 ***********/
  121. #define LSDC_CRTC1_DVO_CONF_REG 0x13D0
  122. /*
  123. * All of the DC variants has the hardware which record the scan position
  124. * of the CRTC, [31:16] : current X position, [15:0] : current Y position
  125. */
  126. #define LSDC_CRTC0_SCAN_POS_REG 0x14C0
  127. #define LSDC_CRTC1_SCAN_POS_REG 0x14D0
  128. /*
  129. * LS7A2000 has Sync Deviation register.
  130. */
  131. #define SYNC_DEVIATION_EN BIT(31)
  132. #define SYNC_DEVIATION_NUM GENMASK(12, 0)
  133. #define LSDC_CRTC0_SYNC_DEVIATION_REG 0x1B80
  134. #define LSDC_CRTC1_SYNC_DEVIATION_REG 0x1B90
  135. /*
  136. * In gross, LSDC_CRTC1_XXX_REG - LSDC_CRTC0_XXX_REG = 0x10, but not all of
  137. * the registers obey this rule, LSDC_CURSORx_XXX_REG just don't honor this.
  138. * This is the root cause we can't untangle the code by manpulating offset
  139. * of the register access simply. Our hardware engineers are lack experiance
  140. * when they design this...
  141. */
  142. #define CRTC_PIPE_OFFSET 0x10
  143. /*
  144. * There is only one hardware cursor unit in LS7A1000 and LS2K1000, let
  145. * CFG_HW_CLONE_EN bit be "1" could eliminate this embarrassment, we made
  146. * it on custom clone mode application. While LS7A2000 has two hardware
  147. * cursor unit which is good enough.
  148. */
  149. #define CURSOR_FORMAT_MASK GENMASK(1, 0)
  150. #define CURSOR_FORMAT_SHIFT 0
  151. enum lsdc_cursor_format {
  152. CURSOR_FORMAT_DISABLE = 0,
  153. CURSOR_FORMAT_MONOCHROME = 1, /* masked */
  154. CURSOR_FORMAT_ARGB8888 = 2, /* A8R8G8B8 */
  155. };
  156. /*
  157. * LS7A1000 and LS2K1000 only support 32x32, LS2K2000 and LS7A2000 support
  158. * 64x64, but it seems that setting this bit make no harms on LS7A1000, it
  159. * just don't take effects.
  160. */
  161. #define CURSOR_SIZE_SHIFT 2
  162. enum lsdc_cursor_size {
  163. CURSOR_SIZE_32X32 = 0,
  164. CURSOR_SIZE_64X64 = 1,
  165. };
  166. #define CURSOR_LOCATION_SHIFT 4
  167. enum lsdc_cursor_location {
  168. CURSOR_ON_CRTC0 = 0,
  169. CURSOR_ON_CRTC1 = 1,
  170. };
  171. #define LSDC_CURSOR0_CFG_REG 0x1520
  172. #define LSDC_CURSOR0_ADDR_LO_REG 0x1530
  173. #define LSDC_CURSOR0_ADDR_HI_REG 0x15e0
  174. #define LSDC_CURSOR0_POSITION_REG 0x1540 /* [31:16] Y, [15:0] X */
  175. #define LSDC_CURSOR0_BG_COLOR_REG 0x1550 /* background color */
  176. #define LSDC_CURSOR0_FG_COLOR_REG 0x1560 /* foreground color */
  177. #define LSDC_CURSOR1_CFG_REG 0x1670
  178. #define LSDC_CURSOR1_ADDR_LO_REG 0x1680
  179. #define LSDC_CURSOR1_ADDR_HI_REG 0x16e0
  180. #define LSDC_CURSOR1_POSITION_REG 0x1690 /* [31:16] Y, [15:0] X */
  181. #define LSDC_CURSOR1_BG_COLOR_REG 0x16A0 /* background color */
  182. #define LSDC_CURSOR1_FG_COLOR_REG 0x16B0 /* foreground color */
  183. /*
  184. * DC Interrupt Control Register, 32bit, Address Offset: 1570
  185. *
  186. * Bits 15:0 inidicate the interrupt status
  187. * Bits 31:16 control enable interrupts corresponding to bit 15:0 or not
  188. * Write 1 to enable, write 0 to disable
  189. *
  190. * RF: Read Finished
  191. * IDBU: Internal Data Buffer Underflow
  192. * IDBFU: Internal Data Buffer Fatal Underflow
  193. * CBRF: Cursor Buffer Read Finished Flag, no use.
  194. * FBRF0: CRTC-0 reading from its framebuffer finished.
  195. * FBRF1: CRTC-1 reading from its framebuffer finished.
  196. *
  197. * +-------+--------------------------+-------+--------+--------+-------+
  198. * | 31:27 | 26:16 | 15:11 | 10 | 9 | 8 |
  199. * +-------+--------------------------+-------+--------+--------+-------+
  200. * | N/A | Interrupt Enable Control | N/A | IDBFU0 | IDBFU1 | IDBU0 |
  201. * +-------+--------------------------+-------+--------+--------+-------+
  202. *
  203. * +-------+-------+-------+------+--------+--------+--------+--------+
  204. * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
  205. * +-------+-------+-------+------+--------+--------+--------+--------+
  206. * | IDBU1 | FBRF0 | FBRF1 | CRRF | HSYNC0 | VSYNC0 | HSYNC1 | VSYNC1 |
  207. * +-------+-------+-------+------+--------+--------+--------+--------+
  208. *
  209. * unfortunately, CRTC0's interrupt is mess with CRTC1's interrupt in one
  210. * register again.
  211. */
  212. #define LSDC_INT_REG 0x1570
  213. #define INT_CRTC0_VSYNC BIT(2)
  214. #define INT_CRTC0_HSYNC BIT(3)
  215. #define INT_CRTC0_RF BIT(6)
  216. #define INT_CRTC0_IDBU BIT(8)
  217. #define INT_CRTC0_IDBFU BIT(10)
  218. #define INT_CRTC1_VSYNC BIT(0)
  219. #define INT_CRTC1_HSYNC BIT(1)
  220. #define INT_CRTC1_RF BIT(5)
  221. #define INT_CRTC1_IDBU BIT(7)
  222. #define INT_CRTC1_IDBFU BIT(9)
  223. #define INT_CRTC0_VSYNC_EN BIT(18)
  224. #define INT_CRTC0_HSYNC_EN BIT(19)
  225. #define INT_CRTC0_RF_EN BIT(22)
  226. #define INT_CRTC0_IDBU_EN BIT(24)
  227. #define INT_CRTC0_IDBFU_EN BIT(26)
  228. #define INT_CRTC1_VSYNC_EN BIT(16)
  229. #define INT_CRTC1_HSYNC_EN BIT(17)
  230. #define INT_CRTC1_RF_EN BIT(21)
  231. #define INT_CRTC1_IDBU_EN BIT(23)
  232. #define INT_CRTC1_IDBFU_EN BIT(25)
  233. #define INT_STATUS_MASK GENMASK(15, 0)
  234. /*
  235. * LS7A1000/LS7A2000 have 4 gpios which are used to emulated I2C.
  236. * They are under control of the LS7A_DC_GPIO_DAT_REG and LS7A_DC_GPIO_DIR_REG
  237. * register, Those GPIOs has no relationship whth the GPIO hardware on the
  238. * bridge chip itself. Those offsets are relative to DC register base address
  239. *
  240. * LS2k1000 don't have those registers, they use hardware i2c or general GPIO
  241. * emulated i2c from linux i2c subsystem.
  242. *
  243. * GPIO data register, address offset: 0x1650
  244. * +---------------+-----------+-----------+
  245. * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
  246. * +---------------+-----------+-----------+
  247. * | | DVO1 | DVO0 |
  248. * + N/A +-----------+-----------+
  249. * | | SCL | SDA | SCL | SDA |
  250. * +---------------+-----------+-----------+
  251. */
  252. #define LS7A_DC_GPIO_DAT_REG 0x1650
  253. /*
  254. * GPIO Input/Output direction control register, address offset: 0x1660
  255. */
  256. #define LS7A_DC_GPIO_DIR_REG 0x1660
  257. /*
  258. * LS7A2000 has two built-in HDMI Encoder and one VGA encoder
  259. */
  260. /*
  261. * Number of continuous packets may be present
  262. * in HDMI hblank and vblank zone, should >= 48
  263. */
  264. #define LSDC_HDMI0_ZONE_REG 0x1700
  265. #define LSDC_HDMI1_ZONE_REG 0x1710
  266. #define HDMI_H_ZONE_IDLE_SHIFT 0
  267. #define HDMI_V_ZONE_IDLE_SHIFT 16
  268. /* HDMI Iterface Control Reg */
  269. #define HDMI_INTERFACE_EN BIT(0)
  270. #define HDMI_PACKET_EN BIT(1)
  271. #define HDMI_AUDIO_EN BIT(2)
  272. /*
  273. * Preamble:
  274. * Immediately preceding each video data period or data island period is the
  275. * preamble. This is a sequence of eight identical control characters that
  276. * indicate whether the upcoming data period is a video data period or is a
  277. * data island. The values of CTL0, CTL1, CTL2, and CTL3 indicate the type of
  278. * data period that follows.
  279. */
  280. #define HDMI_VIDEO_PREAMBLE_MASK GENMASK(7, 4)
  281. #define HDMI_VIDEO_PREAMBLE_SHIFT 4
  282. /* 1: hw i2c, 0: gpio emu i2c, shouldn't put in LSDC_HDMIx_INTF_CTRL_REG */
  283. #define HW_I2C_EN BIT(8)
  284. #define HDMI_CTL_PERIOD_MODE BIT(9)
  285. #define LSDC_HDMI0_INTF_CTRL_REG 0x1720
  286. #define LSDC_HDMI1_INTF_CTRL_REG 0x1730
  287. #define HDMI_PHY_EN BIT(0)
  288. #define HDMI_PHY_RESET_N BIT(1)
  289. #define HDMI_PHY_TERM_L_EN BIT(8)
  290. #define HDMI_PHY_TERM_H_EN BIT(9)
  291. #define HDMI_PHY_TERM_DET_EN BIT(10)
  292. #define HDMI_PHY_TERM_STATUS BIT(11)
  293. #define LSDC_HDMI0_PHY_CTRL_REG 0x1800
  294. #define LSDC_HDMI1_PHY_CTRL_REG 0x1810
  295. /* High level duration need > 1us */
  296. #define HDMI_PLL_ENABLE BIT(0)
  297. #define HDMI_PLL_LOCKED BIT(16)
  298. /* Bypass the software configured values, using default source from somewhere */
  299. #define HDMI_PLL_BYPASS BIT(17)
  300. #define HDMI_PLL_IDF_SHIFT 1
  301. #define HDMI_PLL_IDF_MASK GENMASK(5, 1)
  302. #define HDMI_PLL_LF_SHIFT 6
  303. #define HDMI_PLL_LF_MASK GENMASK(12, 6)
  304. #define HDMI_PLL_ODF_SHIFT 13
  305. #define HDMI_PLL_ODF_MASK GENMASK(15, 13)
  306. #define LSDC_HDMI0_PHY_PLL_REG 0x1820
  307. #define LSDC_HDMI1_PHY_PLL_REG 0x1830
  308. /* LS7A2000/LS2K2000 has hpd status reg, while the two hdmi's status
  309. * located at the one register again.
  310. */
  311. #define LSDC_HDMI_HPD_STATUS_REG 0x1BA0
  312. #define HDMI0_HPD_FLAG BIT(0)
  313. #define HDMI1_HPD_FLAG BIT(1)
  314. #define LSDC_HDMI0_PHY_CAL_REG 0x18C0
  315. #define LSDC_HDMI1_PHY_CAL_REG 0x18D0
  316. /* AVI InfoFrame */
  317. #define LSDC_HDMI0_AVI_CONTENT0 0x18E0
  318. #define LSDC_HDMI1_AVI_CONTENT0 0x18D0
  319. #define LSDC_HDMI0_AVI_CONTENT1 0x1900
  320. #define LSDC_HDMI1_AVI_CONTENT1 0x1910
  321. #define LSDC_HDMI0_AVI_CONTENT2 0x1920
  322. #define LSDC_HDMI1_AVI_CONTENT2 0x1930
  323. #define LSDC_HDMI0_AVI_CONTENT3 0x1940
  324. #define LSDC_HDMI1_AVI_CONTENT3 0x1950
  325. /* 1: enable avi infoframe packet, 0: disable avi infoframe packet */
  326. #define AVI_PKT_ENABLE BIT(0)
  327. /* 1: send one every two frame, 0: send one each frame */
  328. #define AVI_PKT_SEND_FREQ BIT(1)
  329. /*
  330. * 1: write 1 to flush avi reg content0 ~ content3 to the packet to be send,
  331. * The hardware will clear this bit automatically.
  332. */
  333. #define AVI_PKT_UPDATE BIT(2)
  334. #define LSDC_HDMI0_AVI_INFO_CRTL_REG 0x1960
  335. #define LSDC_HDMI1_AVI_INFO_CRTL_REG 0x1970
  336. /*
  337. * LS7A2000 has the hardware which count the number of vblank generated
  338. */
  339. #define LSDC_CRTC0_VSYNC_COUNTER_REG 0x1A00
  340. #define LSDC_CRTC1_VSYNC_COUNTER_REG 0x1A10
  341. /*
  342. * LS7A2000 has the audio hardware associate with the HDMI encoder.
  343. */
  344. #define LSDC_HDMI0_AUDIO_PLL_LO_REG 0x1A20
  345. #define LSDC_HDMI1_AUDIO_PLL_LO_REG 0x1A30
  346. #define LSDC_HDMI0_AUDIO_PLL_HI_REG 0x1A40
  347. #define LSDC_HDMI1_AUDIO_PLL_HI_REG 0x1A50
  348. #endif