mvme16x_scsi.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Detection routine for the NCR53c710 based MVME16x SCSI Controllers for Linux.
  4. *
  5. * Based on work by Alan Hourihane
  6. *
  7. * Rewritten to use 53c700.c by Kars de Jong <jongk@linux-m68k.org>
  8. */
  9. #include <linux/module.h>
  10. #include <linux/blkdev.h>
  11. #include <linux/device.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/init.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/slab.h>
  16. #include <asm/mvme16xhw.h>
  17. #include <scsi/scsi_host.h>
  18. #include <scsi/scsi_device.h>
  19. #include <scsi/scsi_transport.h>
  20. #include <scsi/scsi_transport_spi.h>
  21. #include "53c700.h"
  22. MODULE_AUTHOR("Kars de Jong <jongk@linux-m68k.org>");
  23. MODULE_DESCRIPTION("MVME16x NCR53C710 driver");
  24. MODULE_LICENSE("GPL");
  25. static struct scsi_host_template mvme16x_scsi_driver_template = {
  26. .name = "MVME16x NCR53c710 SCSI",
  27. .proc_name = "MVME16x",
  28. .this_id = 7,
  29. .module = THIS_MODULE,
  30. };
  31. static struct platform_device *mvme16x_scsi_device;
  32. static int mvme16x_probe(struct platform_device *dev)
  33. {
  34. struct Scsi_Host * host = NULL;
  35. struct NCR_700_Host_Parameters *hostdata;
  36. if (!MACH_IS_MVME16x)
  37. goto out;
  38. if (mvme16x_config & MVME16x_CONFIG_NO_SCSICHIP) {
  39. printk(KERN_INFO "mvme16x-scsi: detection disabled, "
  40. "SCSI chip not present\n");
  41. goto out;
  42. }
  43. hostdata = kzalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL);
  44. if (hostdata == NULL) {
  45. printk(KERN_ERR "mvme16x-scsi: "
  46. "Failed to allocate host data\n");
  47. goto out;
  48. }
  49. /* Fill in the required pieces of hostdata */
  50. hostdata->base = (void __iomem *)0xfff47000UL;
  51. hostdata->clock = 50; /* XXX - depends on the CPU clock! */
  52. hostdata->chip710 = 1;
  53. hostdata->dmode_extra = DMODE_FC2;
  54. hostdata->dcntl_extra = EA_710;
  55. hostdata->ctest7_extra = CTEST7_TT1;
  56. /* and register the chip */
  57. host = NCR_700_detect(&mvme16x_scsi_driver_template, hostdata,
  58. &dev->dev);
  59. if (!host) {
  60. printk(KERN_ERR "mvme16x-scsi: No host detected; "
  61. "board configuration problem?\n");
  62. goto out_free;
  63. }
  64. host->this_id = 7;
  65. host->base = 0xfff47000UL;
  66. host->irq = MVME16x_IRQ_SCSI;
  67. if (request_irq(host->irq, NCR_700_intr, 0, "mvme16x-scsi", host)) {
  68. printk(KERN_ERR "mvme16x-scsi: request_irq failed\n");
  69. goto out_put_host;
  70. }
  71. /* Enable scsi chip ints */
  72. {
  73. volatile unsigned long v;
  74. /* Enable scsi interrupts at level 4 in PCCchip2 */
  75. v = in_be32(0xfff4202c);
  76. v = (v & ~0xff) | 0x10 | 4;
  77. out_be32(0xfff4202c, v);
  78. }
  79. platform_set_drvdata(dev, host);
  80. scsi_scan_host(host);
  81. return 0;
  82. out_put_host:
  83. scsi_host_put(host);
  84. out_free:
  85. kfree(hostdata);
  86. out:
  87. return -ENODEV;
  88. }
  89. static int mvme16x_device_remove(struct platform_device *dev)
  90. {
  91. struct Scsi_Host *host = platform_get_drvdata(dev);
  92. struct NCR_700_Host_Parameters *hostdata = shost_priv(host);
  93. /* Disable scsi chip ints */
  94. {
  95. volatile unsigned long v;
  96. v = in_be32(0xfff4202c);
  97. v &= ~0x10;
  98. out_be32(0xfff4202c, v);
  99. }
  100. scsi_remove_host(host);
  101. NCR_700_release(host);
  102. kfree(hostdata);
  103. free_irq(host->irq, host);
  104. return 0;
  105. }
  106. static struct platform_driver mvme16x_scsi_driver = {
  107. .driver = {
  108. .name = "mvme16x-scsi",
  109. },
  110. .probe = mvme16x_probe,
  111. .remove = mvme16x_device_remove,
  112. };
  113. static int __init mvme16x_scsi_init(void)
  114. {
  115. int err;
  116. err = platform_driver_register(&mvme16x_scsi_driver);
  117. if (err)
  118. return err;
  119. mvme16x_scsi_device = platform_device_register_simple("mvme16x-scsi",
  120. -1, NULL, 0);
  121. if (IS_ERR(mvme16x_scsi_device)) {
  122. platform_driver_unregister(&mvme16x_scsi_driver);
  123. return PTR_ERR(mvme16x_scsi_device);
  124. }
  125. return 0;
  126. }
  127. static void __exit mvme16x_scsi_exit(void)
  128. {
  129. platform_device_unregister(mvme16x_scsi_device);
  130. platform_driver_unregister(&mvme16x_scsi_driver);
  131. }
  132. module_init(mvme16x_scsi_init);
  133. module_exit(mvme16x_scsi_exit);