1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright 2010 Matt Turner.
4 * Copyright 2012 Red Hat
6 * Authors: Matthew Garrett
10 #ifndef __MGAG200_DRV_H__
11 #define __MGAG200_DRV_H__
13 #include <linux/i2c-algo-bit.h>
14 #include <linux/i2c.h>
16 #include <video/vga.h>
18 #include <drm/drm_encoder.h>
19 #include <drm/drm_fb_helper.h>
20 #include <drm/drm_gem.h>
21 #include <drm/drm_gem_vram_helper.h>
22 #include <drm/drm_vram_mm_helper.h>
24 #include "mgag200_reg.h"
26 #define DRIVER_AUTHOR "Matthew Garrett"
28 #define DRIVER_NAME "mgag200"
29 #define DRIVER_DESC "MGA G200 SE"
30 #define DRIVER_DATE "20110418"
32 #define DRIVER_MAJOR 1
33 #define DRIVER_MINOR 0
34 #define DRIVER_PATCHLEVEL 0
36 #define MGAG200FB_CONN_LIMIT 1
38 #define RREG8(reg) ioread8(((void __iomem *)mdev->rmmio) + (reg))
39 #define WREG8(reg, v) iowrite8(v, ((void __iomem *)mdev->rmmio) + (reg))
40 #define RREG32(reg) ioread32(((void __iomem *)mdev->rmmio) + (reg))
41 #define WREG32(reg, v) iowrite32(v, ((void __iomem *)mdev->rmmio) + (reg))
43 #define ATTR_INDEX 0x1fc0
44 #define ATTR_DATA 0x1fc1
46 #define WREG_ATTR(reg, v) \
49 WREG8(ATTR_INDEX, reg); \
50 WREG8(ATTR_DATA, v); \
53 #define WREG_SEQ(reg, v) \
55 WREG8(MGAREG_SEQ_INDEX, reg); \
56 WREG8(MGAREG_SEQ_DATA, v); \
59 #define WREG_CRT(reg, v) \
61 WREG8(MGAREG_CRTC_INDEX, reg); \
62 WREG8(MGAREG_CRTC_DATA, v); \
66 #define WREG_ECRT(reg, v) \
68 WREG8(MGAREG_CRTCEXT_INDEX, reg); \
69 WREG8(MGAREG_CRTCEXT_DATA, v); \
72 #define GFX_INDEX 0x1fce
73 #define GFX_DATA 0x1fcf
75 #define WREG_GFX(reg, v) \
77 WREG8(GFX_INDEX, reg); \
81 #define DAC_INDEX 0x3c00
82 #define DAC_DATA 0x3c0a
84 #define WREG_DAC(reg, v) \
86 WREG8(DAC_INDEX, reg); \
90 #define MGA_MISC_OUT 0x1fc2
91 #define MGA_MISC_IN 0x1fcc
93 #define MGAG200_MAX_FB_HEIGHT 4096
94 #define MGAG200_MAX_FB_WIDTH 4096
96 #define MATROX_DPMS_CLEARED (-1)
98 #define to_mga_crtc(x) container_of(x, struct mga_crtc, base)
99 #define to_mga_encoder(x) container_of(x, struct mga_encoder, base)
100 #define to_mga_connector(x) container_of(x, struct mga_connector, base)
103 struct drm_fb_helper helper; /* must be first */
106 int x1, y1, x2, y2; /* dirty rect */
107 spinlock_t dirty_lock;
111 struct drm_crtc base;
112 u8 lut_r[256], lut_g[256], lut_b[256];
117 struct mga_mode_info {
118 bool mode_config_initialized;
119 struct mga_crtc *crtc;
123 struct drm_encoder base;
128 struct mga_i2c_chan {
129 struct i2c_adapter adapter;
130 struct drm_device *dev;
131 struct i2c_algo_bit_data bit;
135 struct mga_connector {
136 struct drm_connector base;
137 struct mga_i2c_chan *i2c;
142 We have to have 2 buffers for the cursor to avoid occasional
143 corruption while switching cursor icons.
144 If either of these is NULL, then don't do hardware cursors, and
145 fall back to software.
147 struct drm_gem_vram_object *pixels_1;
148 struct drm_gem_vram_object *pixels_2;
149 /* The currently displayed icon, this points to one of pixels_1, or pixels_2 */
150 struct drm_gem_vram_object *pixels_current;
154 resource_size_t vram_size;
155 resource_size_t vram_base;
156 resource_size_t vram_window;
170 #define IS_G200_SE(mdev) (mdev->type == G200_SE_A || mdev->type == G200_SE_B)
173 struct drm_device *dev;
176 resource_size_t rmmio_base;
177 resource_size_t rmmio_size;
181 struct mga_mode_info mode_info;
183 struct mga_fbdev *mfbdev;
184 struct mga_cursor cursor;
190 struct drm_display_mode mode;
196 /* SE model number stored in reg 0x1e24 */
201 int mgag200_modeset_init(struct mga_device *mdev);
202 void mgag200_modeset_fini(struct mga_device *mdev);
205 int mgag200_fbdev_init(struct mga_device *mdev);
206 void mgag200_fbdev_fini(struct mga_device *mdev);
209 int mgag200_driver_load(struct drm_device *dev, unsigned long flags);
210 void mgag200_driver_unload(struct drm_device *dev);
211 int mgag200_gem_create(struct drm_device *dev,
212 u32 size, bool iskernel,
213 struct drm_gem_object **obj);
214 int mgag200_dumb_create(struct drm_file *file,
215 struct drm_device *dev,
216 struct drm_mode_create_dumb *args);
219 struct mga_i2c_chan *mgag200_i2c_create(struct drm_device *dev);
220 void mgag200_i2c_destroy(struct mga_i2c_chan *i2c);
222 int mgag200_mm_init(struct mga_device *mdev);
223 void mgag200_mm_fini(struct mga_device *mdev);
224 int mgag200_mmap(struct file *filp, struct vm_area_struct *vma);
226 int mga_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
227 uint32_t handle, uint32_t width, uint32_t height);
228 int mga_crtc_cursor_move(struct drm_crtc *crtc, int x, int y);
230 #endif /* __MGAG200_DRV_H__ */