mvme147.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/types.h>
  3. #include <linux/mm.h>
  4. #include <linux/blkdev.h>
  5. #include <linux/interrupt.h>
  6. #include <linux/init.h>
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <asm/page.h>
  10. #include <asm/pgtable.h>
  11. #include <asm/mvme147hw.h>
  12. #include <asm/irq.h>
  13. #include "scsi.h"
  14. #include <scsi/scsi_host.h>
  15. #include "wd33c93.h"
  16. #include "mvme147.h"
  17. static irqreturn_t mvme147_intr(int irq, void *data)
  18. {
  19. struct Scsi_Host *instance = data;
  20. if (irq == MVME147_IRQ_SCSI_PORT)
  21. wd33c93_intr(instance);
  22. else
  23. m147_pcc->dma_intr = 0x89; /* Ack and enable ints */
  24. return IRQ_HANDLED;
  25. }
  26. static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
  27. {
  28. struct Scsi_Host *instance = cmd->device->host;
  29. struct WD33C93_hostdata *hdata = shost_priv(instance);
  30. unsigned char flags = 0x01;
  31. unsigned long addr = virt_to_bus(cmd->SCp.ptr);
  32. /* setup dma direction */
  33. if (!dir_in)
  34. flags |= 0x04;
  35. /* remember direction */
  36. hdata->dma_dir = dir_in;
  37. if (dir_in) {
  38. /* invalidate any cache */
  39. cache_clear(addr, cmd->SCp.this_residual);
  40. } else {
  41. /* push any dirty cache */
  42. cache_push(addr, cmd->SCp.this_residual);
  43. }
  44. /* start DMA */
  45. m147_pcc->dma_bcr = cmd->SCp.this_residual | (1 << 24);
  46. m147_pcc->dma_dadr = addr;
  47. m147_pcc->dma_cntrl = flags;
  48. /* return success */
  49. return 0;
  50. }
  51. static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
  52. int status)
  53. {
  54. m147_pcc->dma_cntrl = 0;
  55. }
  56. static struct scsi_host_template mvme147_host_template = {
  57. .module = THIS_MODULE,
  58. .proc_name = "MVME147",
  59. .name = "MVME147 built-in SCSI",
  60. .queuecommand = wd33c93_queuecommand,
  61. .eh_abort_handler = wd33c93_abort,
  62. .eh_host_reset_handler = wd33c93_host_reset,
  63. .show_info = wd33c93_show_info,
  64. .write_info = wd33c93_write_info,
  65. .can_queue = CAN_QUEUE,
  66. .this_id = 7,
  67. .sg_tablesize = SG_ALL,
  68. .cmd_per_lun = CMD_PER_LUN,
  69. .use_clustering = ENABLE_CLUSTERING
  70. };
  71. static struct Scsi_Host *mvme147_shost;
  72. static int __init mvme147_init(void)
  73. {
  74. wd33c93_regs regs;
  75. struct WD33C93_hostdata *hdata;
  76. int error = -ENOMEM;
  77. if (!MACH_IS_MVME147)
  78. return 0;
  79. mvme147_shost = scsi_host_alloc(&mvme147_host_template,
  80. sizeof(struct WD33C93_hostdata));
  81. if (!mvme147_shost)
  82. goto err_out;
  83. mvme147_shost->base = 0xfffe4000;
  84. mvme147_shost->irq = MVME147_IRQ_SCSI_PORT;
  85. regs.SASR = (volatile unsigned char *)0xfffe4000;
  86. regs.SCMD = (volatile unsigned char *)0xfffe4001;
  87. hdata = shost_priv(mvme147_shost);
  88. hdata->no_sync = 0xff;
  89. hdata->fast = 0;
  90. hdata->dma_mode = CTRL_DMA;
  91. wd33c93_init(mvme147_shost, regs, dma_setup, dma_stop, WD33C93_FS_8_10);
  92. error = request_irq(MVME147_IRQ_SCSI_PORT, mvme147_intr, 0,
  93. "MVME147 SCSI PORT", mvme147_shost);
  94. if (error)
  95. goto err_unregister;
  96. error = request_irq(MVME147_IRQ_SCSI_DMA, mvme147_intr, 0,
  97. "MVME147 SCSI DMA", mvme147_shost);
  98. if (error)
  99. goto err_free_irq;
  100. #if 0 /* Disabled; causes problems booting */
  101. m147_pcc->scsi_interrupt = 0x10; /* Assert SCSI bus reset */
  102. udelay(100);
  103. m147_pcc->scsi_interrupt = 0x00; /* Negate SCSI bus reset */
  104. udelay(2000);
  105. m147_pcc->scsi_interrupt = 0x40; /* Clear bus reset interrupt */
  106. #endif
  107. m147_pcc->scsi_interrupt = 0x09; /* Enable interrupt */
  108. m147_pcc->dma_cntrl = 0x00; /* ensure DMA is stopped */
  109. m147_pcc->dma_intr = 0x89; /* Ack and enable ints */
  110. error = scsi_add_host(mvme147_shost, NULL);
  111. if (error)
  112. goto err_free_irq;
  113. scsi_scan_host(mvme147_shost);
  114. return 0;
  115. err_free_irq:
  116. free_irq(MVME147_IRQ_SCSI_PORT, mvme147_shost);
  117. err_unregister:
  118. scsi_host_put(mvme147_shost);
  119. err_out:
  120. return error;
  121. }
  122. static void __exit mvme147_exit(void)
  123. {
  124. scsi_remove_host(mvme147_shost);
  125. /* XXX Make sure DMA is stopped! */
  126. free_irq(MVME147_IRQ_SCSI_PORT, mvme147_shost);
  127. free_irq(MVME147_IRQ_SCSI_DMA, mvme147_shost);
  128. scsi_host_put(mvme147_shost);
  129. }
  130. module_init(mvme147_init);
  131. module_exit(mvme147_exit);