1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright 1998-2009 VIA Technologies, Inc. All Rights Reserved. 4 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved. 5 * Copyright 2009 Jonathan Corbet <corbet@lwn.net> 6 */ 7 8 /* 9 * Core code for the Via multifunction framebuffer device. 10 */ 11 #include <linux/aperture.h> 12 #include <linux/export.h> 13 #include <linux/via-core.h> 14 #include <linux/via_i2c.h> 15 #include "via-gpio.h" 16 #include "global.h" 17 18 #include <linux/module.h> 19 #include <linux/interrupt.h> 20 #include <linux/platform_device.h> 21 #include <linux/list.h> 22 #include <linux/pm.h> 23 24 /* 25 * The default port config. 26 */ 27 static struct via_port_cfg adap_configs[] = { 28 [VIA_PORT_26] = { VIA_PORT_I2C, VIA_MODE_I2C, VIASR, 0x26 }, 29 [VIA_PORT_31] = { VIA_PORT_I2C, VIA_MODE_I2C, VIASR, 0x31 }, 30 [VIA_PORT_25] = { VIA_PORT_GPIO, VIA_MODE_GPIO, VIASR, 0x25 }, 31 [VIA_PORT_2C] = { VIA_PORT_GPIO, VIA_MODE_I2C, VIASR, 0x2c }, 32 [VIA_PORT_3D] = { VIA_PORT_GPIO, VIA_MODE_GPIO, VIASR, 0x3d }, 33 { 0, 0, 0, 0 } 34 }; 35 36 /* 37 * The OLPC XO-1.5 puts the camera power and reset lines onto 38 * GPIO 2C. 39 */ 40 static struct via_port_cfg olpc_adap_configs[] = { 41 [VIA_PORT_26] = { VIA_PORT_I2C, VIA_MODE_I2C, VIASR, 0x26 }, 42 [VIA_PORT_31] = { VIA_PORT_I2C, VIA_MODE_I2C, VIASR, 0x31 }, 43 [VIA_PORT_25] = { VIA_PORT_GPIO, VIA_MODE_GPIO, VIASR, 0x25 }, 44 [VIA_PORT_2C] = { VIA_PORT_GPIO, VIA_MODE_GPIO, VIASR, 0x2c }, 45 [VIA_PORT_3D] = { VIA_PORT_GPIO, VIA_MODE_GPIO, VIASR, 0x3d }, 46 { 0, 0, 0, 0 } 47 }; 48 49 /* 50 * We currently only support one viafb device (will there ever be 51 * more than one?), so just declare it globally here. 52 */ 53 static struct viafb_dev global_dev; 54 55 56 /* 57 * Basic register access; spinlock required. 58 */ 59 static inline void viafb_mmio_write(int reg, u32 v) 60 { 61 iowrite32(v, global_dev.engine_mmio + reg); 62 } 63 64 static inline int viafb_mmio_read(int reg) 65 { 66 return ioread32(global_dev.engine_mmio + reg); 67 } 68 69 /* ---------------------------------------------------------------------- */ 70 /* 71 * Interrupt management. We have a single IRQ line for a lot of 72 * different functions, so we need to share it. The design here 73 * is that we don't want to reimplement the shared IRQ code here; 74 * we also want to avoid having contention for a single handler thread. 75 * So each subdev driver which needs interrupts just requests 76 * them directly from the kernel. We just have what's needed for 77 * overall access to the interrupt control register. 78 */ 79 80 /* 81 * Which interrupts are enabled now? 82 */ 83 static u32 viafb_enabled_ints; 84 85 static void viafb_int_init(void) 86 { 87 viafb_enabled_ints = 0; 88 89 viafb_mmio_write(VDE_INTERRUPT, 0); 90 } 91 92 /* 93 * Allow subdevs to ask for specific interrupts to be enabled. These 94 * functions must be called with reg_lock held 95 */ 96 void viafb_irq_enable(u32 mask) 97 { 98 viafb_enabled_ints |= mask; 99 viafb_mmio_write(VDE_INTERRUPT, viafb_enabled_ints | VDE_I_ENABLE); 100 } 101 EXPORT_SYMBOL_GPL(viafb_irq_enable); 102 103 void viafb_irq_disable(u32 mask) 104 { 105 viafb_enabled_ints &= ~mask; 106 if (viafb_enabled_ints == 0) 107 viafb_mmio_write(VDE_INTERRUPT, 0); /* Disable entirely */ 108 else 109 viafb_mmio_write(VDE_INTERRUPT, 110 viafb_enabled_ints | VDE_I_ENABLE); 111 } 112 EXPORT_SYMBOL_GPL(viafb_irq_disable); 113 114 /* ---------------------------------------------------------------------- */ 115 /* 116 * Currently, the camera driver is the only user of the DMA code, so we 117 * only compile it in if the camera driver is being built. Chances are, 118 * most viafb systems will not need to have this extra code for a while. 119 * As soon as another user comes long, the ifdef can be removed. 120 */ 121 #if IS_ENABLED(CONFIG_VIDEO_VIA_CAMERA) 122 /* 123 * Access to the DMA engine. This currently provides what the camera 124 * driver needs (i.e. outgoing only) but is easily expandable if need 125 * be. 126 */ 127 128 /* 129 * There are four DMA channels in the vx855. For now, we only 130 * use one of them, though. Most of the time, the DMA channel 131 * will be idle, so we keep the IRQ handler unregistered except 132 * when some subsystem has indicated an interest. 133 */ 134 static int viafb_dma_users; 135 static DECLARE_COMPLETION(viafb_dma_completion); 136 /* 137 * This mutex protects viafb_dma_users and our global interrupt 138 * registration state; it also serializes access to the DMA 139 * engine. 140 */ 141 static DEFINE_MUTEX(viafb_dma_lock); 142 143 /* 144 * The VX855 DMA descriptor (used for s/g transfers) looks 145 * like this. 146 */ 147 struct viafb_vx855_dma_descr { 148 u32 addr_low; /* Low part of phys addr */ 149 u32 addr_high; /* High 12 bits of addr */ 150 u32 fb_offset; /* Offset into FB memory */ 151 u32 seg_size; /* Size, 16-byte units */ 152 u32 tile_mode; /* "tile mode" setting */ 153 u32 next_desc_low; /* Next descriptor addr */ 154 u32 next_desc_high; 155 u32 pad; /* Fill out to 64 bytes */ 156 }; 157 158 /* 159 * Flags added to the "next descriptor low" pointers 160 */ 161 #define VIAFB_DMA_MAGIC 0x01 /* ??? Just has to be there */ 162 #define VIAFB_DMA_FINAL_SEGMENT 0x02 /* Final segment */ 163 164 /* 165 * The completion IRQ handler. 166 */ 167 static irqreturn_t viafb_dma_irq(int irq, void *data) 168 { 169 int csr; 170 irqreturn_t ret = IRQ_NONE; 171 172 spin_lock(&global_dev.reg_lock); 173 csr = viafb_mmio_read(VDMA_CSR0); 174 if (csr & VDMA_C_DONE) { 175 viafb_mmio_write(VDMA_CSR0, VDMA_C_DONE); 176 complete(&viafb_dma_completion); 177 ret = IRQ_HANDLED; 178 } 179 spin_unlock(&global_dev.reg_lock); 180 return ret; 181 } 182 183 /* 184 * Indicate a need for DMA functionality. 185 */ 186 int viafb_request_dma(void) 187 { 188 int ret = 0; 189 190 /* 191 * Only VX855 is supported currently. 192 */ 193 if (global_dev.chip_type != UNICHROME_VX855) 194 return -ENODEV; 195 /* 196 * Note the new user and set up our interrupt handler 197 * if need be. 198 */ 199 mutex_lock(&viafb_dma_lock); 200 viafb_dma_users++; 201 if (viafb_dma_users == 1) { 202 ret = request_irq(global_dev.pdev->irq, viafb_dma_irq, 203 IRQF_SHARED, "via-dma", &viafb_dma_users); 204 if (ret) 205 viafb_dma_users--; 206 else 207 viafb_irq_enable(VDE_I_DMA0TDEN); 208 } 209 mutex_unlock(&viafb_dma_lock); 210 return ret; 211 } 212 EXPORT_SYMBOL_GPL(viafb_request_dma); 213 214 void viafb_release_dma(void) 215 { 216 mutex_lock(&viafb_dma_lock); 217 viafb_dma_users--; 218 if (viafb_dma_users == 0) { 219 viafb_irq_disable(VDE_I_DMA0TDEN); 220 free_irq(global_dev.pdev->irq, &viafb_dma_users); 221 } 222 mutex_unlock(&viafb_dma_lock); 223 } 224 EXPORT_SYMBOL_GPL(viafb_release_dma); 225 226 /* 227 * Do a scatter/gather DMA copy from FB memory. You must have done 228 * a successful call to viafb_request_dma() first. 229 */ 230 int viafb_dma_copy_out_sg(unsigned int offset, struct scatterlist *sg, int nsg) 231 { 232 struct viafb_vx855_dma_descr *descr; 233 void *descrpages; 234 dma_addr_t descr_handle; 235 unsigned long flags; 236 int i; 237 int ret = 0; 238 struct scatterlist *sgentry; 239 dma_addr_t nextdesc; 240 241 /* 242 * Get a place to put the descriptors. 243 */ 244 descrpages = dma_alloc_coherent(&global_dev.pdev->dev, 245 nsg*sizeof(struct viafb_vx855_dma_descr), 246 &descr_handle, GFP_KERNEL); 247 if (descrpages == NULL) { 248 dev_err(&global_dev.pdev->dev, "Unable to get descr page.\n"); 249 return -ENOMEM; 250 } 251 mutex_lock(&viafb_dma_lock); 252 /* 253 * Fill them in. 254 */ 255 descr = descrpages; 256 nextdesc = descr_handle + sizeof(struct viafb_vx855_dma_descr); 257 for_each_sg(sg, sgentry, nsg, i) { 258 dma_addr_t paddr = sg_dma_address(sgentry); 259 descr->addr_low = paddr & 0xfffffff0; 260 descr->addr_high = ((u64) paddr >> 32) & 0x0fff; 261 descr->fb_offset = offset; 262 descr->seg_size = sg_dma_len(sgentry) >> 4; 263 descr->tile_mode = 0; 264 descr->next_desc_low = (nextdesc&0xfffffff0) | VIAFB_DMA_MAGIC; 265 descr->next_desc_high = ((u64) nextdesc >> 32) & 0x0fff; 266 descr->pad = 0xffffffff; /* VIA driver does this */ 267 offset += sg_dma_len(sgentry); 268 nextdesc += sizeof(struct viafb_vx855_dma_descr); 269 descr++; 270 } 271 descr[-1].next_desc_low = VIAFB_DMA_FINAL_SEGMENT|VIAFB_DMA_MAGIC; 272 /* 273 * Program the engine. 274 */ 275 spin_lock_irqsave(&global_dev.reg_lock, flags); 276 init_completion(&viafb_dma_completion); 277 viafb_mmio_write(VDMA_DQWCR0, 0); 278 viafb_mmio_write(VDMA_CSR0, VDMA_C_ENABLE|VDMA_C_DONE); 279 viafb_mmio_write(VDMA_MR0, VDMA_MR_TDIE | VDMA_MR_CHAIN); 280 viafb_mmio_write(VDMA_DPRL0, descr_handle | VIAFB_DMA_MAGIC); 281 viafb_mmio_write(VDMA_DPRH0, 282 (((u64)descr_handle >> 32) & 0x0fff) | 0xf0000); 283 (void) viafb_mmio_read(VDMA_CSR0); 284 viafb_mmio_write(VDMA_CSR0, VDMA_C_ENABLE|VDMA_C_START); 285 spin_unlock_irqrestore(&global_dev.reg_lock, flags); 286 /* 287 * Now we just wait until the interrupt handler says 288 * we're done. Except that, actually, we need to wait a little 289 * longer: the interrupts seem to jump the gun a little and we 290 * get corrupted frames sometimes. 291 */ 292 wait_for_completion_timeout(&viafb_dma_completion, 1); 293 msleep(1); 294 if ((viafb_mmio_read(VDMA_CSR0) & VDMA_C_DONE) == 0) { 295 printk(KERN_ERR "VIA DMA timeout!\n"); 296 ret = -ETIMEDOUT; 297 } 298 /* 299 * Clean up and we're done. 300 */ 301 viafb_mmio_write(VDMA_CSR0, VDMA_C_DONE); 302 viafb_mmio_write(VDMA_MR0, 0); /* Reset int enable */ 303 mutex_unlock(&viafb_dma_lock); 304 dma_free_coherent(&global_dev.pdev->dev, 305 nsg*sizeof(struct viafb_vx855_dma_descr), descrpages, 306 descr_handle); 307 return ret; 308 } 309 EXPORT_SYMBOL_GPL(viafb_dma_copy_out_sg); 310 #endif /* CONFIG_VIDEO_VIA_CAMERA */ 311 312 /* ---------------------------------------------------------------------- */ 313 /* 314 * Figure out how big our framebuffer memory is. Kind of ugly, 315 * but evidently we can't trust the information found in the 316 * fbdev configuration area. 317 */ 318 static u16 via_function3[] = { 319 CLE266_FUNCTION3, KM400_FUNCTION3, CN400_FUNCTION3, CN700_FUNCTION3, 320 CX700_FUNCTION3, KM800_FUNCTION3, KM890_FUNCTION3, P4M890_FUNCTION3, 321 P4M900_FUNCTION3, VX800_FUNCTION3, VX855_FUNCTION3, VX900_FUNCTION3, 322 }; 323 324 /* Get the BIOS-configured framebuffer size from PCI configuration space 325 * of function 3 in the respective chipset */ 326 static int viafb_get_fb_size_from_pci(int chip_type) 327 { 328 int i; 329 u8 offset = 0; 330 u32 FBSize; 331 u32 VideoMemSize; 332 333 /* search for the "FUNCTION3" device in this chipset */ 334 for (i = 0; i < ARRAY_SIZE(via_function3); i++) { 335 struct pci_dev *pdev; 336 337 pdev = pci_get_device(PCI_VENDOR_ID_VIA, via_function3[i], 338 NULL); 339 if (!pdev) 340 continue; 341 342 DEBUG_MSG(KERN_INFO "Device ID = %x\n", pdev->device); 343 344 switch (pdev->device) { 345 case CLE266_FUNCTION3: 346 case KM400_FUNCTION3: 347 offset = 0xE0; 348 break; 349 case CN400_FUNCTION3: 350 case CN700_FUNCTION3: 351 case CX700_FUNCTION3: 352 case KM800_FUNCTION3: 353 case KM890_FUNCTION3: 354 case P4M890_FUNCTION3: 355 case P4M900_FUNCTION3: 356 case VX800_FUNCTION3: 357 case VX855_FUNCTION3: 358 case VX900_FUNCTION3: 359 /*case CN750_FUNCTION3: */ 360 offset = 0xA0; 361 break; 362 } 363 364 if (!offset) 365 break; 366 367 pci_read_config_dword(pdev, offset, &FBSize); 368 pci_dev_put(pdev); 369 } 370 371 if (!offset) { 372 printk(KERN_ERR "cannot determine framebuffer size\n"); 373 return -EIO; 374 } 375 376 FBSize = FBSize & 0x00007000; 377 DEBUG_MSG(KERN_INFO "FB Size = %x\n", FBSize); 378 379 if (chip_type < UNICHROME_CX700) { 380 switch (FBSize) { 381 case 0x00004000: 382 VideoMemSize = (16 << 20); /*16M */ 383 break; 384 385 case 0x00005000: 386 VideoMemSize = (32 << 20); /*32M */ 387 break; 388 389 case 0x00006000: 390 VideoMemSize = (64 << 20); /*64M */ 391 break; 392 393 default: 394 VideoMemSize = (32 << 20); /*32M */ 395 break; 396 } 397 } else { 398 switch (FBSize) { 399 case 0x00001000: 400 VideoMemSize = (8 << 20); /*8M */ 401 break; 402 403 case 0x00002000: 404 VideoMemSize = (16 << 20); /*16M */ 405 break; 406 407 case 0x00003000: 408 VideoMemSize = (32 << 20); /*32M */ 409 break; 410 411 case 0x00004000: 412 VideoMemSize = (64 << 20); /*64M */ 413 break; 414 415 case 0x00005000: 416 VideoMemSize = (128 << 20); /*128M */ 417 break; 418 419 case 0x00006000: 420 VideoMemSize = (256 << 20); /*256M */ 421 break; 422 423 case 0x00007000: /* Only on VX855/875 */ 424 VideoMemSize = (512 << 20); /*512M */ 425 break; 426 427 default: 428 VideoMemSize = (32 << 20); /*32M */ 429 break; 430 } 431 } 432 433 return VideoMemSize; 434 } 435 436 437 /* 438 * Figure out and map our MMIO regions. 439 */ 440 static int via_pci_setup_mmio(struct viafb_dev *vdev) 441 { 442 int ret; 443 /* 444 * Hook up to the device registers. Note that we soldier 445 * on if it fails; the framebuffer can operate (without 446 * acceleration) without this region. 447 */ 448 vdev->engine_start = pci_resource_start(vdev->pdev, 1); 449 vdev->engine_len = pci_resource_len(vdev->pdev, 1); 450 vdev->engine_mmio = ioremap(vdev->engine_start, 451 vdev->engine_len); 452 if (vdev->engine_mmio == NULL) 453 dev_err(&vdev->pdev->dev, 454 "Unable to map engine MMIO; operation will be " 455 "slow and crippled.\n"); 456 /* 457 * Map in framebuffer memory. For now, failure here is 458 * fatal. Unfortunately, in the absence of significant 459 * vmalloc space, failure here is also entirely plausible. 460 * Eventually we want to move away from mapping this 461 * entire region. 462 */ 463 if (vdev->chip_type == UNICHROME_VX900) 464 vdev->fbmem_start = pci_resource_start(vdev->pdev, 2); 465 else 466 vdev->fbmem_start = pci_resource_start(vdev->pdev, 0); 467 ret = vdev->fbmem_len = viafb_get_fb_size_from_pci(vdev->chip_type); 468 if (ret < 0) 469 goto out_unmap; 470 471 /* try to map less memory on failure, 8 MB should be still enough */ 472 for (; vdev->fbmem_len >= 8 << 20; vdev->fbmem_len /= 2) { 473 vdev->fbmem = ioremap_wc(vdev->fbmem_start, vdev->fbmem_len); 474 if (vdev->fbmem) 475 break; 476 } 477 478 if (vdev->fbmem == NULL) { 479 ret = -ENOMEM; 480 goto out_unmap; 481 } 482 return 0; 483 out_unmap: 484 iounmap(vdev->engine_mmio); 485 return ret; 486 } 487 488 static void via_pci_teardown_mmio(struct viafb_dev *vdev) 489 { 490 iounmap(vdev->fbmem); 491 iounmap(vdev->engine_mmio); 492 } 493 494 /* 495 * Create our subsidiary devices. 496 */ 497 static struct viafb_subdev_info { 498 char *name; 499 struct platform_device *platdev; 500 } viafb_subdevs[] = { 501 { 502 .name = "viafb-gpio", 503 }, 504 { 505 .name = "viafb-i2c", 506 }, 507 #if IS_ENABLED(CONFIG_VIDEO_VIA_CAMERA) 508 { 509 .name = "viafb-camera", 510 }, 511 #endif 512 }; 513 #define N_SUBDEVS ARRAY_SIZE(viafb_subdevs) 514 515 static int via_create_subdev(struct viafb_dev *vdev, 516 struct viafb_subdev_info *info) 517 { 518 int ret; 519 520 info->platdev = platform_device_alloc(info->name, -1); 521 if (!info->platdev) { 522 dev_err(&vdev->pdev->dev, "Unable to allocate pdev %s\n", 523 info->name); 524 return -ENOMEM; 525 } 526 info->platdev->dev.parent = &vdev->pdev->dev; 527 info->platdev->dev.platform_data = vdev; 528 ret = platform_device_add(info->platdev); 529 if (ret) { 530 dev_err(&vdev->pdev->dev, "Unable to add pdev %s\n", 531 info->name); 532 platform_device_put(info->platdev); 533 info->platdev = NULL; 534 } 535 return ret; 536 } 537 538 static int via_setup_subdevs(struct viafb_dev *vdev) 539 { 540 int i; 541 542 /* 543 * Ignore return values. Even if some of the devices 544 * fail to be created, we'll still be able to use some 545 * of the rest. 546 */ 547 for (i = 0; i < N_SUBDEVS; i++) 548 via_create_subdev(vdev, viafb_subdevs + i); 549 return 0; 550 } 551 552 static void via_teardown_subdevs(void) 553 { 554 int i; 555 556 for (i = 0; i < N_SUBDEVS; i++) 557 if (viafb_subdevs[i].platdev) { 558 viafb_subdevs[i].platdev->dev.platform_data = NULL; 559 platform_device_unregister(viafb_subdevs[i].platdev); 560 } 561 } 562 563 /* 564 * Power management functions 565 */ 566 static __maybe_unused LIST_HEAD(viafb_pm_hooks); 567 static __maybe_unused DEFINE_MUTEX(viafb_pm_hooks_lock); 568 569 void viafb_pm_register(struct viafb_pm_hooks *hooks) 570 { 571 INIT_LIST_HEAD(&hooks->list); 572 573 mutex_lock(&viafb_pm_hooks_lock); 574 list_add_tail(&hooks->list, &viafb_pm_hooks); 575 mutex_unlock(&viafb_pm_hooks_lock); 576 } 577 EXPORT_SYMBOL_GPL(viafb_pm_register); 578 579 void viafb_pm_unregister(struct viafb_pm_hooks *hooks) 580 { 581 mutex_lock(&viafb_pm_hooks_lock); 582 list_del(&hooks->list); 583 mutex_unlock(&viafb_pm_hooks_lock); 584 } 585 EXPORT_SYMBOL_GPL(viafb_pm_unregister); 586 587 static int __maybe_unused via_suspend(struct device *dev) 588 { 589 struct viafb_pm_hooks *hooks; 590 591 /* 592 * "I've occasionally hit a few drivers that caused suspend 593 * failures, and each and every time it was a driver bug, and 594 * the right thing to do was to just ignore the error and suspend 595 * anyway - returning an error code and trying to undo the suspend 596 * is not what anybody ever really wants, even if our model 597 *_allows_ for it." 598 * -- Linus Torvalds, Dec. 7, 2009 599 */ 600 mutex_lock(&viafb_pm_hooks_lock); 601 list_for_each_entry_reverse(hooks, &viafb_pm_hooks, list) 602 hooks->suspend(hooks->private); 603 mutex_unlock(&viafb_pm_hooks_lock); 604 605 return 0; 606 } 607 608 static int __maybe_unused via_resume(struct device *dev) 609 { 610 struct viafb_pm_hooks *hooks; 611 612 /* Now bring back any subdevs */ 613 mutex_lock(&viafb_pm_hooks_lock); 614 list_for_each_entry(hooks, &viafb_pm_hooks, list) 615 hooks->resume(hooks->private); 616 mutex_unlock(&viafb_pm_hooks_lock); 617 618 return 0; 619 } 620 621 static int via_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 622 { 623 int ret; 624 625 ret = aperture_remove_conflicting_pci_devices(pdev, "viafb"); 626 if (ret) 627 return ret; 628 629 ret = pci_enable_device(pdev); 630 if (ret) 631 return ret; 632 633 /* 634 * Global device initialization. 635 */ 636 memset(&global_dev, 0, sizeof(global_dev)); 637 global_dev.pdev = pdev; 638 global_dev.chip_type = ent->driver_data; 639 global_dev.port_cfg = adap_configs; 640 if (machine_is_olpc()) 641 global_dev.port_cfg = olpc_adap_configs; 642 643 spin_lock_init(&global_dev.reg_lock); 644 ret = via_pci_setup_mmio(&global_dev); 645 if (ret) 646 goto out_disable; 647 /* 648 * Set up interrupts and create our subdevices. Continue even if 649 * some things fail. 650 */ 651 viafb_int_init(); 652 via_setup_subdevs(&global_dev); 653 /* 654 * Set up the framebuffer device 655 */ 656 ret = via_fb_pci_probe(&global_dev); 657 if (ret) 658 goto out_subdevs; 659 return 0; 660 661 out_subdevs: 662 via_teardown_subdevs(); 663 via_pci_teardown_mmio(&global_dev); 664 out_disable: 665 pci_disable_device(pdev); 666 return ret; 667 } 668 669 static void via_pci_remove(struct pci_dev *pdev) 670 { 671 via_teardown_subdevs(); 672 via_fb_pci_remove(pdev); 673 via_pci_teardown_mmio(&global_dev); 674 pci_disable_device(pdev); 675 } 676 677 678 static const struct pci_device_id via_pci_table[] = { 679 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CLE266_DID), 680 .driver_data = UNICHROME_CLE266 }, 681 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K400_DID), 682 .driver_data = UNICHROME_K400 }, 683 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K800_DID), 684 .driver_data = UNICHROME_K800 }, 685 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_PM800_DID), 686 .driver_data = UNICHROME_PM800 }, 687 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CN700_DID), 688 .driver_data = UNICHROME_CN700 }, 689 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CX700_DID), 690 .driver_data = UNICHROME_CX700 }, 691 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CN750_DID), 692 .driver_data = UNICHROME_CN750 }, 693 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K8M890_DID), 694 .driver_data = UNICHROME_K8M890 }, 695 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_P4M890_DID), 696 .driver_data = UNICHROME_P4M890 }, 697 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_P4M900_DID), 698 .driver_data = UNICHROME_P4M900 }, 699 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_VX800_DID), 700 .driver_data = UNICHROME_VX800 }, 701 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_VX855_DID), 702 .driver_data = UNICHROME_VX855 }, 703 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_VX900_DID), 704 .driver_data = UNICHROME_VX900 }, 705 { } 706 }; 707 MODULE_DEVICE_TABLE(pci, via_pci_table); 708 709 static const struct dev_pm_ops via_pm_ops = { 710 #ifdef CONFIG_PM_SLEEP 711 .suspend = via_suspend, 712 .resume = via_resume, 713 .freeze = NULL, 714 .thaw = via_resume, 715 .poweroff = NULL, 716 .restore = via_resume, 717 #endif 718 }; 719 720 static struct pci_driver via_driver = { 721 .name = "viafb", 722 .id_table = via_pci_table, 723 .probe = via_pci_probe, 724 .remove = via_pci_remove, 725 .driver.pm = &via_pm_ops, 726 }; 727 728 static int __init via_core_init(void) 729 { 730 int ret; 731 732 if (fb_modesetting_disabled("viafb")) 733 return -ENODEV; 734 735 ret = viafb_init(); 736 if (ret) 737 return ret; 738 viafb_i2c_init(); 739 viafb_gpio_init(); 740 ret = pci_register_driver(&via_driver); 741 if (ret) { 742 viafb_gpio_exit(); 743 viafb_i2c_exit(); 744 return ret; 745 } 746 747 return 0; 748 } 749 750 static void __exit via_core_exit(void) 751 { 752 pci_unregister_driver(&via_driver); 753 viafb_gpio_exit(); 754 viafb_i2c_exit(); 755 viafb_exit(); 756 } 757 758 module_init(via_core_init); 759 module_exit(via_core_exit); 760