linux/drivers/vme/boards/vme_vmivme7805.c
<<
>>
Prefs
   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
  22static int vmic_probe(struct pci_dev *, const struct pci_device_id *);
  23static void vmic_remove(struct pci_dev *);
  24
  25/** Base address to access FPGA register */
  26static void __iomem *vmic_base;
  27
  28static const char driver_name[] = "vmivme_7805";
  29
  30static const struct pci_device_id vmic_ids[] = {
  31        { PCI_DEVICE(PCI_VENDOR_ID_VMIC, PCI_DEVICE_ID_VTIMR) },
  32        { },
  33};
  34
  35static struct pci_driver vmic_driver = {
  36        .name = driver_name,
  37        .id_table = vmic_ids,
  38        .probe = vmic_probe,
  39        .remove = vmic_remove,
  40};
  41
  42static 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
  89err_remap:
  90        pci_release_regions(pdev);
  91err_resource:
  92        pci_disable_device(pdev);
  93err:
  94        return retval;
  95}
  96
  97static 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
 105module_pci_driver(vmic_driver);
 106
 107MODULE_DESCRIPTION("VMIVME-7805 board support driver");
 108MODULE_AUTHOR("Arthur Benilov <arthur.benilov@iba-group.com>");
 109MODULE_LICENSE("GPL");
 110
 111