1 /* SPDX-License-Identifier: MIT */
3 * Authors: Dave Airlie <airlied@redhat.com>
8 #include "aspeed_coreboot.h"
10 #define PCI_CHIP_AST2000 0x2000
11 #define PCI_CHIP_AST2100 0x2010
12 #define PCI_CHIP_AST1180 0x1180
33 #define AST_DRAM_512Mx16 0
34 #define AST_DRAM_1Gx16 1
35 #define AST_DRAM_512Mx32 2
36 #define AST_DRAM_1Gx32 3
37 #define AST_DRAM_2Gx16 6
38 #define AST_DRAM_4Gx16 7
39 #define AST_DRAM_8Gx16 8
44 struct drm_device
*dev
;
48 bool io_space_uses_mmap
;
52 uint32_t dram_bus_width
;
57 struct ast_fbdev
*fbdev
;
61 struct drm_gem_object
*cursor_cache
;
62 uint64_t cursor_cache_gpu_addr
;
65 bool support_wide_screen
;
72 enum ast_tx_chip tx_chip_type
;
75 const struct firmware
*dp501_fw
; /* dp501 fw */
78 int ast_driver_load(struct drm_device
*dev
, unsigned long flags
);
79 int ast_driver_unload(struct drm_device
*dev
);
81 #define AST_IO_AR_PORT_WRITE (0x40)
82 #define AST_IO_MISC_PORT_WRITE (0x42)
83 #define AST_IO_VGA_ENABLE_PORT (0x43)
84 #define AST_IO_SEQ_PORT (0x44)
85 #define AST_IO_DAC_INDEX_READ (0x47)
86 #define AST_IO_DAC_INDEX_WRITE (0x48)
87 #define AST_IO_DAC_DATA (0x49)
88 #define AST_IO_GR_PORT (0x4E)
89 #define AST_IO_CRTC_PORT (0x54)
90 #define AST_IO_INPUT_STATUS1_READ (0x5A)
91 #define AST_IO_MISC_PORT_READ (0x4C)
93 #define AST_IO_MM_OFFSET (0x380)
95 #define __ast_read(x) \
96 static inline u##x ast_read##x(struct ast_private *ast, u32 reg) { \
98 val = ioread##x(ast->regs + reg); \
106 #define __ast_io_read(x) \
107 static inline u##x ast_io_read##x(struct ast_private *ast, u32 reg) { \
109 if (ast->io_space_uses_mmap) \
110 val = ioread##x(ast->regs + reg); \
112 val = ioread_cbio##x(ast->ioregs + reg); \
120 #define __ast_write(x) \
121 static inline void ast_write##x(struct ast_private *ast, u32 reg, u##x val) {\
122 iowrite##x(val, ast->regs + reg);\
129 #define __ast_io_write(x) \
130 static inline void ast_io_write##x(struct ast_private *ast, u32 reg, u##x val) {\
131 if (ast->io_space_uses_mmap) \
132 iowrite##x(val, ast->regs + reg);\
134 iowrite_cbio##x(val, ast->ioregs + reg);\
139 #undef __ast_io_write
141 static inline void ast_set_index_reg(struct ast_private
*ast
,
142 uint32_t base
, uint8_t index
,
145 ast_io_write16(ast
, base
, ((u16
)val
<< 8) | index
);
148 void ast_set_index_reg_mask(struct ast_private
*ast
,
149 uint32_t base
, uint8_t index
,
150 uint8_t mask
, uint8_t val
);
151 uint8_t ast_get_index_reg(struct ast_private
*ast
,
152 uint32_t base
, uint8_t index
);
153 uint8_t ast_get_index_reg_mask(struct ast_private
*ast
,
154 uint32_t base
, uint8_t index
, uint8_t mask
);
156 static inline void ast_open_key(struct ast_private
*ast
)
158 ast_set_index_reg(ast
, AST_IO_CRTC_PORT
, 0x80, 0xA8);
161 #define AST_VIDMEM_SIZE_8M 0x00800000
162 #define AST_VIDMEM_SIZE_16M 0x01000000
163 #define AST_VIDMEM_SIZE_32M 0x02000000
164 #define AST_VIDMEM_SIZE_64M 0x04000000
165 #define AST_VIDMEM_SIZE_128M 0x08000000
167 #define AST_VIDMEM_DEFAULT_SIZE AST_VIDMEM_SIZE_8M
169 #define AST_MAX_HWC_WIDTH 64
170 #define AST_MAX_HWC_HEIGHT 64
172 #define AST_HWC_SIZE (AST_MAX_HWC_WIDTH*AST_MAX_HWC_HEIGHT*2)
173 #define AST_HWC_SIGNATURE_SIZE 32
175 #define EINVAL 22 /* Invalid argument */
177 #define AST_DEFAULT_HWC_NUM 2
178 /* define for signature structure */
179 #define AST_HWC_SIGNATURE_CHECKSUM 0x00
180 #define AST_HWC_SIGNATURE_SizeX 0x04
181 #define AST_HWC_SIGNATURE_SizeY 0x08
182 #define AST_HWC_SIGNATURE_X 0x0C
183 #define AST_HWC_SIGNATURE_Y 0x10
184 #define AST_HWC_SIGNATURE_HOTSPOTX 0x14
185 #define AST_HWC_SIGNATURE_HOTSPOTY 0x18
187 /* ast_mode.c stuff */
188 struct ast_vbios_stdtable
{
196 struct ast_vbios_enhtable
{
208 u32 refresh_rate_index
;
212 struct ast_vbios_dclk_info
{
218 struct ast_vbios_mode_info
{
219 const struct ast_vbios_stdtable
*std_table
;
220 const struct ast_vbios_enhtable
*enh_table
;
223 #define DRM_MODE_FLAG_NVSYNC 1
224 #define DRM_MODE_FLAG_PVSYNC 2
225 #define DRM_MODE_FLAG_NHSYNC 4
226 #define DRM_MODE_FLAG_PHSYNC 8
228 struct drm_display_mode
{
229 /* Proposed mode values */
230 u16 vrefresh
; /* in Hz */
236 /* Actual mode we give to hw */
239 u16 crtc_hblank_start
;
241 u16 crtc_hsync_start
;
244 u16 crtc_vsync_start
;
247 u16 crtc_vblank_start
;
252 u32 cpp
[1]; /* Colors per pixel */
255 struct drm_framebuffer
{
257 struct drm_format
*format
;
262 struct drm_framebuffer
*fb
;
266 struct drm_device
*dev
;
267 struct drm_primary
*primary
;
268 struct drm_display_mode mode
;
271 struct drm_connector
{
272 struct drm_device
*dev
;
275 enum drm_mode_status
{
280 #define AST_MM_ALIGN_SHIFT 4
281 #define AST_MM_ALIGN_MASK ((1 << AST_MM_ALIGN_SHIFT) - 1)
283 #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
286 void ast_enable_vga(struct drm_device
*dev
);
287 void ast_enable_mmio(struct drm_device
*dev
);
288 bool ast_is_vga_enabled(struct drm_device
*dev
);
289 void ast_post_gpu(struct drm_device
*dev
);
290 u32
ast_mindwm(struct ast_private
*ast
, u32 r
);
291 void ast_moutdwm(struct ast_private
*ast
, u32 r
, u32 v
);
293 void ast_set_dp501_video_output(struct drm_device
*dev
, u8 mode
);
294 bool ast_backup_fw(struct drm_device
*dev
, u8
*addr
, u32 size
);
295 bool ast_dp501_read_edid(struct drm_device
*dev
, u8
*ediddata
);
296 u8
ast_get_dp501_max_clk(struct drm_device
*dev
);
297 void ast_init_3rdtx(struct drm_device
*dev
);
298 void ast_release_firmware(struct drm_device
*dev
);
301 int ast_crtc_mode_set(struct drm_crtc
*crtc
,
302 struct drm_display_mode
*mode
,
303 struct drm_display_mode
*adjusted_mode
);
304 enum drm_mode_status
ast_mode_valid(struct drm_connector
*connector
,
305 const unsigned int hdisplay
,
306 const unsigned int vdisplay
);
307 void ast_hide_cursor(struct drm_crtc
*crtc
);
308 void ast_set_offset_reg(struct drm_crtc
*crtc
);
309 void ast_set_start_address_crt1(struct ast_private
*ast
, u32 offset
);
311 /* ast_mode_corebootfb */
312 int ast_driver_framebuffer_init(struct drm_device
*dev
, int flags
);
313 int ast_crtc_do_set_base(struct drm_crtc
*crtc
);
316 int ast_software_i2c_read(struct ast_private
*ast_priv
, uint8_t edid
[128]);