| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <device/pci_def.h> |
| 7 |
|
| 8 |
#include "ast_drv.h" |
| 9 |
#include "ast_dram_tables.h" |
| 10 |
|
| 11 |
void ast_set_index_reg_mask(struct ast_private *ast, |
| 12 |
uint32_t base, uint8_t index, |
| 13 |
uint8_t mask, uint8_t val) |
| 14 |
{ |
| 15 |
u8 tmp; |
| 16 |
ast_io_write8(ast, base, index); |
| 17 |
tmp = (ast_io_read8(ast, base + 1) & mask) | val; |
| 18 |
ast_set_index_reg(ast, base, index, tmp); |
| 19 |
} |
| 20 |
|
| 21 |
uint8_t ast_get_index_reg(struct ast_private *ast, |
| 22 |
uint32_t base, uint8_t index) |
| 23 |
{ |
| 24 |
uint8_t ret; |
| 25 |
ast_io_write8(ast, base, index); |
| 26 |
ret = ast_io_read8(ast, base + 1); |
| 27 |
return ret; |
| 28 |
} |
| 29 |
|
| 30 |
uint8_t ast_get_index_reg_mask(struct ast_private *ast, |
| 31 |
uint32_t base, uint8_t index, uint8_t mask) |
| 32 |
{ |
| 33 |
uint8_t ret; |
| 34 |
ast_io_write8(ast, base, index); |
| 35 |
ret = ast_io_read8(ast, base + 1) & mask; |
| 36 |
return ret; |
| 37 |
} |
| 38 |
|
| 39 |
static void ast_detect_config_mode(struct drm_device *dev, u32 *scu_rev) |
| 40 |
{ |
| 41 |
struct ast_private *ast = dev->dev_private; |
| 42 |
uint32_t data, jregd0, jregd1; |
| 43 |
|
| 44 |
|
| 45 |
ast->config_mode = ast_use_defaults; |
| 46 |
*scu_rev = 0xffffffff; |
| 47 |
|
| 48 |
|
| 49 |
if (dev->pdev->device != PCI_CHIP_AST2000) |
| 50 |
return; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
jregd0 = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff); |
| 58 |
jregd1 = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd1, 0xff); |
| 59 |
if (!(jregd0 & 0x80) || !(jregd1 & 0x10)) { |
| 60 |
|
| 61 |
data = ast_read32(ast, 0xf004); |
| 62 |
if (data != 0xFFFFFFFF) { |
| 63 |
|
| 64 |
ast->config_mode = ast_use_p2a; |
| 65 |
|
| 66 |
DRM_INFO("Using P2A bridge for configuration\n"); |
| 67 |
|
| 68 |
|
| 69 |
ast_write32(ast, 0xf004, 0x1e6e0000); |
| 70 |
ast_write32(ast, 0xf000, 0x1); |
| 71 |
*scu_rev = ast_read32(ast, 0x1207c); |
| 72 |
return; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
DRM_INFO("P2A bridge disabled, using default configuration\n"); |
| 78 |
} |
| 79 |
|
| 80 |
static int ast_detect_chip(struct drm_device *dev, bool *need_post) |
| 81 |
{ |
| 82 |
struct ast_private *ast = dev->dev_private; |
| 83 |
uint32_t jreg, scu_rev; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
if (!ast_is_vga_enabled(dev)) { |
| 92 |
ast_enable_vga(dev); |
| 93 |
DRM_INFO("VGA not enabled on entry, requesting chip POST\n"); |
| 94 |
*need_post = true; |
| 95 |
} else |
| 96 |
*need_post = false; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
ast_enable_mmio(dev); |
| 101 |
ast_open_key(ast); |
| 102 |
|
| 103 |
|
| 104 |
ast_detect_config_mode(dev, &scu_rev); |
| 105 |
|
| 106 |
|
| 107 |
if (dev->pdev->device == PCI_CHIP_AST1180) { |
| 108 |
ast->chip = AST1100; |
| 109 |
DRM_INFO("AST 1180 detected\n"); |
| 110 |
} else { |
| 111 |
uint32_t data; |
| 112 |
pci_read_config_dword(ast->dev->pdev, 0x08, &data); |
| 113 |
uint8_t revision = data & 0xff; |
| 114 |
if (revision >= 0x50) { |
| 115 |
ast->chip = AST2600; |
| 116 |
DRM_INFO("AST 2600 detected\n"); |
| 117 |
} else if (revision >= 0x40) { |
| 118 |
ast->chip = AST2500; |
| 119 |
DRM_INFO("AST 2500 detected\n"); |
| 120 |
} else if (revision >= 0x30) { |
| 121 |
ast->chip = AST2400; |
| 122 |
DRM_INFO("AST 2400 detected\n"); |
| 123 |
} else if (revision >= 0x20) { |
| 124 |
ast->chip = AST2300; |
| 125 |
DRM_INFO("AST 2300 detected\n"); |
| 126 |
} else if (revision >= 0x10) { |
| 127 |
switch (scu_rev & 0x0300) { |
| 128 |
case 0x0200: |
| 129 |
ast->chip = AST1100; |
| 130 |
DRM_INFO("AST 1100 detected\n"); |
| 131 |
break; |
| 132 |
case 0x0100: |
| 133 |
ast->chip = AST2200; |
| 134 |
DRM_INFO("AST 2200 detected\n"); |
| 135 |
break; |
| 136 |
case 0x0000: |
| 137 |
ast->chip = AST2150; |
| 138 |
DRM_INFO("AST 2150 detected\n"); |
| 139 |
break; |
| 140 |
default: |
| 141 |
ast->chip = AST2100; |
| 142 |
DRM_INFO("AST 2100 detected\n"); |
| 143 |
break; |
| 144 |
} |
| 145 |
ast->vga2_clone = false; |
| 146 |
} else { |
| 147 |
ast->chip = AST2000; |
| 148 |
DRM_INFO("AST 2000 detected\n"); |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
switch (ast->chip) { |
| 154 |
case AST1180: |
| 155 |
ast->support_wide_screen = true; |
| 156 |
break; |
| 157 |
case AST2000: |
| 158 |
ast->support_wide_screen = false; |
| 159 |
break; |
| 160 |
default: |
| 161 |
jreg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff); |
| 162 |
if (!(jreg & 0x80)) |
| 163 |
ast->support_wide_screen = true; |
| 164 |
else if (jreg & 0x01) |
| 165 |
ast->support_wide_screen = true; |
| 166 |
else { |
| 167 |
ast->support_wide_screen = false; |
| 168 |
if (ast->chip == AST2300 && |
| 169 |
(scu_rev & 0x300) == 0x0) |
| 170 |
ast->support_wide_screen = true; |
| 171 |
if (ast->chip == AST2400 && |
| 172 |
(scu_rev & 0x300) == 0x100) |
| 173 |
ast->support_wide_screen = true; |
| 174 |
if (ast->chip == AST2500 && |
| 175 |
scu_rev == 0x100) |
| 176 |
ast->support_wide_screen = true; |
| 177 |
if (ast->chip == AST2600) |
| 178 |
ast->support_wide_screen = true; |
| 179 |
} |
| 180 |
break; |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
ast->tx_chip_type = AST_TX_NONE; |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
if (!*need_post) { |
| 195 |
jreg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xa3, 0xff); |
| 196 |
if (jreg & 0x80) |
| 197 |
ast->tx_chip_type = AST_TX_SIL164; |
| 198 |
} |
| 199 |
|
| 200 |
if ((ast->chip == AST2300) || (ast->chip == AST2400) || (ast->chip == AST2500)) { |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
jreg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd1, 0xff); |
| 207 |
switch (jreg) { |
| 208 |
case 0x04: |
| 209 |
ast->tx_chip_type = AST_TX_SIL164; |
| 210 |
break; |
| 211 |
case 0x08: |
| 212 |
ast->dp501_fw_addr = kzalloc(32*1024, GFP_KERNEL); |
| 213 |
if (ast->dp501_fw_addr) { |
| 214 |
|
| 215 |
if (ast_backup_fw(dev, ast->dp501_fw_addr, 32*1024)) { |
| 216 |
kfree(ast->dp501_fw_addr); |
| 217 |
ast->dp501_fw_addr = NULL; |
| 218 |
} |
| 219 |
} |
| 220 |
__fallthrough; |
| 221 |
case 0x0c: |
| 222 |
ast->tx_chip_type = AST_TX_DP501; |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
switch (ast->tx_chip_type) { |
| 228 |
case AST_TX_SIL164: |
| 229 |
DRM_INFO("Using Sil164 TMDS transmitter\n"); |
| 230 |
break; |
| 231 |
case AST_TX_DP501: |
| 232 |
DRM_INFO("Using DP501 DisplayPort transmitter\n"); |
| 233 |
break; |
| 234 |
default: |
| 235 |
DRM_INFO("Analog VGA only\n"); |
| 236 |
} |
| 237 |
return 0; |
| 238 |
} |
| 239 |
|
| 240 |
static int ast_get_dram_info(struct drm_device *dev) |
| 241 |
{ |
| 242 |
struct ast_private *ast = dev->dev_private; |
| 243 |
uint32_t mcr_cfg, mcr_scu_mpll, mcr_scu_strap; |
| 244 |
uint32_t denum, num, div, ref_pll, dsel; |
| 245 |
|
| 246 |
switch (ast->config_mode) { |
| 247 |
case ast_use_dt: |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
mcr_cfg = 0x00000577; |
| 253 |
mcr_scu_mpll = 0x000050C0; |
| 254 |
mcr_scu_strap = 0; |
| 255 |
break; |
| 256 |
case ast_use_p2a: |
| 257 |
ast_write32(ast, 0xf004, 0x1e6e0000); |
| 258 |
ast_write32(ast, 0xf000, 0x1); |
| 259 |
mcr_cfg = ast_read32(ast, 0x10004); |
| 260 |
mcr_scu_mpll = ast_read32(ast, 0x10120); |
| 261 |
mcr_scu_strap = ast_read32(ast, 0x10170); |
| 262 |
break; |
| 263 |
case ast_use_defaults: |
| 264 |
default: |
| 265 |
ast->dram_bus_width = 16; |
| 266 |
ast->dram_type = AST_DRAM_1Gx16; |
| 267 |
if (ast->chip == AST2500) |
| 268 |
ast->mclk = 800; |
| 269 |
else |
| 270 |
ast->mclk = 396; |
| 271 |
return 0; |
| 272 |
} |
| 273 |
|
| 274 |
if (mcr_cfg & 0x40) |
| 275 |
ast->dram_bus_width = 16; |
| 276 |
else |
| 277 |
ast->dram_bus_width = 32; |
| 278 |
|
| 279 |
if (ast->chip == AST2500) { |
| 280 |
switch (mcr_cfg & 0x03) { |
| 281 |
case 0: |
| 282 |
ast->dram_type = AST_DRAM_1Gx16; |
| 283 |
break; |
| 284 |
default: |
| 285 |
case 1: |
| 286 |
ast->dram_type = AST_DRAM_2Gx16; |
| 287 |
break; |
| 288 |
case 2: |
| 289 |
ast->dram_type = AST_DRAM_4Gx16; |
| 290 |
break; |
| 291 |
case 3: |
| 292 |
ast->dram_type = AST_DRAM_8Gx16; |
| 293 |
break; |
| 294 |
} |
| 295 |
} else if (ast->chip == AST2300 || ast->chip == AST2400) { |
| 296 |
switch (mcr_cfg & 0x03) { |
| 297 |
case 0: |
| 298 |
ast->dram_type = AST_DRAM_512Mx16; |
| 299 |
break; |
| 300 |
default: |
| 301 |
case 1: |
| 302 |
ast->dram_type = AST_DRAM_1Gx16; |
| 303 |
break; |
| 304 |
case 2: |
| 305 |
ast->dram_type = AST_DRAM_2Gx16; |
| 306 |
break; |
| 307 |
case 3: |
| 308 |
ast->dram_type = AST_DRAM_4Gx16; |
| 309 |
break; |
| 310 |
} |
| 311 |
} else { |
| 312 |
switch (mcr_cfg & 0x0c) { |
| 313 |
case 0: |
| 314 |
case 4: |
| 315 |
ast->dram_type = AST_DRAM_512Mx16; |
| 316 |
break; |
| 317 |
case 8: |
| 318 |
if (mcr_cfg & 0x40) |
| 319 |
ast->dram_type = AST_DRAM_1Gx16; |
| 320 |
else |
| 321 |
ast->dram_type = AST_DRAM_512Mx32; |
| 322 |
break; |
| 323 |
case 0xc: |
| 324 |
ast->dram_type = AST_DRAM_1Gx32; |
| 325 |
break; |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
if (mcr_scu_strap & 0x2000) |
| 330 |
ref_pll = 14318; |
| 331 |
else |
| 332 |
ref_pll = 12000; |
| 333 |
|
| 334 |
denum = mcr_scu_mpll & 0x1f; |
| 335 |
num = (mcr_scu_mpll & 0x3fe0) >> 5; |
| 336 |
dsel = (mcr_scu_mpll & 0xc000) >> 14; |
| 337 |
switch (dsel) { |
| 338 |
case 3: |
| 339 |
div = 0x4; |
| 340 |
break; |
| 341 |
case 2: |
| 342 |
case 1: |
| 343 |
div = 0x2; |
| 344 |
break; |
| 345 |
default: |
| 346 |
div = 0x1; |
| 347 |
break; |
| 348 |
} |
| 349 |
ast->mclk = ref_pll * (num + 2) / (denum + 2) * (div * 1000); |
| 350 |
return 0; |
| 351 |
} |
| 352 |
|
| 353 |
static u32 ast_get_vram_info(struct drm_device *dev) |
| 354 |
{ |
| 355 |
struct ast_private *ast = dev->dev_private; |
| 356 |
u8 jreg; |
| 357 |
u32 vram_size; |
| 358 |
ast_open_key(ast); |
| 359 |
|
| 360 |
vram_size = AST_VIDMEM_DEFAULT_SIZE; |
| 361 |
jreg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xaa, 0xff); |
| 362 |
switch (jreg & 3) { |
| 363 |
case 0: vram_size = AST_VIDMEM_SIZE_8M; break; |
| 364 |
case 1: vram_size = AST_VIDMEM_SIZE_16M; break; |
| 365 |
case 2: vram_size = AST_VIDMEM_SIZE_32M; break; |
| 366 |
case 3: vram_size = AST_VIDMEM_SIZE_64M; break; |
| 367 |
} |
| 368 |
|
| 369 |
jreg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x99, 0xff); |
| 370 |
switch (jreg & 0x03) { |
| 371 |
case 1: |
| 372 |
vram_size -= 0x100000; |
| 373 |
break; |
| 374 |
case 2: |
| 375 |
vram_size -= 0x200000; |
| 376 |
break; |
| 377 |
case 3: |
| 378 |
vram_size -= 0x400000; |
| 379 |
break; |
| 380 |
} |
| 381 |
|
| 382 |
return vram_size; |
| 383 |
} |
| 384 |
|
| 385 |
int ast_driver_load(struct drm_device *dev, unsigned long flags) |
| 386 |
{ |
| 387 |
struct ast_private *ast; |
| 388 |
bool need_post; |
| 389 |
int ret = 0; |
| 390 |
struct resource *res; |
| 391 |
|
| 392 |
ast = kzalloc(sizeof(struct ast_private), GFP_KERNEL); |
| 393 |
if (!ast) |
| 394 |
return -ENOMEM; |
| 395 |
|
| 396 |
dev->dev_private = ast; |
| 397 |
ast->dev = dev; |
| 398 |
|
| 399 |
|
| 400 |
res = probe_resource(dev->pdev, PCI_BASE_ADDRESS_1); |
| 401 |
if (!res) { |
| 402 |
dev_err(dev->pdev, "BAR1 resource not found.\n"); |
| 403 |
ret = -EIO; |
| 404 |
goto out_free; |
| 405 |
} |
| 406 |
ast->regs = res2mmio(res, 0, 0); |
| 407 |
if (!ast->regs) { |
| 408 |
ret = -EIO; |
| 409 |
goto out_free; |
| 410 |
} |
| 411 |
|
| 412 |
|
| 413 |
ast->io_space_uses_mmap = false; |
| 414 |
res = probe_resource(dev->pdev, PCI_BASE_ADDRESS_2); |
| 415 |
if (!res) |
| 416 |
dev_err(dev->pdev, "BAR2 resource not found.\n"); |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
if (!res || !(res->flags & IORESOURCE_IO)) { |
| 424 |
DRM_INFO("platform has no IO space, trying MMIO\n"); |
| 425 |
ast->ioregs = ast->regs + AST_IO_MM_OFFSET; |
| 426 |
ast->io_space_uses_mmap = true; |
| 427 |
} |
| 428 |
|
| 429 |
|
| 430 |
if (!ast->ioregs) { |
| 431 |
ast->ioregs = res2mmio(res, 0, 0); |
| 432 |
if (!ast->ioregs) { |
| 433 |
ret = -EIO; |
| 434 |
goto out_free; |
| 435 |
} |
| 436 |
} |
| 437 |
|
| 438 |
ast_detect_chip(dev, &need_post); |
| 439 |
|
| 440 |
if (need_post) |
| 441 |
ast_post_gpu(dev); |
| 442 |
|
| 443 |
if (ast->chip != AST1180) { |
| 444 |
ret = ast_get_dram_info(dev); |
| 445 |
if (ret) |
| 446 |
goto out_free; |
| 447 |
ast->vram_size = ast_get_vram_info(dev); |
| 448 |
DRM_INFO("dram MCLK=%u MHz type=%d bus_width=%d size=%08x\n", |
| 449 |
ast->mclk, ast->dram_type, |
| 450 |
ast->dram_bus_width, ast->vram_size); |
| 451 |
} |
| 452 |
|
| 453 |
return 0; |
| 454 |
out_free: |
| 455 |
kfree(ast); |
| 456 |
dev->dev_private = NULL; |
| 457 |
return ret; |
| 458 |
} |