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>
23 #include "mgag200_reg.h"
25 #define DRIVER_AUTHOR "Matthew Garrett"
27 #define DRIVER_NAME "mgag200"
28 #define DRIVER_DESC "MGA G200 SE"
29 #define DRIVER_DATE "20110418"
31 #define DRIVER_MAJOR 1
32 #define DRIVER_MINOR 0
33 #define DRIVER_PATCHLEVEL 0
35 #define MGAG200FB_CONN_LIMIT 1
37 #define RREG8(reg) ioread8(((void __iomem *)mdev->rmmio) + (reg))
38 #define WREG8(reg, v) iowrite8(v, ((void __iomem *)mdev->rmmio) + (reg))
39 #define RREG32(reg) ioread32(((void __iomem *)mdev->rmmio) + (reg))
40 #define WREG32(reg, v) iowrite32(v, ((void __iomem *)mdev->rmmio) + (reg))
42 #define ATTR_INDEX 0x1fc0
43 #define ATTR_DATA 0x1fc1
45 #define WREG_ATTR(reg, v) \
48 WREG8(ATTR_INDEX, reg); \
49 WREG8(ATTR_DATA, v); \
52 #define WREG_SEQ(reg, v) \
54 WREG8(MGAREG_SEQ_INDEX, reg); \
55 WREG8(MGAREG_SEQ_DATA, v); \
58 #define WREG_CRT(reg, v) \
60 WREG8(MGAREG_CRTC_INDEX, reg); \
61 WREG8(MGAREG_CRTC_DATA, v); \
65 #define WREG_ECRT(reg, v) \
67 WREG8(MGAREG_CRTCEXT_INDEX, reg); \
68 WREG8(MGAREG_CRTCEXT_DATA, v); \
71 #define GFX_INDEX 0x1fce
72 #define GFX_DATA 0x1fcf
74 #define WREG_GFX(reg, v) \
76 WREG8(GFX_INDEX, reg); \
80 #define DAC_INDEX 0x3c00
81 #define DAC_DATA 0x3c0a
83 #define WREG_DAC(reg, v) \
85 WREG8(DAC_INDEX, reg); \
89 #define MGA_MISC_OUT 0x1fc2
90 #define MGA_MISC_IN 0x1fcc
92 #define MGAG200_MAX_FB_HEIGHT 4096
93 #define MGAG200_MAX_FB_WIDTH 4096
95 #define MATROX_DPMS_CLEARED (-1)
97 #define to_mga_crtc(x) container_of(x, struct mga_crtc, base)
98 #define to_mga_encoder(x) container_of(x, struct mga_encoder, base)
99 #define to_mga_connector(x) container_of(x, struct mga_connector, base)
102 struct drm_crtc base
;
103 u8 lut_r
[256], lut_g
[256], lut_b
[256];
108 struct mga_mode_info
{
109 bool mode_config_initialized
;
110 struct mga_crtc
*crtc
;
114 struct drm_encoder base
;
119 struct mga_i2c_chan
{
120 struct i2c_adapter adapter
;
121 struct drm_device
*dev
;
122 struct i2c_algo_bit_data bit
;
126 struct mga_connector
{
127 struct drm_connector base
;
128 struct mga_i2c_chan
*i2c
;
132 struct drm_gem_vram_object
*gbo
[2];
133 unsigned int next_index
;
137 resource_size_t vram_size
;
138 resource_size_t vram_base
;
139 resource_size_t vram_window
;
153 /* HW does not handle 'startadd' field correct. */
154 #define MGAG200_FLAG_HW_BUG_NO_STARTADD (1ul << 8)
156 #define MGAG200_TYPE_MASK (0x000000ff)
157 #define MGAG200_FLAG_MASK (0x00ffff00)
159 #define IS_G200_SE(mdev) (mdev->type == G200_SE_A || mdev->type == G200_SE_B)
162 struct drm_device
*dev
;
165 resource_size_t rmmio_base
;
166 resource_size_t rmmio_size
;
170 struct mga_mode_info mode_info
;
172 struct mga_cursor cursor
;
174 size_t vram_fb_available
;
180 struct drm_display_mode mode
;
186 /* SE model number stored in reg 0x1e24 */
190 static inline enum mga_type
191 mgag200_type_from_driver_data(kernel_ulong_t driver_data
)
193 return (enum mga_type
)(driver_data
& MGAG200_TYPE_MASK
);
196 static inline unsigned long
197 mgag200_flags_from_driver_data(kernel_ulong_t driver_data
)
199 return driver_data
& MGAG200_FLAG_MASK
;
203 int mgag200_modeset_init(struct mga_device
*mdev
);
204 void mgag200_modeset_fini(struct mga_device
*mdev
);
207 int mgag200_driver_load(struct drm_device
*dev
, unsigned long flags
);
208 void mgag200_driver_unload(struct drm_device
*dev
);
211 struct mga_i2c_chan
*mgag200_i2c_create(struct drm_device
*dev
);
212 void mgag200_i2c_destroy(struct mga_i2c_chan
*i2c
);
214 int mgag200_mm_init(struct mga_device
*mdev
);
215 void mgag200_mm_fini(struct mga_device
*mdev
);
216 int mgag200_mmap(struct file
*filp
, struct vm_area_struct
*vma
);
218 int mgag200_cursor_init(struct mga_device
*mdev
);
219 void mgag200_cursor_fini(struct mga_device
*mdev
);
220 int mgag200_crtc_cursor_set(struct drm_crtc
*crtc
, struct drm_file
*file_priv
,
221 uint32_t handle
, uint32_t width
, uint32_t height
);
222 int mgag200_crtc_cursor_move(struct drm_crtc
*crtc
, int x
, int y
);
224 #endif /* __MGAG200_DRV_H__ */