treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / gpu / drm / mgag200 / mgag200_drv.h
blobaa32aad222c2602e782b736a9509c3d4ba92dc48
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright 2010 Matt Turner.
4 * Copyright 2012 Red Hat
6 * Authors: Matthew Garrett
7 * Matt Turner
8 * Dave Airlie
9 */
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) \
46 do { \
47 RREG8(0x1fda); \
48 WREG8(ATTR_INDEX, reg); \
49 WREG8(ATTR_DATA, v); \
50 } while (0) \
52 #define WREG_SEQ(reg, v) \
53 do { \
54 WREG8(MGAREG_SEQ_INDEX, reg); \
55 WREG8(MGAREG_SEQ_DATA, v); \
56 } while (0) \
58 #define WREG_CRT(reg, v) \
59 do { \
60 WREG8(MGAREG_CRTC_INDEX, reg); \
61 WREG8(MGAREG_CRTC_DATA, v); \
62 } while (0) \
65 #define WREG_ECRT(reg, v) \
66 do { \
67 WREG8(MGAREG_CRTCEXT_INDEX, reg); \
68 WREG8(MGAREG_CRTCEXT_DATA, v); \
69 } while (0) \
71 #define GFX_INDEX 0x1fce
72 #define GFX_DATA 0x1fcf
74 #define WREG_GFX(reg, v) \
75 do { \
76 WREG8(GFX_INDEX, reg); \
77 WREG8(GFX_DATA, v); \
78 } while (0) \
80 #define DAC_INDEX 0x3c00
81 #define DAC_DATA 0x3c0a
83 #define WREG_DAC(reg, v) \
84 do { \
85 WREG8(DAC_INDEX, reg); \
86 WREG8(DAC_DATA, v); \
87 } while (0) \
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)
101 struct mga_crtc {
102 struct drm_crtc base;
103 u8 lut_r[256], lut_g[256], lut_b[256];
104 int last_dpms;
105 bool enabled;
108 struct mga_mode_info {
109 bool mode_config_initialized;
110 struct mga_crtc *crtc;
113 struct mga_encoder {
114 struct drm_encoder base;
115 int last_dpms;
119 struct mga_i2c_chan {
120 struct i2c_adapter adapter;
121 struct drm_device *dev;
122 struct i2c_algo_bit_data bit;
123 int data, clock;
126 struct mga_connector {
127 struct drm_connector base;
128 struct mga_i2c_chan *i2c;
131 struct mga_cursor {
132 struct drm_gem_vram_object *gbo[2];
133 unsigned int next_index;
136 struct mga_mc {
137 resource_size_t vram_size;
138 resource_size_t vram_base;
139 resource_size_t vram_window;
142 enum mga_type {
143 G200_SE_A,
144 G200_SE_B,
145 G200_WB,
146 G200_EV,
147 G200_EH,
148 G200_EH3,
149 G200_ER,
150 G200_EW3,
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)
161 struct mga_device {
162 struct drm_device *dev;
163 unsigned long flags;
165 resource_size_t rmmio_base;
166 resource_size_t rmmio_size;
167 void __iomem *rmmio;
169 struct mga_mc mc;
170 struct mga_mode_info mode_info;
172 struct mga_cursor cursor;
174 size_t vram_fb_available;
176 bool suspended;
177 int num_crtc;
178 enum mga_type type;
179 int has_sdram;
180 struct drm_display_mode mode;
182 int bpp_shifts[4];
184 int fb_mtrr;
186 /* SE model number stored in reg 0x1e24 */
187 u32 unique_rev_id;
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;
202 /* mgag200_mode.c */
203 int mgag200_modeset_init(struct mga_device *mdev);
204 void mgag200_modeset_fini(struct mga_device *mdev);
206 /* mgag200_main.c */
207 int mgag200_driver_load(struct drm_device *dev, unsigned long flags);
208 void mgag200_driver_unload(struct drm_device *dev);
210 /* mgag200_i2c.c */
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__ */