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_shmem_helper.h>
22 #include <drm/drm_simple_kms_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 RREG8(reg) ioread8(((void __iomem *)mdev->rmmio) + (reg))
37 #define WREG8(reg, v) iowrite8(v, ((void __iomem *)mdev->rmmio) + (reg))
38 #define RREG32(reg) ioread32(((void __iomem *)mdev->rmmio) + (reg))
39 #define WREG32(reg, v) iowrite32(v, ((void __iomem *)mdev->rmmio) + (reg))
41 #define MGA_BIOS_OFFSET 0x7ffc
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 RREG_SEQ(reg, v) \
55 WREG8(MGAREG_SEQ_INDEX, reg); \
56 v = RREG8(MGAREG_SEQ_DATA); \
59 #define WREG_SEQ(reg, v) \
61 WREG8(MGAREG_SEQ_INDEX, reg); \
62 WREG8(MGAREG_SEQ_DATA, v); \
65 #define RREG_CRT(reg, v) \
67 WREG8(MGAREG_CRTC_INDEX, reg); \
68 v = RREG8(MGAREG_CRTC_DATA); \
71 #define WREG_CRT(reg, v) \
73 WREG8(MGAREG_CRTC_INDEX, reg); \
74 WREG8(MGAREG_CRTC_DATA, v); \
77 #define RREG_ECRT(reg, v) \
79 WREG8(MGAREG_CRTCEXT_INDEX, reg); \
80 v = RREG8(MGAREG_CRTCEXT_DATA); \
83 #define WREG_ECRT(reg, v) \
85 WREG8(MGAREG_CRTCEXT_INDEX, reg); \
86 WREG8(MGAREG_CRTCEXT_DATA, v); \
89 #define GFX_INDEX 0x1fce
90 #define GFX_DATA 0x1fcf
92 #define WREG_GFX(reg, v) \
94 WREG8(GFX_INDEX, reg); \
98 #define DAC_INDEX 0x3c00
99 #define DAC_DATA 0x3c0a
101 #define WREG_DAC(reg, v) \
103 WREG8(DAC_INDEX, reg); \
104 WREG8(DAC_DATA, v); \
107 #define MGA_MISC_OUT 0x1fc2
108 #define MGA_MISC_IN 0x1fcc
110 #define MGAG200_MAX_FB_HEIGHT 4096
111 #define MGAG200_MAX_FB_WIDTH 4096
113 #define to_mga_connector(x) container_of(x, struct mga_connector, base)
115 struct mga_i2c_chan
{
116 struct i2c_adapter adapter
;
117 struct drm_device
*dev
;
118 struct i2c_algo_bit_data bit
;
122 struct mga_connector
{
123 struct drm_connector base
;
124 struct mga_i2c_chan
*i2c
;
128 resource_size_t vram_size
;
129 resource_size_t vram_base
;
130 resource_size_t vram_window
;
146 /* HW does not handle 'startadd' field correct. */
147 #define MGAG200_FLAG_HW_BUG_NO_STARTADD (1ul << 8)
149 #define MGAG200_TYPE_MASK (0x000000ff)
150 #define MGAG200_FLAG_MASK (0x00ffff00)
152 #define IS_G200_SE(mdev) (mdev->type == G200_SE_A || mdev->type == G200_SE_B)
155 struct drm_device base
;
158 resource_size_t rmmio_base
;
159 resource_size_t rmmio_size
;
165 size_t vram_fb_available
;
180 /* SE model number stored in reg 0x1e24 */
186 struct mga_connector connector
;
187 struct drm_simple_display_pipe display_pipe
;
190 static inline struct mga_device
*to_mga_device(struct drm_device
*dev
)
192 return container_of(dev
, struct mga_device
, base
);
195 static inline enum mga_type
196 mgag200_type_from_driver_data(kernel_ulong_t driver_data
)
198 return (enum mga_type
)(driver_data
& MGAG200_TYPE_MASK
);
201 static inline unsigned long
202 mgag200_flags_from_driver_data(kernel_ulong_t driver_data
)
204 return driver_data
& MGAG200_FLAG_MASK
;
208 int mgag200_modeset_init(struct mga_device
*mdev
);
211 struct mga_i2c_chan
*mgag200_i2c_create(struct drm_device
*dev
);
212 void mgag200_i2c_destroy(struct mga_i2c_chan
*i2c
);
215 int mgag200_mm_init(struct mga_device
*mdev
);
217 #endif /* __MGAG200_DRV_H__ */