blob: a3aa917095038d4afa8515a2d79d1184520e8c6e [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[] = {
Florian Tobias Schandinatee40b7d2010-09-17 01:56:18 +000023 [VIA_PORT_26] = { VIA_PORT_I2C, VIA_MODE_I2C, VIASR, 0x26 },
Jonathan Corbetf045f772009-12-01 20:29:39 -070024 [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/*
Jonathan Corbet024fafbac2010-10-19 21:32:11 -030098 * Currently, the camera driver is the only user of the DMA code, so we
99 * only compile it in if the camera driver is being built. Chances are,
100 * most viafb systems will not need to have this extra code for a while.
101 * As soon as another user comes long, the ifdef can be removed.
102 */
103#if defined(CONFIG_VIDEO_VIA_CAMERA) || defined(CONFIG_VIDEO_VIA_CAMERA_MODULE)
104/*
Jonathan Corbet3d28eb42010-04-23 10:04:12 -0600105 * Access to the DMA engine. This currently provides what the camera
106 * driver needs (i.e. outgoing only) but is easily expandable if need
107 * be.
108 */
Jonathan Corbet94dd1a82010-04-23 09:46:59 -0600109
110/*
Jonathan Corbet3d28eb42010-04-23 10:04:12 -0600111 * There are four DMA channels in the vx855. For now, we only
112 * use one of them, though. Most of the time, the DMA channel
113 * will be idle, so we keep the IRQ handler unregistered except
114 * when some subsystem has indicated an interest.
115 */
116static int viafb_dma_users;
117static DECLARE_COMPLETION(viafb_dma_completion);
118/*
119 * This mutex protects viafb_dma_users and our global interrupt
120 * registration state; it also serializes access to the DMA
121 * engine.
122 */
123static DEFINE_MUTEX(viafb_dma_lock);
124
125/*
126 * The VX855 DMA descriptor (used for s/g transfers) looks
127 * like this.
128 */
129struct viafb_vx855_dma_descr {
130 u32 addr_low; /* Low part of phys addr */
131 u32 addr_high; /* High 12 bits of addr */
132 u32 fb_offset; /* Offset into FB memory */
133 u32 seg_size; /* Size, 16-byte units */
134 u32 tile_mode; /* "tile mode" setting */
135 u32 next_desc_low; /* Next descriptor addr */
136 u32 next_desc_high;
137 u32 pad; /* Fill out to 64 bytes */
138};
139
140/*
141 * Flags added to the "next descriptor low" pointers
142 */
143#define VIAFB_DMA_MAGIC 0x01 /* ??? Just has to be there */
144#define VIAFB_DMA_FINAL_SEGMENT 0x02 /* Final segment */
145
146/*
147 * The completion IRQ handler.
148 */
149static irqreturn_t viafb_dma_irq(int irq, void *data)
150{
151 int csr;
152 irqreturn_t ret = IRQ_NONE;
153
154 spin_lock(&global_dev.reg_lock);
155 csr = viafb_mmio_read(VDMA_CSR0);
156 if (csr & VDMA_C_DONE) {
157 viafb_mmio_write(VDMA_CSR0, VDMA_C_DONE);
158 complete(&viafb_dma_completion);
159 ret = IRQ_HANDLED;
160 }
161 spin_unlock(&global_dev.reg_lock);
162 return ret;
163}
164
165/*
166 * Indicate a need for DMA functionality.
167 */
168int viafb_request_dma(void)
169{
170 int ret = 0;
171
172 /*
173 * Only VX855 is supported currently.
174 */
175 if (global_dev.chip_type != UNICHROME_VX855)
176 return -ENODEV;
177 /*
178 * Note the new user and set up our interrupt handler
179 * if need be.
180 */
181 mutex_lock(&viafb_dma_lock);
182 viafb_dma_users++;
183 if (viafb_dma_users == 1) {
184 ret = request_irq(global_dev.pdev->irq, viafb_dma_irq,
185 IRQF_SHARED, "via-dma", &viafb_dma_users);
186 if (ret)
187 viafb_dma_users--;
188 else
189 viafb_irq_enable(VDE_I_DMA0TDEN);
190 }
191 mutex_unlock(&viafb_dma_lock);
192 return ret;
193}
194EXPORT_SYMBOL_GPL(viafb_request_dma);
195
196void viafb_release_dma(void)
197{
198 mutex_lock(&viafb_dma_lock);
199 viafb_dma_users--;
200 if (viafb_dma_users == 0) {
201 viafb_irq_disable(VDE_I_DMA0TDEN);
202 free_irq(global_dev.pdev->irq, &viafb_dma_users);
203 }
204 mutex_unlock(&viafb_dma_lock);
205}
206EXPORT_SYMBOL_GPL(viafb_release_dma);
207
208
209#if 0
210/*
211 * Copy a single buffer from FB memory, synchronously. This code works
212 * but is not currently used.
213 */
214void viafb_dma_copy_out(unsigned int offset, dma_addr_t paddr, int len)
215{
216 unsigned long flags;
217 int csr;
218
219 mutex_lock(&viafb_dma_lock);
220 init_completion(&viafb_dma_completion);
221 /*
222 * Program the controller.
223 */
224 spin_lock_irqsave(&global_dev.reg_lock, flags);
225 viafb_mmio_write(VDMA_CSR0, VDMA_C_ENABLE|VDMA_C_DONE);
226 /* Enable ints; must happen after CSR0 write! */
227 viafb_mmio_write(VDMA_MR0, VDMA_MR_TDIE);
228 viafb_mmio_write(VDMA_MARL0, (int) (paddr & 0xfffffff0));
229 viafb_mmio_write(VDMA_MARH0, (int) ((paddr >> 28) & 0xfff));
230 /* Data sheet suggests DAR0 should be <<4, but it lies */
231 viafb_mmio_write(VDMA_DAR0, offset);
232 viafb_mmio_write(VDMA_DQWCR0, len >> 4);
233 viafb_mmio_write(VDMA_TMR0, 0);
234 viafb_mmio_write(VDMA_DPRL0, 0);
235 viafb_mmio_write(VDMA_DPRH0, 0);
236 viafb_mmio_write(VDMA_PMR0, 0);
237 csr = viafb_mmio_read(VDMA_CSR0);
238 viafb_mmio_write(VDMA_CSR0, VDMA_C_ENABLE|VDMA_C_START);
239 spin_unlock_irqrestore(&global_dev.reg_lock, flags);
240 /*
241 * Now we just wait until the interrupt handler says
242 * we're done.
243 */
244 wait_for_completion_interruptible(&viafb_dma_completion);
245 viafb_mmio_write(VDMA_MR0, 0); /* Reset int enable */
246 mutex_unlock(&viafb_dma_lock);
247}
248EXPORT_SYMBOL_GPL(viafb_dma_copy_out);
249#endif
250
251/*
252 * Do a scatter/gather DMA copy from FB memory. You must have done
253 * a successful call to viafb_request_dma() first.
254 */
255int viafb_dma_copy_out_sg(unsigned int offset, struct scatterlist *sg, int nsg)
256{
257 struct viafb_vx855_dma_descr *descr;
258 void *descrpages;
259 dma_addr_t descr_handle;
260 unsigned long flags;
261 int i;
262 struct scatterlist *sgentry;
263 dma_addr_t nextdesc;
264
265 /*
266 * Get a place to put the descriptors.
267 */
268 descrpages = dma_alloc_coherent(&global_dev.pdev->dev,
269 nsg*sizeof(struct viafb_vx855_dma_descr),
270 &descr_handle, GFP_KERNEL);
271 if (descrpages == NULL) {
272 dev_err(&global_dev.pdev->dev, "Unable to get descr page.\n");
273 return -ENOMEM;
274 }
275 mutex_lock(&viafb_dma_lock);
276 /*
277 * Fill them in.
278 */
279 descr = descrpages;
280 nextdesc = descr_handle + sizeof(struct viafb_vx855_dma_descr);
281 for_each_sg(sg, sgentry, nsg, i) {
282 dma_addr_t paddr = sg_dma_address(sgentry);
283 descr->addr_low = paddr & 0xfffffff0;
284 descr->addr_high = ((u64) paddr >> 32) & 0x0fff;
285 descr->fb_offset = offset;
286 descr->seg_size = sg_dma_len(sgentry) >> 4;
287 descr->tile_mode = 0;
288 descr->next_desc_low = (nextdesc&0xfffffff0) | VIAFB_DMA_MAGIC;
289 descr->next_desc_high = ((u64) nextdesc >> 32) & 0x0fff;
290 descr->pad = 0xffffffff; /* VIA driver does this */
291 offset += sg_dma_len(sgentry);
292 nextdesc += sizeof(struct viafb_vx855_dma_descr);
293 descr++;
294 }
295 descr[-1].next_desc_low = VIAFB_DMA_FINAL_SEGMENT|VIAFB_DMA_MAGIC;
296 /*
297 * Program the engine.
298 */
299 spin_lock_irqsave(&global_dev.reg_lock, flags);
300 init_completion(&viafb_dma_completion);
301 viafb_mmio_write(VDMA_DQWCR0, 0);
302 viafb_mmio_write(VDMA_CSR0, VDMA_C_ENABLE|VDMA_C_DONE);
303 viafb_mmio_write(VDMA_MR0, VDMA_MR_TDIE | VDMA_MR_CHAIN);
304 viafb_mmio_write(VDMA_DPRL0, descr_handle | VIAFB_DMA_MAGIC);
305 viafb_mmio_write(VDMA_DPRH0,
306 (((u64)descr_handle >> 32) & 0x0fff) | 0xf0000);
307 (void) viafb_mmio_read(VDMA_CSR0);
308 viafb_mmio_write(VDMA_CSR0, VDMA_C_ENABLE|VDMA_C_START);
309 spin_unlock_irqrestore(&global_dev.reg_lock, flags);
310 /*
311 * Now we just wait until the interrupt handler says
312 * we're done. Except that, actually, we need to wait a little
313 * longer: the interrupts seem to jump the gun a little and we
314 * get corrupted frames sometimes.
315 */
316 wait_for_completion_timeout(&viafb_dma_completion, 1);
317 msleep(1);
318 if ((viafb_mmio_read(VDMA_CSR0)&VDMA_C_DONE) == 0)
319 printk(KERN_ERR "VIA DMA timeout!\n");
320 /*
321 * Clean up and we're done.
322 */
323 viafb_mmio_write(VDMA_CSR0, VDMA_C_DONE);
324 viafb_mmio_write(VDMA_MR0, 0); /* Reset int enable */
325 mutex_unlock(&viafb_dma_lock);
326 dma_free_coherent(&global_dev.pdev->dev,
327 nsg*sizeof(struct viafb_vx855_dma_descr), descrpages,
328 descr_handle);
329 return 0;
330}
331EXPORT_SYMBOL_GPL(viafb_dma_copy_out_sg);
Jonathan Corbet024fafbac2010-10-19 21:32:11 -0300332#endif /* CONFIG_VIDEO_VIA_CAMERA */
Jonathan Corbet3d28eb42010-04-23 10:04:12 -0600333
334/* ---------------------------------------------------------------------- */
335/*
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600336 * Figure out how big our framebuffer memory is. Kind of ugly,
337 * but evidently we can't trust the information found in the
338 * fbdev configuration area.
339 */
340static u16 via_function3[] = {
341 CLE266_FUNCTION3, KM400_FUNCTION3, CN400_FUNCTION3, CN700_FUNCTION3,
342 CX700_FUNCTION3, KM800_FUNCTION3, KM890_FUNCTION3, P4M890_FUNCTION3,
Florian Tobias Schandinat51f43322010-10-24 04:02:14 +0000343 P4M900_FUNCTION3, VX800_FUNCTION3, VX855_FUNCTION3, VX900_FUNCTION3,
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600344};
345
346/* Get the BIOS-configured framebuffer size from PCI configuration space
347 * of function 3 in the respective chipset */
348static int viafb_get_fb_size_from_pci(int chip_type)
349{
350 int i;
351 u8 offset = 0;
352 u32 FBSize;
353 u32 VideoMemSize;
354
355 /* search for the "FUNCTION3" device in this chipset */
356 for (i = 0; i < ARRAY_SIZE(via_function3); i++) {
357 struct pci_dev *pdev;
358
359 pdev = pci_get_device(PCI_VENDOR_ID_VIA, via_function3[i],
360 NULL);
361 if (!pdev)
362 continue;
363
364 DEBUG_MSG(KERN_INFO "Device ID = %x\n", pdev->device);
365
366 switch (pdev->device) {
367 case CLE266_FUNCTION3:
368 case KM400_FUNCTION3:
369 offset = 0xE0;
370 break;
371 case CN400_FUNCTION3:
372 case CN700_FUNCTION3:
373 case CX700_FUNCTION3:
374 case KM800_FUNCTION3:
375 case KM890_FUNCTION3:
376 case P4M890_FUNCTION3:
377 case P4M900_FUNCTION3:
378 case VX800_FUNCTION3:
379 case VX855_FUNCTION3:
Florian Tobias Schandinat51f43322010-10-24 04:02:14 +0000380 case VX900_FUNCTION3:
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600381 /*case CN750_FUNCTION3: */
382 offset = 0xA0;
383 break;
384 }
385
386 if (!offset)
387 break;
388
389 pci_read_config_dword(pdev, offset, &FBSize);
390 pci_dev_put(pdev);
391 }
392
393 if (!offset) {
394 printk(KERN_ERR "cannot determine framebuffer size\n");
395 return -EIO;
396 }
397
398 FBSize = FBSize & 0x00007000;
399 DEBUG_MSG(KERN_INFO "FB Size = %x\n", FBSize);
400
401 if (chip_type < UNICHROME_CX700) {
402 switch (FBSize) {
403 case 0x00004000:
404 VideoMemSize = (16 << 20); /*16M */
405 break;
406
407 case 0x00005000:
408 VideoMemSize = (32 << 20); /*32M */
409 break;
410
411 case 0x00006000:
412 VideoMemSize = (64 << 20); /*64M */
413 break;
414
415 default:
416 VideoMemSize = (32 << 20); /*32M */
417 break;
418 }
419 } else {
420 switch (FBSize) {
421 case 0x00001000:
422 VideoMemSize = (8 << 20); /*8M */
423 break;
424
425 case 0x00002000:
426 VideoMemSize = (16 << 20); /*16M */
427 break;
428
429 case 0x00003000:
430 VideoMemSize = (32 << 20); /*32M */
431 break;
432
433 case 0x00004000:
434 VideoMemSize = (64 << 20); /*64M */
435 break;
436
437 case 0x00005000:
438 VideoMemSize = (128 << 20); /*128M */
439 break;
440
441 case 0x00006000:
442 VideoMemSize = (256 << 20); /*256M */
443 break;
444
445 case 0x00007000: /* Only on VX855/875 */
446 VideoMemSize = (512 << 20); /*512M */
447 break;
448
449 default:
450 VideoMemSize = (32 << 20); /*32M */
451 break;
452 }
453 }
454
455 return VideoMemSize;
456}
457
458
459/*
460 * Figure out and map our MMIO regions.
461 */
462static int __devinit via_pci_setup_mmio(struct viafb_dev *vdev)
463{
Jonathan Corbet8bbf50f2010-04-30 10:03:57 -0600464 int ret;
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600465 /*
Jonathan Corbet8bbf50f2010-04-30 10:03:57 -0600466 * Hook up to the device registers. Note that we soldier
467 * on if it fails; the framebuffer can operate (without
468 * acceleration) without this region.
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600469 */
470 vdev->engine_start = pci_resource_start(vdev->pdev, 1);
471 vdev->engine_len = pci_resource_len(vdev->pdev, 1);
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600472 vdev->engine_mmio = ioremap_nocache(vdev->engine_start,
473 vdev->engine_len);
Jonathan Corbet8bbf50f2010-04-30 10:03:57 -0600474 if (vdev->engine_mmio == NULL)
475 dev_err(&vdev->pdev->dev,
476 "Unable to map engine MMIO; operation will be "
477 "slow and crippled.\n");
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600478 /*
Jonathan Corbet8bbf50f2010-04-30 10:03:57 -0600479 * Map in framebuffer memory. For now, failure here is
480 * fatal. Unfortunately, in the absence of significant
481 * vmalloc space, failure here is also entirely plausible.
482 * Eventually we want to move away from mapping this
483 * entire region.
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600484 */
Florian Tobias Schandinat51f43322010-10-24 04:02:14 +0000485 if (vdev->chip_type == UNICHROME_VX900)
486 vdev->fbmem_start = pci_resource_start(vdev->pdev, 2);
487 else
488 vdev->fbmem_start = pci_resource_start(vdev->pdev, 0);
Jonathan Corbet8bbf50f2010-04-30 10:03:57 -0600489 ret = vdev->fbmem_len = viafb_get_fb_size_from_pci(vdev->chip_type);
490 if (ret < 0)
491 goto out_unmap;
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600492 vdev->fbmem = ioremap_nocache(vdev->fbmem_start, vdev->fbmem_len);
Jonathan Corbet8bbf50f2010-04-30 10:03:57 -0600493 if (vdev->fbmem == NULL) {
494 ret = -ENOMEM;
495 goto out_unmap;
496 }
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600497 return 0;
Jonathan Corbet8bbf50f2010-04-30 10:03:57 -0600498out_unmap:
499 iounmap(vdev->engine_mmio);
500 return ret;
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600501}
502
Henrik Kretzschmareca9c472010-06-17 12:01:24 +0200503static void via_pci_teardown_mmio(struct viafb_dev *vdev)
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600504{
505 iounmap(vdev->fbmem);
506 iounmap(vdev->engine_mmio);
507}
508
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600509/*
510 * Create our subsidiary devices.
511 */
512static struct viafb_subdev_info {
513 char *name;
514 struct platform_device *platdev;
515} viafb_subdevs[] = {
516 {
517 .name = "viafb-gpio",
518 },
519 {
520 .name = "viafb-i2c",
Jonathan Corbet024fafbac2010-10-19 21:32:11 -0300521 },
522#if defined(CONFIG_VIDEO_VIA_CAMERA) || defined(CONFIG_VIDEO_VIA_CAMERA_MODULE)
523 {
524 .name = "viafb-camera",
525 },
526#endif
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600527};
528#define N_SUBDEVS ARRAY_SIZE(viafb_subdevs)
529
530static int __devinit via_create_subdev(struct viafb_dev *vdev,
531 struct viafb_subdev_info *info)
532{
533 int ret;
534
535 info->platdev = platform_device_alloc(info->name, -1);
536 if (!info->platdev) {
537 dev_err(&vdev->pdev->dev, "Unable to allocate pdev %s\n",
538 info->name);
539 return -ENOMEM;
540 }
541 info->platdev->dev.parent = &vdev->pdev->dev;
542 info->platdev->dev.platform_data = vdev;
543 ret = platform_device_add(info->platdev);
544 if (ret) {
545 dev_err(&vdev->pdev->dev, "Unable to add pdev %s\n",
546 info->name);
547 platform_device_put(info->platdev);
548 info->platdev = NULL;
549 }
550 return ret;
551}
552
553static int __devinit via_setup_subdevs(struct viafb_dev *vdev)
554{
555 int i;
556
557 /*
558 * Ignore return values. Even if some of the devices
559 * fail to be created, we'll still be able to use some
560 * of the rest.
561 */
562 for (i = 0; i < N_SUBDEVS; i++)
563 via_create_subdev(vdev, viafb_subdevs + i);
564 return 0;
565}
566
Henrik Kretzschmareca9c472010-06-17 12:01:24 +0200567static void via_teardown_subdevs(void)
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600568{
569 int i;
570
571 for (i = 0; i < N_SUBDEVS; i++)
572 if (viafb_subdevs[i].platdev) {
573 viafb_subdevs[i].platdev->dev.platform_data = NULL;
574 platform_device_unregister(viafb_subdevs[i].platdev);
575 }
576}
577
Jonathan Corbetf045f772009-12-01 20:29:39 -0700578
579static int __devinit via_pci_probe(struct pci_dev *pdev,
580 const struct pci_device_id *ent)
581{
582 int ret;
583
584 ret = pci_enable_device(pdev);
585 if (ret)
586 return ret;
587 /*
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600588 * Global device initialization.
589 */
590 memset(&global_dev, 0, sizeof(global_dev));
591 global_dev.pdev = pdev;
592 global_dev.chip_type = ent->driver_data;
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600593 global_dev.port_cfg = adap_configs;
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600594 spin_lock_init(&global_dev.reg_lock);
595 ret = via_pci_setup_mmio(&global_dev);
596 if (ret)
597 goto out_disable;
598 /*
Jonathan Corbet94dd1a82010-04-23 09:46:59 -0600599 * Set up interrupts and create our subdevices. Continue even if
600 * some things fail.
Jonathan Corbetf045f772009-12-01 20:29:39 -0700601 */
Jonathan Corbet94dd1a82010-04-23 09:46:59 -0600602 viafb_int_init();
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600603 via_setup_subdevs(&global_dev);
Jonathan Corbetf045f772009-12-01 20:29:39 -0700604 /*
Jonathan Corbet8bbf50f2010-04-30 10:03:57 -0600605 * Set up the framebuffer device
Jonathan Corbetf045f772009-12-01 20:29:39 -0700606 */
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600607 ret = via_fb_pci_probe(&global_dev);
Jonathan Corbetf045f772009-12-01 20:29:39 -0700608 if (ret)
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600609 goto out_subdevs;
Jonathan Corbetf045f772009-12-01 20:29:39 -0700610 return 0;
611
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600612out_subdevs:
613 via_teardown_subdevs();
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600614 via_pci_teardown_mmio(&global_dev);
Jonathan Corbetf045f772009-12-01 20:29:39 -0700615out_disable:
616 pci_disable_device(pdev);
617 return ret;
618}
619
620static void __devexit via_pci_remove(struct pci_dev *pdev)
621{
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600622 via_teardown_subdevs();
Jonathan Corbetf045f772009-12-01 20:29:39 -0700623 via_fb_pci_remove(pdev);
Jonathan Corbet24b4d822010-04-22 13:48:09 -0600624 via_pci_teardown_mmio(&global_dev);
Jonathan Corbetf045f772009-12-01 20:29:39 -0700625 pci_disable_device(pdev);
626}
627
628
629static struct pci_device_id via_pci_table[] __devinitdata = {
630 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CLE266_DID),
631 .driver_data = UNICHROME_CLE266 },
Jonathan Corbetf045f772009-12-01 20:29:39 -0700632 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K400_DID),
633 .driver_data = UNICHROME_K400 },
634 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K800_DID),
635 .driver_data = UNICHROME_K800 },
Florian Tobias Schandinatad0676c2010-05-22 22:53:06 +0000636 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_PM800_DID),
637 .driver_data = UNICHROME_PM800 },
638 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CN700_DID),
Jonathan Corbetf045f772009-12-01 20:29:39 -0700639 .driver_data = UNICHROME_CN700 },
Jonathan Corbetf045f772009-12-01 20:29:39 -0700640 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CX700_DID),
641 .driver_data = UNICHROME_CX700 },
Jonathan Corbetf045f772009-12-01 20:29:39 -0700642 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CN750_DID),
643 .driver_data = UNICHROME_CN750 },
Florian Tobias Schandinatad0676c2010-05-22 22:53:06 +0000644 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K8M890_DID),
645 .driver_data = UNICHROME_K8M890 },
646 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_P4M890_DID),
647 .driver_data = UNICHROME_P4M890 },
648 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_P4M900_DID),
649 .driver_data = UNICHROME_P4M900 },
Jonathan Corbetf045f772009-12-01 20:29:39 -0700650 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_VX800_DID),
651 .driver_data = UNICHROME_VX800 },
652 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_VX855_DID),
653 .driver_data = UNICHROME_VX855 },
Florian Tobias Schandinat51f43322010-10-24 04:02:14 +0000654 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_VX900_DID),
655 .driver_data = UNICHROME_VX900 },
Jonathan Corbetf045f772009-12-01 20:29:39 -0700656 { }
657};
658MODULE_DEVICE_TABLE(pci, via_pci_table);
659
660static struct pci_driver via_driver = {
661 .name = "viafb",
662 .id_table = via_pci_table,
663 .probe = via_pci_probe,
664 .remove = __devexit_p(via_pci_remove),
Deepak Saxena3fd9b6c2010-04-08 11:15:41 -0600665#ifdef CONFIG_PM
666 .suspend = viafb_suspend,
667 .resume = viafb_resume,
668#endif
Jonathan Corbetf045f772009-12-01 20:29:39 -0700669};
670
671static int __init via_core_init(void)
672{
673 int ret;
674
675 ret = viafb_init();
676 if (ret)
677 return ret;
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600678 viafb_i2c_init();
679 viafb_gpio_init();
Jonathan Corbetf045f772009-12-01 20:29:39 -0700680 return pci_register_driver(&via_driver);
681}
682
683static void __exit via_core_exit(void)
684{
685 pci_unregister_driver(&via_driver);
Jonathan Corbet7582eb92010-04-22 17:39:34 -0600686 viafb_gpio_exit();
687 viafb_i2c_exit();
Jonathan Corbetf045f772009-12-01 20:29:39 -0700688 viafb_exit();
689}
690
691module_init(via_core_init);
692module_exit(via_core_exit);