oak.c 4.2 KB

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