mvme16x_scsi.c 3.7 KB

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