vme_vmivme7805.c 2.5 KB

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