| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#ifndef __AST_DRV_H__ |
| 6 |
#define __AST_DRV_H__ |
| 7 |
|
| 8 |
#include "aspeed_coreboot.h" |
| 9 |
|
| 10 |
#define PCI_CHIP_AST2000 0x2000 |
| 11 |
#define PCI_CHIP_AST2100 0x2010 |
| 12 |
#define PCI_CHIP_AST1180 0x1180 |
| 13 |
|
| 14 |
enum ast_chip { |
| 15 |
AST2000, |
| 16 |
AST2100, |
| 17 |
AST1100, |
| 18 |
AST2200, |
| 19 |
AST2150, |
| 20 |
AST2300, |
| 21 |
AST2400, |
| 22 |
AST2500, |
| 23 |
AST2600, |
| 24 |
AST1180, |
| 25 |
}; |
| 26 |
|
| 27 |
enum ast_tx_chip { |
| 28 |
AST_TX_NONE, |
| 29 |
AST_TX_SIL164, |
| 30 |
AST_TX_ITE66121, |
| 31 |
AST_TX_DP501, |
| 32 |
}; |
| 33 |
|
| 34 |
#define AST_DRAM_512Mx16 0 |
| 35 |
#define AST_DRAM_1Gx16 1 |
| 36 |
#define AST_DRAM_512Mx32 2 |
| 37 |
#define AST_DRAM_1Gx32 3 |
| 38 |
#define AST_DRAM_2Gx16 6 |
| 39 |
#define AST_DRAM_4Gx16 7 |
| 40 |
#define AST_DRAM_8Gx16 8 |
| 41 |
|
| 42 |
struct ast_fbdev; |
| 43 |
|
| 44 |
struct ast_private { |
| 45 |
struct drm_device *dev; |
| 46 |
|
| 47 |
void __iomem *regs; |
| 48 |
void __iomem *ioregs; |
| 49 |
bool io_space_uses_mmap; |
| 50 |
|
| 51 |
enum ast_chip chip; |
| 52 |
bool vga2_clone; |
| 53 |
uint32_t dram_bus_width; |
| 54 |
uint32_t dram_type; |
| 55 |
uint32_t mclk; |
| 56 |
uint32_t vram_size; |
| 57 |
|
| 58 |
struct ast_fbdev *fbdev; |
| 59 |
|
| 60 |
int fb_mtrr; |
| 61 |
|
| 62 |
struct drm_gem_object *cursor_cache; |
| 63 |
uint64_t cursor_cache_gpu_addr; |
| 64 |
|
| 65 |
int next_cursor; |
| 66 |
bool support_wide_screen; |
| 67 |
enum { |
| 68 |
ast_use_p2a, |
| 69 |
ast_use_dt, |
| 70 |
ast_use_defaults |
| 71 |
} config_mode; |
| 72 |
|
| 73 |
enum ast_tx_chip tx_chip_type; |
| 74 |
u8 dp501_maxclk; |
| 75 |
u8 *dp501_fw_addr; |
| 76 |
const struct firmware *dp501_fw; |
| 77 |
}; |
| 78 |
|
| 79 |
int ast_driver_load(struct drm_device *dev, unsigned long flags); |
| 80 |
int ast_driver_unload(struct drm_device *dev); |
| 81 |
|
| 82 |
#define AST_IO_AR_PORT_WRITE (0x40) |
| 83 |
#define AST_IO_MISC_PORT_WRITE (0x42) |
| 84 |
#define AST_IO_VGA_ENABLE_PORT (0x43) |
| 85 |
#define AST_IO_SEQ_PORT (0x44) |
| 86 |
#define AST_IO_DAC_INDEX_READ (0x47) |
| 87 |
#define AST_IO_DAC_INDEX_WRITE (0x48) |
| 88 |
#define AST_IO_DAC_DATA (0x49) |
| 89 |
#define AST_IO_GR_PORT (0x4E) |
| 90 |
#define AST_IO_CRTC_PORT (0x54) |
| 91 |
#define AST_IO_INPUT_STATUS1_READ (0x5A) |
| 92 |
#define AST_IO_MISC_PORT_READ (0x4C) |
| 93 |
|
| 94 |
#define AST_IO_MM_OFFSET (0x380) |
| 95 |
|
| 96 |
#define __ast_read(x) \ |
| 97 |
static inline u##x ast_read##x(struct ast_private *ast, u32 reg) { \ |
| 98 |
u##x val = 0;\ |
| 99 |
val = ioread##x(ast->regs + reg); \ |
| 100 |
return val;\ |
| 101 |
} |
| 102 |
|
| 103 |
__ast_read(8); |
| 104 |
__ast_read(16); |
| 105 |
__ast_read(32) |
| 106 |
|
| 107 |
#define __ast_io_read(x) \ |
| 108 |
static inline u##x ast_io_read##x(struct ast_private *ast, u32 reg) { \ |
| 109 |
u##x val = 0;\ |
| 110 |
if (ast->io_space_uses_mmap) \ |
| 111 |
val = ioread##x(ast->regs + reg); \ |
| 112 |
else \ |
| 113 |
val = ioread_cbio##x(ast->ioregs + reg); \ |
| 114 |
return val;\ |
| 115 |
} |
| 116 |
|
| 117 |
__ast_io_read(8); |
| 118 |
__ast_io_read(16); |
| 119 |
__ast_io_read(32); |
| 120 |
|
| 121 |
#define __ast_write(x) \ |
| 122 |
static inline void ast_write##x(struct ast_private *ast, u32 reg, u##x val) {\ |
| 123 |
iowrite##x(val, ast->regs + reg);\ |
| 124 |
} |
| 125 |
|
| 126 |
__ast_write(8); |
| 127 |
__ast_write(16); |
| 128 |
__ast_write(32); |
| 129 |
|
| 130 |
#define __ast_io_write(x) \ |
| 131 |
static inline void ast_io_write##x(struct ast_private *ast, u32 reg, u##x val) {\ |
| 132 |
if (ast->io_space_uses_mmap) \ |
| 133 |
iowrite##x(val, ast->regs + reg);\ |
| 134 |
else \ |
| 135 |
iowrite_cbio##x(val, ast->ioregs + reg);\ |
| 136 |
} |
| 137 |
|
| 138 |
__ast_io_write(8); |
| 139 |
__ast_io_write(16); |
| 140 |
#undef __ast_io_write |
| 141 |
|
| 142 |
static inline void ast_set_index_reg(struct ast_private *ast, |
| 143 |
uint32_t base, uint8_t index, |
| 144 |
uint8_t val) |
| 145 |
{ |
| 146 |
ast_io_write16(ast, base, ((u16)val << 8) | index); |
| 147 |
} |
| 148 |
|
| 149 |
void ast_set_index_reg_mask(struct ast_private *ast, |
| 150 |
uint32_t base, uint8_t index, |
| 151 |
uint8_t mask, uint8_t val); |
| 152 |
uint8_t ast_get_index_reg(struct ast_private *ast, |
| 153 |
uint32_t base, uint8_t index); |
| 154 |
uint8_t ast_get_index_reg_mask(struct ast_private *ast, |
| 155 |
uint32_t base, uint8_t index, uint8_t mask); |
| 156 |
|
| 157 |
static inline void ast_open_key(struct ast_private *ast) |
| 158 |
{ |
| 159 |
ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x80, 0xA8); |
| 160 |
} |
| 161 |
|
| 162 |
#define AST_VIDMEM_SIZE_8M 0x00800000 |
| 163 |
#define AST_VIDMEM_SIZE_16M 0x01000000 |
| 164 |
#define AST_VIDMEM_SIZE_32M 0x02000000 |
| 165 |
#define AST_VIDMEM_SIZE_64M 0x04000000 |
| 166 |
#define AST_VIDMEM_SIZE_128M 0x08000000 |
| 167 |
|
| 168 |
#define AST_VIDMEM_DEFAULT_SIZE AST_VIDMEM_SIZE_8M |
| 169 |
|
| 170 |
#define AST_MAX_HWC_WIDTH 64 |
| 171 |
#define AST_MAX_HWC_HEIGHT 64 |
| 172 |
|
| 173 |
#define AST_HWC_SIZE (AST_MAX_HWC_WIDTH*AST_MAX_HWC_HEIGHT*2) |
| 174 |
#define AST_HWC_SIGNATURE_SIZE 32 |
| 175 |
|
| 176 |
#define EINVAL 22 |
| 177 |
|
| 178 |
#define AST_DEFAULT_HWC_NUM 2 |
| 179 |
|
| 180 |
#define AST_HWC_SIGNATURE_CHECKSUM 0x00 |
| 181 |
#define AST_HWC_SIGNATURE_SizeX 0x04 |
| 182 |
#define AST_HWC_SIGNATURE_SizeY 0x08 |
| 183 |
#define AST_HWC_SIGNATURE_X 0x0C |
| 184 |
#define AST_HWC_SIGNATURE_Y 0x10 |
| 185 |
#define AST_HWC_SIGNATURE_HOTSPOTX 0x14 |
| 186 |
#define AST_HWC_SIGNATURE_HOTSPOTY 0x18 |
| 187 |
|
| 188 |
|
| 189 |
struct ast_vbios_stdtable { |
| 190 |
u8 misc; |
| 191 |
u8 seq[4]; |
| 192 |
u8 crtc[25]; |
| 193 |
u8 ar[20]; |
| 194 |
u8 gr[9]; |
| 195 |
}; |
| 196 |
|
| 197 |
struct ast_vbios_enhtable { |
| 198 |
u32 ht; |
| 199 |
u32 hde; |
| 200 |
u32 hfp; |
| 201 |
u32 hsync; |
| 202 |
u32 vt; |
| 203 |
u32 vde; |
| 204 |
u32 vfp; |
| 205 |
u32 vsync; |
| 206 |
u32 dclk_index; |
| 207 |
u32 flags; |
| 208 |
u32 refresh_rate; |
| 209 |
u32 refresh_rate_index; |
| 210 |
u32 mode_id; |
| 211 |
}; |
| 212 |
|
| 213 |
struct ast_vbios_dclk_info { |
| 214 |
u8 param1; |
| 215 |
u8 param2; |
| 216 |
u8 param3; |
| 217 |
}; |
| 218 |
|
| 219 |
struct ast_vbios_mode_info { |
| 220 |
const struct ast_vbios_stdtable *std_table; |
| 221 |
const struct ast_vbios_enhtable *enh_table; |
| 222 |
}; |
| 223 |
|
| 224 |
#define DRM_MODE_FLAG_NVSYNC 1 |
| 225 |
#define DRM_MODE_FLAG_PVSYNC 2 |
| 226 |
#define DRM_MODE_FLAG_NHSYNC 4 |
| 227 |
#define DRM_MODE_FLAG_PHSYNC 8 |
| 228 |
|
| 229 |
struct drm_display_mode { |
| 230 |
|
| 231 |
u16 vrefresh; |
| 232 |
u32 clock; |
| 233 |
u16 hdisplay; |
| 234 |
u16 vdisplay; |
| 235 |
u32 flags; |
| 236 |
|
| 237 |
|
| 238 |
u16 crtc_hdisplay; |
| 239 |
u16 crtc_htotal; |
| 240 |
u16 crtc_hblank_start; |
| 241 |
u16 crtc_hblank_end; |
| 242 |
u16 crtc_hsync_start; |
| 243 |
u16 crtc_hsync_end; |
| 244 |
u16 crtc_vtotal; |
| 245 |
u16 crtc_vsync_start; |
| 246 |
u16 crtc_vsync_end; |
| 247 |
u16 crtc_vdisplay; |
| 248 |
u16 crtc_vblank_start; |
| 249 |
u16 crtc_vblank_end; |
| 250 |
}; |
| 251 |
|
| 252 |
struct drm_format { |
| 253 |
u32 cpp[1]; |
| 254 |
}; |
| 255 |
|
| 256 |
struct drm_framebuffer { |
| 257 |
u32 pitches[1]; |
| 258 |
struct drm_format *format; |
| 259 |
u32 mmio_addr; |
| 260 |
}; |
| 261 |
|
| 262 |
struct drm_primary { |
| 263 |
struct drm_framebuffer *fb; |
| 264 |
}; |
| 265 |
|
| 266 |
struct drm_crtc { |
| 267 |
struct drm_device *dev; |
| 268 |
struct drm_primary *primary; |
| 269 |
struct drm_display_mode mode; |
| 270 |
}; |
| 271 |
|
| 272 |
struct drm_connector { |
| 273 |
struct drm_device *dev; |
| 274 |
}; |
| 275 |
|
| 276 |
enum drm_mode_status { |
| 277 |
MODE_NOMODE, |
| 278 |
MODE_OK |
| 279 |
}; |
| 280 |
|
| 281 |
#define AST_MM_ALIGN_SHIFT 4 |
| 282 |
#define AST_MM_ALIGN_MASK ((1 << AST_MM_ALIGN_SHIFT) - 1) |
| 283 |
|
| 284 |
#define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT) |
| 285 |
|
| 286 |
|
| 287 |
void ast_enable_vga(struct drm_device *dev); |
| 288 |
void ast_enable_mmio(struct drm_device *dev); |
| 289 |
bool ast_is_vga_enabled(struct drm_device *dev); |
| 290 |
void ast_post_gpu(struct drm_device *dev); |
| 291 |
u32 ast_mindwm(struct ast_private *ast, u32 r); |
| 292 |
void ast_moutdwm(struct ast_private *ast, u32 r, u32 v); |
| 293 |
|
| 294 |
void ast_set_dp501_video_output(struct drm_device *dev, u8 mode); |
| 295 |
bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 size); |
| 296 |
bool ast_dp501_read_edid(struct drm_device *dev, u8 *ediddata); |
| 297 |
u8 ast_get_dp501_max_clk(struct drm_device *dev); |
| 298 |
void ast_init_3rdtx(struct drm_device *dev); |
| 299 |
void ast_release_firmware(struct drm_device *dev); |
| 300 |
|
| 301 |
|
| 302 |
int ast_crtc_mode_set(struct drm_crtc *crtc, |
| 303 |
struct drm_display_mode *mode, |
| 304 |
struct drm_display_mode *adjusted_mode); |
| 305 |
enum drm_mode_status ast_mode_valid(struct drm_connector *connector, |
| 306 |
const unsigned int hdisplay, |
| 307 |
const unsigned int vdisplay); |
| 308 |
void ast_hide_cursor(struct drm_crtc *crtc); |
| 309 |
void ast_set_offset_reg(struct drm_crtc *crtc); |
| 310 |
void ast_set_start_address_crt1(struct ast_private *ast, u32 offset); |
| 311 |
|
| 312 |
|
| 313 |
int ast_driver_framebuffer_init(struct drm_device *dev, int flags); |
| 314 |
int ast_crtc_do_set_base(struct drm_crtc *crtc); |
| 315 |
|
| 316 |
|
| 317 |
int ast_software_i2c_read(struct ast_private *ast_priv, uint8_t edid[128]); |
| 318 |
|
| 319 |
#endif |