fdomain_isa.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/module.h>
  3. #include <linux/io.h>
  4. #include <linux/isa.h>
  5. #include <scsi/scsi_host.h>
  6. #include "fdomain.h"
  7. #define MAXBOARDS_PARAM 4
  8. static int io[MAXBOARDS_PARAM] = { 0, 0, 0, 0 };
  9. module_param_hw_array(io, int, ioport, NULL, 0);
  10. MODULE_PARM_DESC(io, "base I/O address of controller (0x140, 0x150, 0x160, 0x170)");
  11. static int irq[MAXBOARDS_PARAM] = { 0, 0, 0, 0 };
  12. module_param_hw_array(irq, int, irq, NULL, 0);
  13. MODULE_PARM_DESC(irq, "IRQ of controller (0=auto [default])");
  14. static int scsi_id[MAXBOARDS_PARAM] = { 0, 0, 0, 0 };
  15. module_param_hw_array(scsi_id, int, other, NULL, 0);
  16. MODULE_PARM_DESC(scsi_id, "SCSI ID of controller (default = 7)");
  17. static unsigned long addresses[] = {
  18. 0xc8000,
  19. 0xca000,
  20. 0xce000,
  21. 0xde000,
  22. };
  23. #define ADDRESS_COUNT ARRAY_SIZE(addresses)
  24. static unsigned short ports[] = { 0x140, 0x150, 0x160, 0x170 };
  25. #define PORT_COUNT ARRAY_SIZE(ports)
  26. static unsigned short irqs[] = { 3, 5, 10, 11, 12, 14, 15, 0 };
  27. /* This driver works *ONLY* for Future Domain cards using the TMC-1800,
  28. * TMC-18C50, or TMC-18C30 chip. This includes models TMC-1650, 1660, 1670,
  29. * and 1680. These are all 16-bit cards.
  30. * BIOS versions prior to 3.2 assigned SCSI ID 6 to SCSI adapter.
  31. *
  32. * The following BIOS signature signatures are for boards which do *NOT*
  33. * work with this driver (these TMC-8xx and TMC-9xx boards may work with the
  34. * Seagate driver):
  35. *
  36. * FUTURE DOMAIN CORP. (C) 1986-1988 V4.0I 03/16/88
  37. * FUTURE DOMAIN CORP. (C) 1986-1989 V5.0C2/14/89
  38. * FUTURE DOMAIN CORP. (C) 1986-1989 V6.0A7/28/89
  39. * FUTURE DOMAIN CORP. (C) 1986-1990 V6.0105/31/90
  40. * FUTURE DOMAIN CORP. (C) 1986-1990 V6.0209/18/90
  41. * FUTURE DOMAIN CORP. (C) 1986-1990 V7.009/18/90
  42. * FUTURE DOMAIN CORP. (C) 1992 V8.00.004/02/92
  43. *
  44. * (The cards which do *NOT* work are all 8-bit cards -- although some of
  45. * them have a 16-bit form-factor, the upper 8-bits are used only for IRQs
  46. * and are *NOT* used for data. You can tell the difference by following
  47. * the tracings on the circuit board -- if only the IRQ lines are involved,
  48. * you have a "8-bit" card, and should *NOT* use this driver.)
  49. */
  50. static struct signature {
  51. const char *signature;
  52. int offset;
  53. int length;
  54. int this_id;
  55. int base_offset;
  56. } signatures[] = {
  57. /* 1 2 3 4 5 6 */
  58. /* 123456789012345678901234567890123456789012345678901234567890 */
  59. { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.07/28/89", 5, 50, 6, 0x1fcc },
  60. { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V1.07/28/89", 5, 50, 6, 0x1fcc },
  61. { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.07/28/89", 72, 50, 6, 0x1fa2 },
  62. { "FUTURE DOMAIN CORP. (C) 1986-1990 1800-V2.0", 73, 43, 6, 0x1fa2 },
  63. { "FUTURE DOMAIN CORP. (C) 1991 1800-V2.0.", 72, 39, 6, 0x1fa3 },
  64. { "FUTURE DOMAIN CORP. (C) 1992 V3.00.004/02/92", 5, 44, 6, 0 },
  65. { "FUTURE DOMAIN TMC-18XX (C) 1993 V3.203/12/93", 5, 44, 7, 0 },
  66. { "IBM F1 P2 BIOS v1.0011/09/92", 5, 28, 7, 0x1ff3 },
  67. { "IBM F1 P2 BIOS v1.0104/29/93", 5, 28, 7, 0 },
  68. { "Future Domain Corp. V1.0008/18/93", 5, 33, 7, 0 },
  69. { "Future Domain Corp. V2.0108/18/93", 5, 33, 7, 0 },
  70. { "FUTURE DOMAIN CORP. V3.5008/18/93", 5, 34, 7, 0 },
  71. { "FUTURE DOMAIN 18c30/18c50/1800 (C) 1994 V3.5", 5, 44, 7, 0 },
  72. { "FUTURE DOMAIN CORP. V3.6008/18/93", 5, 34, 7, 0 },
  73. { "FUTURE DOMAIN CORP. V3.6108/18/93", 5, 34, 7, 0 },
  74. };
  75. #define SIGNATURE_COUNT ARRAY_SIZE(signatures)
  76. static int fdomain_isa_match(struct device *dev, unsigned int ndev)
  77. {
  78. struct Scsi_Host *sh;
  79. int i, base = 0, irq = 0;
  80. unsigned long bios_base = 0;
  81. struct signature *sig = NULL;
  82. void __iomem *p;
  83. static struct signature *saved_sig;
  84. int this_id = 7;
  85. if (ndev < ADDRESS_COUNT) { /* scan supported ISA BIOS addresses */
  86. p = ioremap(addresses[ndev], FDOMAIN_BIOS_SIZE);
  87. if (!p)
  88. return 0;
  89. for (i = 0; i < SIGNATURE_COUNT; i++)
  90. if (check_signature(p + signatures[i].offset,
  91. signatures[i].signature,
  92. signatures[i].length))
  93. break;
  94. if (i == SIGNATURE_COUNT) /* no signature found */
  95. goto fail_unmap;
  96. sig = &signatures[i];
  97. bios_base = addresses[ndev];
  98. /* read I/O base from BIOS area */
  99. if (sig->base_offset)
  100. base = readb(p + sig->base_offset) +
  101. (readb(p + sig->base_offset + 1) << 8);
  102. iounmap(p);
  103. if (base) {
  104. dev_info(dev, "BIOS at 0x%lx specifies I/O base 0x%x\n",
  105. bios_base, base);
  106. } else { /* no I/O base in BIOS area */
  107. dev_info(dev, "BIOS at 0x%lx\n", bios_base);
  108. /* save BIOS signature for later use in port probing */
  109. saved_sig = sig;
  110. return 0;
  111. }
  112. } else /* scan supported I/O ports */
  113. base = ports[ndev - ADDRESS_COUNT];
  114. /* use saved BIOS signature if present */
  115. if (!sig && saved_sig)
  116. sig = saved_sig;
  117. if (!request_region(base, FDOMAIN_REGION_SIZE, "fdomain_isa"))
  118. return 0;
  119. irq = irqs[(inb(base + REG_CFG1) & CFG1_IRQ_MASK) >> 1];
  120. if (sig)
  121. this_id = sig->this_id;
  122. sh = fdomain_create(base, irq, this_id, dev);
  123. if (!sh) {
  124. release_region(base, FDOMAIN_REGION_SIZE);
  125. return 0;
  126. }
  127. dev_set_drvdata(dev, sh);
  128. return 1;
  129. fail_unmap:
  130. iounmap(p);
  131. return 0;
  132. }
  133. static int fdomain_isa_param_match(struct device *dev, unsigned int ndev)
  134. {
  135. struct Scsi_Host *sh;
  136. int irq_ = irq[ndev];
  137. if (!io[ndev])
  138. return 0;
  139. if (!request_region(io[ndev], FDOMAIN_REGION_SIZE, "fdomain_isa")) {
  140. dev_err(dev, "base 0x%x already in use", io[ndev]);
  141. return 0;
  142. }
  143. if (irq_ <= 0)
  144. irq_ = irqs[(inb(io[ndev] + REG_CFG1) & CFG1_IRQ_MASK) >> 1];
  145. sh = fdomain_create(io[ndev], irq_, scsi_id[ndev], dev);
  146. if (!sh) {
  147. dev_err(dev, "controller not found at base 0x%x", io[ndev]);
  148. release_region(io[ndev], FDOMAIN_REGION_SIZE);
  149. return 0;
  150. }
  151. dev_set_drvdata(dev, sh);
  152. return 1;
  153. }
  154. static int fdomain_isa_remove(struct device *dev, unsigned int ndev)
  155. {
  156. struct Scsi_Host *sh = dev_get_drvdata(dev);
  157. int base = sh->io_port;
  158. fdomain_destroy(sh);
  159. release_region(base, FDOMAIN_REGION_SIZE);
  160. dev_set_drvdata(dev, NULL);
  161. return 0;
  162. }
  163. static struct isa_driver fdomain_isa_driver = {
  164. .match = fdomain_isa_match,
  165. .remove = fdomain_isa_remove,
  166. .driver = {
  167. .name = "fdomain_isa",
  168. .pm = FDOMAIN_PM_OPS,
  169. },
  170. };
  171. static int __init fdomain_isa_init(void)
  172. {
  173. int isa_probe_count = ADDRESS_COUNT + PORT_COUNT;
  174. if (io[0]) { /* use module parameters if present */
  175. fdomain_isa_driver.match = fdomain_isa_param_match;
  176. isa_probe_count = MAXBOARDS_PARAM;
  177. }
  178. return isa_register_driver(&fdomain_isa_driver, isa_probe_count);
  179. }
  180. static void __exit fdomain_isa_exit(void)
  181. {
  182. isa_unregister_driver(&fdomain_isa_driver);
  183. }
  184. module_init(fdomain_isa_init);
  185. module_exit(fdomain_isa_exit);
  186. MODULE_AUTHOR("Ondrej Zary, Rickard E. Faith");
  187. MODULE_DESCRIPTION("Future Domain TMC-16x0 ISA SCSI driver");
  188. MODULE_LICENSE("GPL");