cumana_1.c 7.8 KB

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