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 struct scatterlist *sgentry; 238 dma_addr_t nextdesc; 239 240 /* 241 * Get a place to put the descriptors. 242 */ 243 descrpages = dma_alloc_coherent(&global_dev.pdev->dev, 244 nsg*sizeof(struct viafb_vx855_dma_descr), 245 &descr_handle, GFP_KERNEL); 246 if (descrpages == NULL) { 247 dev_err(&global_dev.pdev->dev, "Unable to get descr page.\n"); 248 return -ENOMEM; 249 } 250 mutex_lock(&viafb_dma_lock); 251 /* 252 * Fill them in. 253 */ 254 descr = descrpages; 255 nextdesc = descr_handle + sizeof(struct viafb_vx855_dma_descr); 256 for_each_sg(sg, sgentry, nsg, i) { 257 dma_addr_t paddr = sg_dma_address(sgentry); 258 descr->addr_low = paddr & 0xfffffff0; 259 descr->addr_high = ((u64) paddr >> 32) & 0x0fff; 260 descr->fb_offset = offset; 261 descr->seg_size = sg_dma_len(sgentry) >> 4; 262 descr->tile_mode = 0; 263 descr->next_desc_low = (nextdesc&0xfffffff0) | VIAFB_DMA_MAGIC; 264 descr->next_desc_high = ((u64) nextdesc >> 32) & 0x0fff; 265 descr->pad = 0xffffffff; /* VIA driver does this */ 266 offset += sg_dma_len(sgentry); 267 nextdesc += sizeof(struct viafb_vx855_dma_descr); 268 descr++; 269 } 270 descr[-1].next_desc_low = VIAFB_DMA_FINAL_SEGMENT|VIAFB_DMA_MAGIC; 271 /* 272 * Program the engine. 273 */ 274 spin_lock_irqsave(&global_dev.reg_lock, flags); 275 init_completion(&viafb_dma_completion); 276 viafb_mmio_write(VDMA_DQWCR0, 0); 277 viafb_mmio_write(VDMA_CSR0, VDMA_C_ENABLE|VDMA_C_DONE); 278 viafb_mmio_write(VDMA_MR0, VDMA_MR_TDIE | VDMA_MR_CHAIN); 279 viafb_mmio_write(VDMA_DPRL0, descr_handle | VIAFB_DMA_MAGIC); 280 viafb_mmio_write(VDMA_DPRH0, 281 (((u64)descr_handle >> 32) & 0x0fff) | 0xf0000); 282 (void) viafb_mmio_read(VDMA_CSR0); 283 viafb_mmio_write(VDMA_CSR0, VDMA_C_ENABLE|VDMA_C_START); 284 spin_unlock_irqrestore(&global_dev.reg_lock, flags); 285 /* 286 * Now we just wait until the interrupt handler says 287 * we're done. Except that, actually, we need to wait a little 288 * longer: the interrupts seem to jump the gun a little and we 289 * get corrupted frames sometimes. 290 */ 291 wait_for_completion_timeout(&viafb_dma_completion, 1); 292 msleep(1); 293 if ((viafb_mmio_read(VDMA_CSR0)&VDMA_C_DONE) == 0) 294 printk(KERN_ERR "VIA DMA timeout!\n"); 295 /* 296 * Clean up and we're done. 297 */ 298 viafb_mmio_write(VDMA_CSR0, VDMA_C_DONE); 299 viafb_mmio_write(VDMA_MR0, 0); /* Reset int enable */ 300 mutex_unlock(&viafb_dma_lock); 301 dma_free_coherent(&global_dev.pdev->dev, 302 nsg*sizeof(struct viafb_vx855_dma_descr), descrpages, 303 descr_handle); 304 return 0; 305 } 306 EXPORT_SYMBOL_GPL(viafb_dma_copy_out_sg); 307 #endif /* CONFIG_VIDEO_VIA_CAMERA */ 308 309 /* ---------------------------------------------------------------------- */ 310 /* 311 * Figure out how big our framebuffer memory is. Kind of ugly, 312 * but evidently we can't trust the information found in the 313 * fbdev configuration area. 314 */ 315 static u16 via_function3[] = { 316 CLE266_FUNCTION3, KM400_FUNCTION3, CN400_FUNCTION3, CN700_FUNCTION3, 317 CX700_FUNCTION3, KM800_FUNCTION3, KM890_FUNCTION3, P4M890_FUNCTION3, 318 P4M900_FUNCTION3, VX800_FUNCTION3, VX855_FUNCTION3, VX900_FUNCTION3, 319 }; 320 321 /* Get the BIOS-configured framebuffer size from PCI configuration space 322 * of function 3 in the respective chipset */ 323 static int viafb_get_fb_size_from_pci(int chip_type) 324 { 325 int i; 326 u8 offset = 0; 327 u32 FBSize; 328 u32 VideoMemSize; 329 330 /* search for the "FUNCTION3" device in this chipset */ 331 for (i = 0; i < ARRAY_SIZE(via_function3); i++) { 332 struct pci_dev *pdev; 333 334 pdev = pci_get_device(PCI_VENDOR_ID_VIA, via_function3[i], 335 NULL); 336 if (!pdev) 337 continue; 338 339 DEBUG_MSG(KERN_INFO "Device ID = %x\n", pdev->device); 340 341 switch (pdev->device) { 342 case CLE266_FUNCTION3: 343 case KM400_FUNCTION3: 344 offset = 0xE0; 345 break; 346 case CN400_FUNCTION3: 347 case CN700_FUNCTION3: 348 case CX700_FUNCTION3: 349 case KM800_FUNCTION3: 350 case KM890_FUNCTION3: 351 case P4M890_FUNCTION3: 352 case P4M900_FUNCTION3: 353 case VX800_FUNCTION3: 354 case VX855_FUNCTION3: 355 case VX900_FUNCTION3: 356 /*case CN750_FUNCTION3: */ 357 offset = 0xA0; 358 break; 359 } 360 361 if (!offset) 362 break; 363 364 pci_read_config_dword(pdev, offset, &FBSize); 365 pci_dev_put(pdev); 366 } 367 368 if (!offset) { 369 printk(KERN_ERR "cannot determine framebuffer size\n"); 370 return -EIO; 371 } 372 373 FBSize = FBSize & 0x00007000; 374 DEBUG_MSG(KERN_INFO "FB Size = %x\n", FBSize); 375 376 if (chip_type < UNICHROME_CX700) { 377 switch (FBSize) { 378 case 0x00004000: 379 VideoMemSize = (16 << 20); /*16M */ 380 break; 381 382 case 0x00005000: 383 VideoMemSize = (32 << 20); /*32M */ 384 break; 385 386 case 0x00006000: 387 VideoMemSize = (64 << 20); /*64M */ 388 break; 389 390 default: 391 VideoMemSize = (32 << 20); /*32M */ 392 break; 393 } 394 } else { 395 switch (FBSize) { 396 case 0x00001000: 397 VideoMemSize = (8 << 20); /*8M */ 398 break; 399 400 case 0x00002000: 401 VideoMemSize = (16 << 20); /*16M */ 402 break; 403 404 case 0x00003000: 405 VideoMemSize = (32 << 20); /*32M */ 406 break; 407 408 case 0x00004000: 409 VideoMemSize = (64 << 20); /*64M */ 410 break; 411 412 case 0x00005000: 413 VideoMemSize = (128 << 20); /*128M */ 414 break; 415 416 case 0x00006000: 417 VideoMemSize = (256 << 20); /*256M */ 418 break; 419 420 case 0x00007000: /* Only on VX855/875 */ 421 VideoMemSize = (512 << 20); /*512M */ 422 break; 423 424 default: 425 VideoMemSize = (32 << 20); /*32M */ 426 break; 427 } 428 } 429 430 return VideoMemSize; 431 } 432 433 434 /* 435 * Figure out and map our MMIO regions. 436 */ 437 static int via_pci_setup_mmio(struct viafb_dev *vdev) 438 { 439 int ret; 440 /* 441 * Hook up to the device registers. Note that we soldier 442 * on if it fails; the framebuffer can operate (without 443 * acceleration) without this region. 444 */ 445 vdev->engine_start = pci_resource_start(vdev->pdev, 1); 446 vdev->engine_len = pci_resource_len(vdev->pdev, 1); 447 vdev->engine_mmio = ioremap(vdev->engine_start, 448 vdev->engine_len); 449 if (vdev->engine_mmio == NULL) 450 dev_err(&vdev->pdev->dev, 451 "Unable to map engine MMIO; operation will be " 452 "slow and crippled.\n"); 453 /* 454 * Map in framebuffer memory. For now, failure here is 455 * fatal. Unfortunately, in the absence of significant 456 * vmalloc space, failure here is also entirely plausible. 457 * Eventually we want to move away from mapping this 458 * entire region. 459 */ 460 if (vdev->chip_type == UNICHROME_VX900) 461 vdev->fbmem_start = pci_resource_start(vdev->pdev, 2); 462 else 463 vdev->fbmem_start = pci_resource_start(vdev->pdev, 0); 464 ret = vdev->fbmem_len = viafb_get_fb_size_from_pci(vdev->chip_type); 465 if (ret < 0) 466 goto out_unmap; 467 468 /* try to map less memory on failure, 8 MB should be still enough */ 469 for (; vdev->fbmem_len >= 8 << 20; vdev->fbmem_len /= 2) { 470 vdev->fbmem = ioremap_wc(vdev->fbmem_start, vdev->fbmem_len); 471 if (vdev->fbmem) 472 break; 473 } 474 475 if (vdev->fbmem == NULL) { 476 ret = -ENOMEM; 477 goto out_unmap; 478 } 479 return 0; 480 out_unmap: 481 iounmap(vdev->engine_mmio); 482 return ret; 483 } 484 485 static void via_pci_teardown_mmio(struct viafb_dev *vdev) 486 { 487 iounmap(vdev->fbmem); 488 iounmap(vdev->engine_mmio); 489 } 490 491 /* 492 * Create our subsidiary devices. 493 */ 494 static struct viafb_subdev_info { 495 char *name; 496 struct platform_device *platdev; 497 } viafb_subdevs[] = { 498 { 499 .name = "viafb-gpio", 500 }, 501 { 502 .name = "viafb-i2c", 503 }, 504 #if IS_ENABLED(CONFIG_VIDEO_VIA_CAMERA) 505 { 506 .name = "viafb-camera", 507 }, 508 #endif 509 }; 510 #define N_SUBDEVS ARRAY_SIZE(viafb_subdevs) 511 512 static int via_create_subdev(struct viafb_dev *vdev, 513 struct viafb_subdev_info *info) 514 { 515 int ret; 516 517 info->platdev = platform_device_alloc(info->name, -1); 518 if (!info->platdev) { 519 dev_err(&vdev->pdev->dev, "Unable to allocate pdev %s\n", 520 info->name); 521 return -ENOMEM; 522 } 523 info->platdev->dev.parent = &vdev->pdev->dev; 524 info->platdev->dev.platform_data = vdev; 525 ret = platform_device_add(info->platdev); 526 if (ret) { 527 dev_err(&vdev->pdev->dev, "Unable to add pdev %s\n", 528 info->name); 529 platform_device_put(info->platdev); 530 info->platdev = NULL; 531 } 532 return ret; 533 } 534 535 static int via_setup_subdevs(struct viafb_dev *vdev) 536 { 537 int i; 538 539 /* 540 * Ignore return values. Even if some of the devices 541 * fail to be created, we'll still be able to use some 542 * of the rest. 543 */ 544 for (i = 0; i < N_SUBDEVS; i++) 545 via_create_subdev(vdev, viafb_subdevs + i); 546 return 0; 547 } 548 549 static void via_teardown_subdevs(void) 550 { 551 int i; 552 553 for (i = 0; i < N_SUBDEVS; i++) 554 if (viafb_subdevs[i].platdev) { 555 viafb_subdevs[i].platdev->dev.platform_data = NULL; 556 platform_device_unregister(viafb_subdevs[i].platdev); 557 } 558 } 559 560 /* 561 * Power management functions 562 */ 563 static __maybe_unused LIST_HEAD(viafb_pm_hooks); 564 static __maybe_unused DEFINE_MUTEX(viafb_pm_hooks_lock); 565 566 void viafb_pm_register(struct viafb_pm_hooks *hooks) 567 { 568 INIT_LIST_HEAD(&hooks->list); 569 570 mutex_lock(&viafb_pm_hooks_lock); 571 list_add_tail(&hooks->list, &viafb_pm_hooks); 572 mutex_unlock(&viafb_pm_hooks_lock); 573 } 574 EXPORT_SYMBOL_GPL(viafb_pm_register); 575 576 void viafb_pm_unregister(struct viafb_pm_hooks *hooks) 577 { 578 mutex_lock(&viafb_pm_hooks_lock); 579 list_del(&hooks->list); 580 mutex_unlock(&viafb_pm_hooks_lock); 581 } 582 EXPORT_SYMBOL_GPL(viafb_pm_unregister); 583 584 static int __maybe_unused via_suspend(struct device *dev) 585 { 586 struct viafb_pm_hooks *hooks; 587 588 /* 589 * "I've occasionally hit a few drivers that caused suspend 590 * failures, and each and every time it was a driver bug, and 591 * the right thing to do was to just ignore the error and suspend 592 * anyway - returning an error code and trying to undo the suspend 593 * is not what anybody ever really wants, even if our model 594 *_allows_ for it." 595 * -- Linus Torvalds, Dec. 7, 2009 596 */ 597 mutex_lock(&viafb_pm_hooks_lock); 598 list_for_each_entry_reverse(hooks, &viafb_pm_hooks, list) 599 hooks->suspend(hooks->private); 600 mutex_unlock(&viafb_pm_hooks_lock); 601 602 return 0; 603 } 604 605 static int __maybe_unused via_resume(struct device *dev) 606 { 607 struct viafb_pm_hooks *hooks; 608 609 /* Now bring back any subdevs */ 610 mutex_lock(&viafb_pm_hooks_lock); 611 list_for_each_entry(hooks, &viafb_pm_hooks, list) 612 hooks->resume(hooks->private); 613 mutex_unlock(&viafb_pm_hooks_lock); 614 615 return 0; 616 } 617 618 static int via_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 619 { 620 int ret; 621 622 ret = aperture_remove_conflicting_pci_devices(pdev, "viafb"); 623 if (ret) 624 return ret; 625 626 ret = pci_enable_device(pdev); 627 if (ret) 628 return ret; 629 630 /* 631 * Global device initialization. 632 */ 633 memset(&global_dev, 0, sizeof(global_dev)); 634 global_dev.pdev = pdev; 635 global_dev.chip_type = ent->driver_data; 636 global_dev.port_cfg = adap_configs; 637 if (machine_is_olpc()) 638 global_dev.port_cfg = olpc_adap_configs; 639 640 spin_lock_init(&global_dev.reg_lock); 641 ret = via_pci_setup_mmio(&global_dev); 642 if (ret) 643 goto out_disable; 644 /* 645 * Set up interrupts and create our subdevices. Continue even if 646 * some things fail. 647 */ 648 viafb_int_init(); 649 via_setup_subdevs(&global_dev); 650 /* 651 * Set up the framebuffer device 652 */ 653 ret = via_fb_pci_probe(&global_dev); 654 if (ret) 655 goto out_subdevs; 656 return 0; 657 658 out_subdevs: 659 via_teardown_subdevs(); 660 via_pci_teardown_mmio(&global_dev); 661 out_disable: 662 pci_disable_device(pdev); 663 return ret; 664 } 665 666 static void via_pci_remove(struct pci_dev *pdev) 667 { 668 via_teardown_subdevs(); 669 via_fb_pci_remove(pdev); 670 via_pci_teardown_mmio(&global_dev); 671 pci_disable_device(pdev); 672 } 673 674 675 static const struct pci_device_id via_pci_table[] = { 676 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CLE266_DID), 677 .driver_data = UNICHROME_CLE266 }, 678 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K400_DID), 679 .driver_data = UNICHROME_K400 }, 680 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K800_DID), 681 .driver_data = UNICHROME_K800 }, 682 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_PM800_DID), 683 .driver_data = UNICHROME_PM800 }, 684 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CN700_DID), 685 .driver_data = UNICHROME_CN700 }, 686 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CX700_DID), 687 .driver_data = UNICHROME_CX700 }, 688 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CN750_DID), 689 .driver_data = UNICHROME_CN750 }, 690 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K8M890_DID), 691 .driver_data = UNICHROME_K8M890 }, 692 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_P4M890_DID), 693 .driver_data = UNICHROME_P4M890 }, 694 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_P4M900_DID), 695 .driver_data = UNICHROME_P4M900 }, 696 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_VX800_DID), 697 .driver_data = UNICHROME_VX800 }, 698 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_VX855_DID), 699 .driver_data = UNICHROME_VX855 }, 700 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_VX900_DID), 701 .driver_data = UNICHROME_VX900 }, 702 { } 703 }; 704 MODULE_DEVICE_TABLE(pci, via_pci_table); 705 706 static const struct dev_pm_ops via_pm_ops = { 707 #ifdef CONFIG_PM_SLEEP 708 .suspend = via_suspend, 709 .resume = via_resume, 710 .freeze = NULL, 711 .thaw = via_resume, 712 .poweroff = NULL, 713 .restore = via_resume, 714 #endif 715 }; 716 717 static struct pci_driver via_driver = { 718 .name = "viafb", 719 .id_table = via_pci_table, 720 .probe = via_pci_probe, 721 .remove = via_pci_remove, 722 .driver.pm = &via_pm_ops, 723 }; 724 725 static int __init via_core_init(void) 726 { 727 int ret; 728 729 if (fb_modesetting_disabled("viafb")) 730 return -ENODEV; 731 732 ret = viafb_init(); 733 if (ret) 734 return ret; 735 viafb_i2c_init(); 736 viafb_gpio_init(); 737 ret = pci_register_driver(&via_driver); 738 if (ret) { 739 viafb_gpio_exit(); 740 viafb_i2c_exit(); 741 return ret; 742 } 743 744 return 0; 745 } 746 747 static void __exit via_core_exit(void) 748 { 749 pci_unregister_driver(&via_driver); 750 viafb_gpio_exit(); 751 viafb_i2c_exit(); 752 viafb_exit(); 753 } 754 755 module_init(via_core_init); 756 module_exit(via_core_exit); 757