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