blob: 66f40303311176c1672f34b0793264bc4c7ee600 [file] [log] [blame]
Jonathan Corbetf045f772009-12-01 20:29:39 -07001/*
2 * Copyright 1998-2009 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4 * Copyright 2009 Jonathan Corbet <corbet@lwn.net>
5 */
6
7/*
8 * Core code for the Via multifunction framebuffer device.
9 */
Jonathan Corbetec668412010-05-05 14:44:55 -060010#include <linux/via-core.h>
11#include <linux/via_i2c.h>
12#include <linux/via-gpio.h>
Jonathan Corbet24b4d822010-04-22 13:48:09 -060013#include "global.h"
14
Jonathan Corbetf045f772009-12-01 20:29:39 -070015#include <linux/module.h>
Jonathan Corbet3d28eb42010-04-23 10:04:12 -060016#include <linux/interrupt.h>
Jonathan Corbetf045f772009-12-01 20:29:39 -070017#include <linux/platform_device.h>
Jonathan Corbetf045f772009-12-01 20:29:39 -070018
19/*
20 * The default port config.
21 */
22static struct via_port_cfg adap_configs[] = {
23 [VIA_PORT_26] = { VIA_PORT_I2C, VIA_MODE_OFF, VIASR, 0x26 },
24 [VIA_PORT_31] = { VIA_PORT_I2C, VIA_MODE_I2C, VIASR, 0x31 },
25 [VIA_PORT_25] = { VIA_PORT_GPIO, VIA_MODE_GPIO, VIASR, 0x25 },
26 [VIA_PORT_2C] = { VIA_PORT_GPIO, VIA_MODE_I2C, VIASR, 0x2c },
27 [VIA_PORT_3D] = { VIA_PORT_GPIO, VIA_MODE_GPIO, VIASR, 0x3d },
28 { 0, 0, 0, 0 }
29};
30
Jonathan Corbet24b4d822010-04-22 13:48:09 -060031/*
32 * We currently only support one viafb device (will there ever be
33 * more than one?), so just declare it globally here.
34 */
35static struct viafb_dev global_dev;
36
37
38/*
Jonathan Corbet94dd1a82010-04-23 09:46:59 -060039 * Basic register access; spinlock required.
40 */
41static inline void viafb_mmio_write(int reg, u32 v)
42{
43 iowrite32(v, global_dev.engine_mmio + reg);
44}
45
46static inline int viafb_mmio_read(int reg)
47{
48 return ioread32(global_dev.engine_mmio + reg);
49}
50
51/* ---------------------------------------------------------------------- */
52/*
53 * Interrupt management. We have a single IRQ line for a lot of
54 * different functions, so we need to share it. The design here
55 * is that we don't want to reimplement the shared IRQ code here;
56 * we also want to avoid having contention for a single handler thread.
57 * So each subdev driver which needs interrupts just requests
58 * them directly from the kernel. We just have what's needed for
59 * overall access to the interrupt control register.
60 */
61
62/*
63 * Which interrupts are enabled now?
64 */
65static u32 viafb_enabled_ints;
66
Henrik Kretzschmareca9c472010-06-17 12:01:24 +020067static void __devinit viafb_int_init(void)
Jonathan Corbet94dd1a82010-04-23 09:46:59 -060068{
69 viafb_enabled_ints = 0;
70
71 viafb_mmio_write(VDE_INTERRUPT, 0);
72}
73
74/*
75 * Allow subdevs to ask for specific interrupts to be enabled. These
76 * functions must be called with reg_lock held
77 */
78void viafb_irq_enable(u32 mask)
79{
80 viafb_enabled_ints |= mask;
81 viafb_mmio_write(VDE_INTERRUPT, viafb_enabled_ints | VDE_I_ENABLE);
82}
83EXPORT_SYMBOL_GPL(viafb_irq_enable);
84
85void viafb_irq_disable(u32 mask)
86{
87 viafb_enabled_ints &= ~mask;
88 if (viafb_enabled_ints == 0)
89 viafb_mmio_write(VDE_INTERRUPT, 0); /* Disable entirely */
90 else
91 viafb_mmio_write(VDE_INTERRUPT,
92 viafb_enabled_ints | VDE_I_ENABLE);
93}
94EXPORT_SYMBOL_GPL(viafb_irq_disable);
95
Jonathan Corbet3d28eb42010-04-23 10:04:12 -060096/* ---------------------------------------------------------------------- */
97/*
98 * Access to the DMA engine. This currently provides what the camera
99 * driver needs (i.e. outgoing only) but is easily expandable if need
100 * be.
101 */
Jonathan Corbet94dd1a82010-04-23 09:46:59 -0600102
103/*
Jonathan Corbet3d28eb42010-04-23 10:04:12 -0600104 * There are four DMA channels in the vx855. For now, we only
105 * use one of them, though. Most of the time, the DMA channel
106 * will be idle, so we keep the IRQ handler unregistered except
107 * when some subsystem has indicated an interest.
108 */
109static int viafb_dma_users;
110static DECLARE_COMPLETION(viafb_dma_completion);
111/*
112 * This mutex protects viafb_dma_users and our global interrupt
113 * registration state; it also serializes access to the DMA
114 * engine.
115 */
116static DEFINE_MUTEX(viafb_dma_lock);
117
118/*
119 * The VX855 DMA descriptor (used for s/g transfers) looks
120 * like this.
121 */
122struct viafb_vx855_dma_descr {
123 u32 addr_low; /* Low part of phys addr */
124 u32 addr_high; /* High 12 bits of addr */
125 u32 fb_offset; /* Offset into FB memory */
126 u32 seg_size; /* Size, 16-byte units */
127 u32 tile_mode; /* "tile mode" setting */
128 u32 next_desc_low; /* Next descriptor addr */
129 u32 next_desc_high;
130 u32 pad; /* Fill out to 64 bytes */
131};
132
133/*
134 * Flags added to the "next descriptor low" pointers
135 */
136#define VIAFB_DMA_MAGIC 0x01 /* ??? Just has to be there */
137#define VIAFB_DMA_FINAL_SEGMENT 0x02 /* Final segment */
138
139/*
140 * The completion IRQ handler.
141 */
142static irqreturn_t viafb_dma_irq(int irq, void *data)
143{
144 int csr;
145 irqreturn_t ret = IRQ_NONE;
146
147 spin_lock(&global_dev.reg_lock);
148 csr = viafb_mmio_read(VDMA_CSR0);
149 if (csr & VDMA_C_DONE) {
150 viafb_mmio_write(VDMA_CSR0, VDMA_C_DONE);
151 complete(&viafb_dma_completion);
152 ret = IRQ_HANDLED;
153 }
154 spin_unlock(&global_dev.reg_lock);
155 return ret;
156}
157
158/*
159 * Indicate a need for DMA functionality.
160 */
161int viafb_request_dma(void)
162{
163 int ret = 0;
164
165 /*
166 * Only VX855 is supported currently.
167 */
168 if (global_dev.chip_type != UNICHROME_VX855)
169 return -ENODEV;
170 /*
171 * Note the new user and set up our interrupt handler
172 * if need be.
173 */
174 mutex_lock(&viafb_dma_lock);
175 viafb_dma_users++;
176 if (viafb_dma_users == 1) {
177 ret = request_irq(global_dev.pdev->irq, viafb_dma_irq,
178 IRQF_SHARED, "via-dma", &viafb_dma_users);
179 if (ret)
180 viafb_dma_users--;
181 else
182 viafb_irq_enable(VDE_I_DMA0TDEN);
183 }
184 mutex_unlock(&viafb_dma_lock);
185 return ret;
186}
187EXPORT_SYMBOL_GPL(viafb_request_dma);
188
189void viafb_release_dma(void)
190{
191 mutex_lock(&viafb_dma_lock);
192 viafb_dma_users--;
193 if (viafb_dma_users == 0) {
194 viafb_irq_disable(VDE_I_DMA0TDEN);
195 free_irq(global_dev.pdev->irq, &viafb_dma_users);
196 }
197 mutex_unlock(&viafb_dma_lock);
198}
199EXPORT_SYMBOL_GPL(viafb_release_dma);
200
201
202#if 0
203/*
204 * Copy a single buffer from FB memory, synchronously. This code works
205 * but is not currently used.
206 */
207void viafb_dma_copy_out(unsigned int offset, dma_addr_t paddr, int len)
208{
209 unsigned long flags;
210 int csr;
211
212 mutex_lock(&viafb_dma_lock);
213 init_completion(&viafb_dma_completion);
214 /*
215 * Program the controller.
216 */
217 spin_lock_irqsave(&global_dev.reg_lock, flags);
218 viafb_mmio_write(VDMA_CSR0, VDMA_C_ENABLE|VDMA_C_DONE);
219 /* Enable ints; must happen after CSR0 write! */
220 viafb_mmio_write(VDMA_MR0, VDMA_MR_TDIE);
221 viafb_mmio_write(VDMA_MARL0, (int) (paddr & 0xfffffff0));
222 viafb_mmio_write(VDMA_MARH0, (int) ((paddr >> 28) & 0xfff));
223 /* Data sheet suggests DAR0 should be <<4, but it lies */
224 viafb_mmio_write(VDMA_DAR0, offset);
225 viafb_mmio_write(VDMA_DQWCR0, len >> 4);
226 viafb_mmio_write(VDMA_TMR0, 0);
227 viafb_mmio_write(VDMA_DPRL0, 0);
228 viafb_mmio_write(VDMA_DPRH0, 0);
229 viafb_mmio_write(VDMA_PMR0, 0);
230 csr = viafb_mmio_read(VDMA_CSR0);
231 viafb_mmio_write(VDMA_CSR0, VDMA_C_ENABLE|VDMA_C_START);
232 spin_unlock_irqrestore(&global_dev.reg_lock, flags);
233 /*
234 * Now we just wait until the interrupt handler says
235 * we're done.
236 */
237 wait_for_completion_interruptible(&viafb_dma_completion);
238 viafb_mmio_write(VDMA_MR0, 0); /* Reset int enable */
239 mutex_unlock(&viafb_dma_lock);
240}
241EXPORT_SYMBOL_GPL(viafb_dma_copy_out);
242#endif
243
244/*
245 * Do a scatter/gather DMA copy from FB memory. You must have done
246 * a successful call to viafb_request_dma() first.
247 */
248int viafb_dma_copy_out_sg(unsigned int offset, struct scatterlist *sg, int nsg)
249{
250 struct viafb_vx855_dma_descr *descr;
251 void *descrpages;
252 dma_addr_t descr_handle;
253 unsigned long flags;
254 int i;
255 struct scatterlist *sgentry;
256 dma_addr_t nextdesc;
257
258 /*
259 * Get a place to put the descriptors.
260 */
261 descrpages = dma_alloc_coherent(&global_dev.pdev->dev,
262 nsg*sizeof(struct viafb_vx855_dma_descr),
263 &descr_handle, GFP_KERNEL);
264 if (descrpages == NULL) {
265 dev_err(&global_dev.pdev->dev, "Unable to get descr page.\n");
266 return -ENOMEM;
267 }
268 mutex_lock(&viafb_dma_lock);
269 /*
270 * Fill them in.
271 */
272 descr = descrpages;
273 nextdesc = descr_handle + sizeof(struct viafb_vx855_dma_descr);
274 for_each_sg(sg, sgentry, nsg, i) {
275 dma_addr_t paddr = sg_dma_address(sgentry);
276 descr->addr_low = paddr & 0xfffffff0;
277 descr->addr_high = ((u64) paddr >> 32) & 0x0fff;
278 descr->fb_offset = offset;
279 descr->seg_size = sg_dma_len(sgentry) >> 4;
280 descr->tile_mode = 0;
281 descr->next_desc_low = (nextdesc&0xfffffff0) | VIAFB_DMA_MAGIC;
282 descr->next_desc_high = ((u64) nextdesc >> 32) & 0x0fff;
283 descr->pad = 0xffffffff; /* VIA driver does this */
284 offset += sg_dma_len(sgentry);
285 nextdesc += sizeof(struct viafb_vx855_dma_descr);
286 descr++;
287 }
288 descr[-1].next_desc_low = VIAFB_DMA_FINAL_SEGMENT|VIAFB_DMA_MAGIC;
289 /*
290 * Program the engine.
291 */
292 spin_lock_irqsave(&global_dev.reg_lock, flags);
293 init_completion(&viafb_dma_completion);
294 viafb_mmio_write(VDMA_DQWCR0, 0);
295 viafb_mmio_write(VDMA_CSR0, VDMA_C_ENABLE|VDMA_C_DONE);
296 viafb_mmio_write(VDMA_MR0, VDMA_MR_TDIE | VDMA_MR_CHAIN);
297 viafb_mmio_write(VDMA_DPRL0, descr_handle | VIAFB_DMA_MAGIC);
298 viafb_mmio_write(VDMA_DPRH0,
299 (((u64)descr_handle >> 32) & 0x0fff) | 0xf0000);
300 (void) viafb_mmio_read(VDMA_CSR0);
301 viafb_mmio_write(VDMA_CSR0, VDMA_C_ENABLE|VDMA_C_START);
302 spin_unlock_irqrestore(&global_dev.reg_lock, flags);
303 /*
304 * Now we just wait until the interrupt handler says
305 * we're done. Except that, actually, we need to wait a little
306 * longer: the interrupts seem to jump the gun a little and we
307 * get corrupted frames sometimes.
308 */
309 wait_for_completion_timeout(&viafb_dma_completion, 1);
310 msleep(1);
311 if ((viafb_mmio_read(VDMA_CSR0)&VDMA_C_DONE) == 0)
312 printk(KERN_ERR "VIA DMA timeout!\n");
313 /*
314 * Clean up and we're done.
315 */
316 viafb_mmio_write(VDMA_CSR0, VDMA_C_DONE);
317 viafb_mmio_write(VDMA_MR0, 0); /* Reset int enable */
318 mutex_unlock(&viafb_dma_lock);
319 dma_free_coherent(&global_dev.pdev->dev,
320 nsg*sizeof(struct viafb_vx855_dma_descr), descrpages,
321 descr_handle);
322 return 0;
323}
324EXPORT_SYMBOL_GPL(viafb_dma_copy_out_sg);
325
326
327/* ---------------------------------------------------------------------- */
328/*
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600329 * Figure out how big our framebuffer memory is. Kind of ugly,
330 * but evidently we can't trust the information found in the
331 * fbdev configuration area.
332 */
333static u16 via_function3[] = {
334 CLE266_FUNCTION3, KM400_FUNCTION3, CN400_FUNCTION3, CN700_FUNCTION3,
335 CX700_FUNCTION3, KM800_FUNCTION3, KM890_FUNCTION3, P4M890_FUNCTION3,
336 P4M900_FUNCTION3, VX800_FUNCTION3, VX855_FUNCTION3,
337};
338
339/* Get the BIOS-configured framebuffer size from PCI configuration space
340 * of function 3 in the respective chipset */
341static int viafb_get_fb_size_from_pci(int chip_type)
342{
343 int i;
344 u8 offset = 0;
345 u32 FBSize;
346 u32 VideoMemSize;
347
348 /* search for the "FUNCTION3" device in this chipset */
349 for (i = 0; i < ARRAY_SIZE(via_function3); i++) {
350 struct pci_dev *pdev;
351
352 pdev = pci_get_device(PCI_VENDOR_ID_VIA, via_function3[i],
353 NULL);
354 if (!pdev)
355 continue;
356
357 DEBUG_MSG(KERN_INFO "Device ID = %x\n", pdev->device);
358
359 switch (pdev->device) {
360 case CLE266_FUNCTION3:
361 case KM400_FUNCTION3:
362 offset = 0xE0;
363 break;
364 case CN400_FUNCTION3:
365 case CN700_FUNCTION3:
366 case CX700_FUNCTION3:
367 case KM800_FUNCTION3:
368 case KM890_FUNCTION3:
369 case P4M890_FUNCTION3:
370 case P4M900_FUNCTION3:
371 case VX800_FUNCTION3:
372 case VX855_FUNCTION3:
373 /*case CN750_FUNCTION3: */
374 offset = 0xA0;
375 break;
376 }
377
378 if (!offset)
379 break;
380
381 pci_read_config_dword(pdev, offset, &FBSize);
382 pci_dev_put(pdev);
383 }
384
385 if (!offset) {
386 printk(KERN_ERR "cannot determine framebuffer size\n");
387 return -EIO;
388 }
389
390 FBSize = FBSize & 0x00007000;
391 DEBUG_MSG(KERN_INFO "FB Size = %x\n", FBSize);
392
393 if (chip_type < UNICHROME_CX700) {
394 switch (FBSize) {
395 case 0x00004000:
396 VideoMemSize = (16 << 20); /*16M */
397 break;
398
399 case 0x00005000:
400 VideoMemSize = (32 << 20); /*32M */
401 break;
402
403 case 0x00006000:
404 VideoMemSize = (64 << 20); /*64M */
405 break;
406
407 default:
408 VideoMemSize = (32 << 20); /*32M */
409 break;
410 }
411 } else {
412 switch (FBSize) {
413 case 0x00001000:
414 VideoMemSize = (8 << 20); /*8M */
415 break;
416
417 case 0x00002000:
418 VideoMemSize = (16 << 20); /*16M */
419 break;
420
421 case 0x00003000:
422 VideoMemSize = (32 << 20); /*32M */
423 break;
424
425 case 0x00004000:
426 VideoMemSize = (64 << 20); /*64M */
427 break;
428
429 case 0x00005000:
430 VideoMemSize = (128 << 20); /*128M */
431 break;
432
433 case 0x00006000:
434 VideoMemSize = (256 << 20); /*256M */
435 break;
436
437 case 0x00007000: /* Only on VX855/875 */
438 VideoMemSize = (512 << 20); /*512M */
439 break;
440
441 default:
442 VideoMemSize = (32 << 20); /*32M */
443 break;
444 }
445 }
446
447 return VideoMemSize;
448}
449
450
451/*
452 * Figure out and map our MMIO regions.
453 */
454static int __devinit via_pci_setup_mmio(struct viafb_dev *vdev)
455{
Jonathan Corbet8bbf50f2010-04-30 10:03:57 -0600456 int ret;
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600457 /*
Jonathan Corbet8bbf50f2010-04-30 10:03:57 -0600458 * Hook up to the device registers. Note that we soldier
459 * on if it fails; the framebuffer can operate (without
460 * acceleration) without this region.
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600461 */
462 vdev->engine_start = pci_resource_start(vdev->pdev, 1);
463 vdev->engine_len = pci_resource_len(vdev->pdev, 1);
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600464 vdev->engine_mmio = ioremap_nocache(vdev->engine_start,
465 vdev->engine_len);
Jonathan Corbet8bbf50f2010-04-30 10:03:57 -0600466 if (vdev->engine_mmio == NULL)
467 dev_err(&vdev->pdev->dev,
468 "Unable to map engine MMIO; operation will be "
469 "slow and crippled.\n");
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600470 /*
Jonathan Corbet8bbf50f2010-04-30 10:03:57 -0600471 * Map in framebuffer memory. For now, failure here is
472 * fatal. Unfortunately, in the absence of significant
473 * vmalloc space, failure here is also entirely plausible.
474 * Eventually we want to move away from mapping this
475 * entire region.
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600476 */
477 vdev->fbmem_start = pci_resource_start(vdev->pdev, 0);
Jonathan Corbet8bbf50f2010-04-30 10:03:57 -0600478 ret = vdev->fbmem_len = viafb_get_fb_size_from_pci(vdev->chip_type);
479 if (ret < 0)
480 goto out_unmap;
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600481 vdev->fbmem = ioremap_nocache(vdev->fbmem_start, vdev->fbmem_len);
Jonathan Corbet8bbf50f2010-04-30 10:03:57 -0600482 if (vdev->fbmem == NULL) {
483 ret = -ENOMEM;
484 goto out_unmap;
485 }
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600486 return 0;
Jonathan Corbet8bbf50f2010-04-30 10:03:57 -0600487out_unmap:
488 iounmap(vdev->engine_mmio);
489 return ret;
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600490}
491
Henrik Kretzschmareca9c472010-06-17 12:01:24 +0200492static void via_pci_teardown_mmio(struct viafb_dev *vdev)
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600493{
494 iounmap(vdev->fbmem);
495 iounmap(vdev->engine_mmio);
496}
497
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600498/*
499 * Create our subsidiary devices.
500 */
501static struct viafb_subdev_info {
502 char *name;
503 struct platform_device *platdev;
504} viafb_subdevs[] = {
505 {
506 .name = "viafb-gpio",
507 },
508 {
509 .name = "viafb-i2c",
510 }
511};
512#define N_SUBDEVS ARRAY_SIZE(viafb_subdevs)
513
514static int __devinit via_create_subdev(struct viafb_dev *vdev,
515 struct viafb_subdev_info *info)
516{
517 int ret;
518
519 info->platdev = platform_device_alloc(info->name, -1);
520 if (!info->platdev) {
521 dev_err(&vdev->pdev->dev, "Unable to allocate pdev %s\n",
522 info->name);
523 return -ENOMEM;
524 }
525 info->platdev->dev.parent = &vdev->pdev->dev;
526 info->platdev->dev.platform_data = vdev;
527 ret = platform_device_add(info->platdev);
528 if (ret) {
529 dev_err(&vdev->pdev->dev, "Unable to add pdev %s\n",
530 info->name);
531 platform_device_put(info->platdev);
532 info->platdev = NULL;
533 }
534 return ret;
535}
536
537static int __devinit via_setup_subdevs(struct viafb_dev *vdev)
538{
539 int i;
540
541 /*
542 * Ignore return values. Even if some of the devices
543 * fail to be created, we'll still be able to use some
544 * of the rest.
545 */
546 for (i = 0; i < N_SUBDEVS; i++)
547 via_create_subdev(vdev, viafb_subdevs + i);
548 return 0;
549}
550
Henrik Kretzschmareca9c472010-06-17 12:01:24 +0200551static void via_teardown_subdevs(void)
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600552{
553 int i;
554
555 for (i = 0; i < N_SUBDEVS; i++)
556 if (viafb_subdevs[i].platdev) {
557 viafb_subdevs[i].platdev->dev.platform_data = NULL;
558 platform_device_unregister(viafb_subdevs[i].platdev);
559 }
560}
561
Jonathan Corbetf045f772009-12-01 20:29:39 -0700562
563static int __devinit via_pci_probe(struct pci_dev *pdev,
564 const struct pci_device_id *ent)
565{
566 int ret;
567
568 ret = pci_enable_device(pdev);
569 if (ret)
570 return ret;
571 /*
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600572 * Global device initialization.
573 */
574 memset(&global_dev, 0, sizeof(global_dev));
575 global_dev.pdev = pdev;
576 global_dev.chip_type = ent->driver_data;
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600577 global_dev.port_cfg = adap_configs;
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600578 spin_lock_init(&global_dev.reg_lock);
579 ret = via_pci_setup_mmio(&global_dev);
580 if (ret)
581 goto out_disable;
582 /*
Jonathan Corbet94dd1a82010-04-23 09:46:59 -0600583 * Set up interrupts and create our subdevices. Continue even if
584 * some things fail.
Jonathan Corbetf045f772009-12-01 20:29:39 -0700585 */
Jonathan Corbet94dd1a82010-04-23 09:46:59 -0600586 viafb_int_init();
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600587 via_setup_subdevs(&global_dev);
Jonathan Corbetf045f772009-12-01 20:29:39 -0700588 /*
Jonathan Corbet8bbf50f2010-04-30 10:03:57 -0600589 * Set up the framebuffer device
Jonathan Corbetf045f772009-12-01 20:29:39 -0700590 */
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600591 ret = via_fb_pci_probe(&global_dev);
Jonathan Corbetf045f772009-12-01 20:29:39 -0700592 if (ret)
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600593 goto out_subdevs;
Jonathan Corbetf045f772009-12-01 20:29:39 -0700594 return 0;
595
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600596out_subdevs:
597 via_teardown_subdevs();
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600598 via_pci_teardown_mmio(&global_dev);
Jonathan Corbetf045f772009-12-01 20:29:39 -0700599out_disable:
600 pci_disable_device(pdev);
601 return ret;
602}
603
604static void __devexit via_pci_remove(struct pci_dev *pdev)
605{
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600606 via_teardown_subdevs();
Jonathan Corbetf045f772009-12-01 20:29:39 -0700607 via_fb_pci_remove(pdev);
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600608 via_pci_teardown_mmio(&global_dev);
Jonathan Corbetf045f772009-12-01 20:29:39 -0700609 pci_disable_device(pdev);
610}
611
612
613static struct pci_device_id via_pci_table[] __devinitdata = {
614 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CLE266_DID),
615 .driver_data = UNICHROME_CLE266 },
Jonathan Corbetf045f772009-12-01 20:29:39 -0700616 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K400_DID),
617 .driver_data = UNICHROME_K400 },
618 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K800_DID),
619 .driver_data = UNICHROME_K800 },
Florian Tobias Schandinatad0676c2010-05-22 22:53:06 +0000620 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_PM800_DID),
621 .driver_data = UNICHROME_PM800 },
622 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CN700_DID),
Jonathan Corbetf045f772009-12-01 20:29:39 -0700623 .driver_data = UNICHROME_CN700 },
Jonathan Corbetf045f772009-12-01 20:29:39 -0700624 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CX700_DID),
625 .driver_data = UNICHROME_CX700 },
Jonathan Corbetf045f772009-12-01 20:29:39 -0700626 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CN750_DID),
627 .driver_data = UNICHROME_CN750 },
Florian Tobias Schandinatad0676c2010-05-22 22:53:06 +0000628 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K8M890_DID),
629 .driver_data = UNICHROME_K8M890 },
630 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_P4M890_DID),
631 .driver_data = UNICHROME_P4M890 },
632 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_P4M900_DID),
633 .driver_data = UNICHROME_P4M900 },
Jonathan Corbetf045f772009-12-01 20:29:39 -0700634 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_VX800_DID),
635 .driver_data = UNICHROME_VX800 },
636 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_VX855_DID),
637 .driver_data = UNICHROME_VX855 },
638 { }
639};
640MODULE_DEVICE_TABLE(pci, via_pci_table);
641
642static struct pci_driver via_driver = {
643 .name = "viafb",
644 .id_table = via_pci_table,
645 .probe = via_pci_probe,
646 .remove = __devexit_p(via_pci_remove),
647};
648
649static int __init via_core_init(void)
650{
651 int ret;
652
653 ret = viafb_init();
654 if (ret)
655 return ret;
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600656 viafb_i2c_init();
657 viafb_gpio_init();
Jonathan Corbetf045f772009-12-01 20:29:39 -0700658 return pci_register_driver(&via_driver);
659}
660
661static void __exit via_core_exit(void)
662{
663 pci_unregister_driver(&via_driver);
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600664 viafb_gpio_exit();
665 viafb_i2c_exit();
Jonathan Corbetf045f772009-12-01 20:29:39 -0700666 viafb_exit();
667}
668
669module_init(via_core_init);
670module_exit(via_core_exit);