15 #include <linux/module.h>
18 #include <linux/list.h>
57 static inline void viafb_mmio_write(
int reg,
u32 v)
59 iowrite32(v, global_dev.engine_mmio + reg);
62 static inline int viafb_mmio_read(
int reg)
64 return ioread32(global_dev.engine_mmio + reg);
81 static u32 viafb_enabled_ints;
83 static void __devinit viafb_int_init(
void)
85 viafb_enabled_ints = 0;
96 viafb_enabled_ints |=
mask;
103 viafb_enabled_ints &= ~mask;
104 if (viafb_enabled_ints == 0)
119 #if defined(CONFIG_VIDEO_VIA_CAMERA) || defined(CONFIG_VIDEO_VIA_CAMERA_MODULE)
132 static int viafb_dma_users;
145 struct viafb_vx855_dma_descr {
159 #define VIAFB_DMA_MAGIC 0x01
160 #define VIAFB_DMA_FINAL_SEGMENT 0x02
170 spin_lock(&global_dev.reg_lock);
171 csr = viafb_mmio_read(VDMA_CSR0);
172 if (csr & VDMA_C_DONE) {
173 viafb_mmio_write(VDMA_CSR0, VDMA_C_DONE);
177 spin_unlock(&global_dev.reg_lock);
184 int viafb_request_dma(
void)
199 if (viafb_dma_users == 1) {
200 ret =
request_irq(global_dev.pdev->irq, viafb_dma_irq,
212 void viafb_release_dma(
void)
216 if (viafb_dma_users == 0) {
218 free_irq(global_dev.pdev->irq, &viafb_dma_users);
236 init_completion(&viafb_dma_completion);
241 viafb_mmio_write(VDMA_CSR0, VDMA_C_ENABLE|VDMA_C_DONE);
243 viafb_mmio_write(VDMA_MR0, VDMA_MR_TDIE);
244 viafb_mmio_write(VDMA_MARL0, (
int) (paddr & 0xfffffff0));
245 viafb_mmio_write(VDMA_MARH0, (
int) ((paddr >> 28) & 0xfff));
247 viafb_mmio_write(VDMA_DAR0, offset);
248 viafb_mmio_write(VDMA_DQWCR0, len >> 4);
249 viafb_mmio_write(VDMA_TMR0, 0);
250 viafb_mmio_write(VDMA_DPRL0, 0);
251 viafb_mmio_write(VDMA_DPRH0, 0);
252 viafb_mmio_write(VDMA_PMR0, 0);
253 csr = viafb_mmio_read(VDMA_CSR0);
254 viafb_mmio_write(VDMA_CSR0, VDMA_C_ENABLE|VDMA_C_START);
255 spin_unlock_irqrestore(&global_dev.reg_lock, flags);
261 viafb_mmio_write(VDMA_MR0, 0);
271 int viafb_dma_copy_out_sg(
unsigned int offset,
struct scatterlist *
sg,
int nsg)
273 struct viafb_vx855_dma_descr *
descr;
285 nsg*
sizeof(
struct viafb_vx855_dma_descr),
287 if (descrpages ==
NULL) {
288 dev_err(&global_dev.pdev->dev,
"Unable to get descr page.\n");
296 nextdesc = descr_handle +
sizeof(
struct viafb_vx855_dma_descr);
299 descr->addr_low = paddr & 0xfffffff0;
300 descr->addr_high = ((
u64) paddr >> 32) & 0x0fff;
301 descr->fb_offset =
offset;
303 descr->tile_mode = 0;
304 descr->next_desc_low = (nextdesc&0xfffffff0) | VIAFB_DMA_MAGIC;
305 descr->next_desc_high = ((
u64) nextdesc >> 32) & 0x0fff;
306 descr->pad = 0xffffffff;
308 nextdesc +=
sizeof(
struct viafb_vx855_dma_descr);
311 descr[-1].next_desc_low = VIAFB_DMA_FINAL_SEGMENT|VIAFB_DMA_MAGIC;
316 init_completion(&viafb_dma_completion);
317 viafb_mmio_write(VDMA_DQWCR0, 0);
318 viafb_mmio_write(VDMA_CSR0, VDMA_C_ENABLE|VDMA_C_DONE);
319 viafb_mmio_write(VDMA_MR0, VDMA_MR_TDIE | VDMA_MR_CHAIN);
320 viafb_mmio_write(VDMA_DPRL0, descr_handle | VIAFB_DMA_MAGIC);
321 viafb_mmio_write(VDMA_DPRH0,
322 (((
u64)descr_handle >> 32) & 0x0fff) | 0xf0000);
323 (
void) viafb_mmio_read(VDMA_CSR0);
324 viafb_mmio_write(VDMA_CSR0, VDMA_C_ENABLE|VDMA_C_START);
325 spin_unlock_irqrestore(&global_dev.reg_lock, flags);
334 if ((viafb_mmio_read(VDMA_CSR0)&VDMA_C_DONE) == 0)
339 viafb_mmio_write(VDMA_CSR0, VDMA_C_DONE);
340 viafb_mmio_write(VDMA_MR0, 0);
343 nsg*
sizeof(
struct viafb_vx855_dma_descr), descrpages,
356 static u16 via_function3[] = {
364 static int viafb_get_fb_size_from_pci(
int chip_type)
372 for (i = 0; i <
ARRAY_SIZE(via_function3); i++) {
405 pci_read_config_dword(pdev, offset, &FBSize);
414 FBSize = FBSize & 0x00007000;
420 VideoMemSize = (16 << 20);
424 VideoMemSize = (32 << 20);
428 VideoMemSize = (64 << 20);
432 VideoMemSize = (32 << 20);
438 VideoMemSize = (8 << 20);
442 VideoMemSize = (16 << 20);
446 VideoMemSize = (32 << 20);
450 VideoMemSize = (64 << 20);
454 VideoMemSize = (128 << 20);
458 VideoMemSize = (256 << 20);
462 VideoMemSize = (512 << 20);
466 VideoMemSize = (32 << 20);
492 "Unable to map engine MMIO; operation will be "
493 "slow and crippled.\n");
526 static void via_pci_teardown_mmio(
struct viafb_dev *vdev)
535 static struct viafb_subdev_info {
538 } viafb_subdevs[] = {
540 .name =
"viafb-gpio",
545 #if defined(CONFIG_VIDEO_VIA_CAMERA) || defined(CONFIG_VIDEO_VIA_CAMERA_MODULE)
547 .name =
"viafb-camera",
551 #define N_SUBDEVS ARRAY_SIZE(viafb_subdevs)
554 struct viafb_subdev_info *
info)
559 if (!info->platdev) {
560 dev_err(&vdev->
pdev->dev,
"Unable to allocate pdev %s\n",
564 info->platdev->dev.parent = &vdev->
pdev->dev;
565 info->platdev->dev.platform_data = vdev;
568 dev_err(&vdev->
pdev->dev,
"Unable to add pdev %s\n",
571 info->platdev =
NULL;
586 via_create_subdev(vdev, viafb_subdevs + i);
590 static void via_teardown_subdevs(
void)
595 if (viafb_subdevs[i].platdev) {
596 viafb_subdevs[
i].platdev->dev.platform_data =
NULL;
608 void viafb_pm_register(
struct viafb_pm_hooks *
hooks)
610 INIT_LIST_HEAD(&hooks->list);
618 void viafb_pm_unregister(
struct viafb_pm_hooks *
hooks)
628 struct viafb_pm_hooks *
hooks;
643 hooks->
suspend(hooks->private);
654 struct viafb_pm_hooks *hooks;
667 hooks->
resume(hooks->private);
686 memset(&global_dev, 0,
sizeof(global_dev));
687 global_dev.pdev = pdev;
689 global_dev.port_cfg = adap_configs;
690 if (machine_is_olpc())
691 global_dev.port_cfg = olpc_adap_configs;
694 ret = via_pci_setup_mmio(&global_dev);
702 via_setup_subdevs(&global_dev);
712 via_teardown_subdevs();
713 via_pci_teardown_mmio(&global_dev);
721 via_teardown_subdevs();
723 via_pci_teardown_mmio(&global_dev);
761 .id_table = via_pci_table,
762 .probe = via_pci_probe,
765 .suspend = via_suspend,
766 .resume = via_resume,
770 static int __init via_core_init(
void)
779 return pci_register_driver(&via_driver);
782 static void __exit via_core_exit(
void)