cumana_1.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /*
  2. * Generic 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) cumanascsi_read(instance, reg)
  15. #define NCR5380_write(reg, value) cumanascsi_write(instance, reg, value)
  16. #define NCR5380_dma_xfer_len(instance, cmd, phase) (cmd->transfersize)
  17. #define NCR5380_dma_recv_setup cumanascsi_pread
  18. #define NCR5380_dma_send_setup cumanascsi_pwrite
  19. #define NCR5380_dma_residual(instance) (0)
  20. #define NCR5380_intr cumanascsi_intr
  21. #define NCR5380_queue_command cumanascsi_queue_command
  22. #define NCR5380_info cumanascsi_info
  23. #define NCR5380_implementation_fields \
  24. unsigned ctrl; \
  25. void __iomem *base; \
  26. void __iomem *dma
  27. #include "../NCR5380.h"
  28. void cumanascsi_setup(char *str, int *ints)
  29. {
  30. }
  31. #define CTRL 0x16fc
  32. #define STAT 0x2004
  33. #define L(v) (((v)<<16)|((v) & 0x0000ffff))
  34. #define H(v) (((v)>>16)|((v) & 0xffff0000))
  35. static inline int cumanascsi_pwrite(struct Scsi_Host *host,
  36. unsigned char *addr, int len)
  37. {
  38. unsigned long *laddr;
  39. void __iomem *dma = priv(host)->dma + 0x2000;
  40. if(!len) return 0;
  41. writeb(0x02, priv(host)->base + CTRL);
  42. laddr = (unsigned long *)addr;
  43. while(len >= 32)
  44. {
  45. unsigned int status;
  46. unsigned long v;
  47. status = readb(priv(host)->base + STAT);
  48. if(status & 0x80)
  49. goto end;
  50. if(!(status & 0x40))
  51. continue;
  52. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  53. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  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. len -= 32;
  61. if(len == 0)
  62. break;
  63. }
  64. addr = (unsigned char *)laddr;
  65. writeb(0x12, priv(host)->base + CTRL);
  66. while(len > 0)
  67. {
  68. unsigned int status;
  69. status = readb(priv(host)->base + STAT);
  70. if(status & 0x80)
  71. goto end;
  72. if(status & 0x40)
  73. {
  74. writeb(*addr++, dma);
  75. if(--len == 0)
  76. break;
  77. }
  78. status = readb(priv(host)->base + STAT);
  79. if(status & 0x80)
  80. goto end;
  81. if(status & 0x40)
  82. {
  83. writeb(*addr++, dma);
  84. if(--len == 0)
  85. break;
  86. }
  87. }
  88. end:
  89. writeb(priv(host)->ctrl | 0x40, priv(host)->base + CTRL);
  90. if (len)
  91. return -1;
  92. return 0;
  93. }
  94. static inline int cumanascsi_pread(struct Scsi_Host *host,
  95. 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. if (len)
  149. return -1;
  150. return 0;
  151. }
  152. static unsigned char cumanascsi_read(struct Scsi_Host *host, unsigned int reg)
  153. {
  154. void __iomem *base = priv(host)->base;
  155. unsigned char val;
  156. writeb(0, base + CTRL);
  157. val = readb(base + 0x2100 + (reg << 2));
  158. priv(host)->ctrl = 0x40;
  159. writeb(0x40, base + CTRL);
  160. return val;
  161. }
  162. static void cumanascsi_write(struct Scsi_Host *host, unsigned int reg, unsigned int value)
  163. {
  164. void __iomem *base = priv(host)->base;
  165. writeb(0, base + CTRL);
  166. writeb(value, base + 0x2100 + (reg << 2));
  167. priv(host)->ctrl = 0x40;
  168. writeb(0x40, base + CTRL);
  169. }
  170. #include "../NCR5380.c"
  171. static struct scsi_host_template cumanascsi_template = {
  172. .module = THIS_MODULE,
  173. .name = "Cumana 16-bit SCSI",
  174. .info = cumanascsi_info,
  175. .queuecommand = cumanascsi_queue_command,
  176. .eh_abort_handler = NCR5380_abort,
  177. .eh_bus_reset_handler = NCR5380_bus_reset,
  178. .can_queue = 16,
  179. .this_id = 7,
  180. .sg_tablesize = SG_ALL,
  181. .cmd_per_lun = 2,
  182. .use_clustering = DISABLE_CLUSTERING,
  183. .proc_name = "CumanaSCSI-1",
  184. .cmd_size = NCR5380_CMD_SIZE,
  185. .max_sectors = 128,
  186. };
  187. static int cumanascsi1_probe(struct expansion_card *ec,
  188. const struct ecard_id *id)
  189. {
  190. struct Scsi_Host *host;
  191. int ret;
  192. ret = ecard_request_resources(ec);
  193. if (ret)
  194. goto out;
  195. host = scsi_host_alloc(&cumanascsi_template, sizeof(struct NCR5380_hostdata));
  196. if (!host) {
  197. ret = -ENOMEM;
  198. goto out_release;
  199. }
  200. priv(host)->base = ioremap(ecard_resource_start(ec, ECARD_RES_IOCSLOW),
  201. ecard_resource_len(ec, ECARD_RES_IOCSLOW));
  202. priv(host)->dma = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
  203. ecard_resource_len(ec, ECARD_RES_MEMC));
  204. if (!priv(host)->base || !priv(host)->dma) {
  205. ret = -ENOMEM;
  206. goto out_unmap;
  207. }
  208. host->irq = ec->irq;
  209. ret = NCR5380_init(host, FLAG_DMA_FIXUP | FLAG_LATE_DMA_SETUP);
  210. if (ret)
  211. goto out_unmap;
  212. NCR5380_maybe_reset_bus(host);
  213. priv(host)->ctrl = 0;
  214. writeb(0, priv(host)->base + CTRL);
  215. ret = request_irq(host->irq, cumanascsi_intr, 0,
  216. "CumanaSCSI-1", host);
  217. if (ret) {
  218. printk("scsi%d: IRQ%d not free: %d\n",
  219. host->host_no, host->irq, ret);
  220. goto out_exit;
  221. }
  222. ret = scsi_add_host(host, &ec->dev);
  223. if (ret)
  224. goto out_free_irq;
  225. scsi_scan_host(host);
  226. goto out;
  227. out_free_irq:
  228. free_irq(host->irq, host);
  229. out_exit:
  230. NCR5380_exit(host);
  231. out_unmap:
  232. iounmap(priv(host)->base);
  233. iounmap(priv(host)->dma);
  234. scsi_host_put(host);
  235. out_release:
  236. ecard_release_resources(ec);
  237. out:
  238. return ret;
  239. }
  240. static void cumanascsi1_remove(struct expansion_card *ec)
  241. {
  242. struct Scsi_Host *host = ecard_get_drvdata(ec);
  243. ecard_set_drvdata(ec, NULL);
  244. scsi_remove_host(host);
  245. free_irq(host->irq, host);
  246. NCR5380_exit(host);
  247. iounmap(priv(host)->base);
  248. iounmap(priv(host)->dma);
  249. scsi_host_put(host);
  250. ecard_release_resources(ec);
  251. }
  252. static const struct ecard_id cumanascsi1_cids[] = {
  253. { MANU_CUMANA, PROD_CUMANA_SCSI_1 },
  254. { 0xffff, 0xffff }
  255. };
  256. static struct ecard_driver cumanascsi1_driver = {
  257. .probe = cumanascsi1_probe,
  258. .remove = cumanascsi1_remove,
  259. .id_table = cumanascsi1_cids,
  260. .drv = {
  261. .name = "cumanascsi1",
  262. },
  263. };
  264. static int __init cumanascsi_init(void)
  265. {
  266. return ecard_register_driver(&cumanascsi1_driver);
  267. }
  268. static void __exit cumanascsi_exit(void)
  269. {
  270. ecard_remove_driver(&cumanascsi1_driver);
  271. }
  272. module_init(cumanascsi_init);
  273. module_exit(cumanascsi_exit);
  274. MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
  275. MODULE_LICENSE("GPL");