| .. | .. |
|---|
| 28 | 28 | #ifndef __AST_DRV_H__ |
|---|
| 29 | 29 | #define __AST_DRV_H__ |
|---|
| 30 | 30 | |
|---|
| 31 | | -#include <drm/drm_encoder.h> |
|---|
| 32 | | -#include <drm/drm_fb_helper.h> |
|---|
| 33 | | - |
|---|
| 34 | | -#include <drm/ttm/ttm_bo_api.h> |
|---|
| 35 | | -#include <drm/ttm/ttm_bo_driver.h> |
|---|
| 36 | | -#include <drm/ttm/ttm_placement.h> |
|---|
| 37 | | -#include <drm/ttm/ttm_memory.h> |
|---|
| 38 | | -#include <drm/ttm/ttm_module.h> |
|---|
| 39 | | - |
|---|
| 40 | | -#include <drm/drm_gem.h> |
|---|
| 41 | | - |
|---|
| 31 | +#include <linux/types.h> |
|---|
| 32 | +#include <linux/io.h> |
|---|
| 42 | 33 | #include <linux/i2c.h> |
|---|
| 43 | 34 | #include <linux/i2c-algo-bit.h> |
|---|
| 35 | + |
|---|
| 36 | +#include <drm/drm_connector.h> |
|---|
| 37 | +#include <drm/drm_crtc.h> |
|---|
| 38 | +#include <drm/drm_encoder.h> |
|---|
| 39 | +#include <drm/drm_mode.h> |
|---|
| 40 | +#include <drm/drm_framebuffer.h> |
|---|
| 41 | +#include <drm/drm_fb_helper.h> |
|---|
| 44 | 42 | |
|---|
| 45 | 43 | #define DRIVER_AUTHOR "Dave Airlie" |
|---|
| 46 | 44 | |
|---|
| .. | .. |
|---|
| 54 | 52 | |
|---|
| 55 | 53 | #define PCI_CHIP_AST2000 0x2000 |
|---|
| 56 | 54 | #define PCI_CHIP_AST2100 0x2010 |
|---|
| 57 | | -#define PCI_CHIP_AST1180 0x1180 |
|---|
| 58 | 55 | |
|---|
| 59 | 56 | |
|---|
| 60 | 57 | enum ast_chip { |
|---|
| .. | .. |
|---|
| 66 | 63 | AST2300, |
|---|
| 67 | 64 | AST2400, |
|---|
| 68 | 65 | AST2500, |
|---|
| 69 | | - AST1180, |
|---|
| 70 | 66 | }; |
|---|
| 71 | 67 | |
|---|
| 72 | 68 | enum ast_tx_chip { |
|---|
| .. | .. |
|---|
| 84 | 80 | #define AST_DRAM_4Gx16 7 |
|---|
| 85 | 81 | #define AST_DRAM_8Gx16 8 |
|---|
| 86 | 82 | |
|---|
| 87 | | -struct ast_fbdev; |
|---|
| 83 | + |
|---|
| 84 | +#define AST_MAX_HWC_WIDTH 64 |
|---|
| 85 | +#define AST_MAX_HWC_HEIGHT 64 |
|---|
| 86 | + |
|---|
| 87 | +#define AST_HWC_SIZE (AST_MAX_HWC_WIDTH * AST_MAX_HWC_HEIGHT * 2) |
|---|
| 88 | +#define AST_HWC_SIGNATURE_SIZE 32 |
|---|
| 89 | + |
|---|
| 90 | +#define AST_DEFAULT_HWC_NUM 2 |
|---|
| 91 | + |
|---|
| 92 | +/* define for signature structure */ |
|---|
| 93 | +#define AST_HWC_SIGNATURE_CHECKSUM 0x00 |
|---|
| 94 | +#define AST_HWC_SIGNATURE_SizeX 0x04 |
|---|
| 95 | +#define AST_HWC_SIGNATURE_SizeY 0x08 |
|---|
| 96 | +#define AST_HWC_SIGNATURE_X 0x0C |
|---|
| 97 | +#define AST_HWC_SIGNATURE_Y 0x10 |
|---|
| 98 | +#define AST_HWC_SIGNATURE_HOTSPOTX 0x14 |
|---|
| 99 | +#define AST_HWC_SIGNATURE_HOTSPOTY 0x18 |
|---|
| 100 | + |
|---|
| 101 | +struct ast_i2c_chan { |
|---|
| 102 | + struct i2c_adapter adapter; |
|---|
| 103 | + struct drm_device *dev; |
|---|
| 104 | + struct i2c_algo_bit_data bit; |
|---|
| 105 | +}; |
|---|
| 106 | + |
|---|
| 107 | +struct ast_connector { |
|---|
| 108 | + struct drm_connector base; |
|---|
| 109 | + struct ast_i2c_chan *i2c; |
|---|
| 110 | +}; |
|---|
| 111 | + |
|---|
| 112 | +static inline struct ast_connector * |
|---|
| 113 | +to_ast_connector(struct drm_connector *connector) |
|---|
| 114 | +{ |
|---|
| 115 | + return container_of(connector, struct ast_connector, base); |
|---|
| 116 | +} |
|---|
| 88 | 117 | |
|---|
| 89 | 118 | struct ast_private { |
|---|
| 90 | | - struct drm_device *dev; |
|---|
| 119 | + struct drm_device base; |
|---|
| 91 | 120 | |
|---|
| 92 | 121 | void __iomem *regs; |
|---|
| 93 | 122 | void __iomem *ioregs; |
|---|
| 123 | + void __iomem *dp501_fw_buf; |
|---|
| 94 | 124 | |
|---|
| 95 | 125 | enum ast_chip chip; |
|---|
| 96 | 126 | bool vga2_clone; |
|---|
| 97 | 127 | uint32_t dram_bus_width; |
|---|
| 98 | 128 | uint32_t dram_type; |
|---|
| 99 | 129 | uint32_t mclk; |
|---|
| 100 | | - uint32_t vram_size; |
|---|
| 101 | | - |
|---|
| 102 | | - struct ast_fbdev *fbdev; |
|---|
| 103 | 130 | |
|---|
| 104 | 131 | int fb_mtrr; |
|---|
| 105 | 132 | |
|---|
| 106 | 133 | struct { |
|---|
| 107 | | - struct drm_global_reference mem_global_ref; |
|---|
| 108 | | - struct ttm_bo_global_ref bo_global_ref; |
|---|
| 109 | | - struct ttm_bo_device bdev; |
|---|
| 110 | | - } ttm; |
|---|
| 134 | + struct drm_gem_vram_object *gbo[AST_DEFAULT_HWC_NUM]; |
|---|
| 135 | + void __iomem *vaddr[AST_DEFAULT_HWC_NUM]; |
|---|
| 136 | + unsigned int next_index; |
|---|
| 137 | + } cursor; |
|---|
| 111 | 138 | |
|---|
| 112 | | - struct drm_gem_object *cursor_cache; |
|---|
| 113 | | - uint64_t cursor_cache_gpu_addr; |
|---|
| 114 | | - /* Acces to this cache is protected by the crtc->mutex of the only crtc |
|---|
| 115 | | - * we have. */ |
|---|
| 116 | | - struct ttm_bo_kmap_obj cache_kmap; |
|---|
| 117 | | - int next_cursor; |
|---|
| 139 | + struct drm_plane primary_plane; |
|---|
| 140 | + struct drm_plane cursor_plane; |
|---|
| 141 | + struct drm_crtc crtc; |
|---|
| 142 | + struct drm_encoder encoder; |
|---|
| 143 | + struct ast_connector connector; |
|---|
| 144 | + |
|---|
| 118 | 145 | bool support_wide_screen; |
|---|
| 119 | 146 | enum { |
|---|
| 120 | 147 | ast_use_p2a, |
|---|
| .. | .. |
|---|
| 128 | 155 | const struct firmware *dp501_fw; /* dp501 fw */ |
|---|
| 129 | 156 | }; |
|---|
| 130 | 157 | |
|---|
| 131 | | -int ast_driver_load(struct drm_device *dev, unsigned long flags); |
|---|
| 132 | | -void ast_driver_unload(struct drm_device *dev); |
|---|
| 158 | +static inline struct ast_private *to_ast_private(struct drm_device *dev) |
|---|
| 159 | +{ |
|---|
| 160 | + return container_of(dev, struct ast_private, base); |
|---|
| 161 | +} |
|---|
| 133 | 162 | |
|---|
| 134 | | -struct ast_gem_object; |
|---|
| 163 | +struct ast_private *ast_device_create(struct drm_driver *drv, |
|---|
| 164 | + struct pci_dev *pdev, |
|---|
| 165 | + unsigned long flags); |
|---|
| 135 | 166 | |
|---|
| 136 | 167 | #define AST_IO_AR_PORT_WRITE (0x40) |
|---|
| 137 | 168 | #define AST_IO_MISC_PORT_WRITE (0x42) |
|---|
| .. | .. |
|---|
| 146 | 177 | #define AST_IO_MISC_PORT_READ (0x4C) |
|---|
| 147 | 178 | |
|---|
| 148 | 179 | #define AST_IO_MM_OFFSET (0x380) |
|---|
| 180 | + |
|---|
| 181 | +#define AST_IO_VGAIR1_VREFRESH BIT(3) |
|---|
| 149 | 182 | |
|---|
| 150 | 183 | #define __ast_read(x) \ |
|---|
| 151 | 184 | static inline u##x ast_read##x(struct ast_private *ast, u32 reg) { \ |
|---|
| .. | .. |
|---|
| 215 | 248 | |
|---|
| 216 | 249 | #define AST_VIDMEM_DEFAULT_SIZE AST_VIDMEM_SIZE_8M |
|---|
| 217 | 250 | |
|---|
| 218 | | -#define AST_MAX_HWC_WIDTH 64 |
|---|
| 219 | | -#define AST_MAX_HWC_HEIGHT 64 |
|---|
| 220 | | - |
|---|
| 221 | | -#define AST_HWC_SIZE (AST_MAX_HWC_WIDTH*AST_MAX_HWC_HEIGHT*2) |
|---|
| 222 | | -#define AST_HWC_SIGNATURE_SIZE 32 |
|---|
| 223 | | - |
|---|
| 224 | | -#define AST_DEFAULT_HWC_NUM 2 |
|---|
| 225 | | -/* define for signature structure */ |
|---|
| 226 | | -#define AST_HWC_SIGNATURE_CHECKSUM 0x00 |
|---|
| 227 | | -#define AST_HWC_SIGNATURE_SizeX 0x04 |
|---|
| 228 | | -#define AST_HWC_SIGNATURE_SizeY 0x08 |
|---|
| 229 | | -#define AST_HWC_SIGNATURE_X 0x0C |
|---|
| 230 | | -#define AST_HWC_SIGNATURE_Y 0x10 |
|---|
| 231 | | -#define AST_HWC_SIGNATURE_HOTSPOTX 0x14 |
|---|
| 232 | | -#define AST_HWC_SIGNATURE_HOTSPOTY 0x18 |
|---|
| 233 | | - |
|---|
| 234 | | - |
|---|
| 235 | | -struct ast_i2c_chan { |
|---|
| 236 | | - struct i2c_adapter adapter; |
|---|
| 237 | | - struct drm_device *dev; |
|---|
| 238 | | - struct i2c_algo_bit_data bit; |
|---|
| 239 | | -}; |
|---|
| 240 | | - |
|---|
| 241 | | -struct ast_connector { |
|---|
| 242 | | - struct drm_connector base; |
|---|
| 243 | | - struct ast_i2c_chan *i2c; |
|---|
| 244 | | -}; |
|---|
| 245 | | - |
|---|
| 246 | | -struct ast_crtc { |
|---|
| 247 | | - struct drm_crtc base; |
|---|
| 248 | | - struct drm_gem_object *cursor_bo; |
|---|
| 249 | | - uint64_t cursor_addr; |
|---|
| 250 | | - int cursor_width, cursor_height; |
|---|
| 251 | | - u8 offset_x, offset_y; |
|---|
| 252 | | -}; |
|---|
| 253 | | - |
|---|
| 254 | | -struct ast_encoder { |
|---|
| 255 | | - struct drm_encoder base; |
|---|
| 256 | | -}; |
|---|
| 257 | | - |
|---|
| 258 | | -struct ast_framebuffer { |
|---|
| 259 | | - struct drm_framebuffer base; |
|---|
| 260 | | - struct drm_gem_object *obj; |
|---|
| 261 | | -}; |
|---|
| 262 | | - |
|---|
| 263 | | -struct ast_fbdev { |
|---|
| 264 | | - struct drm_fb_helper helper; |
|---|
| 265 | | - struct ast_framebuffer afb; |
|---|
| 266 | | - void *sysram; |
|---|
| 267 | | - int size; |
|---|
| 268 | | - struct ttm_bo_kmap_obj mapping; |
|---|
| 269 | | - int x1, y1, x2, y2; /* dirty rect */ |
|---|
| 270 | | - spinlock_t dirty_lock; |
|---|
| 271 | | -}; |
|---|
| 272 | | - |
|---|
| 273 | | -#define to_ast_crtc(x) container_of(x, struct ast_crtc, base) |
|---|
| 274 | | -#define to_ast_connector(x) container_of(x, struct ast_connector, base) |
|---|
| 275 | | -#define to_ast_encoder(x) container_of(x, struct ast_encoder, base) |
|---|
| 276 | | -#define to_ast_framebuffer(x) container_of(x, struct ast_framebuffer, base) |
|---|
| 277 | | - |
|---|
| 278 | 251 | struct ast_vbios_stdtable { |
|---|
| 279 | 252 | u8 misc; |
|---|
| 280 | 253 | u8 seq[4]; |
|---|
| .. | .. |
|---|
| 310 | 283 | const struct ast_vbios_enhtable *enh_table; |
|---|
| 311 | 284 | }; |
|---|
| 312 | 285 | |
|---|
| 313 | | -extern int ast_mode_init(struct drm_device *dev); |
|---|
| 314 | | -extern void ast_mode_fini(struct drm_device *dev); |
|---|
| 286 | +struct ast_crtc_state { |
|---|
| 287 | + struct drm_crtc_state base; |
|---|
| 315 | 288 | |
|---|
| 316 | | -int ast_framebuffer_init(struct drm_device *dev, |
|---|
| 317 | | - struct ast_framebuffer *ast_fb, |
|---|
| 318 | | - const struct drm_mode_fb_cmd2 *mode_cmd, |
|---|
| 319 | | - struct drm_gem_object *obj); |
|---|
| 289 | + /* Last known format of primary plane */ |
|---|
| 290 | + const struct drm_format_info *format; |
|---|
| 320 | 291 | |
|---|
| 321 | | -int ast_fbdev_init(struct drm_device *dev); |
|---|
| 322 | | -void ast_fbdev_fini(struct drm_device *dev); |
|---|
| 323 | | -void ast_fbdev_set_suspend(struct drm_device *dev, int state); |
|---|
| 324 | | -void ast_fbdev_set_base(struct ast_private *ast, unsigned long gpu_addr); |
|---|
| 325 | | - |
|---|
| 326 | | -struct ast_bo { |
|---|
| 327 | | - struct ttm_buffer_object bo; |
|---|
| 328 | | - struct ttm_placement placement; |
|---|
| 329 | | - struct ttm_bo_kmap_obj kmap; |
|---|
| 330 | | - struct drm_gem_object gem; |
|---|
| 331 | | - struct ttm_place placements[3]; |
|---|
| 332 | | - int pin_count; |
|---|
| 292 | + struct ast_vbios_mode_info vbios_mode_info; |
|---|
| 333 | 293 | }; |
|---|
| 334 | | -#define gem_to_ast_bo(gobj) container_of((gobj), struct ast_bo, gem) |
|---|
| 335 | 294 | |
|---|
| 336 | | -static inline struct ast_bo * |
|---|
| 337 | | -ast_bo(struct ttm_buffer_object *bo) |
|---|
| 338 | | -{ |
|---|
| 339 | | - return container_of(bo, struct ast_bo, bo); |
|---|
| 340 | | -} |
|---|
| 295 | +#define to_ast_crtc_state(state) container_of(state, struct ast_crtc_state, base) |
|---|
| 341 | 296 | |
|---|
| 342 | | - |
|---|
| 343 | | -#define to_ast_obj(x) container_of(x, struct ast_gem_object, base) |
|---|
| 297 | +int ast_mode_config_init(struct ast_private *ast); |
|---|
| 344 | 298 | |
|---|
| 345 | 299 | #define AST_MM_ALIGN_SHIFT 4 |
|---|
| 346 | 300 | #define AST_MM_ALIGN_MASK ((1 << AST_MM_ALIGN_SHIFT) - 1) |
|---|
| 347 | 301 | |
|---|
| 348 | | -extern int ast_dumb_create(struct drm_file *file, |
|---|
| 349 | | - struct drm_device *dev, |
|---|
| 350 | | - struct drm_mode_create_dumb *args); |
|---|
| 302 | +#define AST_DP501_FW_VERSION_MASK GENMASK(7, 4) |
|---|
| 303 | +#define AST_DP501_FW_VERSION_1 BIT(4) |
|---|
| 304 | +#define AST_DP501_PNP_CONNECTED BIT(1) |
|---|
| 351 | 305 | |
|---|
| 352 | | -extern void ast_gem_free_object(struct drm_gem_object *obj); |
|---|
| 353 | | -extern int ast_dumb_mmap_offset(struct drm_file *file, |
|---|
| 354 | | - struct drm_device *dev, |
|---|
| 355 | | - uint32_t handle, |
|---|
| 356 | | - uint64_t *offset); |
|---|
| 306 | +#define AST_DP501_DEFAULT_DCLK 65 |
|---|
| 357 | 307 | |
|---|
| 358 | | -#define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT) |
|---|
| 308 | +#define AST_DP501_GBL_VERSION 0xf000 |
|---|
| 309 | +#define AST_DP501_PNPMONITOR 0xf010 |
|---|
| 310 | +#define AST_DP501_LINKRATE 0xf014 |
|---|
| 311 | +#define AST_DP501_EDID_DATA 0xf020 |
|---|
| 359 | 312 | |
|---|
| 360 | 313 | int ast_mm_init(struct ast_private *ast); |
|---|
| 361 | | -void ast_mm_fini(struct ast_private *ast); |
|---|
| 362 | | - |
|---|
| 363 | | -int ast_bo_create(struct drm_device *dev, int size, int align, |
|---|
| 364 | | - uint32_t flags, struct ast_bo **pastbo); |
|---|
| 365 | | - |
|---|
| 366 | | -int ast_gem_create(struct drm_device *dev, |
|---|
| 367 | | - u32 size, bool iskernel, |
|---|
| 368 | | - struct drm_gem_object **obj); |
|---|
| 369 | | - |
|---|
| 370 | | -int ast_bo_pin(struct ast_bo *bo, u32 pl_flag, u64 *gpu_addr); |
|---|
| 371 | | -int ast_bo_unpin(struct ast_bo *bo); |
|---|
| 372 | | - |
|---|
| 373 | | -static inline int ast_bo_reserve(struct ast_bo *bo, bool no_wait) |
|---|
| 374 | | -{ |
|---|
| 375 | | - int ret; |
|---|
| 376 | | - |
|---|
| 377 | | - ret = ttm_bo_reserve(&bo->bo, true, no_wait, NULL); |
|---|
| 378 | | - if (ret) { |
|---|
| 379 | | - if (ret != -ERESTARTSYS && ret != -EBUSY) |
|---|
| 380 | | - DRM_ERROR("reserve failed %p\n", bo); |
|---|
| 381 | | - return ret; |
|---|
| 382 | | - } |
|---|
| 383 | | - return 0; |
|---|
| 384 | | -} |
|---|
| 385 | | - |
|---|
| 386 | | -static inline void ast_bo_unreserve(struct ast_bo *bo) |
|---|
| 387 | | -{ |
|---|
| 388 | | - ttm_bo_unreserve(&bo->bo); |
|---|
| 389 | | -} |
|---|
| 390 | | - |
|---|
| 391 | | -void ast_ttm_placement(struct ast_bo *bo, int domain); |
|---|
| 392 | | -int ast_bo_push_sysram(struct ast_bo *bo); |
|---|
| 393 | | -int ast_mmap(struct file *filp, struct vm_area_struct *vma); |
|---|
| 394 | 314 | |
|---|
| 395 | 315 | /* ast post */ |
|---|
| 396 | 316 | void ast_enable_vga(struct drm_device *dev); |
|---|
| .. | .. |
|---|
| 405 | 325 | bool ast_dp501_read_edid(struct drm_device *dev, u8 *ediddata); |
|---|
| 406 | 326 | u8 ast_get_dp501_max_clk(struct drm_device *dev); |
|---|
| 407 | 327 | void ast_init_3rdtx(struct drm_device *dev); |
|---|
| 408 | | -void ast_release_firmware(struct drm_device *dev); |
|---|
| 328 | + |
|---|
| 329 | +/* ast_cursor.c */ |
|---|
| 330 | +int ast_cursor_init(struct ast_private *ast); |
|---|
| 331 | +int ast_cursor_blit(struct ast_private *ast, struct drm_framebuffer *fb); |
|---|
| 332 | +void ast_cursor_page_flip(struct ast_private *ast); |
|---|
| 333 | +void ast_cursor_show(struct ast_private *ast, int x, int y, |
|---|
| 334 | + unsigned int offset_x, unsigned int offset_y); |
|---|
| 335 | +void ast_cursor_hide(struct ast_private *ast); |
|---|
| 336 | + |
|---|
| 409 | 337 | #endif |
|---|