cumana_1.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. * Generic 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. #include <scsi/scsicam.h>
  16. #define PSEUDO_DMA
  17. #define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
  18. #define NCR5380_local_declare() struct Scsi_Host *_instance
  19. #define NCR5380_setup(instance) _instance = instance
  20. #define NCR5380_read(reg) cumanascsi_read(_instance, reg)
  21. #define NCR5380_write(reg, value) cumanascsi_write(_instance, reg, value)
  22. #define NCR5380_intr cumanascsi_intr
  23. #define NCR5380_queue_command cumanascsi_queue_command
  24. #define NCR5380_info cumanascsi_info
  25. #define NCR5380_implementation_fields \
  26. unsigned ctrl; \
  27. void __iomem *base; \
  28. void __iomem *dma
  29. #include "../NCR5380.h"
  30. void cumanascsi_setup(char *str, int *ints)
  31. {
  32. }
  33. #define CTRL 0x16fc
  34. #define STAT 0x2004
  35. #define L(v) (((v)<<16)|((v) & 0x0000ffff))
  36. #define H(v) (((v)>>16)|((v) & 0xffff0000))
  37. static inline int
  38. NCR5380_pwrite(struct Scsi_Host *host, unsigned char *addr, int len)
  39. {
  40. unsigned long *laddr;
  41. void __iomem *dma = priv(host)->dma + 0x2000;
  42. if(!len) return 0;
  43. writeb(0x02, priv(host)->base + CTRL);
  44. laddr = (unsigned long *)addr;
  45. while(len >= 32)
  46. {
  47. unsigned int status;
  48. unsigned long v;
  49. status = readb(priv(host)->base + STAT);
  50. if(status & 0x80)
  51. goto end;
  52. if(!(status & 0x40))
  53. continue;
  54. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  55. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  56. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  57. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  58. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  59. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  60. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  61. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  62. len -= 32;
  63. if(len == 0)
  64. break;
  65. }
  66. addr = (unsigned char *)laddr;
  67. writeb(0x12, priv(host)->base + CTRL);
  68. while(len > 0)
  69. {
  70. unsigned int status;
  71. status = readb(priv(host)->base + STAT);
  72. if(status & 0x80)
  73. goto end;
  74. if(status & 0x40)
  75. {
  76. writeb(*addr++, dma);
  77. if(--len == 0)
  78. break;
  79. }
  80. status = readb(priv(host)->base + STAT);
  81. if(status & 0x80)
  82. goto end;
  83. if(status & 0x40)
  84. {
  85. writeb(*addr++, dma);
  86. if(--len == 0)
  87. break;
  88. }
  89. }
  90. end:
  91. writeb(priv(host)->ctrl | 0x40, priv(host)->base + CTRL);
  92. return len;
  93. }
  94. static inline int
  95. NCR5380_pread(struct Scsi_Host *host, unsigned char *addr, int len)
  96. {
  97. unsigned long *laddr;
  98. void __iomem *dma = priv(host)->dma + 0x2000;
  99. if(!len) return 0;
  100. writeb(0x00, priv(host)->base + CTRL);
  101. laddr = (unsigned long *)addr;
  102. while(len >= 32)
  103. {
  104. unsigned int status;
  105. status = readb(priv(host)->base + STAT);
  106. if(status & 0x80)
  107. goto end;
  108. if(!(status & 0x40))
  109. continue;
  110. *laddr++ = readw(dma) | (readw(dma) << 16);
  111. *laddr++ = readw(dma) | (readw(dma) << 16);
  112. *laddr++ = readw(dma) | (readw(dma) << 16);
  113. *laddr++ = readw(dma) | (readw(dma) << 16);
  114. *laddr++ = readw(dma) | (readw(dma) << 16);
  115. *laddr++ = readw(dma) | (readw(dma) << 16);
  116. *laddr++ = readw(dma) | (readw(dma) << 16);
  117. *laddr++ = readw(dma) | (readw(dma) << 16);
  118. len -= 32;
  119. if(len == 0)
  120. break;
  121. }
  122. addr = (unsigned char *)laddr;
  123. writeb(0x10, priv(host)->base + CTRL);
  124. while(len > 0)
  125. {
  126. unsigned int status;
  127. status = readb(priv(host)->base + STAT);
  128. if(status & 0x80)
  129. goto end;
  130. if(status & 0x40)
  131. {
  132. *addr++ = readb(dma);
  133. if(--len == 0)
  134. break;
  135. }
  136. status = readb(priv(host)->base + STAT);
  137. if(status & 0x80)
  138. goto end;
  139. if(status & 0x40)
  140. {
  141. *addr++ = readb(dma);
  142. if(--len == 0)
  143. break;
  144. }
  145. }
  146. end:
  147. writeb(priv(host)->ctrl | 0x40, priv(host)->base + CTRL);
  148. return len;
  149. }
  150. static unsigned char cumanascsi_read(struct Scsi_Host *host, unsigned int reg)
  151. {
  152. void __iomem *base = priv(host)->base;
  153. unsigned char val;
  154. writeb(0, base + CTRL);
  155. val = readb(base + 0x2100 + (reg << 2));
  156. priv(host)->ctrl = 0x40;
  157. writeb(0x40, base + CTRL);
  158. return val;
  159. }
  160. static void cumanascsi_write(struct Scsi_Host *host, unsigned int reg, unsigned int value)
  161. {
  162. void __iomem *base = priv(host)->base;
  163. writeb(0, base + CTRL);
  164. writeb(value, base + 0x2100 + (reg << 2));
  165. priv(host)->ctrl = 0x40;
  166. writeb(0x40, base + CTRL);
  167. }
  168. #include "../NCR5380.c"
  169. static struct scsi_host_template cumanascsi_template = {
  170. .module = THIS_MODULE,
  171. .name = "Cumana 16-bit SCSI",
  172. .info = cumanascsi_info,
  173. .queuecommand = cumanascsi_queue_command,
  174. .eh_abort_handler = NCR5380_abort,
  175. .eh_bus_reset_handler = NCR5380_bus_reset,
  176. .can_queue = 16,
  177. .this_id = 7,
  178. .sg_tablesize = SG_ALL,
  179. .cmd_per_lun = 2,
  180. .use_clustering = DISABLE_CLUSTERING,
  181. .proc_name = "CumanaSCSI-1",
  182. };
  183. static int cumanascsi1_probe(struct expansion_card *ec,
  184. const struct ecard_id *id)
  185. {
  186. struct Scsi_Host *host;
  187. int ret;
  188. ret = ecard_request_resources(ec);
  189. if (ret)
  190. goto out;
  191. host = scsi_host_alloc(&cumanascsi_template, sizeof(struct NCR5380_hostdata));
  192. if (!host) {
  193. ret = -ENOMEM;
  194. goto out_release;
  195. }
  196. priv(host)->base = ioremap(ecard_resource_start(ec, ECARD_RES_IOCSLOW),
  197. ecard_resource_len(ec, ECARD_RES_IOCSLOW));
  198. priv(host)->dma = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
  199. ecard_resource_len(ec, ECARD_RES_MEMC));
  200. if (!priv(host)->base || !priv(host)->dma) {
  201. ret = -ENOMEM;
  202. goto out_unmap;
  203. }
  204. host->irq = ec->irq;
  205. NCR5380_init(host, 0);
  206. priv(host)->ctrl = 0;
  207. writeb(0, priv(host)->base + CTRL);
  208. host->n_io_port = 255;
  209. if (!(request_region(host->io_port, host->n_io_port, "CumanaSCSI-1"))) {
  210. ret = -EBUSY;
  211. goto out_unmap;
  212. }
  213. ret = request_irq(host->irq, cumanascsi_intr, 0,
  214. "CumanaSCSI-1", host);
  215. if (ret) {
  216. printk("scsi%d: IRQ%d not free: %d\n",
  217. host->host_no, host->irq, ret);
  218. goto out_unmap;
  219. }
  220. ret = scsi_add_host(host, &ec->dev);
  221. if (ret)
  222. goto out_free_irq;
  223. scsi_scan_host(host);
  224. goto out;
  225. out_free_irq:
  226. free_irq(host->irq, host);
  227. out_unmap:
  228. iounmap(priv(host)->base);
  229. iounmap(priv(host)->dma);
  230. scsi_host_put(host);
  231. out_release:
  232. ecard_release_resources(ec);
  233. out:
  234. return ret;
  235. }
  236. static void cumanascsi1_remove(struct expansion_card *ec)
  237. {
  238. struct Scsi_Host *host = ecard_get_drvdata(ec);
  239. ecard_set_drvdata(ec, NULL);
  240. scsi_remove_host(host);
  241. free_irq(host->irq, host);
  242. NCR5380_exit(host);
  243. iounmap(priv(host)->base);
  244. iounmap(priv(host)->dma);
  245. scsi_host_put(host);
  246. ecard_release_resources(ec);
  247. }
  248. static const struct ecard_id cumanascsi1_cids[] = {
  249. { MANU_CUMANA, PROD_CUMANA_SCSI_1 },
  250. { 0xffff, 0xffff }
  251. };
  252. static struct ecard_driver cumanascsi1_driver = {
  253. .probe = cumanascsi1_probe,
  254. .remove = cumanascsi1_remove,
  255. .id_table = cumanascsi1_cids,
  256. .drv = {
  257. .name = "cumanascsi1",
  258. },
  259. };
  260. static int __init cumanascsi_init(void)
  261. {
  262. return ecard_register_driver(&cumanascsi1_driver);
  263. }
  264. static void __exit cumanascsi_exit(void)
  265. {
  266. ecard_remove_driver(&cumanascsi1_driver);
  267. }
  268. module_init(cumanascsi_init);
  269. module_exit(cumanascsi_exit);
  270. MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
  271. MODULE_LICENSE("GPL");