vme_vmivme7805.c 2.9 KB

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