vme_vmivme7805.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #include <linux/module.h>
  13. #include <linux/types.h>
  14. #include <linux/errno.h>
  15. #include <linux/pci.h>
  16. #include <linux/poll.h>
  17. #include <linux/io.h>
  18. #include "vme_vmivme7805.h"
  19. static int vmic_probe(struct pci_dev *, const struct pci_device_id *);
  20. static void vmic_remove(struct pci_dev *);
  21. /** Base address to access FPGA register */
  22. static void __iomem *vmic_base;
  23. static const char driver_name[] = "vmivme_7805";
  24. static const struct pci_device_id vmic_ids[] = {
  25. { PCI_DEVICE(PCI_VENDOR_ID_VMIC, PCI_DEVICE_ID_VTIMR) },
  26. { },
  27. };
  28. static struct pci_driver vmic_driver = {
  29. .name = driver_name,
  30. .id_table = vmic_ids,
  31. .probe = vmic_probe,
  32. .remove = vmic_remove,
  33. };
  34. static int vmic_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  35. {
  36. int retval;
  37. u32 data;
  38. /* Enable the device */
  39. retval = pci_enable_device(pdev);
  40. if (retval) {
  41. dev_err(&pdev->dev, "Unable to enable device\n");
  42. goto err;
  43. }
  44. /* Map Registers */
  45. retval = pci_request_regions(pdev, driver_name);
  46. if (retval) {
  47. dev_err(&pdev->dev, "Unable to reserve resources\n");
  48. goto err_resource;
  49. }
  50. /* Map registers in BAR 0 */
  51. vmic_base = ioremap_nocache(pci_resource_start(pdev, 0), 16);
  52. if (!vmic_base) {
  53. dev_err(&pdev->dev, "Unable to remap CRG region\n");
  54. retval = -EIO;
  55. goto err_remap;
  56. }
  57. /* Clear the FPGA VME IF contents */
  58. iowrite32(0, vmic_base + VME_CONTROL);
  59. /* Clear any initial BERR */
  60. data = ioread32(vmic_base + VME_CONTROL) & 0x00000FFF;
  61. data |= BM_VME_CONTROL_BERRST;
  62. iowrite32(data, vmic_base + VME_CONTROL);
  63. /* Enable the vme interface and byte swapping */
  64. data = ioread32(vmic_base + VME_CONTROL) & 0x00000FFF;
  65. data = data | BM_VME_CONTROL_MASTER_ENDIAN |
  66. BM_VME_CONTROL_SLAVE_ENDIAN |
  67. BM_VME_CONTROL_ABLE |
  68. BM_VME_CONTROL_BERRI |
  69. BM_VME_CONTROL_BPENA |
  70. BM_VME_CONTROL_VBENA;
  71. iowrite32(data, vmic_base + VME_CONTROL);
  72. return 0;
  73. err_remap:
  74. pci_release_regions(pdev);
  75. err_resource:
  76. pci_disable_device(pdev);
  77. err:
  78. return retval;
  79. }
  80. static void vmic_remove(struct pci_dev *pdev)
  81. {
  82. iounmap(vmic_base);
  83. pci_release_regions(pdev);
  84. pci_disable_device(pdev);
  85. }
  86. module_pci_driver(vmic_driver);
  87. MODULE_DESCRIPTION("VMIVME-7805 board support driver");
  88. MODULE_AUTHOR("Arthur Benilov <arthur.benilov@iba-group.com>");
  89. MODULE_LICENSE("GPL");