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 13 #include <linux/i2c-algo-bit.h> 14 #include <linux/i2c.h> 15 16 #include <video/vga.h> 17 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 23 #include "mgag200_reg.h" 24 25 #define DRIVER_AUTHOR "Matthew Garrett" 26 27 #define DRIVER_NAME "mgag200" 28 #define DRIVER_DESC "MGA G200 SE" 29 #define DRIVER_DATE "20110418" 30 31 #define DRIVER_MAJOR 1 32 #define DRIVER_MINOR 0 33 #define DRIVER_PATCHLEVEL 0 34 35 #define MGAG200FB_CONN_LIMIT 1 36 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)) 41 42 #define ATTR_INDEX 0x1fc0 43 #define ATTR_DATA 0x1fc1 44 45 #define WREG_ATTR(reg, v) \ 46 do { \ 47 RREG8(0x1fda); \ 48 WREG8(ATTR_INDEX, reg); \ 49 WREG8(ATTR_DATA, v); \ 50 } while (0) \ 51 52 #define WREG_SEQ(reg, v) \ 53 do { \ 54 WREG8(MGAREG_SEQ_INDEX, reg); \ 55 WREG8(MGAREG_SEQ_DATA, v); \ 56 } while (0) \ 57 58 #define WREG_CRT(reg, v) \ 59 do { \ 60 WREG8(MGAREG_CRTC_INDEX, reg); \ 61 WREG8(MGAREG_CRTC_DATA, v); \ 62 } while (0) \ 63 64 65 #define WREG_ECRT(reg, v) \ 66 do { \ 67 WREG8(MGAREG_CRTCEXT_INDEX, reg); \ 68 WREG8(MGAREG_CRTCEXT_DATA, v); \ 69 } while (0) \ 70 71 #define GFX_INDEX 0x1fce 72 #define GFX_DATA 0x1fcf 73 74 #define WREG_GFX(reg, v) \ 75 do { \ 76 WREG8(GFX_INDEX, reg); \ 77 WREG8(GFX_DATA, v); \ 78 } while (0) \ 79 80 #define DAC_INDEX 0x3c00 81 #define DAC_DATA 0x3c0a 82 83 #define WREG_DAC(reg, v) \ 84 do { \ 85 WREG8(DAC_INDEX, reg); \ 86 WREG8(DAC_DATA, v); \ 87 } while (0) \ 88 89 #define MGA_MISC_OUT 0x1fc2 90 #define MGA_MISC_IN 0x1fcc 91 92 #define MGAG200_MAX_FB_HEIGHT 4096 93 #define MGAG200_MAX_FB_WIDTH 4096 94 95 #define MATROX_DPMS_CLEARED (-1) 96 97 #define to_mga_crtc(x) container_of(x, struct mga_crtc, base) 98 #define to_mga_connector(x) container_of(x, struct mga_connector, base) 99 100 struct mga_crtc { 101 struct drm_crtc base; 102 u8 lut_r[256], lut_g[256], lut_b[256]; 103 int last_dpms; 104 bool enabled; 105 }; 106 107 struct mga_mode_info { 108 bool mode_config_initialized; 109 struct mga_crtc *crtc; 110 }; 111 112 struct mga_i2c_chan { 113 struct i2c_adapter adapter; 114 struct drm_device *dev; 115 struct i2c_algo_bit_data bit; 116 int data, clock; 117 }; 118 119 struct mga_connector { 120 struct drm_connector base; 121 struct mga_i2c_chan *i2c; 122 }; 123 124 struct mga_cursor { 125 struct drm_gem_vram_object *gbo[2]; 126 unsigned int next_index; 127 }; 128 129 struct mga_mc { 130 resource_size_t vram_size; 131 resource_size_t vram_base; 132 resource_size_t vram_window; 133 }; 134 135 enum mga_type { 136 G200_SE_A, 137 G200_SE_B, 138 G200_WB, 139 G200_EV, 140 G200_EH, 141 G200_EH3, 142 G200_ER, 143 G200_EW3, 144 }; 145 146 /* HW does not handle 'startadd' field correct. */ 147 #define MGAG200_FLAG_HW_BUG_NO_STARTADD (1ul << 8) 148 149 #define MGAG200_TYPE_MASK (0x000000ff) 150 #define MGAG200_FLAG_MASK (0x00ffff00) 151 152 #define IS_G200_SE(mdev) (mdev->type == G200_SE_A || mdev->type == G200_SE_B) 153 154 struct mga_device { 155 struct drm_device *dev; 156 unsigned long flags; 157 158 resource_size_t rmmio_base; 159 resource_size_t rmmio_size; 160 void __iomem *rmmio; 161 162 struct mga_mc mc; 163 struct mga_mode_info mode_info; 164 165 struct mga_cursor cursor; 166 167 size_t vram_fb_available; 168 169 bool suspended; 170 int num_crtc; 171 enum mga_type type; 172 int has_sdram; 173 struct drm_display_mode mode; 174 175 int bpp_shifts[4]; 176 177 int fb_mtrr; 178 179 /* SE model number stored in reg 0x1e24 */ 180 u32 unique_rev_id; 181 182 struct drm_encoder encoder; 183 }; 184 185 static inline enum mga_type 186 mgag200_type_from_driver_data(kernel_ulong_t driver_data) 187 { 188 return (enum mga_type)(driver_data & MGAG200_TYPE_MASK); 189 } 190 191 static inline unsigned long 192 mgag200_flags_from_driver_data(kernel_ulong_t driver_data) 193 { 194 return driver_data & MGAG200_FLAG_MASK; 195 } 196 197 /* mgag200_mode.c */ 198 int mgag200_modeset_init(struct mga_device *mdev); 199 void mgag200_modeset_fini(struct mga_device *mdev); 200 201 /* mgag200_main.c */ 202 int mgag200_driver_load(struct drm_device *dev, unsigned long flags); 203 void mgag200_driver_unload(struct drm_device *dev); 204 205 /* mgag200_i2c.c */ 206 struct mga_i2c_chan *mgag200_i2c_create(struct drm_device *dev); 207 void mgag200_i2c_destroy(struct mga_i2c_chan *i2c); 208 209 int mgag200_mm_init(struct mga_device *mdev); 210 void mgag200_mm_fini(struct mga_device *mdev); 211 int mgag200_mmap(struct file *filp, struct vm_area_struct *vma); 212 213 int mgag200_cursor_init(struct mga_device *mdev); 214 void mgag200_cursor_fini(struct mga_device *mdev); 215 int mgag200_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv, 216 uint32_t handle, uint32_t width, uint32_t height); 217 int mgag200_crtc_cursor_move(struct drm_crtc *crtc, int x, int y); 218 219 #endif /* __MGAG200_DRV_H__ */ 220