Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / vme / boards / vme_vmivme7805.c
1 /*
2  * Support for the VMIVME-7805 board access to the Universe II bridge.
3  *
4  * Author: Arthur Benilov <arthur.benilov@iba-group.com>
5  * Copyright 2010 Ion Beam Application, Inc.
6  *
7  * This program is free software; you can redistribute  it and/or modify it
8  * under  the terms of  the GNU General  Public License as published by the
9  * Free Software Foundation;  either version 2 of the  License, or (at your
10  * option) any later version.
11  */
12
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/errno.h>
16 #include <linux/pci.h>
17 #include <linux/poll.h>
18 #include <linux/io.h>
19
20 #include "vme_vmivme7805.h"
21
22 static int vmic_probe(struct pci_dev *, const struct pci_device_id *);
23 static void vmic_remove(struct pci_dev *);
24
25 /** Base address to access FPGA register */
26 static void __iomem *vmic_base;
27
28 static const char driver_name[] = "vmivme_7805";
29
30 static const struct pci_device_id vmic_ids[] = {
31         { PCI_DEVICE(PCI_VENDOR_ID_VMIC, PCI_DEVICE_ID_VTIMR) },
32         { },
33 };
34
35 static struct pci_driver vmic_driver = {
36         .name = driver_name,
37         .id_table = vmic_ids,
38         .probe = vmic_probe,
39         .remove = vmic_remove,
40 };
41
42 static int vmic_probe(struct pci_dev *pdev, const struct pci_device_id *id)
43 {
44         int retval;
45         u32 data;
46
47         /* Enable the device */
48         retval = pci_enable_device(pdev);
49         if (retval) {
50                 dev_err(&pdev->dev, "Unable to enable device\n");
51                 goto err;
52         }
53
54         /* Map Registers */
55         retval = pci_request_regions(pdev, driver_name);
56         if (retval) {
57                 dev_err(&pdev->dev, "Unable to reserve resources\n");
58                 goto err_resource;
59         }
60
61         /* Map registers in BAR 0 */
62         vmic_base = ioremap_nocache(pci_resource_start(pdev, 0), 16);
63         if (!vmic_base) {
64                 dev_err(&pdev->dev, "Unable to remap CRG region\n");
65                 retval = -EIO;
66                 goto err_remap;
67         }
68
69         /* Clear the FPGA VME IF contents */
70         iowrite32(0, vmic_base + VME_CONTROL);
71
72         /* Clear any initial BERR  */
73         data = ioread32(vmic_base + VME_CONTROL) & 0x00000FFF;
74         data |= BM_VME_CONTROL_BERRST;
75         iowrite32(data, vmic_base + VME_CONTROL);
76
77         /* Enable the vme interface and byte swapping */
78         data = ioread32(vmic_base + VME_CONTROL) & 0x00000FFF;
79         data = data | BM_VME_CONTROL_MASTER_ENDIAN |
80                         BM_VME_CONTROL_SLAVE_ENDIAN |
81                         BM_VME_CONTROL_ABLE |
82                         BM_VME_CONTROL_BERRI |
83                         BM_VME_CONTROL_BPENA |
84                         BM_VME_CONTROL_VBENA;
85         iowrite32(data, vmic_base + VME_CONTROL);
86
87         return 0;
88
89 err_remap:
90         pci_release_regions(pdev);
91 err_resource:
92         pci_disable_device(pdev);
93 err:
94         return retval;
95 }
96
97 static void vmic_remove(struct pci_dev *pdev)
98 {
99         iounmap(vmic_base);
100         pci_release_regions(pdev);
101         pci_disable_device(pdev);
102
103 }
104
105 module_pci_driver(vmic_driver);
106
107 MODULE_DESCRIPTION("VMIVME-7805 board support driver");
108 MODULE_AUTHOR("Arthur Benilov <arthur.benilov@iba-group.com>");
109 MODULE_LICENSE("GPL");
110