oak.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * Oak Generic NCR5380 driver
  3. *
  4. * Copyright 1995-2002, Russell King
  5. */
  6. #include <linux/module.h>
  7. #include <linux/ioport.h>
  8. #include <linux/blkdev.h>
  9. #include <linux/init.h>
  10. #include <asm/ecard.h>
  11. #include <asm/io.h>
  12. #include <scsi/scsi_host.h>
  13. #define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
  14. #define NCR5380_read(reg) \
  15. readb(priv(instance)->base + ((reg) << 2))
  16. #define NCR5380_write(reg, value) \
  17. writeb(value, priv(instance)->base + ((reg) << 2))
  18. #define NCR5380_dma_xfer_len(instance, cmd, phase) (0)
  19. #define NCR5380_dma_recv_setup oakscsi_pread
  20. #define NCR5380_dma_send_setup oakscsi_pwrite
  21. #define NCR5380_dma_residual(instance) (0)
  22. #define NCR5380_queue_command oakscsi_queue_command
  23. #define NCR5380_info oakscsi_info
  24. #define NCR5380_implementation_fields \
  25. void __iomem *base
  26. #include "../NCR5380.h"
  27. #undef START_DMA_INITIATOR_RECEIVE_REG
  28. #define START_DMA_INITIATOR_RECEIVE_REG (128 + 7)
  29. #define STAT ((128 + 16) << 2)
  30. #define DATA ((128 + 8) << 2)
  31. static inline int oakscsi_pwrite(struct Scsi_Host *instance,
  32. unsigned char *addr, int len)
  33. {
  34. void __iomem *base = priv(instance)->base;
  35. printk("writing %p len %d\n",addr, len);
  36. while(1)
  37. {
  38. int status;
  39. while (((status = readw(base + STAT)) & 0x100)==0);
  40. }
  41. return 0;
  42. }
  43. static inline int oakscsi_pread(struct Scsi_Host *instance,
  44. unsigned char *addr, int len)
  45. {
  46. void __iomem *base = priv(instance)->base;
  47. printk("reading %p len %d\n", addr, len);
  48. while(len > 0)
  49. {
  50. unsigned int status, timeout;
  51. unsigned long b;
  52. timeout = 0x01FFFFFF;
  53. while (((status = readw(base + STAT)) & 0x100)==0)
  54. {
  55. timeout--;
  56. if(status & 0x200 || !timeout)
  57. {
  58. printk("status = %08X\n", status);
  59. return -1;
  60. }
  61. }
  62. if(len >= 128)
  63. {
  64. readsw(base + DATA, addr, 128);
  65. addr += 128;
  66. len -= 128;
  67. }
  68. else
  69. {
  70. b = (unsigned long) readw(base + DATA);
  71. *addr ++ = b;
  72. len -= 1;
  73. if(len)
  74. *addr ++ = b>>8;
  75. len -= 1;
  76. }
  77. }
  78. return 0;
  79. }
  80. #undef STAT
  81. #undef DATA
  82. #include "../NCR5380.c"
  83. static struct scsi_host_template oakscsi_template = {
  84. .module = THIS_MODULE,
  85. .name = "Oak 16-bit SCSI",
  86. .info = oakscsi_info,
  87. .queuecommand = oakscsi_queue_command,
  88. .eh_abort_handler = NCR5380_abort,
  89. .eh_bus_reset_handler = NCR5380_bus_reset,
  90. .can_queue = 16,
  91. .this_id = 7,
  92. .sg_tablesize = SG_ALL,
  93. .cmd_per_lun = 2,
  94. .use_clustering = DISABLE_CLUSTERING,
  95. .proc_name = "oakscsi",
  96. .cmd_size = NCR5380_CMD_SIZE,
  97. .max_sectors = 128,
  98. };
  99. static int oakscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
  100. {
  101. struct Scsi_Host *host;
  102. int ret = -ENOMEM;
  103. ret = ecard_request_resources(ec);
  104. if (ret)
  105. goto out;
  106. host = scsi_host_alloc(&oakscsi_template, sizeof(struct NCR5380_hostdata));
  107. if (!host) {
  108. ret = -ENOMEM;
  109. goto release;
  110. }
  111. priv(host)->base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
  112. ecard_resource_len(ec, ECARD_RES_MEMC));
  113. if (!priv(host)->base) {
  114. ret = -ENOMEM;
  115. goto unreg;
  116. }
  117. host->irq = NO_IRQ;
  118. host->n_io_port = 255;
  119. ret = NCR5380_init(host, FLAG_DMA_FIXUP | FLAG_LATE_DMA_SETUP);
  120. if (ret)
  121. goto out_unmap;
  122. NCR5380_maybe_reset_bus(host);
  123. ret = scsi_add_host(host, &ec->dev);
  124. if (ret)
  125. goto out_exit;
  126. scsi_scan_host(host);
  127. goto out;
  128. out_exit:
  129. NCR5380_exit(host);
  130. out_unmap:
  131. iounmap(priv(host)->base);
  132. unreg:
  133. scsi_host_put(host);
  134. release:
  135. ecard_release_resources(ec);
  136. out:
  137. return ret;
  138. }
  139. static void oakscsi_remove(struct expansion_card *ec)
  140. {
  141. struct Scsi_Host *host = ecard_get_drvdata(ec);
  142. ecard_set_drvdata(ec, NULL);
  143. scsi_remove_host(host);
  144. NCR5380_exit(host);
  145. iounmap(priv(host)->base);
  146. scsi_host_put(host);
  147. ecard_release_resources(ec);
  148. }
  149. static const struct ecard_id oakscsi_cids[] = {
  150. { MANU_OAK, PROD_OAK_SCSI },
  151. { 0xffff, 0xffff }
  152. };
  153. static struct ecard_driver oakscsi_driver = {
  154. .probe = oakscsi_probe,
  155. .remove = oakscsi_remove,
  156. .id_table = oakscsi_cids,
  157. .drv = {
  158. .name = "oakscsi",
  159. },
  160. };
  161. static int __init oakscsi_init(void)
  162. {
  163. return ecard_register_driver(&oakscsi_driver);
  164. }
  165. static void __exit oakscsi_exit(void)
  166. {
  167. ecard_remove_driver(&oakscsi_driver);
  168. }
  169. module_init(oakscsi_init);
  170. module_exit(oakscsi_exit);
  171. MODULE_AUTHOR("Russell King");
  172. MODULE_DESCRIPTION("Oak SCSI driver");
  173. MODULE_LICENSE("GPL");