mgag200_drv.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright 2010 Matt Turner.
  4. * Copyright 2012 Red Hat
  5. *
  6. * Authors: Matthew Garrett
  7. * Matt Turner
  8. * Dave Airlie
  9. */
  10. #ifndef __MGAG200_DRV_H__
  11. #define __MGAG200_DRV_H__
  12. #include <video/vga.h>
  13. #include <drm/drm_connector.h>
  14. #include <drm/drm_crtc.h>
  15. #include <drm/drm_encoder.h>
  16. #include <drm/drm_gem.h>
  17. #include <drm/drm_gem_shmem_helper.h>
  18. #include <drm/drm_plane.h>
  19. #include "mgag200_reg.h"
  20. #define DRIVER_AUTHOR "Matthew Garrett"
  21. #define DRIVER_NAME "mgag200"
  22. #define DRIVER_DESC "MGA G200 SE"
  23. #define DRIVER_DATE "20110418"
  24. #define DRIVER_MAJOR 1
  25. #define DRIVER_MINOR 0
  26. #define DRIVER_PATCHLEVEL 0
  27. #define RREG8(reg) ioread8(((void __iomem *)mdev->rmmio) + (reg))
  28. #define WREG8(reg, v) iowrite8(v, ((void __iomem *)mdev->rmmio) + (reg))
  29. #define RREG32(reg) ioread32(((void __iomem *)mdev->rmmio) + (reg))
  30. #define WREG32(reg, v) iowrite32(v, ((void __iomem *)mdev->rmmio) + (reg))
  31. #define MGA_BIOS_OFFSET 0x7ffc
  32. #define ATTR_INDEX 0x1fc0
  33. #define ATTR_DATA 0x1fc1
  34. #define WREG_MISC(v) \
  35. WREG8(MGA_MISC_OUT, v)
  36. #define RREG_MISC(v) \
  37. ((v) = RREG8(MGA_MISC_IN))
  38. #define WREG_MISC_MASKED(v, mask) \
  39. do { \
  40. u8 misc_; \
  41. u8 mask_ = (mask); \
  42. RREG_MISC(misc_); \
  43. misc_ &= ~mask_; \
  44. misc_ |= ((v) & mask_); \
  45. WREG_MISC(misc_); \
  46. } while (0)
  47. #define WREG_ATTR(reg, v) \
  48. do { \
  49. RREG8(0x1fda); \
  50. WREG8(ATTR_INDEX, reg); \
  51. WREG8(ATTR_DATA, v); \
  52. } while (0) \
  53. #define RREG_SEQ(reg, v) \
  54. do { \
  55. WREG8(MGAREG_SEQ_INDEX, reg); \
  56. v = RREG8(MGAREG_SEQ_DATA); \
  57. } while (0) \
  58. #define WREG_SEQ(reg, v) \
  59. do { \
  60. WREG8(MGAREG_SEQ_INDEX, reg); \
  61. WREG8(MGAREG_SEQ_DATA, v); \
  62. } while (0) \
  63. #define RREG_CRT(reg, v) \
  64. do { \
  65. WREG8(MGAREG_CRTC_INDEX, reg); \
  66. v = RREG8(MGAREG_CRTC_DATA); \
  67. } while (0) \
  68. #define WREG_CRT(reg, v) \
  69. do { \
  70. WREG8(MGAREG_CRTC_INDEX, reg); \
  71. WREG8(MGAREG_CRTC_DATA, v); \
  72. } while (0) \
  73. #define RREG_ECRT(reg, v) \
  74. do { \
  75. WREG8(MGAREG_CRTCEXT_INDEX, reg); \
  76. v = RREG8(MGAREG_CRTCEXT_DATA); \
  77. } while (0) \
  78. #define WREG_ECRT(reg, v) \
  79. do { \
  80. WREG8(MGAREG_CRTCEXT_INDEX, reg); \
  81. WREG8(MGAREG_CRTCEXT_DATA, v); \
  82. } while (0) \
  83. #define GFX_INDEX 0x1fce
  84. #define GFX_DATA 0x1fcf
  85. #define WREG_GFX(reg, v) \
  86. do { \
  87. WREG8(GFX_INDEX, reg); \
  88. WREG8(GFX_DATA, v); \
  89. } while (0) \
  90. #define DAC_INDEX 0x3c00
  91. #define DAC_DATA 0x3c0a
  92. #define WREG_DAC(reg, v) \
  93. do { \
  94. WREG8(DAC_INDEX, reg); \
  95. WREG8(DAC_DATA, v); \
  96. } while (0) \
  97. #define MGA_MISC_OUT 0x1fc2
  98. #define MGA_MISC_IN 0x1fcc
  99. /*
  100. * TODO: This is a pretty large set of default values for all kinds of
  101. * settings. It should be split and set in the various DRM helpers,
  102. * such as the CRTC reset or atomic_enable helpers. The PLL values
  103. * probably belong to each model's PLL code.
  104. */
  105. #define MGAG200_DAC_DEFAULT(xvrefctrl, xpixclkctrl, xmiscctrl, xsyspllm, xsysplln, xsyspllp) \
  106. /* 0x00: */ 0, 0, 0, 0, 0, 0, 0x00, 0, \
  107. /* 0x08: */ 0, 0, 0, 0, 0, 0, 0, 0, \
  108. /* 0x10: */ 0, 0, 0, 0, 0, 0, 0, 0, \
  109. /* 0x18: */ (xvrefctrl), \
  110. /* 0x19: */ 0, \
  111. /* 0x1a: */ (xpixclkctrl), \
  112. /* 0x1b: */ 0xff, 0xbf, 0x20, \
  113. /* 0x1e: */ (xmiscctrl), \
  114. /* 0x1f: */ 0x20, \
  115. /* 0x20: */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  116. /* 0x28: */ 0x00, 0x00, 0x00, 0x00, \
  117. /* 0x2c: */ (xsyspllm), \
  118. /* 0x2d: */ (xsysplln), \
  119. /* 0x2e: */ (xsyspllp), \
  120. /* 0x2f: */ 0x40, \
  121. /* 0x30: */ 0x00, 0xb0, 0x00, 0xc2, 0x34, 0x14, 0x02, 0x83, \
  122. /* 0x38: */ 0x00, 0x93, 0x00, 0x77, 0x00, 0x00, 0x00, 0x3a, \
  123. /* 0x40: */ 0, 0, 0, 0, 0, 0, 0, 0, \
  124. /* 0x48: */ 0, 0, 0, 0, 0, 0, 0, 0 \
  125. #define MGAG200_LUT_SIZE 256
  126. #define MGAG200_MAX_FB_HEIGHT 4096
  127. #define MGAG200_MAX_FB_WIDTH 4096
  128. struct mga_device;
  129. /*
  130. * Stores parameters for programming the PLLs
  131. *
  132. * Fref: reference frequency (A: 25.175 Mhz, B: 28.361, C: XX Mhz)
  133. * Fo: output frequency
  134. * Fvco = Fref * (N / M)
  135. * Fo = Fvco / P
  136. *
  137. * S = [0..3]
  138. */
  139. struct mgag200_pll_values {
  140. unsigned int m;
  141. unsigned int n;
  142. unsigned int p;
  143. unsigned int s;
  144. };
  145. struct mgag200_crtc_state {
  146. struct drm_crtc_state base;
  147. /* Primary-plane format; required for modesetting and color mgmt. */
  148. const struct drm_format_info *format;
  149. struct mgag200_pll_values pixpllc;
  150. bool set_vidrst;
  151. };
  152. static inline struct mgag200_crtc_state *to_mgag200_crtc_state(struct drm_crtc_state *base)
  153. {
  154. return container_of(base, struct mgag200_crtc_state, base);
  155. }
  156. enum mga_type {
  157. G200_PCI,
  158. G200_AGP,
  159. G200_SE_A,
  160. G200_SE_B,
  161. G200_WB,
  162. G200_EV,
  163. G200_EH,
  164. G200_EH3,
  165. G200_ER,
  166. G200_EW3,
  167. };
  168. struct mgag200_device_info {
  169. u16 max_hdisplay;
  170. u16 max_vdisplay;
  171. /*
  172. * Maximum memory bandwidth (MiB/sec). Setting this to zero disables
  173. * the rsp test during mode validation.
  174. */
  175. unsigned long max_mem_bandwidth;
  176. /* Synchronize scanout with BMC */
  177. bool sync_bmc:1;
  178. struct {
  179. unsigned data_bit:3;
  180. unsigned clock_bit:3;
  181. } i2c;
  182. /*
  183. * HW does not handle 'startadd' register correctly. Always set
  184. * it's value to 0.
  185. */
  186. bool bug_no_startadd:1;
  187. };
  188. #define MGAG200_DEVICE_INFO_INIT(_max_hdisplay, _max_vdisplay, _max_mem_bandwidth, \
  189. _sync_bmc, _i2c_data_bit, _i2c_clock_bit, \
  190. _bug_no_startadd) \
  191. { \
  192. .max_hdisplay = (_max_hdisplay), \
  193. .max_vdisplay = (_max_vdisplay), \
  194. .max_mem_bandwidth = (_max_mem_bandwidth), \
  195. .sync_bmc = (_sync_bmc), \
  196. .i2c = { \
  197. .data_bit = (_i2c_data_bit), \
  198. .clock_bit = (_i2c_clock_bit), \
  199. }, \
  200. .bug_no_startadd = (_bug_no_startadd), \
  201. }
  202. struct mgag200_device_funcs {
  203. /*
  204. * Validate that the given state can be programmed into PIXPLLC. On
  205. * success, the calculated parameters should be stored in the CRTC's
  206. * state in struct @mgag200_crtc_state.pixpllc.
  207. */
  208. int (*pixpllc_atomic_check)(struct drm_crtc *crtc, struct drm_atomic_state *new_state);
  209. /*
  210. * Program PIXPLLC from the CRTC state. The parameters should have been
  211. * stored in struct @mgag200_crtc_state.pixpllc by the corresponding
  212. * implementation of @pixpllc_atomic_check.
  213. */
  214. void (*pixpllc_atomic_update)(struct drm_crtc *crtc, struct drm_atomic_state *old_state);
  215. };
  216. struct mga_device {
  217. struct drm_device base;
  218. const struct mgag200_device_info *info;
  219. const struct mgag200_device_funcs *funcs;
  220. struct resource *rmmio_res;
  221. void __iomem *rmmio;
  222. struct mutex rmmio_lock; /* Protects access to rmmio */
  223. struct resource *vram_res;
  224. void __iomem *vram;
  225. resource_size_t vram_available;
  226. struct drm_plane primary_plane;
  227. struct drm_crtc crtc;
  228. struct {
  229. struct {
  230. struct drm_encoder encoder;
  231. struct drm_connector connector;
  232. } vga;
  233. } output;
  234. };
  235. static inline struct mga_device *to_mga_device(struct drm_device *dev)
  236. {
  237. return container_of(dev, struct mga_device, base);
  238. }
  239. struct mgag200_g200_device {
  240. struct mga_device base;
  241. /* PLL constants */
  242. long ref_clk;
  243. long pclk_min;
  244. long pclk_max;
  245. };
  246. static inline struct mgag200_g200_device *to_mgag200_g200_device(struct drm_device *dev)
  247. {
  248. return container_of(to_mga_device(dev), struct mgag200_g200_device, base);
  249. }
  250. struct mgag200_g200se_device {
  251. struct mga_device base;
  252. /* SE model number stored in reg 0x1e24 */
  253. u32 unique_rev_id;
  254. };
  255. static inline struct mgag200_g200se_device *to_mgag200_g200se_device(struct drm_device *dev)
  256. {
  257. return container_of(to_mga_device(dev), struct mgag200_g200se_device, base);
  258. }
  259. /* mgag200_drv.c */
  260. int mgag200_init_pci_options(struct pci_dev *pdev, u32 option, u32 option2);
  261. resource_size_t mgag200_probe_vram(void __iomem *mem, resource_size_t size);
  262. resource_size_t mgag200_device_probe_vram(struct mga_device *mdev);
  263. int mgag200_device_preinit(struct mga_device *mdev);
  264. int mgag200_device_init(struct mga_device *mdev,
  265. const struct mgag200_device_info *info,
  266. const struct mgag200_device_funcs *funcs);
  267. /* mgag200_<device type>.c */
  268. struct mga_device *mgag200_g200_device_create(struct pci_dev *pdev, const struct drm_driver *drv);
  269. struct mga_device *mgag200_g200se_device_create(struct pci_dev *pdev, const struct drm_driver *drv,
  270. enum mga_type type);
  271. void mgag200_g200wb_init_registers(struct mga_device *mdev);
  272. void mgag200_g200wb_pixpllc_atomic_update(struct drm_crtc *crtc, struct drm_atomic_state *old_state);
  273. struct mga_device *mgag200_g200wb_device_create(struct pci_dev *pdev, const struct drm_driver *drv);
  274. struct mga_device *mgag200_g200ev_device_create(struct pci_dev *pdev, const struct drm_driver *drv);
  275. void mgag200_g200eh_init_registers(struct mga_device *mdev);
  276. void mgag200_g200eh_pixpllc_atomic_update(struct drm_crtc *crtc, struct drm_atomic_state *old_state);
  277. struct mga_device *mgag200_g200eh_device_create(struct pci_dev *pdev,
  278. const struct drm_driver *drv);
  279. struct mga_device *mgag200_g200eh3_device_create(struct pci_dev *pdev,
  280. const struct drm_driver *drv);
  281. struct mga_device *mgag200_g200er_device_create(struct pci_dev *pdev,
  282. const struct drm_driver *drv);
  283. struct mga_device *mgag200_g200ew3_device_create(struct pci_dev *pdev,
  284. const struct drm_driver *drv);
  285. /*
  286. * mgag200_mode.c
  287. */
  288. struct drm_crtc;
  289. struct drm_crtc_state;
  290. struct drm_display_mode;
  291. struct drm_plane;
  292. struct drm_atomic_state;
  293. struct drm_scanout_buffer;
  294. extern const uint32_t mgag200_primary_plane_formats[];
  295. extern const size_t mgag200_primary_plane_formats_size;
  296. extern const uint64_t mgag200_primary_plane_fmtmods[];
  297. int mgag200_primary_plane_helper_atomic_check(struct drm_plane *plane,
  298. struct drm_atomic_state *new_state);
  299. void mgag200_primary_plane_helper_atomic_update(struct drm_plane *plane,
  300. struct drm_atomic_state *old_state);
  301. void mgag200_primary_plane_helper_atomic_enable(struct drm_plane *plane,
  302. struct drm_atomic_state *state);
  303. void mgag200_primary_plane_helper_atomic_disable(struct drm_plane *plane,
  304. struct drm_atomic_state *old_state);
  305. int mgag200_primary_plane_helper_get_scanout_buffer(struct drm_plane *plane,
  306. struct drm_scanout_buffer *sb);
  307. #define MGAG200_PRIMARY_PLANE_HELPER_FUNCS \
  308. DRM_GEM_SHADOW_PLANE_HELPER_FUNCS, \
  309. .atomic_check = mgag200_primary_plane_helper_atomic_check, \
  310. .atomic_update = mgag200_primary_plane_helper_atomic_update, \
  311. .atomic_enable = mgag200_primary_plane_helper_atomic_enable, \
  312. .atomic_disable = mgag200_primary_plane_helper_atomic_disable, \
  313. .get_scanout_buffer = mgag200_primary_plane_helper_get_scanout_buffer
  314. #define MGAG200_PRIMARY_PLANE_FUNCS \
  315. .update_plane = drm_atomic_helper_update_plane, \
  316. .disable_plane = drm_atomic_helper_disable_plane, \
  317. .destroy = drm_plane_cleanup, \
  318. DRM_GEM_SHADOW_PLANE_FUNCS
  319. void mgag200_crtc_set_gamma_linear(struct mga_device *mdev, const struct drm_format_info *format);
  320. void mgag200_crtc_set_gamma(struct mga_device *mdev,
  321. const struct drm_format_info *format,
  322. struct drm_color_lut *lut);
  323. enum drm_mode_status mgag200_crtc_helper_mode_valid(struct drm_crtc *crtc,
  324. const struct drm_display_mode *mode);
  325. int mgag200_crtc_helper_atomic_check(struct drm_crtc *crtc, struct drm_atomic_state *new_state);
  326. void mgag200_crtc_helper_atomic_flush(struct drm_crtc *crtc, struct drm_atomic_state *old_state);
  327. void mgag200_crtc_helper_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *old_state);
  328. void mgag200_crtc_helper_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_state *old_state);
  329. #define MGAG200_CRTC_HELPER_FUNCS \
  330. .mode_valid = mgag200_crtc_helper_mode_valid, \
  331. .atomic_check = mgag200_crtc_helper_atomic_check, \
  332. .atomic_flush = mgag200_crtc_helper_atomic_flush, \
  333. .atomic_enable = mgag200_crtc_helper_atomic_enable, \
  334. .atomic_disable = mgag200_crtc_helper_atomic_disable
  335. void mgag200_crtc_reset(struct drm_crtc *crtc);
  336. struct drm_crtc_state *mgag200_crtc_atomic_duplicate_state(struct drm_crtc *crtc);
  337. void mgag200_crtc_atomic_destroy_state(struct drm_crtc *crtc, struct drm_crtc_state *crtc_state);
  338. #define MGAG200_CRTC_FUNCS \
  339. .reset = mgag200_crtc_reset, \
  340. .destroy = drm_crtc_cleanup, \
  341. .set_config = drm_atomic_helper_set_config, \
  342. .page_flip = drm_atomic_helper_page_flip, \
  343. .atomic_duplicate_state = mgag200_crtc_atomic_duplicate_state, \
  344. .atomic_destroy_state = mgag200_crtc_atomic_destroy_state
  345. void mgag200_set_mode_regs(struct mga_device *mdev, const struct drm_display_mode *mode,
  346. bool set_vidrst);
  347. void mgag200_set_format_regs(struct mga_device *mdev, const struct drm_format_info *format);
  348. void mgag200_enable_display(struct mga_device *mdev);
  349. void mgag200_init_registers(struct mga_device *mdev);
  350. int mgag200_mode_config_init(struct mga_device *mdev, resource_size_t vram_available);
  351. /* mgag200_vga_bmc.c */
  352. int mgag200_vga_bmc_output_init(struct mga_device *mdev);
  353. /* mgag200_vga.c */
  354. int mgag200_vga_output_init(struct mga_device *mdev);
  355. /* mgag200_bmc.c */
  356. void mgag200_bmc_stop_scanout(struct mga_device *mdev);
  357. void mgag200_bmc_start_scanout(struct mga_device *mdev);
  358. #endif /* __MGAG200_DRV_H__ */